[
  {
    "path": ".cirrus.yml",
    "content": "FreeBSD_task:\n  matrix:\n    env:\n      SSL: libressl\n  matrix:\n    freebsd_instance:\n      image_family: freebsd-14-3\n  prepare_script:\n    - pkg install -y $SSL git autoconf automake libtool pkgconf opus jpeg-turbo fdk-aac pixman libX11 libXfixes libXrandr libxkbfile nasm fusefs-libs3 check imlib2 freetype2 cmocka ibus\n    - git submodule update --init --recursive\n  configure_script:\n    - ./bootstrap\n    - env CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./configure --localstatedir=/var --enable-strict-locations --with-pkgconfigdir=/usr/local/libdata/pkgconfig --enable-strict-locations --enable-ibus --enable-ipv6 --enable-opus --enable-jpeg --enable-fdkaac --enable-painter --enable-pixman --enable-fuse --with-imlib2 --with-freetype2\n  build_script:\n    - make -j $(sysctl -n hw.ncpu || echo 4)\n  check_script:\n    - make check\n  install_script:\n    - make install\n  test_script:\n    - /usr/local/sbin/xrdp -v\n"
  },
  {
    "path": ".github/FUNDING.yml",
    "content": "open_collective: xrdp-project\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.yml",
    "content": "name: \"🕷️ Bug report\"\ndescription: Report errors or unexpected behavior\nlabels:\n  - \"bug\"\nbody:\n  - type: markdown\n    attributes:\n      value: |\n        Before submitting a bug, read the [FAQ](https://github.com/neutrinolabs/xrdp/wiki/Tips-and-FAQ). **In particular, on systemd-based systems. make sure you are not logged in on the console as the same user you are trying to use for xrdp**\n        \n        Please do not include links to images or videos on external websites. These are not guaranteed to always be available, and could be used to compromise web browsers.\n        \n        Videos hosted on github have a size limit (currently 10MB). If your video is larger than this, please upload it to https://youtube.com\n  - type: input\n    attributes:\n      label: xrdp version\n      placeholder: 0.9.20\n    validations:\n      required: true\n  - type: textarea\n    attributes:\n      label: Detailed xrdp version, build options\n      description: Copy & paste the result of `xrdp --version`. DO NOT remove `~~~` but paste the result between two `~~~`.\n      value: |\n        ~~~\n        Paste the result between `~~~`.  Please DO NOT remove `~~~`!\n        ~~~\n  - type: input\n    attributes:\n      label: Operating system & version\n      placeholder: \"Ubuntu 22.04 / AlmaLinux 9 / FreeBSD 13.2 / etc\"\n      description: Tell us about your operating system. See PRETTY_NAME\n        in /etc/os-release if you don't know.\n\n        Note we are currently unable to provide direct support for Red Hat\n        Enterprise Linux. Either reproduce the issue on CentOS/Alma/Rocky\n        OS, or contact Red Hat directly for support.\n    validations:\n      required: true\n  - type: dropdown\n    attributes:\n      label: Installation method\n      description: How was xrdp installed from?\n      options:\n        - dnf / apt / zypper / pkg / etc\n        - Homebrew / MacPorts\n        - git clone & make install\n        - Doesn't matter\n        - other\n    validations:\n      required: true\n  - type: input\n    attributes:\n      label: Which backend do you use?\n      description: Tell us about xrdp backend and version you're using. Typically, it would be either Xvnc or xorgxrdp or rarely NeutrionRDP / FreeRDP.\n      placeholder: Xvnc (tigervnc-1.12.0-13.el9_2)\n  - type: input\n    attributes:\n      label: What desktop environment do you use?\n      description: Tell us about your desktop (e.g. GNOME / KDE / Xfce / xterm). If you're certain the bug you about to report is not desktop specific, fill \"any\" here.\n      placeholder: GNOME\n  - type: input\n    attributes:\n      label: Environment xrdp running on\n      description: Tell us whether xrdp is running on a VM, or if on a physical machine what graphics cards are installed.\n  - type: input\n    attributes:\n      label: What's your client?\n      description: If you issue occurs with specific clients, tell us the client app name, app version client os version and platform.\n      placeholder: Microsoft's official client from Mac App Store, running on macOS Ventura.\n  - type: dropdown\n    attributes:\n      label: Area(s) with issue?\n      description: What things had an issue? Check all that apply.\n      multiple: true\n      options:\n        - Audio redirection\n        - Authentication\n        - Crashes such as segfault\n        - Clipboard\n        - Compatiblity aginst clients\n        - Compile error\n        - File transfer / drive redirection\n        - Graphic glitches\n        - Keyboard / Mouse\n        - Network\n        - Performance\n        - Session manager (sesman)\n        - Smartcard\n        - Other\n  - type: textarea\n    attributes:\n      label: Steps to reproduce\n      placeholder: Having detailed steps helps us reproduce the bug.\n    validations:\n      required: true\n  - type: textarea\n    attributes:\n      label: ✔️ Expected Behavior\n      placeholder: What were you expecting?\n    validations:\n      required: false\n  - type: textarea\n    attributes:\n      label: ❌ Actual Behavior\n      placeholder: What happened instead?\n    validations:\n      required: false\n  - type: textarea\n    attributes:\n      label: Anything else?\n      description: Links? References? Anything that will give us more context about the issue you are encountering!  We recommend attaching `xrdp.log`, `xrdp-sesman.log`, `xrdp/xorg.conf` or screenshots to clarify context.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/config.yml",
    "content": "contact_links:\n    - name: Questions\n      about: If you are new to xrdp and want to ask community for help, raise it as Q&A in discussion.\n      url: https://github.com/neutrinolabs/xrdp/discussions/new?category=q-a\n\n"
  },
  {
    "path": ".github/workflows/build.yml",
    "content": "name: build and test\non:\n  push:\n    branches-ignore:\n      - \"gh-pages\"\n    tags-ignore:\n      - \"v0.[0-8]**\"\n  pull_request:\n    branches-ignore:\n      - \"gh-pages\"\n\njobs:\n  build_and_test:\n    strategy:\n      fail-fast: false\n      matrix:\n        include:\n\n          # Minimal 64-bit arch builds\n          - CC: gcc\n            feature_set: min\n            arch: amd64\n            os: ubuntu-latest\n            unittests: false\n            DISTCHECK: false\n\n          - CC: g++\n            feature_set: min\n            arch: amd64\n            os: ubuntu-latest\n            unittests: false\n            DISTCHECK: false\n\n          - CC: clang\n            feature_set: min\n            arch: amd64\n            os: ubuntu-latest\n            unittests: false\n            DISTCHECK: false\n\n          # Maximal 64-bit arch builds\n          - CC: gcc\n            feature_set: max\n            arch: amd64\n            os: ubuntu-latest\n            unittests: true\n            DISTCHECK: true\n\n          - CC: g++\n            feature_set: max\n            arch: amd64\n            os: ubuntu-latest\n            unittests: false\n            DISTCHECK: false\n\n          - CC: clang\n            feature_set: max\n            arch: amd64\n            os: ubuntu-latest\n            unittests: true\n            DISTCHECK: true\n\n          - CC: clang\n            feature_set: max\n            arch: amd64\n            os: ubuntu-latest\n            unittests: true\n            DISTCHECK: false\n            name_extra: and AddressSanitized\n            CFLAGS: \"-fsanitize=address -ggdb\"\n            LDFLAGS: \"-fsanitize=address\"\n\n          - CC: clang\n            feature_set: max\n            arch: amd64\n            os: ubuntu-latest\n            unittests: true\n            DISTCHECK: false\n            name_extra: and UndefinedBehaviorSanitized\n            # -fsanitize=nullability is only available for Clang\n            # TODO: enable alignment\n            CFLAGS: \"-fsanitize=undefined -fsanitize=nullability -fno-sanitize=alignment -ggdb\"\n            LDFLAGS: \"-fsanitize=undefined -fsanitize=nullability -fno-sanitize=alignment\"\n            UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1:report_error_type=1\n\n          # Maximal debug 64-bit arch builds\n          # Check we can also do a static build without\n          # installing .a files\n          - CC: gcc\n            feature_set: max\n            arch: amd64\n            os: ubuntu-latest\n            unittests: true\n            DISTCHECK: false\n            name_extra: and DEBUG\n            CONF_FLAGS_EXTRA: \"--enable-devel-all --disable-static\"\n\n          # Maximal 32-bit arch builds\n          - CC: gcc\n            feature_set: max\n            arch: i386\n            os: ubuntu-latest\n            unittests: true\n            DISTCHECK: false\n            name_extra: for 32-bit arch (legacy OS)\n            CFLAGS: \"-m32\"\n            LDFLAGS: \"-m32\"\n\n          - CC: g++\n            feature_set: max\n            arch: i386\n            os: ubuntu-latest\n            unittests: false\n            DISTCHECK: false\n            name_extra: for 32-bit arch (legacy OS)\n            CFLAGS: \"-m32\"\n            LDFLAGS: \"-m32\"\n\n          - CC: clang\n            feature_set: max\n            arch: i386\n            os: ubuntu-latest\n            unittests: true\n            DISTCHECK: false\n            name_extra: for 32-bit arch (legacy OS)\n            CFLAGS: \"-m32\"\n            LDFLAGS: \"-m32\"\n\n    name: ${{ matrix.feature_set }} features with ${{ matrix.CC }} ${{ matrix.name_extra }}\n    runs-on: ${{ matrix.os }}\n    env:\n      CC: ${{ matrix.CC }}\n      CFLAGS: ${{ matrix.CFLAGS }}\n      LDFLAGS: ${{ matrix.LDFLAGS }}\n      UBSAN_OPTIONS: ${{ matrix.UBSAN_OPTIONS }}\n\n      # HACK (2020-11-16): github actions doesn't support YAML anchors/aliases to\n      # avoid repeating long config values. So instead the config values are defined\n      # as environment variables using a naming convention with fields that come from\n      # the job config. These environment variables are then referenced as regular\n      # environment variables via the naming convention in the \"define env\" step to\n      # define the standard environment variable used in the rest of the steps.\n      CONF_FLAGS_amd64_min: \"--disable-ipv6 --disable-jpeg --disable-fuse --disable-mp3lame\n                  --disable-fdkaac --disable-opus --disable-rfxcodec --disable-painter\n                  --disable-pixman --disable-utmp\"\n      CONF_FLAGS_amd64_max: \"--enable-ibus --enable-ipv6 --enable-jpeg --enable-fuse\n                  --enable-mp3lame --enable-fdkaac --enable-opus --enable-rfxcodec\n                  --enable-painter --enable-pixman --enable-utmp\n                  --with-imlib2 --with-freetype2 --enable-tests --enable-x264\n                  --enable-openh264 --enable-smartcard\"\n      CONF_FLAGS_i386_max: \"--enable-ipv6 --enable-jpeg\n                  --enable-mp3lame --enable-opus --enable-rfxcodec\n                  --enable-painter --disable-pixman\n                  --with-freetype2 --host=i686-linux --enable-tests\n                  --enable-smartcard\"\n\n      PKG_CONFIG_PATH_i386: \"/usr/lib/i386-linux-gnu/pkgconfig\"\n    steps:\n      - name: \"Define feature and arch dependent environment variables\"\n        # Note: any \"variable=value\" written to the $GITHUB_ENV file will be\n        # defined as an environment variable for all future steps in this job\n        # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable\n        run: |\n          echo \"CONF_FLAGS=$CONF_FLAGS_${{ matrix.arch }}_${{ matrix.feature_set }} ${{ matrix.CONF_FLAGS_EXTRA }}\" >> $GITHUB_ENV\n          echo \"PKG_CONFIG_PATH=$PKG_CONFIG_PATH_${{ matrix.arch }}\" >> $GITHUB_ENV\n      - uses: actions/checkout@v6\n      - name: \"Install Dependencies\"\n        # See https://github.com/actions/runner-images/issues/7192\n        run: |\n          echo RESET grub-efi/install_devices | sudo debconf-communicate grub-pc\n          sudo scripts/install_xrdp_build_dependencies_with_apt.sh ${{ matrix.feature_set }} ${{ matrix.arch }} --allow-downgrades --allow-remove-essential --allow-change-held-packages\n      - name: Bootstrap\n        run: ./bootstrap\n      - name: configure\n        run: ./configure $CONF_FLAGS\n      - name: make\n        run: make -j $(nproc)\n      - name: unittests\n        if: ${{ matrix.unittests }}\n        run: make check -j $(nproc) || (cat tests/*/test-suite.log && exit 1)\n      - name: distcheck\n        id: dist_check\n        if: ${{ matrix.DISTCHECK }}\n        run: make distcheck -j $(nproc)\n      - name: \"Artifact: test-suite.log distcheck\"\n        uses: actions/upload-artifact@v7\n        if: always() && steps.dist_check.outcome == 'failure'\n        with:\n          name: test-suite-distcheck-${{ matrix.cc }}-${{ matrix.feature_set }}\n          path: ${{ github.workspace }}/xrdp-*/_build/sub/tests/xrdp/test-suite.log\n\n  cppcheck:\n    name: cppcheck\n    runs-on: ubuntu-latest\n    env:\n      CC: gcc\n      # This is required to use a version of cppcheck other than that\n      # supplied with the operating system\n      CPPCHECK_VER: \"2.20.0\"\n      CPPCHECK_REPO: https://github.com/danmar/cppcheck.git\n    steps:\n      # Set steps.os.outputs.image to the specific OS (e.g. 'ubuntu20')\n      - name: Get operating system name and version.\n        id: os\n        run: echo \"image=$ImageOS\" >>$GITHUB_OUTPUT\n        shell: bash\n      - uses: actions/checkout@v6\n      - name: Cache cppcheck\n        uses: actions/cache@v5\n        env:\n          cache-name: cache-cppcheck\n        with:\n          path: ~/cppcheck.local\n          key: ${{ steps.os.outputs.image }}-build-${{ env.cache-name }}-${{ env.CPPCHECK_VER }}\n      - run: sudo scripts/install_cppcheck_dependencies_with_apt.sh $CPPCHECK_VER\n      - run: ./bootstrap\n      - run: ./configure\n      - run: scripts/install_cppcheck.sh $CPPCHECK_REPO $CPPCHECK_VER\n      - run: scripts/run_cppcheck.sh -v $CPPCHECK_VER\n\n  code_formatting_check:\n    name: code formatting check\n    runs-on: ubuntu-latest\n    env:\n      CC: gcc\n      # This is required to use a version of astyle other than that\n      # supplied with the operating system\n      ASTYLE_VER: 3.4.14\n      ASTYLE_REPO: https://gitlab.com/saalen/astyle.git\n    steps:\n      # Set steps.os.outputs.image to the specific OS (e.g. 'ubuntu20')\n      - name: Get operating system name and version.\n        id: os\n        run: echo \"image=$ImageOS\" >>$GITHUB_OUTPUT\n        shell: bash\n      - uses: actions/checkout@v6\n      - name: Cache astyle\n        uses: actions/cache@v5\n        env:\n          cache-name: cache-astyle\n        with:\n          path: ~/astyle.local\n          key: ${{ steps.os.outputs.image }}-build-${{ env.cache-name }}-${{ env.ASTYLE_VER }}\n      - run: sudo scripts/install_astyle_dependencies_with_apt.sh\n      - run: scripts/install_astyle.sh $ASTYLE_REPO $ASTYLE_VER\n      - name: Format code with astyle\n        run: scripts/run_astyle.sh -v $ASTYLE_VER\n      - name: Check code formatting\n        run: git diff --exit-code\n"
  },
  {
    "path": ".github/workflows/coverity.yml",
    "content": "name: Coverity\n\non:\n  schedule:\n  - cron: \"0 0 * * *\"\n  workflow_dispatch:\n\njobs:\n  scan:\n    name: scan\n    runs-on: ubuntu-latest\n    if: ${{ github.repository_owner == 'neutrinolabs' }}\n    env:\n      CC: gcc\n      CONF_FLAGS_amd64_max: \"--enable-ipv6 --enable-jpeg --enable-fuse --enable-mp3lame\n                  --enable-fdkaac --enable-opus --enable-rfxcodec --enable-painter\n                  --enable-pixman --enable-utmp\n                  --enable-x264 --enable-openh264\n                  --with-imlib2 --with-freetype2 --enable-tests\"\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Download Coverity build tool\n        run: |\n          wget -c -N https://scan.coverity.com/download/linux64 --post-data \"token=${{ secrets.COVERITY_SCAN_TOKEN }}&project=neutrinolabs/xrdp\" -O coverity_tool.tar.gz\n          mkdir coverity_tool\n          tar xzf coverity_tool.tar.gz --strip 1 -C coverity_tool\n\n      - name: \"Install Dependencies\"\n        run: |\n          echo RESET grub-efi/install_devices | sudo debconf-communicate grub-pc\n          sudo scripts/install_xrdp_build_dependencies_with_apt.sh max amd64 --allow-downgrades --allow-remove-essential --allow-change-held-packages\n      - name: Bootstrap\n        run: ./bootstrap\n      - name: configure\n        run: ./configure $CONF_FLAGS_amd64_max\n      - name: make\n        run: |\n          export PATH=`pwd`/coverity_tool/bin:$PATH\n          cov-build --dir cov-int make -j $(nproc)\n\n      - name: Submit build result to Coverity Scan\n        run: |\n          tar czvf cov.tar.gz cov-int\n          curl --form token=${{ secrets.COVERITY_SCAN_TOKEN }} \\\n            --form email=meta@vmeta.jp \\\n            --form file=@cov.tar.gz \\\n            --form version=\"Commit $GITHUB_SHA\" \\\n            --form description=\"Build submitted via CI\" \\\n            https://scan.coverity.com/builds?project=neutrinolabs/xrdp\n\n"
  },
  {
    "path": ".github/workflows/release-tarball.yml",
    "content": "name: Generate release tarball\n\non:\n  workflow_dispatch:\n    inputs:\n      tag:\n        description: 'Tag to build'\n        required: true\n\njobs:\n  build:\n    name: Generate release tarball (${{ github.event.repository.name }} ${{ github.event.inputs.tag }})\n    runs-on: ubuntu-latest\n\n    steps:\n      - name: Set timestamp\n        run: echo \"timestamp=$(date +'%Y%m%d-%H%M%S')\" >> $GITHUB_ENV\n\n      - name: Checkout repository\n        uses: actions/checkout@v6\n        with:\n          ref: ${{ github.event.inputs.tag }}\n\n      - name: Install dependencies\n        run: |\n          sudo scripts/install_xrdp_build_dependencies_with_apt.sh min amd64\n\n      - name: Run make distcheck\n        run: |\n          ./bootstrap\n          ./configure\n          make distcheck\n\n      - name: Find generated tarball\n        id: find_tarball\n        run: |\n          TARBALL=$(find . -maxdepth 1 -name \"*.tar.gz\" | head -n 1)\n          if [ -z \"$TARBALL\" ]; then\n            echo \"Error: No tarball found\" >&2\n            exit 1\n          fi\n          echo \"tarball=$TARBALL\" >> $GITHUB_ENV\n\n      - name: Upload Artifact\n        uses: actions/upload-artifact@v7\n        with:\n          name:  ${{ github.event.repository.name }}-${{ github.event.inputs.tag }}-${{ env.timestamp }}\n          path: \"${{ env.tarball }}\"\n          if-no-files-found: error\n          compression-level: 0\n          retention-days: 7\n\n"
  },
  {
    "path": ".gitignore",
    "content": "*~\n*.a\naclocal.m4\nAUTHORS\nautom4te.cache/\nChangeLog\ncompile\nconfig_ac.h\nconfig_ac-h.in\nconfig.guess\nconfig.log\nconfig.status\nconfig.sub\nconfigure\ndepcomp\n.deps/\nfontutils/xrdp-dumpfv1\nfontutils/xrdp-mkfv1\ngenkeymap/xrdp-genkeymap\ninstall-sh\ninstfiles/pam.d/xrdp-sesman\ninstfiles/*.service\nkeygen/xrdp-keygen\n*.la\n.libs\nlibtool\n*.lo\n*.log\nltmain.sh\nMakefile\nMakefile.in\nmissing\nmkinstalldirs\nNEWS\n*.o\nREADME\nsesman/chansrv/xrdp-chansrv\nsesman/sesexec/xrdp-sesexec\nsesman/tools/xrdp-authtest\nsesman/tools/xrdp-dis\nsesman/tools/xrdp-sesadmin\nsesman/tools/xrdp-sesrun\nsesman/tools/xrdp-sestest\nsesman/tools/xrdp-xcon\nsesman/xrdp-sesman\nsesman/sesman.ini\n*.so\nstamp-h1\ntap-driver.sh\ntest-driver\ntests/common/test_common\ntests/libipm/test_libipm\ntests/libxrdp/test_libxrdp\ntests/memtest/memtest\ntests/xrdp/test_xrdp\ntools/devel/tcp_proxy/tcp_proxy\ntools/chkpriv/xrdp-chkpriv\ntools/chkpriv/xrdp-droppriv\n*.trs\nwaitforx/waitforx\nxrdp/xrdp\nxrdp/xrdp.ini\nxrdp_configure_options.h\nxrdpapi/xrdp-xrdpapi-simple\n.vscode/*\nxrdp_accel_assist/xrdp-accel-assist\n"
  },
  {
    "path": ".gitmodules",
    "content": "[submodule \"librfxcodec\"]\n\tpath = librfxcodec\n\turl = https://github.com/neutrinolabs/librfxcodec.git\n\tbranch = .\n\tignore = untracked\n[submodule \"libpainter\"]\n\tpath = libpainter\n\turl = https://github.com/neutrinolabs/libpainter.git\n\tbranch = .\n\tignore = untracked\n[submodule \"ulalaca\"]\n\tpath = ulalaca\n\turl = https://github.com/neutrinolabs/ulalaca-xrdp.git\n"
  },
  {
    "path": "COPYING",
    "content": "Apache License, Version 2.0\n\nVersion 2.0, January 2004\n\nhttp://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n1. Definitions.\n\n\"License\" shall mean the terms and conditions for use, reproduction, and \ndistribution as defined by Sections 1 through 9 of this document.\n\n\"Licensor\" shall mean the copyright owner or entity authorized by the \ncopyright owner that is granting the License.\n\n\"Legal Entity\" shall mean the union of the acting entity and all other \nentities that control, are controlled by, or are under common control \nwith that entity. For the purposes of this definition, \"control\" means \n(i) the power, direct or indirect, to cause the direction or management \nof such entity, whether by contract or otherwise, or (ii) ownership of \nfifty percent (50%) or more of the outstanding shares, or \n(iii) beneficial ownership of such entity.\n\n\"You\" (or \"Your\") shall mean an individual or Legal Entity exercising \npermissions granted by this License.\n\n\"Source\" form shall mean the preferred form for making modifications, \nincluding but not limited to software source code, documentation source, \nand configuration files.\n\n\"Object\" form shall mean any form resulting from mechanical transformation \nor translation of a Source form, including but not limited to compiled \nobject code, generated documentation, and conversions to other media types.\n\n\"Work\" shall mean the work of authorship, whether in Source or Object form, \nmade available under the License, as indicated by a copyright notice that is \nincluded in or attached to the work (an example is provided in the Appendix below).\n\n\"Derivative Works\" shall mean any work, whether in Source or Object form, \nthat is based on (or derived from) the Work and for which the editorial \nrevisions, annotations, elaborations, or other modifications represent, as a \nwhole, an original work of authorship. For the purposes of this License, \nDerivative Works shall not include works that remain separable from, or \nmerely link (or bind by name) to the interfaces of, the Work and \nDerivative Works thereof.\n\n\"Contribution\" shall mean any work of authorship, including the original \nversion of the Work and any modifications or additions to that Work or Derivative \nWorks thereof, that is intentionally submitted to Licensor for inclusion in the \nWork by the copyright owner or by an individual or Legal Entity authorized to \nsubmit on behalf of the copyright owner. For the purposes of this definition, \n\"submitted\" means any form of electronic, verbal, or written communication sent \nto the Licensor or its representatives, including but not limited to \ncommunication on electronic mailing lists, source code control systems, and \nissue tracking systems that are managed by, or on behalf of, the Licensor for \nthe purpose of discussing and improving the Work, but excluding communication \nthat is conspicuously marked or otherwise designated in writing by the copyright \nowner as \"Not a Contribution.\"\n\n\"Contributor\" shall mean Licensor and any individual or Legal Entity on behalf \nof whom a Contribution has been received by Licensor and subsequently incorporated \nwithin the Work.\n\n2. Grant of Copyright License. Subject to the terms and conditions of this License, \neach Contributor hereby grants to You a perpetual, worldwide, non-exclusive, \nno-charge, royalty-free, irrevocable copyright license to reproduce, prepare \nDerivative Works of, publicly display, publicly perform, sublicense, and distribute \nthe Work and such Derivative Works in Source or Object form.\n\n3. Grant of Patent License. Subject to the terms and conditions of this License, \neach Contributor hereby grants to You a perpetual, worldwide, non-exclusive, \nno-charge, royalty-free, irrevocable (except as stated in this section) patent \nlicense to make, have made, use, offer to sell, sell, import, and otherwise transfer \nthe Work, where such license applies only to those patent claims licensable by such \nContributor that are necessarily infringed by their Contribution(s) alone or by \ncombination of their Contribution(s) with the Work to which such Contribution(s) was \nsubmitted. If You institute patent litigation against any entity (including a \ncross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution \nincorporated within the Work constitutes direct or contributory patent infringement, \nthen any patent licenses granted to You under this License for that Work shall \nterminate as of the date such litigation is filed.\n\n4. Redistribution. You may reproduce and distribute copies of the Work or Derivative \nWorks thereof in any medium, with or without modifications, and in Source or Object \nform, provided that You meet the following conditions:\n\nYou must give any other recipients of the Work or Derivative Works a copy of this \nLicense; and\n\nYou must cause any modified files to carry prominent notices stating that You changed \nthe files; and\n\nYou must retain, in the Source form of any Derivative Works that You distribute, \nall copyright, patent, trademark, and attribution notices from the Source form of the Work, \nexcluding those notices that do not pertain to any part of the Derivative Works; and\n\nIf the Work includes a \"NOTICE\" text file as part of its distribution, then any \nDerivative Works that You distribute must include a readable copy of the attribution \nnotices contained within such NOTICE file, excluding those notices that do not pertain \nto any part of the Derivative Works, in at least one of the following places: within a \nNOTICE text file distributed as part of the Derivative Works; within the Source form or \ndocumentation, if provided along with the Derivative Works; or, within a display \ngenerated by the Derivative Works, if and wherever such third-party notices normally \nappear. The contents of the NOTICE file are for informational purposes only and do not \nmodify the License. You may add Your own attribution notices within Derivative Works \nthat You distribute, alongside or as an addendum to the NOTICE text from the Work, \nprovided that such additional attribution notices cannot be construed as modifying \nthe License. You may add Your own copyright statement to Your modifications and may \nprovide additional or different license terms and conditions for use, reproduction, \nor distribution of Your modifications, or for any such Derivative Works as a whole, \nprovided Your use, reproduction, and distribution of the Work otherwise complies \nwith the conditions stated in this License.\n\n5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution \nintentionally submitted for inclusion in the Work by You to the Licensor shall be under \nthe terms and conditions of this License, without any additional terms or conditions. \nNotwithstanding the above, nothing herein shall supersede or modify the terms of any \nseparate license agreement you may have executed with Licensor regarding such Contributions.\n\n6. Trademarks. This License does not grant permission to use the trade names, trademarks, \nservice marks, or product names of the Licensor, except as required for reasonable and \ncustomary use in describing the origin of the Work and reproducing the content of \nthe NOTICE file.\n\n7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, \nLicensor provides the Work (and each Contributor provides its Contributions) on an \n\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, \nincluding, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, \nMERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for \ndetermining the appropriateness of using or redistributing the Work and assume any \nrisks associated with Your exercise of permissions under this License.\n\n8. Limitation of Liability. In no event and under no legal theory, whether in tort \n(including negligence), contract, or otherwise, unless required by applicable law \n(such as deliberate and grossly negligent acts) or agreed to in writing, shall any \nContributor be liable to You for damages, including any direct, indirect, special, \nincidental, or consequential damages of any character arising as a result of this \nLicense or out of the use or inability to use the Work (including but not limited to \ndamages for loss of goodwill, work stoppage, computer failure or malfunction, or any \nand all other commercial damages or losses), even if such Contributor has been advised \nof the possibility of such damages.\n\n9. Accepting Warranty or Additional Liability. While redistributing the Work or \nDerivative Works thereof, You may choose to offer, and charge a fee for, acceptance \nof support, warranty, indemnity, or other liability obligations and/or rights consistent \nwith this License. However, in accepting such obligations, You may act only on Your \nown behalf and on Your sole responsibility, not on behalf of any other Contributor, \nand only if You agree to indemnify, defend, and hold each Contributor harmless for any \nliability incurred by, or claims asserted against, such Contributor by reason of your \naccepting any such warranty or additional liability.\n\nEND OF TERMS AND CONDITIONS\n\nAPPENDIX: How to apply the Apache License to your work\nTo apply the Apache License to your work, attach the following boilerplate notice, \nwith the fields enclosed by brackets \"[]\" replaced with your own identifying \ninformation. (Don't include the brackets!) The text should be enclosed in the \nappropriate comment syntax for the file format. We also recommend that a file or class \nname and description of purpose be included on the same \"printed page\" as the \ncopyright notice for easier identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n\n"
  },
  {
    "path": "Makefile.am",
    "content": "ACLOCAL_AMFLAGS = -I m4\n# Redefine the localstatedir to stop github CI defaulting to\n# something like /home/runner/work/xrdp/xrdp/xrdp-0.10.80/_inst/var\n#\n# A path this long (50 chars) can trigger some -Werror=format-truncation\n# errors when using the XRDP_SOCKET_ROOT_PATH macro to create a Unix\n# domain socket name, as these names have a quite short length (108\n# characters on Linux).\nAM_DISTCHECK_CONFIGURE_FLAGS = \\\n  --localstatedir=/distcheckdummy/var \\\n  --without-systemdsystemunitdir \\\n  --enable-strict-locations \\\n  --enable-tests\n\nEXTRA_DIST = \\\n  COPYING \\\n  README.md \\\n  NEWS.md \\\n  astyle_config.as \\\n  bootstrap \\\n  coding_style.md \\\n  m4 \\\n  vrplayer\n\nif XRDP_NEUTRINORDP\nNEUTRINORDPDIR = neutrinordp\nelse\nNEUTRINORDPDIR =\nendif\n\nif XRDP_XRDPVR\nXRDPVRDIR = xrdpvr\nelse\nXRDPVRDIR =\nendif\n\nif XRDP_PAINTER\nPAINTERDIR = libpainter\nelse\nPAINTERDIR =\nendif\n\nif XRDP_RFXCODEC\nRFXCODECDIR = librfxcodec\nelse\nRFXCODECDIR =\nendif\n\nif XRDP_ULALACA\nULALACADIR = ulalaca\nelse\nULALACADIR =\nendif\n\nif XRDP_ACCEL\nACCELDIR = xrdp_accel_assist\nelse\nACCELDIR =\nendif\n\n# This should not be dictionary order but build order\nSUBDIRS = \\\n  third_party \\\n  third_party/tomlc99 \\\n  common \\\n  vnc \\\n  xup \\\n  mc \\\n  $(NEUTRINORDPDIR) \\\n  libipm \\\n  libxrdp \\\n  $(PAINTERDIR) \\\n  $(RFXCODECDIR) \\\n  sesman \\\n  xrdp \\\n  fontutils \\\n  keygen \\\n  waitforx \\\n  docs \\\n  instfiles \\\n  genkeymap \\\n  xrdpapi \\\n  pkgconfig \\\n  $(XRDPVRDIR) \\\n  $(ULALACADIR) \\\n  tests \\\n  tools \\\n  $(ACCELDIR)\n\ndistclean-local:\n\t-rm -f xrdp_configure_options.h\n"
  },
  {
    "path": "NEWS.md",
    "content": "# Release notes for xrdp v0.9.19 (2022/03/17)\n\n## General announcements\n* Running xrdp and xrdp-sesman on separate hosts is still supported by this release, but is now deprecated. This is not secure. A future release will replace the TCP socket used between these processes with a Unix Domain Socket, and then cross-host running will not be possible.\n\n## New features\n* Both inbound and outbound clipboards can now be restricted for text, files or images [Sponsored by @CyberTrust @clear-code and @kenhys] (#2087)\n\n## Bug fixes\n* [CVE-2022-23613](https://www.cve.org/CVERecord?id=CVE-2022-23613): Privilege escalation on xrdp-sesman (This fix is also in the out-of-band v0.9.18.1 release)\n* The versions of imlib2 used on RHEL 7 and 8 are now detected correctly (#2118)\n* Some situations where zombie processes could exist have been resolved (#2146, #2151, #2168)\n* Some null-pointer exceptions which can happen in the logging module have been addressed (#2149)\n* Some minor logging errors have been corrected (#2152)\n* The signal handling in sesman has been reworked to prevent race conditions when a child exits. This has also made it possible to reliably reload the sesman configuration with SIGHUP (#1729, #2168)\n\n## Internal changes\n* Versions 0.13 and later of checklib can undefine the pre-processor symbol `HAVE_STDINT_H`. The xrdp tests now build successfully against these versions (#2124)\n* OpenSSL packaging changes (#2130):-\n   - The OpenSSL 3 EVP interface is now fully supported\n   - When building against OpenSSL 3, an internal implementation of the RC4 cipher is used instead of the implementation from the OpenSSL legacy provider\n   - The wrapping of the OpenSSL library has been improved which should make it simpler to provide an alternative cryptographic provider in the future, if required\n   - The logging of TLS/non-TLS security negotiation has been improved\n* cppcheck version used for CI bumped to 2.7 (#2140)\n* The `s_check()` macro which is easily mis-used has been removed (#2144)\n* Status values for the DRDYNVC channel are now available in `libxrdp/xrdp_channel.h`\n\n## Changes for packagers or developers\n* On OpenSSL 3 systems, there is now no need to build with the `-Wno-error=deprecated-declarations` flag\n\n## Known issues\n\n* On-the-fly resolution change requires the Microsoft Store version of Remote Desktop client but sometimes crashes on connect (#1869)\n* xrdp's login dialog is not relocated at the center of the new resolution after on-the-fly resolution change happens (#1867)\n\n-----------------------\n\n# Release notes for xrdp v0.9.18.1 (2022/02/08)\n\nThis is a security fix release that includes fixes for the following privilege escalation vulnerability.\n\n* [CVE-2022-23613: Privilege escalation on xrdp-sesman](https://www.cve.org/CVERecord?id=CVE-2022-23613)\n\nUsers who uses xrdp v0.9.17 or v0.9.18 are recommended to update to this version.\n\n## Special thanks\n\nThanks to [Gilad Kleinman](https://github.com/giladkl) reporting the vulnerability and reviewing fix.\n\n-----------------------\n\n# Release notes for xrdp v0.9.18 (2022/01/10)\n\n## General announcements\n* Running xrdp and xrdp-sesman on separate hosts is still supported by this release, but is now deprecated. This is not secure. A future release will replace the TCP socket used between these processes with a Unix Domain Socket, and then cross-host running will not be possible.\n* Special thanks for @trishume for contributing code to the RFX codec\n\n## New features\n* Backgrounds and logos on the login screen can now be zoomed and scaled (#1962)\n* Small change for Alpine Linux support (#2005)\n* loongarch support (#2057)\n* Improved Fail2ban support (#1976)\n\n## Bug fixes\n* Logging is improved for security protocol level decisions (#1974, #1975)\n* An unnecessary log error message which is always generated when running neutrinordp has been removed (#2016)\n* An incorrect development log message has been fixed (#2074)\n* Some informational and error messages written to the console on stdout have been removed or replaced with log messages (#2078 #2080)\n* Failure to attach to the memory area shared with xorgxrdp is now logged (#2065)\n* A regression in the VNC module logging which might cause a connection to drop out has been identified and fixed (#1989)\n* Remote drive redirection now works if printer redirection is also requested by the client (#327)\n* Some file names could not be copied from the client to the server over the clipboard. This is now fixed (#1992, #1995)\n* A config value has been added which allows copy-pasting of files to work with Nautilus for GNOME 3 versions >= 3.29.92 (#1994, #1996)\n* Clipboard now works properly when files can't be read (#1997 #2001)\n* (xorgxrdp v0.2.18) The screen is fully refreshed after initialising shared memory which should fix black screen problems like #1964\n* An incorrect initialisation reported by @qarmin has been fixed (#1909)\n* Some minor memory leaks have been fixed (#2014 #2028)\n* A hard hang in chansrv when copying files from the remote system has been addressed (#2032)\n* Users can now capitalise username and password on the login screen if required (#2061)\n* Some failed size checks in the fastpath code with `--enable-devel-streamcheck` have been addressed (#2066,#2070)\n* Log level for clipboard restriction has been promoted from DEVEL DEBUG to INFO  (#2088)\n* A buffer overflow in the RFX codec associated with large screens has been fixed (#2087)\n\n## Internal changes\n* Some 64-bit packages are removed during the 32-bit CI build process in an attempt to make this more robust (#1985)\n* Minor improvements to error checking and logging for file copy-paste (#1996)\n* Now uses cppcheck 2.6 for CI builds (#2008)\n* Generated systemd unit files now ignored by git (#2006)\n* More internal tests (#2015)\n* Some unnecessary files have been removed from the distribution (#2030)\n* The `which` command in shell scripts has been replaced with `command -v` (#2067)\n* Additional unit tests added for `g_file_get_size()` (#1988)\n* A compiler warning with -O3 on gcc 11.1 has been addressed (#2105)\n* An unused declaration for xrdp_wm_drdynvc_up has been removed (#2098)\n* The SCP V0 code has been unified, which will make it easier to update and replace (#2011)\n* Monitor processing unit tests for existing xrdp_sec function have been added (#1932)\n* The librfxcodec has been updated as part of #2087, and also to add stack frames to assemble code to assist debugging\n\n## Changes for packagers or developers\n* The `--with-imlib2` option has been added. If xrdp is built with imlib2, the login screen supports more image formats for the background and logo, and better quality zooming and scaling (#1962)\n\n## Known issues\n\n* On-the-fly resolution change requires the Microsoft Store version of Remote Desktop client but sometimes crashes on connect (#1869)\n* xrdp's login dialog is not relocated at the center of the new resolution after on-the-fly resolution change happens (#1867)\n\n-----------------------\n\n# Release notes for xrdp v0.9.17 (2021/08/31)\n\n## General announcements\n* Running xrdp and xrdp-sesman on separate hosts is still supported by this release, but is now deprecated. This is not secure. A future release will replace the TCP socket used between these processes with a Unix Domain Socket, and then cross-host running will not be possible.\n\n## New features\n* The IP address, port, and user name of NeutrinoRDP Proxy connection are logged in xrdp.log - these connections may not have a sesman log to use (#1873)\n* The performance settings for NeutrinoRDP can be now configured (#1903)\n* Support for Alpine Linux in startwm.sh (#1965)\n* clipboard: log file transfer for the purpose of audit (#1954)\n* Client's Keyboard layout now can be overridden by xrdp configuration for debugging purposes (#1952)\n\n## Bug fixes\n* PAM_USER environment variable is not set when using pam_exec module (#1882)\n* Allow common channel settings to be overridden for modules as well as chansrv (#1899)\n* The text only-copy/paste interface for the VNC module (used only when chansrv is not active) has been improved (#1900)\n* The unsupported `tcutils` utility has been removed (#1943)\n* The quality of TLS logging has been improved (#1926)\n* Keyboard information is now passed correctly through NeuutrinoRDP, and can be overridden if required (#1934)\n* A message is now logged in the sesman log for unsuccessful login attempts detailing the user used (#1947)\n\n\n## Internal changes\n* astyle formatting is now checked during CI builds (#1879)\n* Generalise development build options, and add --enable-devel-streamcheck (#1887)\n* Now uses cppcheck 2.5 for CI builds (#1938)\n* The SCP protocol is now using a standard `struct trans` for messaging rather than its own thing (#1925)\n\n## Changes for packagers or developers\n* The `--enable-xrdpdebug` developer option has been replaced with finer-grained `--enable-devel-*` options. Consequently, specifying `--enable-xrdpdebug` is now an error (#1913)\n\n## Known issues\n\n* On-the-fly resolution change requires the Microsoft Store version of Remote Desktop client but sometimes crashes on connect (#1869)\n* xrdp's login dialog is not relocated at the center of the new resolution after on-the-fly resolution change happens (#1867)\n\n-----------------------\n\n# Release notes for xrdp v0.9.16 (2021/04/30)\n\n## New features\n* On-the-fly resolution change now supported for Xvnc and Xorg (#448, #1820) - thanks to @Nexarian for this significant first contribution. See the following YouTube video for a demo.\n    * [Windows] https://youtu.be/cZ0ebieZHeA\n    * [Mac] https://youtu.be/6kfAkyLUgFY\n* xrdp can now use key algorithms other than RSA for TLS (#1776)\n* Do not spit on the console 2nd stage (inspired by Debian) #1762\n* Unified and improved logging (#1742, #1767, #1802, #1806, #1807, #1826, #1843) - thanks to @aquesnel for this detailed work.\n* Other logging level fixes (#1864)\n* chansrv can now work on `DISPLAY=:0` so it can be used with x11vnc/Vino/etc sessions (#1849)\n\n## Bug fixes\n* Fix some regressions in sesman auth modules (#1769)\n* Minor manpage fixes (#1787)\n* Fix TS_PLAY_SOUND_PDU_DATA to set the correct frequency and duration (#1793)\n* Fix password leakage to logs in NeutrinoRDP module (#1872) - thanks to @TOMATO-ONE for reporting.\n\n## Internal changes\n* cppcheck version for CI bumped to 2.4 (#1771, #1836)\n* FreeBSD version for CI bumped to 12-2 (#1804)\n* Support for check unit test framework added (#1843, #1860)\n* FreeBSD FUSE module now compiles under CI but needs additional work (#1856)\n* Compilation support added for additional Debian platforms (#1818)\n* Refactoring:-\n   * Confusing preprocessor macro USE_NOPAM replaced with USE_PAM (#1800)\n   * Window manager states in xrdp executable now use symbolic constants instead of numbers (#1803)\n* Documentation improvements\n   * KRDC added to client list (#1817)\n   * Platform support tier added (#1822)\n   * README file revised (#1863)\n* Don't install test+development executables by default (#1858)\n\n## Changes for packagers\nThese changes are likely to impact operating system package builders and those building xrdp from source.\n* (#1843, #1860) This release introduces an additional optional compile-time dependency on the `check` unit test framework. The dependency is recommended when packaging for compile-time tests.\n* (#1858) The executables `memtest` and `tcp_proxy` are no longer copied to the sbin directory on a package install.\n\n## Known issues\n\n* On-the-fly resolution change requires the Microsoft Store version of Remote Desktop client but sometimes crashes on connect (#1869)\n* xrdp's login dialog is not relocated at the center of the new resolution after on-the-fly resolution change happens (#1867)\n\n-----------------------\n\n# Release notes for xrdp v0.9.15 (2020/12/28)\n\n## New features\n* Allow token sign in without autologon for SSO (#1667 #1668)\n* Norwegian keyboard support (#1675)\n* Improved config support for chansrv (#1635)\n* Unified chansrv, sesman and libxrdp logging (#1633 #1708 #1738) - thanks to @aquesnel\n* Support SUSE move to /usr/etc (#1702)\n* Parameters may now be specified for user-specified shell (#1270 #1695)\n* xrdp executables now allow alternative config files to be specified with -c (#1588 #1650 #1651)\n* sesrun improvements (#1741)\n* Drive redirection location can now be specified (#1048)\n* Now compiles on RISC-V (#1761)\n\n## Bug fixes\n* Additional buffer overflow checks (#1662)\n* FUSE support now builds on 32-bit platforms (#1682)\n* genkeymap array size conflict fixed (#1691)\n* Buffering issue with neutrinordp over a slow link fixed (#1608 1634)\n* Various documentation fixes (#1704 #1741 #1755 #1759)\n* Prevent PAM info message from causing authentication failure (#1727)\n* Cosmetic fixes for minor issues (#1751 #1755 #1749)\n* Try harder to clean up socket files on session exit (#1740 #1756)\n* xrdp-chansrv become defunct in docker while file copy (#1658)\n\n## Internal changes\n* Compilation warnings with newer compilers (#1659 #1680)\n* Continuation Integration checks on 32-bit platforms now include FUSE support (#1682)\n* Continuation Integration builds now default to the Ubuntu Focal platform (#1666)\n* FUSE type tidy-ups (#1686)\n* Switch from Travis CI to GitHub Actions (#1728 #1732)\n* Easier to set up console logging for utilities (#1711)\n\n-----------------------\n\n# Release notes for xrdp v0.9.14 (2020/08/31)\n\n## New features\n* VNC multi-monitor support if you are using a suitable Xvnc server #1343\n* VNC sessions now resize by default on reconnection if you are using a suitable Xvnc server #1343\n* Support Slackware for PAM #1558 #1560\n* Support Programmer Dvorak Keyboard #1663\n\n**[HEADS UP]** The VNC changes are significant. They described in more detail on the following wiki page.\n* [Xvnc backend : Multi monitor and resize support](https://github.com/neutrinolabs/xrdp/wiki/Xvnc-backend-:-Multi-monitor-and-resize-support)\n\n## Bug fixes\n* Fix odd shift key behavior (workaround) #397 #1522\n* Fix Xorg path in the document for Arch Linux #1448 #1529\n* Fix Xorg path in the document for CentOS 8 #1646 #1647\n* Fix internal username/password buffer is smaller than RDP protocol specification #1648 #1653\n* Fix possible memory out-of-bounds accesses #1549\n* Fix memory allocation overflow #1557\n* Prevent chansrv input channels being scanned during a server reset #1595\n* Ignore TS_MULTIFRAGMENTUPDATE_CAPABILITYSET from client if fp disabled #1593\n* Minor manpage fixes #1611\n\n## Other changes\n* CI error fixes \n* Introduce cppcheck\n\n## Known issues\n* FreeRDP 2.0.0-rc4 or later might not able to connect to xrdp due to\n  xrdp's bad-mannered behaviour, add `+glyph-cache` option to FreeRDP to connect #1266\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n# Release notes for xrdp v0.9.13.1 (2020/06/30)\n\nThis is a security fix release that includes fixes for the following local buffer overflow vulnerability.\n\n* [CVE-2020-4044: Local users can perform a buffer overflow attack against the xrdp-sesman service and then impersonate it](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-4044)\n\nThis update is recommended for all xrdp users.\n\n## Special thanks\n\nThanks to [Ashley Newson](https://github.com/ashleynewson) reporting the vulnerability and reviewing fix.\n\n-----------------------\n\n# Release notes for xrdp v0.9.13 (2020/03/11)\n\nThis release is an intermediate bugfix release. The previous version v0.9.12 has some regressions on drive redirection.\n\n## Bug fixes (drive redirection related)\n* Fix chansrv crashes with segmentation fault (regression in #1449) #1487\n* Drive redirection now supports Guacamole client #1505 #1507\n* Prevent a coredump in the event of a corrupted file system #1507\n* Resolve double-free in `chansrv_fuse` #1469\n\n## Bug fixes (other)\n* Fix the issue `xrdp --version | less` will show empty output #1471 #1472\n* Fix some warnings found by cppcheck #1479 #1481 #1484 #1485\n\n## Other changes\n* Add FreeBSD CI test #1466\n* Move Microsoft-defined constants into separate includes #1470\n* Perform cppcheck during CI test #1493\n* Support mousex button 8/9 #1478\n\n## Known issues\n* FreeRDP 2.0.0-rc4 or later might not able to connect to xrdp due to\n  xrdp's bad-mannered behaviour, add `+glyph-cache` option to FreeRDP to connect #1266\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n-----------------------\n\n# Release notes for xrdp v0.9.12 (2019/12/28)\n\n## Bug fixes\n* Fix \"The log reference is NULL\" error when sesman startup #1425\n* Fix behavior when shmem_id changes #1439\n* Make vsock config accept -1 for cid and port #1441\n* Cleanup refresh rect and check stream bounds #1437\n* Significant improvements in drive redirection #1449\n* Fix build on macOS Catalina #1462\n\n## Other changes\n* Proprietary microphone redirection via rdpsnd is now default off\n  RDP compatible microphone redirection is on instead #1427\n* Skip connecting to chansrv when no channels enabled #1393\n* Add openSUSE's pam rules #1442\n* Do not terminate xrdp daemon when caught SIGHUP #1319\n\n## Known issues\n* FreeRDP 2.0.0-rc4 or later might not able to connect to xrdp due to\n  xrdp's bad-mannered behaviour, add `+glyph-cache` option to FreeRDP to connect #1266\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n# Release notes for xrdp v0.9.11 (2019/08/19)\n\n## New features\n* Suppress output (do not draw screen when client window is minimized) #1330\n* Audio input (microphone) redirection compatible with [MS-RDPEAI](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpeai/d04ffa42-5a0f-4f80-abb1-cc26f71c9452) #1369\n* Now xrdp can listen on more than one port #1124 #1366\n\n## Bug fixes\n* Fix the issue audio redirection sometimes sounds with long delay  #1363\n* Check term event for more responsive shutdown #1372\n\n## Known issues\n* FreeRDP 2.0.0-rc4 or later might not able to connect to xrdp due to\n  xrdp's bad-mannered behaviour, add `+glyph-cache` option to FreeRDP to connect #1266\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n-----------------------\n\n# Release notes for xrdp v0.9.11 (2019/08/19)\n\n## New features\n* Suppress output (do not draw screen when client window is minimized) #1330\n* Audio input (microphone) redirection compatible with [MS-RDPEAI](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpeai/d04ffa42-5a0f-4f80-abb1-cc26f71c9452) #1369\n* Now xrdp can listen on more than one port #1124 #1366\n\n## Bug fixes\n* Fix the issue audio redirection sometimes sounds with long delay  #1363\n* Check term event for more responsive shutdown #1372\n\n## Known issues\n* FreeRDP 2.0.0-rc4 or later might not able to connect to xrdp due to\n  xrdp's bad-mannered behaviour, add `+glyph-cache` option to FreeRDP to connect #1266\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n-----------------------\n\n# Release notes for xrdp v0.9.10 (2019/04/18)\n\n## Special thanks\nThank you for matt335672 contributing to lots of improvements in drive redirection!\n\n## New features\n* Restrict outbound (server->client) clipboard transfer, configured in `sesman.ini` #1298\n\n## Bug fixes\n* Fix the issue libscp v1 not setting width but height twice #1293\n* Fix the issue reconnecting to session causes duplicate drive entries in fuse fs #1299\n* Fix default_wm and reconnect_sh refer wrong path after sesman caught SIGUP #1315 #1331\n* Shutdown xrdp more responsively #1325\n* Improve remote file lookup in drive redirection #996 #1327\n* Overwriting & appending to existing files is are now supported #1327\n\n## Other changes\n* Add Danish Keyboard #1290\n* Put xrdp- prefix to some executables appear in man page #1313\n* Replace some URLs from SF.net to xrdp.org #1313\n\n## Known issues\n* FreeRDP 2.0.0-rc4 or later might not able to connect to xrdp due to\n  xrdp's bad-mannered behaviour, add `+glyph-cache` option to FreeRDP to connect #1266\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n-----------------------\n\n# Release notes for xrdp v0.9.9 (2018/12/25)\n\n## Release cycle\nFrom the next release, release cycle will be changed from quarterly to every\n4 months. xrdp will be released in April, August, December.\n\n## New features\n* Disconnection by idle timeout (requires xorgxrdp v0.2.9 or later) #1227\n* Glyph cache v2 (fixes no font issue on iOS/macOS/Android client) #367 #1235\n\n## Bug fixes\n* Fix xrdp-chansrv crashes caused in drive redirection #1202 #1225\n* Fix build with FDK AAC v2 #1257\n* Do not enable RemoteApp if the INFO_RAIL flag is not set (RDP-RDP proxy) #1253\n\n## Other changes\n* Add Spanish Latin Amarican keyboard #1237 #1240 #1244\n* Dynamic channel improvements #1222 #1224\n* Remove some deprecated sesman session types #1232\n* Refactoring and cleanups\n\n## Known issues\n* FreeRDP 2.0.0-rc4 or later might not able to connect to xrdp due to\n  xrdp's bad-mannered behaviour, add `+glyph-cache` option to FreeRDP to connect #1266\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n-----------------------\n\n# Release notes for xrdp v0.9.8 (2018/09/25)\n\n## Deprecation notice\nWe removed TLSv1 and TLSv1.1 from the default config. The current default is TLSv1.2\nand TLSv1.3. Users can whenever re-enable these early TLS versions by editing xrdp.\nTo use TLSv1.3, OpenSSL or LibreSSL must support TLSv1.3. You can know the OpenSSL\nor LibreSSL version by `xrdp --version` command that compiled with xrdp.\n\n## Other topics\n\nPulseaudio modules has been removed from xrdp source tree since it is actually\nindependent and not part of xrdp. The repository has been moved to:\nhttps://github.com/neutrinolabs/pulseaudio-module-xrdp\n\nIf you want to use audio redirection, make sure install the module separately.\n\n## New features\n* Add TLSv1.3 support #1193\n\n## Bug fixes\n* Ensure unmount redirected drive on fatal X error #1140\n\n## Other changes\n* Show more helpful message if xrdp-dis failed #1206\n* Pass pulse socket name via environment variable #1198\n* Fix xrdp's log path in man page #1168\n\n# Release notes for xrdp v0.9.7 (2018/06/29)\n\n## Deprecation notice\nx11rdp has been removed from xrdp reposiory and stored in the separate repository.\nCheckout [x11rdp repository](https://github.com/neutrionlabs/x11rdp) if you still need x11rdp.\nIn most cases, [xorgxrdp](https://github.com/neutrinolabs/xorgxrdp) can replace x11rdp.\n\n## Bug fixes\n* Fix endianness detection on ppc64el #1082\n* Fix a bug xrdp file copy slow #1112 #1132\n* Copy the PAM session environment for the reconnect script #1120\n* Accept fullpath for DefaultWindowManager, ReconnectScript #1147\n\n## Other changes\n* Add PAM support for Arch Linux #1078\n* Show OpenSSL version to '--version' CLI option #1096\n* Separate x11rdp from xrdp repository #1104\n* Support sesrun start xorgxrdp sessions #1108\n* Show configure summary when configure is done #1126 #1134 #1137\n* Less spit on the console when sesman starts #1142\n* Fix memory leaks #1146\n* Separate rc script for FreeBSD into xrdp and xrdp-sesman #1153\n* Improve documents and helps\n\n## Known issues\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n-----------------------\n\n# Release notes for xrdp v0.9.6 (2018/03/26)\n\n## Compatibility notice\nExclamation mark (`!`) has been removed from comment out symbol of config files.\nUse number sign (`#`) or semicolon (`;`) instead. As a result of this change, now\nyou can use exclamation mark as config value such as in `tls_ciphers`.\n\n```\ntls_ciphers=HIGH:!aNULL:!eNULL:!EXPORT:!RC4\n```\n\nSee also: #1033\n\n## macOS supports\nPlease note that xrdp still doesn't support macOS officially so far.\nHowever, a volunteer is working on macOS compatibility.\n\n* Generate dylibs for macOS #1015\n* Add PAM support for macOS #1021\n\n## Bug fixes\n* Make listen check before daemon fork #988\n* Fix xrdp sometimes become zombie processes #1000\n* Include hostname in sesman password file name #1006 #1007 #1076\n* Fix default startwm.sh to use bash explicitly #1009 #1049\n* Fix the issue FreeBSD doesn't acknowledge terminated sessions #1016 #1030\n\n## Other changes\n* Add Swiss French keyboard #1053\n* Improve perfect forward secrecy, explicitly enable ECDHE/DHE #1024 #1052 #1063\n* Lots of leak fixes, cleanups and refactoring\n\n## Known issues\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n-----------------------\n\n# Release notes for xrdp v0.9.5 (2017/12/27)\n\n## Security fixes\n* Fix local denial of service [CVE-2017-16927](http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-16927) #958 #979\n\n## New features\n* Add a new log level TRACE more verbose than DEBUG #835 #944\n* SSH agent forwarding via RDP #867 #868 FreeRDP/FreeRDP#4122\n* Support horizontal wheel properly #928\n\n## Bug fixes\n\n* Avoid use of hard-coded sesman port #895\n* Workaround for corrupted display with Windows Server 2008 using NeutrinoRDP #869\n* Fix glitch in audio redirection by AAC #910 #936\n* Implement vsock support #930 #935 #948\n* Avoid 100% CPU usage on SSL accept #956\n\n## Other changes\n* Add US Dvorak keyboard #929\n* Suppress some misleading logs #964\n* Add Finnish keyboard #972\n* Add more user-friendlier description about Xorg config #974\n* Renew pulseaudio document #984 #985\n* Lots of cleanups and refactoring\n\n## Known issues\n* Audio redirection by MP3 codec doesn't sound with some client, use AAC instead #965\n\n-----------------------\n\n# Release notes for xrdp v0.9.4 (2017/09/28)\n\n## New features\n  * Accept prefill credentials in base64 form #153 #811\n  * Indroduce AAC encoder to audio redirection (requires Windows 10 client)\n\n## Bugfixes\n  * Fix ocasional SEGV in drive redirection #838\n  * Fix client's IP addresses in xrdp-sesman.log are always logged as `0.0.0.0` #878 #882\n  * Fix `ls_background_image` didn't accept full path #776 #853\n  * Fix misuse of hidelogwindow #414 #876\n  * Fix WTSVirtualChannelWrite return code #859\n  * Fix no longer needed socket files remained in the socket dir #812 #831\n  * Make creating socket path a bit more robust #823\n\n## Other changes\n  * Add Belgian keyboard #858\n  * Add a PAM file for FreeBSD #824\n  * Several refactorings and cosmetic changes\n\n## Known issues\n  * Windows 10 (1703) shows black blank screen in RemoteFX mode\n   * This issue is already fixed at Insider Preview build 16273\n\n-----------------------\n\n# Release notes for xrdp v0.9.3.1 (2017/08/16)\n\nThis release fixes a trivial packaging issue #848 occurred in v0.9.3.  The issue only affects systemd systems.  This release is principally for distro packagers or users who compile & install xrdp from source.\n\nUsers who running xrdp on these systems don't need to upgrade from v0.9.3 to v0.9.3.1.\n\n* Linux systems without systemd\n* non-Linux systems such as BSD operating systems\n\n-----------------------\n\n# Release notes for xrdp v0.9.3 (2017/07/15)\n\n## New features\n  * Log user-friendly messages when certificate/privkey is inaccessible\n\n## Bugfixes\n  * Now sesman sets mandatory LOGNAME environment variable #725\n  * Now sesman ensures socket directory present #801\n  * Exit with failure status if port already in use #644\n  * Eliminate some hard coded paths\n  * Fix glitches with IPv4 struct initialization #803\n  * Fix some keyboard layout integration (UK, Spanish)\n  * Fix handle OS when IPv6 disabled #714\n  * Fix issues around systemd session #778\n  * Fix protocol error when 32 bit color and non RemoteFX session #737 #804\n  * Fix sesadmin shows error when no sessions #797\n  * Fix TLS spins 100% CPU #728\n  * Fix Xvnc backend disconnects when some data copied to clipboard #755\n  * Pick up the first section if given section(domain) doesn't match anything #750\n\n## Other changes\n  * Change xrdp-chansrv log path to include display number\n  * Optimize startwm.sh for SUSE\n  * Several cleanups and optimizations\n\n## Known issues\n  * Windows 10 (1703) shows black blank screen in RemoteFX mode\n\n-----------------------\n\n# Release notes for xrdp v0.9.2 (2017/03/30)\n## New features\n  * RemoteFX codec support is now enabled by default.\n  * Bitmap updates support is now enabled by default.\n  * TLS ciphers suites and version is now logged.\n  * Connected computer name is now logged.\n  * Switched to Xorg (xorgxrdp) as the default backend now.\n  * Miscellaneous RemoteFX codec mode improvements.\n  * Socket directory is configurable at the compile time.\n\n## Bugfixes\n  * Parallels client for MacOS / iOS can now connect (audio redirection must be disabled on client or xrdp server though).\n  * MS RDP client for iOS can now connect using TLS security layer.\n  * MS RDP client for Android can now connect to xrdp.\n  * Large resolutions (4K) can be used with RemoteFX graphics.\n  * Multiple RemoteApps can be opened throguh NeutrinoRDP proxy.\n  * tls_ciphers in xrdp.ini is not limited to 63 chars anymore, it's variable-length.\n  * Fixed an issue where tls_ciphers were ignored and rdp security layer could be used instead.\n  * Kill disconnected sessions feature is working with Xorg (xorgxrdp) backend.\n  * Miscellaneous code cleanup and memory issues fixes.\n\n-----------------------\n\n# Release notes for xrdp v0.9.1 (2016/12/21)\n## New features\n  * New xorgxrdp backend using existing Xorg with additional modules\n  * Improvements to X11rdp backend\n  * Support for IPv6 (disabled by default)\n  * Initial support for RemoteFX Codec (disabled by default)\n  * Support for TLS security layer (preferred over RDP layer if supported by the client)\n  * Support for disabling deprecated SSLv3 protocol and for selecting custom cipher suites in xrdp.ini\n  * Support for bidirectional fastpath (enabled in both directions by default)\n  * Support clients that don't support drawing orders, such as MS RDP client for Android, ChromeRDP (disabled by default)\n  * More configurable login screen\n  * Support for new virtual channels:\n      * rdpdr: device redirection\n      * rdpsnd: audio output\n      * cliprdr: clipboard\n      * xrdpvr: xrdp video redirection channel (can be used along with NeutrinoRDP client)\n  * Support for disabling virtual channels globally or by session type\n  * Allow to specify the path for backends (Xorg, X11rdp, Xvnc)\n  * Added files for systemd support\n  * Multi-monitor support\n  * xrdp-chansrv stroes logs in `${XDG_DATA_HOME}/xrdp` now\n\n## Security fixes\n  * User's password could be recovered from the Xvnc password file\n  * X11 authentication was not used\n"
  },
  {
    "path": "README.md",
    "content": "[![Build Status](https://github.com/neutrinolabs/xrdp/actions/workflows/build.yml/badge.svg)](https://github.com/neutrinolabs/xrdp/actions)\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/neutrinolabs/xrdp-questions)\n![Apache-License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)\n\n[![Latest Version](https://img.shields.io/github/v/release/neutrinolabs/xrdp.svg?label=Latest%20Version)](https://github.com/neutrinolabs/xrdp/releases)\n\n# xrdp - an open source RDP server\n\n## Overview\n\n**xrdp** provides a graphical login to remote machines using Microsoft\nRemote Desktop Protocol (RDP). xrdp accepts connections from a variety of RDP clients:\n  * FreeRDP\n  * rdesktop\n  * KRDC\n  * NeutrinoRDP\n  * Windows MSTSC (Microsoft Terminal Services Client, aka `mstsc.exe`)\n  * Microsoft Remote Desktop (found on Microsoft Store, which is distinct from MSTSC)\n\nMany of these work on some or all of Windows, Mac OS, iOS, and/or Android.\n\nRDP transport is encrypted using TLS by default.\n\n![demo](https://github.com/neutrinolabs/xrdp/raw/gh-pages/xrdp_demo.gif)\n\n## Features\n\n### Remote Desktop Access\n\n * Connect to a Linux desktop using RDP from anywhere (requires\n   [xorgxrdp](https://github.com/neutrinolabs/xorgxrdp) Xorg module)\n * Reconnect to an existing session\n * Session resizing (both on-connect and on-the-fly)\n * RDP/VNC proxy (connect to another RDP/VNC server via xrdp)\n\n### Access to Remote Resources\n * Two-way clipboard transfer (text, bitmap, file)\n * Audio redirection ([requires to build additional modules](https://github.com/neutrinolabs/xrdp/wiki/How-to-set-up-audio-redirection))\n * Microphone redirection ([requires to build additional modules](https://github.com/neutrinolabs/xrdp/wiki/How-to-set-up-audio-redirection))\n * Drive redirection (mount local client drives on remote machine)\n\n## Supported Platforms\n\n**xrdp** primarily targets GNU/Linux operating system. x86 (including x86-64)\nand ARM processors are most mature architecture to run xrdp on.\nSee also [Platform Support Tier](https://github.com/neutrinolabs/xrdp/wiki/Platform-Support-Tier).\n\nSome components such as xorgxrdp and RemoteFX codec have special optimization\nfor x86 using SIMD instructions. So running xrdp on x86 processors will get\nfully accelerated experience.\n\n## Quick Start\n\nMost Linux distributions should distribute the latest release of xrdp in their\nrepository. You would need xrdp and xorgxrdp packages for the best\nexperience. It is recommended that xrdp depends on xorgxrdp, so it should\nbe sufficient to install xrdp. If xorgxrdp is not provided, use Xvnc\nserver.\n\nxrdp listens on 3389/tcp. Make sure your firewall accepts connection to\n3389/tcp from where you want to access.\n\n### Ubuntu / Debian\n```bash\napt install xrdp\n```\n\n### Fedora, RHEL and derivatives\n\nIf you're not running Fedora, make sure to enable EPEL packages first.\n\n```bash\ndnf install epel-release\n```\n\n(All systems) Install xrdp with:-\n\n```bash\ndnf install xrdp\n```\n\n## Compiling\n\nSee also https://github.com/neutrinolabs/xrdp/wiki#building-from-sources\n\n### Prerequisites\n\nTo compile xrdp from the packaged sources, you need basic build tools - a\ncompiler (**gcc** or **clang**) and the **make** program.  Additionally,\nyou would need **openssl-devel**, **pam-devel**, **libX11-devel**,\n**libXfixes-devel**, **libXrandr-devel**. More additional software would\nbe needed depending on your configuration.\n\nTo compile xrdp from a checked out git repository, you would additionally\nneed **autoconf**, **automake**, **libtool** and **pkg-config**.\n\n### Get the source and build it\n\nIf compiling from the packaged source, unpack the tarball and change to the\nresulting directory.\n\nIf compiling from a checked out repository, please make sure you've got the submodules\ncloned too (use `git clone --recursive https://github.com/neutrinolabs/xrdp`)\n\nThen run following commands to compile and install xrdp:\n```bash\n./bootstrap\n./configure\nmake\nsudo make install\n```\n\nIf you want to use audio redirection, you need to build and install additional\npulseaudio modules. The build instructions can be found at wiki.\n\n* [How to set up audio redirection](https://github.com/neutrinolabs/xrdp/wiki/How-to-set-up-audio-redirection)\n\n## Directory Structure\n\n```\nxrdp\n├── common ······ common code\n├── docs ········ documentation\n├── fontutils ··· font handling utilities\n├── genkeymap ··· keymap generator\n├── instfiles ··· installable data file\n├── keygen ······ xrdp RSA key pair generator\n├── libpainter ·· painter library\n├── librfxcodec · RFX codec library\n├── libxrdp ····· core RDP protocol implementation\n├── m4 ·········· Autoconf macros\n├── mc ·········· media center module\n├── neutrinordp · RDP client module for proxying RDP connections using NeutrinoRDP\n├── pkgconfig ··· pkg-config configuration\n├── scripts ····· build scripts\n├┬─ sesman ······ session manager for xrdp\n|├── chansrv ···· channel server for xrdp\n|├── libsesman ·· Code common to sesman and its related executables\n|└── tools ······ session management tools for sys admins\n├── tests ······· tests for the code\n├┬─ tools ······· tools\n|└┬─ devel ······ development tools\n| ├── gtcp_proxy  GTK app that forwards TCP connections to a remote host\n| └── tcp_proxy · CLI app that forwards TCP connections to a remote host\n├── vnc ········· VNC client module for xrdp\n├── vrplayer ···· QT player redirecting video/audio to clients over xrdpvr channel\n├── xrdp ········ main server code\n├── xrdpapi ····· virtual channel API\n├── xrdpvr ······ API for playing media over RDP\n└── xup ········· xorgxrdp client module\n```\n"
  },
  {
    "path": "SECURITY.md",
    "content": "# Security Policy\n\n## Reporting a Vulnerability\n\nPlease DO NOT report any security issues to public GitHub issue.\n\nIf you find a security vulnerability please kindly inform us via [Report Form](https://github.com/neutrinolabs/xrdp/security/advisories/new) so that we can fix the security problem to protect a lot of users around the world as soon as possible.\n\nIf you have anything else you want to report privately to developers, send us an email to the following email address. This is a private mailing list not open for public viewing.\n\n* [xrdp-core@googlegroups.com](mailto:xrdp-core@googlegroups.com)\n\n"
  },
  {
    "path": "astyle_config.as",
    "content": "\n# detached brackets\n--style=allman\n\n# 4 spaces, no tabs\n--indent=spaces=4\n\n# for C++ files only\n--indent-classes\n\n# Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block.\n# The entire case block is indented.\n--indent-switches\n\n# Add extra indentation to namespace blocks. This option has no effect on Java files.\n--indent-namespaces\n\n# Converts tabs into spaces in the non-indentation part of the line.\n--convert-tabs\n\n# requires --convert-tabs to work properly\n--indent-preproc-define\n\n--indent-col1-comments\n\n--min-conditional-indent=2\n\n--max-continuation-indent=40\n\n# Insert space padding around operators.\n--pad-oper\n\n# Insert space padding after paren headers only (e.g. 'if', 'for', 'while'...).\n--pad-header\n\n\n# Add brackets to unbracketed one line conditional statements (e.g. 'if', 'for', 'while'...).\n--add-braces\n\n--align-pointer=name\n\n# Do not retain a backup of the original file. The original file is purged after it is formatted.\n--suffix=none\n\n# For each directory in the command line, process all subdirectories recursively.\n--recursive\n\n# Exclude git submodule directories and generated files.\n--exclude=libpainter\n--exclude=librfxcodec\n--exclude=xrdp_configure_options.h\n\n# ignore errors from generated files that do not exist\n--ignore-exclude-errors\n\n# Preserve the original file's date and time modified.\n--preserve-date\n\n# Formatted files display mode. Display only the files that have been formatted.\n# Do not display files that are unchanged.\n--formatted\n\n--lineend=linux\n"
  },
  {
    "path": "bootstrap",
    "content": "#!/bin/sh\n\ncommand -v autoconf\nif ! test $? -eq 0\nthen\n  echo \"error, install autoconf\"\n  exit 1\nfi\n\ncommand -v automake\nif ! test $? -eq 0\nthen\n  echo \"error, install automake\"\n  exit 1\nfi\n\ncommand -v libtool || command -v libtoolize\nif ! test $? -eq 0\nthen\n  echo \"error, install libtool\"\n  exit 1\nfi\n\ncommand -v pkg-config\nif ! test $? -eq 0\nthen\n  echo \"error, install pkg-config\"\n  exit 1\nfi\n\nif ! test -f libpainter/configure.ac\nthen\n  git submodule update --init libpainter\nfi\n\nif ! test -f librfxcodec/configure.ac\nthen\n  git submodule update --init librfxcodec\nfi\n\nif ! test -f ulalaca/Makefile.am\nthen\n  git submodule update --init ulalaca\nfi\n\nautoreconf -fvi\n"
  },
  {
    "path": "coding_style.md",
    "content": "XRdp Coding Style\n=================\n\nThe coding style used by XRdp is described below.\n\nThe XRdp project uses astyle (artistic style) to format the code. Astyle\nrequires a configuration file that describes how you want your code\nformatted. This file is present in the XRdp root directory and is named\n`astyle_config.as`.\n\nHere is how we run the astyle command:\n\n    astyle --options=/path/to/file/astyle_config.as \"*.c\"\n\nThis coding style is a work in progress and is still evolving.\n\n\nLanguage Standard\n-----------------\n\nTry to make all code compile with both C and C++ compiler. C++ is more\nstrict, which makes the code safer.\n\n\nIndentation\n-----------\n\n* 4 spaces per indent\n* No tabs for any indents\n\n☞\n\n    if (fd < 0)\n    {\n        return -1;\n    }\n\n\nLine wrapping\n-------------\n\n* Keep lines not longer than 80 chars\n* Align wrapped argument to the first argument\n\n☞\n\n    log_message(\"connection aborted: error %d\",\n                ret);\n\n\nVariable names\n--------------\n\n* Use lowercase with underscores as needed\n* Don't use camelCase\n* Preprocessor constants should be uppercase\n\n☞\n\n    #define BUF_SIZE 1024\n    int fd;\n    int bytes_in_stream;\n\n\nVariable declaration\n--------------------\n\n* Each variable is declared on a separate line\n\n☞\n\n    int i;\n    int j;\n\n\nWhitespace\n----------\n\n* Use blank lines to group statements\n* Use at most one empty line between statements\n* For pointers and references, use a single space before * or & but not after\n* Use one space after a cast\n* No space before square brackets\n\n☞\n\n    char *cptr;\n    int *iptr;\n    cptr = (char *) malloc(1024);\n\n    write(fd, &buf[12], 16);\n\n\nFunction declarations\n---------------------\n\n* Use newline before function name\n\n☞\n\n    static int\n    value_ok(int val)\n    {\n        return (val >= 0);\n    }\n\n\nBraces\n------\n\n* Opening brace is always on a separate line\n* Align braces with the line preceding the opening brace\n\n☞\n\n    struct stream\n    {\n        int flags;\n        char *data;\n    };\n\n    void\n    process_data(struct stream *s)\n    {\n        if (stream == NULL)\n        {\n            return;\n        }\n    }\n\n\n`if` statements\n---------------\n\n* Always use braces\n* Put both braces on separate lines\n\n☞\n\n    if (val <= 0xff)\n    {\n        out_uint8(s, val);\n    }\n    else if (val <= 0xffff)\n    {\n        out_uint16_le(s, val);\n    }\n    else\n    {\n        out_uint32_le(s, val);\n    }\n\n\n`for` statements\n----------------\n\n* Always use braces\n* Put both braces on separate lines\n\n☞\n\n    for (i = 0; i < 10; i++)\n    {\n        printf(\"i = %d\\n\", i);\n    }\n\n\n`while` and `do while` statements\n---------------------------------\n\n* Always use braces\n* `while` after the closing brace is on the same line\n\n☞\n\n    while (cptr)\n    {\n        cptr—;\n    }\n\n    do\n    {\n        cptr--;\n    } while (cptr);\n\n\n`switch` statements\n-------------------\n\n* Indent `case` once\n* Indent statements under `case` one more time\n* Put both braces on separate lines\n\n☞\n\n    switch (cmd)\n    {\n        case READ:\n            read(fd, buf, 1024);\n            break;\n\n        default:\n            printf(\"bad cmd\\n\");\n    }\n\nComments\n--------\n\nUse /* */ for comments\nDon't use //\n"
  },
  {
    "path": "common/Makefile.am",
    "content": "if XRDP_PIXMAN\n  PIXMAN_SOURCES =\nelse\n  PIXMAN_SOURCES = pixman-region16.c pixman-region.h\nendif\n\nEXTRA_DIST = pixman-region.c\n\ninclude_HEADERS = \\\n  ms-erref.h \\\n  ms-fscc.h \\\n  ms-rdpbcgr.h \\\n  ms-rdpeclip.h \\\n  ms-rdpefs.h \\\n  ms-rdpegdi.h \\\n  ms-rdpele.h \\\n  ms-rdperp.h \\\n  ms-rdpedisp.h \\\n  ms-smb2.h \\\n  xup_client_info.h \\\n  xrdp_client_info.h \\\n  xrdp_constants.h \\\n  xrdp_rail.h \\\n  xrdp_scancode_defs.h \\\n  xrdp_sockets.h\n\nAM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -DXRDP_LOG_PATH=\\\"${localstatedir}/log\\\"\n\nif XRDP_NVENC\nAM_CPPFLAGS += -DXRDP_NVENC\nendif\n\n# -no-suppress is an automake-specific flag which is needed\n# to prevent us missing compiler errors in some circumstances\n# (see https://github.com/neutrinolabs/xrdp/pull/1843 )\nAM_CFLAGS = -no-suppress $(OPENSSL_CFLAGS)\n\nmodule_LTLIBRARIES = \\\n  libcommon.la\n\nlibcommon_la_SOURCES = \\\n  arch.h \\\n  base64.h \\\n  base64.c \\\n  channel_defs.h \\\n  defines.h \\\n  fifo.c \\\n  fifo.h \\\n  file.c \\\n  file.h \\\n  guid.c \\\n  guid.h \\\n  list.c \\\n  list.h \\\n  list16.c \\\n  list16.h \\\n  log.c \\\n  log.h \\\n  os_calls.c \\\n  os_calls.h \\\n  parse.c \\\n  parse.h \\\n  rail.h \\\n  scancode.c \\\n  scancode.h \\\n  set_int.c \\\n  set_int.h \\\n  ssl_calls.c \\\n  ssl_calls.h \\\n  string_calls.c \\\n  string_calls.h \\\n  thread_calls.c \\\n  thread_calls.h \\\n  timers.c \\\n  timers.h \\\n  trans.c \\\n  trans.h \\\n  unicode_defines.h \\\n  $(PIXMAN_SOURCES)\n\nlibcommon_la_LIBADD = \\\n  -lpthread \\\n  $(OPENSSL_LIBS) \\\n  $(DLOPEN_LIBS)\n"
  },
  {
    "path": "common/arch.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(ARCH_H)\n#define ARCH_H\n\n#include <stdlib.h>\n#include <string.h>\n\n#if defined(HAVE_STDINT_H)\n#include <stdint.h>\n#else\ntypedef signed char int8_t;\ntypedef unsigned char uint8_t;\ntypedef signed short int16_t;\ntypedef unsigned short uint16_t;\ntypedef signed int int32_t;\ntypedef unsigned int uint32_t;\n#if defined(_WIN64)\ntypedef signed __int64 int64_t;\ntypedef unsigned __int64 uint64_t;\ntypedef signed __int64 intptr_t;\ntypedef unsigned __int64 uintptr_t;\n#else\ntypedef signed long long int64_t;\ntypedef unsigned long long uint64_t;\ntypedef signed long intptr_t;\ntypedef unsigned long uintptr_t;\n#endif\n#endif\n\ntypedef int bool_t;\n\n// Define Unicode character types\n#if defined(HAVE_UCHAR_H)\n#include <uchar.h>\n#elif defined (__APPLE__) && defined(__cplusplus)\n// char16_t and char32_t are in stdint.h (C++ only)\n#elif defined(HAVE_STDINT_H)\ntypedef uint_least16_t char16_t;\ntypedef uint_least32_t char32_t;\n#else\ntypedef uint16_t char16_t;\ntypedef uint32_t char32_t;\n#endif\n\n/* you can define L_ENDIAN or B_ENDIAN and NEED_ALIGN or NO_NEED_ALIGN\n   in the makefile to override */\n\n/* check endianness */\n#if !(defined(L_ENDIAN) || defined(B_ENDIAN))\n#if !defined(__BYTE_ORDER) && defined(__linux__)\n#include <endian.h>\n#endif\n\n#if defined(BYTE_ORDER)\n#if BYTE_ORDER == BIG_ENDIAN\n#define B_ENDIAN\n#else\n#define L_ENDIAN\n#endif\n#endif\n\n#if !(defined(L_ENDIAN) || defined(B_ENDIAN))\n#if defined(__sparc__) || \\\n    defined(__s390__) || defined (__s390x__) || \\\n    defined(__hppa__) || defined (__m68k__) || \\\n    (defined(__PPC__) && defined(__BIG_ENDIAN__)) || \\\n    (defined(__ppc__) && defined(__BIG_ENDIAN__))\n#define B_ENDIAN\n#else\n#define L_ENDIAN\n#endif\n#endif\n#endif\n\n/* check if we need to align data */\n#if !(defined(NEED_ALIGN) || defined(NO_NEED_ALIGN))\n#if defined(__sparc__) || defined(__alpha__) || defined(__hppa__) || \\\n    defined(__AIX__) || defined(__m68k__) || defined(__mips__) || \\\n    defined(__ia64__) || defined(__arm__) || defined(__sh__) || \\\n    (defined(__PPC__) && defined(__BIG_ENDIAN__)) || \\\n    (defined(__ppc__) && defined(__BIG_ENDIAN__)) || \\\n    defined(__loongarch__) || defined(__e2k__)\n#define NEED_ALIGN\n#elif defined(__x86__) || defined(__x86_64__) || \\\n      defined(__AMD64__) || defined(_M_IX86) || defined (_M_AMD64) || \\\n      defined(__i386__) || defined(__aarch64__) || \\\n      defined(__PPC__) || defined(__LITTLE_ENDIAN__) || \\\n      defined(__s390__) || defined (__s390x__) || \\\n      defined(__riscv)\n#define NO_NEED_ALIGN\n#else\n#warning unknown arch\n#endif\n#endif\n\n/* defines for thread creation factory functions */\n#if defined(_WIN32)\n#define THREAD_RV unsigned long\n#define THREAD_CC __stdcall\n#else\n#define THREAD_RV void*\n#define THREAD_CC\n#endif\n\n#if defined(_WIN32)\n#if defined(__BORLANDC__)\n#define EXPORT_CC _export __cdecl\n#else\n#define EXPORT_CC\n#endif\n#else\n#define EXPORT_CC\n#endif\n\n#ifndef DEFINED_Ts\n#define DEFINED_Ts\ntypedef int8_t ti8;\ntypedef uint8_t tui8;\ntypedef int8_t tsi8;\ntypedef int16_t ti16;\ntypedef uint16_t tui16;\ntypedef int16_t tsi16;\ntypedef int32_t ti32;\ntypedef uint32_t tui32;\ntypedef int32_t tsi32;\ntypedef int64_t ti64;\ntypedef uint64_t tui64;\ntypedef int64_t tsi64;\ntypedef bool_t tbool;\ntypedef intptr_t tbus;\ntypedef intptr_t tintptr;\n\n/* socket */\n#if defined(_WIN32)\ntypedef unsigned int tsock;\n#else\ntypedef int tsock;\n#endif\n#endif /* DEFINED_Ts */\n\n/* format string verification */\n#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)\n#define printflike(arg_format, arg_first_check) \\\n    __attribute__((__format__(__printf__, arg_format, arg_first_check)))\n#else\n#define printflike(arg_format, arg_first_check)\n#endif\n\n/* module interface */\n#ifdef __cplusplus\nextern \"C\" {\n#endif\ntintptr mod_init(void);\nint mod_exit(tintptr);\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "common/base64.c",
    "content": "/**\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file    common/base64.c\n * @brief   Base64 encoder / decoder\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"string_calls.h\"\n\n#include \"base64.h\"\n\n/*\n * Values for invalid and padding characters, used in the charmap\n * for converting base64 to binary\n *\n * These values are specially chosen to make it easy to detect padding or\n * invalid characters by or-ing together the values looked up in\n * a base64 quantum */\n#define E_INVALID 0x40\n#define E_PAD 0x80\n\n/* Determine the character set on this platform */\n#if ('a' == 0x61 && 'z' == 0x7a ) && \\\n    ('A' == 0x41 && 'Z' == 0x5a ) && \\\n    ('0' == 0x30 && '9' == 0x39 )\n# define PLATFORM_IS_ASCII 1\n#else\n#   error \"Unrecognised character set on this platform\"\n#endif /* character set check */\n\n\n/*\n * Define a table to map the base64 character values to bit values.\n */\n#ifdef PLATFORM_IS_ASCII\n#define CHARMAP_BASE 0x28\n#define E_IV E_INVALID  /* For table alignment */\nconst unsigned char charmap[] =\n{\n    /* 0x28 */ E_IV, E_IV, E_IV, 0x3e, E_IV, E_IV, E_IV, 0x3f,\n    /* 0x30 */ 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n    /* 0x38 */ 0x3c, 0x3d, E_IV, E_IV, E_IV, E_PAD, E_IV, E_IV,\n    /* 0x40 */ E_IV, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,\n    /* 0x48 */ 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,\n    /* 0x50 */ 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n    /* 0x58 */ 0x17, 0x18, 0x19, E_IV, E_IV, E_IV, E_IV, E_IV,\n    /* 0x60 */ E_IV, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,\n    /* 0x68 */ 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,\n    /* 0x70 */ 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,\n    /* 0x78 */ 0x31, 0x32, 0x33\n};\n#undef E_IV\n#endif /* PLATFORM_IS_ASCII */\n\n\n/**\n * Lookup a value in the charmap\n *\n * @param x - byte to lookup. Only referenced once so can safely have\n *            side effects.\n * @param dest - destination to assign result to.\n */\n#define CM_LOOKUP(x,dest) \\\n    { \\\n        unsigned int t = (unsigned int)(x) - CHARMAP_BASE;\\\n        dest = (t < sizeof(charmap)) ? charmap[t] : E_INVALID; \\\n    }\n\n/*****************************************************************************/\n\nint\nbase64_decode(const char *src, char *dst, size_t dst_len, size_t *actual_len)\n{\n    *actual_len = 0;\n    size_t src_len;\n    size_t src_i = 0;\n    size_t dst_i = 0;\n    unsigned int a;  /* Four characters of base64 quantum */\n    unsigned int b;\n    unsigned int c;\n    unsigned int d;\n    unsigned int v;\n\n#define OUTPUT_CHAR(x) \\\n    { \\\n        if (dst_i < dst_len) \\\n        { \\\n            dst[dst_i] = (x);\\\n        } \\\n        ++dst_i; \\\n    }\n\n    src_len = g_strlen(src);\n\n    while (src_i < src_len)\n    {\n        if ((src_len - src_i) >= 4)\n        {\n            /* Usual case  - full quantum */\n            CM_LOOKUP(src[src_i++], a);\n            CM_LOOKUP(src[src_i++], b);\n            CM_LOOKUP(src[src_i++], c);\n            CM_LOOKUP(src[src_i++], d);\n        }\n        else\n        {\n            /* Add padding on the end to make up the full quantum */\n            CM_LOOKUP(src[src_i++], a);\n            b = E_PAD;\n            c = E_PAD;\n            d = E_PAD;\n            if ((src_len - src_i) > 0)\n            {\n                CM_LOOKUP(src[src_i++], b);\n            }\n            if ((src_len - src_i) > 0)\n            {\n                CM_LOOKUP(src[src_i++], c);\n            }\n        }\n\n        /*\n         * Bitwise-or the translated quantum values together, so that\n         * any invalid or padding characters can be detected with a\n         * single test */\n        v = a | b | c | d;\n\n        if ((v & E_INVALID) != 0)\n        {\n            return -1;  /* At least one invalid character */\n        }\n\n        if ((v & E_PAD) == 0)\n        {\n            /* No padding - a full quantum */\n            v = (a << 18) | (b << 12) | (c << 6) | d;\n            OUTPUT_CHAR(v >> 16);\n            OUTPUT_CHAR((v >> 8) & 0xff);\n            OUTPUT_CHAR(v & 0xff);\n        }\n        else if (((a | b | c) & E_PAD) == 0)\n        {\n            /* No padding in the first 3 chars, so the padding must\n             * be at the end */\n            v = (a << 10) | (b << 4) | (c >> 2);\n            OUTPUT_CHAR(v >> 8);\n            OUTPUT_CHAR(v & 0xff);\n        }\n        else if (((a | b) & E_PAD) == 0 && c == d)\n        {\n            /* No padding in first two chars, so if the last two chars are\n             * equal, they must both be padding */\n            v = (a << 2) | (b >> 4);\n            OUTPUT_CHAR(v);\n        }\n        else\n        {\n            /* Illegal padding */\n            return -1;\n        }\n    }\n\n    *actual_len = dst_i;\n    return 0;\n\n#undef OUTPUT_CHAR\n}\n\n/*****************************************************************************/\nsize_t\nbase64_encode(const char *src, size_t src_len, char *dst, size_t dst_len)\n{\n    char *p = dst;\n    size_t src_i = 0;\n    size_t max_src_len;\n    unsigned int v;\n    static const char *b64chr =\n        \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n        \"abcdefghijklmnopqrstuvwxyz\"\n        \"0123456789+/=\";\n\n    /* Each three octets of the source results in four bytes at the output,\n     * plus we need a terminator. So we can work out the maximum number of\n     * source octets we can process */\n    if (dst_len == 0)\n    {\n        max_src_len = 0;\n    }\n    else\n    {\n        max_src_len = (dst_len - 1) / 4 * 3;\n    }\n\n    if (src_len > max_src_len)\n    {\n        src_len = max_src_len;\n    }\n\n    while (src_i < src_len)\n    {\n        switch (src_len - src_i)\n        {\n            case 1:\n                v = (unsigned int)(unsigned char)src[src_i++] << 4;\n                *p++ = b64chr[v >> 6];\n                *p++ = b64chr[v & 0x3f];\n                *p++ = b64chr[64];\n                *p++ = b64chr[64];\n                break;\n\n            case 2:\n                v = (unsigned int)(unsigned char)src[src_i++] << 10;\n                v |= (unsigned int)(unsigned char)src[src_i++] << 2;\n                *p++ = b64chr[v >> 12];\n                *p++ = b64chr[(v >> 6) & 0x3f];\n                *p++ = b64chr[v & 0x3f];\n                *p++ = b64chr[64];\n                break;\n\n            default:\n                v = (unsigned int)(unsigned char)src[src_i++] << 16;\n                v |= (unsigned int)(unsigned char)src[src_i++] << 8;\n                v |= (unsigned int)(unsigned char)src[src_i++];\n                *p++ = b64chr[v >> 18];\n                *p++ = b64chr[(v >> 12) & 0x3f];\n                *p++ = b64chr[(v >> 6) & 0x3f];\n                *p++ = b64chr[v & 0x3f];\n                break;\n        }\n    }\n\n    *p = '\\0';\n\n    return src_len;\n}\n"
  },
  {
    "path": "common/base64.h",
    "content": "/**\n * Copyright (C) 2021 Koichiro Iwao, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    common/base64.h\n * @brief   Base64 encoder / decoder\n *\n * Base-64 is described in RFC4648. The following notes apply to this\n * implementation:-\n * - The only supported characters are [A-Za-z0-9+/=]. At present,\n *   embedded linefeeds and URL encodings are not supported.\n *\n */\n\n#if !defined(BASE64_CALLS_H)\n#define BASE64_CALLS_H\n\n#include \"arch.h\"\n\n/*\n * Decodes a base64 string\n *\n * @param src Pointer to null-terminated source\n * @param dst Pointer to output buffer\n * @param dst_len Length of above. No more than this is written to the\n *                output buffer\n * @param actual_len Pointer to value to receive actual length of decoded data\n * @return 0 for success, 1 for an invalid input string\n *\n * The following notes apply to this implementation:-\n * - Embedded padding is supported, provided it only occurs at the end\n *   of a quantum as described in RFC4648(4). This allows concatenated\n *   encodings to be fed into the decoder.\n * - Padding of the last quantum is assumed if not provided.\n * - Excess padding of the last quantum is ignored.\n *\n * Only dst_len bytes at most are written to the output. The length\n * returned in actual_len however represents how much buffer is needed for\n * a correct result. This may be more than dst_len, and enables the caller\n * to detect a potential buffer overflow\n */\nint\nbase64_decode(const char *src, char *dst, size_t dst_len, size_t *actual_len);\n\n/*\n * Encodes a buffer as base64\n *\n * @param src Pointer to source\n * @param src_len Length of above.\n * @param dst Pointer to output buffer for null-terminated string\n * @param dst_len Length of above. No more than this is written to the\n *                output buffer\n * @return Number of source characters processed\n *\n * The following notes apply to this implementation:-\n * - Padding of the last quantum is always written if the number of\n *   source bytes is not divisible by 3.\n *\n * The number of source characters processed is always returned. If\n * the destination buffer is too small for all the output plus a\n * terminator, the returned value from this procedure will be less than\n * src_len. In this case no padding characters will have been written,\n * and the remaining characters can be converted with more calls to\n * this procedure.\n */\nsize_t\nbase64_encode(const char *src, size_t src_len, char *dst, size_t dst_len);\n\n#endif /* BASE64_CALLS_H */\n"
  },
  {
    "path": "common/channel_defs.h",
    "content": "/**\n * Copyright (C) 2024 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    common/channel_defs.h\n * @brief   Private xrdp channel definitions\n */\n\n#if !defined(CHANNEL_DEFS_H)\n#define CHANNEL_DEFS_H\n\n#include <stdint.h>\n\n/**\n * Channel IDs assigned to xrdp private channels. These are chosen to avoid conflicts with\n * channel IDs returned by other servers.\n */\nenum\n{\n    CHAN_ID_XRDP_BASE = (('x' << 24) | ('r' << 16) | ('d' << 8) | 'p'),\n    CHAN_ID_XRDP_SESSION_INFO = CHAN_ID_XRDP_BASE,\n    // Add further IDs here\n    CHAN_ID_XRDP_MAX\n};\n\n// Max length of a DVC name. This is taken from the specification of\n// WTSVirtualChannelOpenEx() which limits the length of a virtual channel\n// to Windows MAX_PATH\n#define MAX_DVC_NAME_LEN 260\n\n/**\n * Information to connect to a channel using xrdpapi\n */\n#define XRDPAPI_CONNECT_PDU_LEN 384 // Connect PDU is always this length\n#define XRDPAPI_CONNECT_PDU_VERSION 1 // Current connnect PDU version\n\nstruct xrdp_chan_connect\n{\n    uint32_t version;\n    uint32_t private_chan; // 0 for a standard channel\n    uint32_t flags;\n    char name[MAX_DVC_NAME_LEN + 1]; // null-terminated\n};\n\n// Events received on the CHAN_ID_XRDP_SESSION_INFO channel\n\n// Update on all the session state data held by chansrv\n//\n// If more information is needed to be exported by xrdpapi, it can be\n// added to this event\nstruct xrdp_chan_session_state\n{\n    uint32_t is_connected; // Is the session connected?\n};\n\n#endif /* CHANNEL_DEFS_H */\n"
  },
  {
    "path": "common/defines.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * main define/macro file\n */\n\n#ifndef DEFINES_H\n#define DEFINES_H\n\n/* other macros */\n#undef MIN\n#define MIN(x1, x2) ((x1) < (x2) ? (x1) : (x2))\n#undef MAX\n#define MAX(x1, x2) ((x1) > (x2) ? (x1) : (x2))\n#undef HIWORD\n#define HIWORD(in) (((in) & 0xffff0000) >> 16)\n#undef LOWORD\n#define LOWORD(in) ((in) & 0x0000ffff)\n#undef MAKELONG\n#define MAKELONG(lo, hi) ((((hi) & 0xffff) << 16) | ((lo) & 0xffff))\n#define UNUSED_VAR(x) ((void) (x))\n\n/* graphics macros */\n#define MAKERECT(r, x, y, cx, cy) \\\n    { (r).left = x; (r).top = y; (r).right = (x) + (cx); (r).bottom = (y) + (cy); }\n#define ISRECTEMPTY(r) (((r).right <= (r).left) || ((r).bottom <= (r).top))\n#define RECTOFFSET(r, dx, dy) \\\n    { (r).left += dx; (r).top += dy; (r).right += dx; (r).bottom += dy; }\n#define GETPIXEL8(d, x, y, w) (*(((unsigned char*)d) + ((y) * (w) + (x))))\n#define GETPIXEL16(d, x, y, w) (*(((unsigned short*)d) + ((y) * (w) + (x))))\n#define GETPIXEL32(d, x, y, w) (*(((unsigned int*)d) + ((y) * (w) + (x))))\n#define SETPIXEL8(d, x, y, w, v) \\\n    (*(((unsigned char*)d) + ((y) * (w) + (x))) = (v))\n#define SETPIXEL16(d, x, y, w, v) \\\n    (*(((unsigned short*)d) + ((y) * (w) + (x))) = (v))\n#define SETPIXEL32(d, x, y, w, v) \\\n    (*(((unsigned int*)d) + ((y) * (w) + (x))) = (v))\n#define COLOR8(r, g, b) \\\n    ( \\\n      (((r) >> 5) << 0) | \\\n      (((g) >> 5) << 3) | \\\n      (((b) >> 6) << 6) \\\n    )\n#define COLOR15(r, g, b) ((((r) >> 3) << 10) | (((g) >> 3) << 5) | ((b) >> 3))\n#define COLOR16(r, g, b) ((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3))\n#define COLOR24RGB(r, g, b) (((r) << 16) | ((g) << 8) | (b))\n#define COLOR24BGR(r, g, b) (((b) << 16) | ((g) << 8) | (r))\n#define HRED(c) ((c & 0xff0000) >> 16)\n#define HGREEN(c) ((c & 0x00ff00) >> 8)\n#define HBLUE(c) ((c & 0x0000ff))\n#define HCOLOR(bpp,c) \\\n    ( \\\n      (bpp==8?COLOR8(HRED(c),HGREEN(c),HBLUE(c)): \\\n       (bpp==15?COLOR15(HRED(c),HGREEN(c),HBLUE(c)): \\\n        (bpp==16?COLOR16(HRED(c),HGREEN(c),HBLUE(c)): \\\n         (bpp>=24?COLOR24BGR(HRED(c),HGREEN(c),HBLUE(c)):c) \\\n        ) \\\n       ) \\\n      ) \\\n    )\n#define SPLITCOLOR15(r, g, b, c) \\\n    { \\\n        r = (((c) >> 7) & 0xf8) | (((c) >> 12) & 0x7); \\\n        g = (((c) >> 2) & 0xf8) | (((c) >>  8) & 0x7); \\\n        b = (((c) << 3) & 0xf8) | (((c) >>  2) & 0x7); \\\n    }\n#define SPLITCOLOR16(r, g, b, c) \\\n    { \\\n        r = (((c) >> 8) & 0xf8) | (((c) >> 13) & 0x7); \\\n        g = (((c) >> 3) & 0xfc) | (((c) >>  9) & 0x3); \\\n        b = (((c) << 3) & 0xf8) | (((c) >>  2) & 0x7); \\\n    }\n#define SPLITCOLOR32(r, g, b, c) \\\n    { \\\n        r = ((c) >> 16) & 0xff; \\\n        g = ((c) >> 8) & 0xff; \\\n        b = (c) & 0xff; \\\n    }\n/* font macros */\n#define FONT_DATASIZE_FROM_GEOMETRY(width,height) \\\n    ((((height) * (((width) + 7) / 8)) + 3) & ~3)\n#define FONT_DATASIZE(f) FONT_DATASIZE_FROM_GEOMETRY((f->width), (f->height))\n\n/* use crc for bitmap cache lookups */\n#define USE_CRC\n\n#define XR_RGB2BGR(a_ulColor) \\\n    (a_ulColor & 0xFF000000) | \\\n    ((a_ulColor & 0x00FF0000) >> 16) | \\\n    (a_ulColor & 0x0000FF00) |  \\\n    ((a_ulColor & 0x000000FF) << 16)\n\n#endif\n"
  },
  {
    "path": "common/fifo.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Matt Burt 2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    common/fifo.c\n * @brief   Fifo for storing generic pointers\n *\n * Defines an unbounded FIFO-queue for void * pointers\n *\n * The stored pointers are called 'items' below.\n *\n * Items are stored in groups called 'chunks'. Chunks are linked together\n * in a chain:-\n *\n * +-------------+    +--------+    +--------+    +--------+\n * | first_chunk |--->|  next  |--->|  next  |--->|  NULL  |<-+\n * | last_chunk  |-+  +--------+    +--------+    +--------+  |\n * | . . .       | |  | item.0 |    | item.0 |    | item.0 |  |\n * +-------------+ |  |   ...  |    |   ...  |    |   ...  |  |\n *                 |  | item.n |    | item.n |    | item.n |  |\n *                 |  +--------+    +--------+    +--------+  |\n *                 |                                          |\n *                 +------------------------------------------+\n *\n * This allows items to be added to the FIFO by allocating blocks\n * as each one fills up.\n *\n * The code to read from the FIFO de-allocates blocks as each one is\n * consumed.\n *\n * There is always at least one chunk in the FIFO.\n */\n\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n\n#include \"fifo.h\"\n\n#define ITEMS_PER_CHUNK 31\n\nstruct chunk\n{\n    struct chunk *next;\n    void *items[ITEMS_PER_CHUNK];\n};\n\nstruct fifo\n{\n    struct chunk *first_chunk;\n    struct chunk *last_chunk;\n    /** Next address to write in 'last_chunk' */\n    unsigned short writer;\n    /** Next address to read in 'first_chunk' */\n    unsigned short reader;\n    /** Item destructor function, or NULL */\n    fifo_item_destructor item_destructor;\n};\n\n/*****************************************************************************/\n\nstruct fifo *\nfifo_create(fifo_item_destructor item_destructor)\n{\n    struct fifo *result = NULL;\n    struct chunk *cptr = (struct chunk *)malloc(sizeof(struct chunk));\n    if (cptr != NULL)\n    {\n        /* 'next' pointer in last block is always NULL */\n        cptr->next = NULL;\n        result = (struct fifo *)malloc(sizeof(struct fifo));\n        if (result == NULL)\n        {\n            free(cptr);\n        }\n        else\n        {\n            result->first_chunk = cptr;\n            result->last_chunk = cptr;\n            result->writer = 0;\n            result->reader = 0;\n            result->item_destructor = item_destructor;\n        }\n    }\n    return result;\n}\n\n/*****************************************************************************/\n/**\n * Internal function to call the destructor function on all items in the fifo\n *\n * @param self fifo. Can't be NULL\n * @param closure Additional argument to destructor function\n */\nstatic void\ncall_item_destructor(struct fifo *self, void *closure)\n{\n    if (self->item_destructor != NULL)\n    {\n        struct chunk *cptr = self->first_chunk;\n        unsigned int i = self->reader;\n\n        // Process all the chunks up to the last one\n        while (cptr != self->last_chunk)\n        {\n            (*self->item_destructor)(cptr->items[i++], closure);\n            if (i == ITEMS_PER_CHUNK)\n            {\n                cptr = cptr->next;\n                i = 0;\n            }\n        }\n\n        // Process all the items in the last chunk\n        while (i < self->writer)\n        {\n            (*self->item_destructor)(cptr->items[i++], closure);\n        }\n    }\n}\n\n\n/*****************************************************************************/\nvoid\nfifo_delete(struct fifo *self, void *closure)\n{\n    if (self != NULL)\n    {\n        call_item_destructor(self, closure);\n\n        // Now free all the chunks\n        struct chunk *cptr = self->first_chunk;\n        while (cptr != NULL)\n        {\n            struct chunk *next = cptr->next;\n            free(cptr);\n            cptr = next;\n        }\n\n        free(self);\n    }\n}\n\n\n/*****************************************************************************/\nvoid\nfifo_clear(struct fifo *self, void *closure)\n{\n    if (self != NULL)\n    {\n        call_item_destructor(self, closure);\n\n        // Now free all the chunks except the last one\n        struct chunk *cptr = self->first_chunk;\n        while (cptr->next != NULL)\n        {\n            struct chunk *next = cptr->next;\n            free(cptr);\n            cptr = next;\n        }\n\n        // Re-initialise fifo fields\n        self->first_chunk = cptr;\n        self->last_chunk = cptr;\n        self->reader = 0;\n        self->writer = 0;\n    }\n}\n\n/*****************************************************************************/\nint\nfifo_add_item(struct fifo *self, void *item)\n{\n    int rv = 0;\n    if (self != NULL && item != NULL)\n    {\n        if (self->writer == ITEMS_PER_CHUNK)\n        {\n            // Add another chunk to the chain\n            struct chunk *cptr;\n            cptr = (struct chunk *)malloc(sizeof(struct chunk));\n            if (cptr == NULL)\n            {\n                return 0;\n            }\n            cptr->next = NULL;\n            self->last_chunk->next = cptr;\n            self->last_chunk = cptr;\n            self->writer = 0;\n        }\n\n        self->last_chunk->items[self->writer++] = item;\n        rv = 1;\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nvoid *\nfifo_remove_item(struct fifo *self)\n{\n    void *item = NULL;\n    if (self != NULL)\n    {\n        // More than one chunk in the fifo?\n        if (self->first_chunk != self->last_chunk)\n        {\n            /* We're not reading the last chunk. There\n             * must be something in the fifo */\n            item = self->first_chunk->items[self->reader++];\n\n            /* At the end of this chunk? */\n            if (self->reader == ITEMS_PER_CHUNK)\n            {\n                struct chunk *old_chunk = self->first_chunk;\n                self->first_chunk = old_chunk->next;\n                free(old_chunk);\n                self->reader = 0;\n            }\n        }\n        else if (self->reader < self->writer)\n        {\n            /* We're reading the last chunk */\n            item = self->first_chunk->items[self->reader++];\n            if (self->reader == self->writer)\n            {\n                // fifo is now empty. We can reset the pointers\n                // to prevent unnecessary allocations in the future.\n                self->reader = 0;\n                self->writer = 0;\n            }\n        }\n    }\n    return item;\n}\n\n/*****************************************************************************/\n\nint\nfifo_is_empty(struct fifo *self)\n{\n    return (self == NULL ||\n            (self->first_chunk == self->last_chunk &&\n             self->reader == self->writer));\n}\n"
  },
  {
    "path": "common/fifo.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    common/fifo.h\n * @brief   Fifo for storing generic pointers\n *\n * Declares an unbounded FIFO-queue for void * pointers\n */\n\n#ifndef _FIFO_H\n#define _FIFO_H\n\nstruct fifo;\n\n/**\n * Function used by fifo_clear()/fifo_delete() to destroy items\n *\n * @param item Item being deleted\n * @param closure Additional argument to function\n *\n * Use this function to free any allocated storage (e.g. if the items\n * are dynamically allocated)\n */\ntypedef void (*fifo_item_destructor)(void *item, void *closure);\n\n/**\n * Create new fifo\n *\n * @param item_destructor Destructor for fifo items, or NULL for none\n * @return fifo, or NULL if no memory\n */\nstruct fifo *\nfifo_create(fifo_item_destructor item_destructor);\n\n/**\n * Delete an existing fifo\n *\n * Any existing entries on the fifo are passed in order to the\n * item destructor specified when the fifo was created.\n *\n * @param self fifo to delete (may be NULL)\n * @param closure Additional parameter for fifo item destructor\n */\nvoid\nfifo_delete(struct fifo *self, void *closure);\n\n/**\n * Clear(empty) an existing fifo\n *\n * Any existing entries on the fifo are passed in order to the\n * item destructor specified when the fifo was created.\n *\n * @param self fifo to clear (may be NULL)\n * @param closure Additional parameter for fifo item destructor\n */\nvoid\nfifo_clear(struct fifo *self, void *closure);\n\n/** Add an item to a fifo\n * @param self fifo\n * @param item Item to add\n * @return 1 if successful, 0 for no memory, or tried to add NULL\n */\nint\nfifo_add_item(struct fifo *self, void *item);\n\n/** Remove an item from a fifo\n * @param self fifo\n * @return item if successful, NULL for no items in FIFO\n */\nvoid *\nfifo_remove_item(struct fifo *self);\n\n/** Is fifo empty?\n *\n * @param self fifo\n * @return 1 if fifo is empty, 0 if not\n */\nint\nfifo_is_empty(struct fifo *self);\n\n#endif\n"
  },
  {
    "path": "common/file.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * read a config file\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"list.h\"\n#include \"file.h\"\n#include \"parse.h\"\n\n#define FILE_MAX_LINE_BYTES 2048\n\nstatic int\nfile_read_ini_line(struct stream *s, char *text, int text_bytes);\n\n/*****************************************************************************/\n/* look up for a section name within str (i.e. pattern [section_name])\n * if a section name is found, this function return 1 and copy the section\n * inplace of str. */\nstatic int\nline_lookup_for_section_name(char *str, int str_bytes)\n{\n    int name_index_start;\n    int index;\n    char c;\n\n    name_index_start = -1;\n    index = 0;\n    while ((c = str[index]) != 0)\n    {\n        if (c == '[')\n        {\n            name_index_start = index + 1;\n        }\n        else if (c == ']' && name_index_start > 0)\n        {\n            if (name_index_start + index >= str_bytes)\n            {\n                return 0;\n            }\n            for (index = index - name_index_start; index > 0; index--)\n            {\n                str[0] = str[name_index_start];\n                str++;\n            }\n            str[0] = 0;\n            return 1;\n        }\n        ++index;\n    }\n    return 0;\n}\n\n\n/*****************************************************************************/\n/* returns error\n   returns 0 if everything is ok\n   returns 1 if problem reading file */\nstatic int\nl_file_read_sections(int fd, int max_file_size, struct list *names)\n{\n    struct stream *s;\n    char text[FILE_MAX_LINE_BYTES];\n    int len;\n    int rv;\n\n    rv = 0;\n    g_file_seek(fd, 0);\n    g_memset(text, 0, FILE_MAX_LINE_BYTES);\n    list_clear(names);\n    make_stream(s);\n    init_stream(s, max_file_size);\n    len = g_file_read(fd, s->data, max_file_size);\n\n    if (len > 0)\n    {\n        s->end = s->p + len;\n        while (file_read_ini_line(s, text, FILE_MAX_LINE_BYTES) == 0)\n        {\n            if (line_lookup_for_section_name(text, FILE_MAX_LINE_BYTES) != 0)\n            {\n                list_add_strdup(names, text);\n            }\n        }\n    }\n    else if (len < 0)\n    {\n        rv = 1;\n    }\n\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\n/* Read a line in the stream 's', removing comments.\n * returns error\n * returns 0 if everything is ok\n * returns 1 if problem reading file */\nstatic int\nfile_read_ini_line(struct stream *s, char *text, int text_bytes)\n{\n    int i;\n    int skip_to_end;\n    int at_end;\n    char c;\n\n    skip_to_end = 0;\n\n    if (!s_check_rem(s, 1))\n    {\n        return 1;\n    }\n\n    i = 0;\n    in_uint8(s, c);\n\n    while (c != 10 && c != 13)\n    {\n        /* these mean skip the rest of the line */\n        if (c == '#' || c == ';')\n        {\n            skip_to_end = 1;\n        }\n\n        if (!skip_to_end)\n        {\n            text[i] = c;\n            i++;\n            if (i >= text_bytes)\n            {\n                return 1;\n            }\n        }\n\n        if (s_check_rem(s, 1))\n        {\n            in_uint8(s, c);\n        }\n        else\n        {\n            c = 0;\n            break;\n        }\n    }\n\n    if (c == 10 || c == 13)\n    {\n        at_end = 0;\n\n        while (c == 10 || c == 13)\n        {\n            if (s_check_rem(s, 1))\n            {\n                in_uint8(s, c);\n            }\n            else\n            {\n                at_end = 1;\n                break;\n            }\n        }\n\n        if (!at_end)\n        {\n            s->p--;\n        }\n    }\n\n    text[i] = 0;\n\n    return 0;\n}\n\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nfile_split_name_value(char *text, char *name, char *value)\n{\n    int len;\n    int i;\n    int value_index;\n    int name_index;\n    int on_to;\n\n    value_index = 0;\n    name_index = 0;\n    on_to = 0;\n    name[0] = 0;\n    value[0] = 0;\n    len = g_strlen(text);\n\n    for (i = 0; i < len; i++)\n    {\n        if (text[i] == '=' && !on_to)\n        {\n            on_to = 1;\n        }\n        else if (on_to)\n        {\n            value[value_index] = text[i];\n            value_index++;\n            value[value_index] = 0;\n        }\n        else\n        {\n            name[name_index] = text[i];\n            name_index++;\n            name[name_index] = 0;\n        }\n    }\n\n    g_strtrim(name, 3); /* trim both right and left */\n    g_strtrim(value, 3); /* trim both right and left */\n    return 0;\n}\n\n/*****************************************************************************/\n/* return error */\nstatic int\nl_file_read_section(int fd, int max_file_size, const char *section,\n                    struct list *names, struct list *values)\n{\n    struct stream *s;\n    char *data;\n    char *text;\n    char *name;\n    char *value;\n    char *lvalue;\n    int len;\n    int file_size;\n\n    data = (char *) g_malloc(FILE_MAX_LINE_BYTES * 3, 0);\n    text = data;\n    name = text + FILE_MAX_LINE_BYTES;\n    value = name + FILE_MAX_LINE_BYTES;\n\n    file_size = 32 * 1024; /* 32 K file size limit */\n    g_file_seek(fd, 0);\n    g_memset(text, 0, FILE_MAX_LINE_BYTES);\n    list_clear(names);\n    list_clear(values);\n    make_stream(s);\n    init_stream(s, file_size);\n    len = g_file_read(fd, s->data, file_size);\n\n    if (len > 0)\n    {\n        s->end = s->p + len;\n        while (file_read_ini_line(s, text, FILE_MAX_LINE_BYTES) == 0)\n        {\n            if (line_lookup_for_section_name(text, FILE_MAX_LINE_BYTES) != 0)\n            {\n                if (g_strcasecmp(section, text) == 0)\n                {\n                    while (file_read_ini_line(s, text,\n                                              FILE_MAX_LINE_BYTES) == 0)\n                    {\n                        if (line_lookup_for_section_name(text, FILE_MAX_LINE_BYTES) != 0)\n                        {\n                            break;\n                        }\n\n                        if (g_strlen(text) > 0)\n                        {\n                            file_split_name_value(text, name, value);\n                            list_add_strdup(names, name);\n\n                            if (value[0] == '$')\n                            {\n                                lvalue = g_getenv(value + 1);\n\n                                if (lvalue != 0)\n                                {\n                                    list_add_strdup(values, lvalue);\n                                }\n                                else\n                                {\n                                    list_add_strdup(values, \"\");\n                                }\n                            }\n                            else\n                            {\n                                list_add_strdup(values, value);\n                            }\n                        }\n                    }\n                    free_stream(s);\n                    g_free(data);\n                    return 0;\n                }\n            }\n        }\n    }\n\n    free_stream(s);\n    g_free(data);\n    return 1;\n}\n\n/*****************************************************************************/\n/* returns error\n   returns 0 if everything is ok\n   returns 1 if problem reading file */\n/* 32 K file size limit */\nint\nfile_read_sections(int fd, struct list *names)\n{\n    return l_file_read_sections(fd, 32 * 1024, names);\n}\n\n/*****************************************************************************/\n/* return error */\n/* this function should be preferred over file_read_sections because it can\n   read any file size */\nint\nfile_by_name_read_sections(const char *file_name, struct list *names)\n{\n    int fd;\n    int file_size;\n    int rv;\n\n    file_size = g_file_get_size(file_name);\n\n    if (file_size < 1)\n    {\n        return 1;\n    }\n\n    fd = g_file_open_ro(file_name);\n\n    if (fd < 0)\n    {\n        return 1;\n    }\n\n    rv = l_file_read_sections(fd, file_size, names);\n    g_file_close(fd);\n    return rv;\n}\n\n/*****************************************************************************/\n/* return error */\n/* 32 K file size limit */\nint\nfile_read_section(int fd, const char *section,\n                  struct list *names, struct list *values)\n{\n    return l_file_read_section(fd, 32 * 1024, section, names, values);\n}\n\n/*****************************************************************************/\n/* return error */\n/* this function should be preferred over file_read_section because it can\n   read any file size */\nint\nfile_by_name_read_section(const char *file_name, const char *section,\n                          struct list *names, struct list *values)\n{\n    int fd;\n    int file_size;\n    int rv;\n\n    file_size = g_file_get_size(file_name);\n\n    if (file_size < 1)\n    {\n        return 1;\n    }\n\n    fd = g_file_open_ro(file_name);\n\n    if (fd < 0)\n    {\n        return 1;\n    }\n\n    rv = l_file_read_section(fd, file_size, section, names, values);\n    g_file_close(fd);\n    return rv;\n}\n"
  },
  {
    "path": "common/file.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * read a config file\n */\n\n#if !defined(FILE_H)\n#define FILE_H\n\n#include \"arch.h\"\n\nint\nfile_read_sections(int fd, struct list *names);\nint\nfile_by_name_read_sections(const char *file_name, struct list *names);\nint\nfile_read_section(int fd, const char *section,\n                  struct list *names, struct list *values);\nint\nfile_by_name_read_section(const char *file_name, const char *section,\n                          struct list *names, struct list *values);\n\n#endif\n"
  },
  {
    "path": "common/guid.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) 2021 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file common/guid.c\n * @brief GUID manipulation definitions\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"guid.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\nenum\n{\n    /* Field offsets in the UUID */\n    E_CLOCK_SEQ_HI_AND_RESERVED = 8,\n    E_TIME_HI_AND_VERSION_MSB = 7,\n    /* UUID versions from RFC4122 section 4.1.3 */\n    E_UUID_VERSION_RANDOM = 4\n};\n\nstruct guid\nguid_new(void)\n{\n    struct guid guid = {0};\n    g_random(guid.g, sizeof(guid.g));\n    /* Show this UUID as conforming to RFC4122 (section 4.1.1) */\n    guid.g[E_CLOCK_SEQ_HI_AND_RESERVED] &= ~0x40; /* Clear bit 6 */\n    guid.g[E_CLOCK_SEQ_HI_AND_RESERVED] |= (char)0x80; /* Set bit 7 */\n\n    guid.g[E_TIME_HI_AND_VERSION_MSB] &= ~0xf0;\n    guid.g[E_TIME_HI_AND_VERSION_MSB] |= (E_UUID_VERSION_RANDOM << 4);\n\n    return guid;\n}\n\nvoid\nguid_clear(struct guid *guid)\n{\n    g_memset(&guid->g, '\\x00', GUID_SIZE);\n}\n\nint\nguid_is_set(const struct guid *guid)\n{\n    unsigned int i;\n    int rv = 0;\n    if (guid != NULL)\n    {\n        for (i = 0 ; i < GUID_SIZE; ++i)\n        {\n            if (guid->g[i] != '\\x00')\n            {\n                rv = 1;\n                break;\n            }\n        }\n    }\n\n    return rv;\n\n}\n\nconst char *guid_to_str(const struct guid *src, char *dest)\n{\n    const unsigned char *guid = (const unsigned char *)src->g;\n\n    /*\n     * Flipping integers into little-endian\n     * See also: https://devblogs.microsoft.com/oldnewthing/20220928-00/?p=107221\n     */\n    g_sprintf(dest, \"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\",\n              guid[3], guid[2], guid[1], guid[0],\n              guid[5], guid[4],\n              guid[7], guid[6],\n              guid[8], guid[9],\n              guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]);\n\n    return dest;\n}\n"
  },
  {
    "path": "common/guid.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2021\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file common/guid.h\n * @brief GUID manipulation declarations\n  */\n\n#ifndef GUID_H\n#define GUID_H\n\n#include \"arch.h\"\n\n#define GUID_SIZE 16  /* bytes */\n#define GUID_STR_SIZE (GUID_SIZE * 2 + 4 + 1)   /* w/ 4 hyphens + null terminator */\n#define GUID_ARE_EQUAL(g1,g2) (memcmp((g1)->g, (g2)->g, GUID_SIZE) == 0)\n\n/**\n * Use a struct for the guid so we can easily copy by assignment.\n * We use an array of char so that\n * we can compare GUIDs with a straight memcmp()\n *\n * Some fields of the GUID are in little-endian-order as specified by\n * [MS-DTYP]. This is at odds with RFC4122 which specifies big-endian\n * order for all fields.\n *\n * Octets RFC4122 field\n * ------ -------------\n * 0-3    time_low (little-endian)\n * 4-5    time_mid (little-endian)\n * 6-7    time_hi_and_version (little-endian)\n * 8      clock_seq_hi_and_reserved\n * 9      clock_seq_low (in order)\n * 10-15  node\n  */\nstruct guid\n{\n    char g[GUID_SIZE];\n};\n\n/**\n * Get an initialised GUID\n *\n * The GUID is compatible with RFC4122 section 4.4.\n *\n * @return new GUID\n */\nstruct guid guid_new(void);\n\n/**\n * Clears an initialised GUID, so guid_is_set() returns true\n *\n * @param guid GUID to clear\n */\nvoid\nguid_clear(struct guid *guid);\n\n/**\n * Checks if a GUID is initialised\n *\n * @param guid GUID to check (can be NULL)\n * @return non-zero if GUID is set\n */\nint\nguid_is_set(const struct guid *guid);\n\n/**\n * Converts a GUID to a string representation\n *\n * @param guid GUID to represent\n * @param dest destionation pointer to at least GUID_STR_SIZE\n *             bytes to store the representation\n * @return dest is returned for convenience\n */\nconst char *guid_to_str(const struct guid *guid, char *dest);\n\n#endif\n\n"
  },
  {
    "path": "common/list.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * simple list\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n#include <stdarg.h>\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"list.h\"\n#include \"log.h\"\n\nenum\n{\n    DEFAULT_LIST_SIZE = 10,\n    DEFAULT_GROW_BY_SIZE = 10\n};\n\n/******************************************************************************/\nstruct list *\nlist_create_sized(unsigned int size)\n{\n    struct list *self;\n\n    if (size < DEFAULT_LIST_SIZE)\n    {\n        size = DEFAULT_LIST_SIZE;\n    }\n    self = (struct list *)calloc(1, sizeof(struct list));\n    if (self != NULL)\n    {\n        self->items = (tbus *)malloc(sizeof(tbus) * size);\n        if (self->items == NULL)\n        {\n            free(self);\n            self = NULL;\n        }\n        else\n        {\n            self->grow_by = DEFAULT_GROW_BY_SIZE;\n            self->alloc_size = size;\n        }\n    }\n    return self;\n}\n\n/******************************************************************************/\nstruct list *\nlist_create(void)\n{\n    return list_create_sized(DEFAULT_LIST_SIZE);\n}\n\n/******************************************************************************/\nvoid\nlist_delete(struct list *self)\n{\n    int i;\n\n    if (self == 0)\n    {\n        return;\n    }\n\n    if (self->auto_free)\n    {\n        for (i = 0; i < self->count; i++)\n        {\n            free((void *)self->items[i]);\n            self->items[i] = 0;\n        }\n    }\n\n    free(self->items);\n    free(self);\n}\n\n/******************************************************************************/\nstatic int\ngrow_list(struct list *self)\n{\n    int rv = 1;\n    unsigned int new_alloc_size = self->alloc_size + self->grow_by;\n    tbus *p = (tbus *)realloc(self->items, sizeof(tbus) * new_alloc_size);\n    if (p == NULL)\n    {\n        rv = 0;\n    }\n    else\n    {\n        self->alloc_size = new_alloc_size;\n        self->items = p;\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nint\nlist_add_item(struct list *self, tbus item)\n{\n    if (self->count == self->alloc_size && !grow_list(self))\n    {\n        return 0;\n    }\n\n    self->items[self->count] = item;\n    self->count++;\n    return 1;\n}\n\n/******************************************************************************/\ntbus\nlist_get_item(const struct list *self, int index)\n{\n    if (index < 0 || index >= self->count)\n    {\n        return 0;\n    }\n\n    return self->items[index];\n}\n\n/******************************************************************************/\nvoid\nlist_clear(struct list *self)\n{\n    int i;\n\n    if (self->auto_free)\n    {\n        for (i = 0; i < self->count; i++)\n        {\n            free((void *)self->items[i]);\n            self->items[i] = 0;\n        }\n    }\n\n    self->count = 0;\n    self->grow_by = DEFAULT_GROW_BY_SIZE;\n    self->alloc_size = DEFAULT_LIST_SIZE;\n    self->items = (tbus *)realloc(self->items, sizeof(tbus) * self->alloc_size);\n}\n\n/******************************************************************************/\nint\nlist_index_of(struct list *self, tbus item)\n{\n    int i;\n\n    for (i = 0; i < self->count; i++)\n    {\n        if (self->items[i] == item)\n        {\n            return i;\n        }\n    }\n\n    return -1;\n}\n\n/******************************************************************************/\nvoid\nlist_remove_item(struct list *self, int index)\n{\n    int i;\n\n    if (index >= 0 && index < self->count)\n    {\n        if (self->auto_free)\n        {\n            free((void *)self->items[index]);\n            self->items[index] = 0;\n        }\n\n        for (i = index; i < (self->count - 1); i++)\n        {\n            self->items[i] = self->items[i + 1];\n        }\n\n        self->count--;\n    }\n}\n\nint\nlist_insert_item(struct list *self, int index, tbus item)\n{\n    int i;\n\n    if (index > self->count)\n    {\n        index = self->count;\n    }\n    else if (index < 0)\n    {\n        index = 0;\n    }\n\n    if (self->count == self->alloc_size && !grow_list(self))\n    {\n        return 0;\n    }\n\n    // Move all the items above this location up one\n    for (i = self->count ; i > index ; --i)\n    {\n        self->items[i] = self->items[i - 1];\n    }\n\n    self->count++;\n\n    self->items[index] = item;\n    return 1;\n}\n\n\n/******************************************************************************/\nint\nlist_add_strdup(struct list *self, const char *str)\n{\n    int rv;\n    char *dup;\n\n    if (str == NULL)\n    {\n        rv = list_add_item(self, (tintptr)str);\n    }\n    else if ((dup = g_strdup(str)) == NULL)\n    {\n        rv = 0;\n    }\n    else\n    {\n        rv = list_add_item(self, (tintptr)dup);\n        if (!rv)\n        {\n            g_free(dup);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nlist_add_strdup_multi(struct list *self, ...)\n{\n    va_list ap;\n    int entry_count = self->count;\n    const char *s;\n    int rv = 1;\n\n    va_start(ap, self);\n    while ((s = va_arg(ap, const char *)) != LIST_ADD_STRDUP_TERM)\n    {\n        if (!list_add_strdup(self, s))\n        {\n            rv = 0;\n            break;\n        }\n    }\n    va_end(ap);\n\n    if (rv == 0)\n    {\n        // Remove the additional items we added\n        while (self->count > entry_count)\n        {\n            list_remove_item(self, self->count - 1);\n        }\n    }\n\n    return rv;\n}\n/******************************************************************************/\n/* append one list to another using strdup for each item in the list */\n/* begins copy at start_index, a zero based index on the source list */\nint\nlist_append_list_strdup(struct list *self, struct list *dest, int start_index)\n{\n    int index;\n    int rv = 1;\n    int entry_dest_count = dest->count;\n\n    for (index = start_index; index < self->count; index++)\n    {\n        const char *item = (const char *)list_get_item(self, index);\n        if (!list_add_strdup(dest, item))\n        {\n            rv = 0;\n            break;\n        }\n    }\n\n    if (rv == 0)\n    {\n        // Remove the additional items we added\n        while (dest->count > entry_dest_count)\n        {\n            list_remove_item(dest, dest->count - 1);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nvoid\nlist_dump_items(struct list *self)\n{\n    int index;\n\n    if (self->count == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"List is empty\");\n    }\n\n    for (index = 0; index < self->count; index++)\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"%d: %p\", index, (void *) list_get_item(self, index));\n    }\n}\n\nint\nsplit_string_append_fragment(const char **start, const char *end,\n                             struct list *list)\n{\n    unsigned int len = end - *start;\n    // Check for an unexpected terminator in the string\n    const char *term = (const char *)memchr(*start, '\\0', len);\n    if (term != NULL)\n    {\n        end = term;\n        len = end - *start;\n    }\n    char *copy = (char *)malloc(len + 1);\n    if (copy == NULL)\n    {\n        list_delete(list);\n        return 0;\n    }\n    g_memcpy(copy, *start, len);\n    copy[len] = '\\0';\n    if (!list_add_item(list, (tintptr)copy))\n    {\n        g_free(copy);\n        list_delete(list);\n        return 0;\n    }\n    *start = end + 1;\n    return 1;\n}\n\n/******************************************************************************/\nstruct list *\nsplit_string_into_list(const char *str, char character)\n{\n    struct list *result = list_create();\n    if (result == NULL)\n    {\n        return result;\n    }\n    result->auto_free = 1;\n\n    if (str == NULL)\n    {\n        return result;\n    }\n\n    const char *p;\n    while ((p = g_strchr(str, character)) != NULL)\n    {\n        if (!split_string_append_fragment(&str, p, result))\n        {\n            return NULL;\n        }\n    }\n\n    if (*str != '\\0')\n    {\n        if (!split_string_append_fragment(&str, str + g_strlen(str), result))\n        {\n            return NULL;\n        }\n    }\n    return result;\n}\n"
  },
  {
    "path": "common/list.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * simple list\n */\n\n#if !defined(LIST_H)\n#define LIST_H\n\n#include \"arch.h\"\n\n/* list */\nstruct list\n{\n    tintptr *items;\n    int count;\n    int alloc_size;\n    int grow_by;\n    int auto_free;\n};\n\nstruct list *\nlist_create(void);\n/**\n * Creates a list with at least the specified number of items\n * reserved\n * @param size Number of items to reserve\n * @return list, or NULL if no memory\n */\nstruct list *\nlist_create_sized(unsigned int size);\nvoid\nlist_delete(struct list *self);\n/**\n * Adds an item to a list\n * @param self The list\n * @param item The item to add\n * @result 0 if a memory allocation failure occurred. In this\n *         case the item is not added\n *\n * Memory allocation failures will not occur if the list is\n * sized appropriately when created.\n */\nint\nlist_add_item(struct list *self, tintptr item);\ntintptr\nlist_get_item(const struct list *self, int index);\nvoid\nlist_clear(struct list *self);\nint\nlist_index_of(struct list *self, tintptr item);\nvoid\nlist_remove_item(struct list *self, int index);\n/**\n * Inserts an item into a list\n * @param self The list\n * @param index The location to insert the item before\n * @param item The item to add\n * @result 0 if a memory allocation failure occurred. In this\n *         case the item is not added\n *\n * Memory allocation failures will not occur if the list is\n * sized appropriately when created.\n */\nint\nlist_insert_item(struct list *self, int index, tintptr item);\n/**\n * Adds strings to a list from another list\n * @param self The source list\n * @param dest Destination list\n * @param start_index Index to start on the source list (zero based)\n *\n * @result 0 if a memory allocation failure occurred. In this\n *         case the destination list is unaltered.\n *\n * Strings from the source list are copied with strdup()\n * The dest list should have auto_free set, or memory leaks will occur\n */\nint\nlist_append_list_strdup(struct list *self, struct list *dest, int start_index);\nvoid\nlist_dump_items(struct list *self);\n\n/**\n * Appends a string fragment to a list\n * @param[in,out] start Pointer to start of fragment (by reference)\n * @param end Pointer to one past end of fragment\n * @param list List to append to\n * @result 1 for success\n *\n * In the event of a memory failure, 0 is returned and the list is deleted.\n */\nint\nsplit_string_append_fragment(const char **start, const char *end,\n                             struct list *list);\n\n/**\n * Splits a string on a separation character and then returns a list of\n * the string split by the character, without the character contained within\n * the pieces.\n *\n * The list must be disposed of by the caller.\n *\n * @param str String to split.\n * @param character Character used as the delimiter between strings.\n *\n * @result 0 if a memory allocation failure occurred.\n *\n * String fragments in the list are created with strdup()\n */\nstruct list *\nsplit_string_into_list(const char *str, char character);\n\n/**\n * As list_add_item() but for a C string\n *\n * This is a convenience function for a common operation\n * @param self List to append to\n * @param str String to append\n *\n * The passed-in string is strdup'd onto the list, so if auto_free\n * isn't set, memory leaks will occur.\n *\n * A NULL pointer will be added as a NULL entry.\n *\n * @result 0 if any memory allocation failure occurred. In this case\n * the list is unchanged.\n */\n\nint\nlist_add_strdup(struct list *self, const char *str);\n\n/**\n * Add multiple strings to a list\n *\n * This is a convenience function for a common operation\n * @param self List to append to\n * @param ... Strings to append. Terminate the list with LIST_ADD_STRDUP_TERM\n *\n * @result 0 if any memory allocation failure occurred. In this case\n * the list is unchanged.\n */\n\n/*\n * We need a typed terminator to guarantee the stack object is the\n * correct size (cf C99 std 6.2.5(12) for static checkers */\n#define LIST_ADD_STRDUP_TERM ((const char *)0)\nint\nlist_add_strdup_multi(struct list *self, ...);\n\n#endif\n"
  },
  {
    "path": "common/list16.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * simple list\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"list16.h\"\n\n/*****************************************************************************/\nstruct list16 *\nlist16_create(void)\n{\n    struct list16 *self;\n\n    self = (struct list16 *)g_malloc(sizeof(struct list16), 0);\n    list16_init(self);\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nlist16_delete(struct list16 *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n\n    list16_deinit(self);\n    g_free(self);\n}\n\n/*****************************************************************************/\nvoid\nlist16_init(struct list16 *self)\n{\n    g_memset(self, 0, sizeof(struct list16));\n    self->max_count = 4;\n    self->items = self->mitems;\n}\n\n/*****************************************************************************/\nvoid\nlist16_deinit(struct list16 *self)\n{\n    if (self->items != self->mitems)\n    {\n        g_free(self->items);\n        self->items = self->mitems; // Prevent double=free\n    }\n}\n\n/*****************************************************************************/\n/**\n * Makes the data array larger\n *\n * @param self The list\n * @return 1 for success, 0 for failure\n *\n * On failure, the data array is unchanged\n */\nstatic int\nexpand_array(struct list16 *self)\n{\n    tui16 *p;\n    int i;\n    int new_max_count = self->max_count + 4;\n    if (self->items == self->mitems)\n    {\n        /* Previous allocation is static. Make a new dynamic allocation */\n        p = (tui16 *)malloc(sizeof(tui16) * new_max_count);\n        if (p == NULL)\n        {\n            return 0;\n        }\n        g_memcpy(p, self->items, sizeof(tui16) * self->max_count);\n    }\n    else\n    {\n        /* Try to reallocate the existing array */\n        p = (tui16 *)realloc(self->items, sizeof(tui16) * new_max_count);\n        if (p == NULL)\n        {\n            return 0;\n        }\n    }\n\n    /* Clear the new elements */\n    for (i = self->max_count; i < new_max_count; ++i)\n    {\n        p[i] = 0;\n    }\n\n    self->max_count = new_max_count;\n    self->items = p;\n\n    return 1;\n}\n\n/*****************************************************************************/\nint\nlist16_add_item(struct list16 *self, tui16 item)\n{\n    if (self->count >= self->max_count && !expand_array(self))\n    {\n        return 0;\n    }\n\n    self->items[self->count] = item;\n    self->count++;\n    return 1;\n}\n\n/*****************************************************************************/\ntui16\nlist16_get_item(struct list16 *self, int index)\n{\n    if (index < 0 || index >= self->count)\n    {\n        return 0;\n    }\n\n    return self->items[index];\n}\n\n/*****************************************************************************/\nvoid\nlist16_clear(struct list16 *self)\n{\n    if (self->items != self->mitems)\n    {\n        g_free(self->items);\n    }\n    self->count = 0;\n    self->max_count = 4;\n    self->items = self->mitems;\n}\n\n/*****************************************************************************/\nint\nlist16_index_of(struct list16 *self, tui16 item)\n{\n    int i;\n\n    for (i = 0; i < self->count; i++)\n    {\n        if (self->items[i] == item)\n        {\n            return i;\n        }\n    }\n\n    return -1;\n}\n\n/*****************************************************************************/\nvoid\nlist16_remove_item(struct list16 *self, int index)\n{\n    int i;\n\n    if (index >= 0 && index < self->count)\n    {\n        for (i = index; i < (self->count - 1); i++)\n        {\n            self->items[i] = self->items[i + 1];\n        }\n\n        self->count--;\n    }\n}\n\n/*****************************************************************************/\nint\nlist16_insert_item(struct list16 *self, int index, tui16 item)\n{\n    /* Make sure there's at least one free element in the array */\n    if (self->count >= self->max_count && !expand_array(self))\n    {\n        return 0;\n    }\n\n    if (index < self->count)\n    {\n        memmove(&self->items[index + 1], &self->items[index],\n                (self->count - index) * sizeof(tui16));\n    }\n\n    self->items[index] = item;\n    self->count++;\n    return 1;\n}\n"
  },
  {
    "path": "common/list16.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * simple list\n */\n\n#if !defined(LIST16_H)\n#define LIST16_H\n\n#include \"arch.h\"\n\n/* list */\nstruct list16\n{\n    tui16 *items;\n    int count;\n    int max_count;\n    tui16 mitems[4];\n};\n\nstruct list16 *\nlist16_create(void);\nvoid\nlist16_delete(struct list16 *self);\n/* Initialise a stack-based list16 */\nvoid\nlist16_init(struct list16 *self);\n/* Free any memory allocated to a list16.\n * After this call, list16_init() must be called again to re-use the list */\nvoid\nlist16_deinit(struct list16 *self);\n/* Returns != 0 if item added successfully */\nint\nlist16_add_item(struct list16 *self, tui16 item);\ntui16\nlist16_get_item(struct list16 *self, int index);\nvoid\nlist16_clear(struct list16 *self);\nint\nlist16_index_of(struct list16 *self, tui16 item);\nvoid\nlist16_remove_item(struct list16 *self, int index);\n/* Returns != 0 if item added successfully */\nint\nlist16_insert_item(struct list16 *self, int index, tui16 item);\n\n#endif\n"
  },
  {
    "path": "common/log.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <sys/time.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <syslog.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <time.h>\n#include <unistd.h>\n#include \"list.h\"\n#include \"file.h\"\n#include \"os_calls.h\"\n#include \"thread_calls.h\"\n#include \"string_calls.h\"\n\n/* Add a define here so that the log.h will hold more information\n * when compiled from this C file.\n * When compiled normally the log.h file only contain the public parts\n * of the operators in this file. */\n#define LOGINTERNALSTUFF\n#include \"log.h\"\n\n/* Here we store the current state and configuration of the log */\nstatic struct log_config *g_staticLogConfig = NULL;\n\n/* This file first start with all private functions.\n   In the end of the file the public functions is defined */\n\n/**\n *\n * @brief Opens log file\n * @param fname log file name\n * @return see open(2) return values\n *\n */\nstatic int\ninternal_log_file_open(const char *fname)\n{\n    int ret = -1;\n\n    if (fname != NULL)\n    {\n        if (g_strcmp(fname, \"<stdout>\") != 0)\n        {\n            ret = open(fname, O_WRONLY | O_CREAT | O_APPEND | O_SYNC,\n                       S_IRUSR | S_IWUSR);\n        }\n        else\n        {\n            ret = dup(1);\n        }\n    }\n\n    if (ret != -1)\n    {\n        g_file_set_cloexec(ret, 1);\n    }\n\n    return ret;\n}\n\n/**\n *\n * @brief Converts xrdp log level to syslog logging level\n * @param lvl logging level\n * @return syslog equivalent logging level\n *\n */\nstatic int\ninternal_log_xrdp2syslog(const enum logLevels lvl)\n{\n    switch (lvl)\n    {\n        case LOG_LEVEL_ALWAYS:\n            return LOG_CRIT;\n        case LOG_LEVEL_ERROR:\n            return LOG_ERR;\n        case LOG_LEVEL_WARNING:\n            return LOG_WARNING;\n        case LOG_LEVEL_INFO:\n            return LOG_INFO;\n        case LOG_LEVEL_DEBUG:\n        case LOG_LEVEL_TRACE:\n            return LOG_DEBUG;\n        default:\n            g_writeln(\"Undefined log level - programming error\");\n            return LOG_DEBUG;\n    }\n}\n\n/**\n * @brief Converts xrdp log levels to textual logging levels\n * @param lvl logging level\n * @param str pointer to a string, must be allocated before\n *\n */\nvoid\ninternal_log_lvl2str(const enum logLevels lvl, char *str)\n{\n    switch (lvl)\n    {\n        case LOG_LEVEL_ALWAYS:\n            snprintf(str, 9, \"%s\", \"[CORE ] \");\n            break;\n        case LOG_LEVEL_ERROR:\n            snprintf(str, 9, \"%s\", \"[ERROR] \");\n            break;\n        case LOG_LEVEL_WARNING:\n            snprintf(str, 9, \"%s\", \"[WARN ] \");\n            break;\n        case LOG_LEVEL_INFO:\n            snprintf(str, 9, \"%s\", \"[INFO ] \");\n            break;\n        case LOG_LEVEL_DEBUG:\n            snprintf(str, 9, \"%s\", \"[DEBUG] \");\n            break;\n        case LOG_LEVEL_TRACE:\n            snprintf(str, 9, \"%s\", \"[TRACE] \");\n            break;\n        default:\n            snprintf(str, 9, \"%s\", \"PRG ERR!\");\n            g_writeln(\"Programming error - undefined log level!!!\");\n    }\n}\n\n/******************************************************************************/\nenum logReturns\ninternal_log_start(struct log_config *l_cfg)\n{\n    enum logReturns ret = LOG_GENERAL_ERROR;\n\n    if (0 == l_cfg)\n    {\n        ret = LOG_ERROR_MALLOC;\n        return ret;\n    }\n\n    /* if progname is NULL, we return error */\n    if (0 == l_cfg->program_name)\n    {\n        g_writeln(\"program_name not properly assigned\");\n        return ret;\n    }\n\n    if (l_cfg->dump_on_start)\n    {\n        internal_log_config_dump(l_cfg);\n    }\n\n    /* open file */\n    if (l_cfg->log_file != NULL)\n    {\n        l_cfg->fd = internal_log_file_open(l_cfg->log_file);\n\n        if (-1 == l_cfg->fd)\n        {\n            return LOG_ERROR_FILE_OPEN;\n        }\n    }\n\n    /* if syslog is enabled, open it */\n    if (l_cfg->enable_syslog)\n    {\n        openlog(l_cfg->program_name, LOG_CONS | LOG_PID, LOG_DAEMON);\n    }\n\n#ifdef LOG_ENABLE_THREAD\n    pthread_mutexattr_init(&(l_cfg->log_lock_attr));\n    pthread_mutex_init(&(l_cfg->log_lock), &(l_cfg->log_lock_attr));\n#endif\n\n    return LOG_STARTUP_OK;\n}\n\n/******************************************************************************/\nenum logReturns\ninternal_log_end(struct log_config *l_cfg)\n{\n    enum logReturns ret = LOG_GENERAL_ERROR;\n\n    /* if log is closed, quit silently */\n    if (0 == l_cfg)\n    {\n        return ret;\n    }\n\n    if (-1 != l_cfg->fd)\n    {\n        /* closing logfile... */\n        g_file_close(l_cfg->fd);\n    }\n\n    /* if syslog is enabled, close it */\n    if (l_cfg->enable_syslog)\n    {\n        closelog();\n    }\n\n    /* freeing allocated memory */\n    if (0 != l_cfg->log_file)\n    {\n        g_free(l_cfg->log_file);\n        l_cfg->log_file = 0;\n    }\n\n    ret = LOG_STARTUP_OK;\n    return ret;\n}\n\n/**\n * Converts a string representing the log level to a value\n */\nenum logLevels\ninternal_log_text2level(const char *buf)\n{\n    if (0 == g_strcasecmp(buf, \"0\") ||\n            0 == g_strcasecmp(buf, \"core\"))\n    {\n        return LOG_LEVEL_ALWAYS;\n    }\n    else if (0 == g_strcasecmp(buf, \"1\") ||\n             0 == g_strcasecmp(buf, \"error\"))\n    {\n        return LOG_LEVEL_ERROR;\n    }\n    else if (0 == g_strcasecmp(buf, \"2\") ||\n             0 == g_strcasecmp(buf, \"warn\") ||\n             0 == g_strcasecmp(buf, \"warning\"))\n    {\n        return LOG_LEVEL_WARNING;\n    }\n    else if (0 == g_strcasecmp(buf, \"3\") ||\n             0 == g_strcasecmp(buf, \"info\"))\n    {\n        return LOG_LEVEL_INFO;\n    }\n    else if (0 == g_strcasecmp(buf, \"4\") ||\n             0 == g_strcasecmp(buf, \"debug\"))\n    {\n        return LOG_LEVEL_DEBUG;\n    }\n    else if (0 == g_strcasecmp(buf, \"5\") ||\n             0 == g_strcasecmp(buf, \"trace\"))\n    {\n        return LOG_LEVEL_TRACE;\n    }\n\n    g_writeln(\"Your configured log level is corrupt - we use debug log level\");\n    return LOG_LEVEL_DEBUG;\n}\n\n/******************************************************************************/\nstatic struct log_config *\ninternal_config_read_logging(int file,\n                             const char *applicationName,\n                             const char *section_prefix)\n{\n    int i;\n    char *buf;\n    char *temp_buf;\n    char section_name[512];\n    struct log_config *lc;\n    struct list *param_n;\n    struct list *param_v;\n\n    lc = internalInitAndAllocStruct();\n    if (lc == NULL)\n    {\n        return NULL;\n    }\n\n    param_n = list_create();\n    param_n->auto_free = 1;\n    param_v = list_create();\n    param_v->auto_free = 1;\n\n    list_clear(param_v);\n    list_clear(param_n);\n\n    /* setting defaults */\n    lc->program_name = applicationName;\n    lc->log_file = 0;\n    lc->fd = -1;\n    lc->log_level = LOG_LEVEL_INFO;\n    lc->enable_console = 0;\n    lc->console_level = LOG_LEVEL_INFO;\n    lc->enable_syslog = 0;\n    lc->syslog_level = LOG_LEVEL_INFO;\n    lc->dump_on_start = 0;\n    lc->enable_pid = 0;\n\n    g_snprintf(section_name, 511, \"%s%s\", section_prefix, SESMAN_CFG_LOGGING);\n    file_read_section(file, section_name, param_n, param_v);\n\n    for (i = 0; i < param_n->count; i++)\n    {\n        buf = (char *)list_get_item(param_n, i);\n\n        if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_FILE))\n        {\n            lc->log_file = g_strdup((char *)list_get_item(param_v, i));\n\n            if (lc->log_file != NULL)\n            {\n                if (lc->log_file[0] != '/' && g_strcmp(lc->log_file, \"<stdout>\") != 0)\n                {\n                    temp_buf = (char *)g_malloc(512, 0);\n                    g_snprintf(temp_buf, 511, \"%s/%s\", XRDP_LOG_PATH, lc->log_file);\n                    g_free(lc->log_file);\n                    lc->log_file = temp_buf;\n                }\n            }\n        }\n\n        if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_LEVEL))\n        {\n            lc->log_level = internal_log_text2level((char *)list_get_item(param_v, i));\n        }\n\n        if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_ENABLE_SYSLOG))\n        {\n            lc->enable_syslog = g_text2bool((char *)list_get_item(param_v, i));\n        }\n\n        if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_SYSLOG_LEVEL))\n        {\n            lc->syslog_level = internal_log_text2level((char *)list_get_item(param_v, i));\n        }\n\n        if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_ENABLE_CONSOLE))\n        {\n            lc->enable_console = g_text2bool((char *)list_get_item(param_v, i));\n        }\n\n        if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_CONSOLE_LEVEL))\n        {\n            lc->console_level = internal_log_text2level((char *)list_get_item(param_v, i));\n        }\n\n        if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_ENABLE_PID))\n        {\n            lc->enable_pid = g_text2bool((char *)list_get_item(param_v, i));\n        }\n    }\n\n    if (0 == lc->log_file)\n    {\n        lc->log_file = g_strdup(\"./sesman.log\");\n    }\n\n    /* try to create path if not exist */\n    g_create_path(lc->log_file);\n\n#ifdef LOG_PER_LOGGER_LEVEL\n    int len;\n    struct log_logger_level *logger;\n\n    list_clear(param_v);\n    list_clear(param_n);\n    g_snprintf(section_name, 511, \"%s%s\", section_prefix, SESMAN_CFG_LOGGING_LOGGER);\n    file_read_section(file, section_name, param_n, param_v);\n    for (i = 0; i < param_n->count; i++)\n    {\n        logger = (struct log_logger_level *)g_malloc(sizeof(struct log_logger_level), 1);\n        list_add_item(lc->per_logger_level, (tbus) logger);\n        logger->log_level = internal_log_text2level((char *)list_get_item(param_v, i));\n\n        g_strncpy(logger->logger_name, (char *)list_get_item(param_n, i), LOGGER_NAME_SIZE);\n        logger->logger_name[LOGGER_NAME_SIZE] = '\\0';\n        len = g_strlen(logger->logger_name);\n        if (len >= 2\n                && logger->logger_name[len - 2] == '('\n                && logger->logger_name[len - 1] == ')' )\n        {\n            logger->logger_type = LOG_TYPE_FUNCTION;\n            logger->logger_name[len - 2] = '\\0';\n        }\n        else\n        {\n            logger->logger_type = LOG_TYPE_FILE;\n        }\n    }\n#endif\n\n    list_delete(param_v);\n    list_delete(param_n);\n    return lc;\n}\n\nvoid\ninternal_log_config_dump(struct log_config *config)\n{\n    char str_level[20];\n#ifdef LOG_PER_LOGGER_LEVEL\n    struct log_logger_level *logger;\n    int i;\n#endif\n\n    g_printf(\"logging configuration:\\r\\n\");\n    if (config->log_file)\n    {\n        internal_log_lvl2str(config->log_level, str_level);\n        g_printf(\"\\tLogFile:       %s\\r\\n\", config->log_file);\n        g_printf(\"\\tLogLevel:      %s\\r\\n\", str_level);\n    }\n    else\n    {\n        g_printf(\"\\tLogFile:       %s\\r\\n\", \"<disabled>\");\n    }\n\n    if (config->enable_console)\n    {\n        internal_log_lvl2str(config->console_level, str_level);\n    }\n    else\n    {\n        g_strcpy(str_level, \"<disabled>\");\n    }\n    g_printf(\"\\tConsoleLevel:  %s\\r\\n\", str_level);\n\n    if (config->enable_syslog)\n    {\n        internal_log_lvl2str(config->syslog_level, str_level);\n    }\n    else\n    {\n        g_strcpy(str_level, \"<disabled>\");\n    }\n    g_printf(\"\\tSyslogLevel:   %s\\r\\n\", str_level);\n\n#ifdef LOG_PER_LOGGER_LEVEL\n    g_printf(\"per logger configuration:\\r\\n\");\n    for (i = 0; i < config->per_logger_level->count; i++)\n    {\n        logger = (struct log_logger_level *)list_get_item(config->per_logger_level, i);\n        internal_log_lvl2str(logger->log_level, str_level);\n        g_printf(\"\\t%-*s: %s\\r\\n\", LOGGER_NAME_SIZE, logger->logger_name, str_level);\n    }\n    if (config->per_logger_level->count == 0)\n    {\n        g_printf(\"\\tNone\\r\\n\");\n    }\n#endif\n}\n\nstruct log_config *\ninternalInitAndAllocStruct(void)\n{\n    struct log_config *ret = g_new0(struct log_config, 1);\n\n    if (ret != NULL)\n    {\n        ret->fd = -1;\n        ret->enable_syslog = 0;\n#ifdef LOG_PER_LOGGER_LEVEL\n        ret->per_logger_level = list_create();\n        if (ret->per_logger_level != NULL)\n        {\n            ret->per_logger_level->auto_free = 1;\n        }\n        else\n        {\n            g_writeln(\"could not allocate memory for log struct\");\n            g_free(ret);\n            ret = NULL;\n        }\n#endif\n    }\n    else\n    {\n        g_writeln(\"could not allocate memory for log struct\");\n    }\n\n    return ret;\n}\n\n/**\n * Copies logging levels only from one log_config structure to another\n **/\n\nstatic void\ninternal_log_config_copy_levels(struct log_config *dest,\n                                const struct log_config *src)\n{\n    dest->log_level = src->log_level;\n    dest->enable_syslog = src->enable_syslog;\n    dest->syslog_level = src->syslog_level;\n    dest->enable_console = src->enable_console;\n    dest->console_level = src->console_level;\n\n#ifdef LOG_PER_LOGGER_LEVEL\n    if (dest->per_logger_level == NULL)\n    {\n        dest->per_logger_level = list_create();\n        if (dest->per_logger_level == NULL)\n        {\n            return;\n        }\n        dest->per_logger_level->auto_free = 1;\n    }\n    else\n    {\n        list_clear(dest->per_logger_level);\n    }\n\n    if (src->per_logger_level == NULL)\n    {\n        return;\n    }\n\n    int i;\n\n    for (i = 0; i < src->per_logger_level->count; ++i)\n    {\n        struct log_logger_level *dst_logger =\n            (struct log_logger_level *)g_malloc(sizeof(struct log_logger_level), 1);\n\n        *dst_logger = *(struct log_logger_level *) list_get_item(src->per_logger_level, i),\n\n         list_add_item(dest->per_logger_level, (tbus) dst_logger);\n    }\n#endif\n}\n\nstatic void\ninternal_log_config_copy(struct log_config *dest, const struct log_config *src)\n{\n    if (src != NULL && dest != NULL)\n    {\n        dest->fd = src->fd;\n        g_free(dest->log_file);\n        dest->log_file = g_strdup(src->log_file);\n#ifdef LOG_ENABLE_THREAD\n        dest->log_lock = src->log_lock;\n        dest->log_lock_attr = src->log_lock_attr;\n#endif\n        dest->program_name = src->program_name;\n        dest->enable_pid = src->enable_pid;\n        dest->dump_on_start = src->dump_on_start;\n\n        internal_log_config_copy_levels(dest, src);\n    }\n}\n\nbool_t\ninternal_log_is_enabled_for_level(const enum logLevels log_level,\n                                  const bool_t override_destination_level,\n                                  const enum logLevels override_log_level)\n{\n    /* Is log initialized? */\n    if (g_staticLogConfig == NULL)\n    {\n        return 0;\n    }\n    else if (g_staticLogConfig->fd < 0\n             && !g_staticLogConfig->enable_syslog\n             && !g_staticLogConfig->enable_console)\n    {\n        /* all logging outputs are disabled */\n        return 0;\n    }\n    else if (override_destination_level)\n    {\n        /* Override is enabled - should the message should be logged? */\n        return log_level <= override_log_level;\n    }\n    /* Override is disabled - Is there at least one log destination\n     * which will accept the message based on the log level? */\n    else if (g_staticLogConfig->fd >= 0\n             && log_level <= g_staticLogConfig->log_level)\n    {\n        return 1;\n    }\n    else if (g_staticLogConfig->enable_syslog\n             && log_level <= g_staticLogConfig->syslog_level)\n    {\n        return 1;\n    }\n    else if (g_staticLogConfig->enable_console\n             && log_level <= g_staticLogConfig->console_level)\n    {\n        return 1;\n    }\n    else\n    {\n        return 0;\n    }\n}\n\nbool_t\ninternal_log_location_overrides_level(const char *function_name,\n                                      const char *file_name,\n                                      enum logLevels *log_level_return)\n{\n#ifdef LOG_PER_LOGGER_LEVEL\n    struct log_logger_level *logger = NULL;\n    int i;\n\n    if (g_staticLogConfig == NULL)\n    {\n        return 0;\n    }\n    for (i = 0; i < g_staticLogConfig->per_logger_level->count; i++)\n    {\n        logger = (struct log_logger_level *)list_get_item(g_staticLogConfig->per_logger_level, i);\n\n        if ((logger->logger_type == LOG_TYPE_FILE\n                && 0 == g_strncmp(logger->logger_name, file_name, LOGGER_NAME_SIZE))\n                || (logger->logger_type == LOG_TYPE_FUNCTION\n                    && 0 == g_strncmp(logger->logger_name, function_name, LOGGER_NAME_SIZE)))\n        {\n            *log_level_return = logger->log_level;\n            return 1;\n        }\n    }\n#endif\n\n    return 0;\n}\n\n/*\n * Here below the public functions\n */\n\nstruct log_config *\nlog_config_init_for_console(enum logLevels lvl, const char *override_name)\n{\n    struct log_config *config = internalInitAndAllocStruct();\n\n    if (config != NULL)\n    {\n        config->program_name = \"<null>\";\n        config->enable_console = 1;\n        if (override_name != NULL && override_name[0] != '\\0')\n        {\n            config->console_level = internal_log_text2level(override_name);\n        }\n        else\n        {\n            config->console_level = lvl;\n        }\n    }\n    return config;\n}\n\n\nstruct log_config *\nlog_config_init_from_config(const char *iniFilename,\n                            const char *applicationName,\n                            const char *section_prefix)\n{\n    int fd;\n    struct log_config *config;\n\n    if (applicationName == NULL)\n    {\n        g_writeln(\"Programming error your application name cannot be null\");\n        return NULL;\n    }\n\n    if (iniFilename == NULL)\n    {\n        g_writeln(\"The inifile is null to log_config_init_from_config!\");\n        return NULL;\n    }\n\n    fd = g_file_open_ro(iniFilename);\n\n    if (-1 == fd)\n    {\n        g_writeln(\"We could not open the configuration file to read log parameters\");\n        return NULL;\n    }\n\n    /* read logging config */\n    config = internal_config_read_logging(fd, applicationName, section_prefix);\n\n    /* cleanup */\n    g_file_close(fd);\n    return config;\n}\n\nenum logReturns\nlog_config_free(struct log_config *config)\n{\n    if (config != NULL)\n    {\n#ifdef LOG_PER_LOGGER_LEVEL\n        if (config->per_logger_level != NULL)\n        {\n            list_delete(config->per_logger_level);\n            config->per_logger_level = NULL;\n        }\n#endif\n\n        if (0 != config->log_file)\n        {\n            g_free(config->log_file);\n            config->log_file = 0;\n        }\n\n        g_free(config);\n    }\n\n    return LOG_STARTUP_OK;\n}\n\n/**\n * Restarts the logging.\n *\n * The logging file is never changed, as it is common in xrdp to share a\n * log file between parents and children. The end result would be\n * confusing for the user.\n */\nstatic enum logReturns\nlog_restart_from_param(const struct log_config *lc)\n{\n    enum logReturns rv = LOG_GENERAL_ERROR;\n\n    if (g_staticLogConfig == NULL)\n    {\n        log_message(LOG_LEVEL_ALWAYS, \"Log not already initialized\");\n    }\n    else if (lc == NULL)\n    {\n        g_writeln(\"lc to log_start_from_param is NULL\");\n    }\n    else\n    {\n        if (g_staticLogConfig->fd >= 0 &&\n                g_strcmp(g_staticLogConfig->log_file, lc->log_file) != 0)\n        {\n            log_message(LOG_LEVEL_WARNING,\n                        \"Unable to change log file name from %s to %s\",\n                        g_staticLogConfig->log_file,\n                        lc->log_file);\n        }\n        /* Reconfigure syslog logging, allowing for a program_name change */\n        if (g_staticLogConfig->enable_syslog)\n        {\n            closelog();\n        }\n        if (lc->enable_syslog)\n        {\n            openlog(lc->program_name, LOG_CONS | LOG_PID, LOG_DAEMON);\n        }\n\n        /* Copy over simple values... */\n#ifdef LOG_ENABLE_THREAD\n        g_staticLogConfig->log_lock = lc->log_lock;\n        g_staticLogConfig->log_lock_attr = lc->log_lock_attr;\n#endif\n        g_staticLogConfig->program_name = lc->program_name;\n        g_staticLogConfig->enable_pid = lc->enable_pid;\n        g_staticLogConfig->dump_on_start = lc->dump_on_start;\n\n        /* ... and the log levels */\n        internal_log_config_copy_levels(g_staticLogConfig, lc);\n        rv = LOG_STARTUP_OK;\n    }\n    return rv;\n}\n\nenum logReturns\nlog_start_from_param(const struct log_config *src_log_config)\n{\n    enum logReturns ret = LOG_GENERAL_ERROR;\n\n    if (g_staticLogConfig != NULL)\n    {\n        log_message(LOG_LEVEL_ALWAYS, \"Log already initialized\");\n        return ret;\n    }\n\n    if (src_log_config == NULL)\n    {\n        g_writeln(\"src_log_config to log_start_from_param is NULL\");\n        return ret;\n    }\n    else\n    {\n        g_staticLogConfig = internalInitAndAllocStruct();\n        if (g_staticLogConfig == NULL)\n        {\n            g_writeln(\"internalInitAndAllocStruct failed\");\n            return LOG_ERROR_MALLOC;\n        }\n        internal_log_config_copy(g_staticLogConfig, src_log_config);\n\n        ret = internal_log_start(g_staticLogConfig);\n        if (ret != LOG_STARTUP_OK)\n        {\n            g_writeln(\"Could not start log\");\n\n            log_config_free(g_staticLogConfig);\n            g_staticLogConfig = NULL;\n        }\n    }\n\n    return ret;\n}\n\n/**\n * This function initialize the log facilities according to the configuration\n * file, that is described by the in parameter.\n * @param applicationName the name that is used in the log for the running application\n * @return 0 on success\n */\nenum logReturns\nlog_start(const char *iniFile, const char *applicationName,\n          unsigned int flags)\n{\n    enum logReturns ret = LOG_GENERAL_ERROR;\n    struct log_config *config;\n\n    config = log_config_init_from_config(iniFile, applicationName, \"\");\n\n    if (config != NULL)\n    {\n        config->dump_on_start = (flags & LOG_START_DUMP_CONFIG) ? 1 : 0;\n        if (flags & LOG_START_RESTART)\n        {\n            ret = log_restart_from_param(config);\n            if (ret != LOG_STARTUP_OK)\n            {\n                g_writeln(\"Could not restart log\");\n            }\n        }\n        else\n        {\n            ret = log_start_from_param(config);\n            if (ret != LOG_STARTUP_OK)\n            {\n                g_writeln(\"Could not start log\");\n            }\n        }\n        log_config_free(config);\n    }\n    else\n    {\n        g_writeln(\"Error reading configuration for log based on config: %s\",\n                  iniFile);\n    }\n\n    return ret;\n}\n\n/**\n * Function that terminates all logging\n */\nenum logReturns\nlog_end(void)\n{\n    enum logReturns ret = LOG_GENERAL_ERROR;\n    ret = internal_log_end(g_staticLogConfig);\n    log_config_free(g_staticLogConfig);\n    g_staticLogConfig = NULL;\n\n    return ret;\n}\n\n/*****************************************************************************/\n/* log a hex dump */\nenum logReturns\nlog_hexdump(const enum logLevels log_level,\n            const char *message,\n            const char *src,\n            int len)\n{\n    return log_hexdump_with_location(\"\", \"\", 0, log_level, message, src, len);\n}\n\n/*****************************************************************************/\n/* log a hex dump */\nenum logReturns\nlog_hexdump_with_location(const char *function_name,\n                          const char *file_name,\n                          const int line_number,\n                          const enum logLevels log_level,\n                          const char *message,\n                          const char *src,\n                          int len)\n{\n    char *dump_buffer;\n    enum logReturns rv = LOG_STARTUP_OK;\n    enum logLevels override_log_level = LOG_LEVEL_NEVER;\n    bool_t override_destination_level = 0;\n\n    override_destination_level = internal_log_location_overrides_level(\n        function_name,\n        file_name,\n        &override_log_level);\n    if (!internal_log_is_enabled_for_level(log_level, override_destination_level, override_log_level))\n    {\n        return LOG_STARTUP_OK;\n    }\n\n    /* Start the dump on a new line so that the first line of the dump is\n       aligned to the first column instead of to after the log message\n       preamble (eg. time, log level, ...)\n    */\n#ifdef _WIN32\n#define HEX_DUMP_HEADER (\"Hex Dump:\\r\\n\")\n#else\n#ifdef _MACOS\n#define HEX_DUMP_HEADER (\"Hex Dump:\\r\")\n#else\n#define HEX_DUMP_HEADER (\"Hex Dump:\\n\")\n#endif\n#endif\n\n    dump_buffer = g_bytes_to_hexdump(src, len);\n\n    if (dump_buffer != NULL)\n    {\n        if (g_strlen(file_name) > 0)\n        {\n            rv = log_message_with_location(function_name, file_name, line_number,\n                                           log_level, \"%s %s%s\",\n                                           message, HEX_DUMP_HEADER, dump_buffer);\n        }\n        else\n        {\n            rv = log_message(log_level, \"%s %s%s\",\n                             message, HEX_DUMP_HEADER, dump_buffer);\n        }\n        g_free(dump_buffer);\n    }\n    return rv;\n}\n\nenum logReturns\nlog_message_with_location(const char *function_name,\n                          const char *file_name,\n                          const int line_number,\n                          const enum logLevels level,\n                          const char *msg,\n                          ...)\n{\n    va_list ap;\n    enum logReturns rv;\n    char buff[LOG_BUFFER_SIZE];\n    enum logLevels override_log_level = LOG_LEVEL_NEVER;\n    bool_t override_destination_level = 0;\n\n    if (g_staticLogConfig == NULL)\n    {\n        g_writeln(\"The log reference is NULL - log not initialized properly \"\n                  \"when called from [%s(%s:%d)]\",\n                  (function_name != NULL ? function_name : \"unknown_function\"),\n                  (file_name != NULL ? file_name : \"unknown_file\"),\n                  line_number);\n        return LOG_ERROR_NO_CFG;\n    }\n\n    override_destination_level = internal_log_location_overrides_level(\n        function_name,\n        file_name,\n        &override_log_level);\n    if (!internal_log_is_enabled_for_level(level, override_destination_level, override_log_level))\n    {\n        return LOG_STARTUP_OK;\n    }\n\n    g_snprintf(buff, LOG_BUFFER_SIZE, \"[%s(%s:%d)] %s\",\n               function_name, file_name, line_number, msg);\n\n    va_start(ap, msg);\n    rv = internal_log_message(level, override_destination_level, override_log_level, buff, ap);\n    va_end(ap);\n    return rv;\n}\n\nenum logReturns\nlog_message(const enum logLevels lvl, const char *msg, ...)\n{\n    va_list ap;\n    enum logReturns rv;\n\n    va_start(ap, msg);\n    rv = internal_log_message(lvl, 0, LOG_LEVEL_NEVER, msg, ap);\n    va_end(ap);\n    return rv;\n}\n\nenum logReturns\ninternal_log_message(const enum logLevels lvl,\n                     const bool_t override_destination_level,\n                     const enum logLevels override_log_level,\n                     const char *msg,\n                     va_list ap)\n{\n    char buff[LOG_BUFFER_SIZE + 43]; /* 31 (\"[2022-10-07T19:58:33.065+0900] \") + 8 (log level) + 4 (space+cr+lf+\\0) */\n    int len = 0;\n    enum logReturns rv = LOG_STARTUP_OK;\n    int writereply;\n\n    if (g_staticLogConfig == NULL)\n    {\n        g_writeln(\"The log reference is NULL - log not initialized properly\");\n        return LOG_ERROR_NO_CFG;\n    }\n\n    if (0 > g_staticLogConfig->fd\n            && g_staticLogConfig->enable_syslog == 0\n            && g_staticLogConfig->enable_console == 0)\n    {\n        return LOG_ERROR_FILE_NOT_OPEN;\n    }\n\n    if (!internal_log_is_enabled_for_level(lvl, override_destination_level, override_log_level))\n    {\n        return LOG_STARTUP_OK;\n    }\n\n    getFormattedDateTime(buff, 32);\n\n    internal_log_lvl2str(lvl, buff + 31);\n\n    if (g_staticLogConfig->enable_pid)\n    {\n        /* 31 (datetime) + 8 (log level) = 39 */\n        g_snprintf(buff + 39, LOG_BUFFER_SIZE, \"[pid:%d tid:%lld] \",\n                   g_getpid(), (long long) tc_get_threadid());\n        len = g_strlen(buff + 39);\n    }\n    len += vsnprintf(buff + 39 + len, LOG_BUFFER_SIZE - len, msg, ap);\n\n    /* checking for truncated messages */\n    if (len > LOG_BUFFER_SIZE)\n    {\n        log_message(LOG_LEVEL_WARNING, \"next message will be truncated\");\n        len = LOG_BUFFER_SIZE;\n    }\n\n    /* forcing the end of message string */\n    /* 31 (datetime) + 8 (log level) = 39 */\n#ifdef _WIN32\n    buff[len + 39] = '\\r';\n    buff[len + 40] = '\\n';\n    buff[len + 41] = '\\0';\n#else\n#ifdef _MACOS\n    buff[len + 39] = '\\r';\n    buff[len + 40] = '\\0';\n#else\n    buff[len + 39] = '\\n';\n    buff[len + 40] = '\\0';\n#endif\n#endif\n\n    if (g_staticLogConfig->enable_syslog\n            && ((override_destination_level && lvl <= override_log_level)\n                || (!override_destination_level && lvl <= g_staticLogConfig->syslog_level)))\n    {\n        /* log to syslog*/\n        /* %s fix compiler warning 'not a string literal' */\n        syslog(internal_log_xrdp2syslog(lvl), \"%s\", buff + 31);\n    }\n\n    if (g_staticLogConfig->enable_console\n            && ((override_destination_level && lvl <= override_log_level)\n                || (!override_destination_level && lvl <= g_staticLogConfig->console_level)))\n    {\n        /* log to console */\n        g_printf(\"%s\", buff);\n    }\n\n    if ((override_destination_level && lvl <= override_log_level)\n            || (!override_destination_level && lvl <= g_staticLogConfig->log_level))\n    {\n        /* log to application logfile */\n        if (g_staticLogConfig->fd >= 0)\n        {\n#ifdef LOG_ENABLE_THREAD\n            pthread_mutex_lock(&(g_staticLogConfig->log_lock));\n#endif\n\n            writereply = g_file_write(g_staticLogConfig->fd, buff, g_strlen(buff));\n\n            if (writereply <= 0)\n            {\n                rv = LOG_ERROR_NULL_FILE;\n            }\n\n#ifdef LOG_ENABLE_THREAD\n            pthread_mutex_unlock(&(g_staticLogConfig->log_lock));\n#endif\n        }\n    }\n\n    return rv;\n}\n\n/**\n * Return the configured log file name\n */\nchar *\ngetLogFile(char *replybuf, int bufsize)\n{\n    if (g_staticLogConfig)\n    {\n        if (g_staticLogConfig->log_file)\n        {\n            g_strncpy(replybuf, g_staticLogConfig->log_file, bufsize);\n        }\n        else\n        {\n            g_sprintf(replybuf, \"The log_file name is NULL\");\n        }\n    }\n    else\n    {\n        g_snprintf(replybuf, bufsize, \"The log is not properly started\");\n    }\n\n    return replybuf;\n}\n\n/**\n * Returns formatted datetime for log\n */\nchar *\ngetFormattedDateTime(char *replybuf, int bufsize)\n{\n    char buf_datetime[21]; /* 2022-10-07T16:36:04 + . */\n    char buf_millisec[4];  /* 357 */\n    char buf_timezone[6];  /* +0900 */\n\n    struct tm *now;\n    struct timeval tv;\n    int millisec;\n\n    gettimeofday(&tv, NULL);\n    now = localtime(&tv.tv_sec);\n\n    millisec = (tv.tv_usec + 500 / 1000);\n    g_snprintf(buf_millisec, sizeof(buf_millisec), \"%03d\", millisec);\n\n    strftime(buf_datetime, sizeof(buf_datetime), \"%FT%T.\", now);\n    strftime(buf_timezone, sizeof(buf_timezone), \"%z\", now);\n    g_snprintf(replybuf, bufsize, \"[%s%s%s] \", buf_datetime, buf_millisec, buf_timezone);\n\n    return replybuf;\n}\n\n/*****************************************************************************/\n#ifdef USE_DEVEL_LOGGING\nvoid\nlog_devel_leaking_fds(const char *exe, int min, int max)\n{\n    struct list *fd_list = g_get_open_fds(min, max);\n\n    if (fd_list != NULL)\n    {\n        int i;\n        for (i = 0 ; i < fd_list->count ; ++i)\n        {\n            int fd = (int)fd_list->items[i];\n            if (g_file_get_cloexec(fd) == 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_WARNING,\n                          \"File descriptor %d is not CLOEXEC when running %s\",\n                          fd, exe);\n            }\n        }\n    }\n}\n#endif // USE_DEVEL_LOGGING\n\n"
  },
  {
    "path": "common/log.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef LOG_H\n#define LOG_H\n\n#include <pthread.h>\n\n#include \"arch.h\"\n#include \"defines.h\"\n#include \"list.h\"\n\n/* Check the config_ac.h file is included so we know whether to enable the\n * development macros\n */\n#ifndef CONFIG_AC_H\n#   error config_ac.h not visible in log.h\n#endif\n\n/* logging buffer size */\n#define LOG_BUFFER_SIZE      8192\n#define LOGGER_NAME_SIZE     50\n\n/* logging levels */\nenum logLevels\n{\n    LOG_LEVEL_ALWAYS = 0,\n    LOG_LEVEL_ERROR,     /* for describing non-recoverable error states in a request or method */\n    LOG_LEVEL_WARNING,   /* for describing recoverable error states in a request or method */\n    LOG_LEVEL_INFO,      /* for low verbosity and high level descriptions of normal operations */\n    LOG_LEVEL_DEBUG,     /* for medium verbosity and low level descriptions of normal operations */\n    LOG_LEVEL_TRACE,     /* for high verbosity and low level descriptions of normal operations (eg. method or wire tracing) */\n    LOG_LEVEL_NEVER,\n};\n\n/* startup return values */\nenum logReturns\n{\n    LOG_STARTUP_OK = 0,\n    LOG_ERROR_MALLOC,\n    LOG_ERROR_NULL_FILE,\n    LOG_ERROR_FILE_OPEN,\n    LOG_ERROR_NO_CFG,\n    LOG_ERROR_FILE_NOT_OPEN,\n    LOG_GENERAL_ERROR\n};\n\n#define SESMAN_CFG_LOGGING            \"Logging\"\n#define SESMAN_CFG_LOGGING_LOGGER     \"LoggingPerLogger\"\n#define SESMAN_CFG_LOG_FILE           \"LogFile\"\n#define SESMAN_CFG_LOG_LEVEL          \"LogLevel\"\n#define SESMAN_CFG_LOG_ENABLE_CONSOLE \"EnableConsole\"\n#define SESMAN_CFG_LOG_CONSOLE_LEVEL  \"ConsoleLevel\"\n#define SESMAN_CFG_LOG_ENABLE_SYSLOG  \"EnableSyslog\"\n#define SESMAN_CFG_LOG_SYSLOG_LEVEL   \"SyslogLevel\"\n#define SESMAN_CFG_LOG_ENABLE_PID     \"EnableProcessId\"\n\n/* enable threading */\n/*#define LOG_ENABLE_THREAD*/\n\n#ifdef USE_DEVEL_LOGGING\n\n#define LOG_PER_LOGGER_LEVEL\n\n/**\n * @brief Logging macro for messages that are for an XRDP developer to\n * understand and debug XRDP code.\n *\n * Note: all log levels are relevant to help a developer understand XRDP at\n *      different levels of granularity.\n *\n * Note: the logging function calls are removed when USE_DEVEL_LOGGING is\n * NOT defined.\n *\n * Note: when the build is configured with --enable-devel-logging, then\n *      the log level can be configured per the source file name or method name\n *      (with the suffix \"()\") in the [LoggingPerLogger]\n *      section of the configuration file.\n *\n *      For example:\n *      ```\n *      [LoggingPerLogger]\n *      xrdp.c=DEBUG\n *      main()=WARNING\n *      ```\n *\n * @param lvl, the log level\n * @param msg, the log text as a printf format c-string\n * @param ... the arguments for the printf format c-string\n */\n#define LOG_DEVEL(log_level, args...) \\\n    log_message_with_location(__func__, __FILE__, __LINE__, log_level, args)\n\n/**\n * @brief Logging macro for messages that are for a system administrator to\n * configure and run XRDP on their machine.\n *\n * Note: the logging function calls contain additional code location info when\n *      USE_DEVEL_LOGGING is defined.\n *\n * @param lvl, the log level\n * @param msg, the log text as a printf format c-string\n * @param ... the arguments for the printf format c-string\n */\n#define LOG(log_level, args...) \\\n    log_message_with_location(__func__, __FILE__, __LINE__, log_level, args)\n\n/**\n * @brief Logging macro for logging the contents of a byte array using a hex\n * dump format.\n *\n * Note: the logging function calls are removed when USE_DEVEL_LOGGING is\n * NOT defined.\n *\n * @param log_level, the log level\n * @param message, a message prefix for the hex dump. Note: no printf like\n *          formatting is done to this message.\n * @param buffer, a pointer to the byte array to log as a hex dump\n * @param length, the length of the byte array to log\n */\n#define LOG_DEVEL_HEXDUMP(log_level, message, buffer, length)  \\\n    log_hexdump_with_location(__func__, __FILE__, __LINE__, log_level, message, buffer, length)\n\n/**\n * @brief Logging macro for logging the contents of a byte array using a hex\n * dump format.\n *\n * @param log_level, the log level\n * @param message, a message prefix for the hex dump. Note: no printf like\n *          formatting is done to this message.\n * @param buffer, a pointer to the byte array to log as a hex dump\n * @param length, the length of the byte array to log\n */\n#define LOG_HEXDUMP(log_level, message, buffer, length)  \\\n    log_hexdump_with_location(__func__, __FILE__, __LINE__, log_level, message, buffer, length)\n\n#define LOG_DEVEL_LEAKING_FDS(exe,min,max) log_devel_leaking_fds(exe,min,max)\n\n#else\n#define LOG(log_level, args...) log_message(log_level, args)\n#define LOG_HEXDUMP(log_level, message, buffer, length)  \\\n    log_hexdump(log_level, message, buffer, length)\n\n/* Since log_message() returns a value ensure that the elided versions of\n * LOG_DEVEL and LOG_DEVEL_HEXDUMP also \"fake\" returning the success value\n */\n#define LOG_DEVEL(log_level, args...) UNUSED_VAR(LOG_STARTUP_OK)\n#define LOG_DEVEL_HEXDUMP(log_level, message, buffer, length) UNUSED_VAR(LOG_STARTUP_OK)\n\n#define LOG_DEVEL_LEAKING_FDS(exe,min,max)\n#endif\n\n/* Flags values for log_start() */\n\n/**\n * Dump the log config on startup\n */\n#define LOG_START_DUMP_CONFIG (1<<0)\n\n/**\n * Restart the logging system.\n *\n * On a restart, existing files are not closed. This is because the\n * files may be shared by sub-processes, and the result will not be what the\n * user expects\n */\n#define LOG_START_RESTART (1<<1)\n\n#ifdef LOG_PER_LOGGER_LEVEL\nenum log_logger_type\n{\n    LOG_TYPE_FILE = 0,\n    LOG_TYPE_FUNCTION,\n};\n\nstruct log_logger_level\n{\n    enum logLevels log_level;\n    enum log_logger_type logger_type;\n    char logger_name[LOGGER_NAME_SIZE + 1];\n};\n#endif\n\nstruct log_config\n{\n    const char *program_name; /* Pointer to static storage */\n    char *log_file; /* Dynamically allocated */\n    int fd;\n    enum logLevels log_level;\n    int enable_console;\n    enum logLevels console_level;\n    int enable_syslog;\n    enum logLevels syslog_level;\n#ifdef LOG_PER_LOGGER_LEVEL\n    struct list *per_logger_level;\n#endif\n    int dump_on_start;\n    int enable_pid;\n#ifdef LOG_ENABLE_THREAD\n    pthread_mutex_t log_lock;\n    pthread_mutexattr_t log_lock_attr;\n#endif\n};\n\n/* internal functions, only used in log.c if this ifdef is defined.*/\n#ifdef LOGINTERNALSTUFF\n\n/**\n *\n * @brief Starts the logging subsystem\n * @param l_cfg logging system configuration\n *\n */\nenum logReturns\ninternal_log_start(struct log_config *l_cfg);\n\n/**\n *\n * @brief Shuts down the logging subsystem\n * @param l_cfg pointer to the logging subsystem to stop\n *\n */\nenum logReturns\ninternal_log_end(struct log_config *l_cfg);\n\n/**\n * Converts a log level to a string\n * @param lvl the loglevel\n * @param str pointer where the string will be stored.\n */\nvoid\ninternal_log_lvl2str(const enum logLevels lvl, char *str);\n\n/**\n *\n * @brief Converts a string to a log level\n * @param buf The string to convert\n * @return The corresponding level or LOG_LEVEL_DEBUG if error\n *\n */\nenum logLevels\ninternal_log_text2level(const char *buf);\n\n/**\n * A function that init our struct that holds all state and\n * also init its content.\n * @return  LOG_STARTUP_OK or LOG_ERROR_MALLOC\n */\nstruct log_config *\ninternalInitAndAllocStruct(void);\n\n/**\n * Print the contents of the logging config to stdout.\n */\nvoid\ninternal_log_config_dump(struct log_config *config);\n\n/**\n * the log function that all files use to log an event.\n * @param lvl the loglevel\n * @param override_destination_level if true then the destination log level is not used\n * @param override_log_level the loglevel instead of the destination log level if override_destination_level is true\n * @param msg the logtext.\n * @param ap the values for the message format arguments\n */\nenum logReturns\ninternal_log_message(const enum logLevels lvl,\n                     const bool_t override_destination_level,\n                     const enum logLevels override_log_level,\n                     const char *msg,\n                     va_list ap);\n\n/**\n * @param log_level the log level\n * @param override_destination_level if true then the destination log level is ignored.\n * @param override_log_level the log level to use instead of the destination log level\n *      if override_destination_level is true\n * @return true if at least one log destination will accept a message logged at the given level.\n */\nbool_t\ninternal_log_is_enabled_for_level(const enum logLevels log_level,\n                                  const bool_t override_destination_level,\n                                  const enum logLevels override_log_level);\n\n/**\n * @param function_name the function name (typically the __func__ macro)\n * @param file_name the file name (typically the __FILE__ macro)\n * @param[out] log_level_return the log level to use instead of the destination log level\n * @return true if the logger location overrides the destination log levels\n */\nbool_t\ninternal_log_location_overrides_level(const char *function_name,\n                                      const char *file_name,\n                                      enum logLevels *log_level_return);\n\n/*End of internal functions*/\n#endif\n\n/**\n * This function initialize the log facilities according to the configuration\n * file, that is described by the in parameter.\n * @param applicationName the name that is used in the log for the running\n *                        application\n * @param flags Flags to affect the operation of the call\n * @return LOG_STARTUP_OK on success\n */\nenum logReturns\nlog_start(const char *iniFile, const char *applicationName,\n          unsigned int flags);\n\n/**\n * An alternative log_start where the caller gives the params directly.\n *\n * @post to avoid memory leaks, the config argument must be free'ed using\n * `log_config_free()`\n */\nenum logReturns\nlog_start_from_param(const struct log_config *src_log_config);\n\n/**\n * Sets up a suitable log config for writing to the console only\n * (i.e. for a utility)\n *\n * The config can be customised by the caller before calling\n * log_start_from_param()\n *\n * @param lvl log level\n * @param override_name level name, or NULL. This can be used to provide an\n *        override to the default log level, by environment variable or\n *        argument.\n *\n * @return pointer to struct log_config.\n */\nstruct log_config *\nlog_config_init_for_console(enum logLevels lvl, const char *override_name);\n\n/**\n * Read configuration from a file and store the values in the returned\n * log_config.\n * @param applicationName the application name used in the log events.\n * @param section_prefix prefix for the logging sections to parse\n */\nstruct log_config *\nlog_config_init_from_config(const char *iniFilename,\n                            const char *applicationName,\n                            const char *section_prefix);\n\n/**\n * Free the memory for the log_config struct.\n */\nenum logReturns\nlog_config_free(struct log_config *config);\n\n/**\n * Function that terminates all logging\n */\nenum logReturns\nlog_end(void);\n\n/**\n * the log function that all files use to log an event.\n *\n * Please prefer to use the LOG and LOG_DEVEL macros instead of this function directly.\n *\n * @param lvl the loglevel\n * @param msg the logtext.\n */\nenum logReturns\nlog_message(const enum logLevels lvl, const char *msg, ...) printflike(2, 3);\n\nenum logReturns\nlog_hexdump(const enum logLevels log_level,\n            const char *msg,\n            const char *p,\n            int len);\n\n/**\n * the log function that all files use to log an event,\n * with the function name and file line.\n *\n * Please prefer to use the LOG and LOG_DEVEL macros instead of this function directly.\n *\n * @param function_name the function name (typically the __func__ macro)\n * @param file_name the file name (typically the __FILE__ macro)\n * @param line_number the line number in the file (typically the __LINE__ macro)\n * @param lvl the loglevel\n * @param msg the logtext.\n */\nenum logReturns\nlog_message_with_location(const char *function_name,\n                          const char *file_name,\n                          const int line_number,\n                          const enum logLevels lvl,\n                          const char *msg,\n                          ...) printflike(5, 6);\n\nenum logReturns\nlog_hexdump_with_location(const char *function_name,\n                          const char *file_name,\n                          const int line_number,\n                          const enum logLevels log_level,\n                          const char *msg,\n                          const char *p,\n                          int len);\n\n/**\n * This function returns the configured file name for the logfile\n * @param replybuf the buffer where the reply is stored\n * @param bufsize how big is the reply buffer.\n */\nchar *getLogFile(char *replybuf, int bufsize);\n\n/**\n * Returns formatted datetime for log\n */\nchar *getFormattedDateTime(char *replybuf, int bufsize);\n\n#ifdef USE_DEVEL_LOGGING\n/**\n * Log open file descriptors not cloexec before execing another program\n *\n * Used to ensure file descriptors aren't leaking when running\n * non-privileged executables\n *\n * Use the LOG_DEVEL_LEAKING_FDS() macro to invoke this function\n *\n * @param exe Executable we're about to launch\n * @param min Minimum FD to consider\n * @param max Maximum FD to consider + 1, or -1 for no upper FD\n */\nvoid\nlog_devel_leaking_fds(const char *exe, int min, int max);\n#endif\n\n#endif\n"
  },
  {
    "path": "common/ms-erref.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-ERREF : Definitions from [MS-ERREF]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-ERREF are currently correct for v20180912 of that\n * document\n */\n\n#if !defined(MS_ERREF_H)\n#define MS_ERREF_H\n\n/*\n * NTSTATUS codes (section 2.3)\n */\nenum NTSTATUS\n{\n    STATUS_SUCCESS               = 0x00000000,\n\n    STATUS_NO_MORE_FILES         = 0x80000006,\n\n    STATUS_UNSUCCESSFUL          = 0xc0000001,\n    STATUS_INFO_LENGTH_MISMATCH  = 0xc0000004,\n    STATUS_NO_SUCH_FILE          = 0xc000000f,\n    STATUS_ACCESS_DENIED         = 0xc0000022,\n    STATUS_OBJECT_NAME_INVALID   = 0xc0000033,\n    STATUS_OBJECT_NAME_NOT_FOUND = 0xc0000034,\n    STATUS_SHARING_VIOLATION     = 0xc0000043,\n    STATUS_NOT_SUPPORTED         = 0xc00000bb\n};\n\n#endif /* MS_ERREF_H */\n"
  },
  {
    "path": "common/ms-fscc.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-FSCC : Definitions from [MS-FSCC]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-FSCC are currently correct for v20190923 of that\n * document\n */\n\n#if !defined(MS_FSCC_H)\n#define MS_FSCC_H\n\n/*\n * File system ioctl codes (section 2.3)\n */\n#define FSCTL_DELETE_OBJECT_ID          0x900a0\n\n/*\n * File information classes (section 2.4)\n */\nenum FILE_INFORMATION_CLASS\n{\n    FileAllocationInformation    = 19,  /* Set */\n    FileBasicInformation         = 4,  /* Query, Set */\n    FileBothDirectoryInformation = 3,  /* Query */\n    FileDirectoryInformation     = 1,  /* Query */\n    FileDispositionInformation   = 13, /* Set */\n    FileEndOfFileInformation     = 20, /* Set */\n    FileFullDirectoryInformation = 2,  /* Query */\n    FileNamesInformation         = 12, /* Query */\n    FileRenameInformation        = 10, /* Set */\n    FileStandardInformation      = 5   /* Query */\n};\n\n/*\n * Size of structs above without trailing RESERVED fields (MS-RDPEFS\n * 2.2.3.3.8)\n */\n#define FILE_BASIC_INFORMATION_SIZE 36\n#define FILE_STD_INFORMATION_SIZE 22\n#define FILE_END_OF_FILE_INFORMATION_SIZE 8\n\n/*\n * File System information classes (section 2.5)\n */\nenum FILE_SYSTEM_INFORMATION_CLASS\n{\n    FileFsVolumeInformation = 1,\n    FileFsSizeInformation = 3,\n    FileFsDeviceInformation = 4,\n    FileFsAttributeInformation = 5,\n    FileFsFullSizeInformation = 7\n};\n\n/*\n * Size of structs above without trailing RESERVED fields (MS-RDPEFS\n * 2.2.3.3.6)\n */\n#define FILE_FS_SIZE_INFORMATION_SIZE 24\n#define FILE_FS_DEVICE_INFORMATION_SIZE 8\n#define FILE_FS_FULL_SIZE_INFORMATION_SIZE 32\n\n/* Windows file attributes (section 2.6) */\n#define W_FILE_ATTRIBUTE_DIRECTORY      0x00000010\n#define W_FILE_ATTRIBUTE_READONLY       0x00000001\n#define W_FILE_ATTRIBUTE_SYSTEM         0x00000004\n#define W_FILE_ATTRIBUTE_NORMAL         0x00000080\n\n#endif /* MS_FSCC_H */\n\n\n\n"
  },
  {
    "path": "common/ms-rdpbcgr.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-RDPBCGR : Definitions from [MS-RDPBCGR]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-RDPBCGR are currently correct for v20190923 of that\n * document\n */\n\n#if !defined(MS_RDPBCGR_H)\n#define MS_RDPBCGR_H\n\n/* RDP Security Negotiation codes */\n#define RDP_NEG_REQ                    0x01  /* MS-RDPBCGR 2.2.1.1.1 */\n#define RDP_NEG_RSP                    0x02  /* MS-RDPBCGR 2.2.1.2.1 */\n#define RDP_NEG_FAILURE                0x03  /* MS-RDPBCGR 2.2.1.2.2 */\n#define RDP_CORRELATION_INFO           0x06  /* MS-RDPBCGR 2.2.1.1.2 */\n\n/* Protocol types codes (2.2.1.1.1, 2.2.1.2.1) */\n#define PROTOCOL_RDP                   0x00000000\n#define PROTOCOL_SSL                   0x00000001\n#define PROTOCOL_HYBRID                0x00000002\n#define PROTOCOL_RDSTLS                0x00000004\n#define PROTOCOL_HYBRID_EX             0x00000008\n\n/* Negotiation request packet flags (2.2.1.1.1) */\n#define RESTRICTED_ADMIN_MODE_REQUIRED          0x00000001\n#define REDIRECTED_AUTHENTICATION_MODE_REQUIRED 0x00000002\n#define CORRELATION_INFO_PRESENT                0x00000008\n\n/* Negotiation response packet flags (2.2.1.2.1) */\n#define EXTENDED_CLIENT_DATA_SUPPORTED            0x01\n#define DYNVC_GFX_PROTOCOL_SUPPORTED              0x02\n#define NEGRSP_RESERVED                           0x04\n#define RESTRICTED_ADMIN_MODE_SUPPORTED           0x08\n#define REDIRECTED_AUTHENTICATION_MODE_SUPPORTED  0x10\n\n/* RDP Negotiation Failure Codes (2.2.1.2.2) */\n#define SSL_REQUIRED_BY_SERVER                 0x00000001\n#define SSL_NOT_ALLOWED_BY_SERVER              0x00000002\n#define SSL_CERT_NOT_ON_SERVER                 0x00000003\n#define INCONSISTENT_FLAGS                     0x00000004\n#define HYBRID_REQUIRED_BY_SERVER              0x00000005\n#define SSL_WITH_USER_AUTH_REQUIRED_BY_SERVER  0x00000006\n\n/* TS_UD_HEADER: type ((2.2.1.3.1) */\n/* TODO: to be renamed */\n#define SEC_TAG_CLI_INFO       0xc001 /* CS_CORE? */\n#define SEC_TAG_CLI_CRYPT      0xc002 /* CS_SECURITY? */\n#define SEC_TAG_CLI_CHANNELS   0xc003 /* CS_CHANNELS? */\n#define SEC_TAG_CLI_4          0xc004 /* CS_CLUSTER? */\n#define SEC_TAG_CLI_MONITOR    0xc005 /* CS_MONITOR */\n#define SEC_TAG_CLI_MONITOR_EX 0xc008 /* CS_MONITOR_EX */\n#define SEC_TAG_SRV_INFO       0x0c01 /* SC_CORE */\n#define SEC_TAG_SRV_CRYPT      0x0c02 /* SC_SECURITY */\n#define SEC_TAG_SRV_CHANNELS   0x0c03 /* SC_NET? */\n\n\n/* Client Core Data: colorDepth, postBeta2ColorDepth (2.2.1.3.2) */\n#define RNS_UD_COLOR_4BPP      0xCA00\n#define RNS_UD_COLOR_8BPP      0xCA01\n#define RNS_UD_COLOR_16BPP_555 0xCA02\n#define RNS_UD_COLOR_16BPP_565 0xCA03\n#define RNS_UD_COLOR_24BPP     0xCA04\n\n/* Client Core Data: supportedColorDepths (2.2.1.3.2) */\n#define RNS_UD_24BPP_SUPPORT 0x0001\n#define RNS_UD_16BPP_SUPPORT 0x0002\n#define RNS_UD_15BPP_SUPPORT 0x0004\n#define RNS_UD_32BPP_SUPPORT 0x0008\n\n/* Client Core Data: earlyCapabilityFlags (2.2.1.3.2) */\n#define RNS_UD_CS_SUPPORT_ERRINFO_PDU        0x0001\n#define RNS_UD_CS_WANT_32BPP_SESSION         0x0002\n#define RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU 0x0040\n#define RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL 0x0100\n#define RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN   0x0800\n\n/* Client Core Data: connectionType  (2.2.1.3.2) */\n#define CONNECTION_TYPE_MODEM          0x01\n#define CONNECTION_TYPE_BROADBAND_LOW  0x02\n#define CONNECTION_TYPE_SATELLITE      0x03\n#define CONNECTION_TYPE_BROADBAND_HIGH 0x04\n#define CONNECTION_TYPE_WAN            0x05\n#define CONNECTION_TYPE_LAN            0x06\n#define CONNECTION_TYPE_AUTODETECT     0x07\n\n/* TS_UD_CS_NET (2.2.1.3.4) */\n/* This isn't explicitly named in MS-RDPBCGR */\n#define MAX_STATIC_CHANNELS            31\n\n/* Channel definition structure CHANNEL_DEF (2.2.1.3.4.1) */\n#define CHANNEL_NAME_LEN                7\n/* These names are also not explicitly defined in MS-RDPBCGR */\n#define CLIPRDR_SVC_CHANNEL_NAME        \"cliprdr\"\n#define DRDYNVC_SVC_CHANNEL_NAME        \"drdynvc\"\n#define RAIL_SVC_CHANNEL_NAME           \"rail\"\n#define RDPSND_SVC_CHANNEL_NAME         \"rdpsnd\"\n#define RDPDR_SVC_CHANNEL_NAME          \"rdpdr\"\n\n/* 2.2.1.3.6 Client Monitor Data */\n/* monitorCount (4 bytes): A 32-bit, unsigned integer. The number of display */\n/* monitor definitions in the monitorDefArray field (the maximum allowed is 16). */\n#define CLIENT_MONITOR_DATA_MAXIMUM_MONITORS               16\n\n/* 2.2.1.3.6 Client Monitor Data */\n/* The maximum width of the virtual desktop resulting from the union of the monitors */\n/* contained in the monitorDefArray field MUST NOT exceed 32,766 pixels. Similarly, */\n/* the maximum height of the virtual desktop resulting from the union of the monitors  */\n/* contained in the monitorDefArray field MUST NOT exceed 32,766 pixels. */\n/* The minimum permitted size of the virtual desktop is 200 x 200 pixels. */\n#define CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_DESKTOP_WIDTH  0xC8   // 200\n#define CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_DESKTOP_HEIGHT 0xC8   // 200\n#define CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_DESKTOP_WIDTH  0x7FFE // 32766\n#define CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_DESKTOP_HEIGHT 0x7FFE // 32766\n\n/* 2.2.1.3.6.1 Monitor Definition (TS_MONITOR_DEF) */\n#define TS_MONITOR_PRIMARY 0x00000001\n\n/* Options field */\n/* NOTE: XR_ prefixed to avoid conflict with FreeRDP */\n#define XR_CHANNEL_OPTION_INITIALIZED   0x80000000\n#define XR_CHANNEL_OPTION_ENCRYPT_RDP   0x40000000\n#define XR_CHANNEL_OPTION_ENCRYPT_SC    0x20000000\n#define XR_CHANNEL_OPTION_ENCRYPT_CS    0x10000000\n#define XR_CHANNEL_OPTION_PRI_HIGH      0x08000000\n#define XR_CHANNEL_OPTION_PRI_MED       0x04000000\n#define XR_CHANNEL_OPTION_PRI_LOW       0x02000000\n#define XR_CHANNEL_OPTION_COMPRESS_RDP  0x00800000\n#define XR_CHANNEL_OPTION_COMPRESS      0x00400000\n#define XR_CHANNEL_OPTION_SHOW_PROTOCOL 0x00200000\n#define REMOTE_CONTROL_PERSISTENT       0x00100000\n\n/* Server earlyCapabilityFlags (2.2.1.4.2) */\n#define RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED 0x00000008\n\n/* Server Proprietary Certificate (2.2.1.4.3.1.1) */\n/* TODO: to be renamed */\n#define SEC_TAG_PUBKEY                 0x0006 /* BB_RSA_KEY_BLOB */\n#define SEC_TAG_KEYSIG                 0x0008 /* BB_SIGNATURE_KEY_BLOB */\n\n/* Info Packet (TS_INFO_PACKET): flags (2.2.1.11.1.1) */\n/* TODO: to be renamed */\n#define RDP_LOGON_AUTO                 0x0008\n#define RDP_LOGON_NORMAL               0x0033\n#define RDP_COMPRESSION                0x0080\n#define RDP_LOGON_BLOB                 0x0100\n#define RDP_LOGON_LEAVE_AUDIO          0x2000\n#define RDP_LOGON_RAIL                 0x8000\n\n/* Extended Info Packet: clientAddress (2.2.1.11.1.1.1) */\n#define EXTENDED_INFO_MAX_CLIENT_ADDR_LENGTH 80\n\n/* Extended Info Packet: performanceFlags (2.2.1.11.1.1.1) */\n/* TODO: to be renamed */\n#define RDP5_DISABLE_NOTHING           0x00\n#define RDP5_NO_WALLPAPER              0x01\n#define RDP5_NO_FULLWINDOWDRAG         0x02\n#define RDP5_NO_MENUANIMATIONS         0x04\n#define RDP5_NO_THEMING                0x08\n#define RDP5_NO_CURSOR_SHADOW          0x20\n#define RDP5_NO_CURSORSETTINGS         0x40 /* disables cursor blinking */\n\n/* LICENSE_PREAMBLE (2.2.1.12.1.1) */\n#define ERROR_ALERT                    0xff\n#define PREAMBLE_VERSION_3_0           0x03\n\n/* LICENSE_BINARY_BLOB (2.2.1.12.1.2) */\n#define BB_ERROR_BLOB                  0x0004\n\n/* LICENSE_ERROR_MESSAGE (2.2.1.12.1.3) */\n#define STATUS_VALID_CLIENT            0x00000007\n#define ST_NO_TRANSITION               0x00000002\n\n/* Maps to generalCapabilitySet in T.128 page 138 */\n\n/* Capability Set: capabilitySetType (2.2.1.13.1.1.1) */\n#define CAPSTYPE_GENERAL                        0x0001\n#define CAPSTYPE_GENERAL_LEN                    0x18\n\n#define CAPSTYPE_BITMAP                         0x0002\n#define CAPSTYPE_BITMAP_LEN                     0x1C\n\n#define CAPSTYPE_ORDER                          0x0003\n#define CAPSTYPE_ORDER_LEN                      0x58\n#define ORDER_CAP_NEGOTIATE                     2 /* NEGOTIATEORDERSUPPORT? not used */\n#define ORDER_CAP_NOSUPPORT                     4 /* not used */\n\n#define CAPSTYPE_BITMAPCACHE                    0x0004\n#define CAPSTYPE_BITMAPCACHE_LEN                0x28\n\n#define CAPSTYPE_CONTROL                        0x0005\n#define CAPSTYPE_CONTROL_LEN                    0x0C\n\n#define CAPSTYPE_ACTIVATION                     0x0007\n#define CAPSTYPE_ACTIVATION_LEN                 0x0C\n\n#define CAPSTYPE_POINTER                        0x0008\n#define CAPSTYPE_POINTER_LEN                    0x0a\n#define CAPSTYPE_POINTER_MONO_LEN               0x08\n\n#define CAPSTYPE_SHARE                          0x0009\n#define CAPSTYPE_SHARE_LEN                      0x08\n\n#define CAPSTYPE_COLORCACHE                     0x000A\n#define CAPSTYPE_COLORCACHE_LEN                 0x08\n\n#define CAPSTYPE_SOUND                          0x000C\n\n#define CAPSTYPE_INPUT                          0x000D\n#define CAPSTYPE_INPUT_LEN                      0x58\n\n#define CAPSTYPE_FONT                           0x000E\n#define CAPSTYPE_FONT_LEN                       0x04\n\n#define CAPSTYPE_BRUSH                          0x000F\n#define CAPSTYPE_BRUSH_LEN                      0x08\n\n#define CAPSTYPE_GLYPHCACHE                     0x0010\n#define CAPSTYPE_OFFSCREENCACHE                 0x0011\n\n#define CAPSTYPE_BITMAPCACHE_HOSTSUPPORT        0x0012\n#define CAPSTYPE_BITMAPCACHE_HOSTSUPPORT_LEN    0x08\n\n#define CAPSTYPE_BITMAPCACHE_REV2               0x0013\n#define CAPSTYPE_BITMAPCACHE_REV2_LEN           0x28\n#define BMPCACHE2_FLAG_PERSIST                  ((long)1<<31)\n\n#define CAPSTYPE_VIRTUALCHANNEL                 0x0014\n#define CAPSTYPE_VIRTUALCHANNEL_LEN             0x08\n\n#define CAPSTYPE_DRAWNINGRIDCACHE               0x0015\n#define CAPSTYPE_DRAWGDIPLUS                    0x0016\n#define CAPSTYPE_RAIL                           0x0017\n#define CAPSTYPE_WINDOW                         0x0018\n\n#define CAPSSETTYPE_COMPDESK                    0x0019\n#define CAPSSETTYPE_COMPDESK_LEN                0x06\n\n#define CAPSSETTYPE_MULTIFRAGMENTUPDATE         0x001A\n#define CAPSSETTYPE_MULTIFRAGMENTUPDATE_LEN     0x08\n\n#define CAPSETTYPE_LARGE_POINTER                0x001B\n#define CAPSETTYPE_LARGE_POINTER_LEN            0x06\n\n#define CAPSETTYPE_SURFACE_COMMANDS             0x001C\n#define CAPSETTYPE_SURFACE_COMMANDS_LEN         0x0C\n\n#define CAPSSETTYPE_BITMAP_CODECS               0x001D\n#define CAPSSETTYPE_BITMAP_CODECS_LEN           0x1C\n\n#define CAPSTYPE_FRAME_ACKNOWLEDGE              0x001E\n#define CAPSTYPE_FRAME_ACKNOWLEDGE_LEN          0x08\n\n/* Control PDU Data: action (2.2.1.15.1) */\n/* TODO: to be renamed */\n#define RDP_CTL_REQUEST_CONTROL        1 /* CTRLACTION_REQUEST_CONTROL */\n#define RDP_CTL_GRANT_CONTROL          2\n#define RDP_CTL_DETACH                 3\n#define RDP_CTL_COOPERATE              4\n\n/* RDP5 disconnect PDU */\n/* Set Error Info PDU Data: errorInfo (2.2.5.1.1) */\n#define ERRINFO_NONE                                  0x0000\n#define ERRINFO_RPC_INITIATED_DISCONNECT              0x0001\n#define ERRINFO_RPC_INITIATED_LOGOFF                  0x0002\n#define ERRINFO_IDLE_TIMEOUT                          0x0003\n#define ERRINFO_LOGON_TIMEOUT                         0x0004\n#define ERRINFO_DISCONNECTED_BY_OTHERCONNECTION       0x0005\n#define ERRINFO_OUT_OF_MEMORY                         0x0006\n#define ERRINFO_SERVER_DENIED_CONNECTION              0x0007\n#define ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES        0x0009\n#define ERRINFO_LOGOFF_BY_USER                        0x000c\n#define ERRINFO_SERVER_DWM_CRASH                      0x0010\n#define ERRINFO_SERVER_CSRSS_CRASH                    0x0018\n\n/* Virtual channel PDU (2.2.6.1) */\n#define CHANNEL_CHUNK_LENGTH                          1600\n\n/* Channel PDU Header flags (2.2.6.1.1) */\n/* NOTE: XR_ prefixed to avoid conflict with FreeRDP */\n#define XR_CHANNEL_FLAG_FIRST          0x00000001\n#define XR_CHANNEL_FLAG_LAST           0x00000002\n#define XR_CHANNEL_FLAG_SHOW_PROTOCOL  0x00000010\n\n/* General Capability Set: osMajorType (2.2.7.1.1) */\n#define OSMAJORTYPE_UNSPECIFIED        0x0000\n#define OSMAJORTYPE_WINDOWS            0x0001\n#define OSMAJORTYPE_OS2                0x0002\n#define OSMAJORTYPE_MACINTOSH          0x0003\n#define OSMAJORTYPE_UNIX               0x0004\n#define OSMAJORTYPE_IOS                0x0005\n#define OSMAJORTYPE_OSX                0x0006\n#define OSMAJORTYPE_ANDROID            0x0007\n#define OSMAJORTYPE_CHROME_OS          0x0008\n\n/* General Capability Set: osMinorType (2.2.7.1.1) */\n#define OSMINORTYPE_UNSPECIFIED        0x0000\n#define OSMINORTYPE_WINDOWS_31X        0x0001\n#define OSMINORTYPE_WINDOWS_95         0x0002\n#define OSMINORTYPE_WINDOWS_NT         0x0003\n#define OSMINORTYPE_OS2_V21            0x0004\n#define OSMINORTYPE_POWER_PC           0x0005\n#define OSMINORTYPE_MACINTOSH          0x0006\n#define OSMINORTYPE_NATIVE_XSERVER     0x0007\n#define OSMINORTYPE_PSEUDO_XSERVER     0x0008\n#define OSMINORTYPE_WINDOWS_RT         0x0009\n\n/*  General Capability Set: protocolVersion (2.2.7.1.1) */\n#define  TS_CAPS_PROTOCOLVERSION       0x0200\n\n/* General Capability Set: extraFlags (2.2.7.1.1) */\n#define  FASTPATH_OUTPUT_SUPPORTED     0x0001\n#define  NO_BITMAP_COMPRESSION_HDR     0x0400\n#define  LONG_CREDENTIALS_SUPPORTED    0x0004\n#define  AUTORECONNECT_SUPPORTED       0x0008\n#define  ENC_SALTED_CHECKSUM           0x0010\n\n/* Order Capability Set: orderSupportExFlags (2.2.7.1.3)  */\n/* NOTE: XR_ prefixed to avoid conflict with FreeRDP */\n/* XR_PRIMARY_ORDER_COUNT is not an official definition */\n#define XR_PRIMARY_ORDER_COUNT         32\n#define XR_ORDERFLAGS_EX_CACHE_BITMAP_REV3_SUPPORT   0x0002\n#define XR_ORDERFLAGS_EX_ALTSEC_FRAME_MARKER_SUPPORT 0x0004\n\n/* Order Capability Set: orderFlags (2.2.7.1.3) */\n#define  NEGOTIATEORDERSUPPORT         0x0002\n#define  ZEROBOUNDSDELTASUPPORT        0x0008\n#define  COLORINDEXSUPPORT             0x0020\n#define  SOLIDPATTERNBRUSHONLY         0x0040\n#define  ORDERFLAGS_EXTRA_FLAGS        0x0080\n\n/* Order Capability Set: orderSupport (2.2.7.1.3) */\n#define TS_NEG_DSTBLT_INDEX             0x00\n#define TS_NEG_PATBLT_INDEX             0x01\n#define TS_NEG_SCRBLT_INDEX             0x02\n#define TS_NEG_MEMBLT_INDEX             0x03\n#define TS_NEG_MEM3BLT_INDEX            0x04\n/*                                      0x05 */\n/*                                      0x06 */\n#define TS_NEG_DRAWNINEGRID_INDEX       0x07\n#define TS_NEG_LINETO_INDEX             0x08\n#define TS_NEG_MULTI_DRAWNINEGRID_INDEX 0x09\n/*                                      0x0A */\n#define TS_NEG_SAVEBITMAP_INDEX         0x0B\n/*                                      0x0C */\n/*                                      0x0D */\n/*                                      0x0E */\n#define TS_NEG_MULTIDSTBLT_INDEX        0x0F\n#define TS_NEG_MULTIPATBLT_INDEX        0x10\n#define TS_NEG_MULTISCRBLT_INDEX        0x11\n#define TS_NEG_MULTIOPAQUERECT_INDEX    0x12\n#define TS_NEG_FAST_INDEX_INDEX         0x13\n#define TS_NEG_POLYGON_SC_INDEX         0x14\n#define TS_NEG_POLYGON_CB_INDEX         0x15\n#define TS_NEG_POLYLINE_INDEX           0x16\n/*                                      0x17 */\n#define TS_NEG_FAST_GLYPH_INDEX         0x18\n#define TS_NEG_ELLIPSE_SC_INDEX         0x19\n#define TS_NEG_ELLIPSE_CB_INDEX         0x1A\n#define TS_NEG_INDEX_INDEX              0x1B\n/*                                      0x1C */\n/*                                      0x1D */\n/*                                      0x1E */\n/*                                      0x1F */\n\n/* Input Capability Set: inputFlags (2.2.7.1.6) */\n#define  INPUT_FLAG_SCANCODES          0x0001\n#define  INPUT_FLAG_MOUSEX             0x0004\n#define  INPUT_FLAG_FASTPATH_INPUT     0x0008\n#define  INPUT_FLAG_UNICODE            0x0010\n#define  INPUT_FLAG_FASTPATH_INPUT2    0x0020\n#define  INPUT_FLAG_UNUSED1            0x0040\n#define  INPUT_FLAG_UNUSED2            0x0080\n#define  TS_INPUT_FLAG_MOUSE_HWHEEL    0x0100\n#define  TS_INPUT_FLAG_QOE_TIMESTAMPS  0x0200\n\n/* Glyph Cache Capability Set: GlyphSupportLevel (2.2.7.1.8) */\n#define GLYPH_SUPPORT_NONE             0x0000\n#define GLYPH_SUPPORT_PARTIAL          0x0001\n#define GLYPH_SUPPORT_FULL             0x0002\n#define GLYPH_SUPPORT_ENCODE           0x0003\n\n/* Desktop Composition Capability Set: CompDeskSupportLevel (2.2.7.2.8) */\n#define  COMPDESK_NOT_SUPPORTED      0x0000\n#define  COMPDESK_SUPPORTED          0x0001\n\n/* Surface Commands Capability Set: cmdFlags (2.2.7.2.9) */\n#define SURFCMDS_SETSURFACEBITS      0x00000002\n#define SURFCMDS_FRAMEMARKER         0x00000010\n#define SURFCMDS_STREAMSUFRACEBITS   0x00000040\n\n/* Bitmap Codec: codecGUID (2.2.7.2.10.1.1) */\n\n/* CODEC_GUID_NSCODEC  CA8D1BB9-000F-154F-589F-AE2D1A87E2D6 */\n#define XR_CODEC_GUID_NSCODEC \\\n    \"\\xb9\\x1b\\x8d\\xca\\x0f\\x00\\x4f\\x15\\x58\\x9f\\xae\\x2d\\x1a\\x87\\xe2\\xd6\"\n\n/* CODEC_GUID_REMOTEFX 76772F12-BD72-4463-AFB3-B73C9C6F7886 */\n#define XR_CODEC_GUID_REMOTEFX \\\n    \"\\x12\\x2F\\x77\\x76\\x72\\xBD\\x63\\x44\\xAF\\xB3\\xB7\\x3C\\x9C\\x6F\\x78\\x86\"\n\n/* CODEC_GUID_IMAGE_REMOTEFX 2744CCD4-9D8A-4E74-803C-0ECBEEA19C54 */\n#define XR_CODEC_GUID_IMAGE_REMOTEFX \\\n    \"\\xD4\\xCC\\x44\\x27\\x8A\\x9D\\x74\\x4E\\x80\\x3C\\x0E\\xCB\\xEE\\xA1\\x9C\\x54\"\n\n/* MFVideoFormat_H264  34363248-0000-0010-8000-00AA00389B71 */\n#define XR_CODEC_GUID_H264 \\\n    \"\\x48\\x32\\x36\\x34\\x00\\x00\\x10\\x00\\x80\\x00\\x00\\xAA\\x00\\x38\\x9B\\x71\"\n\n/* CODEC_GUID_JPEG     1BAF4CE6-9EED-430C-869A-CB8B37B66237 */\n#define XR_CODEC_GUID_JPEG \\\n    \"\\xE6\\x4C\\xAF\\x1B\\xED\\x9E\\x0C\\x43\\x86\\x9A\\xCB\\x8B\\x37\\xB6\\x62\\x37\"\n\n/* CODEC_GUID_PNG      0E0C858D-28E0-45DB-ADAA-0F83E57CC560 */\n#define XR_CODEC_GUID_PNG \\\n    \"\\x8D\\x85\\x0C\\x0E\\xE0\\x28\\xDB\\x45\\xAD\\xAA\\x0F\\x83\\xE5\\x7C\\xC5\\x60\"\n\n/* CODEC_GUID_IGNORE   0C4351A6-3535-42AE-910C-CDFCE5760B58 */\n#define XR_CODEC_GUID_IGNORE \\\n    \"\\xA6\\x51\\x43\\x0C\\x35\\x35\\xAE\\x42\\x91\\x0C\\xCD\\xFC\\xE5\\x76\\x0B\\x58\"\n\n/* PDU Types (2.2.8.1.1.1.1) */\n#define PDUTYPE_DEMANDACTIVEPDU        0x1\n#define PDUTYPE_CONFIRMACTIVEPDU       0x3\n#define PDUTYPE_DEACTIVATEALLPDU       0x6\n#define PDUTYPE_DATAPDU                0x7\n#define PDUTYPE_SERVER_REDIR_PKT       0xA\n\n#define PDUTYPE_TO_STR(pdu_type) \\\n    ((pdu_type) == PDUTYPE_DEMANDACTIVEPDU ? \"PDUTYPE_DEMANDACTIVEPDU\" : \\\n     (pdu_type) == PDUTYPE_CONFIRMACTIVEPDU ? \"PDUTYPE_CONFIRMACTIVEPDU\" : \\\n     (pdu_type) == PDUTYPE_DEACTIVATEALLPDU ? \"PDUTYPE_DEACTIVATEALLPDU\" : \\\n     (pdu_type) == PDUTYPE_DATAPDU ? \"PDUTYPE_DATAPDU\" : \\\n     (pdu_type) == PDUTYPE_SERVER_REDIR_PKT ? \"PDUTYPE_SERVER_REDIR_PKT\" : \\\n     \"unknown\" \\\n    )\n\n/* Share Data Header: pduType2 (2.2.8.1.1.1.2) */\n#define PDUTYPE2_UPDATE                2\n#define PDUTYPE2_CONTROL               20\n#define PDUTYPE2_POINTER               27\n#define PDUTYPE2_INPUT                 28\n#define PDUTYPE2_SYNCHRONISE           31\n#define PDUTYPE2_REFRESH_RECT          33\n#define PDUTYPE2_PLAY_SOUND            34\n#define PDUTYPE2_SUPPRESS_OUTPUT       35\n#define PDUTYPE2_SHUTDOWN_REQUEST      36\n#define PDUTYPE2_SHUTDOWN_DENIED       37\n#define PDUTYPE2_SAVE_SESSION_INFO     38\n#define PDUTYPE2_FONTLIST              39\n#define PDUTYPE2_SET_ERROR_INFO_PDU    47\n#define PDUTYPE2_MONITOR_LAYOUT_PDU    55\n#define PDUTYPE2_FRAME_ACKNOWLEDGE     56 /* From [MS-RDPRFX] */\n\n/* TS_SECURITY_HEADER: flags (2.2.8.1.1.2.1) */\n#define SEC_EXCHANGE_PKT               0x0001\n#define SEC_ENCRYPT                    0x0008\n#define SEC_INFO_PKT                   0x0040\n#define SEC_LICENSE_PKT                0x0080\n#define SEC_LICENSE_ENCRYPT_CS         0x0280\n\n/* Slow-Path Input Event: messageType (2.2.8.1.1.3.1.1) */\n/* TODO: to be renamed */\n#define RDP_INPUT_SYNCHRONIZE          0\n#define RDP_INPUT_CODEPOINT            1\n#define RDP_INPUT_VIRTKEY              2\n#define RDP_INPUT_SCANCODE             4\n#define RDP_INPUT_UNICODE              5\n#define RDP_INPUT_MOUSE                0x8001\n#define RDP_INPUT_MOUSEX               0x8002\n\n/* Keyboard Event: keyboardFlags (2.2.8.1.1.3.1.1.1) */\n#define KBDFLAGS_EXTENDED              0x0100\n#define KBDFLAGS_EXTENDED1             0x0200\n#define KBDFLAGS_DOWN                  0x4000\n#define KBDFLAGS_RELEASE               0x8000\n\n/* Mouse Event: pointerFlags (2.2.8.1.1.3.1.1.3) */\n#define PTRFLAGS_HWHEEL                0x0400\n#define PTRFLAGS_WHEEL                 0x0200\n#define PTRFLAGS_WHEEL_NEGATIVE        0x0100\n#define WheelRotationMask              0x01FF\n#define PTRFLAGS_MOVE                  0x0800\n#define PTRFLAGS_DOWN                  0x8000\n#define PTRFLAGS_BUTTON1               0x1000\n#define PTRFLAGS_BUTTON2               0x2000\n#define PTRFLAGS_BUTTON3               0x4000\n\n/* Extended Mouse Event: pointerFlags (2.2.8.1.1.3.1.1.4) */\n#define PTRXFLAGS_DOWN                 0x8000\n#define PTRXFLAGS_BUTTON1              0x0001\n#define PTRXFLAGS_BUTTON2              0x0002\n\n/* Synchronize Event: toggleFlags (2.2.8.1.1.3.1.1.5) */\n#define TS_SYNC_SCROLL_LOCK            0x0001\n#define TS_SYNC_NUM_LOCK               0x0002\n#define TS_SYNC_CAPS_LOCK              0x0004\n#define TS_SYNC_KANA_LOCK              0x0008\n\n/* Client Fast-Path Input Event PDU 2.2.8.1.2 */\n#define FASTPATH_INPUT_ENCRYPTED            0x2\n\n/* Fast-Path Input Event: eventCode (2.2.8.1.2.2) */\n#define FASTPATH_INPUT_EVENT_SCANCODE       0x0\n#define FASTPATH_INPUT_EVENT_MOUSE          0x1\n#define FASTPATH_INPUT_EVENT_MOUSEX         0x2\n#define FASTPATH_INPUT_EVENT_SYNC           0x3\n#define FASTPATH_INPUT_EVENT_UNICODE        0x4\n#define FASTPATH_INPUT_EVENT_QOE_TIMESTAMP  0x6\n\n/* Fast-Path Keyboard Event: eventHeader (2.2.8.1.2.2.1) */\n#define FASTPATH_INPUT_KBDFLAGS_RELEASE     0x01\n#define FASTPATH_INPUT_KBDFLAGS_EXTENDED    0x02\n#define FASTPATH_INPUT_KBDFLAGS_EXTENDED1   0x04\n\n/* Slow-Path Graphics Update: updateType (2.2.9.1.1.3.1) */\n#define UPDATETYPE_ORDERS              0\n#define UPDATETYPE_BITMAP              1\n#define UPDATETYPE_PALETTE             2\n#define UPDATETYPE_SYNCHRONIZE         3\n\n#define GRAPHICS_UPDATE_TYPE_TO_STR(type) \\\n    ((type) == UPDATETYPE_ORDERS ? \"UPDATETYPE_ORDERS\" : \\\n     (type) == UPDATETYPE_BITMAP ? \"UPDATETYPE_BITMAP\" : \\\n     (type) == UPDATETYPE_PALETTE ? \"UPDATETYPE_PALETTE\" : \\\n     (type) == UPDATETYPE_SYNCHRONIZE ? \"UPDATETYPE_SYNCHRONIZE\" : \\\n     \"unknown\" \\\n    )\n\n/* Server Pointer Update PDU: messageType (2.2.9.1.1.4) */\n#define TS_PTRMSGTYPE_SYSTEM           1\n#define TS_PTRMSGTYPE_POSITION         3\n#define TS_PTRMSGTYPE_COLOR            6\n#define TS_PTRMSGTYPE_CACHED           7\n#define TS_PTRMSGTYPE_POINTER          8\n\n/* System Pointer Update: systemPointerType (2.2.9.1.1.4.3) */\n/* These may also be defined by freerdp */\n#ifndef SYSPTR_NULL\n#define SYSPTR_NULL                    0\n#define SYSPTR_DEFAULT                 0x7F00\n#endif\n\n/* Server Fast-Path Update PDU: action (2.2.9.1.2) */\n#define FASTPATH_OUTPUT_ACTION_FASTPATH     0x0\n#define FASTPATH_OUTPUT_ACTION_X224         0x3\n\n/* Server Fast-Path Update PDU: flags (2.2.9.1.2) */\n#define FASTPATH_OUTPUT_SECURE_CHECKSUM     0x1\n#define FASTPATH_OUTPUT_ENCRYPTED           0x2\n\n/* Fast-Path Update: updateCode (2.2.9.1.2.1) */\n#define FASTPATH_UPDATETYPE_ORDERS        0x0\n#define FASTPATH_UPDATETYPE_BITMAP        0x1\n#define FASTPATH_UPDATETYPE_PALETTE       0x2\n#define FASTPATH_UPDATETYPE_SYNCHRONIZE   0x3\n#define FASTPATH_UPDATETYPE_SURFCMDS      0x4\n#define FASTPATH_UPDATETYPE_PTR_NULL      0x5\n#define FASTPATH_UPDATETYPE_PTR_DEFAULT   0x6\n#define FASTPATH_UPDATETYPE_PTR_POSITION  0x8\n#define FASTPATH_UPDATETYPE_COLOR         0x9\n#define FASTPATH_UPDATETYPE_CACHED        0xA\n#define FASTPATH_UPDATETYPE_POINTER       0xB\n\n/* Fast-Path Update: fragmentation (2.2.9.1.2.1) */\n#define FASTPATH_FRAGMENT_SINGLE          0x0\n#define FASTPATH_FRAGMENT_LAST            0x1\n#define FASTPATH_FRAGMENT_FIRST           0x2\n#define FASTPATH_FRAGMENT_NEXT            0x3\n#define FASTPATH_OUTPUT_COMPRESSION_USED  0x2\n\n/* Surface Command Type (2.2.9.1.2.1.10.1) */\n#define CMDTYPE_SET_SURFACE_BITS       0x0001\n#define CMDTYPE_FRAME_MARKER           0x0004\n#define CMDTYPE_STREAM_SURFACE_BITS    0x0006\n\n/* Compression Flags (3.1.8.2.1) */\n/* TODO: to be renamed, not used anywhere */\n#define RDP_MPPC_COMPRESSED            0x20\n#define RDP_MPPC_RESET                 0x40\n#define RDP_MPPC_FLUSH                 0x80\n#define RDP_MPPC_DICT_SIZE             8192 /* RDP 4.0 | MS-RDPBCGR 3.1.8 */\n\n/* largePointerSupprtFlags (2.2.7.2.7) */\n#define LARGE_POINTER_FLAG_96x96   0x00000001\n#define LARGE_POINTER_FLAG_384x384 0x00000002\n\n#endif /* MS_RDPBCGR_H */\n"
  },
  {
    "path": "common/ms-rdpeclip.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-RDPECLIP : Definitions from [MS-RDPECLIP]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-RDPECLIP are currently correct for v220210407 of that\n * document\n */\n\n#if !defined(MS_RDPECLIP_H)\n#define MS_RDPECLIP_H\n\n/* Clipboard PDU header message codes 2.2.1 */\n#define CB_MONITOR_READY         1\n#define CB_FORMAT_LIST           2\n#define CB_FORMAT_LIST_RESPONSE  3\n#define CB_FORMAT_DATA_REQUEST   4\n#define CB_FORMAT_DATA_RESPONSE  5\n#define CB_TEMP_DIRECTORY        6\n#define CB_CLIP_CAPS             7\n#define CB_FILECONTENTS_REQUEST  8\n#define CB_FILECONTENTS_RESPONSE 9\n#define CB_LOCK_CLIPDATA         10\n#define CB_UNLOCK_CLIPDATA       11\n\n#define CB_PDUTYPE_TO_STR(pdu_type) \\\n    ((pdu_type) == CB_MONITOR_READY ? \"CB_MONITOR_READY\" : \\\n     (pdu_type) == CB_FORMAT_LIST ? \"CB_FORMAT_LIST\" : \\\n     (pdu_type) == CB_FORMAT_LIST_RESPONSE ? \"CB_FORMAT_LIST_RESPONSE\" : \\\n     (pdu_type) == CB_FORMAT_DATA_REQUEST ? \"CB_FORMAT_DATA_REQUEST\" : \\\n     (pdu_type) == CB_FORMAT_DATA_RESPONSE ? \"CB_FORMAT_DATA_RESPONSE\" : \\\n     (pdu_type) == CB_TEMP_DIRECTORY ? \"CB_TEMP_DIRECTORY\" : \\\n     (pdu_type) == CB_CLIP_CAPS ? \"CB_CLIP_CAPS\" : \\\n     (pdu_type) == CB_FILECONTENTS_REQUEST ? \"CB_FILECONTENTS_REQUEST\" : \\\n     (pdu_type) == CB_FILECONTENTS_RESPONSE ? \"CB_FILECONTENTS_RESPONSE\" : \\\n     (pdu_type) == CB_LOCK_CLIPDATA ? \"CB_LOCK_CLIPDATA\" : \\\n     (pdu_type) == CB_UNLOCK_CLIPDATA ? \"CB_UNLOCK_CLIPDATA\" : \\\n     \"unknown\" \\\n    )\n\n/* Clipboard PDU header message flags 2.2.1 */\n#define CB_RESPONSE_OK 0x0001\n#define CB_RESPONSE_FAIL 0x0002\n#define CB_ASCII_NAMES 0x0004\n\n/* Capability set codes 2.2.2.1.1 */\n#define CB_CAPSTYPE_GENERAL 1\n#define CB_CAPS_VERSION_1 1\n#define CB_CAPS_VERSION_2 2\n\n/* General capability set general flags 2.2.2.1.1.1 */\n#define CB_USE_LONG_FORMAT_NAMES   0x00000002\n#define CB_STREAM_FILECLIP_ENABLED 0x00000004\n#define CB_FILECLIP_NO_FILE_PATHS  0x00000008\n#define CB_CAN_LOCK_CLIPDATA       0x00000010\n\n/* File contents request PDU 2.2.5.3 */\n/* Note that in the document these do not have a CB_ prefix */\n#define CB_FILECONTENTS_SIZE 0x00000001\n#define CB_FILECONTENTS_RANGE 0x00000002\n\n/* File descriptor structure flags 2.2.5.2.3.1 */\n/* Note that in the document these do not have a CB_ prefix */\n#define CB_FD_ATTRIBUTES 0x00000004\n#define CB_FD_FILESIZE   0x00000040\n#define CB_FD_WRITESTIME 0x00000020\n#define CB_FD_PROGRESSUI 0x00004000\n\n/* File descriptor structure file attributes 2.2.5.2.3.1 */\n/* Note that in the document these do not have a CB_ prefix */\n#define CB_FILE_ATTRIBUTE_READONLY  0x00000001\n#define CB_FILE_ATTRIBUTE_HIDDEN    0x00000002\n#define CB_FILE_ATTRIBUTE_SYSTEM    0x00000004\n#define CB_FILE_ATTRIBUTE_DIRECTORY 0x00000010\n#define CB_FILE_ATTRIBUTE_ARCHIVE   0x00000020\n#define CB_FILE_ATTRIBUTE_NORMAL    0x00000080\n\n#endif /* MS_RDPECLIP_H */\n"
  },
  {
    "path": "common/ms-rdpedisp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-RDPEDISP : Definitions from [MS-RDPEDISP]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-RDPEDISP are currently correct for v20201030 of that\n * document\n */\n\n#if !defined(MS_RDPEDISP_H)\n#define MS_RDPEDISP_H\n\n/* Display Control Messages: Display Virtual Channel Extension (2.2.2) */\n#define DISPLAYCONTROL_PDU_TYPE_MONITOR_LAYOUT             0x00000002\n#define DISPLAYCONTROL_PDU_TYPE_CAPS                       0x00000005\n\n/* Display Control Monitor Layout (2.2.2.2.1) */\n#define DISPLAYCONTROL_MONITOR_PRIMARY                     0x00000001\n#define CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_MONITOR_WIDTH  0xC8\n#define CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_MONITOR_HEIGHT 0xC8\n#define CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_MONITOR_WIDTH  0x2000\n#define CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_MONITOR_HEIGHT 0x2000\n\n#define ORIENTATION_LANDSCAPE                              0\n#define ORIENTATION_PORTRAIT                               90\n#define ORIENTATION_LANDSCAPE_FLIPPED                      180\n#define ORIENTATION_PORTRAIT_FLIPPED                       270\n\n/* Display Control Monitor Layout (2.2.2.2.1) */\n#define DISPLAYCONTROL_MONITOR_PRIMARY                     0x00000001\n\n#endif /* MS_RDPEDISP_H */\n"
  },
  {
    "path": "common/ms-rdpefs.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-RDPEFS : Definitions from [MS-RDPEFS]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-RDPEFS are currently correct for v20180912 of that\n * document\n */\n\n#if !defined(MS_RDPEFS_H)\n#define MS_RDPEFS_H\n\n/*\n * RDPDR_HEADER definitions (2.2.1.1)\n */\n\n/* device redirector core component; most of the packets in this protocol */\n/* are sent under this component ID                                       */\n#define RDPDR_CTYP_CORE                 0x4472\n\n/* printing component. the packets that use this ID are typically about   */\n/* printer cache management and identifying XPS printers                  */\n#define RDPDR_CTYP_PRN                  0x5052\n\n/* Server Announce Request, as specified in section 2.2.2.2               */\n#define PAKID_CORE_SERVER_ANNOUNCE      0x496E\n\n/* Client Announce Reply and Server Client ID Confirm, as specified in    */\n/* sections 2.2.2.3 and 2.2.2.6.                                          */\n#define PAKID_CORE_CLIENTID_CONFIRM     0x4343\n\n/* Client Name Request, as specified in section 2.2.2.4                   */\n#define PAKID_CORE_CLIENT_NAME          0x434E\n\n/* Client Device List Announce Request, as specified in section 2.2.2.9   */\n#define PAKID_CORE_DEVICELIST_ANNOUNCE  0x4441\n\n/* Server Device Announce Response, as specified in section 2.2.2.1       */\n#define PAKID_CORE_DEVICE_REPLY         0x6472\n\n/* Device I/O Request, as specified in section 2.2.1.4                    */\n#define PAKID_CORE_DEVICE_IOREQUEST     0x4952\n\n/* Device I/O Response, as specified in section 2.2.1.5                   */\n#define PAKID_CORE_DEVICE_IOCOMPLETION  0x4943\n\n/* Server Core Capability Request, as specified in section 2.2.2.7        */\n#define PAKID_CORE_SERVER_CAPABILITY    0x5350\n\n/* Client Core Capability Response, as specified in section 2.2.2.8       */\n#define PAKID_CORE_CLIENT_CAPABILITY    0x4350\n\n/* Client Drive Device List Remove, as specified in section 2.2.3.2       */\n#define PAKID_CORE_DEVICELIST_REMOVE    0x444D\n\n/* Add Printer Cachedata, as specified in [MS-RDPEPC] section 2.2.2.3     */\n#define PAKID_PRN_CACHE_DATA            0x5043\n\n/* Server User Logged On, as specified in section 2.2.2.5                 */\n#define PAKID_CORE_USER_LOGGEDON        0x554C\n\n/* Server Printer Set XPS Mode, as specified in [MS-RDPEPC] section 2.2.2.2 */\n#define PAKID_PRN_USING_XPS             0x5543\n\n/*\n * Capability header definitions (2.2.1.2)\n */\n\n#define CAP_GENERAL_TYPE   0x0001 /* General cap set - GENERAL_CAPS_SET      */\n#define CAP_PRINTER_TYPE   0x0002 /* Print cap set - PRINTER_CAPS_SET        */\n#define CAP_PORT_TYPE      0x0003 /* Port cap set - PORT_CAPS_SET            */\n#define CAP_DRIVE_TYPE     0x0004 /* Drive cap set - DRIVE_CAPS_SET          */\n#define CAP_SMARTCARD_TYPE 0x0005 /* Smart card cap set - SMARTCARD_CAPS_SET */\n\n/*\n * Device announce header (2.2.1.3)\n */\n#define RDPDR_DTYP_SERIAL               0x0001\n#define RDPDR_DTYP_PARALLEL             0x0002\n#define RDPDR_DTYP_PRINT                0x0004\n#define RDPDR_DTYP_FILESYSTEM           0x0008\n#define RDPDR_DTYP_SMARTCARD            0x0020\n\n/* Device I/O Request definitions (2.2.1.4) */\n/* MajorFunction */\nenum IRP_MJ\n{\n    IRP_MJ_CREATE                   = 0x00000000,\n    IRP_MJ_CLOSE                    = 0x00000002,\n    IRP_MJ_READ                     = 0x00000003,\n    IRP_MJ_WRITE                    = 0x00000004,\n    IRP_MJ_DEVICE_CONTROL           = 0x0000000E,\n    IRP_MJ_QUERY_VOLUME_INFORMATION = 0x0000000A,\n    IRP_MJ_SET_VOLUME_INFORMATION   = 0x0000000B,\n    IRP_MJ_QUERY_INFORMATION        = 0x00000005,\n    IRP_MJ_SET_INFORMATION          = 0x00000006,\n    IRP_MJ_DIRECTORY_CONTROL        = 0x0000000C,\n    IRP_MJ_LOCK_CONTROL             = 0x00000011\n};\n\n/* MinorFunction */\n/* Set to zero unless MajorFunction code == IRP_MJ_DIRECTORY_CONTROL */\nenum IRP_MN\n{\n    IRP_MN_NONE                     = 0x00000000, /* Name not in MS docs */\n    IRP_MN_QUERY_DIRECTORY          = 0x00000001,\n    IRP_MN_NOTIFY_CHANGE_DIRECTORY  = 0x00000002\n};\n\n/*\n * General Capability Set (2.2.2.7.1)\n */\n/* extendedPDU fields */\n#define RDPDR_USER_LOGGEDON_PDU         0x00000004\n\n#endif /* MS_RDPEFS_H */\n"
  },
  {
    "path": "common/ms-rdpegdi.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-RDPEGDI : Definitions from [MS-RDPEGDI]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-RDPEGDI are currently correct for v20180912 of that\n * document\n */\n\n#if !defined(MS_RDPEGDI_H)\n#define MS_RDPEGDI_H\n\n/* Drawing Order: controlFlags (2.2.2.2.1, 2.2.2.2.1.1.2) */\n#define TS_STANDARD                     0x01\n#define TS_SECONDARY                    0x02\n#define TS_BOUNDS                       0x04\n#define TS_TYPE_CHANGE                  0x08\n#define TS_DELTA_COORDINATES            0x10\n#define TS_ZERO_BOUNDS_DELTAS           0x20\n#define TS_ZERO_FIELD_BYTE_BIT0         0x40\n#define TS_ZERO_FIELD_BYTE_BIT1         0x80\n\n/* Drawing Order: orderType (2.2.2.2.1.1.2) */\n/* Should be renamed */\n#define RDP_ORDER_DESTBLT   0 /* TS_ENC_DSTBLT_ORDER */\n#define RDP_ORDER_PATBLT    1\n#define RDP_ORDER_SCREENBLT 2\n#define RDP_ORDER_LINE      9\n#define RDP_ORDER_RECT      10\n#define RDP_ORDER_DESKSAVE  11\n#define RDP_ORDER_MEMBLT    13\n#define RDP_ORDER_TRIBLT    14\n#define RDP_ORDER_POLYLINE  22\n#define RDP_ORDER_TEXT2     27\n#define RDP_ORDER_COMPOSITE 37 /* 0x25  - not defined in RDPEGDI */\n\n/* Secondary Drawing Order Header: orderType (2.2.2.2.1.2.1.1) */\n#define TS_CACHE_BITMAP_UNCOMPRESSED        0x00\n#define TS_CACHE_COLOR_TABLE                0x01\n#define TS_CACHE_BITMAP_COMPRESSED          0x02\n#define TS_CACHE_GLYPH                      0x03\n#define TS_CACHE_BITMAP_UNCOMPRESSED_REV2   0x04\n#define TS_CACHE_BITMAP_COMPRESSED_REV2     0x05\n#define TS_CACHE_BRUSH                      0x07\n#define TS_CACHE_BITMAP_COMPRESSED_REV3     0x08\n\n#endif /* MS_RDPEGDI_H */\n"
  },
  {
    "path": "common/ms-rdpele.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-RDPELE : Definitions from [MS-RDPELE]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-RDPELE are currently correct for v20180912 of that\n * document\n */\n\n#if !defined(MS_RDPELE_H)\n#define MS_RDPELE_H\n\n/* LicensingMessage (MS-RDPELE 2.2.2) */\n/* TODO: to be renamed */\n#define LICENCE_TAG_DEMAND             0x01 /* LICENSE_REQUEST */\n#define LICENCE_TAG_AUTHREQ            0x02 /* PLATFORM_CHALLENGE */\n#define LICENCE_TAG_ISSUE              0x03 /* NEW_LICENSE */\n#define LICENCE_TAG_REISSUE            0x04 /* UPGRADE_LICENSE */\n#define LICENCE_TAG_PRESENT            0x12 /* LICENSE_INFO */\n#define LICENCE_TAG_REQUEST            0x13 /* NEW_LICENSE_REQUEST */\n#define LICENCE_TAG_AUTHRESP           0x15 /* PLATFORM_CHALLENGE_RESPONSE */\n#define LICENCE_TAG_RESULT             0xff\n\n#endif /* MS_RDPELE_H */\n"
  },
  {
    "path": "common/ms-rdperp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-RDPERP : Definitions from [MS-RDPERP]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-RDPERP are currently correct for v20190923 of that\n * document\n */\n\n#if !defined(MS_RDPERP_H)\n#define MS_RDPERP_H\n\n/* Window List Capability Set: WndSupportLevel (2.2.1.1.2) */\n#define TS_WINDOW_LEVEL_NOT_SUPPORTED  0x00000000\n#define TS_WINDOW_LEVEL_SUPPORTED      0x00000001\n#define TS_WINDOW_LEVEL_SUPPORTED_EX   0x00000002\n\n\n#endif /* MS_RDPERP_H */\n"
  },
  {
    "path": "common/ms-smb2.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-SMB2 : Definitions from [MS-SMB2]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-SMB2 are currently correct for v20190923 of that\n * document\n */\n\n#if !defined(MS_SMB2_H)\n#define MS_SMB2_H\n\n/* SMB2 CREATE request values (section 2.2.13) */\n\n/*\n * ShareAccess Mask. Currently, this is referred\n * to in MS-RDPEFS 2.2.1.4.1 as 'SharedAccess' rather than 'ShareAccess'.\n */\n#define SA_FILE_SHARE_READ              0x00000001\n#define SA_FILE_SHARE_WRITE             0x00000002\n#define SA_FILE_SHARE_DELETE            0x00000004\n\n/* CreateDisposition Mask */\n#define CD_FILE_SUPERSEDE               0x00000000\n#define CD_FILE_OPEN                    0x00000001\n#define CD_FILE_CREATE                  0x00000002\n#define CD_FILE_OPEN_IF                 0x00000003\n#define CD_FILE_OVERWRITE               0x00000004\n#define CD_FILE_OVERWRITE_IF            0x00000005\n\n/* CreateOptions Mask */\nenum CREATE_OPTIONS\n{\n    CO_FILE_DIRECTORY_FILE          = 0x00000001,\n    CO_FILE_WRITE_THROUGH           = 0x00000002,\n    CO_FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020,\n    CO_FILE_DELETE_ON_CLOSE         = 0x00001000\n};\n\n/*\n * DesiredAccess Mask (section 2.2.13.1.1)\n */\n\n#define DA_FILE_READ_DATA               0x00000001\n#define DA_FILE_WRITE_DATA              0x00000002\n#define DA_FILE_APPEND_DATA             0x00000004\n#define DA_FILE_READ_EA                 0x00000008 /* rd extended attributes */\n#define DA_FILE_WRITE_EA                0x00000010 /* wr extended attributes */\n#define DA_FILE_EXECUTE                 0x00000020\n#define DA_FILE_READ_ATTRIBUTES         0x00000080\n#define DA_FILE_WRITE_ATTRIBUTES        0x00000100\n#define DA_DELETE                       0x00010000\n#define DA_READ_CONTROL                 0x00020000 /* rd security descriptor */\n#define DA_WRITE_DAC                    0x00040000\n#define DA_WRITE_OWNER                  0x00080000\n#define DA_SYNCHRONIZE                  0x00100000\n#define DA_ACCESS_SYSTEM_SECURITY       0x01000000\n#define DA_MAXIMUM_ALLOWED              0x02000000\n#define DA_GENERIC_ALL                  0x10000000\n#define DA_GENERIC_EXECUTE              0x20000000\n#define DA_GENERIC_WRITE                0x40000000\n#define DA_GENERIC_READ                 0x80000000\n\n#endif /* MS_SMB2_H */\n\n\n\n"
  },
  {
    "path": "common/os_calls.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * generic operating system calls\n *\n * put all the os / arch define in here you want\n */\n\n/* To test for Windows (64 bit or 32 bit) use _WIN32 and _WIN64 in addition\n   for 64 bit windows.  _WIN32 is defined for both.\n   To test for Linux use __linux__.\n   To test for BSD use BSD */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n#if defined(_WIN32)\n#include <windows.h>\n#include <winsock.h>\n#else\n/* fix for solaris 10 with gcc 3.3.2 problem */\n#if defined(sun) || defined(__sun)\n#define ctid_t id_t\n#endif\n#include <unistd.h>\n#include <dirent.h>\n#include <errno.h>\n#include <netinet/in.h>\n#include <netinet/tcp.h>\n#include <sys/socket.h>\n#if defined(XRDP_ENABLE_VSOCK)\n#if defined(__linux__)\n#include <linux/vm_sockets.h>\n#elif defined(__FreeBSD__)\n// sockaddr_hvs is not available outside the kernel for whatever reason\nstruct sockaddr_hvs\n{\n    unsigned char sa_len;\n    sa_family_t   sa_family;\n    unsigned int  hvs_port;\n    unsigned char hvs_zero[sizeof(struct sockaddr) -  sizeof(sa_family_t) - sizeof(unsigned char) - sizeof(unsigned int)];\n};\n#endif\n#endif\n#include <poll.h>\n#include <sys/un.h>\n#include <sys/time.h>\n#include <sys/times.h>\n#include <sys/types.h>\n#include <sys/wait.h>\n#include <sys/stat.h>\n#include <sys/ipc.h>\n#include <sys/shm.h>\n#if defined(HAVE_SYS_PRCTL_H)\n#include <sys/prctl.h>\n#endif\n#include <sys/mman.h>\n#include <dlfcn.h>\n#include <arpa/inet.h>\n#include <netdb.h>\n#include <signal.h>\n#include <fcntl.h>\n#include <pwd.h>\n#include <time.h>\n#include <grp.h>\n#endif\n#ifdef HAVE_SETUSERCONTEXT\n#include <login_cap.h>\n#endif\n\n#include <stdlib.h>\n#include <string.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <locale.h>\n\n/* this is so we can use #ifdef BSD later */\n/* This is the recommended way of detecting BSD in the\n   FreeBSD Porter's Handbook. */\n#if (defined(__unix__) || defined(unix)) && !defined(USG)\n#include <sys/param.h>\n#endif\n\n#include \"os_calls.h\"\n#include <limits.h>\n#include \"string_calls.h\"\n#include \"log.h\"\n#include \"xrdp_constants.h\"\n\n#if defined(__linux__)\n#include <linux/unistd.h>\n#endif\n\n/* sys/ucred.h needs to be included to use struct xucred\n * in FreeBSD and OS X. No need for other BSDs except GNU/kFreeBSD */\n#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)\n#include <sys/ucred.h>\n#endif\n\n/* for solaris */\n#if !defined(PF_LOCAL)\n#define PF_LOCAL AF_UNIX\n#endif\n#if !defined(INADDR_NONE)\n#define INADDR_NONE ((unsigned long)-1)\n#endif\n\n// MacOS uses a different type for getgrouplist() than getgroups(). This\n// appears to be the only platform which does this.\n#ifdef __APPLE__\n#    define GETGROUPLIST_T int\n#else\n#    define GETGROUPLIST_T GETGROUPS_T\n#endif\n\n/**\n * Type big enough to hold socket address information for any connecting type\n */\nunion sock_info\n{\n    struct sockaddr sa;\n    struct sockaddr_in sa_in;\n#if defined(XRDP_ENABLE_IPV6)\n    struct sockaddr_in6 sa_in6;\n#endif\n    struct sockaddr_un sa_un;\n#if defined(XRDP_ENABLE_VSOCK)\n#if defined(__linux__)\n    struct sockaddr_vm sa_vm;\n#elif defined(__FreeBSD__)\n    struct sockaddr_hvs sa_hvs;\n#endif\n#endif\n};\n\n/******************************************************************************/\nstatic oom_type g_out_of_memory_handler;\n\n/*****************************************************************************/\nint\ng_rm_temp_dir(void)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nvoid\ng_init(const char *app_name)\n{\n#if defined(_WIN32)\n    WSADATA wsadata;\n\n    WSAStartup(2, &wsadata);\n#endif\n#if defined(XRDP_NVENC)\n    if (g_strcmp(app_name, \"xrdp-sesman\") == 0)\n    {\n        /* call cuInit() to initalize the nvidia drivers */\n        /* TODO create an issue on nvidia forums to figure out why we need to\n        *  do this */\n        if (g_fork() == 0)\n        {\n            typedef int (*cu_init_proc)(int flags);\n            cu_init_proc cu_init;\n            long lib;\n            char cuda_lib_name[] = \"libcuda.so\";\n            char cuda_func_name[] = \"cuInit\";\n\n            lib = g_load_library(cuda_lib_name);\n            if (lib != 0)\n            {\n                cu_init = (cu_init_proc)\n                          g_get_proc_address(lib, cuda_func_name);\n                if (cu_init != NULL)\n                {\n                    cu_init(0);\n                }\n            }\n            log_end();\n            g_deinit();\n            g_exit(0);\n        }\n    }\n#endif\n}\n\n/*****************************************************************************/\nvoid\ng_deinit(void)\n{\n#if defined(_WIN32)\n    WSACleanup();\n#endif\n    fflush(stdout);\n    fflush(stderr);\n    g_rm_temp_dir();\n}\n\n/*****************************************************************************/\n/* output text to stdout, try to use g_write / g_writeln instead to avoid\n   linux / windows EOL problems */\nvoid\ng_printf(const char *format, ...)\n{\n    va_list ap;\n\n    va_start(ap, format);\n    vfprintf(stdout, format, ap);\n    va_end(ap);\n}\n\n/*****************************************************************************/\nvoid\ng_sprintf(char *dest, const char *format, ...)\n{\n    va_list ap;\n\n    va_start(ap, format);\n    vsprintf(dest, format, ap);\n    va_end(ap);\n}\n\n/*****************************************************************************/\nint\ng_snprintf(char *dest, int len, const char *format, ...)\n{\n    int err;\n    va_list ap;\n\n    va_start(ap, format);\n    err = vsnprintf(dest, len, format, ap);\n    va_end(ap);\n\n    return err;\n}\n\n/*****************************************************************************/\nvoid\ng_writeln(const char *format, ...)\n{\n    va_list ap;\n\n    va_start(ap, format);\n    vfprintf(stdout, format, ap);\n    va_end(ap);\n#if defined(_WIN32)\n    g_printf(\"\\r\\n\");\n#else\n    g_printf(\"\\n\");\n#endif\n}\n\n/*****************************************************************************/\nvoid\ng_write(const char *format, ...)\n{\n    va_list ap;\n\n    va_start(ap, format);\n    vfprintf(stdout, format, ap);\n    va_end(ap);\n}\n\n/*****************************************************************************/\n/* print a hex dump to stdout*/\nvoid\ng_hexdump(const char *p, int len)\n{\n    unsigned char *line;\n    int i;\n    int thisline;\n    int offset;\n\n    line = (unsigned char *)p;\n    offset = 0;\n\n    while (offset < len)\n    {\n        g_printf(\"%04x \", offset);\n        thisline = len - offset;\n\n        if (thisline > 16)\n        {\n            thisline = 16;\n        }\n\n        for (i = 0; i < thisline; i++)\n        {\n            g_printf(\"%02x \", line[i]);\n        }\n\n        for (; i < 16; i++)\n        {\n            g_printf(\"   \");\n        }\n\n        for (i = 0; i < thisline; i++)\n        {\n            g_printf(\"%c\", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');\n        }\n\n        g_writeln(\"%s\", \"\");\n        offset += thisline;\n        line += thisline;\n    }\n}\n\n/*****************************************************************************/\nint\ng_getchar(void)\n{\n    return getchar();\n}\n\n/*****************************************************************************/\n/*Returns 0 on success*/\nint\ng_tcp_set_no_delay(int sck)\n{\n    int ret = 1; /* error */\n    int option_value;\n    socklen_t option_len;\n\n    option_len = sizeof(option_value);\n\n    /* SOL_TCP IPPROTO_TCP */\n    if (getsockopt(sck, IPPROTO_TCP, TCP_NODELAY, (char *)&option_value,\n                   &option_len) == 0)\n    {\n        if (option_value == 0)\n        {\n            option_value = 1;\n            option_len = sizeof(option_value);\n\n            if (setsockopt(sck, IPPROTO_TCP, TCP_NODELAY, (char *)&option_value,\n                           option_len) == 0)\n            {\n                ret = 0; /* success */\n            }\n            else\n            {\n                LOG(LOG_LEVEL_ERROR, \"Error setting tcp_nodelay\");\n            }\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error getting tcp_nodelay\");\n    }\n\n    return ret;\n}\n\n/*****************************************************************************/\n/*Returns 0 on success*/\nint\ng_tcp_set_keepalive(int sck)\n{\n    int ret = 1; /* error */\n    int option_value;\n    socklen_t option_len;\n\n    option_len = sizeof(option_value);\n\n    /* SOL_TCP IPPROTO_TCP */\n    if (getsockopt(sck, SOL_SOCKET, SO_KEEPALIVE, (char *)&option_value,\n                   &option_len) == 0)\n    {\n        if (option_value == 0)\n        {\n            option_value = 1;\n            option_len = sizeof(option_value);\n\n            if (setsockopt(sck, SOL_SOCKET, SO_KEEPALIVE, (char *)&option_value,\n                           option_len) == 0)\n            {\n                ret = 0; /* success */\n            }\n            else\n            {\n                LOG(LOG_LEVEL_ERROR, \"Error setting tcp_keepalive\");\n            }\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error getting tcp_keepalive\");\n    }\n\n    return ret;\n}\n\n/*****************************************************************************/\n/* returns a newly created socket or -1 on error */\n/* in win32 a socket is an unsigned int, in linux, it's an int */\nint\ng_tcp_socket(void)\n{\n    int rv;\n\n#if defined(XRDP_ENABLE_IPV6)\n    rv = (int)socket(AF_INET6, SOCK_STREAM, 0);\n    if (rv < 0)\n    {\n        switch (errno)\n        {\n            case EPROTONOSUPPORT: /* if IPv6 is supported, but don't have an IPv6 address */\n            case EAFNOSUPPORT: /* if IPv6 not supported, retry IPv4 */\n                LOG(LOG_LEVEL_INFO, \"IPv6 not supported, falling back to IPv4\");\n                rv = (int)socket(AF_INET, SOCK_STREAM, 0);\n                break;\n\n            default:\n                LOG(LOG_LEVEL_ERROR, \"g_tcp_socket: %s\", g_get_strerror());\n                return -1;\n        }\n    }\n#else\n    rv = (int)socket(AF_INET, SOCK_STREAM, 0);\n#endif\n    if (rv < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"g_tcp_socket: %s\", g_get_strerror());\n        return -1;\n    }\n#if defined(XRDP_ENABLE_IPV6)\n    int option_value;\n    socklen_t option_len = sizeof(option_value);\n    if (getsockopt(rv, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&option_value,\n                   &option_len) == 0)\n    {\n        if (option_value != 0)\n        {\n#if defined(XRDP_ENABLE_IPV6ONLY)\n            option_value = 1;\n#else\n            option_value = 0;\n#endif\n            option_len = sizeof(option_value);\n            if (setsockopt(rv, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&option_value,\n                           option_len) < 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"g_tcp_socket: setsockopt() failed\");\n            }\n        }\n    }\n#endif\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_sck_set_send_buffer_bytes(int sck, int bytes)\n{\n    int option_value;\n    socklen_t option_len;\n\n    option_value = bytes;\n    option_len = sizeof(option_value);\n    if (setsockopt(sck, SOL_SOCKET, SO_SNDBUF, (char *)&option_value,\n                   option_len) != 0)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_sck_get_send_buffer_bytes(int sck, int *bytes)\n{\n    int option_value;\n    socklen_t option_len;\n\n    option_value = 0;\n    option_len = sizeof(option_value);\n    if (getsockopt(sck, SOL_SOCKET, SO_SNDBUF, (char *)&option_value,\n                   &option_len) != 0)\n    {\n        return 1;\n    }\n    *bytes = option_value;\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_sck_set_recv_buffer_bytes(int sck, int bytes)\n{\n    int option_value;\n    socklen_t option_len;\n\n    option_value = bytes;\n    option_len = sizeof(option_value);\n    if (setsockopt(sck, SOL_SOCKET, SO_RCVBUF, (char *)&option_value,\n                   option_len) != 0)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_sck_get_recv_buffer_bytes(int sck, int *bytes)\n{\n    int option_value;\n    socklen_t option_len;\n\n    option_value = 0;\n    option_len = sizeof(option_value);\n    if (getsockopt(sck, SOL_SOCKET, SO_RCVBUF, (char *)&option_value,\n                   &option_len) != 0)\n    {\n        return 1;\n    }\n    *bytes = option_value;\n    return 0;\n}\n\n/*****************************************************************************/\nint\ng_sck_set_reuseaddr(int sck)\n{\n    int rv;\n    int option_value = 1;\n    socklen_t option_len = sizeof(option_value);\n\n    rv = setsockopt(sck, SOL_SOCKET, SO_REUSEADDR,\n                    (char *) &option_value, option_len);\n    if (rv < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"g_sck_set_reuseaddr: %s\", g_get_strerror());\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nint\ng_sck_local_socket(void)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    return socket(PF_LOCAL, SOCK_STREAM, 0);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_sck_local_socketpair(int sck[2])\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    return socketpair(PF_LOCAL, SOCK_STREAM, 0, sck);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_sck_vsock_socket(void)\n{\n#if defined(XRDP_ENABLE_VSOCK)\n#if defined(__linux__)\n    LOG(LOG_LEVEL_DEBUG, \"g_sck_vsock_socket: returning Linux vsock socket\");\n    return socket(PF_VSOCK, SOCK_STREAM, 0);\n#elif defined(__FreeBSD__)\n    LOG(LOG_LEVEL_DEBUG, \"g_sck_vsock_socket: returning FreeBSD Hyper-V socket\");\n    return socket(AF_HYPERV, SOCK_STREAM, 0); // docs say to use AF_HYPERV here - PF_HYPERV does not exist\n#else\n    LOG(LOG_LEVEL_DEBUG, \"g_sck_vsock_socket: vsock enabled at compile time, but platform is unsupported\");\n    return -1;\n#endif\n#else\n    LOG(LOG_LEVEL_DEBUG, \"g_sck_vsock_socket: vsock disabled at compile time\");\n    return -1;\n#endif\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid)\n{\n#if defined(SO_PEERCRED)\n    socklen_t ucred_length;\n    struct myucred\n    {\n        pid_t pid;\n        uid_t uid;\n        gid_t gid;\n    } credentials;\n\n    ucred_length = sizeof(credentials);\n    if (getsockopt(sck, SOL_SOCKET, SO_PEERCRED, &credentials, &ucred_length))\n    {\n        return 1;\n    }\n    if (pid != 0)\n    {\n        *pid = credentials.pid;\n    }\n    if (uid != 0)\n    {\n        *uid = credentials.uid;\n    }\n    if (gid != 0)\n    {\n        *gid = credentials.gid;\n    }\n    return 0;\n#elif defined(LOCAL_PEERCRED)\n    /* FreeBSD, OS X reach here*/\n    struct xucred xucred;\n    unsigned int xucred_length;\n    xucred_length = sizeof(xucred);\n\n    if (getsockopt(sck, SOL_LOCAL, LOCAL_PEERCRED, &xucred, &xucred_length))\n    {\n        return 1;\n    }\n    if (pid != 0)\n    {\n        *pid = 0; /* can't get pid in FreeBSD, OS X */\n    }\n    if (uid != 0)\n    {\n        *uid = xucred.cr_uid;\n    }\n    if (gid != 0)\n    {\n        *gid = xucred.cr_gid;\n    }\n    return 0;\n#else\n    return 1;\n#endif\n}\n\n/*****************************************************************************/\n\nstatic const char *\nget_peer_description(const union sock_info *sock_info,\n                     char *desc, unsigned int bytes)\n{\n    if (bytes > 0)\n    {\n        int family = sock_info->sa.sa_family;\n        switch (family)\n        {\n            case AF_INET:\n            {\n                char ip[INET_ADDRSTRLEN];\n                const struct sockaddr_in *sa_in = &sock_info->sa_in;\n                if (inet_ntop(family, &sa_in->sin_addr,\n                              ip, sizeof(ip)) != NULL)\n                {\n                    g_snprintf(desc, bytes, \"%s:%d\", ip,\n                               ntohs(sa_in->sin_port));\n                }\n                else\n                {\n                    g_snprintf(desc, bytes, \"<unknown AF_INET>:%d\",\n                               ntohs(sa_in->sin_port));\n                }\n                break;\n            }\n\n#if defined(XRDP_ENABLE_IPV6)\n            case AF_INET6:\n            {\n                char ip[INET6_ADDRSTRLEN];\n                const struct sockaddr_in6 *sa_in6 = &sock_info->sa_in6;\n                if (inet_ntop(family, &sa_in6->sin6_addr,\n                              ip, sizeof(ip)) != NULL)\n                {\n                    g_snprintf(desc, bytes, \"[%s]:%d\", ip,\n                               ntohs(sa_in6->sin6_port));\n                }\n                else\n                {\n                    g_snprintf(desc, bytes, \"[<unknown AF_INET6>]:%d\",\n                               ntohs(sa_in6->sin6_port));\n                }\n                break;\n            }\n#endif\n\n            case AF_UNIX:\n            {\n                g_snprintf(desc, bytes, \"AF_UNIX\");\n                break;\n            }\n\n#if defined(XRDP_ENABLE_VSOCK)\n#if defined(__linux__)\n\n            case AF_VSOCK:\n            {\n                const struct sockaddr_vm *sa_vm = &sock_info->sa_vm;\n\n                g_snprintf(desc, bytes, \"AF_VSOCK:cid=%u/port=%u\",\n                           sa_vm->svm_cid, sa_vm->svm_port);\n\n                break;\n            }\n\n#elif defined(__FreeBSD__)\n\n            case AF_HYPERV:\n            {\n                const struct sockaddr_hvs *sa_hvs = &sock_info->sa_hvs;\n\n                g_snprintf(desc, bytes, \"AF_HYPERV:port=%u\", sa_hvs->hvs_port);\n\n                break;\n            }\n\n#endif\n#endif\n            default:\n                g_snprintf(desc, bytes, \"Unknown address family %d\", family);\n                break;\n        }\n    }\n\n    return desc;\n}\n\n/*****************************************************************************/\nvoid\ng_sck_close(int sck)\n{\n#if defined(_WIN32)\n    closesocket(sck);\n#else\n    char sockname[MAX_PEER_DESCSTRLEN];\n\n    union sock_info sock_info;\n    socklen_t sock_len = sizeof(sock_info);\n    memset(&sock_info, 0, sizeof(sock_info));\n\n    if (getsockname(sck, &sock_info.sa, &sock_len) == 0)\n    {\n        get_peer_description(&sock_info, sockname, sizeof(sockname));\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"getsockname() failed on socket %d: %s\",\n            sck, g_get_strerror());\n\n        if (errno == EBADF || errno == ENOTSOCK)\n        {\n            return;\n        }\n\n        g_snprintf(sockname, sizeof(sockname), \"unknown\");\n    }\n\n    if (close(sck) == 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Closed socket %d (%s)\", sck, sockname);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"Cannot close socket %d (%s): %s\", sck,\n            sockname, g_get_strerror());\n    }\n\n#endif\n}\n\n#if defined(XRDP_ENABLE_IPV6)\n/*****************************************************************************/\n/* Helper function for g_tcp_connect.                                        */\nstatic int\nconnect_loopback(int sck, const char *port)\n{\n    struct sockaddr_in6 sa;\n    struct sockaddr_in s;\n    int res;\n\n    // First IPv6\n    g_memset(&sa, 0, sizeof(sa));\n    sa.sin6_family = AF_INET6;\n    sa.sin6_addr = in6addr_loopback;             // IPv6 ::1\n    sa.sin6_port = htons((tui16)atoi(port));\n    res = connect(sck, (struct sockaddr *)&sa, sizeof(sa));\n    if (res == -1 && errno == EINPROGRESS)\n    {\n        return -1;\n    }\n    if (res == 0 || (res == -1 && errno == EISCONN))\n    {\n        return 0;\n    }\n\n    // else IPv4\n    g_memset(&s, 0, sizeof(s));\n    s.sin_family = AF_INET;\n    s.sin_addr.s_addr = htonl(INADDR_LOOPBACK);  // IPv4 127.0.0.1\n    s.sin_port = htons((tui16)atoi(port));\n    res = connect(sck, (struct sockaddr *)&s, sizeof(s));\n    if (res == -1 && errno == EINPROGRESS)\n    {\n        return -1;\n    }\n    if (res == 0 || (res == -1 && errno == EISCONN))\n    {\n        return 0;\n    }\n\n    // else IPv6 with IPv4 address\n    g_memset(&sa, 0, sizeof(sa));\n    sa.sin6_family = AF_INET6;\n    inet_pton(AF_INET6, \"::FFFF:127.0.0.1\", &sa.sin6_addr);\n    sa.sin6_port = htons((tui16)atoi(port));\n    res = connect(sck, (struct sockaddr *)&sa, sizeof(sa));\n    if (res == -1 && errno == EINPROGRESS)\n    {\n        return -1;\n    }\n    if (res == 0 || (res == -1 && errno == EISCONN))\n    {\n        return 0;\n    }\n\n    return -1;\n}\n#endif\n\n/*****************************************************************************/\n/* returns error, zero is good                                               */\n/* The connection might get to be in progress, if so -1 is returned.         */\n/* The caller needs to call again to check if succeed.                       */\n#if defined(XRDP_ENABLE_IPV6)\nint\ng_tcp_connect(int sck, const char *address, const char *port)\n{\n    int res = 0;\n    struct addrinfo p;\n    struct addrinfo *h = (struct addrinfo *)NULL;\n    struct addrinfo *rp = (struct addrinfo *)NULL;\n\n    g_memset(&p, 0, sizeof(struct addrinfo));\n\n    p.ai_socktype = SOCK_STREAM;\n    p.ai_protocol = IPPROTO_TCP;\n    p.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;\n    p.ai_family = AF_INET6;\n    if (g_strcmp(address, \"127.0.0.1\") == 0)\n    {\n        return connect_loopback(sck, port);\n    }\n    else\n    {\n        res = getaddrinfo(address, port, &p, &h);\n    }\n    if (res != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"g_tcp_connect(%d, %s, %s): getaddrinfo() failed: %s\",\n            sck, address, port, gai_strerror(res));\n    }\n    if (res > -1)\n    {\n        if (h != NULL)\n        {\n            for (rp = h; rp != NULL; rp = rp->ai_next)\n            {\n                res = connect(sck, (struct sockaddr *)(rp->ai_addr),\n                              rp->ai_addrlen);\n                if (res == -1 && errno == EINPROGRESS)\n                {\n                    break; /* Return -1 */\n                }\n                if (res == 0 || (res == -1 && errno == EISCONN))\n                {\n                    res = 0;\n                    break; /* Success */\n                }\n            }\n            freeaddrinfo(h);\n        }\n    }\n\n    return res;\n}\n#else\nint\ng_tcp_connect(int sck, const char *address, const char *port)\n{\n    struct sockaddr_in s;\n    struct hostent *h;\n    int res;\n\n    g_memset(&s, 0, sizeof(struct sockaddr_in));\n    s.sin_family = AF_INET;\n    s.sin_port = htons((tui16)atoi(port));\n    s.sin_addr.s_addr = inet_addr(address);\n    if (s.sin_addr.s_addr == INADDR_NONE)\n    {\n        h = gethostbyname(address);\n        if (h != 0)\n        {\n            if (h->h_name != 0)\n            {\n                if (h->h_addr_list != 0)\n                {\n                    if ((*(h->h_addr_list)) != 0)\n                    {\n                        s.sin_addr.s_addr = *((int *)(*(h->h_addr_list)));\n                    }\n                }\n            }\n        }\n    }\n    res = connect(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_in));\n\n    /* Mac OSX connect() returns -1 for already established connections */\n    if (res == -1 && errno == EISCONN)\n    {\n        res = 0;\n    }\n\n    return res;\n}\n#endif\n\n/*****************************************************************************/\n/* returns error, zero is good */\nint\ng_sck_local_connect(int sck, const char *port)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    struct sockaddr_un s;\n\n    memset(&s, 0, sizeof(struct sockaddr_un));\n    s.sun_family = AF_UNIX;\n    strncpy(s.sun_path, port, sizeof(s.sun_path));\n    s.sun_path[sizeof(s.sun_path) - 1] = 0;\n\n    return connect(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_un));\n#endif\n}\n\n/*****************************************************************************/\nint\ng_sck_set_non_blocking(int sck)\n{\n    unsigned long i;\n\n#if defined(_WIN32)\n    i = 1;\n    ioctlsocket(sck, FIONBIO, &i);\n#else\n    i = fcntl(sck, F_GETFL);\n    i = i | O_NONBLOCK;\n    if (fcntl(sck, F_SETFL, i) < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"g_sck_set_non_blocking: fcntl() failed\");\n    }\n#endif\n    return 0;\n}\n\n#if defined(XRDP_ENABLE_IPV6)\n/*****************************************************************************/\n/* returns error, zero is good */\nint\ng_tcp_bind(int sck, const char *port)\n{\n    struct sockaddr_in6 sa;\n    struct sockaddr_in s;\n    int errno6;\n\n    // First IPv6\n    g_memset(&sa, 0, sizeof(sa));\n    sa.sin6_family = AF_INET6;\n    sa.sin6_addr = in6addr_any;                 // IPv6 ::\n    sa.sin6_port = htons((tui16)atoi(port));\n    if (bind(sck, (struct sockaddr *)&sa, sizeof(sa)) == 0)\n    {\n        return 0;\n    }\n    errno6 = errno;\n\n    // else IPv4\n    g_memset(&s, 0, sizeof(s));\n    s.sin_family = AF_INET;\n    s.sin_addr.s_addr = htonl(INADDR_ANY);     // IPv4 0.0.0.0\n    s.sin_port = htons((tui16)atoi(port));\n    if (bind(sck, (struct sockaddr *)&s, sizeof(s)) == 0)\n    {\n        return 0;\n    }\n\n    LOG(LOG_LEVEL_ERROR, \"g_tcp_bind(%d, %s) failed \"\n        \"bind IPv6 (errno=%d) and IPv4 (errno=%d).\",\n        sck, port, errno6, errno);\n    return -1;\n}\n#else\nint\ng_tcp_bind(int sck, const char *port)\n{\n    struct sockaddr_in s;\n\n    memset(&s, 0, sizeof(struct sockaddr_in));\n    s.sin_family = AF_INET;\n    s.sin_port = htons((tui16)atoi(port));\n    s.sin_addr.s_addr = INADDR_ANY;\n    return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_in));\n}\n#endif\n\n/*****************************************************************************/\nint\ng_sck_local_bind(int sck, const char *port)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    struct sockaddr_un s;\n\n    memset(&s, 0, sizeof(struct sockaddr_un));\n    s.sun_family = AF_UNIX;\n    strncpy(s.sun_path, port, sizeof(s.sun_path));\n    s.sun_path[sizeof(s.sun_path) - 1] = 0;\n\n    return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_un));\n#endif\n}\n\n/*****************************************************************************/\nint\ng_sck_vsock_bind(int sck, const char *port)\n{\n#if defined(XRDP_ENABLE_VSOCK)\n#if defined(__linux__)\n    struct sockaddr_vm s;\n\n    g_memset(&s, 0, sizeof(struct sockaddr_vm));\n    s.svm_family = AF_VSOCK;\n    s.svm_port = atoi(port);\n    s.svm_cid = VMADDR_CID_ANY;\n\n    return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_vm));\n#elif defined(__FreeBSD__)\n    struct sockaddr_hvs s;\n\n    g_memset(&s, 0, sizeof(struct sockaddr_hvs));\n    s.sa_family = AF_HYPERV;\n    s.hvs_port = atoi(port);\n\n    return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_hvs));\n#else\n    return -1;\n#endif\n#else\n    return -1;\n#endif\n}\n\n/*****************************************************************************/\nint\ng_sck_vsock_bind_address(int sck, const char *port, const char *address)\n{\n#if defined(XRDP_ENABLE_VSOCK)\n#if defined(__linux__)\n    struct sockaddr_vm s;\n\n    g_memset(&s, 0, sizeof(struct sockaddr_vm));\n    s.svm_family = AF_VSOCK;\n    s.svm_port = atoi(port);\n    s.svm_cid = atoi(address);\n\n    return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_vm));\n#elif defined(__FreeBSD__)\n    struct sockaddr_hvs s;\n\n    g_memset(&s, 0, sizeof(struct sockaddr_hvs));\n    s.sa_family = AF_HYPERV;\n    s.hvs_port = atoi(port);\n    // channel/address currently unsupported in FreeBSD 13.\n\n    return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_hvs));\n#else\n    return -1;\n#endif\n#else\n    return -1;\n#endif\n}\n\n\n#if defined(XRDP_ENABLE_IPV6)\n/*****************************************************************************/\n/* Helper function for g_tcp_bind_address.                                   */\nstatic int\nbind_loopback(int sck, const char *port)\n{\n    struct sockaddr_in6 sa;\n    struct sockaddr_in s;\n    int errno6;\n    int errno4;\n\n    // First IPv6\n    g_memset(&sa, 0, sizeof(sa));\n    sa.sin6_family = AF_INET6;\n    sa.sin6_addr = in6addr_loopback;             // IPv6 ::1\n    sa.sin6_port = htons((tui16)atoi(port));\n    if (bind(sck, (struct sockaddr *)&sa, sizeof(sa)) == 0)\n    {\n        return 0;\n    }\n    errno6 = errno;\n\n    // else IPv4\n    g_memset(&s, 0, sizeof(s));\n    s.sin_family = AF_INET;\n    s.sin_addr.s_addr = htonl(INADDR_LOOPBACK);  // IPv4 127.0.0.1\n    s.sin_port = htons((tui16)atoi(port));\n    if (bind(sck, (struct sockaddr *)&s, sizeof(s)) == 0)\n    {\n        return 0;\n    }\n    errno4 = errno;\n\n    // else IPv6 with IPv4 address\n    g_memset(&sa, 0, sizeof(sa));\n    sa.sin6_family = AF_INET6;\n    inet_pton(AF_INET6, \"::FFFF:127.0.0.1\", &sa.sin6_addr);\n    sa.sin6_port = htons((tui16)atoi(port));\n    if (bind(sck, (struct sockaddr *)&sa, sizeof(sa)) == 0)\n    {\n        return 0;\n    }\n\n    LOG(LOG_LEVEL_ERROR, \"bind_loopback(%d, %s) failed; \"\n        \"IPv6 ::1 (errno=%d), IPv4 127.0.0.1 (errno=%d) and IPv6 ::FFFF:127.0.0.1 (errno=%d).\",\n        sck, port, errno6, errno4, errno);\n    return -1;\n}\n\n/*****************************************************************************/\n/* Helper function for g_tcp_bind_address.                                   */\n/* Returns error, zero is good.                                              */\nstatic int\ngetaddrinfo_bind(int sck, const char *port, const char *address)\n{\n    int res;\n    int error;\n    struct addrinfo hints;\n    struct addrinfo *list;\n    struct addrinfo *i;\n\n    res = -1;\n    g_memset(&hints, 0, sizeof(hints));\n    hints.ai_family = AF_UNSPEC;\n    hints.ai_flags = 0;\n    hints.ai_socktype = SOCK_STREAM;\n    hints.ai_protocol = IPPROTO_TCP;\n    error = getaddrinfo(address, port, &hints, &list);\n    if (error == 0)\n    {\n        i = list;\n        while ((i != 0) && (res < 0))\n        {\n            res = bind(sck, i->ai_addr, i->ai_addrlen);\n            i = i->ai_next;\n        }\n        freeaddrinfo(list);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"getaddrinfo error: %s\", gai_strerror(error));\n        return -1;\n    }\n    return res;\n}\n\n/*****************************************************************************/\n/* Binds a socket to a port. If no specified address the port will be bind   */\n/* to 'any', i.e. available on all network.                                  */\n/* For bind to local host, see valid address strings below.                  */\n/* Returns error, zero is good.                                              */\nint\ng_tcp_bind_address(int sck, const char *port, const char *address)\n{\n    int res;\n\n    if ((address == 0) ||\n            (address[0] == 0) ||\n            (g_strcmp(address, \"0.0.0.0\") == 0) ||\n            (g_strcmp(address, \"::\") == 0))\n    {\n        return g_tcp_bind(sck, port);\n    }\n\n    if ((g_strcmp(address, \"127.0.0.1\") == 0) ||\n            (g_strcmp(address, \"::1\") == 0) ||\n            (g_strcmp(address, \"localhost\") == 0))\n    {\n        return bind_loopback(sck, port);\n    }\n\n    // Let getaddrinfo translate the address string...\n    // IPv4: ddd.ddd.ddd.ddd\n    // IPv6: x:x:x:x:x:x:x:x%<interface>, or x::x:x:x:x%<interface>\n    res = getaddrinfo_bind(sck, port, address);\n    if (res != 0)\n    {\n        // If fail and it is an IPv4 address, try with the mapped address\n        struct in_addr a;\n        if ((inet_aton(address, &a) == 1) && (strlen(address) <= 15))\n        {\n            char sz[7 + 15 + 1];\n            sprintf(sz, \"::FFFF:%s\", address);\n            res = getaddrinfo_bind(sck, port, sz);\n            if (res == 0)\n            {\n                return 0;\n            }\n        }\n\n        LOG(LOG_LEVEL_ERROR, \"g_tcp_bind_address(%d, %s, %s) Failed!\",\n            sck, port, address);\n        return -1;\n    }\n    return 0;\n}\n#else\nint\ng_tcp_bind_address(int sck, const char *port, const char *address)\n{\n    struct sockaddr_in s;\n\n    memset(&s, 0, sizeof(struct sockaddr_in));\n    s.sin_family = AF_INET;\n    s.sin_port = htons((tui16)atoi(port));\n    s.sin_addr.s_addr = INADDR_ANY;\n    if (inet_aton(address, &s.sin_addr) < 0)\n    {\n        return -1; /* bad address */\n    }\n    return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_in));\n}\n#endif\n\n/*****************************************************************************/\n/* returns error, zero is good */\nint\ng_sck_listen(int sck)\n{\n    return listen(sck, 2);\n}\n\n/*****************************************************************************/\nint\ng_sck_accept(int sck)\n{\n    int ret;\n    union sock_info sock_info;\n    socklen_t sock_len = sizeof(sock_info);\n    memset(&sock_info, 0, sock_len);\n\n    ret = accept(sck, (struct sockaddr *)&sock_info, &sock_len);\n\n    if (ret > 0)\n    {\n        char description[MAX_PEER_DESCSTRLEN];\n        get_peer_description(&sock_info, description, sizeof(description));\n        LOG(LOG_LEVEL_INFO, \"Socket %d: connection accepted from %s\",\n            ret, description);\n\n    }\n\n    return ret;\n}\n\n/*****************************************************************************/\n\nconst char *\ng_sck_get_peer_ip_address(int sck,\n                          char *ip, unsigned int bytes,\n                          unsigned short *port)\n{\n    if (bytes > 0)\n    {\n        int ok = 0;\n        union sock_info sock_info;\n\n        socklen_t sock_len = sizeof(sock_info);\n        memset(&sock_info, 0, sock_len);\n\n        if (getpeername(sck, (struct sockaddr *)&sock_info, &sock_len) == 0)\n        {\n            int family = sock_info.sa.sa_family;\n            switch (family)\n            {\n                case AF_INET:\n                {\n                    struct sockaddr_in *sa_in = &sock_info.sa_in;\n                    if (inet_ntop(family, &sa_in->sin_addr, ip, bytes) != NULL)\n                    {\n                        ok = 1;\n                        if (port != NULL)\n                        {\n                            *port = ntohs(sa_in->sin_port);\n                        }\n                    }\n                    break;\n                }\n\n#if defined(XRDP_ENABLE_IPV6)\n\n                case AF_INET6:\n                {\n                    struct sockaddr_in6 *sa_in6 = &sock_info.sa_in6;\n                    if (inet_ntop(family, &sa_in6->sin6_addr, ip, bytes) != NULL)\n                    {\n                        ok = 1;\n                        if (port != NULL)\n                        {\n                            *port = ntohs(sa_in6->sin6_port);\n                        }\n                    }\n                    break;\n                }\n\n#endif\n                default:\n                    break;\n            }\n        }\n\n        if (!ok)\n        {\n            ip[0] = '\\0';\n        }\n    }\n\n    return ip;\n}\n\n/*****************************************************************************/\n\nconst char *\ng_sck_get_peer_description(int sck,\n                           char *desc, unsigned int bytes)\n{\n    union sock_info sock_info;\n    socklen_t sock_len = sizeof(sock_info);\n    memset(&sock_info, 0, sock_len);\n\n    if (getpeername(sck, (struct sockaddr *)&sock_info, &sock_len) == 0)\n    {\n        get_peer_description(&sock_info, desc, bytes);\n    }\n\n    return desc;\n}\n\n/*****************************************************************************/\nvoid\ng_sleep(int msecs)\n{\n#if defined(_WIN32)\n    Sleep(msecs);\n#else\n    usleep(msecs * 1000);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_pipe(int fd[2])\n{\n    return pipe(fd);\n}\n\n/*****************************************************************************/\nint\ng_sck_last_error_would_block(int sck)\n{\n#if defined(_WIN32)\n    return WSAGetLastError() == WSAEWOULDBLOCK;\n#else\n    return (errno == EWOULDBLOCK) || (errno == EAGAIN) || (errno == EINPROGRESS);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_sck_recv(int sck, void *ptr, unsigned int len, int flags)\n{\n#if defined(_WIN32)\n    return recv(sck, (char *)ptr, len, flags);\n#else\n    return recv(sck, ptr, len, flags);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_sck_send(int sck, const void *ptr, unsigned int len, int flags)\n{\n#if defined(_WIN32)\n    return send(sck, (const char *)ptr, len, flags);\n#else\n    return send(sck, ptr, len, flags);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_sck_recv_fd_set(int sck, void *ptr, unsigned int len,\n                  int fds[], unsigned int maxfd,\n                  unsigned int *fdcount)\n{\n    int rv = -1;\n#if !defined(_WIN32)\n    // The POSIX API gives us no way to see how much ancillary data is\n    // present for recvmsg() - just use a big buffer.\n    //\n    // Use a union, so control_un.control is properly aligned.\n    union\n    {\n        struct cmsghdr cm;\n        unsigned char control[8192];\n    } control_un;\n    struct msghdr msg = {0};\n\n    *fdcount = 0;\n\n    /* Set up descriptor for vanilla data */\n    struct iovec iov[1] = { {ptr, len} };\n    msg.msg_iov = &iov[0];\n    msg.msg_iovlen = 1;\n\n    /* Add in the ancillary data buffer */\n    msg.msg_control = control_un.control;\n    msg.msg_controllen = sizeof(control_un.control);\n\n    if ((rv = recvmsg(sck, &msg, 0)) > 0)\n    {\n        struct cmsghdr *cmsg;\n\n        // Coverity: msg is 'tainted', so check msg.control and\n        // msg.msg_controllen are sane (i.e. recvmsg() hasn't done\n        // something odd)\n        msg.msg_control = control_un.control;\n        if (msg.msg_controllen > sizeof(control_un.control))\n        {\n            msg.msg_controllen = sizeof(control_un.control);\n        }\n\n        if ((msg.msg_flags & MSG_CTRUNC) != 0)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Ancillary data on recvmsg() was truncated\");\n        }\n\n        // Iterate over the cmsghdr structures in the ancillary data\n        for (cmsg = CMSG_FIRSTHDR(&msg);\n                cmsg != NULL;\n                cmsg = CMSG_NXTHDR(&msg, cmsg))\n        {\n            if (cmsg->cmsg_level == SOL_SOCKET &&\n                    cmsg->cmsg_type == SCM_RIGHTS)\n            {\n                const unsigned char *data = CMSG_DATA(cmsg);\n                unsigned int data_len = cmsg->cmsg_len - CMSG_LEN(0);\n\n                // Check the data length doesn't point past the end of\n                // control_un.control (see below). This shouldn't happen,\n                // but is conceivable if the ancillary data is truncated\n                // and the OS doesn't handle that properly.\n                //\n                // <--  (sizeof(control_un.control)   -->\n                // +------------------------------------+\n                // |                                    |\n                // +------------------------------------+\n                // ^                       ^\n                // |                       | <- data_len ->\n                // |                       |\n                // control_un.control      data\n                unsigned int max_data_len =\n                    sizeof(control_un.control) - (data - control_un.control);\n                if (len > max_data_len)\n                {\n                    len = max_data_len;\n                }\n\n                // Process all the file descriptors in the structure\n                while (data_len >= sizeof(int))\n                {\n                    int fd;\n                    memcpy(&fd, data, sizeof(int));\n                    data += sizeof(int);\n                    data_len -= sizeof(int);\n\n                    if (*fdcount < maxfd)\n                    {\n                        fds[(*fdcount)++] = fd;\n                    }\n                    else\n                    {\n                        // No room in the user's buffer for this fd\n                        close(fd);\n                    }\n                }\n            }\n        }\n    }\n#endif /* !WIN32 */\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\ng_sck_send_fd_set(int sck, const void *ptr, unsigned int len,\n                  int fds[], unsigned int fdcount)\n{\n    int rv = -1;\n#if !defined(_WIN32)\n    struct msghdr msg = {0};\n\n    /* Set up descriptor for vanilla data */\n    struct iovec iov[1] = { {(void *)ptr, len} };\n    msg.msg_iov = &iov[0];\n    msg.msg_iovlen = 1;\n\n    if (fdcount > 0)\n    {\n        unsigned int fdsize = sizeof(fds[0]) * fdcount; /* Payload size */\n        /* Allocate ancillary data structure */\n        msg.msg_controllen  = CMSG_SPACE(fdsize);\n        msg.msg_control = (struct cmsghdr *)g_malloc(msg.msg_controllen, 1);\n        if (msg.msg_control == NULL)\n        {\n            /* Memory allocation failure */\n            LOG(LOG_LEVEL_ERROR, \"Error allocating buffer for %u fds\",\n                fdcount);\n            return -1;\n        }\n\n        /* Fill in the ancillary data structure */\n        struct cmsghdr *cmptr = CMSG_FIRSTHDR(&msg);\n        cmptr->cmsg_len = CMSG_LEN(fdsize);\n        cmptr->cmsg_level = SOL_SOCKET;\n        cmptr->cmsg_type = SCM_RIGHTS;\n        memcpy(CMSG_DATA(cmptr), fds, fdsize);\n    }\n\n    rv = sendmsg(sck, &msg, 0);\n    g_free(msg.msg_control);\n\n#endif /* !WIN32 */\n\n    return rv;\n}\n\n/******************************************************************************/\nint\ng_alloc_shm_map_fd(void **addr, int *fd, size_t size)\n{\n    int lfd = -1;\n    void *laddr;\n    char name[128];\n    static unsigned int autoinc;\n\n    snprintf(name, 128, \"/%8.8X%8.8X\", getpid(), autoinc++);\n    lfd = shm_open(name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);\n    if (lfd == -1)\n    {\n        return 1;\n    }\n    shm_unlink(name);\n    if (ftruncate(lfd, size) == -1)\n    {\n        close(lfd);\n        return 2;\n    }\n    /* map fd to address space */\n    laddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, lfd, 0);\n    if (laddr == MAP_FAILED)\n    {\n        close(lfd);\n        return 3;\n    }\n    *addr = laddr;\n    *fd = lfd;\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns boolean */\nint\ng_sck_socket_ok(int sck)\n{\n    int opt;\n    socklen_t opt_len;\n\n    opt_len = sizeof(opt);\n\n    if (getsockopt(sck, SOL_SOCKET, SO_ERROR, (char *)(&opt), &opt_len) == 0)\n    {\n        if (opt == 0)\n        {\n            return 1;\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* wait 'millis' milliseconds for the socket to be able to write */\n/* returns boolean */\nint\ng_sck_can_send(int sck, int millis)\n{\n    int rv = 0;\n    if (sck > 0)\n    {\n        struct pollfd pollfd;\n\n        pollfd.fd = sck;\n        pollfd.events = POLLOUT;\n        pollfd.revents = 0;\n        if (poll(&pollfd, 1, millis) > 0)\n        {\n            if ((pollfd.revents & POLLOUT) != 0)\n            {\n                rv = 1;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* wait 'millis' milliseconds for the socket to be able to receive */\n/* returns boolean */\nint\ng_sck_can_recv(int sck, int millis)\n{\n    int rv = 0;\n\n    if (sck > 0)\n    {\n        struct pollfd pollfd;\n\n        pollfd.fd = sck;\n        pollfd.events = POLLIN;\n        pollfd.revents = 0;\n        if (poll(&pollfd, 1, millis) > 0)\n        {\n            if ((pollfd.revents & (POLLIN | POLLHUP)) != 0)\n            {\n                rv = 1;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\ng_sck_select(int sck1, int sck2)\n{\n    struct pollfd pollfd[2] = {0};\n    int rvmask[2] = {0}; /* Output masks corresponding to fds in pollfd */\n\n    unsigned int i = 0;\n    int rv = 0;\n\n    if (sck1 > 0)\n    {\n        pollfd[i].fd = sck1;\n        pollfd[i].events = POLLIN;\n        rvmask[i] = 1;\n        ++i;\n    }\n\n    if (sck2 > 0)\n    {\n        pollfd[i].fd = sck2;\n        pollfd[i].events = POLLIN;\n        rvmask[i] = 2;\n        ++i;\n    }\n\n    if (poll(pollfd, i, 0) > 0)\n    {\n        if ((pollfd[0].revents & (POLLIN | POLLHUP)) != 0)\n        {\n            rv |= rvmask[0];\n        }\n\n        if ((pollfd[1].revents & (POLLIN | POLLHUP)) != 0)\n        {\n            rv |= rvmask[1];\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns boolean */\nstatic int\ng_fd_can_read(int fd)\n{\n    int rv = 0;\n    if (fd > 0)\n    {\n        struct pollfd pollfd;\n\n        pollfd.fd = fd;\n        pollfd.events = POLLIN;\n        pollfd.revents = 0;\n        if (poll(&pollfd, 1, 0) > 0)\n        {\n            if ((pollfd.revents & (POLLIN | POLLHUP)) != 0)\n            {\n                rv = 1;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* O_NONBLOCK = 0x00000800 */\nstatic int\ng_set_nonblock(int fd)\n{\n    int error;\n    int flags;\n\n    error = fcntl(fd, F_GETFL);\n    if (error < 0)\n    {\n        return 1;\n    }\n    flags = error;\n    if ((flags & O_NONBLOCK) != O_NONBLOCK)\n    {\n        flags |= O_NONBLOCK;\n        error = fcntl(fd, F_SETFL, flags);\n        if (error < 0)\n        {\n            return 1;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns 0 on error */\ntintptr\ng_create_wait_obj(const char *name)\n{\n#ifdef _WIN32\n    tintptr obj;\n\n    obj = (tintptr)CreateEvent(0, 1, 0, name);\n    return obj;\n#else\n    int fds[2];\n    int error;\n\n    error = pipe(fds);\n    if (error != 0)\n    {\n        return 0;\n    }\n    if (g_set_nonblock(fds[0]) != 0)\n    {\n        close(fds[0]);\n        close(fds[1]);\n        return 0;\n    }\n    if (g_set_nonblock(fds[1]) != 0)\n    {\n        close(fds[0]);\n        close(fds[1]);\n        return 0;\n    }\n    g_file_set_cloexec(fds[0], 1);\n    g_file_set_cloexec(fds[1], 1);\n    return (fds[1] << 16) | fds[0];\n#endif\n}\n\n/*****************************************************************************/\n/* returns 0 on error */\ntintptr\ng_create_wait_obj_from_socket(tintptr socket, int write)\n{\n#ifdef _WIN32\n    /* Create and return corresponding event handle for WaitForMultipleObjects */\n    WSAEVENT event;\n    long lnetevent = 0;\n\n    g_memset(&event, 0, sizeof(WSAEVENT));\n\n    event = WSACreateEvent();\n    lnetevent = (write ? FD_WRITE : FD_READ) | FD_CLOSE;\n\n    if (WSAEventSelect(socket, event, lnetevent) == 0)\n    {\n        return (tbus)event;\n    }\n    else\n    {\n        return 0;\n    }\n\n#else\n    return socket;\n#endif\n}\n\n/*****************************************************************************/\nvoid\ng_delete_wait_obj_from_socket(tintptr wait_obj)\n{\n#ifdef _WIN32\n\n    if (wait_obj == NULL_WAIT_OBJ)\n    {\n        return;\n    }\n\n    WSACloseEvent((HANDLE)wait_obj);\n#else\n#endif\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_set_wait_obj(tintptr obj)\n{\n#ifdef _WIN32\n#error \"Win32 is no longer supported.\"\n#else\n    int error;\n    int fd;\n    int written;\n    int to_write;\n    char buf[4] = \"sig\";\n\n    if (obj == NULL_WAIT_OBJ)\n    {\n        return 0;\n    }\n    fd = obj & USHRT_MAX;\n    if (g_fd_can_read(fd))\n    {\n        /* already signalled */\n        return 0;\n    }\n    fd = obj >> 16;\n    to_write = sizeof(buf);\n    written = 0;\n    while (written < to_write)\n    {\n        error = write(fd, buf + written, to_write - written);\n        if (error == -1)\n        {\n            error = errno;\n            if ((error == EAGAIN) || (error == EWOULDBLOCK) ||\n                    (error == EINPROGRESS) || (error == EINTR))\n            {\n                /* ok */\n            }\n            else\n            {\n                return 1;\n            }\n        }\n        else if (error > 0 && error <= (int)sizeof(buf))\n        {\n            written += error;\n        }\n        else\n        {\n            // Shouldn't get here.\n            return 1;\n        }\n    }\n    return 0;\n#endif\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_reset_wait_obj(tintptr obj)\n{\n#ifdef _WIN32\n    if (obj == NULL_WAIT_OBJ)\n    {\n        return 0;\n    }\n    ResetEvent((HANDLE)obj);\n    return 0;\n#else\n    char buf[4];\n    int error;\n    int fd;\n\n    if (obj == NULL_WAIT_OBJ)\n    {\n        return 0;\n    }\n    fd = obj & 0xffff;\n    while (g_fd_can_read(fd))\n    {\n        error = read(fd, buf, 4);\n        if (error == -1)\n        {\n            error = errno;\n            if ((error == EAGAIN) || (error == EWOULDBLOCK) ||\n                    (error == EINPROGRESS) || (error == EINTR))\n            {\n                /* ok */\n            }\n            else\n            {\n                return 1;\n            }\n        }\n        else if (error == 0)\n        {\n            return 1;\n        }\n    }\n    return 0;\n#endif\n}\n\n/*****************************************************************************/\n/* returns boolean */\nint\ng_is_wait_obj_set(tintptr obj)\n{\n#ifdef _WIN32\n    if (obj == NULL_WAIT_OBJ)\n    {\n        return 0;\n    }\n    if (WaitForSingleObject((HANDLE)obj, 0) == WAIT_OBJECT_0)\n    {\n        return 1;\n    }\n    return 0;\n#else\n    if (obj == NULL_WAIT_OBJ)\n    {\n        return 0;\n    }\n    return g_fd_can_read(obj & 0xffff);\n#endif\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_delete_wait_obj(tintptr obj)\n{\n#ifdef _WIN32\n    if (obj == NULL_WAIT_OBJ)\n    {\n        return 0;\n    }\n    /* Close event handle */\n    CloseHandle((HANDLE)obj);\n    return 0;\n#else\n    if (obj == 0)\n    {\n        return 0;\n    }\n    close(obj & 0xffff);\n    close(obj >> 16);\n    return 0;\n#endif\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_obj_wait(tintptr *read_objs, int rcount, tintptr *write_objs, int wcount,\n           int mstimeout)\n{\n#define MAX_HANDLES 256\n#ifdef _WIN32\n    HANDLE handles[MAX_HANDLES];\n    DWORD count;\n    DWORD error;\n    int j;\n    int i;\n\n    j = 0;\n    count = rcount + wcount;\n\n    for (i = 0; i < rcount; i++)\n    {\n        handles[j++] = (HANDLE)(read_objs[i]);\n    }\n\n    for (i = 0; i < wcount; i++)\n    {\n        handles[j++] = (HANDLE)(write_objs[i]);\n    }\n\n    if (mstimeout < 0)\n    {\n        mstimeout = INFINITE;\n    }\n\n    error = WaitForMultipleObjects(count, handles, FALSE, mstimeout);\n\n    if (error == WAIT_FAILED)\n    {\n        return 1;\n    }\n\n    return 0;\n#else\n    struct pollfd pollfd[MAX_HANDLES];\n    int sck;\n    int i;\n    unsigned int j = 0;\n    int rv = 1;\n\n    if (read_objs == NULL && rcount != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Programming error read_objs is null\");\n    }\n    else if (write_objs == NULL && wcount != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Programming error write_objs is null\");\n    }\n    /* Check carefully for int overflow in passed-in counts */\n    else if ((unsigned int)rcount > MAX_HANDLES ||\n             (unsigned int)wcount > MAX_HANDLES ||\n             ((unsigned int)rcount + (unsigned int)wcount) > MAX_HANDLES)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Programming error too many handles\");\n    }\n    else\n    {\n        if (mstimeout < 0)\n        {\n            mstimeout = -1;\n        }\n\n        for (i = 0; i < rcount ; ++i)\n        {\n            sck = read_objs[i] & 0xffff;\n            if (sck > 0)\n            {\n                pollfd[j].fd = sck;\n                pollfd[j].events = POLLIN;\n                ++j;\n            }\n        }\n\n        for (i = 0; i < wcount; ++i)\n        {\n            sck = write_objs[i];\n            if (sck > 0)\n            {\n                pollfd[j].fd = sck;\n                pollfd[j].events = POLLOUT;\n                ++j;\n            }\n        }\n\n        rv = (poll(pollfd, j, mstimeout) < 0);\n        if (rv != 0)\n        {\n            /* these are not really errors */\n            if ((errno == EAGAIN) ||\n                    (errno == EWOULDBLOCK) ||\n                    (errno == EINPROGRESS) ||\n                    (errno == EINTR)) /* signal occurred */\n            {\n                rv = 0;\n            }\n        }\n    }\n\n    return rv;\n#endif\n#undef MAX_HANDLES\n}\n\n/*****************************************************************************/\nvoid\ng_random(char *data, int len)\n{\n    int fd;\n\n    memset(data, 0x44, len);\n    fd = open(\"/dev/urandom\", O_RDONLY);\n\n    if (fd == -1)\n    {\n        fd = open(\"/dev/random\", O_RDONLY);\n    }\n\n    if (fd != -1)\n    {\n        if (read(fd, data, len) != len)\n        {\n        }\n\n        close(fd);\n    }\n}\n\n/*****************************************************************************/\nint\ng_abs(int i)\n{\n    return abs(i);\n}\n\n/*****************************************************************************/\nint\ng_memcmp(const void *s1, const void *s2, int len)\n{\n    return memcmp(s1, s2, len);\n}\n\n/*****************************************************************************/\n/* returns -1 on error, else return handle or file descriptor */\nint\ng_file_open_rw(const char *file_name)\n{\n#if defined(_WIN32)\n    return (int)CreateFileA(file_name, GENERIC_READ | GENERIC_WRITE,\n                            FILE_SHARE_READ | FILE_SHARE_WRITE,\n                            0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);\n#else\n    return open(file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);\n#endif\n}\n\n/*****************************************************************************/\n/* returns -1 on error, else return handle or file descriptor */\nint\ng_file_open_ex(const char *file_name, int aread, int awrite,\n               int acreate, int atrunc)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    int rv;\n    int flags;\n\n    flags = 0;\n    if (aread && awrite)\n    {\n        flags |= O_RDWR;\n    }\n    else if (aread)\n    {\n        flags |= O_RDONLY;\n    }\n    else if (awrite)\n    {\n        flags |= O_WRONLY;\n    }\n    if (acreate)\n    {\n        flags |= O_CREAT;\n    }\n    if (atrunc)\n    {\n        flags |= O_TRUNC;\n    }\n    rv =  open(file_name, flags, S_IRUSR | S_IWUSR);\n    return rv;\n#endif\n}\n\n/*****************************************************************************/\n/* returns -1 on error, else return handle or file descriptor */\nint\ng_file_open_ro(const char *file_name)\n{\n    return g_file_open_ex(file_name, 1, 0, 0, 0);\n}\n\n/*****************************************************************************/\n/* returns error, always 0 */\nint\ng_file_close(int fd)\n{\n#if defined(_WIN32)\n    CloseHandle((HANDLE)fd);\n#else\n    close(fd);\n#endif\n    return 0;\n}\n\n/*****************************************************************************/\nint\ng_file_is_open(int fd)\n{\n    return (fcntl(fd, F_GETFD) >= 0);\n}\n\n/*****************************************************************************/\n/* read from file, returns the number of bytes read or -1 on error */\nint\ng_file_read(int fd, char *ptr, int len)\n{\n#if defined(_WIN32)\n\n    if (ReadFile((HANDLE)fd, (LPVOID)ptr, (DWORD)len, (LPDWORD)&len, 0))\n    {\n        return len;\n    }\n    else\n    {\n        return -1;\n    }\n\n#else\n    return read(fd, ptr, len);\n#endif\n}\n\n/*****************************************************************************/\n/* write to file, returns the number of bytes written or -1 on error */\nint\ng_file_write(int fd, const char *ptr, int len)\n{\n#if defined(_WIN32)\n\n    if (WriteFile((HANDLE)fd, (LPVOID)ptr, (DWORD)len, (LPDWORD)&len, 0))\n    {\n        return len;\n    }\n    else\n    {\n        return -1;\n    }\n\n#else\n    return write(fd, ptr, len);\n#endif\n}\n\n/*****************************************************************************/\n/* move file pointer, returns offset on success, -1 on failure */\nint\ng_file_seek(int fd, int offset)\n{\n#if defined(_WIN32)\n    int rv;\n\n    rv = (int)SetFilePointer((HANDLE)fd, offset, 0, FILE_BEGIN);\n\n    if (rv == (int)INVALID_SET_FILE_POINTER)\n    {\n        return -1;\n    }\n    else\n    {\n        return rv;\n    }\n\n#else\n    return (int)lseek(fd, offset, SEEK_SET);\n#endif\n}\n\n/*****************************************************************************/\n/* move file pointer to end of file, plus an offset */\nint\ng_file_seek_end(int fd, int offset)\n{\n#if defined(_WIN32)\n    int rv;\n\n    rv = (int)SetFilePointer((HANDLE)fd, offset, 0, FILE_END);\n\n    if (rv == (int)INVALID_SET_FILE_POINTER)\n    {\n        return -1;\n    }\n    else\n    {\n        return rv;\n    }\n\n#else\n    return (int)lseek(fd, offset, SEEK_END);\n#endif\n}\n\n/*****************************************************************************/\n/* do a write lock on a file */\n/* return boolean */\nint\ng_file_lock(int fd, int start, int len)\n{\n#if defined(_WIN32)\n    return LockFile((HANDLE)fd, start, 0, len, 0);\n#else\n    struct flock lock;\n\n    lock.l_type = F_WRLCK;\n    lock.l_whence = SEEK_SET;\n    lock.l_start = start;\n    lock.l_len = len;\n\n    if (fcntl(fd, F_SETLK, &lock) == -1)\n    {\n        return 0;\n    }\n\n    return 1;\n#endif\n}\n\n/*****************************************************************************/\n/* Gets the close-on-exec flag for a file descriptor */\nint\ng_file_get_cloexec(int fd)\n{\n    int rv = 0;\n    int flags = fcntl(fd, F_GETFD);\n    if (flags >= 0 && (flags & FD_CLOEXEC) != 0)\n    {\n        rv = 1;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* Sets/clears the close-on-exec flag for a file descriptor */\n/* return boolean */\nint\ng_file_set_cloexec(int fd, int status)\n{\n    int rv = 0;\n    int current_flags = fcntl(fd, F_GETFD);\n    if (current_flags >= 0)\n    {\n        int new_flags;\n        if (status)\n        {\n            new_flags = current_flags | FD_CLOEXEC;\n        }\n        else\n        {\n            new_flags = current_flags & ~FD_CLOEXEC;\n        }\n        if (new_flags != current_flags)\n        {\n            rv = (fcntl(fd, F_SETFD, new_flags) >= 0);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstruct list *\ng_get_open_fds(int min, int max)\n{\n    if (min < 0)\n    {\n        min = 0;\n    }\n\n    struct list *result = list_create();\n\n    if (result != NULL)\n    {\n        if (max < 0)\n        {\n            // sysconf() returns a long. Limit it to a sane value\n#define SANE_MAX 100000\n            long sc_max = sysconf(_SC_OPEN_MAX);\n            max = (sc_max < 0) ? 0 :\n                  (sc_max > (long)SANE_MAX) ? SANE_MAX :\n                  sc_max;\n#undef SANE_MAX\n        }\n\n        // max and min are now both guaranteed to be >= 0\n        if (max > min)\n        {\n            struct pollfd *fds = g_new0(struct pollfd, max - min);\n            int i;\n\n            if (fds == NULL)\n            {\n                goto nomem;\n            }\n\n            for (i = min ; i < max ; ++i)\n            {\n                fds[i - min].fd = i;\n            }\n\n            if (poll(fds, max - min, 0) >= 0)\n            {\n                for (i = min ; i < max ; ++i)\n                {\n                    if (fds[i - min].revents != POLLNVAL)\n                    {\n                        // Descriptor is open\n                        if (!list_add_item(result, i))\n                        {\n                            g_free(fds);\n                            goto nomem;\n                        }\n                    }\n                }\n            }\n            g_free(fds);\n        }\n    }\n\n    return result;\n\nnomem:\n    list_delete(result);\n    return NULL;\n}\n\n/*****************************************************************************/\nint\ng_file_map(int fd, int aread, int awrite, size_t length, void **addr)\n{\n    int prot = 0;\n    void *laddr;\n\n    if (aread)\n    {\n        prot |= PROT_READ;\n    }\n    if (awrite)\n    {\n        prot |= PROT_WRITE;\n    }\n    laddr = mmap(NULL, length, prot, MAP_SHARED, fd, 0);\n    if (laddr == MAP_FAILED)\n    {\n        return 1;\n    }\n    *addr = laddr;\n    return 0;\n}\n\n/*****************************************************************************/\nint\ng_munmap(void *addr, size_t length)\n{\n    return munmap(addr, length);\n}\n\n/*****************************************************************************/\n/* Converts a hex mask to a mode_t value */\n#if !defined(_WIN32)\nstatic mode_t\nhex_to_mode_t(int hex)\n{\n    mode_t mode = 0;\n\n    mode |= (hex & 0x4000) ? S_ISUID : 0;\n    mode |= (hex & 0x2000) ? S_ISGID : 0;\n    mode |= (hex & 0x1000) ? S_ISVTX : 0;\n    mode |= (hex & 0x0400) ? S_IRUSR : 0;\n    mode |= (hex & 0x0200) ? S_IWUSR : 0;\n    mode |= (hex & 0x0100) ? S_IXUSR : 0;\n    mode |= (hex & 0x0040) ? S_IRGRP : 0;\n    mode |= (hex & 0x0020) ? S_IWGRP : 0;\n    mode |= (hex & 0x0010) ? S_IXGRP : 0;\n    mode |= (hex & 0x0004) ? S_IROTH : 0;\n    mode |= (hex & 0x0002) ? S_IWOTH : 0;\n    mode |= (hex & 0x0001) ? S_IXOTH : 0;\n    return mode;\n}\n#endif\n\n/*****************************************************************************/\n/* Converts a mode_t value to a hex mask */\n#if !defined(_WIN32)\nstatic int\nmode_t_to_hex(mode_t mode)\n{\n    int hex = 0;\n\n    hex |= (mode & S_ISUID) ?  0x4000 : 0;\n    hex |= (mode & S_ISGID) ?  0x2000 : 0;\n    hex |= (mode & S_ISVTX) ?  0x1000 : 0;\n    hex |= (mode & S_IRUSR) ?  0x0400 : 0;\n    hex |= (mode & S_IWUSR) ?  0x0200 : 0;\n    hex |= (mode & S_IXUSR) ?  0x0100 : 0;\n    hex |= (mode & S_IRGRP) ?  0x0040 : 0;\n    hex |= (mode & S_IWGRP) ?  0x0020 : 0;\n    hex |= (mode & S_IXGRP) ?  0x0010 : 0;\n    hex |= (mode & S_IROTH) ?  0x0004 : 0;\n    hex |= (mode & S_IWOTH) ?  0x0002 : 0;\n    hex |= (mode & S_IXOTH) ?  0x0001 : 0;\n\n    return hex;\n}\n#endif\n\n/*****************************************************************************/\n/* Duplicates a file descriptor onto another one using the semantics\n * of dup2() */\n/* return boolean */\nint\ng_file_duplicate_on(int fd, int target_fd)\n{\n    int rv = (dup2(fd, target_fd) >= 0);\n\n    if (rv < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't clone file %d as file %d [%s]\",\n            fd, target_fd, g_get_strerror());\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_chmod_hex(const char *filename, int flags)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    mode_t m = hex_to_mode_t(flags);\n    return chmod(filename, m);\n#endif\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_umask_hex(int flags)\n{\n#if defined(_WIN32)\n    return flags;\n#else\n    mode_t m = hex_to_mode_t(flags);\n    m = umask(m);\n    return mode_t_to_hex(m);\n#endif\n}\n\n/*****************************************************************************/\n/* returns error, zero is ok */\nint\ng_chown(const char *name, int uid, int gid)\n{\n    return chown(name, uid, gid);\n}\n\n/*****************************************************************************/\n/* returns error, always zero */\nint\ng_mkdir(const char *dirname)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return mkdir(dirname, S_IRWXU);\n#endif\n}\n\n/*****************************************************************************/\n/* gets the current working directory and puts up to maxlen chars in\n   dirname\n   always returns 0 */\nchar *\ng_get_current_dir(char *dirname, int maxlen)\n{\n#if defined(_WIN32)\n    GetCurrentDirectoryA(maxlen, dirname);\n    return 0;\n#else\n\n    if (getcwd(dirname, maxlen) == 0)\n    {\n    }\n\n    return 0;\n#endif\n}\n\n/*****************************************************************************/\n/* returns error, zero on success and -1 on failure */\nint\ng_set_current_dir(const char *dirname)\n{\n#if defined(_WIN32)\n\n    if (SetCurrentDirectoryA(dirname))\n    {\n        return 0;\n    }\n    else\n    {\n        return -1;\n    }\n\n#else\n    return chdir(dirname);\n#endif\n}\n\n/*****************************************************************************/\n/* returns boolean, non zero if the file exists */\nint\ng_file_exist(const char *filename)\n{\n#if defined(_WIN32)\n    return 0; // use FileAge(filename) <> -1\n#else\n    return access(filename, F_OK) == 0;\n#endif\n}\n\n/*****************************************************************************/\n/* returns boolean, non zero if the file is readable */\nint\ng_file_readable(const char *filename)\n{\n#if defined(_WIN32)\n    return _waccess(filename, 04) == 0;\n#else\n    return access(filename, R_OK) == 0;\n#endif\n}\n\n/*****************************************************************************/\n/* returns boolean, non zero if the directory exists */\nint\ng_directory_exist(const char *dirname)\n{\n#if defined(_WIN32)\n    return 0; // use GetFileAttributes and check return value\n    // is not -1 and FILE_ATTRIBUTE_DIRECTORY bit is set\n#else\n    struct stat st;\n\n    if (stat(dirname, &st) == 0)\n    {\n        return S_ISDIR(st.st_mode);\n    }\n    else\n    {\n        return 0;\n    }\n\n#endif\n}\n\n/*****************************************************************************/\n/* returns boolean, non zero if the file exists  and is a readable executable */\nint\ng_executable_exist(const char *exename)\n{\n    return access(exename, R_OK | X_OK) == 0;\n}\n\n/*****************************************************************************/\n/* returns boolean, non zero if the socket exists */\nint\ng_socket_exist(const char *sockname)\n{\n    struct stat st;\n\n    if (stat(sockname, &st) == 0)\n    {\n        return S_ISSOCK(st.st_mode);\n    }\n    else\n    {\n        return 0;\n    }\n}\n\n/*****************************************************************************/\n/* returns boolean */\nint\ng_create_dir(const char *dirname)\n{\n#if defined(_WIN32)\n    return CreateDirectoryA(dirname, 0); // test this\n#else\n    return mkdir(dirname, 0777) == 0;\n#endif\n}\n\n/*****************************************************************************/\n/* will try to create directories up to last / in name\n   example /tmp/a/b/c/readme.txt will try to create /tmp/a/b/c\n   returns boolean */\nint\ng_create_path(const char *path)\n{\n    char *pp;\n    char *sp;\n    char *copypath;\n    int status;\n\n    status = 1;\n    copypath = g_strdup(path);\n    pp = copypath;\n    sp = strchr(pp, '/');\n\n    while (sp != 0)\n    {\n        if (sp != pp)\n        {\n            *sp = 0;\n\n            if (!g_directory_exist(copypath))\n            {\n                // Create and check again to avoid a race with another\n                // process making the same traversal\n                (void)g_create_dir(copypath);\n                if (!g_directory_exist(copypath))\n                {\n                    status = 0;\n                    break;\n                }\n            }\n\n            *sp = '/';\n        }\n\n        pp = sp + 1;\n        sp = strchr(pp, '/');\n    }\n\n    g_free(copypath);\n    return status;\n}\n\n/*****************************************************************************/\n/* returns boolean */\nint\ng_remove_dir(const char *dirname)\n{\n#if defined(_WIN32)\n    return RemoveDirectoryA(dirname); // test this\n#else\n    return rmdir(dirname) == 0;\n#endif\n}\n\n/*****************************************************************************/\n/* returns non zero if the file was deleted */\nint\ng_file_delete(const char *filename)\n{\n#if defined(_WIN32)\n    return DeleteFileA(filename);\n#else\n    return unlink(filename) != -1;\n#endif\n}\n\n/*****************************************************************************/\n/* returns file size, -1 on error */\nint\ng_file_get_size(const char *filename)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    struct stat st;\n\n    if (stat(filename, &st) == 0)\n    {\n        return (int)(st.st_size);\n    }\n    else\n    {\n        return -1;\n    }\n\n#endif\n}\n\n/*****************************************************************************/\n/* returns device number, -1 on error */\nint\ng_file_get_device_number(const char *filename)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    struct stat st;\n\n    if (stat(filename, &st) == 0)\n    {\n        return (int)(st.st_dev);\n    }\n    else\n    {\n        return -1;\n    }\n\n#endif\n}\n\n/*****************************************************************************/\n/* returns inode number, -1 on error */\nint\ng_file_get_inode_num(const char *filename)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    struct stat st;\n\n    if (stat(filename, &st) == 0)\n    {\n        return (int)(st.st_ino);\n    }\n    else\n    {\n        return -1;\n    }\n\n#endif\n}\n\n/*****************************************************************************/\nlong\ng_load_library(char *in)\n{\n#if defined(_WIN32)\n    return (long)LoadLibraryA(in);\n#else\n    return (long)dlopen(in, RTLD_LOCAL | RTLD_LAZY);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_free_library(long lib)\n{\n    if (lib == 0)\n    {\n        return 0;\n    }\n\n#if defined(_WIN32)\n    return FreeLibrary((HMODULE)lib);\n#else\n    return dlclose((void *)lib);\n#endif\n}\n\n/*****************************************************************************/\n/* returns NULL if not found */\nvoid *\ng_get_proc_address(long lib, const char *name)\n{\n    if (lib == 0)\n    {\n        return 0;\n    }\n\n#if defined(_WIN32)\n    return GetProcAddress((HMODULE)lib, name);\n#else\n    return dlsym((void *)lib, name);\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nint\ng_system(const char *aexec)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return system(aexec);\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nchar *\ng_get_strerror(void)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return strerror(errno);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_get_errno(void)\n{\n#if defined(_WIN32)\n    return GetLastError();\n#else\n    return errno;\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\n\n#define ARGS_STR_LEN 1024\n\nint\ng_execvp(const char *p1, char *args[])\n{\n#if defined(_WIN32)\n    return 0;\n#else\n\n    int rv;\n    char args_str[ARGS_STR_LEN];\n    int args_len;\n\n    args_len = 0;\n    while (args[args_len] != NULL)\n    {\n        args_len++;\n    }\n\n    g_strnjoin(args_str, ARGS_STR_LEN, \" \", (const char **) args, args_len);\n\n    LOG(LOG_LEVEL_DEBUG,\n        \"Calling exec (excutable: %s, arguments: %s)\",\n        p1, args_str);\n\n    rv = execvp(p1, args);\n\n    /* should not get here */\n    int saved_errno = errno;\n\n    LOG(LOG_LEVEL_ERROR,\n        \"Error calling exec (excutable: %s, arguments: %s) \"\n        \"returned errno: %d, description: %s\",\n        p1, args_str, g_get_errno(), g_get_strerror());\n\n    errno = saved_errno;\n    return rv;\n#endif\n}\n\n/*****************************************************************************/\nint\ng_execvp_list(const char *file, struct list *argv)\n{\n    int rv = -1;\n\n    /* Push a terminating NULL onto the list for the system call */\n    if (!list_add_item(argv, (tintptr)NULL))\n    {\n        LOG(LOG_LEVEL_ERROR, \"No memory for exec to terminate list\");\n        errno = ENOMEM;\n    }\n    else\n    {\n        /* Read the argv argument straight from the list */\n        rv = g_execvp(file, (char **)argv->items);\n\n        /* should not get here */\n        list_remove_item(argv, argv->count - 1); // Lose terminating NULL\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nint\ng_execlp3(const char *a1, const char *a2, const char *a3)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    int rv;\n    const char *args[] = {a2, a3, NULL};\n    char args_str[ARGS_STR_LEN];\n\n    g_strnjoin(args_str, ARGS_STR_LEN, \" \", args, 2);\n\n    LOG(LOG_LEVEL_DEBUG,\n        \"Calling exec (executable: %s, arguments: %s)\",\n        a1, args_str);\n\n    g_rm_temp_dir();\n    rv = execlp(a1, a2, a3, (void *)0);\n\n    /* should not get here */\n    LOG(LOG_LEVEL_ERROR,\n        \"Error calling exec (executable: %s, arguments: %s) \"\n        \"returned errno: %d, description: %s\",\n        a1, args_str, g_get_errno(), g_get_strerror());\n\n    return rv;\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nunsigned int\ng_set_alarm(void (*func)(int), unsigned int secs)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    struct sigaction action;\n\n    /* Cancel any previous alarm to prevent a race */\n    unsigned int rv = alarm(0);\n\n    if (func == NULL)\n    {\n        action.sa_handler = SIG_DFL;\n        action.sa_flags = 0;\n    }\n    else\n    {\n        action.sa_handler = func;\n        action.sa_flags = SA_RESTART;\n    }\n    sigemptyset (&action.sa_mask);\n\n    sigaction(SIGALRM, &action, NULL);\n    if (func != NULL && secs > 0)\n    {\n        (void)alarm(secs);\n    }\n    return rv;\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nvoid\ng_signal_child_stop(void (*func)(int))\n{\n#if defined(_WIN32)\n#else\n    struct sigaction action;\n\n    if (func == NULL)\n    {\n        action.sa_handler = SIG_DFL;\n        action.sa_flags = 0;\n    }\n    else\n    {\n        action.sa_handler = func;\n        // Don't need to know when children are stopped or started\n        action.sa_flags = (SA_RESTART | SA_NOCLDSTOP);\n    }\n    sigemptyset (&action.sa_mask);\n\n    sigaction(SIGCHLD, &action, NULL);\n#endif\n}\n\n/*****************************************************************************/\n\nvoid\ng_signal_segfault(void (*func)(int))\n{\n#if defined(_WIN32)\n#else\n    struct sigaction action;\n\n    if (func == NULL)\n    {\n        action.sa_handler = SIG_DFL;\n        action.sa_flags = 0;\n    }\n    else\n    {\n        action.sa_handler = func;\n        action.sa_flags = SA_RESETHAND; // This is a one-shot\n    }\n    sigemptyset (&action.sa_mask);\n\n    sigaction(SIGSEGV, &action, NULL);\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nvoid\ng_signal_hang_up(void (*func)(int))\n{\n#if defined(_WIN32)\n#else\n    struct sigaction action;\n\n    if (func == NULL)\n    {\n        action.sa_handler = SIG_DFL;\n        action.sa_flags = 0;\n    }\n    else\n    {\n        action.sa_handler = func;\n        action.sa_flags = SA_RESTART;\n    }\n    sigemptyset (&action.sa_mask);\n\n    sigaction(SIGHUP, &action, NULL);\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nvoid\ng_signal_user_interrupt(void (*func)(int))\n{\n#if defined(_WIN32)\n#else\n    struct sigaction action;\n\n    if (func == NULL)\n    {\n        action.sa_handler = SIG_DFL;\n        action.sa_flags = 0;\n    }\n    else\n    {\n        action.sa_handler = func;\n        action.sa_flags = SA_RESTART;\n    }\n    sigemptyset (&action.sa_mask);\n\n    sigaction(SIGINT, &action, NULL);\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nvoid\ng_signal_terminate(void (*func)(int))\n{\n#if defined(_WIN32)\n#else\n    struct sigaction action;\n\n    if (func == NULL)\n    {\n        action.sa_handler = SIG_DFL;\n        action.sa_flags = 0;\n    }\n    else\n    {\n        action.sa_handler = func;\n        action.sa_flags = SA_RESTART;\n    }\n    sigemptyset (&action.sa_mask);\n\n    sigaction(SIGTERM, &action, NULL);\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nvoid\ng_signal_pipe(void (*func)(int))\n{\n#if defined(_WIN32)\n#else\n    struct sigaction action;\n\n    if (func == NULL)\n    {\n        action.sa_handler = SIG_DFL;\n        action.sa_flags = 0;\n    }\n    else\n    {\n        action.sa_handler = func;\n        action.sa_flags = SA_RESTART;\n    }\n    sigemptyset (&action.sa_mask);\n\n    sigaction(SIGPIPE, &action, NULL);\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nvoid\ng_signal_usr1(void (*func)(int))\n{\n#if defined(_WIN32)\n#else\n    struct sigaction action;\n\n    if (func == NULL)\n    {\n        action.sa_handler = SIG_DFL;\n        action.sa_flags = 0;\n    }\n    else\n    {\n        action.sa_handler = func;\n        action.sa_flags = SA_RESTART;\n    }\n    sigemptyset (&action.sa_mask);\n\n    sigaction(SIGUSR1, &action, NULL);\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nint\ng_fork(void)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    int rv;\n\n    rv = fork();\n\n    if (rv == -1) /* error */\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Process fork failed with errno: %d, description: %s\",\n            g_get_errno(), g_get_strerror());\n    }\n\n    return rv;\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nint\ng_setgid(int pid)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return setgid(pid);\n#endif\n}\n\n/*****************************************************************************/\n/* Used by daemonizing code */\n/* returns error, zero is success, non zero is error */\nint\ng_drop_privileges(const char *user, const char *group)\n{\n    int rv = 1;\n    int uid;\n    int gid;\n    if (g_getuser_info_by_name(user, &uid, NULL, NULL, NULL, NULL) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to get UID for user '%s' [%s]\", user,\n            g_get_strerror());\n    }\n    else if (g_getgroup_info(group, &gid) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to get GID for group '%s' [%s]\", group,\n            g_get_strerror());\n    }\n    else if (initgroups(user, gid) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to init groups for '%s' [%s]\", user,\n            g_get_strerror());\n    }\n    else if (g_setgid(gid) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to set group to '%s' [%s]\", group,\n            g_get_strerror());\n    }\n    else if (g_setuid(uid) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to set user to '%s' [%s]\", user,\n            g_get_strerror());\n    }\n    else\n    {\n        rv = 0;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error, zero is success, non zero is error */\n/* does not work in win32 */\nint\ng_initgroups(const char *username)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    int gid;\n    int error = g_getuser_info_by_name(username, NULL, &gid, NULL, NULL, NULL);\n    if (error == 0)\n    {\n        error = initgroups(username, gid);\n    }\n    return error;\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\n/* returns user id */\nint\ng_getuid(void)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return getuid();\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\n/* returns user id */\nint\ng_getgid(void)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return getgid();\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\n/* On success, zero is returned. On error, -1 is returned */\nint\ng_setuid(int pid)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return setuid(pid);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_setsid(void)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    return setsid();\n#endif\n}\n\n/*****************************************************************************/\nint\ng_getlogin(char *name, unsigned int len)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    return getlogin_r(name, len);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_setlogin(const char *name)\n{\n#ifdef BSD\n    return setlogin(name);\n#else\n    return -1;\n#endif\n}\n\n/*****************************************************************************/\n#ifdef HAVE_SETUSERCONTEXT\nint\ng_set_allusercontext(int uid)\n{\n    int rv;\n    struct passwd *pwd = getpwuid(uid);\n    if (pwd == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"No password entry for UID %d\", uid);\n        rv = 1;\n    }\n    else\n    {\n        rv = setusercontext(NULL, pwd, uid, LOGIN_SETALL);\n        if (rv != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"setusercontext(%d) failed [%s]\",\n                uid, g_get_strerror());\n        }\n    }\n\n    return (rv != 0);  /* Return 0 or 1 */\n}\n#endif\n/*****************************************************************************/\n/* does not work in win32\n   returns pid of process that exits or zero if signal occurred\n   a proc_exit_status struct can optionally be passed in to get the\n   exit status of the child */\nint\ng_waitchild(struct proc_exit_status *e)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    int wstat;\n    int rv;\n\n    struct proc_exit_status dummy;\n\n    if (e == NULL)\n    {\n        e = &dummy;  // Set this, then throw it away\n    }\n\n    e->reason = E_PXR_UNEXPECTED;\n    e->val = 0;\n\n    rv = waitpid(-1, &wstat, WNOHANG);\n\n    if (rv == -1)\n    {\n        if (errno == EINTR)\n        {\n            /* This shouldn't happen as signal handlers use SA_RESTART */\n            rv = 0;\n        }\n    }\n    else if (WIFEXITED(wstat))\n    {\n        e->reason = E_PXR_STATUS_CODE;\n        e->val = WEXITSTATUS(wstat);\n    }\n    else if (WIFSIGNALED(wstat))\n    {\n        e->reason = E_PXR_SIGNAL;\n        e->val = WTERMSIG(wstat);\n    }\n\n    return rv;\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32\n   returns pid of process that exits or <= 0 if no process was found\n\n   Note that signal handlers are established with BSD-style semantics,\n   so this call is NOT interrupted by a signal  */\nint\ng_waitpid(int pid)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    int rv = 0;\n\n    if (pid < 0)\n    {\n        rv = -1;\n    }\n    else\n    {\n        rv = waitpid(pid, 0, 0);\n    }\n\n    return rv;\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32\n   returns exit status code of child process with pid\n\n   Note that signal handlers are established with BSD-style semantics,\n   so this call is NOT interrupted by a signal  */\nstruct proc_exit_status\ng_waitpid_status(int pid)\n{\n    struct proc_exit_status exit_status =\n    {\n        .reason = E_PXR_UNEXPECTED,\n        .val = 0\n    };\n\n#if !defined(_WIN32)\n    if (pid > 0)\n    {\n        int rv;\n        int status;\n\n        LOG(LOG_LEVEL_DEBUG, \"waiting for pid %d to exit\", pid);\n        rv = waitpid(pid, &status, 0);\n\n        if (rv != -1)\n        {\n            if (WIFEXITED(status))\n            {\n                exit_status.reason = E_PXR_STATUS_CODE;\n                exit_status.val = WEXITSTATUS(status);\n            }\n            if (WIFSIGNALED(status))\n            {\n                exit_status.reason = E_PXR_SIGNAL;\n                exit_status.val = WTERMSIG(status);\n            }\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING, \"wait for pid %d returned unknown result\", pid);\n        }\n    }\n\n#endif\n    return exit_status;\n}\n\n/*****************************************************************************/\nint\ng_setpgid(int pid, int pgid)\n{\n    int rv = setpgid(pid, pgid);\n    if (rv < 0)\n    {\n        if (pid == 0)\n        {\n            pid = getpid();\n        }\n        LOG(LOG_LEVEL_ERROR, \"Can't set process group ID of %d to %d [%s]\",\n            pid, pgid, g_get_strerror());\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nvoid\ng_clearenv(void)\n{\n#if defined(HAVE_CLEARENV)\n    clearenv();\n#elif defined(_WIN32)\n#elif defined(BSD)\n    extern char **environ;\n    environ[0] = 0;\n#else\n    extern char **environ;\n    environ = 0;\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nint\ng_setenv(const char *name, const char *value, int rewrite)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return setenv(name, value, rewrite);\n#endif\n}\n\n\n/*****************************************************************************/\n/* does not work in win32 */\nvoid\ng_setenv_log(const char *name, const char *value, int rewrite)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    if (setenv(name, value, rewrite) != 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Unable to set environment variable '%s' [%s]\",\n            name, g_get_strerror());\n    }\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nchar *\ng_getenv(const char *name)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return getenv(name);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_exit(int exit_code)\n{\n    exit(exit_code);\n    return 0;\n}\n\n/*****************************************************************************/\nint\ng_getpid(void)\n{\n#if defined(_WIN32)\n    return (int)GetCurrentProcessId();\n#else\n    return (int)getpid();\n#endif\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nint\ng_sigterm(int pid)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return kill(pid, SIGTERM);\n#endif\n}\n\n/*****************************************************************************/\nint g_pid_is_active(int pid)\n{\n    return (kill(pid, 0) == 0);\n}\n\n/*****************************************************************************/\n/* does not work in win32 */\nint\ng_sighup(int pid)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return kill(pid, SIGHUP);\n#endif\n}\n\n/*****************************************************************************/\n/* returns 0 if ok */\n/* the caller is responsible to free the buffs */\n/* does not work in win32 */\nint\ng_getuser_info_by_name(const char *username, int *uid, int *gid,\n                       char **shell, char **dir, char **gecos)\n{\n    int rv = 1;\n#if !defined(_WIN32)\n\n    if (username == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"g_getuser_info_by_name() called for NULL user\");\n    }\n    else\n    {\n        struct passwd *pwd_1 = getpwnam(username);\n\n        if (pwd_1 != 0)\n        {\n            rv = 0;\n\n            if (uid != 0)\n            {\n                *uid = pwd_1->pw_uid;\n            }\n\n            if (gid != 0)\n            {\n                *gid = pwd_1->pw_gid;\n            }\n\n            if (shell != 0)\n            {\n                *shell = g_strdup(pwd_1->pw_shell);\n            }\n\n            if (dir != 0)\n            {\n                *dir = g_strdup(pwd_1->pw_dir);\n            }\n\n            if (gecos != 0)\n            {\n                *gecos = g_strdup(pwd_1->pw_gecos);\n            }\n        }\n    }\n#endif\n    return rv;\n}\n\n\n/*****************************************************************************/\n/* returns 0 if ok */\n/* the caller is responsible to free the buffs */\n/* does not work in win32 */\nint\ng_getuser_info_by_uid(int uid, char **username, int *gid,\n                      char **shell, char **dir, char **gecos)\n{\n#if defined(_WIN32)\n    return 1;\n#else\n    struct passwd *pwd_1;\n\n    pwd_1 = getpwuid(uid);\n\n    if (pwd_1 != 0)\n    {\n        if (username != NULL)\n        {\n            *username = g_strdup(pwd_1->pw_name);\n        }\n\n        if (gid != 0)\n        {\n            *gid = pwd_1->pw_gid;\n        }\n\n        if (shell != 0)\n        {\n            *shell = g_strdup(pwd_1->pw_shell);\n        }\n\n        if (dir != 0)\n        {\n            *dir = g_strdup(pwd_1->pw_dir);\n        }\n\n        if (gecos != 0)\n        {\n            *gecos = g_strdup(pwd_1->pw_gecos);\n        }\n\n        return 0;\n    }\n\n    return 1;\n#endif\n}\n\n/*****************************************************************************/\n/* returns 0 if ok */\n/* does not work in win32 */\nint\ng_getgroup_info(const char *groupname, int *gid)\n{\n#if defined(_WIN32)\n    return 1;\n#else\n    struct group *g;\n\n    g = getgrnam(groupname);\n\n    if (g != 0)\n    {\n        if (gid != 0)\n        {\n            *gid = g->gr_gid;\n        }\n\n        return 0;\n    }\n\n    return 1;\n#endif\n}\n\n/*****************************************************************************/\n#ifdef HAVE_GETGROUPLIST\nint\ng_check_user_in_group(const char *username, int gid, int *ok)\n{\n    int rv = 1;\n    struct passwd *pwd_1 = getpwnam(username);\n    if (pwd_1 != NULL)\n    {\n        // Get number of groups for user\n        //\n        // Some implementations of getgrouplist() (i.e. muslc) don't\n        // allow ngroups to be <1 on entry\n        int ngroups = 1;\n        GETGROUPLIST_T dummy;\n        getgrouplist(username, pwd_1->pw_gid, &dummy, &ngroups);\n\n        if (ngroups > 0) // Should always be true\n        {\n            GETGROUPLIST_T *grouplist;\n            grouplist = (GETGROUPLIST_T *)malloc(ngroups * sizeof(grouplist[0]));\n            if (grouplist != NULL)\n            {\n                // Now get the actual groups. The number of groups returned\n                // by this call is not necessarily the same as the number\n                // returned by the first call.\n                int allocgroups = ngroups;\n                getgrouplist(username, pwd_1->pw_gid, grouplist, &ngroups);\n                ngroups = MIN(ngroups, allocgroups);\n\n                rv = 0;\n                *ok = 0;\n\n                int i;\n                for (i = 0 ; i < ngroups; ++i)\n                {\n                    if (grouplist[i] == (GETGROUPLIST_T)gid)\n                    {\n                        *ok = 1;\n                        break;\n                    }\n                }\n                free(grouplist);\n            }\n        }\n    }\n    return rv;\n}\n/*****************************************************************************/\n#else // HAVE_GETGROUPLIST\nint\ng_check_user_in_group(const char *username, int gid, int *ok)\n{\n#if defined(_WIN32)\n    return 1;\n#else\n    int i;\n\n    struct passwd *pwd_1 = getpwnam(username);\n    struct group *groups = getgrgid(gid);\n    if (pwd_1 == NULL || groups == NULL)\n    {\n        return 1;\n    }\n\n    if (pwd_1->pw_gid == gid)\n    {\n        *ok = 1;\n    }\n    else\n    {\n        *ok = 0;\n        i = 0;\n\n        while (0 != groups->gr_mem[i])\n        {\n            if (0 == g_strcmp(groups->gr_mem[i], username))\n            {\n                *ok = 1;\n                break;\n            }\n\n            i++;\n        }\n    }\n\n    return 0;\n#endif\n}\n#endif // HAVE_GETGROUPLIST\n\n/*****************************************************************************/\nunsigned int\ng_get_elapsed_ms(void)\n{\n    unsigned int result = 0;\n    struct timespec tp;\n\n    if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)\n    {\n        result = (unsigned int)tp.tv_sec * 1000;\n        // POSIX 1003.1-2004 specifies that tv_nsec is a long (i.e. a\n        // signed type), but can only contain [0..999,999,999]\n        result += tp.tv_nsec / 1000000;\n    }\n\n    return result;\n}\n\n/******************************************************************************/\n/******************************************************************************/\nstruct bmp_magic\n{\n    char magic[2];\n};\n\nstruct bmp_hdr\n{\n    unsigned int   size;        /* file size in bytes */\n    unsigned short reserved1;\n    unsigned short reserved2;\n    unsigned int   offset;      /* offset to image data, in bytes */\n};\n\nstruct dib_hdr\n{\n    unsigned int   hdr_size;\n    int            width;\n    int            height;\n    unsigned short nplanes;\n    unsigned short bpp;\n    unsigned int   compress_type;\n    unsigned int   image_size;\n    int            hres;\n    int            vres;\n    unsigned int   ncolors;\n    unsigned int   nimpcolors;\n};\n\n/******************************************************************************/\nint\ng_save_to_bmp(const char *filename, char *data, int stride_bytes,\n              int width, int height, int depth, int bits_per_pixel)\n{\n    struct bmp_magic bm;\n    struct bmp_hdr bh;\n    struct dib_hdr dh;\n    int bytes;\n    int fd;\n    int index;\n    int i1;\n    int pixel;\n    int extra;\n    int file_stride_bytes;\n    char *line;\n    char *line_ptr;\n\n    if ((depth == 24) && (bits_per_pixel == 32))\n    {\n    }\n    else if ((depth == 32) && (bits_per_pixel == 32))\n    {\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"g_save_to_bpp: unimplemented for: depth %d, bits_per_pixel %d\",\n            depth, bits_per_pixel);\n        return 1;\n    }\n    bm.magic[0] = 'B';\n    bm.magic[1] = 'M';\n\n    /* scan lines are 32 bit aligned, bottom 2 bits must be zero */\n    file_stride_bytes = width * ((depth + 7) / 8);\n    extra = file_stride_bytes;\n    extra = extra & 3;\n    extra = (4 - extra) & 3;\n    file_stride_bytes += extra;\n\n    bh.size = sizeof(bm) + sizeof(bh) + sizeof(dh) + height * file_stride_bytes;\n    bh.reserved1 = 0;\n    bh.reserved2 = 0;\n    bh.offset = sizeof(bm) + sizeof(bh) + sizeof(dh);\n\n    dh.hdr_size = sizeof(dh);\n    dh.width = width;\n    dh.height = height;\n    dh.nplanes = 1;\n    dh.bpp = depth;\n    dh.compress_type = 0;\n    dh.image_size = height * file_stride_bytes;\n    dh.hres = 0xb13;\n    dh.vres = 0xb13;\n    dh.ncolors = 0;\n    dh.nimpcolors = 0;\n\n    fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);\n    if (fd == -1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"g_save_to_bpp: open error\");\n        return 1;\n    }\n    bytes = write(fd, &bm, sizeof(bm));\n    if (bytes != sizeof(bm))\n    {\n        LOG(LOG_LEVEL_ERROR, \"g_save_to_bpp: write error\");\n    }\n    bytes = write(fd, &bh, sizeof(bh));\n    if (bytes != sizeof(bh))\n    {\n        LOG(LOG_LEVEL_ERROR, \"g_save_to_bpp: write error\");\n    }\n    bytes = write(fd, &dh, sizeof(dh));\n    if (bytes != sizeof(dh))\n    {\n        LOG(LOG_LEVEL_ERROR, \"g_save_to_bpp: write error\");\n    }\n    data += stride_bytes * height;\n    data -= stride_bytes;\n    if ((depth == 24) && (bits_per_pixel == 32))\n    {\n        line = (char *) g_malloc_nofail(file_stride_bytes);\n        memset(line, 0, file_stride_bytes);\n        for (index = 0; index < height; index++)\n        {\n            line_ptr = line;\n            for (i1 = 0; i1 < width; i1++)\n            {\n                pixel = ((int *)data)[i1];\n                *(line_ptr++) = (pixel >>  0) & 0xff;\n                *(line_ptr++) = (pixel >>  8) & 0xff;\n                *(line_ptr++) = (pixel >> 16) & 0xff;\n            }\n            bytes = write(fd, line, file_stride_bytes);\n            if (bytes != file_stride_bytes)\n            {\n                LOG(LOG_LEVEL_ERROR, \"g_save_to_bpp: write error\");\n            }\n            data -= stride_bytes;\n        }\n        free(line);\n    }\n    else if (depth == bits_per_pixel)\n    {\n        for (index = 0; index < height; index++)\n        {\n            bytes = write(fd, data, width * (bits_per_pixel / 8));\n            if (bytes != width * (bits_per_pixel / 8))\n            {\n                LOG(LOG_LEVEL_ERROR, \"g_save_to_bpp: write error\");\n            }\n            data -= stride_bytes;\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"g_save_to_bpp: unimplemented for: depth %d, bits_per_pixel %d\",\n            depth, bits_per_pixel);\n    }\n    close(fd);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns pointer or nil on error */\nvoid *\ng_shmat(int shmid)\n{\n#if defined(_WIN32)\n    return 0;\n#else\n    return shmat(shmid, 0, 0);\n#endif\n}\n\n/*****************************************************************************/\n/* returns -1 on error 0 on success */\nint\ng_shmdt(const void *shmaddr)\n{\n#if defined(_WIN32)\n    return -1;\n#else\n    return shmdt(shmaddr);\n#endif\n}\n\n/*****************************************************************************/\n/* returns -1 on error 0 on success */\nint\ng_gethostname(char *name, int len)\n{\n    return gethostname(name, len);\n}\n\nstatic unsigned char g_reverse_byte[0x100] =\n{\n    0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,\n    0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,\n    0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,\n    0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,\n    0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,\n    0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,\n    0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,\n    0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,\n    0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,\n    0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,\n    0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,\n    0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,\n    0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,\n    0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,\n    0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,\n    0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,\n    0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,\n    0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,\n    0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,\n    0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,\n    0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,\n    0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,\n    0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,\n    0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,\n    0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,\n    0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,\n    0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,\n    0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,\n    0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,\n    0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,\n    0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,\n    0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff\n};\n\n/*****************************************************************************/\n/* mirror each byte while copying */\nint\ng_mirror_memcpy(void *dst, const void *src, int len)\n{\n    tui8 *dst8;\n    const tui8 *src8;\n\n    dst8 = (tui8 *) dst;\n    src8 = (const tui8 *) src;\n    while (len > 0)\n    {\n        *dst8 = g_reverse_byte[*src8];\n        dst8++;\n        src8++;\n        len--;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\ng_tcp4_socket(void)\n{\n#if defined(XRDP_ENABLE_IPV6ONLY)\n    return -1;\n#else\n    return socket(AF_INET, SOCK_STREAM, 0);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_tcp4_bind_address(int sck, const char *port, const char *address)\n{\n#if defined(XRDP_ENABLE_IPV6ONLY)\n    return -1;\n#else\n    struct sockaddr_in s;\n\n    memset(&s, 0, sizeof(s));\n    s.sin_family = AF_INET;\n    s.sin_addr.s_addr = htonl(INADDR_ANY);\n    s.sin_port = htons((uint16_t) atoi(port));\n    if (inet_aton(address, &s.sin_addr) < 0)\n    {\n        return -1; /* bad address */\n    }\n    if (bind(sck, (struct sockaddr *) &s, sizeof(s)) < 0)\n    {\n        return -1;\n    }\n    return 0;\n#endif\n}\n\n/*****************************************************************************/\nint\ng_tcp6_socket(void)\n{\n#if defined(XRDP_ENABLE_IPV6)\n    int rv;\n    int option_value;\n    socklen_t option_len;\n\n    rv = socket(AF_INET6, SOCK_STREAM, 0);\n    if (rv < 0)\n    {\n        return -1;\n    }\n    option_len = sizeof(option_value);\n    if (getsockopt(rv, IPPROTO_IPV6, IPV6_V6ONLY,\n                   (char *) &option_value, &option_len) == 0)\n    {\n#if defined(XRDP_ENABLE_IPV6ONLY)\n        if (option_value == 0)\n        {\n            option_value = 1;\n#else\n        if (option_value != 0)\n        {\n            option_value = 0;\n#endif\n            option_len = sizeof(option_value);\n            if (setsockopt(rv, IPPROTO_IPV6, IPV6_V6ONLY,\n                           (char *) &option_value, option_len) < 0)\n            {\n            }\n        }\n    }\n    return rv;\n#else\n    return -1;\n#endif\n}\n\n/*****************************************************************************/\nint\ng_tcp6_bind_address(int sck, const char *port, const char *address)\n{\n#if defined(XRDP_ENABLE_IPV6)\n    int rv;\n    int error;\n    struct addrinfo hints;\n    struct addrinfo *list;\n    struct addrinfo *i;\n\n    rv = -1;\n    memset(&hints, 0, sizeof(hints));\n    hints.ai_family = AF_UNSPEC;\n    hints.ai_flags = 0;\n    hints.ai_socktype = SOCK_STREAM;\n    hints.ai_protocol = IPPROTO_TCP;\n    error = getaddrinfo(address, port, &hints, &list);\n    if (error == 0)\n    {\n        i = list;\n        while ((i != NULL) && (rv < 0))\n        {\n            rv = bind(sck, i->ai_addr, i->ai_addrlen);\n            i = i->ai_next;\n        }\n        freeaddrinfo(list);\n    }\n    else\n    {\n        return -1;\n    }\n    return rv;\n#else\n    return -1;\n#endif\n}\n\n/*****************************************************************************/\n/* returns error, zero is success, non zero is error */\n/* only works in linux */\nint\ng_no_new_privs(void)\n{\n#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NO_NEW_PRIVS)\n    /*\n     * PR_SET_NO_NEW_PRIVS requires Linux kernel 3.5 and newer.\n     */\n    return prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);\n#else\n    return 0;\n#endif\n}\n\n\n/*****************************************************************************/\nint\ng_fips_mode_enabled(void)\n{\n    int rv = 0;\n#if defined (__linux)\n    char buff[16];\n    int fd = open(\"/proc/sys/crypto/fips_enabled\", O_RDONLY);\n\n    if (fd >= 0)\n    {\n        ssize_t res = read(fd, buff, sizeof(buff));\n        if (res > 0 && (size_t)res < sizeof(buff))\n        {\n            rv = (buff[0] != '0');\n        }\n\n        close(fd);\n    }\n#endif\n    return rv;\n}\n\n/*****************************************************************************/\nvoid\ng_qsort(void *base, size_t nitems, size_t size,\n        int (*compar)(const void *, const void *))\n{\n    qsort(base, nitems, size, compar);\n}\n\n/*****************************************************************************/\nstruct list *\ng_readdir(const char *dir)\n{\n    DIR *handle;\n    struct list *result = NULL;\n    struct dirent *dent;\n    int saved_errno;\n\n    errno = 0; // See readdir(3)\n    if ((handle = opendir(dir)) != NULL &&\n            (result = list_create()) != NULL)\n    {\n        result->auto_free = 1;\n        while (1)\n        {\n            errno = 0;\n            dent = readdir(handle);\n            if (dent == NULL)\n            {\n                break; // errno = 0 for end-of-dir, or != 0 for error\n            }\n\n            // Ignore '.' and '..'\n            if (dent->d_name[0] == '.' && dent->d_name[1] == '\\0')\n            {\n                continue;\n            }\n            if (dent->d_name[0] == '.' && dent->d_name[1] == '.' &&\n                    dent->d_name[2] == '\\0')\n            {\n                continue;\n            }\n\n            if (!list_add_strdup(result, dent->d_name))\n            {\n                // Memory allocation failure\n                errno = ENOMEM;\n                break;\n            }\n        }\n    }\n\n    saved_errno = errno;\n    if (errno != 0)\n    {\n        list_delete(result);\n        result = NULL;\n    }\n    if (handle != NULL)\n    {\n        closedir(handle);\n    }\n    errno = saved_errno;\n\n    return result;\n}\n\n/******************************************************************************/\noom_type\ng_set_out_of_memory_handler(oom_type new_handler)\n{\n    oom_type old_handler = g_out_of_memory_handler;\n    g_out_of_memory_handler = new_handler;\n    return old_handler;\n}\n\n/******************************************************************************/\nstatic void\nout_of_memory(void)\n{\n    if (g_out_of_memory_handler != NULL)\n    {\n        g_out_of_memory_handler();\n        _exit(1);\n    }\n    else\n    {\n        abort();\n    }\n}\n\n/******************************************************************************/\nvoid *\ng_malloc_nofail(size_t size)\n{\n    void *res = malloc(size);\n    if (res == NULL)\n    {\n        LOG(LOG_LEVEL_ALWAYS, \"g_malloc_nofail() can't allocate %zu bytes\",\n            size);\n        out_of_memory();\n    }\n    return res;\n}\n\n/******************************************************************************/\nvoid *\ng_calloc_nofail(size_t nmemb, size_t size)\n{\n    void *res = calloc(nmemb, size);\n    if (res == NULL)\n    {\n        LOG(LOG_LEVEL_ALWAYS,\n            \"g_calloc_nofail() can't allocate %zu * %zu bytes\",\n            nmemb, size);\n        out_of_memory();\n    }\n    return res;\n}\n"
  },
  {
    "path": "common/os_calls.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * generic operating system calls\n */\n\n#if !defined(OS_CALLS_H)\n#define OS_CALLS_H\n\n#include \"arch.h\"\n\nenum proc_exit_reason\n{\n    E_PXR_STATUS_CODE = 0, ///< 'val' contains exit status\n    E_PXR_SIGNAL, ///< 'val' contains a signal number\n    E_PXR_UNEXPECTED\n};\n\nstruct proc_exit_status\n{\n    enum proc_exit_reason reason;\n    int val;\n};\n\nstruct list;\n\n/** Out-of-memory handler type */\ntypedef void (*oom_type)(void);\n\n#define g_tcp_can_recv g_sck_can_recv\n#define g_tcp_can_send g_sck_can_send\n#define g_tcp_recv g_sck_recv\n#define g_tcp_send g_sck_send\n#define g_tcp_close g_sck_close\n#define g_tcp_last_error_would_block g_sck_last_error_would_block\n#define g_tcp_set_non_blocking g_sck_set_non_blocking\n#define g_tcp_local_socket g_sck_local_socket\n#define g_tcp_local_connect g_sck_local_connect\n#define g_tcp_listen g_sck_listen\n#define g_tcp_local_bind g_sck_local_bind\n#define g_tcp_select g_sck_select\n#define g_close_wait_obj g_delete_wait_obj\n\nint      g_rm_temp_dir(void);\nvoid     g_init(const char *app_name);\nvoid     g_deinit(void);\nvoid g_printf(const char *format, ...) printflike(1, 2);\nvoid g_sprintf(char *dest, const char *format, ...) \\\nprintflike(2, 3);\nint  g_snprintf(char *dest, int len, const char *format, ...) \\\nprintflike(3, 4);\nvoid g_writeln(const char *format, ...) printflike(1, 2);\nvoid g_write(const char *format, ...) printflike(1, 2);\nvoid     g_hexdump(const char *p, int len);\nint      g_getchar(void);\nint      g_tcp_set_no_delay(int sck);\nint      g_tcp_set_keepalive(int sck);\nint      g_tcp_socket(void);\nint      g_sck_set_send_buffer_bytes(int sck, int bytes);\nint      g_sck_get_send_buffer_bytes(int sck, int *bytes);\nint      g_sck_set_recv_buffer_bytes(int sck, int bytes);\nint      g_sck_get_recv_buffer_bytes(int sck, int *bytes);\n/**\n * Set SO_REUSEADDR for a socket\n *\n * Use before binding, if appropriate.\n * @param sck Socket\n * @return 0 for success\n */\nint      g_sck_set_reuseaddr(int sck);\nint      g_sck_local_socket(void);\nint      g_sck_local_socketpair(int sck[2]);\nint      g_sck_vsock_socket(void);\nint      g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid);\nvoid     g_sck_close(int sck);\nint      g_tcp_connect(int sck, const char *address, const char *port);\nint      g_sck_local_connect(int sck, const char *port);\nint      g_sck_set_non_blocking(int sck);\nint      g_tcp_bind(int sck, const char *port);\nint      g_sck_local_bind(int sck, const char *port);\nint      g_sck_vsock_bind(int sck, const char *port);\nint      g_sck_vsock_bind_address(int sck, const char *port, const char *address);\nint      g_tcp_bind_address(int sck, const char *port, const char *address);\nint      g_sck_listen(int sck);\nint      g_sck_accept(int sck);\nint      g_sck_recv(int sck, void *ptr, unsigned int len, int flags);\nint      g_sck_send(int sck, const void *ptr, unsigned int len, int flags);\n/**\n * Receives data and file descriptors on a unix domain socket\n *\n * @param sck - Socket to receive data + file descriptors from\n * @param ptr - Pointer to buffer for incoming data\n * @param len - Length of data. Must be > 0\n * @param[out] fds - Array of file descriptors\n * @param [in] maxfd - Max number of elements in fds\n * @param[out] fdcount - Actual number of file descriptors received\n * @return Bytes received, or < 0 for error.\n *\n * If the result is > 0 but less than len, the file descriptors have\n * been received. Get the rest of the data with normal g_sck_recv() calls.\n *\n * fdcount may be more that maxfd. This indicates that more file descriptors\n * were received than there was space for. The excess file descriptors\n * are closed and discarded.\n */\nint      g_sck_recv_fd_set(int sck, void *ptr, unsigned int len,\n                           int fds[], unsigned int maxfd,\n                           unsigned int *fdcount);\n/**\n * Sends data and file descriptors on a unix domain socket\n *\n * @param sck - Socket to send data + file descriptors on\n * @param ptr - Data to send\n * @param len - Length of data. Must be > 0\n * @param fds - Array of file descriptors\n * @param fdcount - Number of file descriptors\n * @return Bytes sent, or < 0 for error.\n *\n * If the result is > 0 but less than len, the file descriptors have\n * been sent. Send the rest of the data with normal g_sck_send() calls.\n */\nint      g_sck_send_fd_set(int sck, const void *ptr, unsigned int len,\n                           int fds[], unsigned int fdcount);\nint      g_alloc_shm_map_fd(void **addr, int *fd, size_t size);\nint      g_sck_last_error_would_block(int sck);\nint      g_sck_socket_ok(int sck);\n/**\n * Checks socket writeability with an optional wait\n *\n * @param sck - Socket to check\n * @param millis - Maximum milliseconds to wait for writeability to be true\n *\n * @note The wait time may not be reached in the event of an incoming signal\n *       so do not use this call to impose a hard timeout */\nint      g_sck_can_send(int sck, int millis);\n/**\n * Checks socket readability with an optional wait\n *\n * @param sck - Socket to check\n * @param millis - Maximum milliseconds to wait for readability to be true\n *\n * @note The wait time may not be reached in the event of an incoming signal\n *       so do not use this call to impose a hard timeout */\nint      g_sck_can_recv(int sck, int millis);\nint      g_sck_select(int sck1, int sck2);\n\n/**\n * Gets the IP address of a connected peer, if it has one\n * @param sck File descriptor for peer\n * @param ip buffer to write IP address to\n * @param bytes Size of ip buffer. Should be at least MAX_IP_ADDRSTRLEN\n * @param[out] port Optional variable to receive the port number\n * @return Pointer to IP for convenience\n *\n * If the peer has no IP address (for example, it is a Unix Domain Socket),\n * or the specified buffer is too small, the returned string is \"\"\n */\nconst char *\ng_sck_get_peer_ip_address(int sck,\n                          char *ip, unsigned int bytes,\n                          unsigned short *port);\n/**\n * Gets a description for a connected peer\n * @param sck File descriptor for peer\n * @param desc buffer to write description to\n * @param bytes Size of description buffer. Should be at least\n *              MAX_PEER_DESCSTRLEN\n * @return Pointer to desc for convenience\n *\n * Unlike g_sck_get_peer_ip_address(), this will return a\n * description of some sort for any socket type.\n */\nconst char *\ng_sck_get_peer_description(int sck,\n                           char *desc, unsigned int bytes);\n/**\n * Sleep for the specified number of milli-seconds\n * @param msecs Milli-seconds\n *\n * If a signal is processed, it is possible that this call will\n * sleep for less than the specified number of milli-seconds. This\n * is platform-specific\n */\nvoid     g_sleep(int msecs);\nint      g_pipe(int fd[2]);\n\n// Wait objects with this value are ignored by\n// g_set_wait_obj() / g_reset_wait_obj() / g_is_wait_obj_set() /\n// g_delete_wait_obj()\n#define NULL_WAIT_OBJ (tintptr)0\n\ntintptr  g_create_wait_obj(const char *name);\ntintptr  g_create_wait_obj_from_socket(tintptr socket, int write);\nvoid     g_delete_wait_obj_from_socket(tintptr wait_obj);\nint      g_set_wait_obj(tintptr obj);\nint      g_reset_wait_obj(tintptr obj);\nint      g_is_wait_obj_set(tintptr obj);\nint      g_delete_wait_obj(tintptr obj);\n/**\n * Wait for the specified readable and writeable objs\n *\n * The wait finishes when at least one of the objects becomes\n * readable or writeable\n *\n * @param read_objs Array of read objects\n * @param rcount Number of elements in read_objs\n * @param write_objs Array of write objects\n * @param wcount Number of elements in write_objs\n * @param mstimeout Timeout in milliseconds. < 0 means an infinite timeout.\n *\n * @return 0 for success. The objects will need to be polled to\n * find out what is readable or writeable.\n *\n * An mstimeout of zero will return immediately, although\n * error conditions may be checked for.\n */\nint      g_obj_wait(tintptr *read_objs, int rcount, tintptr *write_objs,\n                    int wcount, int mstimeout);\nvoid     g_random(char *data, int len);\nint      g_abs(int i);\nint      g_memcmp(const void *s1, const void *s2, int len);\nint      g_file_open_rw(const char *file_name);\nint      g_file_open_ex(const char *file_name, int aread, int awrite,\n                        int acreate, int atrunc);\nint      g_file_open_ro(const char *file_name);\nint      g_file_close(int fd);\n/**\n * Returns 1 if a file is open (i.e. the file descriptor is valid)\n * @param fd File descriptor\n * @return 1 for file open, 0 for not open\n */\nint      g_file_is_open(int fd);\nint      g_file_read(int fd, char *ptr, int len);\nint      g_file_write(int fd, const char *ptr, int len);\nint      g_file_seek(int fd, int offset);\nint      g_file_seek_end(int fd, int offset);\nint      g_file_lock(int fd, int start, int len);\nint\ng_file_map(int fd, int aread, int awrite, size_t length, void **addr);\nint\ng_munmap(void *addr, size_t length);\nint      g_file_duplicate_on(int fd, int target_fd);\nint      g_file_get_cloexec(int fd);\nint      g_file_set_cloexec(int fd, int status);\n/**\n * Get a list of open file descriptors\n *\n * @param min Min FD to consider\n * @param max Max FD to consider (+1), or -1 for no limit\n * @result Array of file descriptors, in ascending order.\n *\n * Call delete_list() on the result when you've finished with it.\n */\nstruct list *g_get_open_fds(int min, int max);\nint      g_chmod_hex(const char *filename, int flags);\nint      g_umask_hex(int flags);\nint      g_chown(const char *name, int uid, int gid);\nint      g_mkdir(const char *dirname);\nchar    *g_get_current_dir(char *dirname, int maxlen);\nint      g_set_current_dir(const char *dirname);\nint      g_file_exist(const char *filename);\nint      g_file_readable(const char *filename);\nint      g_directory_exist(const char *dirname);\nint      g_executable_exist(const char *dirname);\nint      g_socket_exist(const char *dirname);\nint      g_create_dir(const char *dirname);\nint      g_create_path(const char *path);\nint      g_remove_dir(const char *dirname);\nint      g_file_delete(const char *filename);\nint      g_file_get_size(const char *filename);\nint      g_file_get_device_number(const char *filename);\nint      g_file_get_inode_num(const char *filename);\nlong     g_load_library(char *in);\nint      g_free_library(long lib);\nvoid    *g_get_proc_address(long lib, const char *name);\nint      g_system(const char *aexec);\nchar    *g_get_strerror(void);\nint      g_get_errno(void);\nint      g_execvp(const char *p1, char *args[]);\n/**\n * Issues an execvp() call\n *\n * @param file Executable\n * @param argv Argument list for executable.\n *\n * argv does not need to be NULL terminated - the call takes care\n * of this.\n *\n * @return Only if an error has occurred - use g_get_errno() or equivalent\n */\nint      g_execvp_list(const char *file, struct list *argv);\nint      g_execlp3(const char *a1, const char *a2, const char *a3);\n/**\n * Set an alarm using SIGALRM\n * @param func Signal handler, or NULL to cancel an alarm\n * @param secs Number of seconds until an alarm is raised\n * @return Number of seconds remaining before a previously requested\n *         alarm is raised\n */\nunsigned int g_set_alarm(void (*func)(int), unsigned int secs);\n/**\n * Set a handler up for SIGCHLD\n * @param func signal handler, or NULL to restore the default handler\n * The handler remains in place until explicitly replaced.\n */\nvoid     g_signal_child_stop(void (*func)(int));\n/**\n * Set a handler up for SIGSEGV\n * @param func signal handler, or NULL to restore the default handler\n * The handler can only be called once, at which point the\n * default handler is restored. This is to avoid infinite loops\n */\nvoid     g_signal_segfault(void (*func)(int));\n/**\n * Set a handler up for SIGHUP\n * @param func signal handler, or NULL to restore the default handler\n * The handler remains in place until explicitly replaced.\n */\nvoid     g_signal_hang_up(void (*func)(int));\n/**\n * Set a handler up for SIGINT\n * @param func signal handler, or NULL to restore the default handler\n * The handler remains in place until explicitly replaced.\n */\nvoid     g_signal_user_interrupt(void (*func)(int));\n/**\n * Set a handler up for SIGTERM\n * @param func signal handler, or NULL to restore the default handler\n * The handler remains in place until explicitly replaced.\n */\nvoid     g_signal_terminate(void (*func)(int));\n/**\n * Set a handler up for SIGPIPE\n * @param func signal handler, or NULL to restore the default handler\n * The handler remains in place until explicitly replaced.\n */\nvoid     g_signal_pipe(void (*func)(int));\n/**\n * Set a handler up for SIGUSR1\n * @param func signal handler, or NULL to restore the default handler\n * The handler remains in place until explicitly replaced.\n */\nvoid     g_signal_usr1(void (*func)(int));\nint      g_fork(void);\nint      g_setgid(int pid);\nint      g_drop_privileges(const char *user, const char *group);\nint      g_initgroups(const char *user);\nint      g_getuid(void);\nint      g_getgid(void);\nint      g_setuid(int pid);\nint      g_setsid(void);\nint      g_getlogin(char *name, unsigned int len);\nint      g_setlogin(const char *name);\n#ifdef HAVE_SETUSERCONTEXT\n/** Sets the login user context (BSD systems only)\n * @param uid UID of suer\n * @return 0 for success\n */\nint      g_set_allusercontext(int uid);\n#endif\nint      g_waitchild(struct proc_exit_status *e);\nint      g_waitpid(int pid);\nstruct proc_exit_status g_waitpid_status(int pid);\n/*\n * Sets the process group ID of the indicated process to the specified value.\n * (POSIX.1)\n *\n * Errors are logged.\n *\n * May do nothing if process groups are not supported\n */\nint      g_setpgid(int pid, int pgid);\nvoid     g_clearenv(void);\nint      g_setenv(const char *name, const char *value, int rewrite);\nchar    *g_getenv(const char *name);\n/**\n * Calls g_setenv(), logging failures\n *\n * @param name Name to set\n * @param value String to set $name to\n * @param rewrite Set to non-zero to allow rewriting of existing names\n *\n * Unlike g_setenv() this function returns no value. Use this function if the\n * only reasonable thing to do on failure is to log it.\n */\nvoid     g_setenv_log(const char *name, const char *value, int rewrite);\nint      g_exit(int exit_code);\nint      g_getpid(void);\nint      g_sigterm(int pid);\nint      g_sighup(int pid);\n/*\n * Is a particular PID active?\n * @param pid PID to check\n * Returns boolean\n */\nint      g_pid_is_active(int pid);\nint      g_getuser_info_by_name(const char *username, int *uid, int *gid,\n                                char **shell, char **dir, char **gecos);\nint      g_getuser_info_by_uid(int uid, char **username, int *gid,\n                               char **shell, char **dir, char **gecos);\nint      g_getgroup_info(const char *groupname, int *gid);\n/**\n * Checks whether a user is in the specified group\n * @param username Name of user\n * @param gid GID of group\n * @param[out] ok Whether user is in group\n * @return Non-zero if a system error occurred. In this instance OK is not set\n *\n * Primary group of username is also checked\n */\nint      g_check_user_in_group(const char *username, int gid, int *ok);\n\n/**\n * Gets elapsed milliseconds since some arbitrary point in the past\n *\n * The returned value is unaffected by leap-seconds or time zone changes.\n *\n * @return elaped ms since some arbitrary point\n *\n * Calculate the duration of a task by calling this routine before and\n * after the task, and subtracting the two values.\n *\n * The value wraps every so often (every 49.7 days on a 32-bit system),\n * but as we are using unsigned arithmetic, the difference of any of these\n * two values can be used to calculate elapsed time, whether-or-not a wrap\n * occurs during the interval - provided of course the time being measured\n * is less than the total wrap-around interval.\n */\nunsigned int\ng_get_elapsed_ms(void);\n\nint      g_save_to_bmp(const char *filename, char *data, int stride_bytes,\n                       int width, int height, int depth, int bits_per_pixel);\nvoid    *g_shmat(int shmid);\nint      g_shmdt(const void *shmaddr);\nint      g_gethostname(char *name, int len);\nint      g_mirror_memcpy(void *dst, const void *src, int len);\nint      g_tcp4_socket(void);\nint      g_tcp4_bind_address(int sck, const char *port, const char *address);\nint      g_tcp6_socket(void);\nint      g_tcp6_bind_address(int sck, const char *port, const char *address);\nint      g_no_new_privs(void);\n/**\n * Query whether FIPS mode is enabled\n *\n * In FIPS mode, some cryptographic algorithms are disabled\n *\n * @return 1 -> FIPS mode enabled, 0 -> FIPS mode disabled or unknown\n */\nint      g_fips_mode_enabled(void);\nvoid\ng_qsort(void *base, size_t nitems, size_t size,\n        int (*compar)(const void *, const void *));\n\n/**\n * Returns a list of the filenames contained within a directory\n *\n * @param dir Name of directory\n * @return list of directory entry names\n *\n * If NULL is returned, further information may be available in errno. No\n * other errors are specifically logged.\n * The special files '.' and '..' are not returned.\n */\nstruct list *\ng_readdir(const char *dir);\n\n/** Set the out-of-memory handler\n * @param new_handler Function to call if a memory allocation fails\n * @result old handler or NULL if none.\n *\n * After calling an out-of-memory handler, the program exits\n * If no out-of-memory handler is set, the program aborts\n *\n * Only use this function if there is urgent cleaning-up that must be done\n * before the program exits.\n */\noom_type\ng_set_out_of_memory_handler(oom_type new_handler);\n\n/** Allocate memory with error-checking\n *\n * @param size Size of memory to allocate\n * @return Allocated memory\n *\n * If memory cannot be allocated, the out-of-memory handler is called and\n * the program exits\n *\n * Only use this function if you are unable to handle an out-of-memory\n * condition.\n */\nvoid *\ng_malloc_nofail(size_t size);\n\n/** Allocate memory with error-checking\n *\n * @param nmemb Number of elements to allocate\n * @param size Size of each element\n * @return Allocated memory\n *\n * If memory cannot be allocated, the out-of-memory handler is called and\n * the program exits\n *\n * Only use this function if you are unable to handle an out-of-memory\n * condition.\n */\nvoid *\ng_calloc_nofail(size_t nmemb, size_t size);\n\n/* glib-style wrappers */\n#define g_new(struct_type, n_structs) \\\n    (struct_type *) g_malloc_nofail(sizeof(struct_type) * (n_structs))\n#define g_new0(struct_type, n_structs) \\\n    (struct_type *) g_calloc_nofail((n_structs), sizeof(struct_type))\n\n/* remove these when no longer used */\n#define g_malloc(_size, _zero) \\\n    (_zero ? g_calloc_nofail(1, _size) : g_malloc_nofail(_size))\n#define g_free free\n#define g_memset memset\n#define g_memcpy memcpy\n#define g_memmove memmove\n\n#endif\n"
  },
  {
    "path": "common/parse.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) 2021 Matt Burt\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Enforce stream primitive checking\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n#include \"unicode_defines.h\"\n\n/******************************************************************************/\n\n#if defined(B_ENDIAN) || defined(NEED_ALIGN)\n#define out_uint16_le_unchecked(s, v) do \\\n    { \\\n        *((s)->p) = (unsigned char)((v) >> 0); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 8); \\\n        (s)->p++; \\\n    } while (0)\n#else\n#define out_uint16_le_unchecked(s, v) do \\\n    { \\\n        *((unsigned short*)((s)->p)) = (unsigned short)(v); \\\n        (s)->p += 2; \\\n    } while (0)\n#endif\n\n/******************************************************************************/\n#if defined(B_ENDIAN) || defined(NEED_ALIGN)\n#define in_uint16_le_unchecked(s, v) do \\\n    { \\\n        (v) = (unsigned short) \\\n              ( \\\n                (*((unsigned char*)((s)->p + 0)) << 0) | \\\n                (*((unsigned char*)((s)->p + 1)) << 8) \\\n              ); \\\n        (s)->p += 2; \\\n    } while (0)\n#else\n#define in_uint16_le_unchecked(s, v) do \\\n    { \\\n        (v) = *((unsigned short*)((s)->p)); \\\n        (s)->p += 2; \\\n    } while (0)\n#endif\n\n/******************************************************************************/\nvoid\nparser_stream_overflow_check(const struct stream *s, int n, int is_out,\n                             const char *file, int line)\n{\n    /* Sanity checks */\n    if (n < 0)\n    {\n        LOG(LOG_LEVEL_ALWAYS, \"%s:%d \"\n            \"stream primitive called with negative n=%d\",\n            file, line, n);\n        abort();\n    }\n\n    if (is_out)\n    {\n        /* Output overflow */\n        if (!s_check_rem_out(s, n))\n        {\n            LOG(LOG_LEVEL_ALWAYS, \"%s:%d Stream output buffer overflow. \"\n                \"Size=%d, pos=%d, requested=%d\", file, line,\n                s->size, (int)(s->p - s->data), n);\n            abort();\n        }\n    }\n    else\n    {\n        /* Input overflow */\n        if (!s_check_rem(s, n))\n        {\n            LOG(LOG_LEVEL_ALWAYS, \"%s:%d Stream input buffer overflow. \"\n                \"Max=%d, pos=%d, requested=%d\", file, line,\n                (int)(s->end - s->data), (int)(s->p - s->data), n);\n            abort();\n        }\n    }\n}\n\n/******************************************************************************/\nvoid\nout_utf8_as_utf16_le_proc(struct stream *s, const char *v,\n                          unsigned int vn,\n                          const char *file, int line)\n{\n    // Expansion of S_CHECK_REM_OUT(s, <octet_count>) using passed-in\n    // file and line\n#ifdef USE_DEVEL_STREAMCHECK\n    int octet_cnt = utf8_as_utf16_word_count(v, vn) * 2;\n    parser_stream_overflow_check(s, octet_cnt, 1, file, line);\n#endif\n\n    while (vn > 0)\n    {\n        char32_t c32 = utf8_get_next_char(&v, &vn);\n        char16_t low;\n        if (c32 < 0x10000)\n        {\n            low = (char16_t)c32;\n        }\n        else\n        {\n            /* Need a surrogate pair */\n            low = LOW_SURROGATE_FROM_C32(c32);\n            char16_t high = HIGH_SURROGATE_FROM_C32(c32);\n            out_uint16_le_unchecked(s, high);\n        }\n        out_uint16_le_unchecked(s, low);\n    }\n}\n\n/******************************************************************************/\n/**\n * Gets the next Unicode character from a code stream\n * @param s Stream\n * @return Unicode character\n *\n * Non-characters and illegally coded characters are mapped to\n * UCS_REPLACEMENT_CHARACTER\n *\n * @pre Two bytes are assumed to be available on the stram on entry\n */\nstatic char32_t\nget_c32_from_stream(struct stream *s)\n{\n    char32_t c32 = UCS_REPLACEMENT_CHARACTER; // Assume failure\n    char16_t w;\n\n    in_uint16_le_unchecked(s, w);\n\n    if (IS_HIGH_SURROGATE(w))\n    {\n        if (s_check_rem(s, 2))\n        {\n            char16_t low;\n            in_uint16_le_unchecked(s, low);\n            if (IS_LOW_SURROGATE(low))\n            {\n                /* Valid surrogate pair */\n                char32_t v = C32_FROM_SURROGATE_PAIR(low, w);\n\n                /* Ignore some values which can be successfully encoded\n                 * in this way */\n                if (!IS_PLANE_END_NON_CHARACTER(c32))\n                {\n                    c32 = v;\n                }\n            }\n            else\n            {\n                /* Invalid low surrogate  - pop character back */\n                s->p -= 2;\n            }\n        }\n    }\n    else if (!IS_LOW_SURROGATE(w) &&\n             !IS_PLANE_END_NON_CHARACTER(w) &&\n             !IS_ARABIC_NON_CHARACTER(w))\n    {\n        /* Character from the Basic Multilingual Plane */\n        c32 = (char32_t)w;\n    }\n\n    return c32;\n}\n\n/******************************************************************************/\nunsigned int\nin_utf16_le_fixed_as_utf8_proc(struct stream *s, unsigned int n,\n                               char *v, unsigned int vn,\n                               const char *file, int line)\n{\n    unsigned int rv = 0;\n    char32_t c32;\n    char u8str[MAXLEN_UTF8_CHAR];\n    unsigned int u8len;\n    char *saved_s_end = s->end;\n\n    // Expansion of S_CHECK_REM(s, n*2) using passed-in file and line\n#ifdef USE_DEVEL_STREAMCHECK\n    parser_stream_overflow_check(s, n * 2, 0, file, line);\n#endif\n    // Temporarily set the stream end pointer to allow us to use\n    // s_check_rem() when reading in UTF-16 words\n    if (s->end - s->p > (int)(n * 2))\n    {\n        s->end = s->p + (int)(n * 2);\n    }\n\n    while (s_check_rem(s, 2))\n    {\n        c32 = get_c32_from_stream(s);\n\n        u8len = utf_char32_to_utf8(c32, u8str);\n        if (u8len + 1 <= vn)\n        {\n            /* Room for this character and a terminator. Add the character */\n            unsigned int i;\n            for (i = 0 ; i < u8len ; ++i)\n            {\n                v[i] = u8str[i];\n            }\n            vn -= u8len;\n            v += u8len;\n        }\n        else if (vn > 1)\n        {\n            /* We've skipped a character, but there's more than one byte\n             * remaining in the output buffer. Mark the output buffer as\n             * full so we don't get a smaller character being squeezed into\n             * the remaining space */\n            vn = 1;\n        }\n\n        rv += u8len;\n    }\n\n    // Restore stream to full length\n    s->end = saved_s_end;\n\n    if (vn > 0)\n    {\n        *v = '\\0';\n    }\n    ++rv;\n    return rv;\n}\n\n/******************************************************************************/\nunsigned int\nin_utf16_le_fixed_as_utf8_length(struct stream *s, unsigned int n)\n{\n    char *saved_s_p = s->p;\n    unsigned int rv = in_utf16_le_fixed_as_utf8(s, n, NULL, 0);\n    s->p = saved_s_p;\n    return rv;\n}\n\n/******************************************************************************/\nunsigned int\nin_utf16_le_terminated_as_utf8(struct stream *s,\n                               char *v, unsigned int vn)\n{\n    unsigned int rv = 0;\n    char32_t c32;\n    char u8str[MAXLEN_UTF8_CHAR];\n    unsigned int u8len;\n    while (s_check_rem(s, 2))\n    {\n        c32 = get_c32_from_stream(s);\n        if (c32 == 0)\n        {\n            break;  // Terminator encountered\n        }\n\n        u8len = utf_char32_to_utf8(c32, u8str);\n        if (u8len + 1 <= vn)\n        {\n            /* Room for this character and a terminator. Add the character */\n            unsigned int i;\n            for (i = 0 ; i < u8len ; ++i)\n            {\n                v[i] = u8str[i];\n            }\n            vn -= u8len;\n            v += u8len;\n        }\n        else if (vn > 1)\n        {\n            /* We've skipped a character, but there's more than one byte\n             * remaining in the output buffer. Mark the output buffer as\n             * full so we don't get a smaller character being squeezed into\n             * the remaining space */\n            vn = 1;\n        }\n        rv += u8len;\n    }\n\n    if (vn > 0)\n    {\n        *v = '\\0';\n    }\n    ++rv;\n\n    return rv;\n}\n\n/******************************************************************************/\nunsigned int\nin_utf16_le_terminated_as_utf8_length(struct stream *s)\n{\n    char *saved_s_p = s->p;\n    unsigned int rv = in_utf16_le_terminated_as_utf8(s, NULL, 0);\n    s->p = saved_s_p;\n    return rv;\n}\n"
  },
  {
    "path": "common/parse.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Parsing structs and macros\n *\n * based on parse.h from rdesktop\n * this is a super fast stream method, you bet\n * needed functions g_malloc, g_free, g_memset, g_memcpy\n */\n\n#if !defined(PARSE_H)\n#define PARSE_H\n\n#include \"arch.h\"\n#include \"log.h\"\n\n/* Check the config_ac.h file is included so we know whether to enable the\n * development macros\n */\n#ifndef CONFIG_AC_H\n#   error config_ac.h not visible in parse.h\n#endif\n\n#if defined(L_ENDIAN)\n#elif defined(B_ENDIAN)\n#else\n#error Unknown endianness.\n#endif\n\n/* parser state */\nstruct stream\n{\n    char *p;\n    char *end;\n    char *data;\n    int size;\n    int pad0;\n    /* offsets of various headers */\n    char *iso_hdr;\n    char *mcs_hdr;\n    char *sec_hdr;\n    char *rdp_hdr;\n    char *channel_hdr;\n    /* other */\n    char *next_packet;\n    struct stream *next;\n    int *source;\n};\n\n/** Check arguments to stream primitives\n *\n * This adds a function call overhead to every stream primitive and is\n * intended for development only\n *\n * @param s stream\n * @param n Bytes being requested for input/output\n * @param is_out (0=input, !0=output)\n * @param file __file__for caller\n * @param line __line__ for caller\n *\n * On any kind of violation a message is output and the program is\n * aborted.\n */\nvoid\nparser_stream_overflow_check(const struct stream *s, int n, int is_out,\n                             const char *file, int line);\n\n#ifdef USE_DEVEL_STREAMCHECK\n#   define S_CHECK_REM(s,n) \\\n    parser_stream_overflow_check((s), (n), 0, __FILE__, __LINE__)\n#   define S_CHECK_REM_OUT(s,n) \\\n    parser_stream_overflow_check((s), (n), 1, __FILE__, __LINE__)\n#else\n#   define S_CHECK_REM(s,n)\n#   define S_CHECK_REM_OUT(s,n)\n#endif\n\n/******************************************************************************/\n/**\n * Copies a UTF-8 string to a stream as little-endian UTF-16\n *\n * @param s Stream\n * @param v UTF-8 string\n * @param vn Length of UTF-8 string.\n * @param file Caller location (from __FILE__)\n * @param line Caller location (from __LINE__)\n *\n * Caller is expected to check there is room for the result in s\n */\nvoid\nout_utf8_as_utf16_le_proc(struct stream *s, const char *v,\n                          unsigned int vn,\n                          const char *file, int line);\n\n#define out_utf8_as_utf16_le(s,v,vn) \\\n    out_utf8_as_utf16_le_proc((s), (v), (vn), __FILE__, __LINE__)\n\n\n/******************************************************************************/\n/**\n * Copies a fixed-size little-endian UTF-16 string from a stream as UTF-8\n *\n * @param s Stream\n * @param n Number of 16-bit words to copy\n * @param v Pointer to result buffer\n * @param vn Max size of result buffer\n *\n * @return number of characters which would be written to v, INCLUDING\n *         an additional terminator. This can be used to check for a buffer\n *         overflow. A terminator is added whether or not the input\n *         includes one.\n *\n * Output is unconditionally NULL-terminated.\n * Input is not checked for NULLs - these are copied verbatim\n */\nunsigned int\nin_utf16_le_fixed_as_utf8_proc(struct stream *s, unsigned int n,\n                               char *v, unsigned int vn,\n                               const char *file, int line);\n\n#define in_utf16_le_fixed_as_utf8(s,n,v,vn) \\\n    in_utf16_le_fixed_as_utf8_proc((s), (n), (v), (vn), __FILE__, __LINE__)\n\n/******************************************************************************/\n/**\n * Returns the size of the buffer needed to store a fixed-size\n * little-endian UTF-16 string in a stream as a UTF-8 string\n *\n * @param s Stream\n * @param n Number of 16-bit words to consider\n * @return number of characters needed to store the UTF-8 string. This\n *         includes a terminator, which is written whether the parsed\n *         string includes one or not.\n * @post Stream position is not moved between start and end of this call\n */\nunsigned int\nin_utf16_le_fixed_as_utf8_length(struct stream *s, unsigned int n);\n\n/******************************************************************************/\n/**\n * Copies a terminated little-endian UTF-16 string from a stream as UTF-8\n *\n * @param s Stream\n * @param v Pointer to result buffer\n * @param vn Max size of result buffer\n *\n * @return number of characters which would be written to v, INCLUDING\n *         the terminator. This can be used to check for a buffer overflow.\n *\n * Output is unconditionally NULL-terminated.\n * Input processing stops when a NULL is encountered, or the end of the buffer\n * is reached.\n */\nunsigned int\nin_utf16_le_terminated_as_utf8(struct stream *s,\n                               char *v, unsigned int vn);\n\n/******************************************************************************/\n/**\n * Returns the size of the buffer needed to store a terminated\n * little-endian UTF-16 string in a stream as a terminated UTF-8 string\n *\n * @param s Stream\n * @return number of characters needed to store the UTF-8 string,\n *         including the terminator\n * @post Stream position is not moved between start and end of this call\n *\n * Input processing stops when a NULL is encountered, or the end of the buffer\n * is reached.\n */\nunsigned int\nin_utf16_le_terminated_as_utf8_length(struct stream *s);\n\n/******************************************************************************/\n#define s_check_rem(s, n) ((s)->p + (n) <= (s)->end)\n\n/******************************************************************************/\n/**\n * @returns true if there are at least n bytes remaining in the stream,\n *          else false and logs an error message\n */\n#define s_check_rem_and_log(s, n, msg_prefix) \\\n    ( s_check_rem((s), (n)) ? \\\n      1 : \\\n      LOG(LOG_LEVEL_ERROR, \\\n          \"%s Not enough bytes in the stream: expected %d, remaining %d\", \\\n          (msg_prefix), (n), s_rem(s)) \\\n      && 0 )\n\n/******************************************************************************/\n#define s_check_rem_out(s, n) ((s)->p + (n) <= (s)->data + (s)->size)\n\n/******************************************************************************/\n/**\n * @returns true if there are at least n bytes remaining in the stream,\n *          else false and logs an error message\n */\n#define s_check_rem_out_and_log(s, n, msg_prefix) \\\n    ( s_check_rem_out((s), (n)) ? \\\n      1 : \\\n      LOG(LOG_LEVEL_ERROR, \\\n          \"%s Not enough bytes in the stream: expected %d, remaining %d\", \\\n          (msg_prefix), (n), s_rem_out(s)) \\\n      && 0 )\n\n/******************************************************************************/\n#define s_check_end(s) ((s)->p == (s)->end)\n\n/******************************************************************************/\n/**\n * @returns true if there are exactly 0 bytes remaining in the stream,\n *          else false and logs an error message\n */\n#define s_check_end_and_log(s, msg_prefix) \\\n    ( s_check_end((s)) ? \\\n      1 : \\\n      LOG(LOG_LEVEL_ERROR, \\\n          \"%s Expected to be at the end of the stream, \" \\\n          \"but there are %d bytes remaining\", \\\n          (msg_prefix), s_rem(s)) \\\n      && 0 )\n\n/******************************************************************************/\n#define s_rem(s) ((int) ((s)->end - (s)->p))\n\n/******************************************************************************/\n#define s_rem_out(s) ((int) ((s)->data + (s)->size - (s)->p))\n\n/******************************************************************************/\n#define make_stream(s) \\\n    (s) = (struct stream*)g_malloc(sizeof(struct stream), 1)\n\n/******************************************************************************/\n#define init_stream(s, v) do \\\n    { \\\n        if ((v) > (s)->size) \\\n        { \\\n            g_free((s)->data); \\\n            (s)->data = (char*)g_malloc((v), 0); \\\n            (s)->size = (v); \\\n        } \\\n        (s)->p = (s)->data; \\\n        (s)->end = (s)->data; \\\n        (s)->next_packet = 0; \\\n    } while (0)\n\n/******************************************************************************/\n#define free_stream(s) do \\\n    { \\\n        if ((s) != 0) \\\n        { \\\n            g_free((s)->data); \\\n        } \\\n        g_free((s)); \\\n    } while (0)\n\n/******************************************************************************/\n#define s_push_layer(s, h, n) do \\\n    { \\\n        (s)->h = (s)->p; \\\n        (s)->p += (n); \\\n    } while (0)\n\n/******************************************************************************/\n#define s_pop_layer(s, h) \\\n    (s)->p = (s)->h\n\n/******************************************************************************/\n#define s_mark_end(s) \\\n    (s)->end = (s)->p\n\n#define in_sint8(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 1); \\\n        (v) = *((signed char*)((s)->p)); \\\n        (s)->p++; \\\n    } while (0)\n\n/******************************************************************************/\n#define in_uint8(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 1); \\\n        (v) = *((unsigned char*)((s)->p)); \\\n        (s)->p++; \\\n    } while (0)\n/******************************************************************************/\n#define in_uint8_peek(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 1); \\\n        v = *s->p; \\\n    } while (0)\n/******************************************************************************/\n#if defined(B_ENDIAN) || defined(NEED_ALIGN)\n#define in_sint16_le(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 2); \\\n        (v) = (signed short) \\\n              ( \\\n                (*((unsigned char*)((s)->p + 0)) << 0) | \\\n                (*((unsigned char*)((s)->p + 1)) << 8) \\\n              ); \\\n        (s)->p += 2; \\\n    } while (0)\n#else\n#define in_sint16_le(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 2); \\\n        (v) = *((signed short*)((s)->p)); \\\n        (s)->p += 2; \\\n    } while (0)\n#endif\n\n/******************************************************************************/\n#if defined(B_ENDIAN) || defined(NEED_ALIGN)\n#define in_uint16_le(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 2); \\\n        (v) = (unsigned short) \\\n              ( \\\n                (*((unsigned char*)((s)->p + 0)) << 0) | \\\n                (*((unsigned char*)((s)->p + 1)) << 8) \\\n              ); \\\n        (s)->p += 2; \\\n    } while (0)\n#else\n#define in_uint16_le(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 2); \\\n        (v) = *((unsigned short*)((s)->p)); \\\n        (s)->p += 2; \\\n    } while (0)\n#endif\n\n/******************************************************************************/\n#define in_uint16_be(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 2); \\\n        (v) = *((unsigned char*)((s)->p)); \\\n        (s)->p++; \\\n        (v) <<= 8; \\\n        (v) |= *((unsigned char*)((s)->p)); \\\n        (s)->p++; \\\n    } while (0)\n\n/******************************************************************************/\n#if defined(B_ENDIAN) || defined(NEED_ALIGN)\n#define in_uint32_le(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 4); \\\n        (v) = (unsigned int) \\\n              ( \\\n                (*((unsigned char*)((s)->p + 0)) << 0) | \\\n                (*((unsigned char*)((s)->p + 1)) << 8) | \\\n                (*((unsigned char*)((s)->p + 2)) << 16) | \\\n                (*((unsigned char*)((s)->p + 3)) << 24) \\\n              ); \\\n        (s)->p += 4; \\\n    } while (0)\n#else\n#define in_uint32_le(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 4); \\\n        (v) = *((unsigned int*)((s)->p)); \\\n        (s)->p += 4; \\\n    } while (0)\n#endif\n\n/******************************************************************************/\n#if defined(B_ENDIAN) || defined(NEED_ALIGN)\n#define in_uint64_le(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 8); \\\n        (v) = (tui64) \\\n              ( \\\n                (((tui64)(*((unsigned char*)((s)->p + 0)))) << 0) | \\\n                (((tui64)(*((unsigned char*)((s)->p + 1)))) << 8) | \\\n                (((tui64)(*((unsigned char*)((s)->p + 2)))) << 16) | \\\n                (((tui64)(*((unsigned char*)((s)->p + 3)))) << 24) | \\\n                (((tui64)(*((unsigned char*)((s)->p + 4)))) << 32) | \\\n                (((tui64)(*((unsigned char*)((s)->p + 5)))) << 40) | \\\n                (((tui64)(*((unsigned char*)((s)->p + 6)))) << 48) | \\\n                (((tui64)(*((unsigned char*)((s)->p + 7)))) << 56) \\\n              ); \\\n        (s)->p += 8; \\\n    } while (0)\n#else\n#define in_uint64_le(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 8); \\\n        (v) = *((tui64*)((s)->p)); \\\n        (s)->p += 8; \\\n    } while (0)\n#endif\n\n/******************************************************************************/\n#define in_uint32_be(s, v) do \\\n    { \\\n        S_CHECK_REM((s), 4); \\\n        (v) = *((unsigned char*)((s)->p)); \\\n        (s)->p++; \\\n        (v) <<= 8; \\\n        (v) |= *((unsigned char*)((s)->p)); \\\n        (s)->p++; \\\n        (v) <<= 8; \\\n        (v) |= *((unsigned char*)((s)->p)); \\\n        (s)->p++; \\\n        (v) <<= 8; \\\n        (v) |= *((unsigned char*)((s)->p)); \\\n        (s)->p++; \\\n    } while (0)\n\n/******************************************************************************/\n#define out_uint8(s, v) do \\\n    { \\\n        S_CHECK_REM_OUT((s), 1); \\\n        *((s)->p) = (unsigned char)(v); \\\n        (s)->p++; \\\n    } while (0)\n\n/******************************************************************************/\n#if defined(B_ENDIAN) || defined(NEED_ALIGN)\n#define out_uint16_le(s, v) do \\\n    { \\\n        S_CHECK_REM_OUT((s), 2); \\\n        *((s)->p) = (unsigned char)((v) >> 0); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 8); \\\n        (s)->p++; \\\n    } while (0)\n#else\n#define out_uint16_le(s, v) do \\\n    { \\\n        S_CHECK_REM_OUT((s), 2); \\\n        *((unsigned short*)((s)->p)) = (unsigned short)(v); \\\n        (s)->p += 2; \\\n    } while (0)\n#endif\n\n/******************************************************************************/\n#define out_uint16_be(s, v) do \\\n    { \\\n        S_CHECK_REM_OUT((s), 2); \\\n        *((s)->p) = (unsigned char)((v) >> 8); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 0); \\\n        (s)->p++; \\\n    } while (0)\n\n/******************************************************************************/\n#if defined(B_ENDIAN) || defined(NEED_ALIGN)\n#define out_uint32_le(s, v) do \\\n    { \\\n        S_CHECK_REM_OUT((s), 4); \\\n        *((s)->p) = (unsigned char)((v) >> 0); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 8); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 16); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 24); \\\n        (s)->p++; \\\n    } while (0)\n#else\n#define out_uint32_le(s, v) do \\\n    { \\\n        S_CHECK_REM_OUT((s), 4); \\\n        *((unsigned int*)((s)->p)) = (v); \\\n        (s)->p += 4; \\\n    } while (0)\n#endif\n\n/******************************************************************************/\n#if defined(B_ENDIAN) || defined(NEED_ALIGN)\n#define out_uint64_le(s, v) do \\\n    { \\\n        S_CHECK_REM_OUT((s), 8); \\\n        *((s)->p) = (unsigned char)((v) >> 0); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 8); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 16); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 24); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 32); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 40); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 48); \\\n        (s)->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 56); \\\n        (s)->p++; \\\n    } while (0)\n#else\n#define out_uint64_le(s, v) do \\\n    { \\\n        S_CHECK_REM_OUT((s), 8); \\\n        *((tui64*)((s)->p)) = (v); \\\n        (s)->p += 8; \\\n    } while (0)\n#endif\n\n/******************************************************************************/\n#define out_uint32_be(s, v) do \\\n    { \\\n        S_CHECK_REM_OUT((s), 4); \\\n        *((s)->p) = (unsigned char)((v) >> 24); \\\n        s->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 16); \\\n        s->p++; \\\n        *((s)->p) = (unsigned char)((v) >> 8); \\\n        s->p++; \\\n        *((s)->p) = (unsigned char)(v); \\\n        (s)->p++; \\\n    } while (0)\n\n/******************************************************************************/\n// Platform-endian out_uint32\n#if defined(B_ENDIAN)\n#define out_uint32_pe(s, v) out_uint32_be(s, v)\n#else\n#define out_uint32_pe(s, v) out_uint32_le(s, v)\n#endif\n\n/******************************************************************************/\n#define in_uint8p(s, v, n) do \\\n    { \\\n        S_CHECK_REM((s), (n)); \\\n        (v) = (s)->p; \\\n        (s)->p += (n); \\\n    } while (0)\n\n/******************************************************************************/\n#define in_uint8a(s, v, n) do \\\n    { \\\n        S_CHECK_REM((s), (n)); \\\n        g_memcpy((v), (s)->p, (n)); \\\n        (s)->p += (n); \\\n    } while (0)\n\n/******************************************************************************/\n#define in_uint8s(s, n) do \\\n    { \\\n        S_CHECK_REM((s), (n)); \\\n        (s)->p += (n); \\\n    } while (0);\n\n/******************************************************************************/\n#define out_uint8p(s, v, n) do \\\n    { \\\n        S_CHECK_REM_OUT((s), (n)); \\\n        g_memcpy((s)->p, (v), (n)); \\\n        (s)->p += (n); \\\n    } while (0)\n\n/******************************************************************************/\n#define out_uint8a(s, v, n) \\\n    out_uint8p((s), (v), (n))\n\n/******************************************************************************/\n#define out_uint8s(s, n) do \\\n    { \\\n        S_CHECK_REM_OUT((s), (n)); \\\n        g_memset((s)->p, 0, (n)); \\\n        (s)->p += (n); \\\n    } while (0)\n\n/*\n * @brief allocate a new stream\n *\n * @param _s opaque handle to the new stream\n * @param _l length of new stream\n ******************************************************************************/\n#define xstream_new(_s, _l)   \\\n    do                           \\\n    {                            \\\n        make_stream((_s));       \\\n        init_stream((_s), (_l)); \\\n    } while (0)\n\n/**\n * @brief release a previously allocated stream\n *\n * @param _s opaque handle returned by stream_new()\n *****************************************************************************/\n#define xstream_free(_s) free_stream(_s)\n\n#define xstream_skip_u8(_s, _n)       in_uint8s(_s, _n)\n\n#define xstream_rd_u8(_s, _var)       in_uint8(_s, _var)\n#define xstream_rd_u16_le(_s, _var)   in_uint16_le(_s, _var)\n#define xstream_rd_u32_le(_s, _var)   in_uint32_le(_s, _var)\n\n#define xstream_rd_s8_le(_s, _var)    in_sint8(_s, _var)\n#define xstream_rd_s16_le(_s, _var)   in_sint16_le(_s, _var)\n#define xstream_rd_s32_le(_s, _var)   TODO\n\n#define xstream_wr_u8(_s, _var)       out_uint8(_s, _var)\n#define xstream_wr_u16_le(_s, _var)   out_uint16_le(_s, _var)\n#define xstream_wr_u32_le(_s, _var)   out_uint32_le(_s, _var)\n\n#define xstream_wr_s8(_s, _var)       TODO\n#define xstream_wr_s16_le(_s, _var)   TODO\n#define xstream_wr_s32_le(_s, _var)   TODO\n\n#define xstream_rd_u64_le(_s, _v)                             \\\n    do                                                            \\\n    {                                                             \\\n        _v =                                                      \\\n            (tui64)(*((unsigned char *)_s->p)) |                      \\\n            (((tui64) (*(((unsigned char *)_s->p) + 1))) << 8)  |     \\\n            (((tui64) (*(((unsigned char *)_s->p) + 2))) << 16) |     \\\n            (((tui64) (*(((unsigned char *)_s->p) + 3))) << 24) |     \\\n            (((tui64) (*(((unsigned char *)_s->p) + 4))) << 32) |     \\\n            (((tui64) (*(((unsigned char *)_s->p) + 5))) << 40) |     \\\n            (((tui64) (*(((unsigned char *)_s->p) + 6))) << 48) |     \\\n            (((tui64) (*(((unsigned char *)_s->p) + 7))) << 56);      \\\n        _s->p += 8;                                               \\\n    } while (0)\n\n#define xstream_wr_u64_le(_s, _v)                                           \\\n    do                                                                          \\\n    {                                                                           \\\n        *(((unsigned char *) _s->p) + 0) = (unsigned char) ((_v >>  0) & 0xff); \\\n        *(((unsigned char *) _s->p) + 1) = (unsigned char) ((_v >>  8) & 0xff); \\\n        *(((unsigned char *) _s->p) + 2) = (unsigned char) ((_v >> 16) & 0xff); \\\n        *(((unsigned char *) _s->p) + 3) = (unsigned char) ((_v >> 24) & 0xff); \\\n        *(((unsigned char *) _s->p) + 4) = (unsigned char) ((_v >> 32) & 0xff); \\\n        *(((unsigned char *) _s->p) + 5) = (unsigned char) ((_v >> 40) & 0xff); \\\n        *(((unsigned char *) _s->p) + 6) = (unsigned char) ((_v >> 48) & 0xff); \\\n        *(((unsigned char *) _s->p) + 7) = (unsigned char) ((_v >> 56) & 0xff); \\\n        _s->p += 8;                                                             \\\n    } while (0)\n\n/* copy data into stream */\n#define xstream_copyin(_s, _dest, _len)   \\\n    do                                        \\\n    {                                         \\\n        g_memcpy((_s)->p, (_dest), (_len));   \\\n        (_s)->p += (_len);                    \\\n    } while (0)\n\n/* copy data out of stream */\n#define xstream_copyout(_dest, _s, _len)  \\\n    do                                        \\\n    {                                         \\\n        g_memcpy((_dest), (_s)->p, (_len));   \\\n        (_s)->p += (_len);                    \\\n    } while (0)\n\n#define xstream_rd_string(_dest, _s, _len) \\\n    do                                         \\\n    {                                          \\\n        g_memcpy((_dest), (_s)->p, (_len));    \\\n        (_s)->p += (_len);                     \\\n    } while (0)\n\n#define xstream_wr_string(_s, _src, _len) \\\n    do                                        \\\n    {                                         \\\n        g_memcpy((_s)->p, (_src), (_len));    \\\n        (_s)->p += (_len);                    \\\n    } while (0)\n\n#define xstream_len(_s)               (int) ((_s)->p - (_s)->data)\n#define xstream_seek(_s, _len)        (_s)->p += (_len)\n\n#endif\n"
  },
  {
    "path": "common/pixman-region.c",
    "content": "/*\n * Copyright 1987, 1988, 1989, 1998  The Open Group\n *\n * Permission to use, copy, modify, distribute, and sell this software and its\n * documentation for any purpose is hereby granted without fee, provided that\n * the above copyright notice appear in all copies and that both that\n * copyright notice and this permission notice appear in supporting\n * documentation.\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\n * OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\n * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * Except as contained in this notice, the name of The Open Group shall not be\n * used in advertising or otherwise to promote the sale, use or other dealings\n * in this Software without prior written authorization from The Open Group.\n *\n * Copyright 1987, 1988, 1989 by\n * Digital Equipment Corporation, Maynard, Massachusetts.\n *\n *                    All Rights Reserved\n *\n * Permission to use, copy, modify, and distribute this software and its\n * documentation for any purpose and without fee is hereby granted,\n * provided that the above copyright notice appear in all copies and that\n * both that copyright notice and this permission notice appear in\n * supporting documentation, and that the name of Digital not be\n * used in advertising or publicity pertaining to distribution of the\n * software without specific, written prior permission.\n *\n * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING\n * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL\n * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR\n * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,\n * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\n * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\n * SOFTWARE.\n *\n * Copyright © 1998 Keith Packard\n *\n * Permission to use, copy, modify, distribute, and sell this software and its\n * documentation for any purpose is hereby granted without fee, provided that\n * the above copyright notice appear in all copies and that both that\n * copyright notice and this permission notice appear in supporting\n * documentation, and that the name of Keith Packard not be used in\n * advertising or publicity pertaining to distribution of the software without\n * specific, written prior permission.  Keith Packard makes no\n * representations about the suitability of this software for any purpose.  It\n * is provided \"as is\" without express or implied warranty.\n *\n * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\n * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO\n * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR\n * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,\n * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n#ifndef PIXMAN_REGION_MAX\n#error \"This file should be #included from pixman-region16.c, not compiled directly\"\n#endif\n#ifndef CONFIG_AC_H\n#error \"config_ac.h not visible in pixman-region.c\"\n#endif\n\n#define PIXREGION_NIL(reg) ((reg)->data && !(reg)->data->numRects)\n/* not a region */\n#define PIXREGION_NAR(reg)      ((reg)->data == pixman_broken_data)\n#define PIXREGION_NUMRECTS(reg) ((reg)->data ? (reg)->data->numRects : 1)\n#define PIXREGION_SIZE(reg) ((reg)->data ? (reg)->data->size : 0)\n#define PIXREGION_RECTS(reg) \\\n    ((reg)->data ? (box_type_t *)((reg)->data + 1) \\\n     : &(reg)->extents)\n#define PIXREGION_BOXPTR(reg) ((box_type_t *)((reg)->data + 1))\n#define PIXREGION_BOX(reg, i) (&PIXREGION_BOXPTR (reg)[i])\n#define PIXREGION_TOP(reg) PIXREGION_BOX (reg, (reg)->data->numRects)\n#define PIXREGION_END(reg) PIXREGION_BOX (reg, (reg)->data->numRects - 1)\n\n#define GOOD_RECT(rect) ((rect)->x1 < (rect)->x2 && (rect)->y1 < (rect)->y2)\n#define BAD_RECT(rect) ((rect)->x1 > (rect)->x2 || (rect)->y1 > (rect)->y2)\n\n/* This file is included by pixman-region16.c which defines PREFIX(x).\n * This check allows cppcheck 2.x to scan this file separately */\n#ifndef PREFIX\n#define PREFIX(x) pixman_region##x\n#endif\n\n#ifdef USE_DEVEL_LOGGING\n\npixman_bool_t PREFIX(_selfcheck) (region_type_t *reg);\n\n#define GOOD(reg)                                                       \\\n    do                                                                  \\\n    {                                                                   \\\n        if (!PREFIX (_selfcheck (reg)))                                 \\\n            _pixman_log_error (FUNC, \"Malformed region \" # reg);        \\\n    } while (0)\n\n#else\n\n#define GOOD(reg)\n\n#endif\n\nstatic const box_type_t PREFIX (_empty_box_) = { 0, 0, 0, 0 };\nstatic const region_data_type_t PREFIX (_empty_data_) = { 0, 0 };\n#if defined (__llvm__) && !defined (__clang__)\nstatic const volatile region_data_type_t PREFIX (_broken_data_) = { 0, 0 };\n#else\nstatic const region_data_type_t PREFIX (_broken_data_) = { 0, 0 };\n#endif\n\nstatic box_type_t *pixman_region_empty_box =\n    (box_type_t *) &PREFIX (_empty_box_);\nstatic region_data_type_t *pixman_region_empty_data =\n    (region_data_type_t *) &PREFIX (_empty_data_);\nstatic region_data_type_t *pixman_broken_data =\n    (region_data_type_t *) &PREFIX (_broken_data_);\n\nstatic pixman_bool_t\npixman_break (region_type_t *region);\n\n/*\n * The functions in this file implement the Region abstraction used extensively\n * throughout the X11 sample server. A Region is simply a set of disjoint\n * (non-overlapping) rectangles, plus an \"extent\" rectangle which is the\n * smallest single rectangle that contains all the non-overlapping rectangles.\n *\n * A Region is implemented as a \"y-x-banded\" array of rectangles.  This array\n * imposes two degrees of order.  First, all rectangles are sorted by top side\n * y coordinate first (y1), and then by left side x coordinate (x1).\n *\n * Furthermore, the rectangles are grouped into \"bands\".  Each rectangle in a\n * band has the same top y coordinate (y1), and each has the same bottom y\n * coordinate (y2).  Thus all rectangles in a band differ only in their left\n * and right side (x1 and x2).  Bands are implicit in the array of rectangles:\n * there is no separate list of band start pointers.\n *\n * The y-x band representation does not minimize rectangles.  In particular,\n * if a rectangle vertically crosses a band (the rectangle has scanlines in\n * the y1 to y2 area spanned by the band), then the rectangle may be broken\n * down into two or more smaller rectangles stacked one atop the other.\n *\n *  -----------                             -----------\n *  |         |                             |         |             band 0\n *  |         |  --------                   -----------  --------\n *  |         |  |      |  in y-x banded    |         |  |      |   band 1\n *  |         |  |      |  form is          |         |  |      |\n *  -----------  |      |                   -----------  --------\n *               |      |                                |      |   band 2\n *               --------                                --------\n *\n * An added constraint on the rectangles is that they must cover as much\n * horizontal area as possible: no two rectangles within a band are allowed\n * to touch.\n *\n * Whenever possible, bands will be merged together to cover a greater vertical\n * distance (and thus reduce the number of rectangles). Two bands can be merged\n * only if the bottom of one touches the top of the other and they have\n * rectangles in the same places (of the same width, of course).\n *\n * Adam de Boor wrote most of the original region code.  Joel McCormack\n * substantially modified or rewrote most of the core arithmetic routines, and\n * added pixman_region_validate in order to support several speed improvements\n * to pixman_region_validate_tree.  Bob Scheifler changed the representation\n * to be more compact when empty or a single rectangle, and did a bunch of\n * gratuitous reformatting. Carl Worth did further gratuitous reformatting\n * while re-merging the server and client region code into libpixregion.\n * Soren Sandmann did even more gratuitous reformatting.\n */\n\n/*  true iff two Boxes overlap */\n#define EXTENTCHECK(r1, r2)        \\\n    (!( ((r1)->x2 <= (r2)->x1)  || \\\n        ((r1)->x1 >= (r2)->x2)  || \\\n        ((r1)->y2 <= (r2)->y1)  || \\\n        ((r1)->y1 >= (r2)->y2) ) )\n\n/* true iff (x,y) is in Box */\n#define INBOX(r, x, y)  \\\n    ( ((r)->x2 >  x) && \\\n      ((r)->x1 <= x) && \\\n      ((r)->y2 >  y) && \\\n      ((r)->y1 <= y) )\n\n/* true iff Box r1 contains Box r2 */\n#define SUBSUMES(r1, r2)        \\\n    ( ((r1)->x1 <= (r2)->x1) && \\\n      ((r1)->x2 >= (r2)->x2) && \\\n      ((r1)->y1 <= (r2)->y1) && \\\n      ((r1)->y2 >= (r2)->y2) )\n\nstatic size_t\nPIXREGION_SZOF (size_t n)\n{\n    size_t size = n * sizeof(box_type_t);\n\n    if (n > UINT32_MAX / sizeof(box_type_t))\n    {\n        return 0;\n    }\n\n    if (sizeof(region_data_type_t) > UINT32_MAX - size)\n    {\n        return 0;\n    }\n\n    return size + sizeof(region_data_type_t);\n}\n\nstatic region_data_type_t *\nalloc_data (size_t n)\n{\n    size_t sz = PIXREGION_SZOF (n);\n\n    if (!sz)\n    {\n        return NULL;\n    }\n\n    return (region_data_type_t *) malloc(sz);\n}\n\n#define FREE_DATA(reg) if ((reg)->data && (reg)->data->size) free ((reg)->data)\n\n#define RECTALLOC_BAIL(region, n, bail)                                 \\\n    do                                                                  \\\n    {                                                                   \\\n        if (!(region)->data ||                                          \\\n                (((region)->data->numRects + (n)) > (region)->data->size))  \\\n        {                                                               \\\n            if (!pixman_rect_alloc (region, n))                         \\\n                goto bail;                                              \\\n        }                                                               \\\n    } while (0)\n\n#define RECTALLOC(region, n)                                            \\\n    do                                                                  \\\n    {                                                                   \\\n        if (!(region)->data ||                                          \\\n                (((region)->data->numRects + (n)) > (region)->data->size))  \\\n        {                                                               \\\n            if (!pixman_rect_alloc (region, n)) {                       \\\n                return FALSE;                                           \\\n            }                                                           \\\n        }                                                               \\\n    } while (0)\n\n#define ADDRECT(next_rect, nx1, ny1, nx2, ny2)      \\\n    do                                              \\\n    {                                               \\\n        next_rect->x1 = nx1;                        \\\n        next_rect->y1 = ny1;                        \\\n        next_rect->x2 = nx2;                        \\\n        next_rect->y2 = ny2;                        \\\n        next_rect++;                                \\\n    }                                               \\\n    while (0)\n\n#define NEWRECT(region, next_rect, nx1, ny1, nx2, ny2)                  \\\n    do                                                                  \\\n    {                                                                   \\\n        if (!(region)->data ||                                          \\\n                ((region)->data->numRects == (region)->data->size))         \\\n        {                                                               \\\n            if (!pixman_rect_alloc (region, 1))                         \\\n                return FALSE;                                           \\\n            next_rect = PIXREGION_TOP (region);                         \\\n        }                                                               \\\n        ADDRECT (next_rect, nx1, ny1, nx2, ny2);                        \\\n        region->data->numRects++;                                       \\\n        critical_if_fail (region->data->numRects <= region->data->size);                \\\n    } while (0)\n\n#define DOWNSIZE(reg, numRects)                                         \\\n    do                                                                  \\\n    {                                                                   \\\n        if (((numRects) < ((reg)->data->size >> 1)) &&                  \\\n                ((reg)->data->size > 50))                                   \\\n        {                                                               \\\n            region_data_type_t * new_data;                              \\\n            size_t data_size = PIXREGION_SZOF (numRects);               \\\n            \\\n            if (!data_size)                                             \\\n            {                                                           \\\n                new_data = NULL;                                        \\\n            }                                                           \\\n            else                                                        \\\n            {                                                           \\\n                new_data = (region_data_type_t *)                       \\\n                           realloc ((reg)->data, data_size);                   \\\n            }                                                           \\\n            \\\n            if (new_data)                                               \\\n            {                                                           \\\n                new_data->size = (numRects);                            \\\n                (reg)->data = new_data;                                 \\\n            }                                                           \\\n        }                                                               \\\n    } while (0)\n\n\nPIXMAN_EXPORT void\nPREFIX (_init) (region_type_t *region)\n{\n    region->extents = *pixman_region_empty_box;\n    region->data = pixman_region_empty_data;\n}\n\nPIXMAN_EXPORT void\nPREFIX (_init_rect) (region_type_t     *region,\n                     int                x,\n                     int                y,\n                     unsigned int       width,\n                     unsigned int       height)\n{\n    region->extents.x1 = x;\n    region->extents.y1 = y;\n    region->extents.x2 = x + width;\n    region->extents.y2 = y + height;\n\n    if (!GOOD_RECT (&region->extents))\n    {\n        if (BAD_RECT (&region->extents))\n        {\n            _pixman_log_error (FUNC, \"Invalid rectangle passed\");\n        }\n        PREFIX (_init) (region);\n        return;\n    }\n\n    region->data = NULL;\n}\n\nPIXMAN_EXPORT void\nPREFIX (_fini) (region_type_t *region)\n{\n    GOOD (region);\n    FREE_DATA (region);\n}\n\nPIXMAN_EXPORT box_type_t *\nPREFIX (_rectangles) (region_type_t *region,\n                      int               *n_rects)\n{\n    if (n_rects)\n    {\n        *n_rects = PIXREGION_NUMRECTS (region);\n    }\n\n    return PIXREGION_RECTS (region);\n}\n\nstatic pixman_bool_t\npixman_break (region_type_t *region)\n{\n    FREE_DATA (region);\n\n    region->extents = *pixman_region_empty_box;\n    region->data = pixman_broken_data;\n\n    return FALSE;\n}\n\nstatic pixman_bool_t\npixman_rect_alloc (region_type_t *region,\n                   int             n)\n{\n    region_data_type_t *data;\n\n    if (!region->data)\n    {\n        n++;\n        region->data = alloc_data (n);\n\n        if (!region->data)\n        {\n            return pixman_break (region);\n        }\n\n        region->data->numRects = 1;\n        *PIXREGION_BOXPTR (region) = region->extents;\n    }\n    else if (!region->data->size)\n    {\n        region->data = alloc_data (n);\n\n        if (!region->data)\n        {\n            return pixman_break (region);\n        }\n\n        region->data->numRects = 0;\n    }\n    else\n    {\n        size_t data_size;\n\n        if (n == 1)\n        {\n            n = region->data->numRects;\n            if (n > 500) /* XXX pick numbers out of a hat */\n            {\n                n = 250;\n            }\n        }\n\n        n += region->data->numRects;\n        data_size = PIXREGION_SZOF (n);\n\n        if (!data_size)\n        {\n            data = NULL;\n        }\n        else\n        {\n            data = (region_data_type_t *)\n                   realloc (region->data, PIXREGION_SZOF (n));\n        }\n\n        if (!data)\n        {\n            return pixman_break (region);\n        }\n\n        region->data = data;\n    }\n\n    region->data->size = n;\n\n    return TRUE;\n}\n\nstatic PIXMAN_EXPORT pixman_bool_t\nPREFIX (_copy) (region_type_t *dst, region_type_t *src)\n{\n    GOOD (dst);\n    GOOD (src);\n\n    if (dst == src)\n    {\n        return TRUE;\n    }\n\n    dst->extents = src->extents;\n\n    if (!src->data || !src->data->size)\n    {\n        FREE_DATA (dst);\n        dst->data = src->data;\n        return TRUE;\n    }\n\n    if (!dst->data || (dst->data->size < src->data->numRects))\n    {\n        FREE_DATA (dst);\n\n        dst->data = alloc_data (src->data->numRects);\n\n        if (!dst->data)\n        {\n            return pixman_break (dst);\n        }\n\n        dst->data->size = src->data->numRects;\n    }\n\n    dst->data->numRects = src->data->numRects;\n\n    memmove ((char *)PIXREGION_BOXPTR (dst), (char *)PIXREGION_BOXPTR (src),\n             dst->data->numRects * sizeof(box_type_t));\n\n    return TRUE;\n}\n\n/*======================================================================\n *          Generic Region Operator\n *====================================================================*/\n\n/*-\n *-----------------------------------------------------------------------\n * pixman_coalesce --\n *      Attempt to merge the boxes in the current band with those in the\n *      previous one.  We are guaranteed that the current band extends to\n *      the end of the rects array.  Used only by pixman_op.\n *\n * Results:\n *      The new index for the previous band.\n *\n * Side Effects:\n *      If coalescing takes place:\n *          - rectangles in the previous band will have their y2 fields\n *            altered.\n *          - region->data->numRects will be decreased.\n *\n *-----------------------------------------------------------------------\n */\nstatic inline int\npixman_coalesce (region_type_t *region,       /* Region to coalesce              */\n                 int             prev_start,  /* Index of start of previous band */\n                 int             cur_start)   /* Index of start of current band  */\n{\n    box_type_t *prev_box;       /* Current box in previous band      */\n    box_type_t *cur_box;        /* Current box in current band       */\n    int numRects;               /* Number rectangles in both bands   */\n    int y2;                     /* Bottom of current band            */\n\n    /*\n     * Figure out how many rectangles are in the band.\n     */\n    numRects = cur_start - prev_start;\n    critical_if_fail (numRects == region->data->numRects - cur_start);\n\n    if (!numRects)\n    {\n        return cur_start;\n    }\n\n    /*\n     * The bands may only be coalesced if the bottom of the previous\n     * matches the top scanline of the current.\n     */\n    prev_box = PIXREGION_BOX (region, prev_start);\n    cur_box = PIXREGION_BOX (region, cur_start);\n    if (prev_box->y2 != cur_box->y1)\n    {\n        return cur_start;\n    }\n\n    /*\n     * Make sure the bands have boxes in the same places. This\n     * assumes that boxes have been added in such a way that they\n     * cover the most area possible. I.e. two boxes in a band must\n     * have some horizontal space between them.\n     */\n    y2 = cur_box->y2;\n\n    do\n    {\n        if ((prev_box->x1 != cur_box->x1) || (prev_box->x2 != cur_box->x2))\n        {\n            return (cur_start);\n        }\n\n        prev_box++;\n        cur_box++;\n        numRects--;\n    }\n    while (numRects);\n\n    /*\n     * The bands may be merged, so set the bottom y of each box\n     * in the previous band to the bottom y of the current band.\n     */\n    numRects = cur_start - prev_start;\n    region->data->numRects -= numRects;\n\n    do\n    {\n        prev_box--;\n        prev_box->y2 = y2;\n        numRects--;\n    }\n    while (numRects);\n\n    return prev_start;\n}\n\n/* Quicky macro to avoid trivial reject procedure calls to pixman_coalesce */\n\n#define COALESCE(new_reg, prev_band, cur_band)                          \\\n    do                                                                  \\\n    {                                                                   \\\n        if (cur_band - prev_band == new_reg->data->numRects - cur_band) \\\n            prev_band = pixman_coalesce (new_reg, prev_band, cur_band); \\\n        else                                                            \\\n            prev_band = cur_band;                                       \\\n    } while (0)\n\n/*-\n *-----------------------------------------------------------------------\n * pixman_region_append_non_o --\n *      Handle a non-overlapping band for the union and subtract operations.\n *      Just adds the (top/bottom-clipped) rectangles into the region.\n *      Doesn't have to check for subsumption or anything.\n *\n * Results:\n *      None.\n *\n * Side Effects:\n *      region->data->numRects is incremented and the rectangles overwritten\n *      with the rectangles we're passed.\n *\n *-----------------------------------------------------------------------\n */\nstatic inline pixman_bool_t\npixman_region_append_non_o (region_type_t *region,\n                            box_type_t     *r,\n                            box_type_t     *r_end,\n                            int             y1,\n                            int             y2)\n{\n    box_type_t *next_rect;\n    int new_rects;\n\n    new_rects = r_end - r;\n\n    critical_if_fail (y1 < y2);\n    critical_if_fail (new_rects != 0);\n\n    /* Make sure we have enough space for all rectangles to be added */\n    RECTALLOC (region, new_rects);\n    next_rect = PIXREGION_TOP (region);\n    region->data->numRects += new_rects;\n\n    do\n    {\n        critical_if_fail (r->x1 < r->x2);\n        ADDRECT (next_rect, r->x1, y1, r->x2, y2);\n        r++;\n    }\n    while (r != r_end);\n\n    return TRUE;\n}\n\n#define FIND_BAND(r, r_band_end, r_end, ry1)                         \\\n    do                                                               \\\n    {                                                                \\\n        ry1 = r->y1;                                                 \\\n        r_band_end = r + 1;                                          \\\n        while ((r_band_end != r_end) && (r_band_end->y1 == ry1)) {   \\\n            r_band_end++;                                            \\\n        }                                                            \\\n    } while (0)\n\n#define APPEND_REGIONS(new_reg, r, r_end)                               \\\n    do                                                                  \\\n    {                                                                   \\\n        int new_rects;                                                  \\\n        if ((new_rects = r_end - r)) {                                  \\\n            RECTALLOC_BAIL (new_reg, new_rects, bail);                  \\\n            memmove ((char *)PIXREGION_TOP (new_reg), (char *)r,        \\\n                     new_rects * sizeof(box_type_t));                   \\\n            new_reg->data->numRects += new_rects;                       \\\n        }                                                               \\\n    } while (0)\n\n/*-\n *-----------------------------------------------------------------------\n * pixman_op --\n *      Apply an operation to two regions. Called by pixman_region_union, pixman_region_inverse,\n *      pixman_region_subtract, pixman_region_intersect....  Both regions MUST have at least one\n *      rectangle, and cannot be the same object.\n *\n * Results:\n *      TRUE if successful.\n *\n * Side Effects:\n *      The new region is overwritten.\n *      overlap set to TRUE if overlap_func ever returns TRUE.\n *\n * Notes:\n *      The idea behind this function is to view the two regions as sets.\n *      Together they cover a rectangle of area that this function divides\n *      into horizontal bands where points are covered only by one region\n *      or by both. For the first case, the non_overlap_func is called with\n *      each the band and the band's upper and lower extents. For the\n *      second, the overlap_func is called to process the entire band. It\n *      is responsible for clipping the rectangles in the band, though\n *      this function provides the boundaries.\n *      At the end of each band, the new region is coalesced, if possible,\n *      to reduce the number of rectangles in the region.\n *\n *-----------------------------------------------------------------------\n */\n\ntypedef pixman_bool_t (*overlap_proc_ptr) (region_type_t *region,\n        box_type_t    *r1,\n        box_type_t    *r1_end,\n        box_type_t    *r2,\n        box_type_t    *r2_end,\n        int            y1,\n        int            y2);\n\nstatic pixman_bool_t\npixman_op (region_type_t   *new_reg,               /* Place to store result         */\n           region_type_t   *reg1,                  /* First region in operation     */\n           region_type_t   *reg2,                  /* 2d region in operation        */\n           overlap_proc_ptr overlap_func,          /* Function to call for over-\n                                                    * lapping bands                 */\n           int              append_non1,           /* Append non-overlapping bands\n                                                    * in region 1 ?\n                                                    */\n           int              append_non2            /* Append non-overlapping bands\n                                                    * in region 2 ?\n                                                    */\n          )\n{\n    box_type_t *r1;                 /* Pointer into first region     */\n    box_type_t *r2;                 /* Pointer into 2d region        */\n    box_type_t *r1_end;             /* End of 1st region             */\n    box_type_t *r2_end;             /* End of 2d region              */\n    int ybot;                       /* Bottom of intersection        */\n    int ytop;                       /* Top of intersection           */\n    region_data_type_t *old_data;   /* Old data for new_reg          */\n    int prev_band;                  /* Index of start of\n                                     * previous band in new_reg       */\n    int cur_band;                   /* Index of start of current\n                                     * band in new_reg               */\n    box_type_t *r1_band_end;        /* End of current band in r1     */\n    box_type_t *r2_band_end;        /* End of current band in r2     */\n    int top;                        /* Top of non-overlapping band   */\n    int bot;                        /* Bottom of non-overlapping band*/\n    int r1y1;                       /* Temps for r1->y1 and r2->y1   */\n    int r2y1;\n    int new_size;\n    int numRects;\n\n    /*\n     * Break any region computed from a broken region\n     */\n    if (PIXREGION_NAR (reg1) || PIXREGION_NAR (reg2))\n    {\n        return pixman_break (new_reg);\n    }\n\n    /*\n     * Initialization:\n     *  set r1, r2, r1_end and r2_end appropriately, save the rectangles\n     * of the destination region until the end in case it's one of\n     * the two source regions, then mark the \"new\" region empty, allocating\n     * another array of rectangles for it to use.\n     */\n\n    r1 = PIXREGION_RECTS (reg1);\n    new_size = PIXREGION_NUMRECTS (reg1);\n    r1_end = r1 + new_size;\n\n    numRects = PIXREGION_NUMRECTS (reg2);\n    r2 = PIXREGION_RECTS (reg2);\n    r2_end = r2 + numRects;\n\n    critical_if_fail (r1 != r1_end);\n    critical_if_fail (r2 != r2_end);\n\n    old_data = (region_data_type_t *)NULL;\n\n    if (((new_reg == reg1) && (new_size > 1)) ||\n            ((new_reg == reg2) && (numRects > 1)))\n    {\n        old_data = new_reg->data;\n        new_reg->data = pixman_region_empty_data;\n    }\n\n    /* guess at new size */\n    if (numRects > new_size)\n    {\n        new_size = numRects;\n    }\n\n    new_size <<= 1;\n\n    if (!new_reg->data)\n    {\n        new_reg->data = pixman_region_empty_data;\n    }\n    else if (new_reg->data->size)\n    {\n        new_reg->data->numRects = 0;\n    }\n\n    if (new_size > new_reg->data->size)\n    {\n        if (!pixman_rect_alloc (new_reg, new_size))\n        {\n            free (old_data);\n            return FALSE;\n        }\n    }\n\n    /*\n     * Initialize ybot.\n     * In the upcoming loop, ybot and ytop serve different functions depending\n     * on whether the band being handled is an overlapping or non-overlapping\n     * band.\n     *  In the case of a non-overlapping band (only one of the regions\n     * has points in the band), ybot is the bottom of the most recent\n     * intersection and thus clips the top of the rectangles in that band.\n     * ytop is the top of the next intersection between the two regions and\n     * serves to clip the bottom of the rectangles in the current band.\n     *  For an overlapping band (where the two regions intersect), ytop clips\n     * the top of the rectangles of both regions and ybot clips the bottoms.\n     */\n\n    ybot = MIN (r1->y1, r2->y1);\n\n    /*\n     * prev_band serves to mark the start of the previous band so rectangles\n     * can be coalesced into larger rectangles. qv. pixman_coalesce, above.\n     * In the beginning, there is no previous band, so prev_band == cur_band\n     * (cur_band is set later on, of course, but the first band will always\n     * start at index 0). prev_band and cur_band must be indices because of\n     * the possible expansion, and resultant moving, of the new region's\n     * array of rectangles.\n     */\n    prev_band = 0;\n\n    do\n    {\n        /*\n         * This algorithm proceeds one source-band (as opposed to a\n         * destination band, which is determined by where the two regions\n         * intersect) at a time. r1_band_end and r2_band_end serve to mark the\n         * rectangle after the last one in the current band for their\n         * respective regions.\n         */\n        critical_if_fail (r1 != r1_end);\n        critical_if_fail (r2 != r2_end);\n\n        FIND_BAND (r1, r1_band_end, r1_end, r1y1);\n        FIND_BAND (r2, r2_band_end, r2_end, r2y1);\n\n        /*\n         * First handle the band that doesn't intersect, if any.\n         *\n         * Note that attention is restricted to one band in the\n         * non-intersecting region at once, so if a region has n\n         * bands between the current position and the next place it overlaps\n         * the other, this entire loop will be passed through n times.\n         */\n        if (r1y1 < r2y1)\n        {\n            if (append_non1)\n            {\n                top = MAX (r1y1, ybot);\n                bot = MIN (r1->y2, r2y1);\n                if (top != bot)\n                {\n                    cur_band = new_reg->data->numRects;\n                    if (!pixman_region_append_non_o (new_reg, r1, r1_band_end, top, bot))\n                    {\n                        goto bail;\n                    }\n                    COALESCE (new_reg, prev_band, cur_band);\n                }\n            }\n            ytop = r2y1;\n        }\n        else if (r2y1 < r1y1)\n        {\n            if (append_non2)\n            {\n                top = MAX (r2y1, ybot);\n                bot = MIN (r2->y2, r1y1);\n\n                if (top != bot)\n                {\n                    cur_band = new_reg->data->numRects;\n\n                    if (!pixman_region_append_non_o (new_reg, r2, r2_band_end, top, bot))\n                    {\n                        goto bail;\n                    }\n\n                    COALESCE (new_reg, prev_band, cur_band);\n                }\n            }\n            ytop = r1y1;\n        }\n        else\n        {\n            ytop = r1y1;\n        }\n\n        /*\n         * Now see if we've hit an intersecting band. The two bands only\n         * intersect if ybot > ytop\n         */\n        ybot = MIN (r1->y2, r2->y2);\n        if (ybot > ytop)\n        {\n            cur_band = new_reg->data->numRects;\n\n            if (!(*overlap_func)(new_reg,\n                                 r1, r1_band_end,\n                                 r2, r2_band_end,\n                                 ytop, ybot))\n            {\n                goto bail;\n            }\n\n            COALESCE (new_reg, prev_band, cur_band);\n        }\n\n        /*\n         * If we've finished with a band (y2 == ybot) we skip forward\n         * in the region to the next band.\n         */\n        if (r1->y2 == ybot)\n        {\n            r1 = r1_band_end;\n        }\n\n        if (r2->y2 == ybot)\n        {\n            r2 = r2_band_end;\n        }\n\n    }\n    while (r1 != r1_end && r2 != r2_end);\n\n    /*\n     * Deal with whichever region (if any) still has rectangles left.\n     *\n     * We only need to worry about banding and coalescing for the very first\n     * band left.  After that, we can just group all remaining boxes,\n     * regardless of how many bands, into one final append to the list.\n     */\n\n    if ((r1 != r1_end) && append_non1)\n    {\n        /* Do first non_overlap1Func call, which may be able to coalesce */\n        FIND_BAND (r1, r1_band_end, r1_end, r1y1);\n\n        cur_band = new_reg->data->numRects;\n\n        if (!pixman_region_append_non_o (new_reg,\n                                         r1, r1_band_end,\n                                         MAX (r1y1, ybot), r1->y2))\n        {\n            goto bail;\n        }\n\n        COALESCE (new_reg, prev_band, cur_band);\n\n        /* Just append the rest of the boxes  */\n        APPEND_REGIONS (new_reg, r1_band_end, r1_end);\n    }\n    else if ((r2 != r2_end) && append_non2)\n    {\n        /* Do first non_overlap2Func call, which may be able to coalesce */\n        FIND_BAND (r2, r2_band_end, r2_end, r2y1);\n\n        cur_band = new_reg->data->numRects;\n\n        if (!pixman_region_append_non_o (new_reg,\n                                         r2, r2_band_end,\n                                         MAX (r2y1, ybot), r2->y2))\n        {\n            goto bail;\n        }\n\n        COALESCE (new_reg, prev_band, cur_band);\n\n        /* Append rest of boxes */\n        APPEND_REGIONS (new_reg, r2_band_end, r2_end);\n    }\n\n    free (old_data);\n\n    if (!(numRects = new_reg->data->numRects))\n    {\n        FREE_DATA (new_reg);\n        new_reg->data = pixman_region_empty_data;\n    }\n    else if (numRects == 1)\n    {\n        new_reg->extents = *PIXREGION_BOXPTR (new_reg);\n        FREE_DATA (new_reg);\n        new_reg->data = (region_data_type_t *)NULL;\n    }\n    else\n    {\n        DOWNSIZE (new_reg, numRects);\n    }\n\n    return TRUE;\n\nbail:\n    free (old_data);\n\n    return pixman_break (new_reg);\n}\n\n/*-\n *-----------------------------------------------------------------------\n * pixman_set_extents --\n *      Reset the extents of a region to what they should be. Called by\n *      pixman_region_subtract and pixman_region_intersect as they can't\n *      figure it out along the way or do so easily, as pixman_region_union can.\n *\n * Results:\n *      None.\n *\n * Side Effects:\n *      The region's 'extents' structure is overwritten.\n *\n *-----------------------------------------------------------------------\n */\nstatic void\npixman_set_extents (region_type_t *region)\n{\n    box_type_t *box, *box_end;\n\n    if (!region->data)\n    {\n        return;\n    }\n\n    if (!region->data->size)\n    {\n        region->extents.x2 = region->extents.x1;\n        region->extents.y2 = region->extents.y1;\n        return;\n    }\n\n    box = PIXREGION_BOXPTR (region);\n    box_end = PIXREGION_END (region);\n\n    /*\n     * Since box is the first rectangle in the region, it must have the\n     * smallest y1 and since box_end is the last rectangle in the region,\n     * it must have the largest y2, because of banding. Initialize x1 and\n     * x2 from  box and box_end, resp., as good things to initialize them\n     * to...\n     */\n    region->extents.x1 = box->x1;\n    region->extents.y1 = box->y1;\n    region->extents.x2 = box_end->x2;\n    region->extents.y2 = box_end->y2;\n\n    critical_if_fail (region->extents.y1 < region->extents.y2);\n\n    while (box <= box_end)\n    {\n        if (box->x1 < region->extents.x1)\n        {\n            region->extents.x1 = box->x1;\n        }\n        if (box->x2 > region->extents.x2)\n        {\n            region->extents.x2 = box->x2;\n        }\n        box++;\n    }\n\n    critical_if_fail (region->extents.x1 < region->extents.x2);\n}\n\n/*======================================================================\n *          Region Intersection\n *====================================================================*/\n/*-\n *-----------------------------------------------------------------------\n * pixman_region_intersect_o --\n *      Handle an overlapping band for pixman_region_intersect.\n *\n * Results:\n *      TRUE if successful.\n *\n * Side Effects:\n *      Rectangles may be added to the region.\n *\n *-----------------------------------------------------------------------\n */\n/*ARGSUSED*/\nstatic pixman_bool_t\npixman_region_intersect_o (region_type_t *region,\n                           box_type_t    *r1,\n                           box_type_t    *r1_end,\n                           box_type_t    *r2,\n                           box_type_t    *r2_end,\n                           int            y1,\n                           int            y2)\n{\n    int x1;\n    int x2;\n    box_type_t         *next_rect;\n\n    next_rect = PIXREGION_TOP (region);\n\n    critical_if_fail (y1 < y2);\n    critical_if_fail (r1 != r1_end && r2 != r2_end);\n\n    do\n    {\n        x1 = MAX (r1->x1, r2->x1);\n        x2 = MIN (r1->x2, r2->x2);\n\n        /*\n         * If there's any overlap between the two rectangles, add that\n         * overlap to the new region.\n         */\n        if (x1 < x2)\n        {\n            NEWRECT (region, next_rect, x1, y1, x2, y2);\n        }\n\n        /*\n         * Advance the pointer(s) with the leftmost right side, since the next\n         * rectangle on that list may still overlap the other region's\n         * current rectangle.\n         */\n        if (r1->x2 == x2)\n        {\n            r1++;\n        }\n        if (r2->x2 == x2)\n        {\n            r2++;\n        }\n    }\n    while ((r1 != r1_end) && (r2 != r2_end));\n\n    return TRUE;\n}\n\nPIXMAN_EXPORT pixman_bool_t\nPREFIX (_intersect) (region_type_t      *new_reg,\n                     region_type_t         *reg1,\n                     region_type_t         *reg2)\n{\n    GOOD (reg1);\n    GOOD (reg2);\n    GOOD (new_reg);\n\n    /* check for trivial reject */\n    if (PIXREGION_NIL (reg1) || PIXREGION_NIL (reg2) ||\n            !EXTENTCHECK (&reg1->extents, &reg2->extents))\n    {\n        /* Covers about 20% of all cases */\n        FREE_DATA (new_reg);\n        new_reg->extents.x2 = new_reg->extents.x1;\n        new_reg->extents.y2 = new_reg->extents.y1;\n        if (PIXREGION_NAR (reg1) || PIXREGION_NAR (reg2))\n        {\n            new_reg->data = pixman_broken_data;\n            return FALSE;\n        }\n        else\n        {\n            new_reg->data = pixman_region_empty_data;\n        }\n    }\n    else if (!reg1->data && !reg2->data)\n    {\n        /* Covers about 80% of cases that aren't trivially rejected */\n        new_reg->extents.x1 = MAX (reg1->extents.x1, reg2->extents.x1);\n        new_reg->extents.y1 = MAX (reg1->extents.y1, reg2->extents.y1);\n        new_reg->extents.x2 = MIN (reg1->extents.x2, reg2->extents.x2);\n        new_reg->extents.y2 = MIN (reg1->extents.y2, reg2->extents.y2);\n\n        FREE_DATA (new_reg);\n\n        new_reg->data = (region_data_type_t *)NULL;\n    }\n    else if (!reg2->data && SUBSUMES (&reg2->extents, &reg1->extents))\n    {\n        return PREFIX (_copy) (new_reg, reg1);\n    }\n    else if (!reg1->data && SUBSUMES (&reg1->extents, &reg2->extents))\n    {\n        return PREFIX (_copy) (new_reg, reg2);\n    }\n    else if (reg1 == reg2)\n    {\n        return PREFIX (_copy) (new_reg, reg1);\n    }\n    else\n    {\n        /* General purpose intersection */\n\n        if (!pixman_op (new_reg, reg1, reg2, pixman_region_intersect_o, FALSE, FALSE))\n        {\n            return FALSE;\n        }\n\n        pixman_set_extents (new_reg);\n    }\n\n    GOOD (new_reg);\n    return (TRUE);\n}\n\n#define MERGERECT(r)                                                    \\\n    do                                                                  \\\n    {                                                                   \\\n        if (r->x1 <= x2)                                                \\\n        {                                                               \\\n            /* Merge with current rectangle */                          \\\n            if (x2 < r->x2)                                             \\\n                x2 = r->x2;                                             \\\n        }                                                               \\\n        else                                                            \\\n        {                                                               \\\n            /* Add current rectangle, start new one */                  \\\n            NEWRECT (region, next_rect, x1, y1, x2, y2);                \\\n            x1 = r->x1;                                                 \\\n            x2 = r->x2;                                                 \\\n        }                                                               \\\n        r++;                                                            \\\n    } while (0)\n\n/*======================================================================\n *          Region Union\n *====================================================================*/\n\n/*-\n *-----------------------------------------------------------------------\n * pixman_region_union_o --\n *      Handle an overlapping band for the union operation. Picks the\n *      left-most rectangle each time and merges it into the region.\n *\n * Results:\n *      TRUE if successful.\n *\n * Side Effects:\n *      region is overwritten.\n *      overlap is set to TRUE if any boxes overlap.\n *\n *-----------------------------------------------------------------------\n */\nstatic pixman_bool_t\npixman_region_union_o (region_type_t *region,\n                       box_type_t    *r1,\n                       box_type_t    *r1_end,\n                       box_type_t    *r2,\n                       box_type_t    *r2_end,\n                       int            y1,\n                       int            y2)\n{\n    box_type_t *next_rect;\n    int x1;            /* left and right side of current union */\n    int x2;\n\n    critical_if_fail (y1 < y2);\n    critical_if_fail (r1 != r1_end && r2 != r2_end);\n\n    next_rect = PIXREGION_TOP (region);\n\n    /* Start off current rectangle */\n    if (r1->x1 < r2->x1)\n    {\n        x1 = r1->x1;\n        x2 = r1->x2;\n        r1++;\n    }\n    else\n    {\n        x1 = r2->x1;\n        x2 = r2->x2;\n        r2++;\n    }\n    while (r1 != r1_end && r2 != r2_end)\n    {\n        if (r1->x1 < r2->x1)\n        {\n            MERGERECT (r1);\n        }\n        else\n        {\n            MERGERECT (r2);\n        }\n    }\n\n    /* Finish off whoever (if any) is left */\n    if (r1 != r1_end)\n    {\n        do\n        {\n            MERGERECT (r1);\n        }\n        while (r1 != r1_end);\n    }\n    else if (r2 != r2_end)\n    {\n        do\n        {\n            MERGERECT (r2);\n        }\n        while (r2 != r2_end);\n    }\n\n    /* Add current rectangle */\n    NEWRECT (region, next_rect, x1, y1, x2, y2);\n\n    return TRUE;\n}\n\nPIXMAN_EXPORT pixman_bool_t\nPREFIX (_union) (region_type_t *new_reg,\n                 region_type_t *reg1,\n                 region_type_t *reg2)\n{\n    /* Return TRUE if some overlap\n     * between reg1, reg2\n     */\n    GOOD (reg1);\n    GOOD (reg2);\n    GOOD (new_reg);\n\n    /*  checks all the simple cases */\n\n    /*\n     * Region 1 and 2 are the same\n     */\n    if (reg1 == reg2)\n    {\n        return PREFIX (_copy) (new_reg, reg1);\n    }\n\n    /*\n     * Region 1 is empty\n     */\n    if (PIXREGION_NIL (reg1))\n    {\n        if (PIXREGION_NAR (reg1))\n        {\n            return pixman_break (new_reg);\n        }\n\n        if (new_reg != reg2)\n        {\n            return PREFIX (_copy) (new_reg, reg2);\n        }\n\n        return TRUE;\n    }\n\n    /*\n     * Region 2 is empty\n     */\n    if (PIXREGION_NIL (reg2))\n    {\n        if (PIXREGION_NAR (reg2))\n        {\n            return pixman_break (new_reg);\n        }\n\n        if (new_reg != reg1)\n        {\n            return PREFIX (_copy) (new_reg, reg1);\n        }\n\n        return TRUE;\n    }\n\n    /*\n     * Region 1 completely subsumes region 2\n     */\n    if (!reg1->data && SUBSUMES (&reg1->extents, &reg2->extents))\n    {\n        if (new_reg != reg1)\n        {\n            return PREFIX (_copy) (new_reg, reg1);\n        }\n\n        return TRUE;\n    }\n\n    /*\n     * Region 2 completely subsumes region 1\n     */\n    if (!reg2->data && SUBSUMES (&reg2->extents, &reg1->extents))\n    {\n        if (new_reg != reg2)\n        {\n            return PREFIX (_copy) (new_reg, reg2);\n        }\n\n        return TRUE;\n    }\n\n    if (!pixman_op (new_reg, reg1, reg2, pixman_region_union_o, TRUE, TRUE))\n    {\n        return FALSE;\n    }\n\n    new_reg->extents.x1 = MIN (reg1->extents.x1, reg2->extents.x1);\n    new_reg->extents.y1 = MIN (reg1->extents.y1, reg2->extents.y1);\n    new_reg->extents.x2 = MAX (reg1->extents.x2, reg2->extents.x2);\n    new_reg->extents.y2 = MAX (reg1->extents.y2, reg2->extents.y2);\n\n    GOOD (new_reg);\n\n    return TRUE;\n}\n\n/*======================================================================\n *          Batch Rectangle Union\n *====================================================================*/\n\n#define EXCHANGE_RECTS(a, b)    \\\n    {                           \\\n        box_type_t t;           \\\n        t = rects[a];           \\\n        rects[a] = rects[b];    \\\n        rects[b] = t;           \\\n    }\n\n/*======================================================================\n *                Region Subtraction\n *====================================================================*/\n\n/*-\n *-----------------------------------------------------------------------\n * pixman_region_subtract_o --\n *      Overlapping band subtraction. x1 is the left-most point not yet\n *      checked.\n *\n * Results:\n *      TRUE if successful.\n *\n * Side Effects:\n *      region may have rectangles added to it.\n *\n *-----------------------------------------------------------------------\n */\n/*ARGSUSED*/\nstatic pixman_bool_t\npixman_region_subtract_o (region_type_t *region,\n                          box_type_t     *r1,\n                          box_type_t     *r1_end,\n                          box_type_t     *r2,\n                          box_type_t     *r2_end,\n                          int             y1,\n                          int             y2)\n{\n    box_type_t         *next_rect;\n    int x1;\n\n    x1 = r1->x1;\n\n    critical_if_fail (y1 < y2);\n    critical_if_fail (r1 != r1_end && r2 != r2_end);\n\n    next_rect = PIXREGION_TOP (region);\n\n    do\n    {\n        if (r2->x2 <= x1)\n        {\n            /*\n             * Subtrahend entirely to left of minuend: go to next subtrahend.\n             */\n            r2++;\n        }\n        else if (r2->x1 <= x1)\n        {\n            /*\n             * Subtrahend precedes minuend: nuke left edge of minuend.\n             */\n            x1 = r2->x2;\n            if (x1 >= r1->x2)\n            {\n                /*\n                 * Minuend completely covered: advance to next minuend and\n                 * reset left fence to edge of new minuend.\n                 */\n                r1++;\n                if (r1 != r1_end)\n                {\n                    x1 = r1->x1;\n                }\n            }\n            else\n            {\n                /*\n                 * Subtrahend now used up since it doesn't extend beyond\n                 * minuend\n                 */\n                r2++;\n            }\n        }\n        else if (r2->x1 < r1->x2)\n        {\n            /*\n             * Left part of subtrahend covers part of minuend: add uncovered\n             * part of minuend to region and skip to next subtrahend.\n             */\n            critical_if_fail (x1 < r2->x1);\n            NEWRECT (region, next_rect, x1, y1, r2->x1, y2);\n\n            x1 = r2->x2;\n            if (x1 >= r1->x2)\n            {\n                /*\n                 * Minuend used up: advance to new...\n                 */\n                r1++;\n                if (r1 != r1_end)\n                {\n                    x1 = r1->x1;\n                }\n            }\n            else\n            {\n                /*\n                 * Subtrahend used up\n                 */\n                r2++;\n            }\n        }\n        else\n        {\n            /*\n             * Minuend used up: add any remaining piece before advancing.\n             */\n            if (r1->x2 > x1)\n            {\n                NEWRECT (region, next_rect, x1, y1, r1->x2, y2);\n            }\n\n            r1++;\n\n            if (r1 != r1_end)\n            {\n                x1 = r1->x1;\n            }\n        }\n    }\n    while ((r1 != r1_end) && (r2 != r2_end));\n\n    /*\n     * Add remaining minuend rectangles to region.\n     */\n    while (r1 != r1_end)\n    {\n        critical_if_fail (x1 < r1->x2);\n\n        NEWRECT (region, next_rect, x1, y1, r1->x2, y2);\n\n        r1++;\n        if (r1 != r1_end)\n        {\n            x1 = r1->x1;\n        }\n    }\n    return TRUE;\n}\n\n/*-\n *-----------------------------------------------------------------------\n * pixman_region_subtract --\n *      Subtract reg_s from reg_m and leave the result in reg_d.\n *      S stands for subtrahend, M for minuend and D for difference.\n *\n * Results:\n *      TRUE if successful.\n *\n * Side Effects:\n *      reg_d is overwritten.\n *\n *-----------------------------------------------------------------------\n */\nPIXMAN_EXPORT pixman_bool_t\nPREFIX (_subtract) (region_type_t *reg_d,\n                    region_type_t *reg_m,\n                    region_type_t *reg_s)\n{\n    GOOD (reg_m);\n    GOOD (reg_s);\n    GOOD (reg_d);\n\n    /* check for trivial rejects */\n    if (PIXREGION_NIL (reg_m) || PIXREGION_NIL (reg_s) ||\n            !EXTENTCHECK (&reg_m->extents, &reg_s->extents))\n    {\n        if (PIXREGION_NAR (reg_s))\n        {\n            return pixman_break (reg_d);\n        }\n\n        return PREFIX (_copy) (reg_d, reg_m);\n    }\n    else if (reg_m == reg_s)\n    {\n        FREE_DATA (reg_d);\n        reg_d->extents.x2 = reg_d->extents.x1;\n        reg_d->extents.y2 = reg_d->extents.y1;\n        reg_d->data = pixman_region_empty_data;\n\n        return TRUE;\n    }\n\n    /* Add those rectangles in region 1 that aren't in region 2,\n       do yucky subtraction for overlaps, and\n       just throw away rectangles in region 2 that aren't in region 1 */\n    if (!pixman_op (reg_d, reg_m, reg_s, pixman_region_subtract_o, TRUE, FALSE))\n    {\n        return FALSE;\n    }\n\n    /*\n     * Can't alter reg_d's extents before we call pixman_op because\n     * it might be one of the source regions and pixman_op depends\n     * on the extents of those regions being unaltered. Besides, this\n     * way there's no checking against rectangles that will be nuked\n     * due to coalescing, so we have to examine fewer rectangles.\n     */\n    pixman_set_extents (reg_d);\n    GOOD (reg_d);\n    return TRUE;\n}\n\n/*======================================================================\n *          Region Inversion\n *====================================================================*/\n\nPIXMAN_EXPORT int\nPREFIX (_not_empty) (region_type_t *region)\n{\n    GOOD (region);\n\n    return (!PIXREGION_NIL (region));\n}\n\nPIXMAN_EXPORT box_type_t *\nPREFIX (_extents) (region_type_t *region)\n{\n    GOOD (region);\n\n    return (&region->extents);\n}\n\n#ifdef USE_DEVEL_LOGGING\n/*\n * Clip a list of scanlines to a region.  The caller has allocated the\n * space.  FSorted is non-zero if the scanline origins are in ascending order.\n *\n * returns the number of new, clipped scanlines.\n *\n * NB: For xrdp this function is only used if we are running devel logging\n */\n\nPIXMAN_EXPORT pixman_bool_t\nPREFIX (_selfcheck) (region_type_t *reg)\n{\n    int i, numRects;\n\n    if ((reg->extents.x1 > reg->extents.x2) ||\n            (reg->extents.y1 > reg->extents.y2))\n    {\n        return FALSE;\n    }\n\n    numRects = PIXREGION_NUMRECTS (reg);\n    if (!numRects)\n    {\n        return ((reg->extents.x1 == reg->extents.x2) &&\n                (reg->extents.y1 == reg->extents.y2) &&\n                (reg->data->size || (reg->data == pixman_region_empty_data)));\n    }\n    else if (numRects == 1)\n    {\n        return (!reg->data);\n    }\n    else\n    {\n        box_type_t *pbox_p, *pbox_n;\n        box_type_t box;\n\n        pbox_p = PIXREGION_RECTS (reg);\n        box = *pbox_p;\n        box.y2 = pbox_p[numRects - 1].y2;\n        pbox_n = pbox_p + 1;\n\n        for (i = numRects; --i > 0; pbox_p++, pbox_n++)\n        {\n            if ((pbox_n->x1 >= pbox_n->x2) ||\n                    (pbox_n->y1 >= pbox_n->y2))\n            {\n                return FALSE;\n            }\n\n            if (pbox_n->x1 < box.x1)\n            {\n                box.x1 = pbox_n->x1;\n            }\n\n            if (pbox_n->x2 > box.x2)\n            {\n                box.x2 = pbox_n->x2;\n            }\n\n            if ((pbox_n->y1 < pbox_p->y1) ||\n                    ((pbox_n->y1 == pbox_p->y1) &&\n                     ((pbox_n->x1 < pbox_p->x2) || (pbox_n->y2 != pbox_p->y2))))\n            {\n                return FALSE;\n            }\n        }\n\n        return ((box.x1 == reg->extents.x1) &&\n                (box.x2 == reg->extents.x2) &&\n                (box.y1 == reg->extents.y1) &&\n                (box.y2 == reg->extents.y2));\n    }\n}\n#endif // USE_DEVEL_LOGGING\n"
  },
  {
    "path": "common/pixman-region.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2016\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * region, from pixman.h\n */\n\n#ifndef PIXMAN_PIXMAN_H__\n#define PIXMAN_PIXMAN_H__\n\ntypedef int pixman_bool_t;\n\nstruct pixman_region16_data\n{\n    long size;\n    long numRects;\n};\n\nstruct pixman_box16\n{\n    signed short x1, y1, x2, y2;\n};\n\nstruct pixman_region16\n{\n    struct pixman_box16 extents;\n    struct pixman_region16_data *data;\n};\n\nenum _pixman_region_overlap_t\n{\n    PIXMAN_REGION_OUT,\n    PIXMAN_REGION_IN,\n    PIXMAN_REGION_PART\n};\n\ntypedef enum _pixman_region_overlap_t pixman_region_overlap_t;\n\ntypedef struct pixman_region16_data     pixman_region16_data_t;\ntypedef struct pixman_box16             pixman_box16_t;\ntypedef struct pixman_region16          pixman_region16_t;\n\n/* creation/destruction */\nvoid    pixman_region_init        (pixman_region16_t *region);\nvoid    pixman_region_init_rect   (pixman_region16_t *region, int x, int y,\n                                   unsigned int width, unsigned int height);\nvoid    pixman_region_fini        (pixman_region16_t *region);\npixman_bool_t pixman_region_union (pixman_region16_t *new_reg,\n                                   pixman_region16_t *reg1,\n                                   pixman_region16_t *reg2);\npixman_bool_t pixman_region_subtract  (pixman_region16_t *reg_d,\n                                       pixman_region16_t *reg_m,\n                                       pixman_region16_t *reg_s);\npixman_bool_t pixman_region_intersect (pixman_region16_t *new_reg,\n                                       pixman_region16_t *reg1,\n                                       pixman_region16_t *reg2);\npixman_box16_t *pixman_region_rectangles (pixman_region16_t *region,\n        int *n_rects);\npixman_bool_t pixman_region_not_empty (pixman_region16_t *region);\npixman_box16_t *pixman_region_extents (pixman_region16_t *region);\n\n#endif\n"
  },
  {
    "path": "common/pixman-region16.c",
    "content": "/*\n * Copyright © 2008 Red Hat, Inc.\n *\n * Permission to use, copy, modify, distribute, and sell this software\n * and its documentation for any purpose is hereby granted without\n * fee, provided that the above copyright notice appear in all copies\n * and that both that copyright notice and this permission notice\n * appear in supporting documentation, and that the name of\n * Red Hat, Inc. not be used in advertising or publicity pertaining to\n * distribution of the software without specific, written prior\n * permission. Red Hat, Inc. makes no representations about the\n * suitability of this software for any purpose.  It is provided \"as\n * is\" without express or implied warranty.\n *\n * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS\n * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,\n * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER\n * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION\n * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR\n * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n *\n * Author: Soren Sandmann <sandmann@redhat.com>\n */\n\n/* taken from pixman 0.34\n   altered to compile without all of pixman */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#if defined(HAVE_STDINT_H)\n#include <stdint.h>\n#endif\n#include \"pixman-region.h\"\n\n#if !defined(UINT32_MAX)\n#define UINT32_MAX  (4294967295U)\n#endif\n#if !defined(INT16_MIN)\n#define INT16_MIN   (-32767-1)\n#endif\n#if !defined(INT16_MAX)\n#define INT16_MAX   (32767)\n#endif\n\n#define PIXMAN_EXPORT\n#define FALSE 0\n#define TRUE 1\n\n#define MIN(x1, x2) ((x1) < (x2) ? (x1) : (x2))\n#define MAX(x1, x2) ((x1) > (x2) ? (x1) : (x2))\n\ntypedef pixman_box16_t                  box_type_t;\ntypedef pixman_region16_data_t          region_data_type_t;\ntypedef pixman_region16_t               region_type_t;\ntypedef signed int                      overflow_int_t;\n\n#define PREFIX(x) pixman_region##x\n\n#define PIXMAN_REGION_MAX INT16_MAX\n#define PIXMAN_REGION_MIN INT16_MIN\n\n#define FUNC \"func\"\n\n#define critical_if_fail(expr)\n\nstatic int _pixman_log_error(const char *func, const char *format, ...)\n{\n    return 0;\n}\n\n#include \"pixman-region.c\"\n\n"
  },
  {
    "path": "common/rail.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(_RAIL_H)\n#define _RAIL_H\n\n/*\n  ORDER_TYPE_WINDOW\n    WINDOW_ORDER_TYPE_WINDOW\n      WINDOW_ORDER_ICON\n      WINDOW_ORDER_CACHED_ICON\n      WINDOW_ORDER_STATE_DELETED\n      WINDOW_ORDER_STATE_NEW on\n      WINDOW_ORDER_STATE_NEW off\n    WINDOW_ORDER_TYPE_NOTIFY\n      WINDOW_ORDER_STATE_DELETED\n      WINDOW_ORDER_STATE_NEW on\n      WINDOW_ORDER_STATE_NEW off\n    WINDOW_ORDER_TYPE_DESKTOP\n      WINDOW_ORDER_FIELD_DESKTOP_NONE on\n      WINDOW_ORDER_FIELD_DESKTOP_NONE off\n*/\n\n/* Window Order Header Flags */\n#define WINDOW_ORDER_TYPE_WINDOW                        0x01000000\n#define WINDOW_ORDER_TYPE_NOTIFY                        0x02000000\n#define WINDOW_ORDER_TYPE_DESKTOP                       0x04000000\n#define WINDOW_ORDER_STATE_NEW                          0x10000000\n#define WINDOW_ORDER_STATE_DELETED                      0x20000000\n#define WINDOW_ORDER_FIELD_OWNER                        0x00000002\n#define WINDOW_ORDER_FIELD_STYLE                        0x00000008\n#define WINDOW_ORDER_FIELD_SHOW                         0x00000010\n#define WINDOW_ORDER_FIELD_TITLE                        0x00000004\n#define WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET           0x00004000\n#define WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE             0x00010000\n#define WINDOW_ORDER_FIELD_RP_CONTENT                   0x00020000\n#define WINDOW_ORDER_FIELD_ROOT_PARENT                  0x00040000\n#define WINDOW_ORDER_FIELD_WND_OFFSET                   0x00000800\n#define WINDOW_ORDER_FIELD_WND_CLIENT_DELTA             0x00008000\n#define WINDOW_ORDER_FIELD_WND_SIZE                     0x00000400\n#define WINDOW_ORDER_FIELD_WND_RECTS                    0x00000100\n#define WINDOW_ORDER_FIELD_VIS_OFFSET                   0x00001000\n#define WINDOW_ORDER_FIELD_VISIBILITY                   0x00000200\n#define WINDOW_ORDER_FIELD_ICON_BIG                     0x00002000\n#define WINDOW_ORDER_ICON                               0x40000000\n#define WINDOW_ORDER_CACHED_ICON                        0x80000000\n#define WINDOW_ORDER_FIELD_NOTIFY_VERSION               0x00000008\n#define WINDOW_ORDER_FIELD_NOTIFY_TIP                   0x00000001\n#define WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP              0x00000002\n#define WINDOW_ORDER_FIELD_NOTIFY_STATE                 0x00000004\n#define WINDOW_ORDER_FIELD_DESKTOP_NONE                 0x00000001\n#define WINDOW_ORDER_FIELD_DESKTOP_HOOKED               0x00000002\n#define WINDOW_ORDER_FIELD_DESKTOP_ARC_COMPLETED        0x00000004\n#define WINDOW_ORDER_FIELD_DESKTOP_ARC_BEGAN            0x00000008\n#define WINDOW_ORDER_FIELD_DESKTOP_ZORDER               0x00000010\n#define WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND           0x00000020\n\nstruct rail_icon_info\n{\n    int bpp;\n    int width;\n    int height;\n    int cmap_bytes;\n    int mask_bytes;\n    int data_bytes;\n    char *mask;\n    char *cmap;\n    char *data;\n};\n\nstruct rail_window_rect\n{\n    short left;\n    short top;\n    short right;\n    short bottom;\n};\n\nstruct rail_notify_icon_infotip\n{\n    int timeout;\n    int flags;\n    char *text;\n    char *title;\n};\n\nstruct rail_window_state_order\n{\n    int owner_window_id;\n    int style;\n    int extended_style;\n    int show_state;\n    char *title_info;\n    int client_offset_x;\n    int client_offset_y;\n    int client_area_width;\n    int client_area_height;\n    int rp_content;\n    int root_parent_handle;\n    int window_offset_x;\n    int window_offset_y;\n    int window_client_delta_x;\n    int window_client_delta_y;\n    int window_width;\n    int window_height;\n    int num_window_rects;\n    struct rail_window_rect *window_rects;\n    int visible_offset_x;\n    int visible_offset_y;\n    int num_visibility_rects;\n    struct rail_window_rect *visibility_rects;\n};\n\nstruct rail_notify_state_order\n{\n    int version;\n    char *tool_tip;\n    struct rail_notify_icon_infotip infotip;\n    int state;\n    int icon_cache_entry;\n    int icon_cache_id;\n    struct rail_icon_info icon_info;\n};\n\nstruct rail_monitored_desktop_order\n{\n    int active_window_id;\n    int num_window_ids;\n    int *window_ids;\n};\n\n#endif\n"
  },
  {
    "path": "common/scancode.c",
    "content": "/**\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file    common/scancode.c\n * @brief   Scancode handling\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n#include <stddef.h>\n#include <string.h>\n\n#include \"scancode.h\"\n\nstruct scancode_to_keycode\n{\n    unsigned short scancode; // 0x1xx implies an extended key\n    unsigned char keycode;\n};\n\n#define ELEMENTS(x) (sizeof(x) / sizeof(x[0]))\n\n// Sources:-\n// file:/usr/share/X11/xkb/keycodes/evdev\n// https://wiki.osdev.org/PS/2_Keyboard\n// https://www.kbdlayout.info/\nstatic const struct scancode_to_keycode\n    evdev_scancode_to_keycode_map[] =\n{\n    //                   Virtual              XKB\n    //                   Key (US)             Symbol\n    //                   --------             ------\n    { 0x001, 9 },   //   VK_ESCAPE            ESC\n    { 0x002, 10 },  //   VK_1                 AE01\n    { 0x003, 11 },  //   VK_2                 AE02\n    { 0x004, 12 },  //   VK_3                 AE03\n    { 0x005, 13 },  //   VK_4                 AE04\n    { 0x006, 14 },  //   VK_5                 AE05\n    { 0x007, 15 },  //   VK_6                 AE06\n    { 0x008, 16 },  //   VK_7                 AE07\n    { 0x009, 17 },  //   VK_8                 AE08\n    { 0x00a, 18 },  //   VK_9                 AE09\n    { 0x00b, 19 },  //   VK_0                 AE10\n    { 0x00c, 20 },  //   VK_OEM_MINUS         AE11\n    { 0x00d, 21 },  //   VK_OEM_PLUS          AE12\n    { 0x00e, 22 },  //   VK_BACK              BKSP\n    { 0x00f, 23 },  //   VK_TAB               TAB\n    { 0x010, 24 },  //   VK_Q                 AD01\n    { 0x011, 25 },  //   VK_W                 AD02\n    { 0x012, 26 },  //   VK_E                 AD03\n    { 0x013, 27 },  //   VK_R                 AD04\n    { 0x014, 28 },  //   VK_T                 AD05\n    { 0x015, 29 },  //   VK_Y                 AD06\n    { 0x016, 30 },  //   VK_U                 AD07\n    { 0x017, 31 },  //   VK_I                 AD08\n    { 0x018, 32 },  //   VK_O                 AD09\n    { 0x019, 33 },  //   VK_P                 AD10\n    { 0x01a, 34 },  //   VK_OEM_4             AD11\n    { 0x01b, 35 },  //   VK_OEM_6             AD12\n    { 0x01c, 36 },  //   VK_RETURN            RTRN\n    { 0x01d, 37 },  //   VK_LCONTROL          LCTL\n    { 0x01e, 38 },  //   VK_A                 AC01\n    { 0x01f, 39 },  //   VK_S                 AC02\n    { 0x020, 40 },  //   VK_D                 AC03\n    { 0x021, 41 },  //   VK_F                 AC04\n    { 0x022, 42 },  //   VK_G                 AC05\n    { 0x023, 43 },  //   VK_H                 AC06\n    { 0x024, 44 },  //   VK_J                 AC07\n    { 0x025, 45 },  //   VK_K                 AC08\n    { 0x026, 46 },  //   VK_L                 AC09\n    { 0x027, 47 },  //   VK_OEM_1             AC10\n    { 0x028, 48 },  //   VK_OEM_7             AC11\n    { 0x029, 49 },  //   VK_OEM_3             TLDE\n    { 0x02a, 50 },  //   VK_LSHIFT            LFSH\n    { 0x02b, 51 },  //   VK_OEM_5             BKSL\n    { 0x02c, 52 },  //   VK_Z                 AB01\n    { 0x02d, 53 },  //   VK_X                 AB02\n    { 0x02e, 54 },  //   VK_C                 AB03\n    { 0x02f, 55 },  //   VK_V                 AB04\n    { 0x030, 56 },  //   VK_B                 AB05\n    { 0x031, 57 },  //   VK_N                 AB06\n    { 0x032, 58 },  //   VK_M                 AB07\n    { 0x033, 59 },  //   VK_OEM_COMMA         AB08\n    { 0x034, 60 },  //   VK_OEM_PERIOD        AB09\n    { 0x035, 61 },  //   VK_OEM_2             AB10\n    { 0x036, 62 },  //   VK_RSHIFT            RTSH\n    { 0x037, 63 },  //   VK_MULTIPLY          KPMU\n    { 0x038, 64 },  //   VK_LMENU             LALT\n    { 0x039, 65 },  //   VK_SPACE             SPCE\n    { 0x03a, 66 },  //   VK_CAPITAL           CAPS\n    { 0x03b, 67 },  //   VK_F1                FK01\n    { 0x03c, 68 },  //   VK_F2                FK02\n    { 0x03d, 69 },  //   VK_F3                FK03\n    { 0x03e, 70 },  //   VK_F4                FK04\n    { 0x03f, 71 },  //   VK_F5                FK05\n    { 0x040, 72 },  //   VK_F6                FK06\n    { 0x041, 73 },  //   VK_F7                FK07\n    { 0x042, 74 },  //   VK_F8                FK08\n    { 0x043, 75 },  //   VK_F9                FK09\n    { 0x044, 76 },  //   VK_F10               FK10\n    { 0x045, 77 },  //   VK_NUMLOCK           NMLK\n    { 0x046, 78 },  //   VK_SCROLL            SCLK\n    { 0x047, 79 },  //   VK_HOME              KP7\n    { 0x048, 80 },  //   VK_UP                KP8\n    { 0x049, 81 },  //   VK_PRIOR             KP9\n    { 0x04a, 82 },  //   VK_SUBTRACT          KPSU\n    { 0x04b, 83 },  //   VK_LEFT              KP4\n    { 0x04c, 84 },  //   VK_CLEAR             KP5\n    { 0x04d, 85 },  //   VK_RIGHT             KP6\n    { 0x04e, 86 },  //   VK_ADD               KPAD\n    { 0x04f, 87 },  //   VK_END               KP1\n    { 0x050, 88 },  //   VK_DOWN              KP2\n    { 0x051, 89 },  //   VK_NEXT              KP3\n    { 0x052, 90 },  //   VK_INSERT            KP0\n    { 0x053, 91 },  //   VK_DELETE            KPDL\n    { 0x056, 94 },  //   VK_OEM_102           LSGT\n    { 0x057, 95 },  //   VK_F11               FK11\n    { 0x058, 96 },  //   VK_F12               FK12\n    { 0x070, 101 }, //   -                    HKTG\n    { 0x073, 97 },  //   VK_ABNT_C1           AB11\n    { 0x079, 100 }, //   -                    HENK\n    { 0x07b, 102 }, //   VK_OEM_PA1           MUHE\n    { 0x07d, 132 }, //   -                    AE13\n    { 0x07e, 129 }, //   VK_ABNT_C2           KPPT (Brazil ABNT2)\n    { 0x110, 173 }, //   VK_MEDIA_PREV_TRACK  I173 (KEY_PREVIOUSSONG)\n    { 0x119, 171 }, //   VK_MEDIA_NEXT_TRACK  I171 (KEY_NEXTSONG)\n    { 0x11c, 104 }, //   VK_RETURN            KPEN\n    { 0x11d, 105 }, //   VK_RCONTROL          RCTL\n    { 0x120, 121 }, //   VK_VOLUME_MUTE       MUTE\n    { 0x121, 148 }, //   VK_LAUNCH_APP2       I148 (KEY_CALC)\n    { 0x122, 172 }, //   VK_PLAY_PAUSE        I172 (KEY_PLAYPAUSE)\n    { 0x124, 174 }, //   VK_MEDIA_STOP        I174 (KEY_STOPCD)\n    { 0x12e, 122 }, //   VK_VOLUME_DOWN       VOL-\n    { 0x130, 123 }, //   VK_VOLUME_UP         VOL+\n    { 0x132, 180 }, //   VK_BROWSER_HOME      I180 (KEY_HOMEPAGE)\n    { 0x135, 106 }, //   VK_DIVIDE            KPDV\n    { 0x137, 107 }, //   VK_SNAPSHOT          PRSC\n    { 0x138, 108 }, //   VK_RMENU             RALT\n    { 0x147, 110 }, //   VK_HOME              HOME\n    { 0x148, 111 }, //   VK_UP                UP\n    { 0x149, 112 }, //   VK_PRIOR             PGUP (KEY_COMPUTER)\n    { 0x14b, 113 }, //   VK_LEFT              LEFT\n    { 0x14d, 114 }, //   VK_RIGHT             RGHT\n    { 0x14f, 115 }, //   VK_END               END\n    { 0x150, 116 }, //   VK_DOWN              DOWN\n    { 0x151, 117 }, //   VK_NEXT              PGDN\n    { 0x152, 118 }, //   VK_INSERT            INS\n    { 0x153, 119 }, //   VK_DELETE            DELE\n    { 0x15b, 133 }, //   VK_LWIN              LWIN\n    { 0x15c, 134 }, //   VK_RWIN              RWIN\n    { 0x15d, 135 }, //   VK_APPS              COMP\n    { 0x165, 225 }, //   VK_BROWSER_SEARCH    I225 (KEY_SEARCH)\n    { 0x166, 164 }, //   VK_BROWSER_FAVORITES I164 (KEY_BOOKMARKS)\n    { 0x16b, 165 }, //   VK_LAUNCH_APP1       I165 (KEY_COMPUTER)\n    { 0x16c, 163 }, //   VK_LAUNCH_MAIL       I163 (KEY_MAIL)\n    { 0x21d, 127 }  //   VK_PAUSE             PAUS (KEY_PAUSE)\n};\n\n// Sources:-\n// file:/usr/share/X11/xkb/keycodes/xfree86\n// https://wiki.osdev.org/PS/2_Keyboard\n// https://www.kbdlayout.info/\nstatic const struct scancode_to_keycode\n    base_scancode_to_keycode_map[] =\n{\n    //                   Virtual              XKB\n    //                   Key (US)             Symbol\n    //                   --------             ------\n    { 0x001, 9 },   //   VK_ESCAPE            ESC\n    { 0x002, 10 },  //   VK_1                 AE01\n    { 0x003, 11 },  //   VK_2                 AE02\n    { 0x004, 12 },  //   VK_3                 AE03\n    { 0x005, 13 },  //   VK_4                 AE04\n    { 0x006, 14 },  //   VK_5                 AE05\n    { 0x007, 15 },  //   VK_6                 AE06\n    { 0x008, 16 },  //   VK_7                 AE07\n    { 0x009, 17 },  //   VK_8                 AE08\n    { 0x00a, 18 },  //   VK_9                 AE09\n    { 0x00b, 19 },  //   VK_0                 AE10\n    { 0x00c, 20 },  //   VK_OEM_MINUS         AE11\n    { 0x00d, 21 },  //   VK_OEM_PLUS          AE12\n    { 0x00e, 22 },  //   VK_BACK              BKSP\n    { 0x00f, 23 },  //   VK_TAB               TAB\n    { 0x010, 24 },  //   VK_Q                 AD01\n    { 0x011, 25 },  //   VK_W                 AD02\n    { 0x012, 26 },  //   VK_E                 AD03\n    { 0x013, 27 },  //   VK_R                 AD04\n    { 0x014, 28 },  //   VK_T                 AD05\n    { 0x015, 29 },  //   VK_Y                 AD06\n    { 0x016, 30 },  //   VK_U                 AD07\n    { 0x017, 31 },  //   VK_I                 AD08\n    { 0x018, 32 },  //   VK_O                 AD09\n    { 0x019, 33 },  //   VK_P                 AD10\n    { 0x01a, 34 },  //   VK_OEM_4             AD11\n    { 0x01b, 35 },  //   VK_OEM_6             AD12\n    { 0x01c, 36 },  //   VK_RETURN            RTRN\n    { 0x01d, 37 },  //   VK_LCONTROL          LCTL\n    { 0x01e, 38 },  //   VK_A                 AC01\n    { 0x01f, 39 },  //   VK_S                 AC02\n    { 0x020, 40 },  //   VK_D                 AC03\n    { 0x021, 41 },  //   VK_F                 AC04\n    { 0x022, 42 },  //   VK_G                 AC05\n    { 0x023, 43 },  //   VK_H                 AC06\n    { 0x024, 44 },  //   VK_J                 AC07\n    { 0x025, 45 },  //   VK_K                 AC08\n    { 0x026, 46 },  //   VK_L                 AC09\n    { 0x027, 47 },  //   VK_OEM_1             AC10\n    { 0x028, 48 },  //   VK_OEM_7             AC11\n    { 0x029, 49 },  //   VK_OEM_3             TLDE\n    { 0x02a, 50 },  //   VK_LSHIFT            LFSH\n    { 0x02b, 51 },  //   VK_OEM_5             BKSL\n    { 0x02c, 52 },  //   VK_Z                 AB01\n    { 0x02d, 53 },  //   VK_X                 AB02\n    { 0x02e, 54 },  //   VK_C                 AB03\n    { 0x02f, 55 },  //   VK_V                 AB04\n    { 0x030, 56 },  //   VK_B                 AB05\n    { 0x031, 57 },  //   VK_N                 AB06\n    { 0x032, 58 },  //   VK_M                 AB07\n    { 0x033, 59 },  //   VK_OEM_COMMA         AB08\n    { 0x034, 60 },  //   VK_OEM_PERIOD        AB09\n    { 0x035, 61 },  //   VK_OEM_2             AB10\n    { 0x036, 62 },  //   VK_RSHIFT            RTSH\n    { 0x037, 63 },  //   VK_MULTIPLY          KPMU\n    { 0x038, 64 },  //   VK_LMENU             LALT\n    { 0x039, 65 },  //   VK_SPACE             SPCE\n    { 0x03a, 66 },  //   VK_CAPITAL           CAPS\n    { 0x03b, 67 },  //   VK_F1                FK01\n    { 0x03c, 68 },  //   VK_F2                FK02\n    { 0x03d, 69 },  //   VK_F3                FK03\n    { 0x03e, 70 },  //   VK_F4                FK04\n    { 0x03f, 71 },  //   VK_F5                FK05\n    { 0x040, 72 },  //   VK_F6                FK06\n    { 0x041, 73 },  //   VK_F7                FK07\n    { 0x042, 74 },  //   VK_F8                FK08\n    { 0x043, 75 },  //   VK_F9                FK09\n    { 0x044, 76 },  //   VK_F10               FK10\n    { 0x045, 77 },  //   VK_NUMLOCK           NMLK\n    { 0x046, 78 },  //   VK_SCROLL            SCLK\n    { 0x047, 79 },  //   VK_HOME              KP7\n    { 0x048, 80 },  //   VK_UP                KP8\n    { 0x049, 81 },  //   VK_PRIOR             KP9\n    { 0x04a, 82 },  //   VK_SUBTRACT          KPSU\n    { 0x04b, 83 },  //   VK_LEFT              KP4\n    { 0x04c, 84 },  //   VK_CLEAR             KP5\n    { 0x04d, 85 },  //   VK_RIGHT             KP6\n    { 0x04e, 86 },  //   VK_ADD               KPAD\n    { 0x04f, 87 },  //   VK_END               KP1\n    { 0x050, 88 },  //   VK_DOWN              KP2\n    { 0x051, 89 },  //   VK_NEXT              KP3\n    { 0x052, 90 },  //   VK_INSERT            KP0\n    { 0x053, 91 },  //   VK_DELETE            KPDL\n    { 0x056, 94 },  //   VK_OEM_102           LSGT\n    { 0x057, 95 },  //   VK_F11               FK11\n    { 0x058, 96 },  //   VK_F12               FK12\n    { 0x070, 208 }, //   -                    HKTG\n    { 0x073, 211 }, //   VK_ABNT_C1           AB11\n    { 0x079, 129 }, //   -                    XFER\n    { 0x07b, 131 }, //   VK_OEM_PA1           NFER\n    { 0x07d, 133 }, //   -                    AE13\n    { 0x07e, 134 }, //   VK_ABNT_C2           KPPT (Brazil ABNT2)\n    { 0x11c, 108 }, //   VK_RETURN            KPEN\n    { 0x11d, 109 }, //   VK_RCONTROL          RCTL\n    { 0x120, 141 }, //   VK_VOLUME_MUTE       MUTE\n    { 0x12e, 142 }, //   VK_VOLUME_DOWN       VOL-\n    { 0x130, 143 }, //   VK_VOLUME_UP         VOL+\n    { 0x135, 112 }, //   VK_DIVIDE            KPDV\n    { 0x137, 121 }, //   VK_SNAPSHOT          PRSC\n    { 0x138, 113 }, //   VK_RMENU             RALT\n    { 0x147, 97 },  //   VK_HOME              HOME\n    { 0x148, 98 },  //   VK_UP                UP\n    { 0x149, 99 },  //   VK_PRIOR             PGUP (KEY_COMPUTER)\n    { 0x14b, 100 }, //   VK_LEFT              LEFT\n    { 0x14d, 102 }, //   VK_RIGHT             RGHT\n    { 0x14f, 103 }, //   VK_END               END\n    { 0x150, 104 }, //   VK_DOWN              DOWN\n    { 0x151, 105 }, //   VK_NEXT              PGDN\n    { 0x152, 106 }, //   VK_INSERT            INS\n    { 0x153, 107 }, //   VK_DELETE            DELE\n    { 0x15b, 115 }, //   VK_LWIN              LWIN\n    { 0x15c, 116 }, //   VK_RWIN              RWIN\n    { 0x15d, 117 }, //   VK_APPS              COMP\n    { 0x21d, 110 }  //   VK_PAUSE             PAUS (KEY_PAUSE)\n};\n\nstruct map_settings\n{\n    const struct scancode_to_keycode *map;\n    const char *name;\n    unsigned int size;\n};\n\nenum settings_index\n{\n    SI_EVDEV = 0,\n    SI_BASE\n};\n\nconst struct map_settings global_settings[] =\n{\n    {\n        // SI_EVDEV\n        .map = evdev_scancode_to_keycode_map,\n        .name = \"evdev\",\n        .size = ELEMENTS(evdev_scancode_to_keycode_map),\n    },\n    {\n        // SI_BASE\n        .map = base_scancode_to_keycode_map,\n        .name = \"base\",\n        .size = ELEMENTS(base_scancode_to_keycode_map)\n    }\n};\n\n// Default mapping set is \"evdev\"\nconst struct map_settings *settings = &global_settings[SI_EVDEV];\n\n/*****************************************************************************/\nint\nscancode_to_index(unsigned short scancode)\n{\n    if (scancode <= 0x7f)\n    {\n        return scancode;\n    }\n    if (scancode <= 0xff)\n    {\n        // 0x80 - 0xff : Invalid code\n        return -1;\n    }\n    if (scancode <= 0x177)\n    {\n        // 01x100 - 0x177 : Move bit 9 to bit 8\n        return (scancode & 0x7f) | 0x80;\n    }\n\n    if (scancode == SCANCODE_PAUSE_KEY)\n    {\n        return SCANCODE_INDEX_PAUSE_KEY;\n    }\n\n    // This leaves the following which are all rejected\n    // 0x178 - 0x17f (currently unused). These would map to indexes 0xf8\n    //               to 0xff which we are reserving for extended1 keys.\n    // 0x180 - 0x1ff Illegal format\n    // >0x200        Anything not mentioned explicitly above (e.g.\n    //               SCANCODE_PAUSE_KEY)\n    return -1;\n}\n\n/*****************************************************************************/\nunsigned short\nscancode_from_index(int index)\n{\n    unsigned short result = index & 0xff;\n\n    if (result == SCANCODE_INDEX_PAUSE_KEY)\n    {\n        result = SCANCODE_PAUSE_KEY;\n    }\n    else if ((result & 0x80) != 0)\n    {\n        result ^= 0x180; // Clear bit 7, set bit 8\n    }\n    return result;\n}\n\n/*****************************************************************************/\nunsigned short\nscancode_to_x11_keycode(unsigned short scancode)\n{\n    unsigned int min = 0;\n    unsigned int max = settings->size;\n    unsigned short rv = 0;\n\n    // Check scancode is in range of map\n    if (scancode >= settings->map[min].scancode &&\n            scancode <= settings->map[max - 1].scancode)\n    {\n        // Use a binary chop to locate the correct index\n        // in logarithmic time.\n        while (1)\n        {\n            unsigned int index = (min + max) / 2;\n            if (scancode == settings->map[index].scancode)\n            {\n                rv = settings->map[index].keycode;\n                break;\n            }\n            // Adjust min or max, checking for end\n            // of iteration\n            if (scancode < settings->map[index].scancode)\n            {\n                max = index;\n            }\n            else if (min == index)\n            {\n                // We've already checked this value\n                break;\n            }\n            else\n            {\n                min = index;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nunsigned short\nscancode_get_next(unsigned int *iter)\n{\n    unsigned short rv = 0;\n    if (*iter < settings->size)\n    {\n        rv = settings->map[*iter].scancode;\n        ++(*iter);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nscancode_set_keycode_set(const char *kk_set)\n{\n    int rv = 0;\n\n    if (kk_set == NULL)\n    {\n        rv = 1;\n    }\n    else if (strncmp(kk_set, \"evdev\", 5) == 0)\n    {\n        settings = &global_settings[SI_EVDEV];\n    }\n    else if (strncmp(kk_set, \"base\", 4) == 0)\n    {\n        settings = &global_settings[SI_BASE];\n    }\n    else if (strncmp(kk_set, \"xfree86\", 7) == 0)\n    {\n        settings = &global_settings[SI_BASE];\n    }\n    else\n    {\n        rv = 1;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nconst char *\nscancode_get_keycode_set(void)\n{\n    return settings->name;\n}\n\n/*****************************************************************************/\nconst char *\nscancode_get_xkb_rules(void)\n{\n    // Currently supported keycods map directly to the same name for\n    // the rules which use them.\n    return settings->name;\n}\n"
  },
  {
    "path": "common/scancode.h",
    "content": "/**\n * Copyright (C) 2024 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    common/scancode.h\n * @brief   Scancode handling\n *\n * This module provides functionality for the following:-\n * 1) Mapping from TS_KEYBOARD_EVENT PDU values to an 'RDP scancode'\n * 2) Handling RDP scancodes\n * 3) Convert between RDP scancodes and X11 keycodes.\n *\n * The values received in TS_KEYBOARD_EVENT PDUs are largely the same as\n * Windows scancodes. These are indirectly documented in the Microsoft\n * \"Keyboard Scan Code Specification\", Rev 1.3a (March 16th 2000) and\n * are otherwise known as \"Scan code set 1\" scancodes. This document no\n * longer appears to be available directly from the Microsoft website.\n *\n * A TS_KEYBOARD_EVENT_PDU contains two important values:-\n * 1) key_code       This is not unique. For example, left-shift and\n *                   right-shift share a key_code of 0x2a\n * 2) keyboard_flags Among other flags, contains KBDFLAGS_EXTENDED and\n *                   KBDFLAGS_EXTENDED1. These combine with the key_code\n *                   to allow a specific key to be determined.\n *\n * An 'RDP scancode' as defined by this module is a mapping of the\n * Windows key_code and keyboard_flags into a single value which\n * represents a unique key. For example:-\n * Left control  : key_code=0x1d, KBDFLAGS_EXTENDED=0 scancode = 0x1d\n * Right control : key_code=0x1d, KBDFLAGS_EXTENDED=1 scancode = 0x11d\n *\n * This model of unique keys more closely maps what X11 does with its\n * own keycodes.\n *\n * X11 keycodes are the X11 equivalent of RDP scancodes. In general, these\n * are specific to an X server. In practice however, these are nowadays\n * handled by the XKB extension and only two sets are in common use:-\n * - evdev : Linux, FreeBSD and possibly others\n * - base  : Everything else.\n *\n * This module presents a single source of truth for conversions between\n * RDP scancodes and X11 keycodes.\n */\n\n#if !defined(SCANCODE_H)\n#define SCANCODE_H\n\n#include \"xrdp_scancode_defs.h\"\n\nenum\n{\n    /**\n     * Scancodes for keys used in the code are defined in the global\n     * file xrdp_scancode_defs.h\n     */\n\n    /**\n     * Scancode indexes for some of the keys in xrdp_scancode_defs.h\n     */\n    SCANCODE_INDEX_LSHIFT_KEY = SCANCODE_LSHIFT_KEY,\n    SCANCODE_INDEX_RSHIFT_KEY = SCANCODE_RSHIFT_KEY,\n    SCANCODE_INDEX_RALT_KEY = (SCANCODE_RALT_KEY & 0x7f) | 0x80,\n    SCANCODE_INDEX_PAUSE_KEY = 0xf8,\n    // 0xf9 - 0xff reserved for future extended1 mappings\n\n    /**\n     * Maximum value returned by scancode_to_index()\n     */\n    SCANCODE_MAX_INDEX = 255\n};\n\n/**\n * Convert a scancode to an index\n * @param scancode scancode in the range 0x00 - 0x2ff\n * @return index in the range 0..SCANCODE_MAX_INDEX (inclusive) or -1\n *\n * This function converts a 10-bit scancode into an 8-bit array index,\n * independent of the currently loaded keymap\n *\n * This is possible as the scancodes from 0x80 - 0x2ff are sparsely allocated.\n *\n * For scancodes in the range 0x00 - 0x7f, the index is identical to the\n * scancode. This includes scancodes for all the keys affected by\n * numlock.\n */\nint\nscancode_to_index(unsigned short scancode);\n\n/**\n * Convert an index back to a scancode.\n * @param index in the range 0..SCANCODE_MAX_INDEX\n *\n * @result scancode which is mapped to the index value\n *\n * The result is always a valid scancode, even if the index is\n * not valid.\n */\nunsigned short\nscancode_from_index(int index);\n\n/**\n * Looks up an RDP scancode and converts to an x11 keycode\n *\n * @param scancode Scancode. Extended scancodes have bit 9 set\n *                 (i.e. are in 0x100 - 0x1ff). Extended1 scancodes\n *                 (currently just the pause key) are in the range 0x200-0x2ff\n *  @return keycode, or 0 for no keycode\n */\nunsigned short\nscancode_to_x11_keycode(unsigned short scancode);\n\n/**\n * Gets the next valid scancode from the list of valid scancodes\n * @param iter Value (initialised to zero), used to iterate\n *             over available scancodes.\n * @return Next valid scancode, or zero.\n *\n * The iterator is updated on a successful call. Use like this:-\n *\n * iter = 0;\n * while ((scancode = scancode_get_next(&iter)) != 0)\n * {\n *     . . .\n * }\n */\nunsigned short\nscancode_get_next(unsigned int *iter);\n\n/**\n * Sets the keycode set used for the scancode translation\n *\n * @param kk_set \"evdev\", \"base\", or something more\n *        complex (e.g. \"evdev+aliases(qwerty)\")\n * @result 0 for success\n */\nint\nscancode_set_keycode_set(const char *kk_set);\n\n/**\n * Gets the keycode set used for the scancode translation\n *\n * @result \"evdev\", or \"base\"\n */\nconst char *\nscancode_get_keycode_set(void);\n\n/**\n * Gets the XKB rules set which can be used to access the currently\n * loaded keycode set\n *\n * @result \"evdev\", or \"base\"\n */\nconst char *\nscancode_get_xkb_rules(void);\n\n#endif /* SCANCODE_H */\n"
  },
  {
    "path": "common/set_int.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2021\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file common/set_int.c\n * @brief Handle a set of integer values (definitions)\n  */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stddef.h>\n\n#include \"arch.h\"\n#include \"set_int.h\"\n#include \"log.h\"\n\n// Type to use for the bitmap in the set. This should be an\n// optimum type for the platform, to improve search performance for\n// sparse sets. The type must be unsigned for defined behaviour on\n// right-shift.\ntypedef unsigned int word_type;\n#define BITS_PER_WORD (sizeof(word_type) * 8)\n\nstruct set_int\n{\n    int min;\n    int max;\n    size_t word_count;\n#ifdef __cplusplus\n    word_type bits[1];\n#else\n    word_type bits[];\n#endif\n};\n\n/*****************************************************************************/\nstruct set_int *\nset_int_init(int min, int max)\n{\n    struct set_int *result = NULL;\n    if (max < min)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Tried to create a set with max(%d) < min(%d)\",\n            max, min);\n    }\n    else\n    {\n        // Calculate the number of words needed for the bits;\n        size_t word_count = (max - min) / BITS_PER_WORD + 1;\n\n        result = (struct set_int *)malloc(\n                     offsetof(struct set_int, bits) +\n                     word_count * sizeof(word_type));\n        if (result == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Out of memory constructing a set(%d, %d)\",\n                min, max);\n        }\n        else\n        {\n            result->min = min;\n            result->max = max;\n            result->word_count = word_count;\n            set_int_remove_all(result);\n        }\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nvoid\nset_int_delete(struct set_int *set)\n{\n    free(set);\n}\n\n/*****************************************************************************/\nvoid\nset_int_add(struct set_int *set, int val)\n{\n    if (set != NULL && val >= set->min && val <= set->max)\n    {\n        size_t index = (val - set->min) / BITS_PER_WORD;\n        unsigned int bit = (val - set->min) % BITS_PER_WORD;\n        set->bits[index] |= 1 << bit;\n    }\n}\n\n/*****************************************************************************/\nvoid\nset_int_remove(struct set_int *set, int val)\n{\n    if (set != NULL && val >= set->min && val <= set->max)\n    {\n        size_t index = (val - set->min) / BITS_PER_WORD;\n        unsigned int bit = (val - set->min) % BITS_PER_WORD;\n        set->bits[index] &= ~(1 << bit);\n    }\n}\n\n/*****************************************************************************/\nint\nset_int_contains(const struct set_int *set, int val)\n{\n    int result = 0;\n    if (set != NULL && val >= set->min && val <= set->max)\n    {\n        size_t index = (val - set->min) / BITS_PER_WORD;\n        unsigned int bit = (val - set->min) % BITS_PER_WORD;\n        result = (set->bits[index] >> bit) & 1;\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nvoid\nset_int_add_all(struct set_int *set)\n{\n    if (set != NULL)\n    {\n        memset(set->bits, 0xff, set->word_count * sizeof(set->bits[0]));\n    }\n}\n\n/*****************************************************************************/\nvoid\nset_int_remove_all(struct set_int *set)\n{\n    if (set != NULL)\n    {\n        memset(set->bits, 0, set->word_count * sizeof(set->bits[0]));\n    }\n}\n\n/*****************************************************************************/\nint\nset_int_get_next(const struct set_int *set, int *val)\n{\n    // Sanity checks\n    if (set == NULL || *val >= set->max)\n    {\n        return 0;\n    }\n\n    // Work out the next likely value\n    int next = (*val < set->min) ? set->min : (*val) + 1;\n\n    // Convert that to an index and bit\n    size_t index = (next - set->min) / BITS_PER_WORD;\n    unsigned int bit = (next - set->min) % BITS_PER_WORD;\n\n    // Any bits left in the current word?\n    word_type w = set->bits[index] >> bit;\n    if (w == 0)\n    {\n        // Look for the next word with set bits\n        do\n        {\n            ++index;\n            if (index >= set->word_count)\n            {\n                return 0;\n            }\n        }\n        while (set->bits[index] == 0);\n\n        w = set->bits[index];\n        bit = 0;\n    }\n\n    // If we get here, w is guaranteed to have at least one set bit\n    while ((w & 1) == 0)\n    {\n        w = w >> 1;\n        ++bit;\n    }\n\n    // Now the index and bit are pointing to the\n    // next set bit in the bitmap\n    next = index * BITS_PER_WORD + bit + set->min; // Turn back into a value\n    int result = (next <= set->max); // Must be in range.\n    if (result)\n    {\n        *val = next;\n    }\n    return result;;\n}\n"
  },
  {
    "path": "common/set_int.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2021\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file common/set_int.h\n * @brief Handle a set of integer values (declarations)\n  */\n\n#ifndef SET_INT_H\n#define SET_INT_H\n\n#include \"arch.h\"\n\nstruct set_int;\n\n/**\n * Construct a set capable of holding integer values\n *\n * At most one copy of each vlue will be held in the set\n *\n * @param min Lowest value which will be added to the set\n * @param max highest value which will be added to the set\n *\n * @return new set\n *\n * NULL is returned for no memory, or if min > max\n *\n * The set is initially empty\n */\nstruct set_int *\nset_int_init(int min, int max);\n\n/**\n * Destroy a set\n *\n * @param set set to destroy\n */\nvoid\nset_int_delete(struct set_int *set);\n\n/**\n * Adds a value to a set\n *\n * @param set set\n * @param val value to add\n *\n * values outside of the initial max..max range will be silently ignored\n */\nvoid\nset_int_add(struct set_int *set, int val);\n\n\n/**\n * Removes a value from a set\n *\n * @param set set\n * @param val value to remove\n *\n * It is not an error to remove a value which isn't in the set\n */\nvoid\nset_int_remove(struct set_int *set, int val);\n\n\n/**\n * Tests whether a set contains a particular value\n *\n * @param set set\n * @param val value to test\n *\n * @return != 0 if the value is in the set\n */\nint\nset_int_contains(const struct set_int *set, int val);\n\n/**\n * Adds all values in the range min..max to a set\n *\n * @param set set\n */\nvoid\nset_int_add_all(struct set_int *set);\n\n/**\n * Removes all values in the range min..max from a set\n *\n * @param set set\n */\nvoid\nset_int_remove_all(struct set_int *set);\n\n/**\n * Gets the next value from a set\n *\n * @param set set\n * @param[in,out] val Value to search from\n * @return != 0 if another value was found\n *\n * On success, the val parameter is replaced with the next highest\n * value from the set.\n */\nint\nset_int_get_next(const struct set_int *set, int *val);\n\n#endif // SET_INT_H\n"
  },
  {
    "path": "common/ssl_calls.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n * Copyright (C) Idan Freiberg 2013-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * ssl calls\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h> /* needed for openssl headers */\n#include <openssl/ssl.h>\n#include <openssl/err.h>\n#include <openssl/rc4.h>\n#include <openssl/md5.h>\n#include <openssl/sha.h>\n#include <openssl/hmac.h>\n#include <openssl/bn.h>\n#include <openssl/rsa.h>\n#include <openssl/dh.h>\n#include <openssl/crypto.h>\n\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"arch.h\"\n#include \"ssl_calls.h\"\n#include \"trans.h\"\n#include \"log.h\"\n\n#define SSL_WANT_READ_WRITE_TIMEOUT 100\n\n/*\n * Globals used by openssl 3 and later */\n#if OPENSSL_VERSION_NUMBER >= 0x30000000L\nstatic EVP_MD *g_md_md5;    /* MD5 message digest */\nstatic EVP_MD *g_md_sha1;   /* SHA1 message digest */\nstatic EVP_CIPHER *g_cipher_des_ede3_cbc; /* DES3 CBC cipher */\nstatic EVP_MAC *g_mac_hmac; /* HMAC MAC */\n#endif\n\n#if OPENSSL_VERSION_NUMBER >= 0x10101000L\n#define HAS_KEYLOG_CALLBACK /* SSL_CTX_set_keylog_callback() is available */\nstatic char *g_keylog_filename = NULL;\n#endif\n\n/* definition of ssl_tls */\nstruct ssl_tls\n{\n    SSL *ssl; /* SSL * */\n    SSL_CTX *ctx; /* SSL_CTX * */\n    char *cert;\n    char *key;\n    struct trans *trans;\n    tintptr rwo; /* wait obj */\n    int error_logged; /* Error has already been logged */\n};\n\n#if OPENSSL_VERSION_NUMBER < 0x10100000L\nstatic inline HMAC_CTX *\nHMAC_CTX_new(void)\n{\n    HMAC_CTX *hmac_ctx = g_new(HMAC_CTX, 1);\n    HMAC_CTX_init(hmac_ctx);\n    return hmac_ctx;\n}\n\nstatic inline void\nHMAC_CTX_free(HMAC_CTX *hmac_ctx)\n{\n    HMAC_CTX_cleanup(hmac_ctx);\n    g_free(hmac_ctx);\n}\n\nstatic inline void\nRSA_get0_key(const RSA *key, const BIGNUM **n, const BIGNUM **e,\n             const BIGNUM **d)\n{\n    *n = key->n;\n    *d = key->d;\n}\n\nstatic inline int\nDH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)\n{\n    /* If the fields p and g in d are NULL, the corresponding input\n     * parameters MUST be non-NULL.  q may remain NULL.\n     */\n    if ((dh->p == NULL && p == NULL)\n            || (dh->g == NULL && g == NULL))\n    {\n        return 0;\n    }\n\n    if (p != NULL)\n    {\n        BN_free(dh->p);\n        dh->p = p;\n    }\n    if (q != NULL)\n    {\n        BN_free(dh->q);\n        dh->q = q;\n    }\n    if (g != NULL)\n    {\n        BN_free(dh->g);\n        dh->g = g;\n    }\n\n    if (q != NULL)\n    {\n        dh->length = BN_num_bits(q);\n    }\n\n    return 1;\n}\n#endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */\n\n\n\n/*****************************************************************************/\nstatic void\ndump_error_stack(const char *prefix)\n{\n    /* Dump the error stack from the SSL library */\n    unsigned long code;\n    char buff[256];\n    while ((code = ERR_get_error()) != 0L)\n    {\n        ERR_error_string_n(code, buff, sizeof(buff));\n        LOG(LOG_LEVEL_ERROR, \"%s: %s\", prefix, buff);\n    }\n}\n\n/*****************************************************************************/\n/* As above, but used for TLS connection errors where only the first\n   error is logged */\nstatic void\ndump_ssl_error_stack(struct ssl_tls *self)\n{\n    if (!self->error_logged)\n    {\n        dump_error_stack(\"SSL\");\n        self->error_logged = 1;\n    }\n}\n\n/*****************************************************************************/\nint\nssl_init(void)\n{\n    SSL_load_error_strings();\n    SSL_library_init();\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nssl_finish(void)\n{\n#if OPENSSL_VERSION_NUMBER >= 0x30000000L\n    /* De-allocate any allocated globals\n     * For OpenSSL 3, these can all safely be passed a NULL pointer */\n    EVP_MD_free(g_md_md5);\n    g_md_md5 = NULL;\n    EVP_MD_free(g_md_sha1);\n    g_md_sha1 = NULL;\n    EVP_CIPHER_free(g_cipher_des_ede3_cbc);\n    g_cipher_des_ede3_cbc = NULL;\n    EVP_MAC_free(g_mac_hmac);\n    g_mac_hmac = NULL;\n#endif\n\n#ifdef HAS_KEYLOG_CALLBACK\n    free(g_keylog_filename);\n    g_keylog_filename = NULL;\n#endif\n    return 0;\n}\n\n/*****************************************************************************/\nint\nssl_set_pre_master_secret_logfile(const char *filename)\n{\n    int rv = 0;\n#ifdef HAS_KEYLOG_CALLBACK\n    int fd = -1;\n\n    /* Remove any existing setting */\n    free(g_keylog_filename);\n    g_keylog_filename = NULL;\n\n    if (filename == NULL || filename[0] == '\\0')\n    {\n        /* all done */\n    }\n    else if (filename[0] != '/')\n    {\n        LOG(LOG_LEVEL_ERROR, \"TLS pre-master log file must start with '/'\");\n    }\n    else if ((fd = g_file_open_rw(filename)) < 0)\n    {\n        /* Can't open file for writing. We'll log a single error here\n         * rather than lots of errors in the callback */\n        LOG(LOG_LEVEL_ERROR, \"Can't write TLS pre-master secrets to %s [%s]\",\n            filename, g_get_strerror());\n    }\n    else if (g_file_close(fd) != 0)\n    {\n        /* Ignore this one */\n    }\n    else if (g_chmod_hex(filename, 0x640) != 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Can't set expected permissions on %s [%s]\",\n            filename, g_get_strerror());\n\n    }\n    else if ((g_keylog_filename = g_strdup(filename)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Out of memory setting TLS pre-master log\");\n    }\n    else\n    {\n        rv = 1;\n    }\n#else\n    LOG(LOG_LEVEL_WARNING,\n        \"This system is unable to log TLS pre-master secrets\");\n#endif\n    return rv;\n}\n\n/*****************************************************************************/\n/* Log the pre-master secret for debugging purposes */\n#ifdef HAS_KEYLOG_CALLBACK\nstatic void\nlog_pre_master_secret(const SSL *ssl, const char *line)\n{\n    if (g_keylog_filename != NULL && g_keylog_filename[0] == '/')\n    {\n        int fd = g_file_open_rw(g_keylog_filename);\n        if (fd < 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't write pre-master secret to %s [ %s]\",\n                g_keylog_filename, g_get_strerror());\n        }\n        else\n        {\n            g_file_seek_end(fd, 0);\n            g_file_write(fd, line, strlen(line));\n            g_file_write(fd, \"\\n\", 1);\n            (void)g_file_close(fd);\n        }\n    }\n}\n#endif // HAS_KEYLOG_CALLBACK\n\n/*****************************************************************************/\n\n/* rc4 stuff\n *\n * For OpenSSL 3.0, the rc4 encryption algorithm is only provided by the\n * legacy provider (see crypto(7)). Since RC4 is so simple, we can implement\n * it directly rather than having to load the legacy provider.  This will\n * avoids problems if running on a system where openssl has been built\n * without the legacy provider */\n\n#if OPENSSL_VERSION_NUMBER >= 0x30000000L\nstruct rc4_data\n{\n    /* See https://en.wikipedia.org/wiki/RC4 */\n    unsigned char S[256];\n    int i;\n    int j;\n};\n#endif\n\n/*****************************************************************************/\nvoid *\nssl_rc4_info_create(void)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    return g_malloc(sizeof(RC4_KEY), 1);\n#else\n    return g_malloc(sizeof(struct rc4_data), 1);\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_rc4_info_delete(void *rc4_info)\n{\n    g_free(rc4_info);\n}\n\n/*****************************************************************************/\nvoid\nssl_rc4_set_key(void *rc4_info, const char *key, int len)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    RC4_set_key((RC4_KEY *)rc4_info, len, (tui8 *)key);\n#else\n    unsigned char *S = ((struct rc4_data *)rc4_info)->S;\n    int i;\n    int j = 0;\n    unsigned char t;\n    for (i = 0 ; i < 256; ++i)\n    {\n        S[i] = i;\n    }\n    for (i = 0 ; i < 256; ++i)\n    {\n        j = (j + S[i] + key[i % len]) & 0xff;\n        t = S[i];\n        S[i] = S[j];\n        S[j] = t;\n    }\n    ((struct rc4_data *)rc4_info)->i = 0;\n    ((struct rc4_data *)rc4_info)->j = 0;\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_rc4_crypt(void *rc4_info, char *data, int len)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    RC4((RC4_KEY *)rc4_info, len, (tui8 *)data, (tui8 *)data);\n#else\n    unsigned char *S = ((struct rc4_data *)rc4_info)->S;\n    int i = ((struct rc4_data *)rc4_info)->i;\n    int j = ((struct rc4_data *)rc4_info)->j;\n    unsigned char *p = (unsigned char *)data;\n    unsigned char t;\n    unsigned char k;\n\n    /*\n     * Do some loop-unrolling for performance. Here are the steps\n     * for each byte */\n#define RC4_ROUND \\\n    i = (i + 1) & 0xff; \\\n    j = (j + S[i]) & 0xff; \\\n    t = S[i]; \\\n    S[i] = S[j]; \\\n    S[j] = t; \\\n    k = S[(S[i] + S[j]) & 0xff]; \\\n    *p++ ^= k\n\n    while (len >= 8)\n    {\n        RC4_ROUND;\n        RC4_ROUND;\n        RC4_ROUND;\n        RC4_ROUND;\n        RC4_ROUND;\n        RC4_ROUND;\n        RC4_ROUND;\n        RC4_ROUND;\n        len -= 8;\n    }\n    while (len-- > 0)\n    {\n        RC4_ROUND;\n    }\n\n    ((struct rc4_data *)rc4_info)->i = i;\n    ((struct rc4_data *)rc4_info)->j = j;\n#endif\n}\n\n/* sha1 stuff */\n\n/*****************************************************************************/\nvoid *\nssl_sha1_info_create(void)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    return g_malloc(sizeof(SHA_CTX), 1);\n#else\n    /*\n     * If we can't get the digest loaded, there's a problem with the\n     * library providers, so there's no point in us returning anything useful.\n     * If we do load the digest, it's used later */\n    if (g_md_sha1 == NULL)\n    {\n        if ((g_md_sha1 = EVP_MD_fetch(NULL, \"sha1\", NULL)) == NULL)\n        {\n            dump_error_stack(\"sha1\");\n            return NULL;\n        }\n    }\n\n    return (void *)EVP_MD_CTX_new();\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_sha1_info_delete(void *sha1_info)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    g_free(sha1_info);\n#else\n    EVP_MD_CTX_free((EVP_MD_CTX *)sha1_info);\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_sha1_clear(void *sha1_info)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    SHA1_Init((SHA_CTX *)sha1_info);\n#else\n    if (sha1_info != NULL)\n    {\n        EVP_DigestInit_ex((EVP_MD_CTX *)sha1_info, g_md_sha1, NULL);\n    }\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_sha1_transform(void *sha1_info, const char *data, int len)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    SHA1_Update((SHA_CTX *)sha1_info, data, len);\n#else\n    if (sha1_info != NULL)\n    {\n        EVP_DigestUpdate((EVP_MD_CTX *)sha1_info, data, len);\n    }\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_sha1_complete(void *sha1_info, char *data)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    SHA1_Final((tui8 *)data, (SHA_CTX *)sha1_info);\n#else\n    if (sha1_info != NULL)\n    {\n        EVP_DigestFinal_ex((EVP_MD_CTX *)sha1_info, (unsigned char *)data,\n                           NULL);\n    }\n#endif\n}\n\n/* md5 stuff */\n\n/*****************************************************************************/\nvoid *\nssl_md5_info_create(void)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    return g_malloc(sizeof(MD5_CTX), 1);\n#else\n    /*\n     * If we can't get the digest loaded, there's a problem with the\n     * library providers, so there's no point in us returning anything useful.\n     * If we do load the digest, it's used later */\n    if (g_md_md5 == NULL)\n    {\n        if ((g_md_md5 = EVP_MD_fetch(NULL, \"md5\", NULL)) == NULL)\n        {\n            dump_error_stack(\"md5\");\n            return NULL;\n        }\n    }\n\n    return (void *)EVP_MD_CTX_new();\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_md5_info_delete(void *md5_info)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    g_free(md5_info);\n#else\n    EVP_MD_CTX_free((EVP_MD_CTX *)md5_info);\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_md5_clear(void *md5_info)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    MD5_Init((MD5_CTX *)md5_info);\n#else\n    if (md5_info != NULL)\n    {\n        EVP_DigestInit_ex((EVP_MD_CTX *)md5_info, g_md_md5, NULL);\n    }\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_md5_transform(void *md5_info, const char *data, int len)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    MD5_Update((MD5_CTX *)md5_info, data, len);\n#else\n    if (md5_info != NULL)\n    {\n        EVP_DigestUpdate((EVP_MD_CTX *)md5_info, data, len);\n    }\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_md5_complete(void *md5_info, char *data)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    MD5_Final((tui8 *)data, (MD5_CTX *)md5_info);\n#else\n    if (md5_info != NULL)\n    {\n        EVP_DigestFinal_ex((EVP_MD_CTX *)md5_info, (unsigned char *)data, NULL);\n    }\n#endif\n}\n\n/* FIPS stuff */\n\n/*****************************************************************************/\nvoid *\nssl_des3_encrypt_info_create(const char *key, const char *ivec)\n{\n    EVP_CIPHER_CTX *des3_ctx;\n    const tui8 *lkey;\n    const tui8 *livec;\n\n#if OPENSSL_VERSION_NUMBER >= 0x30000000L\n    /*\n     * For these versions of OpenSSL, there are no long-term guarantees the\n     * DES3 cipher will be available. We'll try to load it here so we\n     * can log any errors */\n    if (g_cipher_des_ede3_cbc == NULL)\n    {\n        g_cipher_des_ede3_cbc = EVP_CIPHER_fetch(NULL, \"des-ede3-cbc\", NULL);\n        if (g_cipher_des_ede3_cbc == NULL)\n        {\n            dump_error_stack(\"DES-EDE3-CBC\");\n            return NULL;\n        }\n    }\n#endif\n\n    des3_ctx = EVP_CIPHER_CTX_new();\n    lkey = (const tui8 *) key;\n    livec = (const tui8 *) ivec;\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    EVP_EncryptInit_ex(des3_ctx, EVP_des_ede3_cbc(), NULL, lkey, livec);\n#else\n    EVP_EncryptInit_ex(des3_ctx, g_cipher_des_ede3_cbc, NULL, lkey, livec);\n#endif\n    EVP_CIPHER_CTX_set_padding(des3_ctx, 0);\n    return des3_ctx;\n}\n\n/*****************************************************************************/\nvoid *\nssl_des3_decrypt_info_create(const char *key, const char *ivec)\n{\n    EVP_CIPHER_CTX *des3_ctx;\n    const tui8 *lkey;\n    const tui8 *livec;\n\n#if OPENSSL_VERSION_NUMBER >= 0x30000000L\n    /*\n     * For these versions of OpenSSL, there are no long-term guarantees the\n     * DES3 cipher will be available. We'll try to load it here so we\n     * can log any errors */\n    if (g_cipher_des_ede3_cbc == NULL)\n    {\n        g_cipher_des_ede3_cbc = EVP_CIPHER_fetch(NULL, \"des-ede3-cbc\", NULL);\n        if (g_cipher_des_ede3_cbc == NULL)\n        {\n            dump_error_stack(\"DES-EDE3-CBC\");\n            return NULL;\n        }\n    }\n#endif\n\n    des3_ctx = EVP_CIPHER_CTX_new();\n    lkey = (const tui8 *) key;\n    livec = (const tui8 *) ivec;\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    EVP_DecryptInit_ex(des3_ctx, EVP_des_ede3_cbc(), NULL, lkey, livec);\n#else\n    EVP_DecryptInit_ex(des3_ctx, g_cipher_des_ede3_cbc, NULL, lkey, livec);\n#endif\n    EVP_CIPHER_CTX_set_padding(des3_ctx, 0);\n    return des3_ctx;\n}\n\n/*****************************************************************************/\nvoid\nssl_des3_info_delete(void *des3)\n{\n    EVP_CIPHER_CTX *des3_ctx;\n\n    des3_ctx = (EVP_CIPHER_CTX *) des3;\n    if (des3_ctx != 0)\n    {\n        EVP_CIPHER_CTX_free(des3_ctx);\n    }\n}\n\n/*****************************************************************************/\nint\nssl_des3_encrypt(void *des3, int length, const char *in_data, char *out_data)\n{\n    EVP_CIPHER_CTX *des3_ctx;\n    int len;\n    const tui8 *lin_data;\n    tui8 *lout_data;\n\n    des3_ctx = (EVP_CIPHER_CTX *) des3;\n    if (des3_ctx != NULL)\n    {\n        lin_data = (const tui8 *) in_data;\n        lout_data = (tui8 *) out_data;\n        len = 0;\n        EVP_EncryptUpdate(des3_ctx, lout_data, &len, lin_data, length);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nssl_des3_decrypt(void *des3, int length, const char *in_data, char *out_data)\n{\n    EVP_CIPHER_CTX *des3_ctx;\n    int len;\n    const tui8 *lin_data;\n    tui8 *lout_data;\n\n    des3_ctx = (EVP_CIPHER_CTX *) des3;\n    if (des3_ctx != NULL)\n    {\n        lin_data = (const tui8 *) in_data;\n        lout_data = (tui8 *) out_data;\n        len = 0;\n        EVP_DecryptUpdate(des3_ctx, lout_data, &len, lin_data, length);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nvoid *\nssl_hmac_info_create(void)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    return (HMAC_CTX *)HMAC_CTX_new();\n#else\n    /* Need a MAC algorithm loaded */\n    if (g_mac_hmac == NULL)\n    {\n        if ((g_mac_hmac = EVP_MAC_fetch(NULL, \"hmac\", NULL)) == NULL)\n        {\n            dump_error_stack(\"hmac\");\n            return NULL;\n        }\n    }\n\n    return (void *)EVP_MAC_CTX_new(g_mac_hmac);\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_hmac_info_delete(void *hmac)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    HMAC_CTX *hmac_ctx;\n\n    hmac_ctx = (HMAC_CTX *) hmac;\n    if (hmac_ctx != 0)\n    {\n        HMAC_CTX_free(hmac_ctx);\n    }\n#else\n    EVP_MAC_CTX_free((EVP_MAC_CTX *)hmac);\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_hmac_sha1_init(void *hmac, const char *data, int len)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    HMAC_CTX *hmac_ctx;\n\n    hmac_ctx = (HMAC_CTX *) hmac;\n    HMAC_Init_ex(hmac_ctx, data, len, EVP_sha1(), NULL);\n#else\n    if (hmac != NULL)\n    {\n        char digest[] = \"sha1\";\n        OSSL_PARAM params[3];\n        size_t n = 0;\n        params[n++] = OSSL_PARAM_construct_utf8_string(\"digest\", digest, 0);\n        params[n++] = OSSL_PARAM_construct_end();\n        if (EVP_MAC_init((EVP_MAC_CTX *)hmac, (unsigned char *)data,\n                         len, params) == 0)\n        {\n            dump_error_stack(\"hmac-sha1\");\n        }\n    }\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_hmac_transform(void *hmac, const char *data, int len)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    HMAC_CTX *hmac_ctx;\n    const tui8 *ldata;\n\n    hmac_ctx = (HMAC_CTX *) hmac;\n    ldata = (const tui8 *) data;\n    HMAC_Update(hmac_ctx, ldata, len);\n#else\n    if (hmac != NULL)\n    {\n        EVP_MAC_update((EVP_MAC_CTX *)hmac, (unsigned char *)data, len);\n    }\n#endif\n}\n\n/*****************************************************************************/\nvoid\nssl_hmac_complete(void *hmac, char *data, int len)\n{\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    HMAC_CTX *hmac_ctx;\n    tui8 *ldata;\n    tui32 llen;\n\n    hmac_ctx = (HMAC_CTX *) hmac;\n    ldata = (tui8 *) data;\n    llen = len;\n    HMAC_Final(hmac_ctx, ldata, &llen);\n#else\n    if (hmac != NULL)\n    {\n        EVP_MAC_final((EVP_MAC_CTX *)hmac, (unsigned char *)data, NULL, len);\n    }\n#endif\n}\n\n/*****************************************************************************/\nstatic void\nssl_reverse_it(char *p, int len)\n{\n    int i;\n    int j;\n    char temp;\n\n    i = 0;\n    j = len - 1;\n\n    while (i < j)\n    {\n        temp = p[i];\n        p[i] = p[j];\n        p[j] = temp;\n        i++;\n        j--;\n    }\n}\n\n/*****************************************************************************/\nint\nssl_mod_exp(char *out, int out_len, const char *in, int in_len,\n            const char *mod, int mod_len, const char *exp, int exp_len)\n{\n    BN_CTX *ctx;\n    BIGNUM *lmod;\n    BIGNUM *lexp;\n    BIGNUM *lin;\n    BIGNUM *lout;\n    int rv;\n    char *l_out;\n    char *l_in;\n    char *l_mod;\n    char *l_exp;\n\n    l_out = (char *)g_malloc(out_len, 1);\n    l_in = (char *)g_malloc(in_len, 1);\n    l_mod = (char *)g_malloc(mod_len, 1);\n    l_exp = (char *)g_malloc(exp_len, 1);\n    g_memcpy(l_in, in, in_len);\n    g_memcpy(l_mod, mod, mod_len);\n    g_memcpy(l_exp, exp, exp_len);\n    ssl_reverse_it(l_in, in_len);\n    ssl_reverse_it(l_mod, mod_len);\n    ssl_reverse_it(l_exp, exp_len);\n    ctx = BN_CTX_new();\n    lmod = BN_new();\n    lexp = BN_new();\n    lin = BN_new();\n    lout = BN_new();\n    BN_bin2bn((tui8 *)l_mod, mod_len, lmod);\n    BN_bin2bn((tui8 *)l_exp, exp_len, lexp);\n    BN_bin2bn((tui8 *)l_in, in_len, lin);\n    BN_mod_exp(lout, lin, lexp, lmod, ctx);\n    rv = BN_bn2bin(lout, (tui8 *)l_out);\n\n    if (rv <= out_len)\n    {\n        ssl_reverse_it(l_out, rv);\n        g_memcpy(out, l_out, out_len);\n    }\n    else\n    {\n        rv = 0;\n    }\n\n    BN_free(lin);\n    BN_free(lout);\n    BN_free(lexp);\n    BN_free(lmod);\n    BN_CTX_free(ctx);\n    g_free(l_out);\n    g_free(l_in);\n    g_free(l_mod);\n    g_free(l_exp);\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error\n   generates a new rsa key\n   exp is passed in and mod and pri are passed out */\nint\nssl_gen_key_xrdp1(int key_size_in_bits, const char *exp, int exp_len,\n                  char *mod, int mod_len, char *pri, int pri_len)\n{\n    BIGNUM *my_e;\n    char *lexp;\n    char *lmod;\n    char *lpri;\n    int error;\n    int len;\n    int diff;\n\n    if ((exp_len != 4) || ((mod_len != 64) && (mod_len != 256)) ||\n            ((pri_len != 64) && (pri_len != 256)))\n    {\n        return 1;\n    }\n\n    diff = 0;\n    lexp = (char *)g_malloc(exp_len, 1);\n    lmod = (char *)g_malloc(mod_len, 1);\n    lpri = (char *)g_malloc(pri_len, 1);\n    g_memcpy(lexp, exp, exp_len);\n    ssl_reverse_it(lexp, exp_len);\n    my_e = BN_new();\n    BN_bin2bn((tui8 *)lexp, exp_len, my_e);\n\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    const BIGNUM *n = NULL;\n    const BIGNUM *d = NULL;\n    RSA *my_key = RSA_new();\n    error = RSA_generate_key_ex(my_key, key_size_in_bits, my_e, 0) == 0;\n\n    /* After this call, n and d point directly into my_key, and are valid\n     * until my_key is free'd */\n    RSA_get0_key(my_key, &n, NULL, &d);\n#else\n    BIGNUM *n = NULL;\n    BIGNUM *d = NULL;\n    OSSL_PARAM params[] =\n    {\n        OSSL_PARAM_construct_int(\"bits\", &key_size_in_bits),\n        OSSL_PARAM_construct_end()\n    };\n    EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_from_name(NULL, \"RSA\", NULL);\n    EVP_PKEY *pkey = NULL;\n\n    if (pctx != NULL &&\n            EVP_PKEY_keygen_init(pctx) > 0 &&\n            EVP_PKEY_CTX_set_params(pctx, params) > 0 &&\n            EVP_PKEY_generate(pctx, &pkey) > 0 &&\n            EVP_PKEY_get_bn_param(pkey, \"n\", &n) > 0 &&\n            EVP_PKEY_get_bn_param(pkey, \"d\", &d) > 0)\n    {\n        error = 0;\n    }\n    else\n    {\n        error = 1;\n    }\n\n    EVP_PKEY_CTX_free(pctx);\n    EVP_PKEY_free(pkey);\n#endif\n\n    if (error == 0)\n    {\n        len = BN_num_bytes(n);\n        error = (len < 1) || (len > mod_len);\n        diff = mod_len - len;\n    }\n\n    if (error == 0)\n    {\n        BN_bn2bin(n, (tui8 *)(lmod + diff));\n        ssl_reverse_it(lmod, mod_len);\n    }\n\n    if (error == 0)\n    {\n        len = BN_num_bytes(d);\n        error = (len < 1) || (len > pri_len);\n        diff = pri_len - len;\n    }\n\n    if (error == 0)\n    {\n        BN_bn2bin(d, (tui8 *)(lpri + diff));\n        ssl_reverse_it(lpri, pri_len);\n    }\n\n    if (error == 0)\n    {\n        g_memcpy(mod, lmod, mod_len);\n        g_memcpy(pri, lpri, pri_len);\n    }\n\n    BN_free(my_e);\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    RSA_free(my_key);\n#else\n    BN_free(n);\n    BN_clear_free(d);\n#endif\n    g_free(lexp);\n    g_free(lmod);\n    g_free(lpri);\n    return error;\n}\n\n/*****************************************************************************/\n/** static DH parameter, can be used if no custom parameter is specified\nsee also\n * https://wiki.openssl.org/index.php/Diffie-Hellman_parameters\n * https://wiki.openssl.org/index.php/Manual:SSL_CTX_set_tmp_dh_callback(3)\n *\n * We dont do this for OpenSSL 3 - we use SSL_CTX_set_dh_auto() instead, as this\n * can cater for different key sizes on the certificate\n*/\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\nstatic DH *ssl_get_dh2236()\n{\n    static unsigned char dh2236_p[] =\n    {\n        0x0E, 0xF8, 0x69, 0x0B, 0x35, 0x2F, 0x62, 0x59, 0xF7, 0xAF, 0x4E, 0x19,\n        0xB5, 0x9B, 0xD2, 0xEB, 0x33, 0x78, 0x1D, 0x43, 0x1D, 0xB6, 0xE4, 0xA3,\n        0x63, 0x47, 0x6A, 0xD4, 0xA8, 0x28, 0x11, 0x8C, 0x3F, 0xC8, 0xF1, 0x32,\n        0x2B, 0x5D, 0x9F, 0xF8, 0xA6, 0xCA, 0x21, 0x71, 0xDE, 0x30, 0xD7, 0xB5,\n        0xD6, 0xA4, 0xC2, 0xEE, 0xC0, 0x49, 0x30, 0xE7, 0x8C, 0x9B, 0x1A, 0x5A,\n        0x08, 0x2A, 0x11, 0x84, 0xE2, 0xC8, 0x36, 0x6C, 0xDC, 0x06, 0x79, 0x59,\n        0x51, 0xA4, 0xA0, 0x8F, 0xE1, 0x20, 0x94, 0x80, 0xAC, 0x6D, 0xFD, 0x3B,\n        0xA6, 0xA6, 0x70, 0x51, 0x93, 0x59, 0x28, 0x51, 0x54, 0xA3, 0xC5, 0x15,\n        0x44, 0x2C, 0x12, 0xE7, 0x95, 0x62, 0x0E, 0x65, 0x2F, 0x8C, 0x0D, 0xF8,\n        0x63, 0x52, 0x00, 0x2A, 0xA5, 0xD7, 0x59, 0xEF, 0x13, 0x18, 0x33, 0x25,\n        0xBC, 0xAD, 0xC8, 0x0A, 0x72, 0x8D, 0x26, 0x63, 0xD5, 0xB3, 0xBC, 0x43,\n        0x35, 0x0B, 0x5D, 0xC7, 0xCA, 0x45, 0x17, 0x06, 0x24, 0x71, 0xCA, 0x20,\n        0x73, 0xE8, 0x18, 0xD3, 0x8E, 0xE9, 0xE9, 0x8F, 0x67, 0xC0, 0x2C, 0x14,\n        0x7E, 0x41, 0x18, 0x6C, 0x74, 0x72, 0x56, 0x34, 0xC0, 0xDB, 0xDD, 0x85,\n        0x8B, 0xE0, 0x99, 0xE8, 0x5E, 0xC8, 0xF7, 0xD1, 0x0C, 0xF8, 0x83, 0x34,\n        0x37, 0x9E, 0x01, 0xDF, 0x1C, 0xD9, 0xE9, 0x95, 0xC1, 0x4C, 0x64, 0x37,\n        0x9B, 0xF5, 0x8F, 0x99, 0x97, 0x55, 0x68, 0x2E, 0x23, 0xB0, 0x35, 0xF3,\n        0xA5, 0x97, 0x92, 0xA0, 0x6D, 0xB4, 0xF8, 0xD8, 0x47, 0xCE, 0x3F, 0x0B,\n        0x36, 0x0E, 0xEB, 0x13, 0x15, 0xFD, 0x4F, 0x98, 0x4F, 0x14, 0x26, 0xE2,\n        0xAC, 0xD9, 0x42, 0xC6, 0x43, 0x8A, 0x95, 0x6B, 0x2B, 0x44, 0x38, 0x7F,\n        0x60, 0x97, 0x77, 0xD8, 0x7C, 0x6F, 0x5D, 0x62, 0x7C, 0xE1, 0xC8, 0x83,\n        0x12, 0x8B, 0x5E, 0x5E, 0xC7, 0x5E, 0xD5, 0x60, 0xF3, 0x2F, 0xFC, 0xFE,\n        0x70, 0xAC, 0x58, 0x3A, 0x3C, 0x18, 0x15, 0x54, 0x84, 0xA8, 0xAA, 0x41,\n        0x26, 0x7B, 0xE0, 0xA3,\n    };\n    static unsigned char dh2236_g[] =\n    {\n        0x02,\n    };\n\n    DH *dh = DH_new();\n    if (dh == NULL)\n    {\n        return NULL;\n    }\n\n    BIGNUM *p = BN_bin2bn(dh2236_p, sizeof(dh2236_p), NULL);\n    BIGNUM *g = BN_bin2bn(dh2236_g, sizeof(dh2236_g), NULL);\n    if (p == NULL || g == NULL)\n    {\n        BN_free(p);\n        BN_free(g);\n        DH_free(dh);\n        return NULL;\n    }\n\n    // p, g are freed later by DH_free()\n    if (0 == DH_set0_pqg(dh, p, NULL, g))\n    {\n        BN_free(p);\n        BN_free(g);\n        DH_free(dh);\n        return NULL;\n    }\n\n    return dh;\n}\n#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */\n\n/*****************************************************************************/\nstruct ssl_tls *\nssl_tls_create(struct trans *trans, const char *key, const char *cert)\n{\n    struct ssl_tls *self;\n    int pid;\n    char buf[1024];\n\n    self = (struct ssl_tls *) g_malloc(sizeof(struct ssl_tls), 1);\n    if (self != NULL)\n    {\n        self->trans = trans;\n        self->cert = (char *) cert;\n        self->key = (char *) key;\n        pid = g_getpid();\n        g_snprintf(buf, 1024, \"xrdp_%8.8x_tls_rwo\", pid);\n        self->rwo = g_create_wait_obj(buf);\n    }\n\n    return self;\n}\n/*****************************************************************************/\nstatic int\nssl_tls_log_error(struct ssl_tls *self, const char *func, int value)\n{\n    int result = 1;\n    int ssl_error = SSL_get_error(self->ssl, value);\n\n    if (ssl_error == SSL_ERROR_WANT_READ || ssl_error == SSL_ERROR_WANT_WRITE)\n    {\n        result = 0;\n    }\n    else if (!self->error_logged)\n    {\n        switch (ssl_error)\n        {\n            case SSL_ERROR_ZERO_RETURN:\n                LOG(LOG_LEVEL_ERROR, \"%s: Server closed TLS connection\", func);\n                break;\n\n            case SSL_ERROR_SYSCALL:\n                LOG(LOG_LEVEL_ERROR, \"%s: I/O error\", func);\n                break;\n\n            case SSL_ERROR_SSL:\n                LOG(LOG_LEVEL_ERROR, \"%s: Failure in SSL library \"\n                    \"(protocol error?)\", func);\n                break;\n\n            default:\n                LOG(LOG_LEVEL_ERROR, \"%s: Unknown SSL error\", func);\n                break;\n        }\n\n        dump_ssl_error_stack(self); /* Sets self->error_logged */\n    }\n\n    return result;\n}\n\n/**************************************************************************//**\n * Log an attempt to use an encrypted file\n *\n * For example, a private key could have a password set on it. We don't\n * support this.\n */\nstatic int\nlog_encrypted_file_unsupported(char *buf, int size, int rwflag, void *u)\n{\n    LOG(LOG_LEVEL_ERROR, \"Encryption is not supported for %s\",\n        (const char *)u);\n    return -1; /* See pem_password_cb(3ssl) */\n}\n\n/*****************************************************************************/\n\nint\nssl_tls_accept(struct ssl_tls *self, long ssl_protocols,\n               const char *tls_ciphers,\n               int (*is_term)(void))\n{\n    int connection_status;\n    long options = 0;\n\n    ERR_clear_error();\n\n    /**\n     * SSL_OP_NO_SSLv2\n     * SSLv3 is used by, eg. Microsoft RDC for Mac OS X.\n     */\n    options |= SSL_OP_NO_SSLv2;\n\n    /**\n     * Disable SSL protocols not listed in ssl_protocols.\n     */\n    options |= ssl_protocols;\n\n\n#if defined(SSL_OP_NO_COMPRESSION)\n    /**\n     * SSL_OP_NO_COMPRESSION:\n     *\n     * The Microsoft RDP server does not advertise support\n     * for TLS compression, but alternative servers may support it.\n     * This was observed between early versions of the FreeRDP server\n     * and the FreeRDP client, and caused major performance issues,\n     * which is why we're disabling it.\n     */\n    options |= SSL_OP_NO_COMPRESSION;\n#endif\n\n    /**\n     * SSL_OP_TLS_BLOCK_PADDING_BUG:\n     *\n     * The Microsoft RDP server does *not* support TLS padding.\n     * It absolutely needs to be disabled otherwise it won't work.\n     */\n    options |= SSL_OP_TLS_BLOCK_PADDING_BUG;\n\n    /**\n     * SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS:\n     *\n     * Just like TLS padding, the Microsoft RDP server does not\n     * support empty fragments. This needs to be disabled.\n     */\n    options |= SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;\n\n    self->ctx = SSL_CTX_new(SSLv23_server_method());\n    if (self->ctx == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to negotiate a TLS connection with the client\");\n        dump_ssl_error_stack(self);\n        return 1;\n    }\n\n    /* set context options */\n    SSL_CTX_set_mode(self->ctx,\n                     SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER |\n                     SSL_MODE_ENABLE_PARTIAL_WRITE);\n    SSL_CTX_set_options(self->ctx, options);\n\n    /* set DH parameters */\n#if OPENSSL_VERSION_NUMBER < 0x30000000L\n    DH *dh = ssl_get_dh2236();\n    if (dh == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to generate DHE parameters for TLS\");\n        return 1;\n    }\n\n    if (SSL_CTX_set_tmp_dh(self->ctx, dh) != 1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to setup DHE parameters for TLS\");\n        dump_ssl_error_stack(self);\n        return 1;\n    }\n    DH_free(dh); // ok to free, copied into ctx by SSL_CTX_set_tmp_dh()\n#endif\n\n#if (OPENSSL_VERSION_NUMBER >= 0x10000020L) && \\\n    OPENSSL_VERSION_NUMBER < (0x10100000L)\n    // SSL_CTX_set_ecdh_auto() added in OpenSSL 1.0.2 and\n    // removed for OpenSSL 1.1.0\n    if (!SSL_CTX_set_ecdh_auto(self->ctx, 1))\n    {\n        LOG(LOG_LEVEL_WARNING, \"TLS ecdh auto failed to be enabled\");\n    }\n#endif\n\n    if (g_strlen(tls_ciphers) > 1)\n    {\n        LOG(LOG_LEVEL_TRACE, \"tls_ciphers=%s\", tls_ciphers);\n        if (SSL_CTX_set_cipher_list(self->ctx, tls_ciphers) == 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Invalid TLS cipher options %s\", tls_ciphers);\n            dump_ssl_error_stack(self);\n            return 1;\n        }\n    }\n\n    SSL_CTX_set_read_ahead(self->ctx, 0);\n\n    /*\n     * We don't currently handle encrypted private keys - set a callback\n     * to tell the user if one is provided */\n    SSL_CTX_set_default_passwd_cb(self->ctx, log_encrypted_file_unsupported);\n    SSL_CTX_set_default_passwd_cb_userdata(self->ctx, self->key);\n\n    if (SSL_CTX_use_PrivateKey_file(self->ctx, self->key, SSL_FILETYPE_PEM)\n            <= 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error loading TLS private key from %s\", self->key);\n        dump_ssl_error_stack(self);\n        return 1;\n    }\n    SSL_CTX_set_default_passwd_cb(self->ctx, NULL);\n    SSL_CTX_set_default_passwd_cb_userdata(self->ctx, NULL);\n\n    if (SSL_CTX_use_certificate_chain_file(self->ctx, self->cert) <= 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error loading TLS certificate chain from %s\", self->cert);\n        dump_ssl_error_stack(self);\n        return 1;\n    }\n\n    /*\n     * Don't call SSL_check_private_key() for openSSL prior to 1.0.2, as\n     * certificate chains are not handled in the same way - see\n     * SSL_CTX_check_private_key(3ssl) */\n#if OPENSSL_VERSION_NUMBER >= 0x10002000L\n    if (!SSL_CTX_check_private_key(self->ctx))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Private key %s and certificate %s do not match\",\n            self->key, self->cert);\n        dump_ssl_error_stack(self);\n        return 1;\n    }\n#endif\n\n#ifdef HAS_KEYLOG_CALLBACK\n    SSL_CTX_set_keylog_callback(self->ctx, log_pre_master_secret);\n#endif // HAS_KEYLOG_CALLBACK\n\n    self->ssl = SSL_new(self->ctx);\n\n    if (self->ssl == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to create an SSL structure\");\n        dump_ssl_error_stack(self);\n        return 1;\n    }\n\n    if (SSL_set_fd(self->ssl, self->trans->sck) < 1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to set up an SSL structure on fd %d\",\n            (int)self->trans->sck);\n        dump_ssl_error_stack(self);\n        return 1;\n    }\n\n    while (1)\n    {\n        /*\n         * Make sure the error queue is clear before (re-) attempting the\n         * accept. If the accept is successful, the error queue will\n         * remain clear for normal SSL operation */\n        ERR_clear_error();\n\n        connection_status = SSL_accept(self->ssl);\n\n        if (connection_status <= 0)\n        {\n            if (ssl_tls_log_error(self, \"SSL_accept\", connection_status))\n            {\n                return 1;\n            }\n            /**\n             * retry when SSL_get_error returns:\n             *     SSL_ERROR_WANT_READ\n             *     SSL_ERROR_WANT_WRITE\n             */\n            switch (SSL_get_error(self->ssl, connection_status))\n            {\n                case SSL_ERROR_WANT_READ:\n                    g_sck_can_recv(self->trans->sck, SSL_WANT_READ_WRITE_TIMEOUT);\n                    break;\n                case SSL_ERROR_WANT_WRITE:\n                    g_sck_can_send(self->trans->sck, SSL_WANT_READ_WRITE_TIMEOUT);\n                    break;\n            }\n\n            if (is_term != NULL && (*is_term)())\n            {\n                return 1;\n            }\n        }\n        else\n        {\n            break;\n        }\n    }\n\n    LOG(LOG_LEVEL_TRACE, \"TLS connection accepted\");\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error, */\nint\nssl_tls_disconnect(struct ssl_tls *self)\n{\n    int status;\n\n    if (self == NULL)\n    {\n        return 0;\n    }\n    if (self->ssl == NULL)\n    {\n        return 0;\n    }\n    status = SSL_shutdown(self->ssl);\n    if (status != 1)\n    {\n        status = SSL_shutdown(self->ssl);\n        if (status <= 0)\n        {\n            if (ssl_tls_log_error(self, \"SSL_shutdown\", status))\n            {\n                return 1;\n            }\n            /**\n             * retry when SSL_get_error returns:\n             *     SSL_ERROR_WANT_READ\n             *     SSL_ERROR_WANT_WRITE\n             */\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nvoid\nssl_tls_delete(struct ssl_tls *self)\n{\n    if (self != NULL)\n    {\n        if (self->ssl)\n        {\n            SSL_free(self->ssl);\n        }\n\n        if (self->ctx)\n        {\n            SSL_CTX_free(self->ctx);\n        }\n\n        g_delete_wait_obj(self->rwo);\n\n        g_free(self);\n    }\n}\n\n/*****************************************************************************/\nint\nssl_tls_read(struct ssl_tls *tls, char *data, int length)\n{\n    int status;\n    int break_flag;\n\n    while (1)\n    {\n        status = SSL_read(tls->ssl, data, length);\n\n        switch (SSL_get_error(tls->ssl, status))\n        {\n            case SSL_ERROR_NONE:\n                break_flag = 1;\n                break;\n\n            /**\n             * retry when SSL_get_error returns:\n             *     SSL_ERROR_WANT_READ\n             *     SSL_ERROR_WANT_WRITE\n             */\n            case SSL_ERROR_WANT_READ:\n                g_sck_can_recv(tls->trans->sck, SSL_WANT_READ_WRITE_TIMEOUT);\n                continue;\n            case SSL_ERROR_WANT_WRITE:\n                g_sck_can_send(tls->trans->sck, SSL_WANT_READ_WRITE_TIMEOUT);\n                continue;\n\n            /* socket closed */\n            case SSL_ERROR_ZERO_RETURN:\n                return 0;\n\n            default:\n                ssl_tls_log_error(tls, \"SSL_read\", status);\n                status = -1;\n                break_flag = 1;\n                break;\n        }\n\n        if (break_flag)\n        {\n            break;\n        }\n    }\n\n    if (SSL_pending(tls->ssl) > 0)\n    {\n        g_set_wait_obj(tls->rwo);\n    }\n\n    return status;\n}\n\n/*****************************************************************************/\nint\nssl_tls_write(struct ssl_tls *tls, const char *data, int length)\n{\n    int status;\n    int break_flag;\n\n    while (1)\n    {\n        status = SSL_write(tls->ssl, data, length);\n\n        switch (SSL_get_error(tls->ssl, status))\n        {\n            case SSL_ERROR_NONE:\n                break_flag = 1;\n                break;\n\n            /**\n             * retry when SSL_get_error returns:\n             *     SSL_ERROR_WANT_READ\n             *     SSL_ERROR_WANT_WRITE\n             */\n            case SSL_ERROR_WANT_READ:\n                g_sck_can_recv(tls->trans->sck, SSL_WANT_READ_WRITE_TIMEOUT);\n                continue;\n            case SSL_ERROR_WANT_WRITE:\n                g_sck_can_send(tls->trans->sck, SSL_WANT_READ_WRITE_TIMEOUT);\n                continue;\n\n            /* socket closed */\n            case SSL_ERROR_ZERO_RETURN:\n                return 0;\n\n            default:\n                ssl_tls_log_error(tls, \"SSL_write\", status);\n                status = -1;\n                break_flag = 1;\n                break;\n        }\n\n        if (break_flag)\n        {\n            break;\n        }\n    }\n\n    return status;\n}\n\n/*****************************************************************************/\n/* returns boolean */\nint\nssl_tls_can_recv(struct ssl_tls *tls, int sck, int millis)\n{\n    if (SSL_pending(tls->ssl) > 0)\n    {\n        return 1;\n    }\n    g_reset_wait_obj(tls->rwo);\n    return g_sck_can_recv(sck, millis);\n}\n\n/*****************************************************************************/\nconst char *\nssl_get_version(const struct ssl_tls *ssl)\n{\n    return SSL_get_version(ssl->ssl);\n}\n\n/*****************************************************************************/\nconst char *\nssl_get_cipher_name(const struct ssl_tls *ssl)\n{\n    return SSL_get_cipher_name(ssl->ssl);\n}\n\n/*****************************************************************************/\ntintptr\nssl_get_rwo(const struct ssl_tls *ssl)\n{\n    return ssl->rwo;\n}\n\n/*****************************************************************************/\nint\nssl_get_protocols_from_string(const char *str, long *ssl_protocols)\n{\n    long protocols;\n    long bad_protocols;\n    int rv;\n\n    if ((str == NULL) || (ssl_protocols == NULL))\n    {\n        return 1;\n    }\n    rv = 0;\n    protocols = 0;\n#if defined(SSL_OP_NO_SSLv3)\n    protocols |= SSL_OP_NO_SSLv3;\n#endif\n#if defined(SSL_OP_NO_TLSv1)\n    protocols |= SSL_OP_NO_TLSv1;\n#endif\n#if defined(SSL_OP_NO_TLSv1_1)\n    protocols |= SSL_OP_NO_TLSv1_1;\n#endif\n#if defined(SSL_OP_NO_TLSv1_2)\n    protocols |= SSL_OP_NO_TLSv1_2;\n#endif\n#if defined(SSL_OP_NO_TLSv1_3)\n    protocols |= SSL_OP_NO_TLSv1_3;\n#endif\n    bad_protocols = protocols;\n    if (g_pos(str, \",TLSv1.3,\") >= 0)\n    {\n#if defined(SSL_OP_NO_TLSv1_3)\n        LOG(LOG_LEVEL_DEBUG, \"TLSv1.3 enabled\");\n        protocols &= ~SSL_OP_NO_TLSv1_3;\n#else\n        LOG(LOG_LEVEL_WARNING,\n            \"TLSv1.3 enabled by config, \"\n            \"but not supported by system OpenSSL\");\n        rv |= (1 << 6);\n#endif\n    }\n    if (g_pos(str, \",TLSv1.2,\") >= 0)\n    {\n#if defined(SSL_OP_NO_TLSv1_2)\n        LOG(LOG_LEVEL_DEBUG, \"TLSv1.2 enabled\");\n        protocols &= ~SSL_OP_NO_TLSv1_2;\n#else\n        LOG(LOG_LEVEL_WARNING,\n            \"TLSv1.2 enabled by config, \"\n            \"but not supported by system OpenSSL\");\n        rv |= (1 << 1);\n#endif\n    }\n    if (g_pos(str, \",TLSv1.1,\") >= 0)\n    {\n#if defined(SSL_OP_NO_TLSv1_1)\n        LOG(LOG_LEVEL_DEBUG, \"TLSv1.1 enabled\");\n        protocols &= ~SSL_OP_NO_TLSv1_1;\n#else\n        LOG(LOG_LEVEL_WARNING,\n            \"TLSv1.1 enabled by config, \"\n            \"but not supported by system OpenSSL\");\n        rv |= (1 << 2);\n#endif\n    }\n    if (g_pos(str, \",TLSv1,\") >= 0)\n    {\n#if defined(SSL_OP_NO_TLSv1)\n        LOG(LOG_LEVEL_DEBUG, \"TLSv1 enabled\");\n        protocols &= ~SSL_OP_NO_TLSv1;\n#else\n        LOG(LOG_LEVEL_WARNING,\n            \"TLSv1 enabled by config, \"\n            \"but not supported by system OpenSSL\");\n        rv |= (1 << 3);\n#endif\n    }\n    if (g_pos(str, \",SSLv3,\") >= 0)\n    {\n#if defined(SSL_OP_NO_SSLv3)\n        LOG(LOG_LEVEL_DEBUG, \"SSLv3 enabled\");\n        protocols &= ~SSL_OP_NO_SSLv3;\n#else\n        LOG(LOG_LEVEL_WARNING,\n            \"SSLv3 enabled by config, \"\n            \"but not supported by system OpenSSL\");\n        rv |= (1 << 4);\n#endif\n    }\n    if (protocols == bad_protocols)\n    {\n        LOG(LOG_LEVEL_WARNING, \"No SSL/TLS protocols enabled. \"\n            \"At least one protocol should be enabled to accept \"\n            \"TLS connections.\");\n        rv |= (1 << 5);\n    }\n    *ssl_protocols = protocols;\n    return rv;\n}\n\n/*****************************************************************************/\nconst char\n*get_openssl_version(void)\n{\n#if OPENSSL_VERSION_NUMBER < 0x10100000L\n    return SSLeay_version(SSLEAY_VERSION);\n#else\n    return OpenSSL_version(OPENSSL_VERSION);\n#endif\n\n}\n\n"
  },
  {
    "path": "common/ssl_calls.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n * Copyright (C) Idan Freiberg 2013-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(SSL_CALLS_H)\n#define SSL_CALLS_H\n\n#include \"arch.h\"\n\n/* Incomplete types */\nstruct ssl_tls;\nstruct trans;\n\nint\nssl_init(void);\nint\nssl_finish(void);\n/**\n * Sets a log file for recording TLS pre-master secrets\n *\n * @param filename Filename to log secrets in\n * @return != 0 if the log was successfully set\n */\nint\nssl_set_pre_master_secret_logfile(const char *filename);\nvoid *\nssl_rc4_info_create(void);\nvoid\nssl_rc4_info_delete(void *rc4_info);\nvoid\nssl_rc4_set_key(void *rc4_info, const char *key, int len);\nvoid\nssl_rc4_crypt(void *rc4_info, char *data, int len);\nvoid *\nssl_sha1_info_create(void);\nvoid\nssl_sha1_info_delete(void *sha1_info);\nvoid\nssl_sha1_clear(void *sha1_info);\nvoid\nssl_sha1_transform(void *sha1_info, const char *data, int len);\nvoid\nssl_sha1_complete(void *sha1_info, char *data);\nvoid *\nssl_md5_info_create(void);\nvoid\nssl_md5_info_delete(void *md5_info);\nvoid\nssl_md5_clear(void *md5_info);\nvoid\nssl_md5_transform(void *md5_info, const char *data, int len);\nvoid\nssl_md5_complete(void *md5_info, char *data);\nvoid *\nssl_des3_encrypt_info_create(const char *key, const char *ivec);\nvoid *\nssl_des3_decrypt_info_create(const char *key, const char *ivec);\nvoid\nssl_des3_info_delete(void *des3);\nint\nssl_des3_encrypt(void *des3, int length, const char *in_data, char *out_data);\nint\nssl_des3_decrypt(void *des3, int length, const char *in_data, char *out_data);\nvoid *\nssl_hmac_info_create(void);\nvoid\nssl_hmac_info_delete(void *hmac);\nvoid\nssl_hmac_sha1_init(void *hmac, const char *data, int len);\nvoid\nssl_hmac_transform(void *hmac, const char *data, int len);\nvoid\nssl_hmac_complete(void *hmac, char *data, int len);\nint\nssl_mod_exp(char *out, int out_len, const char *in, int in_len,\n            const char *mod, int mod_len, const char *exp, int exp_len);\nint\nssl_gen_key_xrdp1(int key_size_in_bits, const char *exp, int exp_len,\n                  char *mod, int mod_len, char *pri, int pri_len);\n\n/* xrdp_tls.c */\nstruct ssl_tls *\nssl_tls_create(struct trans *trans, const char *key, const char *cert);\nint\nssl_tls_accept(struct ssl_tls *self, long ssl_protocols,\n               const char *tls_ciphers,\n               int (*is_term)(void));\nint\nssl_tls_disconnect(struct ssl_tls *self);\nvoid\nssl_tls_delete(struct ssl_tls *self);\nint\nssl_tls_read(struct ssl_tls *tls, char *data, int length);\nint\nssl_tls_write(struct ssl_tls *tls, const char *data, int length);\nint\nssl_tls_can_recv(struct ssl_tls *tls, int sck, int millis);\nconst char *\nssl_get_version(const struct ssl_tls *ssl);\nconst char *\nssl_get_cipher_name(const struct ssl_tls *ssl);\nint\nssl_get_protocols_from_string(const char *str, long *ssl_protocols);\nconst char *\nget_openssl_version(void);\ntintptr\nssl_get_rwo(const struct ssl_tls *ssl);\n\n#endif\n"
  },
  {
    "path": "common/string_calls.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2020\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * The strlcpy implementation is taken from OpenBSD and reformatted. The\n * original has the following notice attached:-\n * |\n * |   Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>\n * |\n * |   Permission to use, copy, modify, and distribute this software for any\n * |   purpose with or without fee is hereby granted, provided that the above\n * |   copyright notice and this permission notice appear in all copies.\n * |\n * |   THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n * |   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n * |   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n * |   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n * |   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n * |   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n * |   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.*\n *\n * generic string handling calls\n */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n#include <signal.h>\n#include <string.h>\n#include <strings.h>\n#include <stdlib.h>\n#include <ctype.h>\n\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"defines.h\"\n#include \"unicode_defines.h\"\n\nunsigned int\ng_format_info_string(char *dest, unsigned int len,\n                     const char *format,\n                     const struct info_string_tag map[])\n{\n    unsigned int result = 0;\n    const char *copy_from;  /* Data to add to output */\n    unsigned int copy_len;  /* Length of above */\n    unsigned int skip;      /* Date to skip over in format string */\n    const char *p;\n    const struct info_string_tag *m;\n\n    for ( ; *format != '\\0'; format += skip)\n    {\n        if (*format == '%')\n        {\n            char ch = *(format + 1);\n            if (ch == '%')\n            {\n                /* '%%' in format - replace with single '%' */\n                copy_from = format;\n                copy_len = 1;\n                skip = 2;\n            }\n            else if (ch == '\\0')\n            {\n                /* Percent at end of string - ignore */\n                copy_from = NULL;\n                copy_len = 0;\n                skip = 1;\n            }\n            else\n            {\n                /* Look up the character in the map, assuming failure */\n                copy_from = NULL;\n                copy_len = 0;\n                skip = 2;\n\n                for (m = map ; m->ch != '\\0' ; ++m)\n                {\n                    if (ch == m->ch)\n                    {\n                        copy_from = m->val;\n                        copy_len = strlen(copy_from);\n                        break;\n                    }\n                }\n            }\n        }\n        else if ((p = strchr(format, '%')) != NULL)\n        {\n            /* Copy up to the next '%' */\n            copy_from = format;\n            copy_len = p - format;\n            skip = copy_len;\n        }\n        else\n        {\n            /* Copy the rest of the format string */\n            copy_from = format;\n            copy_len = strlen(format);\n            skip = copy_len;\n        }\n\n        /* Update the result before any truncation */\n        result += copy_len;\n\n        /* Do we have room in the output buffer for any more data? We\n         * must always write a terminator if possible */\n        if (len > 1)\n        {\n            if (copy_len > (len - 1))\n            {\n                copy_len = len - 1;\n            }\n            memcpy(dest, copy_from, copy_len);\n            dest += copy_len;\n            len -= copy_len;\n        }\n    }\n\n    /* Room for a terminator? */\n    if (len > 0)\n    {\n        *dest = '\\0';\n    }\n\n    return result;\n}\n\n/******************************************************************************/\nconst char *\ng_bool2text(int value)\n{\n    return value ? \"true\" : \"false\";\n}\n\n/*****************************************************************************/\nint\ng_text2bool(const char *s)\n{\n    if ( (g_atoi(s) != 0) ||\n            (0 == g_strcasecmp(s, \"true\")) ||\n            (0 == g_strcasecmp(s, \"on\")) ||\n            (0 == g_strcasecmp(s, \"yes\")))\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nget_display_num_from_display(const char *display_text)\n{\n    int rv = -1;\n    const char *p;\n\n    /* Skip over the hostname part of the DISPLAY */\n    if (display_text != NULL && (p = strchr(display_text, ':')) != NULL)\n    {\n        ++p; /* Skip the ':' */\n\n        /* Cater for the (still supported) double-colon. See\n         * https://www.x.org/releases/X11R7.7/doc/libX11/libX11/libX11.html */\n        if (*p == ':')\n        {\n            ++p;\n        }\n\n        /* Check it starts with a digit, to avoid oddities like DISPLAY=\":zz.0\"\n         * being parsed successfully */\n        if (isdigit(*p))\n        {\n            rv = g_atoi(p);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\ng_get_display_string_from_x11_display(int display_num,\n                                      char buff[], unsigned int bufflen)\n{\n    unsigned int res = g_snprintf(buff, bufflen, \"X11-%d\", display_num);\n    return (res >= bufflen) ? -1 : 0;\n}\n\n\n/*****************************************************************************/\nint\ng_get_x11_display_from_display_string(const char *display_str)\n{\n    int result = -1;\n    if (display_str != NULL)\n    {\n        if (display_str[0] == 'X' && display_str[1] == '1' &&\n                display_str[2] == '1' && display_str[3] == '-' &&\n                isdigit(display_str[4]))\n        {\n            result = g_atoi(display_str + 4);\n        }\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nint\ng_get_display_string(char buff[], unsigned int bufflen)\n{\n    const char *str;\n    const char *p = NULL;\n    int rv = 0;\n\n    if ((str = g_getenv(\"WAYLAND_DISPLAY\")) != NULL)\n    {\n        // Return the unqualified part of the name\n        p = strrchr(str, '/');\n        p = (p != NULL) ? (p + 1) : str;\n        if (strlcpy(buff, p, bufflen) >= bufflen)\n        {\n            rv = -1; /* Buffer overflow */\n        }\n    }\n    else if ((str = g_getenv(\"DISPLAY\")) != NULL)\n    {\n        int n = get_display_num_from_display(str);\n\n        if (n >= 0)\n        {\n            if ((unsigned int)g_snprintf(buff, bufflen, \"X11-%d\", n)\n                    >= bufflen)\n            {\n                rv = -1; /* Buffer overflow */\n            }\n        }\n        else\n        {\n            rv = g_get_display_string_from_x11_display(n, buff, bufflen);\n        }\n    }\n    else\n    {\n        rv = -1;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns length of text */\nint\ng_strlen(const char *text)\n{\n    if (text == NULL)\n    {\n        return 0;\n    }\n\n    return strlen(text);\n}\n\n/*****************************************************************************/\n/* locates char in text */\nchar *\ng_strchr(const char *text, int c)\n{\n    if (text == NULL)\n    {\n        return 0;\n    }\n\n    /* Cast needed to compile with C++ */\n    return (char *)strchr(text, c);\n}\n\n/*****************************************************************************/\n/* locates char in text */\nchar *\ng_strrchr(const char *text, int c)\n{\n    if (text == NULL)\n    {\n        return 0;\n    }\n\n    /* Cast needed to compile with C++ */\n    return (char *)strrchr(text, c);\n}\n\n/*****************************************************************************/\n/* locates char in text with length */\nchar *\ng_strnchr(const char *text, int c, int len)\n{\n    if (text == NULL || len <= 0)\n    {\n        return NULL;\n    }\n\n    return (char *)memchr(text, c, len);\n}\n\n/*****************************************************************************/\n/* returns dest */\nchar *\ng_strcpy(char *dest, const char *src)\n{\n    if (src == 0 && dest != 0)\n    {\n        dest[0] = 0;\n        return dest;\n    }\n\n    if (dest == 0 || src == 0)\n    {\n        return 0;\n    }\n\n    return strcpy(dest, src);\n}\n\n/*****************************************************************************/\n/* returns dest */\nchar *\ng_strncpy(char *dest, const char *src, int len)\n{\n    char *rv;\n\n    if (src == 0 && dest != 0)\n    {\n        dest[0] = 0;\n        return dest;\n    }\n\n    if (dest == 0 || src == 0)\n    {\n        return 0;\n    }\n\n    rv = strncpy(dest, src, len);\n    dest[len] = 0;\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns dest */\nchar *\ng_strcat(char *dest, const char *src)\n{\n    if (dest == 0 || src == 0)\n    {\n        return dest;\n    }\n\n    return strcat(dest, src);\n}\n\n/*****************************************************************************/\n/* returns dest */\nchar *\ng_strncat(char *dest, const char *src, int len)\n{\n    if (dest == 0 || src == 0)\n    {\n        return dest;\n    }\n\n    return strncat(dest, src, len);\n}\n\n/*****************************************************************************/\n/* if in = 0, return 0 else return newly alloced copy of in */\nchar *\ng_strdup(const char *in)\n{\n    int len;\n    char *p;\n\n    if (in == 0)\n    {\n        return 0;\n    }\n\n    len = g_strlen(in);\n    p = (char *)g_malloc(len + 1, 0);\n\n    if (p != NULL)\n    {\n        g_strcpy(p, in);\n    }\n\n    return p;\n}\n\n/*****************************************************************************/\n/* if in = 0, return 0 else return newly alloced copy of input string\n * if the input string is larger than maxlen the returned string will be\n * truncated. All strings returned will include null termination*/\nchar *\ng_strndup(const char *in, const unsigned int maxlen)\n{\n    unsigned int len;\n    char *p;\n\n    if (in == 0)\n    {\n        return 0;\n    }\n\n    len = g_strlen(in);\n\n    if (len > maxlen)\n    {\n        len = maxlen - 1;\n    }\n\n    p = (char *)g_malloc(len + 2, 0);\n\n    if (p != NULL)\n    {\n        g_strncpy(p, in, len + 1);\n    }\n\n    return p;\n}\n\n/*****************************************************************************/\nint\ng_strcmp(const char *c1, const char *c2)\n{\n    return strcmp(c1, c2);\n}\n\n/*****************************************************************************/\nint\ng_strncmp(const char *c1, const char *c2, int len)\n{\n    return strncmp(c1, c2, len);\n}\n\n/*****************************************************************************/\n/* compare up to delim */\nint\ng_strncmp_d(const char *s1, const char *s2, const char delim, int n)\n{\n    char c1;\n    char c2;\n\n    c1 = 0;\n    c2 = 0;\n    while (n > 0)\n    {\n        c1 = *(s1++);\n        c2 = *(s2++);\n        if ((c1 == 0) || (c1 != c2) || (c1 == delim) || (c2 == delim))\n        {\n            return c1 - c2;\n        }\n        n--;\n    }\n    return c1 - c2;\n}\n\n/*****************************************************************************/\nint\ng_strcasecmp(const char *c1, const char *c2)\n{\n#if defined(_WIN32)\n    return stricmp(c1, c2);\n#else\n    return strcasecmp(c1, c2);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_strncasecmp(const char *c1, const char *c2, int len)\n{\n#if defined(_WIN32)\n    return strnicmp(c1, c2, len);\n#else\n    return strncasecmp(c1, c2, len);\n#endif\n}\n\n/*****************************************************************************/\nint\ng_atoi(const char *str)\n{\n    if (str == 0)\n    {\n        return 0;\n    }\n\n    return atoi(str);\n}\n\n/*****************************************************************************/\n/* As g_atoi() but allows for hexadecimal too */\nint\ng_atoix(const char *str)\n{\n    int base = 10;\n    if (str == NULL)\n    {\n        str = \"0\";\n    }\n\n    while (isspace(*str))\n    {\n        ++str;\n    }\n\n    if (*str == '0' && tolower(*(str + 1)) == 'x')\n    {\n        str += 2;\n        base = 16;\n    }\n    //coverity[OVERRUN:FALSE]\n    return strtol(str, NULL, base);\n}\n\n/*****************************************************************************/\n#if !defined(HAVE_STRLCPY)\nsize_t strlcpy(char *dst, const char *src, size_t dsize)\n{\n    const char *osrc = src;\n    size_t nleft = dsize;\n\n    /* Copy as many bytes as will fit. */\n    if (nleft != 0)\n    {\n        while (--nleft != 0)\n        {\n            if ((*dst++ = *src++) == '\\0')\n            {\n                break;\n            }\n        }\n    }\n\n    /* Not enough room in dst, add NUL and traverse rest of src. */\n    if (nleft == 0)\n    {\n        if (dsize != 0)\n        {\n            *dst = '\\0';        /* NUL-terminate dst */\n        }\n        while (*src++)\n        {\n            ;\n        }\n    }\n\n    return (src - osrc - 1);      /* count does not include NUL */\n}\n#endif\n\n/*****************************************************************************/\nunsigned int\ng_htoi(const char *str)\n{\n    unsigned int rv = 0;\n    while (*str != '\\0')\n    {\n        char c = *str;\n        unsigned int val;\n        if (c >= '0' && c <= '9')\n        {\n            val = c - '0';\n        }\n        else if (c >= 'A' && c <= 'F')\n        {\n            val = (c - 'A' + 10);\n        }\n        else if (c >= 'a' && c <= 'f')\n        {\n            val = (c - 'a' + 10);\n        }\n        else\n        {\n            break; // Unrecognised character\n        }\n        rv = (rv << 4) | val;\n        ++str;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns number of bytes copied into out_str */\nint\ng_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str,\n                  int bytes_out_str)\n{\n    int rv;\n    int index;\n    char *lout_str;\n    const tui8 *lbytes;\n\n    rv = 0;\n    lbytes = (const tui8 *) bytes;\n    lout_str = out_str;\n    for (index = 0; index < num_bytes; index++)\n    {\n        if (bytes_out_str < 3)\n        {\n            break;\n        }\n        g_snprintf(lout_str, bytes_out_str, \"%2.2x\", lbytes[index]);\n        lout_str += 2;\n        bytes_out_str -= 2;\n        rv += 2;\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* convert a byte array into a hex dump */\nchar *\ng_bytes_to_hexdump(const char *src, int len)\n{\n    unsigned char *line;\n    int i;\n    int dump_number_lines;\n    int dump_line_length;\n    int dump_length;\n    int dump_offset;\n    int thisline;\n    int offset;\n    char *dump_buffer;\n\n#define HEX_DUMP_SOURCE_BYTES_PER_LINE (16)\n#ifdef _WIN32\n#define HEX_DUMP_NEWLINE_SIZE (2)\n#else\n#ifdef _MACOS\n#define HEX_DUMP_NEWLINE_SIZE (1)\n#else\n#define HEX_DUMP_NEWLINE_SIZE (1)\n#endif\n#endif\n\n    dump_line_length = (4 + 3             /* = 4 offset + 3 space */\n                        + ((2 + 1) * HEX_DUMP_SOURCE_BYTES_PER_LINE)  /* + (2 hex char + 1 space) per source byte */\n                        + 2 /* + 2 space */\n                        + HEX_DUMP_SOURCE_BYTES_PER_LINE\n                        + HEX_DUMP_NEWLINE_SIZE);\n\n    dump_number_lines = (len / HEX_DUMP_SOURCE_BYTES_PER_LINE) + 1; /* +1 to round up */\n    dump_length = (dump_number_lines * dump_line_length   /* hex dump lines */\n                   + 1);    /* terminating NULL */\n    dump_buffer = (char *)g_malloc(dump_length, 1);\n    if (dump_buffer == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_WARNING,\n                  \"Failed to allocate buffer for hex dump of size %d\",\n                  dump_length);\n        return NULL;\n    }\n\n    line = (unsigned char *)src;\n    offset = 0;\n    dump_offset = 0;\n\n    while (offset < len)\n    {\n        g_sprintf(dump_buffer + dump_offset, \"%04x   \", offset);\n        dump_offset += 7;\n        thisline = len - offset;\n\n        if (thisline > HEX_DUMP_SOURCE_BYTES_PER_LINE)\n        {\n            thisline = HEX_DUMP_SOURCE_BYTES_PER_LINE;\n        }\n\n        for (i = 0; i < thisline; i++)\n        {\n            g_sprintf(dump_buffer + dump_offset, \"%02x \", line[i]);\n            dump_offset += 3;\n        }\n\n        for (; i < HEX_DUMP_SOURCE_BYTES_PER_LINE; i++)\n        {\n            dump_buffer[dump_offset++] = ' ';\n            dump_buffer[dump_offset++] = ' ';\n            dump_buffer[dump_offset++] = ' ';\n        }\n\n        dump_buffer[dump_offset++] = ' ';\n        dump_buffer[dump_offset++] = ' ';\n\n        for (i = 0; i < thisline; i++)\n        {\n            dump_buffer[dump_offset++] = (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.';\n        }\n\n        for (; i < HEX_DUMP_SOURCE_BYTES_PER_LINE; i++)\n        {\n            dump_buffer[dump_offset++] = ' ';\n        }\n\n#ifdef _WIN32\n        dump_buffer[dump_offset++] = '\\r';\n        dump_buffer[dump_offset++] = '\\n';\n#else\n#ifdef _MACOS\n        dump_buffer[dump_offset++] = '\\r';\n#else\n        dump_buffer[dump_offset++] = '\\n';\n#endif\n#endif\n        offset += thisline;\n        line += thisline;\n\n\n        if (dump_offset % dump_line_length != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING,\n                      \"BUG: dump_offset (%d) at the end of a line is not a \"\n                      \"multiple of the line length (%d)\",\n                      dump_offset, dump_line_length);\n        }\n\n    }\n    if (dump_offset > dump_length)\n    {\n        LOG_DEVEL(LOG_LEVEL_WARNING,\n                  \"BUG: dump_offset (%d) is larger than the dump_buffer length (%d)\",\n                  dump_offset, dump_length);\n        dump_buffer[0] = '\\0';\n        return dump_buffer;\n    }\n\n    /* replace the last new line with the end of the string since log_message\n       will add a new line */\n    dump_buffer[dump_offset - HEX_DUMP_NEWLINE_SIZE] = '\\0';\n    return dump_buffer;\n}\n\n/*****************************************************************************/\nint\ng_pos(const char *str, const char *to_find)\n{\n    const char *pp;\n\n    pp = strstr(str, to_find);\n\n    if (pp == 0)\n    {\n        return -1;\n    }\n\n    return (pp - str);\n}\n\n/*****************************************************************************/\n\nchar *\ng_strstr(const char *haystack, const char *needle)\n{\n    if (haystack == NULL || needle == NULL)\n    {\n        return NULL;\n    }\n\n    /* Cast needed to compile with C++ */\n    return (char *)strstr(haystack, needle);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ng_strtrim(char *str, int trim_flags)\n{\n#define TRIMMABLE_CHAR(c) ((unsigned char)(c) <= ' ')\n    int rv = 0;\n    int index;\n    int j;\n\n    switch (trim_flags)\n    {\n        case 4: /* trim through */\n\n            j = 0;\n            for (index = 0; str[index] != '\\0'; index++)\n            {\n                if (!TRIMMABLE_CHAR(str[index]))\n                {\n                    str[j++] = str[index];\n                }\n            }\n\n            str[j] = '\\0';\n            break;\n\n        case 3: /* trim both */\n            rv = g_strtrim(str, 1) || g_strtrim(str, 2);\n            break;\n\n        case 2: /* trim right */\n            index = strlen(str);\n            while (index > 0 && TRIMMABLE_CHAR(str[index - 1]))\n            {\n                --index;\n            }\n            str[index] = '\\0';\n            break;\n\n        case 1: /* trim left */\n            index = 0;\n            while (str[index] != '\\0' && TRIMMABLE_CHAR(str[index]))\n            {\n                ++index;\n            }\n            if (index > 0)\n            {\n                memmove(str, str + index, strlen(str) + 1 - index);\n            }\n            break;\n\n        default:\n            rv = 1;\n    }\n\n    return rv;\n#undef TRIMMABLE_CHAR\n}\n\n/*****************************************************************************/\nchar *\ng_strnjoin(char *dest, int dest_len, const char *joiner, const char *src[], int src_len)\n{\n    int len;\n    int joiner_len;\n    int i = 0;\n    int dest_remaining;\n    char *dest_pos = dest;\n    char *dest_end;\n\n    if (dest == NULL || dest_len < 1)\n    {\n        return dest;\n    }\n    if (src == NULL || src_len < 1)\n    {\n        dest[0] = '\\0';\n        return dest;\n    }\n\n    dest[0] = '\\0';\n    dest_end = dest + dest_len - 1;\n    joiner_len = g_strlen(joiner);\n    for (i = 0; i < src_len - 1 && dest_pos < dest_end; i++)\n    {\n        len = g_strlen(src[i]);\n        dest_remaining = dest_end - dest_pos;\n        g_strncat(dest_pos, src[i], dest_remaining);\n        dest_pos += MIN(len, dest_remaining);\n\n        if (dest_pos < dest_end)\n        {\n            dest_remaining = dest_end - dest_pos;\n            g_strncat(dest_pos, joiner, dest_remaining);\n            dest_pos += MIN(joiner_len, dest_remaining);\n        }\n    }\n\n    if (i == src_len - 1 && dest_pos < dest_end)\n    {\n        g_strncat(dest_pos, src[i], dest_end - dest_pos);\n    }\n\n    return dest;\n}\n\n/*****************************************************************************/\nint\ng_bitmask_to_str(int bitmask, const struct bitmask_string bitdefs[],\n                 char delim, char *buff, int bufflen)\n{\n    int rlen = 0; /* Returned length */\n\n    if (bufflen <= 0) /* Caller error */\n    {\n        rlen = -1;\n    }\n    else\n    {\n        char *p = buff;\n        /* Find the last writeable character in the buffer */\n        const char *last = buff + (bufflen - 1);\n\n        const struct bitmask_string *b;\n\n        for (b = &bitdefs[0] ; b->mask != 0; ++b)\n        {\n            if ((bitmask & b->mask) != 0)\n            {\n                if (p > buff)\n                {\n                    /* Not first item - append separator */\n                    if (p < last)\n                    {\n                        *p++ = delim;\n                    }\n                    ++rlen;\n                }\n\n                int slen = g_strlen(b->str);\n                int copylen = MIN(slen, last - p);\n                g_memcpy(p, b->str, copylen);\n                p += copylen;\n                rlen += slen;\n\n                /* Remove the bit so we can check for undefined bits later*/\n                bitmask &= ~b->mask;\n            }\n        }\n\n        if (bitmask != 0)\n        {\n            /* Bits left which aren't named by the user */\n            if (p > buff)\n            {\n                if (p < last)\n                {\n                    *p++ = delim;\n                }\n                ++rlen;\n            }\n            /* This call will terminate the return buffer */\n            rlen += g_snprintf(p, last - p + 1, \"0x%x\", bitmask);\n        }\n        else\n        {\n            *p = '\\0';\n        }\n    }\n\n    return rlen;\n}\n\n/*****************************************************************************/\nint\ng_str_to_bitmask(const char *str, const struct bitmask_string bitdefs[],\n                 const char *delim, char *unrecognised, int unrecognised_len)\n{\n    char *properties = NULL;\n    char *p = NULL;\n    int mask = 0;\n\n    if (unrecognised_len < 1)\n    {\n        /* No space left to tell unrecognised tokens */\n        return 0;\n    }\n    if (!unrecognised)\n    {\n        return 0;\n    }\n    /* ensure not to return with uninitialized buffer */\n    unrecognised[0] = '\\0';\n    if (!str || !bitdefs || !delim)\n    {\n        return 0;\n    }\n    properties = g_strdup(str);\n    if (!properties)\n    {\n        return 0;\n    }\n    p = strtok(properties, delim);\n    while (p != NULL)\n    {\n        g_strtrim(p, 3);\n        const struct bitmask_string *b;\n        int found = 0;\n        for (b = &bitdefs[0] ; b->str != NULL; ++b)\n        {\n            if (0 == g_strcasecmp(p, b->str))\n            {\n                mask |= b->mask;\n                found = 1;\n                break;\n            }\n        }\n        if (found == 0)\n        {\n            int length = g_strlen(unrecognised);\n            if (length > 0)\n            {\n                /* adding \",property\" */\n                if (length + g_strlen(p) + 1 < unrecognised_len)\n                {\n                    unrecognised[length] = delim[0];\n                    length += 1;\n                    g_strcpy(unrecognised + length, p);\n                }\n            }\n            else if (g_strlen(p) < unrecognised_len)\n            {\n                g_strcpy(unrecognised, p);\n            }\n        }\n        p = strtok(NULL, delim);\n    }\n\n    g_free(properties);\n    return mask;\n}\n\n/*****************************************************************************/\nint\ng_bitmask_to_charstr(int bitmask, const struct bitmask_char bitdefs[],\n                     char *buff, int bufflen, int *rest)\n{\n    int rlen = 0; /* Returned length */\n\n    if (bufflen <= 0) /* Caller error */\n    {\n        rlen = -1;\n    }\n    else\n    {\n        char *p = buff;\n        /* Find the last writeable character in the buffer */\n        const char *last = buff + (bufflen - 1);\n\n        const struct bitmask_char *b;\n\n        for (b = &bitdefs[0] ; b->c != '\\0'; ++b)\n        {\n            if ((bitmask & b->mask) != 0)\n            {\n                if (p < last)\n                {\n                    *p++ = b->c;\n                }\n                ++rlen;\n\n                /* Remove the bit so we don't report it back */\n                bitmask &= ~b->mask;\n            }\n        }\n        *p = '\\0';\n\n        if (rest != NULL)\n        {\n            *rest = bitmask;\n        }\n    }\n\n    return rlen;\n}\n\n/*****************************************************************************/\nint\ng_charstr_to_bitmask(const char *str, const struct bitmask_char bitdefs[],\n                     char *unrecognised, int unrecognised_len)\n{\n    int bitmask = 0;\n    const char *cp;\n    int j = 0;\n\n    if (str != NULL && bitdefs != NULL)\n    {\n        for (cp = str ; *cp != '\\0' ; ++cp)\n        {\n            const struct bitmask_char *b;\n            char c = toupper(*cp);\n\n            for (b = &bitdefs[0] ; b->c != '\\0'; ++b)\n            {\n                if (toupper(b->c) == c)\n                {\n                    bitmask |= b->mask;\n                    break;\n                }\n            }\n            if (b->c == '\\0')\n            {\n                if (unrecognised != NULL && j < (unrecognised_len - 1))\n                {\n                    unrecognised[j++] = *cp;\n                }\n            }\n        }\n    }\n\n    if (unrecognised != NULL && j < unrecognised_len)\n    {\n        unrecognised[j] = '\\0';\n    }\n\n    return bitmask;\n}\n\n/*****************************************************************************/\n/*\n * Looks for a simple mapping of signal number to name\n */\nstatic const char *\nfind_sig_name(int signum)\n{\n    typedef struct\n    {\n        int num;\n        const char *name;\n    } sig_to_name_type;\n\n    // Map a string 'zzz' to { SIGzzz, \"zzz\"} for making\n    // typo-free sig_to_name_type objects\n#   define DEFSIG(sig) { SIG ## sig, # sig }\n\n    // Entries in this array are taken from\n    // The Single UNIX ® Specification, Version 2 (1997)\n    // plus additions from specific operating systems.\n    //\n    // The SUS requires these to be positive integer constants with a\n    // macro definition.  Note that SIGRTMIN and SIGRTMAX on Linux are\n    // NOT constants, so have to be handled separately.\n    static const sig_to_name_type sigmap[] =\n    {\n        // Names from SUS v2, in the order they are listed in that document\n        // that *should* be defined everywhere\n        //\n        // Commented out definitions below are NOT used everywhere\n        DEFSIG(ABRT), DEFSIG(ALRM), DEFSIG(FPE), DEFSIG(HUP),\n        DEFSIG(ILL), DEFSIG(INT), DEFSIG(KILL), DEFSIG(PIPE),\n        DEFSIG(QUIT), DEFSIG(SEGV), DEFSIG(TERM), DEFSIG(USR1),\n        DEFSIG(USR2), DEFSIG(CHLD), DEFSIG(CONT), DEFSIG(STOP),\n        DEFSIG(TSTP), DEFSIG(TTIN), DEFSIG(TTOU), DEFSIG(BUS),\n        /* DEFSIG(POLL), */ /* DEFSIG(PROF), */ DEFSIG(SYS), DEFSIG(TRAP),\n        DEFSIG(URG), DEFSIG(VTALRM), DEFSIG(XCPU), DEFSIG(XFSZ),\n\n        // SIGPOLL and SIGPROF are marked as obselescent in 1003.1-2017,\n        // Also SIGPOLL isn't in *BSD operating systems which use SIGIO\n#ifdef SIGPOLL\n        DEFSIG(POLL),\n#endif\n#ifdef SIGPROF\n        DEFSIG(PROF),\n#endif\n\n        // BSD signals (from FreeBSD/OpenBSD sys/signal.h and\n        // Darwin/Illumos signal.h)\n#ifdef SIGEMT\n        DEFSIG(EMT),\n#endif\n#ifdef SIGIO\n        DEFSIG(IO),\n#endif\n#ifdef SIGWINCH\n        DEFSIG(WINCH),\n#endif\n#ifdef SIGINFO\n        DEFSIG(INFO),\n#endif\n#ifdef SIGTHR\n        DEFSIG(THR),\n#endif\n#ifdef SIGLIBRT\n        DEFSIG(LIBRT),\n#endif\n#ifdef SIGPWR\n        DEFSIG(PWR),\n#endif\n#ifdef SIGWAITING\n        DEFSIG(WAITING),\n#endif\n#ifdef SIGLWP\n        DEFSIG(LWP),\n#endif\n\n        // Linux additions to *BSD (signal(7))\n#ifdef SIGLOST\n        DEFSIG(LOST),\n#endif\n#ifdef SIGSTKFLT\n        DEFSIG(STKFLT),\n#endif\n\n        // Terminator\n        {0, NULL}\n#undef DEFSIG\n    };\n\n    const sig_to_name_type *p;\n\n    for (p = &sigmap[0] ; p->name != NULL ; ++p)\n    {\n        if (p->num == signum)\n        {\n            return p->name;\n        }\n    }\n\n    // These aren't constants on Linux\n#ifdef SIGRTMIN\n    if (signum == SIGRTMIN)\n    {\n        return \"RTMIN\";\n    }\n#endif\n#ifdef SIGRTMAX\n    if (signum == SIGRTMAX)\n    {\n        return \"RTMAX\";\n    }\n#endif\n\n    return NULL;\n}\n\n/*****************************************************************************/\nchar *\ng_sig2text(int signum, char sigstr[])\n{\n    if (signum >= 0)\n    {\n        const char *name = find_sig_name(signum);\n\n        if (name != NULL)\n        {\n            g_snprintf(sigstr, MAXSTRSIGLEN, \"SIG%s\", name);\n            return sigstr;\n        }\n\n#if defined(SIGRTMIN) && defined(SIGRTMAX)\n        if (signum > SIGRTMIN && signum < SIGRTMAX)\n        {\n            g_snprintf(sigstr, MAXSTRSIGLEN, \"SIGRTMIN+%d\", signum - SIGRTMIN);\n            return sigstr;\n        }\n#endif\n    }\n\n    // If all else fails...\n    g_snprintf(sigstr, MAXSTRSIGLEN, \"SIG#%d\", signum);\n    return sigstr;\n}\n\n/*****************************************************************************/\nchar32_t\nutf8_get_next_char(const char **utf8str_ref, unsigned int *len_ref)\n{\n    /*\n     * Macro used to parse a continuation character\n     * @param cp Character Pointer (incremented on success)\n     * @param end One character past end of input string, or NULL\n     * @param value The value we're constructing\n     * @param finish_label Where to go in the event of an error */\n#define PARSE_CONTINUATION_CHARACTER(cp, end, value, finish_label) \\\n    { \\\n        /* Error if we're out of data, or this char isn't a continuation */ \\\n        if (cp == end || !IS_VALID_CONTINUATION_CHAR(*cp)) \\\n        { \\\n            value = UCS_REPLACEMENT_CHARACTER; \\\n            goto finish_label; \\\n        } \\\n        value = (value) << 6 | (*cp & 0x3f); \\\n        ++cp; \\\n    }\n\n    char32_t rv;\n\n    /* Easier to work with unsigned chars and no indirection */\n    const unsigned char *cp = (const unsigned char *)*utf8str_ref;\n    const unsigned char *end = (len_ref != NULL) ? cp + *len_ref : NULL;\n\n    if (cp == end)\n    {\n        return 0; // Pathological case\n    }\n\n    unsigned int c0 = *cp++;\n\n    if (c0 < 0x80)\n    {\n        rv = c0;\n    }\n    else if (c0 < 0xc0)\n    {\n        /* Unexpected continuation character */\n        rv = UCS_REPLACEMENT_CHARACTER;\n    }\n    else if (c0 < 0xe0)\n    {\n        /* Valid start character for sequence of length 2\n         * U-00000080 – U-000007FF */\n        rv = (c0 & 0x1f);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n\n        if (rv < 0x80 || INVALID_UNICODE_80_TO_7FF(rv))\n        {\n            rv = UCS_REPLACEMENT_CHARACTER;\n        }\n    }\n    else if (c0 < 0xf0)\n    {\n        /* Valid start character for sequence of length 3\n         *  U-00000800 – U-0000FFFF */\n        rv = (c0 & 0xf);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        if (rv < 0x800 || INVALID_UNICODE_800_TO_FFFF(rv))\n        {\n            rv = UCS_REPLACEMENT_CHARACTER;\n        }\n    }\n    else if (c0 < 0xf8)\n    {\n        /* Valid start character for sequence of length 4\n         * U-00010000 – U-0001FFFFF */\n        rv = (c0 & 0x7);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        if (rv < 0x10000 || INVALID_UNICODE_10000_TO_1FFFFF(rv))\n        {\n            rv = UCS_REPLACEMENT_CHARACTER;\n        }\n    }\n    else if (c0 < 0xfc)\n    {\n        /* Valid start character for sequence of length 5\n         * U-00200000 – U-03FFFFFF */\n        rv = (c0 & 0x3);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n\n        // These values are currently unsupported\n        rv = UCS_REPLACEMENT_CHARACTER;\n    }\n\n    else if (c0 < 0xfe)\n    {\n        /* Valid start character for sequence of length 6\n         * U-04000000 – U-7FFFFFFF */\n        rv = (c0 & 0x1);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n        PARSE_CONTINUATION_CHARACTER(cp, end, rv, finish);\n\n        // These values are currently unsupported\n        rv = UCS_REPLACEMENT_CHARACTER;\n    }\n    else\n    {\n        // Invalid characters\n        rv = UCS_REPLACEMENT_CHARACTER;\n    }\n\nfinish:\n\n    if (len_ref)\n    {\n        *len_ref -= ((const char *)cp - *utf8str_ref);\n    }\n    *utf8str_ref = (const char *)cp;\n\n    return rv;\n#undef PARSE_CONTINUATION_CHARACTER\n}\n\n/*****************************************************************************/\nunsigned int\nutf_char32_to_utf8(char32_t c32, char *u8str)\n{\n    unsigned int rv;\n\n    if (INVALID_UNICODE(c32))\n    {\n        c32 = UCS_REPLACEMENT_CHARACTER;\n    }\n\n    if (c32 < 0x80)\n    {\n        rv = 1;\n        if (u8str != NULL)\n        {\n            u8str[0] = (char)c32;\n        }\n    }\n    else if (c32 < 0x800)\n    {\n        rv = 2;\n        // 11 bits. Five in first byte, six in second\n        if (u8str != NULL)\n        {\n            u8str[1] = (c32 & 0x3f) | 0x80;\n            c32 >>= 6;\n            u8str[0] = (c32 & 0x1f) | 0xc0;\n        }\n    }\n    else if (c32 < 0xffff)\n    {\n        rv = 3;\n        // 16 bits. Four in first byte, six in second and third\n        if (u8str != NULL)\n        {\n            u8str[2] = (c32 & 0x3f) | 0x80;\n            c32 >>= 6;\n            u8str[1] = (c32 & 0x3f) | 0x80;\n            c32 >>= 6;\n            u8str[0] = (c32 & 0xf) | 0xe0;\n        }\n    }\n    else\n    {\n        rv = 4;\n        // 21 bits. Three in first byte, six in second, third and fourth\n        if (u8str != NULL)\n        {\n            u8str[3] = (c32 & 0x3f) | 0x80;\n            c32 >>= 6;\n            u8str[2] = (c32 & 0x3f) | 0x80;\n            c32 >>= 6;\n            u8str[1] = (c32 & 0x3f) | 0x80;\n            c32 >>= 6;\n            u8str[0] = (c32 & 0x7) | 0xf0;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nunsigned int\nutf8_char_count(const char *utf8str)\n{\n    unsigned int rv = 0;\n    char32_t c;\n\n    if (utf8str != NULL)\n    {\n        while ((c = utf8_get_next_char(&utf8str, NULL)) != 0)\n        {\n            ++rv;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nunsigned int\nutf8_as_utf16_word_count(const char *utf8str, unsigned int len)\n{\n    unsigned int rv = 0;\n    while (len > 0)\n    {\n        char32_t c = utf8_get_next_char(&utf8str, &len);\n        // Characters not in the BMP (i.e. over 0xffff) need a high/low\n        // surrogate pair\n        rv += (c >= 0x10000) ? 2 : 1;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nutf8_add_char_at(char *utf8str, unsigned int len, char32_t c32,\n                 unsigned int index)\n{\n    int rv = 0;\n\n    char c8[MAXLEN_UTF8_CHAR];\n    unsigned int c8len = utf_char32_to_utf8(c32, c8);\n\n    // Find out where to insert the character\n    char *insert_pos = utf8str;\n\n    while (index > 0 && *insert_pos != '\\0')\n    {\n        utf8_get_next_char((const char **)&insert_pos, NULL);\n        --index;\n    }\n\n    // Did we get to where we need to be?\n    if (index == 0)\n    {\n        unsigned int bytes_to_move = strlen(insert_pos) + 1; // Include terminator\n        // Is there room to insert the character?\n        //\n        //  <----------- len ---------->\n        //            <--> (bytes_to_move)\n        // +----------------------------+\n        // |ABCDEFGHIJLMN\\0             |\n        // +----------------------------+\n        //  ^         ^\n        //  +-utf8str +-insert_pos\n        //\n        if ((insert_pos - utf8str) + bytes_to_move + c8len <= len)\n        {\n            memmove(insert_pos + c8len, insert_pos, bytes_to_move);\n            memcpy(insert_pos, c8, c8len);\n            rv = 1;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nchar32_t\nutf8_remove_char_at(char *utf8str, unsigned int index)\n{\n    int rv = 0;\n\n    // Find out where to remove the character\n    char *remove_pos = utf8str;\n\n    while (index > 0)\n    {\n        // Any characters left in string?\n        if (*remove_pos == '\\0')\n        {\n            break;\n        }\n\n        utf8_get_next_char((const char **)&remove_pos, NULL);\n        --index;\n    }\n\n    // Did we get to where we need to be?\n    if (index == 0)\n    {\n        // Find the position after the character\n        char *after_pos = remove_pos;\n        rv = utf8_get_next_char((const char **)&after_pos, NULL);\n\n        // Move everything up\n        memmove(remove_pos, after_pos, strlen(after_pos) + 1);\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "common/string_calls.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2020\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * generic string handling calls\n */\n\n#if !defined(STRING_CALLS_H)\n#define STRING_CALLS_H\n\n#include \"arch.h\"\n\n/**\n * Map a character to a string value\n *\n * This structure is used by g_format_info_string() to specify the\n * string which could be output for %'ch', where ch is a character\n */\nstruct info_string_tag\n{\n    char ch;\n    const char *val;\n};\n\n#define INFO_STRING_END_OF_LIST { '\\0', NULL }\n\n/**\n * Map a bitmask to a string value\n *\n *\n * This structure is used by g_bitmask_to_str() to specify the\n * string for each bit in the bitmask\n */\nstruct bitmask_string\n{\n    int mask;\n    const char *str;\n};\n\n#define BITMASK_STRING_END_OF_LIST { 0, NULL }\n\n/**\n * Map a bitmask to a char value\n *\n *\n * This structure is used by g_bitmask_to_charstr() to specify the\n * char for each bit in the bitmask\n */\nstruct bitmask_char\n{\n    int mask;\n    char c;\n};\n\n#define BITMASK_CHAR_END_OF_LIST { 0, '\\0' }\n\nenum\n{\n    // See g_sig2text()\n    // Must be able to hold \"SIG#%d\" for INT_MIN\n    //\n    // ((sizeof(int) * 5 + 1) / 2) provides a very slight overestimate of\n    // the bytes requires to store a decimal expansion of 'int':-\n    // sizeof  INT_MAX     display bytes   ((sizeof(int) * 5 + 1)\n    // (int)               needed           / 2)\n    // ------  -------     -------------   ---------------------------\n    // 1       127         3                3\n    // 2       32767       5                5\n    // 3       8388607     7                8\n    // 4       2147483637  10              10\n    // 8       9*(10**18)  19              20\n    // 16      2*(10**38)  39              40\n    // 32      6*(10**76)  77              80\n    MAXSTRSIGLEN =  (3 + 1 + 1 + ((sizeof(int) * 5 + 1) / 2) + 1)\n};\n\n/*\n * Significant Universal Character Set (Unicode) characters\n */\nenum\n{\n    UCS_WHITE_SQUARE  = 0x25a1,\n    UCS_REPLACEMENT_CHARACTER  = 0xfffd\n};\n\n/**\n * Processes a format string for general info\n *\n * @param[out] dest Destination buffer\n * @param[in] len Length of buffer, including space for a terminator\n * @param[in] format Format string to process\n * @param[in] map Array of struct info_string_tag.\n *\n * Where a '%<ch>' is encountered in the format string, the map is scanned\n * and the corresponding string is copied instead of '%<ch>'.\n *\n * '%%' is always replaced with a single '%' in the output. %<ch> strings\n * not present in the map are ignored.\n *\n * The map is terminated with INFO_STRING_END_OF_LIST\n *\n * Caller can check for buffer truncation by comparing the result with\n * the buffer length (as in snprintf())\n */\nunsigned int\ng_format_info_string(char *dest, unsigned int len,\n                     const char *format,\n                     const struct info_string_tag map[]);\n\n\n/**\n * Converts a boolean to a string for output\n *\n * @param[in] value Value to convert\n * @return String representation\n */\nconst char *\ng_bool2text(int value);\n\n/**\n * Converts a string to a boolean value\n *\n * @param[in] s String to convert\n * @return machine representation\n */\nint\ng_text2bool(const char *s);\n\n/**\n * Joins an array of strings into a single string.\n *\n * Note: The joiner is placed between each source string. The joiner is not\n *      placed after the last source string. If there is only one source string,\n *      then the result string will be equal to the source string.\n *\n * Note: any content that is present in dest will be overwritten with the new\n *      joined string.\n *\n * Note: If the destination array is not large enough to hold the entire\n *      contents of the joined string, then the joined string will be truncated\n *      to fit in the destination array.\n *\n * @param[out] dest The destination array to write the joined string into.\n * @param[in] dest_len The max number of characters to write to the destination\n *      array including the terminating null. Must be > 0\n * @param[in] joiner The string to concatenate between each source string.\n *      The joiner string may be NULL which is processed as a zero length string.\n * @param[in] src An array of strings to join. The array must be non-null.\n *      Array items may be NULL and are processed as zero length strings.\n * @param[in] src_len The number of strings to join in the src array. Must be > 0\n * @return A pointer to the beginning of the joined string (ie. returns dest).\n */\nchar *\ng_strnjoin(char *dest, int dest_len, const char *joiner, const char *src[], int src_len);\n\n/**\n * Converts a binary array into a hux dump suitable for displaying to a user.\n *\n * The format of the hex dump is:\n * 0000   01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16   ................\n * /\\     /\\                                                /\\\n * |      |                                                 |\n * |      |                                                 ascii representation of bytes\n * |      hex representation of bytes\n * offset from beginning of the byte array in hex\n *\n * Note: the ascii representation uses '.' for all non-printable\n * characters (eg. below 32 or above 127).\n *\n * Note: the string contains embedded new lines, but is not new line terminated.\n *\n * @param[in] src Value to convert\n * @param[in] len The number of bytes in src to convert\n * @return string containing the hex dump that must be free'd by the caller\n */\nchar *\ng_bytes_to_hexdump(const char *src, int len);\n\n/**\n * Converts an X11 display number to a display string\n *\n * @param display_num X11 display unmber\n * @param buff Buffer for result\n * @param bufflen size of above\n * @return != 0 if the result doesn't fit\n */\nint\ng_get_display_string_from_x11_display(int display_num,\n                                      char buff[], unsigned int bufflen);\n/**\n * Converts a display string to an X11 display number\n *\n * @param display_str Display string\n * @return X11 display number, or -1 if the display string isn't X11\n */\nint\ng_get_x11_display_from_display_string(const char *display_str);\n\n/**\n * Extracts the display string from either DISPLAY or WAYLAND_DISPLAY\n *\n * @param buff Buffer for result\n * @param bufflen Length of above buffer\n *\n * Returned buffer will be (e.g.) \"X11-10\" for X11 or \"wayland-1\" for Wayland\n *\n * @result != 0 if the string could not be found or parsed\n */\nint\ng_get_display_string(char buff[], unsigned int bufflen);\n\n/**\n * Converts a bitmask into a string for output purposes\n *\n * Similar to g_bitmask_to_charstr(), but tokens are strings, separated\n * by delimiters.\n *\n * @param bitmask Bitmask to convert\n * @param bitdefs Definitions for strings for bits\n * @param delim Delimiter to use between strings\n * @param buff Output buff\n * @param bufflen Length of buff, including terminator '`\\0'\n *\n * @return Total length excluding terminator which would be written, as\n *         in snprintf(). Can be used to check for overflow\n *\n * @note Any undefined bits in the bitmask are appended to the output as\n *       a hexadecimal constant.\n */\nint\ng_bitmask_to_str(int bitmask, const struct bitmask_string bitdefs[],\n                 char delim, char *buff, int bufflen);\n\n/***\n * Converts a string containing a series of tokens to a bitmask.\n *\n * Similar to g_charstr_to_bitmask(), but tokens are strings, separated\n * by delimiters.\n *\n * @param str Input string\n * @param bitdefs Array mapping tokens to bitmask values\n * @param delim Delimiter for tokens in str\n * @param[out] unrecognised Buffer for any unrecognised tokens\n * @param unrecognised_len Length of unrecognised including '\\0';\n * @return bitmask value for recognised tokens\n */\nint\ng_str_to_bitmask(const char *str, const struct bitmask_string bitdefs[],\n                 const char *delim, char *unrecognised,\n                 int unrecognised_len);\n\n/**\n * Converts a bitmask into a string for output purposes\n *\n * Similar to g_bitmask_to_str(), but tokens are individual characters, and\n * there are no delimiters.\n *\n * @param bitmask Bitmask to convert\n * @param bitdefs Definitions for strings for bits\n * @param buff Output buff\n * @param bufflen Length of buff, including terminator '`\\0'\n * @param[out] rest Any unused bits which weren't covered by bitdefs.\n *                  May be NULL.\n *\n * @return Total length excluding terminator which would be written, as\n *         in snprintf(). Can be used to check for overflow\n *\n * @note Any undefined bits in the bitmask are appended to the output as\n *       a hexadecimal constant.\n */\nint\ng_bitmask_to_charstr(int bitmask, const struct bitmask_char bitdefs[],\n                     char *buff, int bufflen, int *rest);\n\n/***\n * Converts a string containing a series of characters to a bitmask.\n *\n * Similar to g_str_to_bitmask(), but tokens are individual characters, and\n * there are no delimiters.\n *\n * @param str Input string\n * @param bitdefs Array mapping tokens to bitmask values\n * @param[out] unrecognised Buffer for any unrecognised tokens\n * @param unrecognised_len Length of unrecognised including '\\0';\n * @return bitmask value for recognised tokens\n */\nint\ng_charstr_to_bitmask(const char *str, const struct bitmask_char bitdefs[],\n                     char *unrecognised, int unrecognised_len);\n\nint      g_strlen(const char *text);\nchar    *g_strchr(const char *text, int c);\nchar    *g_strrchr(const char *text, int c);\nchar    *g_strnchr(const char *text, int c, int len);\nchar    *g_strcpy(char *dest, const char *src);\nchar    *g_strncpy(char *dest, const char *src, int len);\nchar    *g_strcat(char *dest, const char *src);\nchar    *g_strncat(char *dest, const char *src, int len);\nchar    *g_strdup(const char *in);\nchar    *g_strndup(const char *in, const unsigned int maxlen);\nint      g_strcmp(const char *c1, const char *c2);\nint      g_strncmp(const char *c1, const char *c2, int len);\nint      g_strncmp_d(const char *c1, const char *c2, const char delim, int len);\nint      g_strcasecmp(const char *c1, const char *c2);\nint      g_strncasecmp(const char *c1, const char *c2, int len);\nint      g_atoi(const char *str);\n\n/* Non-standard but useful functions */\n#if !defined(HAVE_STRLCPY)\nsize_t   strlcpy(char *dst, const char *src, size_t dsize);\n#endif\n\n/**\n * Extends g_atoi(), Converts decimal and hexadecimal number String to integer\n *\n * Prefix hexadecimal numbers with '0x'\n *\n * @param str String to convert to an integer\n * @return int Integer expression of a string\n */\nint      g_atoix(const char *str);\n/**\n * Converts a hex string to an integer\n * @param str pointer to Hex string containing only hex digits\n * @return value, converted from hex\n *\n * This function is intended to be used as an analogue to the standard\n * function atoi(). It performs no error checking of its own\n */\nunsigned int g_htoi(const char *str);\nint      g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str,\n                           int bytes_out_str);\nint      g_pos(const char *str, const char *to_find);\nchar    *g_strstr(const char *haystack, const char *needle);\n\n/** trim spaces and tabs, anything <= space\n *\n * @param str (assumed to be UTF-8)\n * @param trim_flags 1 trim left, 2 trim right, 3 trim both, 4 trim through\n * @return != 0 - trim_flags not recognised\n * this will always shorten the string or not change it */\nint      g_strtrim(char *str, int trim_flags);\n\n/**\n * Maps a signal number to a string, i.e. SIGHUP -> \"SIGHUP\"\n *\n * @param signum Signal number\n * @param sigstr buffer for result\n * @return sigstr, for convenience\n *\n * Buffer is assumed to be at least MAXSTRSIGLEN\n *\n * The string \"SIG#<num>\" is returned for unrecognised signums\n */\nchar    *g_sig2text(int signum, char sigstr[]);\n\n/**\n * Get the next Unicode character from a UTF-8 string\n *\n * @param utf8str_ref UTF 8 string [by reference]\n * @param len_ref Length of string [by reference] or NULL\n * @return Unicode character\n *\n * On return, utf8str and len are updated to point past the decoded character.\n * Unrecognised characters are mapped to UCS_REPLACEMENT_CHARACTER\n *\n * len is not needed if your utf8str has a terminator, or is known to\n * be well-formed.\n */\nchar32_t\nutf8_get_next_char(const char **utf8str_ref, unsigned int *len_ref);\n\n/**\n * Convert a Unicode character to UTF-8\n * @param c32 Unicode character\n * @param u8str buffer containing at least MAXLEN_UTF8_CHAR  bytes for result\n * @return Number of bytes written to u8str. Can be NULL if only the\n *         length is needed.\n *\n * The bytes written to u8str are unterminated\n */\n#define MAXLEN_UTF8_CHAR 4\nunsigned int\nutf_char32_to_utf8(char32_t c32, char *u8str);\n\n/**\n * Returns the number of Unicode characters in a UTF-8 string\n * @param utf8str UTF-8 string\n * @result Number of Unicode characters in the string (terminator not included)\n */\nunsigned int\nutf8_char_count(const char *utf8str);\n\n/**\n * Returns the number of UTF-16 words required to store a UTF-8 string\n * @param utf8str UTF-8 string\n * @param len Length of UTF-8 string\n * @result number of words to store UTF-8 string as UTF-16.\n */\nunsigned int\nutf8_as_utf16_word_count(const char *utf8str, unsigned int len);\n\n/**\n * Add a Unicode character into a UTF-8 string\n * @param utf8str Pointer to UTF-8 string\n * @param len Length of buffer for UTF-8 string (includes NULL)\n * @param c32 character to add\n * @param index Where to add the codepoint\n * @return 1 for success, 0 if no character was inserted\n *\n * This routine has to parse the string as it goes, so can be slow.\n */\nint\nutf8_add_char_at(char *utf8str, unsigned int len, char32_t c32,\n                 unsigned int index);\n\n/**\n * Remove a Unicode character from a UTF-8 string\n * @param utf8str Pointer to UTF-8 string\n * @param index Where to remove the codepoint from (0-based)\n * @return Character removed, or 0 if no character was removed\n *\n * This routine has to parse the string as it goes, so can be slow.\n */\nchar32_t\nutf8_remove_char_at(char *utf8str, unsigned int index);\n\n#endif\n"
  },
  {
    "path": "common/thread_calls.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * thread calls\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#if defined(_WIN32)\n#include <windows.h>\n#elif defined(__APPLE__)\n#include <pthread.h>\n#include <dispatch/dispatch.h>\n#include <dispatch/time.h>\n#else\n#include <pthread.h>\n#include <semaphore.h>\n#endif\n#include \"arch.h\"\n#include \"log.h\"\n#include \"thread_calls.h\"\n#include \"os_calls.h\"\n\n\n/*****************************************************************************/\n/* returns error */\n#if defined(_WIN32)\nint\ntc_thread_create(unsigned long (__stdcall *start_routine)(void *), void *arg)\n{\n    int rv = 0;\n    DWORD thread_id = 0;\n    HANDLE thread = (HANDLE)0;\n\n    /* CreateThread returns handle or zero on error */\n    thread = CreateThread(0, 0, start_routine, arg, 0, &thread_id);\n    rv = !thread;\n    CloseHandle(thread);\n    return rv;\n}\n#else\nint\ntc_thread_create(void *(* start_routine)(void *), void *arg)\n{\n    int rv = 0;\n    pthread_t thread = (pthread_t)0;\n\n    g_memset(&thread, 0x00, sizeof(pthread_t));\n\n    /* pthread_create returns error */\n    rv = pthread_create(&thread, 0, start_routine, arg);\n\n    if (!rv)\n    {\n        rv = pthread_detach(thread);\n    }\n\n    return rv;\n}\n#endif\n\n/*****************************************************************************/\ntbus\ntc_get_threadid(void)\n{\n#if defined(_WIN32)\n    return (tbus)GetCurrentThreadId();\n#else\n    return (tbus)pthread_self();\n#endif\n}\n\n/*****************************************************************************/\n/* returns boolean */\nint\ntc_threadid_equal(tbus tid1, tbus tid2)\n{\n#if defined(_WIN32)\n    return tid1 == tid2;\n#else\n    return pthread_equal((pthread_t)tid1, (pthread_t)tid2);\n#endif\n}\n\n/*****************************************************************************/\ntbus\ntc_mutex_create(void)\n{\n#if defined(_WIN32)\n    return (tbus)CreateMutex(0, 0, 0);\n#else\n    pthread_mutex_t *lmutex;\n\n    lmutex = (pthread_mutex_t *)g_malloc(sizeof(pthread_mutex_t), 0);\n    pthread_mutex_init(lmutex, 0);\n    return (tbus)lmutex;\n#endif\n}\n\n/*****************************************************************************/\nvoid\ntc_mutex_delete(tbus mutex)\n{\n#if defined(_WIN32)\n    CloseHandle((HANDLE)mutex);\n#else\n    pthread_mutex_t *lmutex;\n\n    lmutex = (pthread_mutex_t *)mutex;\n    if (lmutex != NULL)\n    {\n        pthread_mutex_destroy(lmutex);\n        g_free(lmutex);\n    }\n#endif\n}\n\n/*****************************************************************************/\nint\ntc_mutex_lock(tbus mutex)\n{\n#if defined(_WIN32)\n    WaitForSingleObject((HANDLE)mutex, INFINITE);\n#else\n    if (mutex != 0)\n    {\n        pthread_mutex_lock((pthread_mutex_t *)mutex);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"Attempt made to lock NULL mutex\");\n    }\n#endif\n    return 0;\n}\n\n/*****************************************************************************/\nint\ntc_mutex_unlock(tbus mutex)\n{\n    int rv = 0;\n#if defined(_WIN32)\n    ReleaseMutex((HANDLE)mutex);\n#else\n\n    if (mutex != 0)\n    {\n        rv = pthread_mutex_unlock((pthread_mutex_t *)mutex);\n    }\n\n#endif\n    return rv;\n}\n\n/*****************************************************************************/\ntbus\ntc_sem_create(int init_count)\n{\n#if defined(_WIN32)\n    HANDLE sem;\n\n    sem = CreateSemaphore(0, init_count, init_count + 10, 0);\n    return (tbus)sem;\n#elif defined(__APPLE__)\n    dispatch_semaphore_t sem = dispatch_semaphore_create(init_count);\n    return (tbus)sem;\n#else\n    sem_t *sem = (sem_t *)NULL;\n\n    sem = (sem_t *)g_malloc(sizeof(sem_t), 0);\n    sem_init(sem, 0, init_count);\n    return (tbus)sem;\n#endif\n}\n\n/*****************************************************************************/\nvoid\ntc_sem_delete(tbus sem)\n{\n#if defined(_WIN32)\n    CloseHandle((HANDLE)sem);\n#elif defined(__APPLE__)\n    dispatch_release((dispatch_semaphore_t)sem);\n#else\n    sem_t *lsem;\n\n    lsem = (sem_t *)sem;\n    sem_destroy(lsem);\n    g_free(lsem);\n#endif\n}\n\n/*****************************************************************************/\nint\ntc_sem_dec(tbus sem)\n{\n#if defined(_WIN32)\n    WaitForSingleObject((HANDLE)sem, INFINITE);\n    return 0;\n#elif defined(__APPLE__)\n    dispatch_semaphore_wait((dispatch_semaphore_t)sem, DISPATCH_TIME_FOREVER);\n    return 0;\n#else\n    sem_wait((sem_t *)sem);\n    return 0;\n#endif\n}\n\n/*****************************************************************************/\nint\ntc_sem_inc(tbus sem)\n{\n#if defined(_WIN32)\n    ReleaseSemaphore((HANDLE)sem, 1, 0);\n    return 0;\n#elif defined(__APPLE__)\n    dispatch_semaphore_signal((dispatch_semaphore_t)sem);\n    return 0;\n#else\n    sem_post((sem_t *)sem);\n    return 0;\n#endif\n}\n"
  },
  {
    "path": "common/thread_calls.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * thread calls\n */\n\n#if !defined(THREAD_CALLS_H)\n#define THREAD_CALLS_H\n\n#include \"arch.h\"\n\nint\ntc_thread_create(THREAD_RV (THREAD_CC *start_routine)(void *), void *arg);\ntbus\ntc_get_threadid(void);\nint\ntc_threadid_equal(tbus tid1, tbus tid2);\ntbus\ntc_mutex_create(void);\nvoid\ntc_mutex_delete(tbus mutex);\nint\ntc_mutex_lock(tbus mutex);\nint\ntc_mutex_unlock(tbus mutex);\ntbus\ntc_sem_create(int init_count);\nvoid\ntc_sem_delete(tbus sem);\nint\ntc_sem_dec(tbus sem);\nint\ntc_sem_inc(tbus sem);\n\n#endif\n"
  },
  {
    "path": "common/timers.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2025\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file common/timers.h\n * @brief Timers and related functions (declarations)\n * @author Matt Burt\n  */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"os_calls.h\"\n#include \"timers.h\"\n\nstruct timers_oneshot\n{\n    unsigned int add_time;  // Time event was added from_g_get_elapsed_ms()\n    int trigger_time;\n};\n\n/******************************************************************************/\nstruct timers_oneshot *\ntimers_oneshot_init(int ms)\n{\n    struct timers_oneshot *t = (struct timers_oneshot *)malloc(sizeof(*t));\n    if (t != NULL)\n    {\n        t->add_time = g_get_elapsed_ms();\n        t->trigger_time = (ms <= 0) ? 0 : ms;\n    }\n    return t;\n}\n\n/******************************************************************************/\nint\ntimers_oneshot_get_remaining(struct timers_oneshot *timer,\n                             unsigned int now)\n{\n    int rv = -1;\n    if (timer != NULL)\n    {\n        if (timer->trigger_time == 0)\n        {\n            rv = 0;\n        }\n        else\n        {\n            rv = timer->trigger_time - (int)(now - timer->add_time);\n            if (rv <= 0)\n            {\n                rv = 0;\n                // (pathological) Make sure the timer doesn't stop\n                // triggering if it isn't attended to for the rollover\n                // period (~20 days for a 32-bit timer).\n                timer->trigger_time = 0;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nvoid\ntimers_oneshot_update_poll(struct timers_oneshot *timer, unsigned int now,\n                           int *timeout)\n{\n    if (timer != NULL && timeout != NULL)\n    {\n        int remaining = timers_oneshot_get_remaining(timer, now);\n        if (*timeout < 0 || *timeout > remaining)\n        {\n            *timeout = remaining;\n        }\n    }\n}\n"
  },
  {
    "path": "common/timers.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2025\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file common/timers.h\n * @brief Timers and related functions (declarations)\n * @author Matt Burt\n  */\n\n#ifndef TIMERS_H\n#define TIMERS_H\n\n#include \"arch.h\"\n\nstruct timers_oneshot;\n\n/**\n * Initialise a one-shot timer\n * @param ms Milliseconds until timer fires (>= 0)\n * @return pointer to timer\n *\n * Returns NULL if no memory.\n *\n * When the timer is no longer required, it can simply be passed to free()\n */\nstruct timers_oneshot *\ntimers_oneshot_init(int ms);\n\n/**\n * Return ms remaining on a one-shot timer\n * @param timer pointer to timer (or NULL)\n * @param now Value of g_get_elapsed_ms()\n * @return remaining ms\n *\n * Once this routine has returned 0 for a particular timer, it will never\n * return anything else. Don't pass anything to 'now' apart from a recent\n * value from g_get_elapsed_ms()\n *\n * If the timer is NULL, -1 is returned.\n */\nint\ntimers_oneshot_get_remaining(struct timers_oneshot *timer,\n                             unsigned int now);\n\n/**\n * Variant of timers_oneshot_get_remaining() for g_obj_wait()\n * @param timer pointer to timer (or NULL)\n * @param now Value of g_get_elapsed_ms()\n * @param[in,out] timeout timeout\n *\n * Use this to update a timeout passed to g_obj_wait() (or poll()). The\n * timeout is updated if the timer will fire before the current timeout.\n */\nvoid\ntimers_oneshot_update_poll(struct timers_oneshot *timer, unsigned int now,\n                           int *timeout);\n\n#endif // TIMERS_H\n"
  },
  {
    "path": "common/trans.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * generic transport\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <errno.h>\n\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"trans.h\"\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"ssl_calls.h\"\n#include \"log.h\"\n\n#define MAX_SBYTES 0\n\n/** Time between polls of is_term when connecting */\n#define CONNECT_TERM_POLL_MS 3000\n/** Time we wait before another connect() attempt if one fails immediately */\n#define CONNECT_DELAY_ON_FAIL_MS 2000\n\n/*****************************************************************************/\nstatic int\ntrans_tls_recv(struct trans *self, char *ptr, int len)\n{\n    if (self->tls == NULL)\n    {\n        return 1;\n    }\n    return ssl_tls_read(self->tls, ptr, len);\n}\n\n/*****************************************************************************/\nstatic int\ntrans_tls_send(struct trans *self, const char *data, int len)\n{\n    if (self->tls == NULL)\n    {\n        return 1;\n    }\n    return ssl_tls_write(self->tls, data, len);\n}\n\n/*****************************************************************************/\nstatic int\ntrans_tls_can_recv(struct trans *self, int sck, int millis)\n{\n    if (self->tls == NULL)\n    {\n        return 1;\n    }\n    return ssl_tls_can_recv(self->tls, sck, millis);\n}\n\n/*****************************************************************************/\nstatic int\ntrans_tcp_recv(struct trans *self, char *ptr, int len)\n{\n    return g_tcp_recv(self->sck, ptr, len, 0);\n}\n\n/*****************************************************************************/\nstatic int\ntrans_tcp_send(struct trans *self, const char *data, int len)\n{\n    return g_tcp_send(self->sck, data, len, 0);\n}\n\n/*****************************************************************************/\nstatic int\ntrans_tcp_can_recv(struct trans *self, int sck, int millis)\n{\n    return g_sck_can_recv(sck, millis);\n}\n\n/*****************************************************************************/\nstruct trans *\ntrans_create(int mode, int in_size, int out_size)\n{\n    struct trans *self = (struct trans *) NULL;\n\n    self = (struct trans *) g_malloc(sizeof(struct trans), 1);\n\n    if (self != NULL)\n    {\n        self->sck = -1;\n        make_stream(self->in_s);\n        init_stream(self->in_s, in_size);\n        make_stream(self->out_s);\n        init_stream(self->out_s, out_size);\n        self->mode = mode;\n        self->tls = 0;\n        /* assign tcp calls by default */\n        self->trans_recv = trans_tcp_recv;\n        self->trans_send = trans_tcp_send;\n        self->trans_can_recv = trans_tcp_can_recv;\n    }\n\n    return self;\n}\n\n/*****************************************************************************/\nvoid\ntrans_delete(struct trans *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n\n    /* Call the user-specified destructor if one exists */\n    if (self->extra_destructor != NULL)\n    {\n        self->extra_destructor(self);\n    }\n\n    free_stream(self->in_s);\n    free_stream(self->out_s);\n\n    if (self->sck >= 0)\n    {\n        g_tcp_close(self->sck);\n    }\n\n    self->sck = -1;\n\n    if (self->listen_filename != 0)\n    {\n        g_file_delete(self->listen_filename);\n        g_free(self->listen_filename);\n    }\n\n    if (self->tls != 0)\n    {\n        ssl_tls_delete(self->tls);\n    }\n\n    g_free(self);\n}\n\n/*****************************************************************************/\nvoid\ntrans_delete_from_child(struct trans *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n\n    if (self->listen_filename != 0)\n    {\n        g_free(self->listen_filename);\n        self->listen_filename = 0;\n    }\n\n    trans_delete(self);\n}\n\n/*****************************************************************************/\nint\ntrans_get_wait_objs(struct trans *self, tbus *objs, int *count)\n{\n    if (self == 0)\n    {\n        return 1;\n    }\n\n    if (self->status != TRANS_STATUS_UP)\n    {\n        return 1;\n    }\n\n    objs[*count] = self->sck;\n    (*count)++;\n\n    if (self->tls != NULL && (objs[*count] = ssl_get_rwo(self->tls)) != 0)\n    {\n        (*count)++;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\ntrans_get_wait_objs_rw(struct trans *self, tbus *robjs, int *rcount,\n                       tbus *wobjs, int *wcount, int *timeout)\n{\n    if (self == 0)\n    {\n        return 1;\n    }\n\n    if (self->status != TRANS_STATUS_UP)\n    {\n        return 1;\n    }\n\n    if ((self->si != 0) && (self->si->source[self->my_source] > MAX_SBYTES))\n    {\n    }\n    else\n    {\n        if (trans_get_wait_objs(self, robjs, rcount) != 0)\n        {\n            return 1;\n        }\n    }\n\n    if (self->wait_s != 0)\n    {\n        wobjs[*wcount] = self->sck;\n        (*wcount)++;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\ntrans_send_waiting(struct trans *self, int block)\n{\n    struct stream *temp_s;\n    int bytes;\n    int sent;\n    int timeout;\n    int cont;\n\n    timeout = block ? 100 : 0;\n    cont = 1;\n    while (cont)\n    {\n        if (self->wait_s != 0)\n        {\n            temp_s = self->wait_s;\n            if (g_tcp_can_send(self->sck, timeout))\n            {\n                bytes = (int) (temp_s->end - temp_s->p);\n                sent = self->trans_send(self, temp_s->p, bytes);\n                if (sent > 0)\n                {\n                    temp_s->p += sent;\n                    if (temp_s->source != 0)\n                    {\n                        temp_s->source[0] -= sent;\n                    }\n                    if (temp_s->p >= temp_s->end)\n                    {\n                        self->wait_s = temp_s->next;\n                        free_stream(temp_s);\n                    }\n                }\n                else if (sent == 0)\n                {\n                    return 1;\n                }\n                else\n                {\n                    if (!g_tcp_last_error_would_block(self->sck))\n                    {\n                        return 1;\n                    }\n                }\n            }\n            else if (block)\n            {\n                /* check for term here */\n                if (self->is_term != 0)\n                {\n                    if (self->is_term())\n                    {\n                        /* term */\n                        return 1;\n                    }\n                }\n            }\n        }\n        else\n        {\n            break;\n        }\n        cont = block;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\ntrans_check_wait_objs(struct trans *self)\n{\n    tbus in_sck;\n    struct trans *in_trans = (struct trans *) NULL;\n    int read_bytes;\n    unsigned int to_read;\n    unsigned int read_so_far;\n    int rv = 0;\n    enum xrdp_source cur_source;\n\n    if (self == 0)\n    {\n        return 1;\n    }\n\n    if (self->status != TRANS_STATUS_UP)\n    {\n        return 1;\n    }\n\n    rv = 0;\n\n    if (self->type1 == TRANS_TYPE_LISTENER) /* listening */\n    {\n        if (g_sck_can_recv(self->sck, 0))\n        {\n            in_sck = g_sck_accept(self->sck);\n            if (in_sck == -1)\n            {\n                if (g_tcp_last_error_would_block(self->sck))\n                {\n                    /* ok, but shouldn't happen */\n                }\n                else\n                {\n                    /* error */\n                    self->status = TRANS_STATUS_DOWN;\n                    return 1;\n                }\n            }\n\n            if (in_sck != -1)\n            {\n                if (self->trans_conn_in != 0) /* is function assigned */\n                {\n                    in_trans = trans_create(self->mode, self->in_s->size,\n                                            self->out_s->size);\n                    in_trans->sck = in_sck;\n                    in_trans->type1 = TRANS_TYPE_SERVER;\n                    in_trans->status = TRANS_STATUS_UP;\n                    in_trans->is_term = self->is_term;\n                    g_file_set_cloexec(in_sck, 1);\n                    g_sck_set_non_blocking(in_sck);\n                    if (self->trans_conn_in(self, in_trans) != 0)\n                    {\n                        trans_delete(in_trans);\n                    }\n                }\n                else\n                {\n                    g_tcp_close(in_sck);\n                }\n            }\n        }\n    }\n    else /* connected server or client (2 or 3) */\n    {\n        if (self->si != 0 && self->si->source[self->my_source] > MAX_SBYTES)\n        {\n        }\n        else if (self->trans_can_recv(self, self->sck, 0))\n        {\n            /* CVE-2022-23479 - check a malicious caller hasn't managed\n             * to set the header_size to an unreasonable value */\n            if (self->header_size > (unsigned int)self->in_s->size)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"trans_check_wait_objs: Reading %u bytes beyond buffer\",\n                    self->header_size - (unsigned int)self->in_s->size);\n                self->status = TRANS_STATUS_DOWN;\n                return 1;\n            }\n\n            cur_source = XRDP_SOURCE_NONE;\n            if (self->si != 0)\n            {\n                cur_source = self->si->cur_source;\n                self->si->cur_source = self->my_source;\n            }\n            read_so_far = self->in_s->end - self->in_s->data;\n            to_read = self->header_size - read_so_far;\n\n            if (to_read > 0)\n            {\n                read_bytes = self->trans_recv(self, self->in_s->end, to_read);\n\n                if (read_bytes == -1)\n                {\n                    if (g_tcp_last_error_would_block(self->sck))\n                    {\n                        /* ok, but shouldn't happen */\n                    }\n                    else\n                    {\n                        /* error */\n                        self->status = TRANS_STATUS_DOWN;\n                        if (self->si != 0)\n                        {\n                            self->si->cur_source = cur_source;\n                        }\n                        return 1;\n                    }\n                }\n                else if (read_bytes == 0)\n                {\n                    /* error */\n                    self->status = TRANS_STATUS_DOWN;\n                    if (self->si != 0)\n                    {\n                        self->si->cur_source = cur_source;\n                    }\n                    return 1;\n                }\n                else\n                {\n                    self->in_s->end += read_bytes;\n                }\n            }\n\n            read_so_far = self->in_s->end - self->in_s->data;\n\n            if (read_so_far == self->header_size)\n            {\n                if (self->trans_data_in != 0)\n                {\n                    rv = self->trans_data_in(self);\n                    if (self->no_stream_init_on_data_in == 0)\n                    {\n                        init_stream(self->in_s, 0);\n                    }\n                }\n            }\n            if (self->si != 0)\n            {\n                self->si->cur_source = cur_source;\n            }\n        }\n        if (trans_send_waiting(self, 0) != 0)\n        {\n            /* error */\n            self->status = TRANS_STATUS_DOWN;\n            return 1;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\ntrans_force_read_s(struct trans *self, struct stream *in_s, int size)\n{\n    int rcvd;\n\n    if (self->status != TRANS_STATUS_UP ||\n            size < 0 || !s_check_rem_out(in_s, size))\n    {\n        return 1;\n    }\n\n    while (size > 0)\n    {\n        rcvd = self->trans_recv(self, in_s->end, size);\n        if (rcvd == -1)\n        {\n            if (g_tcp_last_error_would_block(self->sck))\n            {\n                if (!self->trans_can_recv(self, self->sck, 100))\n                {\n                    /* check for term here */\n                    if (self->is_term != 0)\n                    {\n                        if (self->is_term())\n                        {\n                            /* term */\n                            self->status = TRANS_STATUS_DOWN;\n                            return 1;\n                        }\n                    }\n                }\n            }\n            else\n            {\n                /* error */\n                self->status = TRANS_STATUS_DOWN;\n                return 1;\n            }\n        }\n        else if (rcvd == 0)\n        {\n            /* error */\n            self->status = TRANS_STATUS_DOWN;\n            return 1;\n        }\n        else\n        {\n            in_s->end += rcvd;\n            size -= rcvd;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\ntrans_force_read(struct trans *self, int size)\n{\n    return trans_force_read_s(self, self->in_s, size);\n}\n\n/*****************************************************************************/\nint\ntrans_force_write_s(struct trans *self, struct stream *out_s)\n{\n    int size;\n    int total;\n    int sent;\n\n    if (self->status != TRANS_STATUS_UP)\n    {\n        return 1;\n    }\n    size = (int) (out_s->end - out_s->data);\n    total = 0;\n    if (trans_send_waiting(self, 1) != 0)\n    {\n        self->status = TRANS_STATUS_DOWN;\n        return 1;\n    }\n    while (total < size)\n    {\n        sent = self->trans_send(self, out_s->data + total, size - total);\n        if (sent == -1)\n        {\n            if (g_tcp_last_error_would_block(self->sck))\n            {\n                if (!g_tcp_can_send(self->sck, 100))\n                {\n                    /* check for term here */\n                    if (self->is_term != 0)\n                    {\n                        if (self->is_term())\n                        {\n                            /* term */\n                            self->status = TRANS_STATUS_DOWN;\n                            return 1;\n                        }\n                    }\n                }\n            }\n            else\n            {\n                /* error */\n                self->status = TRANS_STATUS_DOWN;\n                return 1;\n            }\n        }\n        else if (sent == 0)\n        {\n            /* error */\n            self->status = TRANS_STATUS_DOWN;\n            return 1;\n        }\n        else\n        {\n            total = total + sent;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\ntrans_force_write(struct trans *self)\n{\n    return trans_force_write_s(self, self->out_s);\n}\n\n/*****************************************************************************/\nint\ntrans_write_copy_s(struct trans *self, struct stream *out_s)\n{\n    int size;\n    int sent;\n    struct stream *wait_s;\n    struct stream *temp_s;\n    char *out_data;\n\n    if (self->status != TRANS_STATUS_UP)\n    {\n        return 1;\n    }\n    /* try to send any left over */\n    if (trans_send_waiting(self, 0) != 0)\n    {\n        /* error */\n        self->status = TRANS_STATUS_DOWN;\n        return 1;\n    }\n    out_data = out_s->data;\n    size = (int) (out_s->end - out_s->data);\n    if (self->wait_s == 0)\n    {\n        /* if no left over, try to send this new data */\n        if (g_tcp_can_send(self->sck, 0))\n        {\n            sent = self->trans_send(self, out_s->data, size);\n            if (sent > 0)\n            {\n                out_data += sent;\n                size -= sent;\n            }\n            else if (sent == 0)\n            {\n                return 1;\n            }\n            else\n            {\n                if (!g_tcp_last_error_would_block(self->sck))\n                {\n                    return 1;\n                }\n            }\n        }\n    }\n    if (size < 1)\n    {\n        return 0;\n    }\n    /* did not send right away, have to copy */\n    make_stream(wait_s);\n    init_stream(wait_s, size);\n    if (self->si != 0)\n    {\n        if ((self->si->cur_source != XRDP_SOURCE_NONE) &&\n                (self->si->cur_source != self->my_source))\n        {\n            self->si->source[self->si->cur_source] += size;\n            wait_s->source = self->si->source + self->si->cur_source;\n        }\n    }\n    out_uint8a(wait_s, out_data, size);\n    s_mark_end(wait_s);\n    wait_s->p = wait_s->data;\n    if (self->wait_s == 0)\n    {\n        self->wait_s = wait_s;\n    }\n    else\n    {\n        temp_s = self->wait_s;\n        while (temp_s->next != 0)\n        {\n            temp_s = temp_s->next;\n        }\n        temp_s->next = wait_s;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\ntrans_write_copy(struct trans *self)\n{\n    return trans_write_copy_s(self, self->out_s);\n}\n\n/*****************************************************************************/\n\n/* Shim to apply the function signature of g_tcp_connect()\n * to g_tcp_local_connect()\n */\nstatic int\nlocal_connect_shim(int fd, const char *server, const char *port)\n{\n    return g_tcp_local_connect(fd, port);\n}\n\n/**************************************************************************//**\n * Waits for an asynchronous connect to complete.\n * @param self - Transport object\n * @param start_time Start time of connect (from g_get_elapsed_ms())\n * @param timeout Total wait timeout\n * @return 0 - connect succeeded, 1 - Connect failed\n *\n * If the transport is set up for checking a termination object, this\n * on a regular basis.\n */\nstatic int\npoll_for_async_connect(struct trans *self, unsigned int start_time, int timeout)\n{\n    int rv = 1;\n    int ms_remaining = timeout - (int)(g_get_elapsed_ms() - start_time);\n\n    while (ms_remaining > 0)\n    {\n        int poll_time = ms_remaining;\n        /* Lower bound for waiting for a result */\n        if (poll_time < 100)\n        {\n            poll_time = 100;\n        }\n        /* Limit the wait time if we need to poll for termination */\n        if (self->is_term != NULL && poll_time > CONNECT_TERM_POLL_MS)\n        {\n            poll_time = CONNECT_TERM_POLL_MS;\n        }\n\n        if (g_tcp_can_send(self->sck, poll_time))\n        {\n            /* Connect has finished - return the socket status */\n            rv = g_sck_socket_ok(self->sck) ? 0 : 1;\n            break;\n        }\n\n        /* Check for program termination */\n        if (self->is_term != NULL && self->is_term())\n        {\n            break;\n        }\n\n        ms_remaining = timeout - (int)(g_get_elapsed_ms() - start_time);\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\ntrans_connect(struct trans *self, const char *server, const char *port,\n              int timeout)\n{\n    unsigned int start_time = g_get_elapsed_ms();\n    int error;\n    int ms_before_next_connect;\n    int connect_errno = 0;\n\n    /*\n     * Function pointers which we use in the main loop to avoid\n     * having to switch on the socket mode */\n    int (*f_alloc_socket)(void);\n    int (*f_connect)(int fd, const char *server, const char *port);\n\n    switch (self->mode)\n    {\n        case TRANS_MODE_TCP:\n            f_alloc_socket = g_tcp_socket;\n            f_connect = g_tcp_connect;\n            break;\n\n        case TRANS_MODE_UNIX:\n            f_alloc_socket = g_tcp_local_socket;\n            f_connect = local_connect_shim;\n            break;\n\n        default:\n            LOG(LOG_LEVEL_ERROR, \"Bad socket mode %d\", self->mode);\n            return 1;\n    }\n\n    while (1)\n    {\n        /* Check the program isn't terminating */\n        if (self->is_term != NULL && self->is_term())\n        {\n            error = 1;\n            break;\n        }\n\n        /* Allocate a new socket */\n        if (self->sck >= 0)\n        {\n            g_tcp_close(self->sck);\n        }\n        self->sck = f_alloc_socket();\n\n        if (self->sck < 0)\n        {\n            connect_errno = errno;\n            error = 1;\n            break;\n        }\n\n        /* Try to connect asynchronously */\n        g_file_set_cloexec(self->sck, 1);\n        g_tcp_set_non_blocking(self->sck);\n        error = f_connect(self->sck, server, port);\n        connect_errno = errno;\n        if (error == 0)\n        {\n            /* Connect was immediately successful */\n            break;\n        }\n\n        if (g_tcp_last_error_would_block(self->sck))\n        {\n            /* Async connect is in progress */\n            if (poll_for_async_connect(self, start_time, timeout) == 0)\n            {\n                /* Async connect was successful */\n                error = 0;\n                break;\n            }\n            /* No need to wait any more before the next connect attempt */\n            ms_before_next_connect = 0;\n        }\n        else\n        {\n            /* Connect failed immediately. Wait a bit before the next\n             * attempt */\n            ms_before_next_connect = CONNECT_DELAY_ON_FAIL_MS;\n        }\n\n        /* Have we reached the total timeout yet? */\n        int ms_left = timeout - (int)(g_get_elapsed_ms() - start_time);\n        if (ms_left <= 0)\n        {\n            error = 1;\n            break;\n        }\n\n        /* Sleep a bit before trying again */\n        if (ms_before_next_connect > 0)\n        {\n            if (ms_before_next_connect > ms_left)\n            {\n                ms_before_next_connect = ms_left;\n            }\n            g_sleep(ms_before_next_connect);\n        }\n    }\n\n    if (error != 0)\n    {\n        if (self->sck >= 0)\n        {\n            g_tcp_close(self->sck);\n            self->sck = -1;\n        }\n        /* Ensure errno is representative of the last connection attempt */\n        errno = connect_errno;\n        self->status = TRANS_STATUS_DOWN;\n    }\n    else\n    {\n        self->status = TRANS_STATUS_UP; /* ok */\n        self->type1 = TRANS_TYPE_CLIENT; /* client */\n    }\n\n    return error;\n}\n\n/*****************************************************************************/\n\n/**\n * @return 0 on success, 1 on failure\n */\nint\ntrans_listen_address(struct trans *self, const char *port, const char *address)\n{\n    if (self->sck >= 0)\n    {\n        g_tcp_close(self->sck);\n    }\n\n    if (self->mode == TRANS_MODE_TCP) /* tcp */\n    {\n        self->sck = g_tcp_socket();\n        if (self->sck < 0)\n        {\n            return 1;\n        }\n\n        g_file_set_cloexec(self->sck, 1);\n        g_tcp_set_non_blocking(self->sck);\n        g_sck_set_reuseaddr(self->sck);\n\n        if (g_tcp_bind_address(self->sck, port, address) == 0)\n        {\n            if (g_tcp_listen(self->sck) == 0)\n            {\n                self->status = TRANS_STATUS_UP; /* ok */\n                self->type1 = TRANS_TYPE_LISTENER; /* listener */\n                return 0;\n            }\n        }\n    }\n    else if (self->mode == TRANS_MODE_UNIX) /* unix socket */\n    {\n        g_free(self->listen_filename);\n        self->listen_filename = 0;\n        g_file_delete(port);\n\n        self->sck = g_tcp_local_socket();\n        if (self->sck < 0)\n        {\n            return 1;\n        }\n\n        g_file_set_cloexec(self->sck, 1);\n        g_tcp_set_non_blocking(self->sck);\n\n        if (g_tcp_local_bind(self->sck, port) == 0)\n        {\n            self->listen_filename = g_strdup(port);\n\n            if (g_tcp_listen(self->sck) == 0)\n            {\n                g_chmod_hex(port, 0x0660);\n                self->status = TRANS_STATUS_UP; /* ok */\n                self->type1 = TRANS_TYPE_LISTENER; /* listener */\n                return 0;\n            }\n        }\n    }\n    else if (self->mode == TRANS_MODE_VSOCK) /* vsock socket */\n    {\n        self->sck = g_sck_vsock_socket();\n        if (self->sck < 0)\n        {\n            return 1;\n        }\n\n        g_file_set_cloexec(self->sck, 1);\n        g_tcp_set_non_blocking(self->sck);\n\n        if (g_sck_vsock_bind_address(self->sck, port, address) == 0)\n        {\n            if (g_tcp_listen(self->sck) == 0)\n            {\n                self->status = TRANS_STATUS_UP; /* ok */\n                self->type1 = TRANS_TYPE_LISTENER; /* listener */\n                return 0;\n            }\n        }\n    }\n    else if (self->mode == TRANS_MODE_TCP4) /* tcp4 */\n    {\n        self->sck = g_tcp4_socket();\n        if (self->sck < 0)\n        {\n            return 1;\n        }\n        g_file_set_cloexec(self->sck, 1);\n        g_tcp_set_non_blocking(self->sck);\n        g_sck_set_reuseaddr(self->sck);\n        if (g_tcp4_bind_address(self->sck, port, address) == 0)\n        {\n            if (g_tcp_listen(self->sck) == 0)\n            {\n                self->status = TRANS_STATUS_UP; /* ok */\n                self->type1 = TRANS_TYPE_LISTENER; /* listener */\n                return 0;\n            }\n        }\n    }\n    else if (self->mode == TRANS_MODE_TCP6) /* tcp6 */\n    {\n        self->sck = g_tcp6_socket();\n        if (self->sck < 0)\n        {\n            return 1;\n        }\n        g_file_set_cloexec(self->sck, 1);\n        g_tcp_set_non_blocking(self->sck);\n        g_sck_set_reuseaddr(self->sck);\n        if (g_tcp6_bind_address(self->sck, port, address) == 0)\n        {\n            if (g_tcp_listen(self->sck) == 0)\n            {\n                self->status = TRANS_STATUS_UP; /* ok */\n                self->type1 = TRANS_TYPE_LISTENER; /* listener */\n                return 0;\n            }\n        }\n    }\n    return 1;\n}\n\n/*****************************************************************************/\nint\ntrans_listen(struct trans *self, const char *port)\n{\n    return trans_listen_address(self, port, \"0.0.0.0\");\n}\n\n/*****************************************************************************/\nstruct stream *\ntrans_get_in_s(struct trans *self)\n{\n    struct stream *rv = (struct stream *) NULL;\n\n    if (self == NULL)\n    {\n        rv = (struct stream *) NULL;\n    }\n    else\n    {\n        rv = self->in_s;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstruct stream *\ntrans_get_out_s(struct trans *self, int size)\n{\n    struct stream *rv = (struct stream *) NULL;\n\n    if (self == NULL)\n    {\n        rv = (struct stream *) NULL;\n    }\n    else\n    {\n        init_stream(self->out_s, size);\n        rv = self->out_s;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ntrans_set_tls_mode(struct trans *self, const char *key, const char *cert,\n                   long ssl_protocols, const char *tls_ciphers)\n{\n    self->tls = ssl_tls_create(self, key, cert);\n    if (self->tls == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"trans_set_tls_mode: ssl_tls_create malloc error\");\n        return 1;\n    }\n\n    if (ssl_tls_accept(self->tls, ssl_protocols,\n                       tls_ciphers, self->is_term) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"trans_set_tls_mode: ssl_tls_accept failed\");\n        return 1;\n    }\n\n    /* assign tls functions */\n    self->trans_recv = trans_tls_recv;\n    self->trans_send = trans_tls_send;\n    self->trans_can_recv = trans_tls_can_recv;\n\n    self->ssl_protocol = ssl_get_version(self->tls);\n    self->cipher_name = ssl_get_cipher_name(self->tls);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\ntrans_shutdown_tls_mode(struct trans *self)\n{\n    if (self->tls != NULL)\n    {\n        return ssl_tls_disconnect(self->tls);\n    }\n\n    /* assign callback back to tcp cal */\n    self->trans_recv = trans_tcp_recv;\n    self->trans_send = trans_tcp_send;\n    self->trans_can_recv = trans_tcp_can_recv;\n\n    return 0;\n}\n"
  },
  {
    "path": "common/trans.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * generic transport\n */\n\n#if !defined(TRANS_H)\n#define TRANS_H\n\n#include \"arch.h\"\n#include \"parse.h\"\n\n#define TRANS_MODE_TCP 1 /* tcp6 if defined, else tcp4 */\n#define TRANS_MODE_UNIX 2\n#define TRANS_MODE_VSOCK 3\n#define TRANS_MODE_TCP4 4 /* tcp4 only */\n#define TRANS_MODE_TCP6 6 /* tcp6 only */\n\n#define TRANS_TYPE_LISTENER 1\n#define TRANS_TYPE_SERVER 2\n#define TRANS_TYPE_CLIENT 3\n\n#define TRANS_STATUS_DOWN 0\n#define TRANS_STATUS_UP 1\n\nstruct trans; /* forward declaration */\nstruct xrdp_tls;\n\ntypedef int (*ttrans_data_in)(struct trans *self);\ntypedef int (*ttrans_conn_in)(struct trans *self,\n                              struct trans *new_self);\ntypedef int (*tis_term)(void);\ntypedef int (*trans_recv_proc) (struct trans *self, char *ptr, int len);\ntypedef int (*trans_send_proc) (struct trans *self, const char *data, int len);\ntypedef int (*trans_can_recv_proc) (struct trans *self, int sck, int millis);\n\n/* optional source info */\n\nenum xrdp_source\n{\n    XRDP_SOURCE_NONE = 0,\n    XRDP_SOURCE_CLIENT,\n    XRDP_SOURCE_SESMAN,\n    XRDP_SOURCE_CHANSRV,\n    XRDP_SOURCE_MOD,\n    XORGXRDP_SOURCE_XORG,\n    XORGXRDP_SOURCE_XRDP,\n\n    XRDP_SOURCE_MAX_COUNT\n};\n\n/*\n * @brief Provide flow control mechanism for (primarily) xrdp\n *\n * There is one of these data structures per-program.\n *\n * While input is being read from a 'struct trans' and processed, the\n * cur_source member is set to the my_source member from the transport.\n * During this processing, trans_write_copy() may be called to send output\n * on another struct trans. If this happens, and the output needs to be\n * buffered, trans_write_copy() can add the number of bytes generated by\n * the input trans to the source field for the cur_source. This allows us to\n * see how much output has been buffered for each input source.\n *\n * When the program assembles 'struct trans' objects to scan for input\n * (normally in trans_get_wait_objs()), it is able to see how much buffered\n * output is registered for each input. Inputs which have too much buffered\n * output owing are skipped, and not considered for input.\n *\n * This provides a simple means of providing back-pressure on an input\n * where the data it is providing is being processed and then sent out on\n * a much slower link.\n */\nstruct source_info\n{\n    enum xrdp_source cur_source;\n    int source[XRDP_SOURCE_MAX_COUNT];\n};\n\nstruct trans\n{\n    tbus sck; /* socket handle */\n    int mode; /* 1 tcp, 2 unix socket, 3 vsock */\n    int status;\n    int type1; /* 1 listener 2 server 3 client */\n    ttrans_data_in trans_data_in;\n    ttrans_conn_in trans_conn_in;\n    void *callback_data;\n    unsigned int header_size;\n    struct stream *in_s;\n    struct stream *out_s;\n    char *listen_filename;\n    tis_term is_term; /* used to test for exit */\n    struct stream *wait_s;\n    int no_stream_init_on_data_in;\n    int extra_flags; /* user defined */\n    void *extra_data; /* user defined */\n    void (*extra_destructor)(struct trans *); /* user defined */\n\n    struct ssl_tls *tls;\n    const char *ssl_protocol; /* e.g. TLSv1, TLSv1.1, TLSv1.2, unknown */\n    const char *cipher_name;  /* e.g. AES256-GCM-SHA384 */\n    trans_recv_proc trans_recv;\n    trans_send_proc trans_send;\n    trans_can_recv_proc trans_can_recv;\n    struct source_info *si;\n    enum xrdp_source my_source;\n};\n\nstruct trans *\ntrans_create(int mode, int in_size, int out_size);\nvoid\ntrans_delete(struct trans *self);\nvoid\ntrans_delete_from_child(struct trans *self);\nint\ntrans_get_wait_objs(struct trans *self, tbus *objs, int *count);\nint\ntrans_get_wait_objs_rw(struct trans *self,\n                       tbus *robjs, int *rcount,\n                       tbus *wobjs, int *wcount, int *timeout);\nint\ntrans_check_wait_objs(struct trans *self);\nint\ntrans_force_read_s(struct trans *self, struct stream *in_s, int size);\nint\ntrans_force_write_s(struct trans *self, struct stream *out_s);\nint\ntrans_force_read(struct trans *self, int size);\nint\ntrans_force_write(struct trans *self);\nint\ntrans_write_copy(struct trans *self);\nint\ntrans_write_copy_s(struct trans *self, struct stream *out_s);\n/**\n * Connect the transport to the specified destination\n *\n * @param self Transport\n * @param server Destination server (TCP transports only)\n * @param port TCP port, or UNIX socket to connect to\n * @param timeout in milli-seconds for the operation\n * @return 0 for success\n *\n * Multiple connection attempts may be made within the timeout period.\n *\n * If the operation is not successful, errno will have been set by\n * the last connection attempt.\n *\n * If the operation is successful, 0 is returned and self->status will\n * be TRANS_STATUS_UP\n */\nint\ntrans_connect(struct trans *self, const char *server, const char *port,\n              int timeout);\nint\ntrans_listen_address(struct trans *self, const char *port, const char *address);\nint\ntrans_listen(struct trans *self, const char *port);\nstruct stream *\ntrans_get_in_s(struct trans *self);\nstruct stream *\ntrans_get_out_s(struct trans *self, int size);\nint\ntrans_set_tls_mode(struct trans *self, const char *key, const char *cert,\n                   long ssl_protocols, const char *tls_ciphers);\nint\ntrans_shutdown_tls_mode(struct trans *self);\nint\ntrans_tcp_force_read_s(struct trans *self, struct stream *in_s, int size);\n\n#endif\n"
  },
  {
    "path": "common/unicode_defines.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/**\n * @file common/unicode_defines.h\n *\n * Defines used internally by the implementations of the Unicode routines\n */\n\n#if !defined(UNICODE_DEFINES_H)\n#define UNICODE_DEFINES_H\n\n/**\n * Is this byte a valid UTF-8 continuation character?\n */\n#define IS_VALID_CONTINUATION_CHAR(c) ((c) >= 0x80 && (c) < 0xc0)\n\n/**\n * Is this character one of the end-of-plane non-characters?\n *\n * These are U+xFFFE and U+xFFFF for x in (0..10}\n */\n#define IS_PLANE_END_NON_CHARACTER(c32) (((c32) & 0xfffe) == 0xfffe)\n\n/**\n * Is this character one of the additional non-characters?\n *\n * 32 additional non-charactersare defined in the\n * \"Arabic Presentation Forms-A\" Unicode block */\n#define IS_ARABIC_NON_CHARACTER(c32) ((c32) >= 0xfdd0 && (c32) <= 0xfdef)\n\n// Invalid characters, based on UTF-8 decoding range\n//\n// By 'invalid' we mean characters that should not be encoded or\n// decoded when switching between UTF-8 and UTF-32\n//\n// See \"UTF-8 decoder capability and stress test\" Markus Kuhn 2015-08-28\n#define INVALID_UNICODE_0_TO_7F(c) (0)   // No invalid characters\n#define INVALID_UNICODE_80_TO_7FF(c) (0) // No invalid characters\n#define INVALID_UNICODE_800_TO_FFFF(c) \\\n    (((c) >= 0xd800 && (c) <= 0xdfff) || /* Surrogate pairs */ \\\n     IS_ARABIC_NON_CHARACTER(c) || \\\n     IS_PLANE_END_NON_CHARACTER(c))\n\n#define INVALID_UNICODE_10000_TO_1FFFFF(c) \\\n    (IS_PLANE_END_NON_CHARACTER(c) || (c) > 0x10ffff)\n\n// Returns true for all 'invalid' Unicode chars\n#define INVALID_UNICODE(c) \\\n    ( \\\n      INVALID_UNICODE_0_TO_7F(c) || \\\n      INVALID_UNICODE_80_TO_7FF(c) || \\\n      INVALID_UNICODE_800_TO_FFFF(c) || \\\n      INVALID_UNICODE_10000_TO_1FFFFF(c) \\\n    )\n\n/**\n * Is this character a UTF-16 high surrogate?\n */\n#define IS_HIGH_SURROGATE(u16) (((u16) & 0xfc00) == 0xd800)\n\n/**\n * Is this character a UTF-16 low surrogate?\n */\n#define IS_LOW_SURROGATE(u16) (((u16) & 0xfc00) == 0xdc00)\n\n/**\n * Extract the UTF-16 high surrogate from a character\n */\n#define HIGH_SURROGATE_FROM_C32(c32) \\\n    (((((c32) - 0x10000) >> 10) & 0x3ff) | 0xd800)\n\n/**\n * Extract the UTF-16 low surrogate from a character\n */\n#define LOW_SURROGATE_FROM_C32(c32) (((c32) & 0x3ff) | 0xdc00)\n\n/**\n * Reconstruct a character from a UTF-16 surrogate pair\n *\n * This macro cannot return values higher than 0x10ffff\n */\n#define C32_FROM_SURROGATE_PAIR(low,high) \\\n    ((char32_t)(((high) & 0x3ff) << 10) + ((low) & 0x3ff) + 0x10000)\n\n#endif // UNICODE_DEFINES_H\n"
  },
  {
    "path": "common/xrdp_client_info.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * xrdp / xserver info / caps\n */\n\n#include \"xrdp_constants.h\"\n#include \"ms-rdpbcgr.h\"\n\n#if !defined(XRDP_CLIENT_INFO_H)\n#define XRDP_CLIENT_INFO_H\n\n/*\n * 2.2.1.3.6.1 Monitor Definition (TS_MONITOR_DEF)\n * 2.2.1.3.9.1 Monitor Attributes (TS_MONITOR_ATTRIBUTES)\n * 2.2.2.2.1 DISPLAYCONTROL_MONITOR_LAYOUT\n */\nstruct monitor_info\n{\n    /* From 2.2.1.3.6.1 Monitor Definition (TS_MONITOR_DEF) */\n    int left;\n    int top;\n    int right;\n    int bottom;\n    int flags;\n\n    /* From [MS-RDPEDISP] 2.2.2.2.1 DISPLAYCONTROL_MONITOR_LAYOUT, or\n     * [MS-RDPBCGR] 2.2.1.3.9.1 (TS_MONITOR_ATTRIBUTES) */\n    unsigned int physical_width;\n    unsigned int physical_height;\n    unsigned int orientation;\n    unsigned int desktop_scale_factor;\n    unsigned int device_scale_factor;\n\n    /* Derived setting */\n    unsigned int is_primary;\n};\n\n/* xrdp keyboard overrids */\nstruct xrdp_keyboard_overrides\n{\n    int type;\n    int subtype;\n    int layout;\n};\n\nstruct display_size_description\n{\n    unsigned int monitorCount; /* 2.2.2.2 DISPLAYCONTROL_MONITOR_LAYOUT_PDU: number of monitors detected (max = 16) */\n    struct monitor_info minfo[CLIENT_MONITOR_DATA_MAXIMUM_MONITORS]; /* client monitor data */\n    struct monitor_info minfo_wm[CLIENT_MONITOR_DATA_MAXIMUM_MONITORS]; /* client monitor data, non-negative values */\n    unsigned int session_width;\n    unsigned int session_height;\n};\n\n/* Values used for the security_layer */\n/* TODO: Make this an enum, and move it below xrdp_client_info */\n#define SECURITY_LAYER_NEGOTIATE 0\n#define SECURITY_LAYER_RDP 1\n#define SECURITY_LAYER_TLS 2\n\nenum client_resize_mode\n{\n    CRMODE_NONE,\n    CRMODE_SINGLE_SCREEN,\n    CRMODE_MULTI_SCREEN\n};\n\nenum xrdp_capture_code\n{\n    CC_SIMPLE       = 0,\n    CC_SUF_A16      = 1,\n    CC_SUF_RFX      = 2,\n    CC_SUF_A2       = 3,\n    CC_GFX_PRO      = 4,\n    CC_GFX_A2       = 5\n};\n\n/**\n * Type describing Unicode input state\n */\nenum unicode_input_state\n{\n    UIS_UNSUPPORTED = 0, ///< Client does not support Unicode\n    UIS_SUPPORTED,       ///< Client supports Unicode, but it's not active\n    UIS_ACTIVE           ///< Unicode input is active\n};\n\nenum xrdp_encoder_flags\n{\n    NONE                                   = 0,\n    ENCODE_COMPLETE                        = 1 << 0,\n    GFX_PROGRESSIVE_RFX                    = 1 << 1,\n    GFX_H264                               = 1 << 2,\n    KEY_FRAME_REQUESTED                    = 1 << 3\n};\n\n/* Size definitions for some arrays in xrdp_client_info */\nenum\n{\n    CI_KBD_MODEL_SIZE = 16,\n    CI_KBD_LAYOUT_SIZE = 16,\n    CI_KBD_VARIANT_SIZE = 16,\n    CI_KBD_OPTIONS_SIZE = 256,\n    CI_KBD_XKB_RULES_SIZE = 32\n};\n\n/**\n * Information about the xrdp client\n *\n * Note to maintainers; this structure is no longer shared with\n * xorgxrdp. See common/xup_client_info.h for that structure.\n */\nstruct xrdp_client_info\n{\n    int bpp;\n    /* bitmap cache info */\n    int cache1_entries;\n    int cache1_size;\n    int cache2_entries;\n    int cache2_size;\n    int cache3_entries;\n    int cache3_size;\n    int bitmap_cache_persist_enable; /* 0 or 2 */\n    int bitmap_cache_version; /* ored 1 = original version, 2 = v2, 4 = v3 */\n    /* pointer info */\n    int pointer_cache_entries;\n    /* other */\n    int use_bitmap_comp;\n    int use_bitmap_cache;\n    int op1; /* use smaller bitmap header, non cache */\n    int op2; /* use smaller bitmap header in bitmap cache */\n    int desktop_cache;\n    int use_compact_packets; /* rdp5 smaller packets */\n    char client_name[INFO_CLIENT_NAME_BYTES_UTF8];\n    int build;\n    int keylayout;\n    char username[INFO_CLIENT_MAX_CB_LEN];\n    char password[INFO_CLIENT_MAX_CB_LEN];\n    char domain[INFO_CLIENT_MAX_CB_LEN];\n    char program[INFO_CLIENT_MAX_CB_LEN];\n    char directory[INFO_CLIENT_MAX_CB_LEN];\n    int rdp_compression;\n    int rdp_autologin;\n    int crypt_level; /* 1, 2, 3 = low, medium, high */\n    int channels_allowed; /* 0 = no channels 1 = channels */\n    int sound_code; /* 1 = leave sound at server */\n    int is_mce;\n    int rdp5_performanceflags;\n    int brush_cache_code; /* 0 = no cache 1 = 8x8 standard cache\n                           2 = arbitrary dimensions */\n\n    int max_bpp;\n    int jpeg; /* non standard bitmap cache v2 cap */\n    int offscreen_support_level;\n    int offscreen_cache_size;\n    int offscreen_cache_entries;\n    int rfx;\n\n    /* CAPSETTYPE_RAIL */\n    int rail_support_level;\n    /* CAPSETTYPE_WINDOW */\n    int wnd_support_level;\n    int wnd_num_icon_caches;\n    int wnd_num_icon_cache_entries;\n    /* codecs */\n    int rfx_codec_id;\n    int rfx_prop_len;\n    char rfx_prop[64];\n    int ns_codec_id;\n    int ns_prop_len;\n    char ns_prop[64];\n    int jpeg_codec_id;\n    int jpeg_prop_len;\n    char jpeg_prop[64];\n    int v3_codec_id;\n    int rfx_min_pixel;\n    char orders[XR_PRIMARY_ORDER_COUNT];\n    int order_flags_ex;\n    int use_bulk_comp;\n    int pointer_flags; /* 0 color, 1 new, 2 no new */\n    int use_fast_path;\n    int require_credentials; /* when true, credentials *must* be passed on cmd line */\n\n    int security_layer; /* SECURITY_LAYER_* */\n    int vmconnect; /* Used when used from inside Hyper-V */\n\n    int multimon; /* 0 = deny , 1 = allow */\n    struct display_size_description display_sizes;\n\n    int keyboard_type;\n    int keyboard_subtype;\n\n    int png_codec_id;\n    int png_prop_len;\n    char png_prop[64];\n    int vendor_flags[4];\n    int mcs_connection_type;\n    int mcs_early_capability_flags;\n\n    int max_fastpath_frag_bytes;\n    int capture_format;\n\n    char certificate[1024];\n    char key_file[1024];\n\n    /* X11 keyboard layout - inferred from keyboard type/subtype */\n    char model[CI_KBD_MODEL_SIZE];\n    char layout[CI_KBD_LAYOUT_SIZE];\n    char variant[CI_KBD_VARIANT_SIZE];\n    char options[CI_KBD_OPTIONS_SIZE];\n    char xkb_rules[CI_KBD_XKB_RULES_SIZE];\n    // A few x11 keycodes are needed by the xup module\n    int x11_keycode_caps_lock;\n    int x11_keycode_num_lock;\n    int x11_keycode_scroll_lock;\n\n    /* xorgxrdp: frame capture interval (milliseconds) */\n    int rfx_frame_interval;\n    int h264_frame_interval;\n    int normal_frame_interval;\n\n    /* codec */\n    int h264_codec_id;\n    int h264_prop_len;\n    char h264_prop[64];\n\n    int use_frame_acks;\n    int max_unacknowledged_frame_count;\n\n    long ssl_protocols;\n    char *tls_ciphers;\n\n    char client_ip[MAX_PEER_ADDRSTRLEN];\n    char client_description[MAX_PEER_DESCSTRLEN];\n\n    int client_os_major;\n    int client_os_minor;\n\n    int no_orders_supported;\n    int use_cache_glyph_v2;\n    int rail_enable;\n    // Mask of reasons why output may be suppressed\n    // (see enum suppress_output_reason)\n    unsigned int suppress_output_mask;\n\n    int enable_token_login;\n    char domain_user_separator[16];\n\n    /* xrdp.override_* values */\n    struct xrdp_keyboard_overrides xrdp_keyboard_overrides;\n\n    /* These values are optionally send over as part of TS_UD_CS_CORE.\n     * They can be used as a fallback for a single monitor session\n     * if physical sizes are not available in the monitor-specific\n     * data */\n    unsigned int session_physical_width; /* in mm */\n    unsigned int session_physical_height; /* in mm */\n\n    int large_pointer_support_flags;\n    int gfx;\n\n    // Can we resize the desktop by using a Deactivation-Reactivation Sequence?\n    enum client_resize_mode client_resize_mode;\n\n    enum unicode_input_state unicode_input_support;\n    enum xrdp_capture_code capture_code;\n};\n\n/*\n * Return true if output is suppressed for a particular reason\n */\n#define OUTPUT_SUPPRESSED_FOR_REASON(ci,reason) \\\n    (((ci)->suppress_output_mask & (unsigned int)reason) != 0)\n\n#endif\n"
  },
  {
    "path": "common/xrdp_constants.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n * Miscellaneous protocol constants\n *\n * Copyright (C) Matthew Chapman 1999-2008\n * Copyright (C) Jay Sorg 2004-2014\n * Copyright (C) Kevin Zhou 2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(XRDP_CONSTANTS_H)\n#define XRDP_CONSTANTS_H\n\n/* TCP port for Remote Desktop Protocol */\n#define TCP_PORT_RDP                   3389\n\n/******************************************************************************\n *\n * xrdp constants\n *\n * Constants defined in publicly available Microsoft documents are not\n * stored here, but are stored in the include files ms-*.h, where the name\n * of the file is the name of the document defining the constant.\n *\n * So for example, NTSTATUS values found in [MS-ERREF] are found in\n * ms-erref.h\n ******************************************************************************/\n\n/**\n * Size of buffer including terminator for an IP address as returned\n * by g_sck_get_peer_ip_address(). See POSIX INET6_ADDRSTRLEN\n */\n#define MAX_PEER_ADDRSTRLEN 46\n\n/**\n * Max length of buffer containing an instance name used to\n * tag sessions for discrimination on reconnection.\n **/\n#define MAX_XRDP_INSTANCE_NAMELEN 80\n\n/**\n * Max length of buffer containing a Wayland or X11 display\n * name\n **/\n#define MAX_DISPLAY_NAME_SIZE 32\n\n/**\n * Size of buffer including terminator for a socket description, as\n * returned by g_sck_get_peer_description()\n * Currently the largest is an IPv6 address (INET6_ADDRSTRLEN), plus\n * []:<port> characters\n */\n#define MAX_PEER_DESCSTRLEN (46 + 2 + 1 + 5)\n\n/*\n * Number of bytes used to send a client name in the client core data\n * ([MS-RDPBCGR] 2.2.1.3.2). This is 15 characters plus a terminator in\n * UTF-16\n */\n#define INFO_CLIENT_NAME_BYTES_UTF16  ((15 + 1) * 2)\n\n/*\n * Number of bytes needed to store the client name as UTF-8. It is assumed\n * that the 15 Unicode characters in the name all occupy BMP codepoints\n * between U+0800 and U+FFFF. These codepoints all need three octets\n * in UTF-8\n */\n#define INFO_CLIENT_NAME_BYTES_UTF8 ((3 * 15) + 1)\n/**\n * Maximum length of a string including the mandatory null terminator\n * [MS-RDPBCGR] TS_INFO_PACKET(2.2.1.11.1.1)\n */\n#define INFO_CLIENT_MAX_CB_LEN  512\n\n#define XRDP_MAX_BITMAP_CACHE_ID  3\n#define XRDP_MAX_BITMAP_CACHE_IDX 2000\n#define XRDP_BITMAP_CACHE_ENTRIES 2048\n\n/*\n * Constants come from ITU-T Recommendations\n */\n\n#define ISO_PDU_CR                     0xE0 /* X.224 Connection Request */\n#define ISO_PDU_CC                     0xD0 /* X.224 Connection Confirm */\n#define ISO_PDU_DR                     0x80 /* Disconnect Request */\n#define ISO_PDU_DT                     0xF0 /* Data */\n#define ISO_PDU_ER                     0x70 /* Error */\n\n/* MCS PDU codes (T.125) */\n#define MCS_EDRQ                       1  /* Erect Domain Request */\n#define MCS_DPUM                       8  /* Disconnect Provider Ultimatum */\n#define MCS_AURQ                       10 /* Attach User Request */\n#define MCS_AUCF                       11 /* Attach User Confirm */\n#define MCS_CJRQ                       14 /* Channel Join Request */\n#define MCS_CJCF                       15 /* Channel Join Confirm */\n#define MCS_SDRQ                       25 /* Send Data Request */\n#define MCS_SDIN                       26 /* Send Data Indication */\n\n/* xorgxrdp: frame capture interval (milliseconds) */\n#define DEFAULT_RFX_FRAME_INTERVAL     32\n#define DEFAULT_H264_FRAME_INTERVAL    16\n#define DEFAULT_NORMAL_FRAME_INTERVAL  40\n\n/******************************************************************************\n *\n * Constants come from other Microsoft products\n *\n *****************************************************************************/\n\n/* Sound format constants - see also RFC 2361 and MS-RDPAI  */\n#define WAVE_FORMAT_PCM                0x0001\n#define WAVE_FORMAT_ADPCM              0x0002\n#define WAVE_FORMAT_ALAW               0x0006\n#define WAVE_FORMAT_MULAW              0x0007\n#define WAVE_FORMAT_MPEGLAYER3         0x0055\n#define WAVE_FORMAT_OPUS               0x0069\n#define WAVE_FORMAT_AAC                0xA106\n\n/* https://technet.microsoft.com/ja-jp/library/aa387685.aspx */\n#define SEC_RSA_MAGIC                  0x31415352 /* RSA1 */\n\n/* NTSTATUS Values (MS-ERREF 2.3.1) */\n/* used for RDPDR */\n/*\n * not yet sorted out\n */\n\n#define MCS_CONNECT_INITIAL            0x7f65 /* MCS BER: big endian, class=application (0x4000), constructed (0x2000), tag number > 30 (0x1f00), tag number=101 (0x0065) */\n#define MCS_CONNECT_RESPONSE           0x7f66 /* MCS BER: application 102 */\n\n#define BER_TAG_BOOLEAN                1\n#define BER_TAG_INTEGER                2\n#define BER_TAG_OCTET_STRING           4\n#define BER_TAG_RESULT                 10\n#define MCS_TAG_DOMAIN_PARAMS          0x30\n\n#define MCS_GLOBAL_CHANNEL             1003\n#define MCS_USERCHANNEL_BASE           1001\n\n/* RDP secure transport constants */\n/* not used anywhere */\n#define SEC_RANDOM_SIZE                32\n#define SEC_MODULUS_SIZE               64\n#define SEC_PADDING_SIZE               8\n#define SEC_EXPONENT_SIZE              4\n\n/* RDP licensing constants */\n#define LICENCE_TOKEN_SIZE             10\n#define LICENCE_HWID_SIZE              20\n#define LICENCE_SIGNATURE_SIZE         16\n\n\n/* See T.128 */\n/* not used anywhere */\n#define RDP_KEYPRESS                   0\n#define RDP_KEYRELEASE                 (KBD_FLAG_DOWN | KBD_FLAG_UP)\n\n/* Raster operation masks */\n#define ROP2_S(rop3)                   (rop3 & 0xf)\n#define ROP2_P(rop3)                   ((rop3 & 0x3) | ((rop3 & 0x30) >> 2))\n\n#define ROP2_COPY                      0xc\n#define ROP2_XOR                       0x6\n#define ROP2_AND                       0x8\n#define ROP2_NXOR                      0x9\n#define ROP2_OR                        0xe\n\n#define MIX_TRANSPARENT                0\n#define MIX_OPAQUE                     1\n\n#define TEXT2_VERTICAL                 0x04\n#define TEXT2_IMPLICIT_X               0x20\n\n/* RDP bitmap cache (version 2) constants */\n#define BMPCACHE2_C0_CELLS             0x78\n#define BMPCACHE2_C1_CELLS             0x78\n#define BMPCACHE2_C2_CELLS             0x150\n#define BMPCACHE2_NUM_PSTCELLS         0x9f6\n\n#define PDU_FLAG_FIRST                 0x01\n#define PDU_FLAG_LAST                  0x02\n\n#define RDP_SOURCE                     \"MSTSC\"\n\n/* Keymap flags */\n#define MapRightShiftMask              (1 << 0)\n#define MapLeftShiftMask               (1 << 1)\n#define MapShiftMask                   (MapRightShiftMask | MapLeftShiftMask)\n\n#define MapRightAltMask                (1 << 2)\n#define MapLeftAltMask                 (1 << 3)\n#define MapAltGrMask                   MapRightAltMask\n\n#define MapRightCtrlMask               (1 << 4)\n#define MapLeftCtrlMask                (1 << 5)\n#define MapCtrlMask                    (MapRightCtrlMask | MapLeftCtrlMask)\n\n#define MapRightWinMask                (1 << 6)\n#define MapLeftWinMask                 (1 << 7)\n#define MapWinMask                     (MapRightWinMask | MapLeftWinMask)\n\n#define MapNumLockMask                 (1 << 8)\n#define MapCapsLockMask                (1 << 9)\n\n#define MapLocalStateMask              (1 << 10)\n\n#define MapInhibitMask                 (1 << 11)\n\n#define MASK_ADD_BITS(var, mask)       (var |= mask)\n#define MASK_REMOVE_BITS(var, mask)    (var &= ~mask)\n#define MASK_HAS_BITS(var, mask)       ((var & mask)>0)\n#define MASK_CHANGE_BIT(var, mask, active) \\\n    (var = ((var & ~mask) | (active ? mask : 0)))\n\n/* Clipboard constants, \"borrowed\" from GCC system headers in\n   the w32 cross compiler */\n\n#define CF_TEXT                        1\n#define CF_BITMAP                      2\n#define CF_METAFILEPICT                3\n#define CF_SYLK                        4\n#define CF_DIF                         5\n#define CF_TIFF                        6\n#define CF_OEMTEXT                     7\n#define CF_DIB                         8\n#define CF_PALETTE                     9\n#define CF_PENDATA                     10\n#define CF_RIFF                        11\n#define CF_WAVE                        12\n#define CF_UNICODETEXT                 13\n#define CF_ENHMETAFILE                 14\n#define CF_HDROP                       15\n#define CF_LOCALE                      16\n#define CF_MAX                         17\n#define CF_OWNERDISPLAY                128\n#define CF_DSPTEXT                     129\n#define CF_DSPBITMAP                   130\n#define CF_DSPMETAFILEPICT             131\n#define CF_DSPENHMETAFILE              142\n#define CF_PRIVATEFIRST                512\n#define CF_PRIVATELAST                 767\n#define CF_GDIOBJFIRST                 768\n#define CF_GDIOBJLAST                  1023\n\n/* RDPDR constants */\n#define RDPDR_MAX_DEVICES              0x10\n\n/* drawable types */\n#define WND_TYPE_BITMAP  0\n#define WND_TYPE_WND     1\n#define WND_TYPE_SCREEN  2\n#define WND_TYPE_BUTTON  3\n#define WND_TYPE_IMAGE   4\n#define WND_TYPE_EDIT    5\n#define WND_TYPE_LABEL   6\n#define WND_TYPE_COMBO   7\n#define WND_TYPE_SPECIAL 8\n#define WND_TYPE_LISTBOX 9\n#define WND_TYPE_OFFSCREEN 10\n\n/* button states */\n#define BUTTON_STATE_UP   0\n#define BUTTON_STATE_DOWN 1\n\n/* touch gestures */\n#define TOUCH_TWO_FINGERS_DOWN 0\n#define TOUCH_TWO_FINGERS_UP 1\n#define TOUCH_TWO_FINGERS_LEFT 2\n#define TOUCH_TWO_FINGERS_RIGHT 3\n\n/* messages */\n#define WM_PAINT       3\n#define WM_KEYDOWN     15\n#define WM_KEYUP       16\n#define WM_KEYBRD_SYNC 17\n#define WM_MOUSEMOVE   100\n#define WM_LBUTTONUP   101\n#define WM_LBUTTONDOWN 102\n#define WM_RBUTTONUP   103\n#define WM_RBUTTONDOWN 104\n#define WM_BUTTON3UP   105\n#define WM_BUTTON3DOWN 106\n#define WM_BUTTON4UP   107\n#define WM_BUTTON4DOWN 108\n#define WM_BUTTON5UP   109\n#define WM_BUTTON5DOWN 110\n#define WM_BUTTON6UP   111\n#define WM_BUTTON6DOWN 112\n#define WM_BUTTON7UP   113\n#define WM_BUTTON7DOWN 114\n#define WM_BUTTON8UP   115\n#define WM_BUTTON8DOWN 116\n#define WM_BUTTON9UP   117\n#define WM_BUTTON9DOWN 118\n\n#define WM_TOUCH_VSCROLL 140\n#define WM_TOUCH_HSCROLL 141\n\n#define WM_INVALIDATE  200\n#define WM_CHANNEL_DATA 201\n\n#define CB_ITEMCHANGE  300\n\n#define FASTPATH_MAX_PACKET_SIZE    0x3fff\n\n// Since we're not guaranteed to have pixman, copy these directives.\n#define XRDP_PIXMAN_TYPE_ARGB   2\n#define XRDP_PIXMAN_TYPE_ABGR   3\n#define XRDP_PIXMAN_FORMAT(bpp,type,a,r,g,b)    (((bpp) << 24) |  \\\n        ((type) << 16) | \\\n        ((a) << 12) |    \\\n        ((r) << 8) |     \\\n        ((g) << 4) |     \\\n        ((b)))\n\n#define XRDP_a8b8g8r8 \\\n    XRDP_PIXMAN_FORMAT(32, XRDP_PIXMAN_TYPE_ABGR, 8, 8, 8, 8)\n\n#define XRDP_a8r8g8b8 \\\n    XRDP_PIXMAN_FORMAT(32, XRDP_PIXMAN_TYPE_ARGB, 8, 8, 8, 8)\n\n#define XRDP_r5g6b5 \\\n    XRDP_PIXMAN_FORMAT(16, XRDP_PIXMAN_TYPE_ARGB, 0, 5, 6, 5)\n\n#define XRDP_a1r5g5b5 \\\n    XRDP_PIXMAN_FORMAT(16, XRDP_PIXMAN_TYPE_ARGB, 1, 5, 5, 5)\n\n#define XRDP_r3g3b2 \\\n    XRDP_PIXMAN_FORMAT(8, XRDP_PIXMAN_TYPE_ARGB, 0, 3, 3, 2)\n\n// The last used constant in pixman is 63, so use 64+\n#define XRDP_nv12 \\\n    XRDP_PIXMAN_FORMAT(12, 64, 0, 0, 0, 0)\n\n#define XRDP_i420 \\\n    XRDP_PIXMAN_FORMAT(12, 65, 0, 0, 0, 0)\n\n#define XRDP_nv12_709fr \\\n    XRDP_PIXMAN_FORMAT(12, 66, 0, 0, 0, 0)\n\n#define XRDP_yuv444_709fr \\\n    XRDP_PIXMAN_FORMAT(32, 67, 0, 0, 0, 0)\n\n// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpegfx/8131c1bc-1af8-4907-a05a-f72f4581160f\n#define XRDP_yuv444_v1_stream_709fr \\\n    XRDP_PIXMAN_FORMAT(32, 68, 0, 0, 0, 0)\n\n// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpegfx/781406c3-5e24-4f2b-b6ff-42b76bf64f6d\n#define XRDP_yuv444_v2_stream_709fr \\\n    XRDP_PIXMAN_FORMAT(32, 69, 0, 0, 0, 0)\n\n#endif\n"
  },
  {
    "path": "common/xrdp_rail.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(_RAIL_H)\n#define _RAIL_H\n\n/*\n  ORDER_TYPE_WINDOW\n    WINDOW_ORDER_TYPE_WINDOW\n      WINDOW_ORDER_ICON\n      WINDOW_ORDER_CACHED_ICON\n      WINDOW_ORDER_STATE_DELETED\n      WINDOW_ORDER_STATE_NEW on\n      WINDOW_ORDER_STATE_NEW off\n    WINDOW_ORDER_TYPE_NOTIFY\n      WINDOW_ORDER_STATE_DELETED\n      WINDOW_ORDER_STATE_NEW on\n      WINDOW_ORDER_STATE_NEW off\n    WINDOW_ORDER_TYPE_DESKTOP\n      WINDOW_ORDER_FIELD_DESKTOP_NONE on\n      WINDOW_ORDER_FIELD_DESKTOP_NONE off\n*/\n\n/* Window Order Header Flags */\n#define WINDOW_ORDER_TYPE_WINDOW                        0x01000000\n#define WINDOW_ORDER_TYPE_NOTIFY                        0x02000000\n#define WINDOW_ORDER_TYPE_DESKTOP                       0x04000000\n#define WINDOW_ORDER_STATE_NEW                          0x10000000\n#define WINDOW_ORDER_STATE_DELETED                      0x20000000\n#define WINDOW_ORDER_FIELD_OWNER                        0x00000002\n#define WINDOW_ORDER_FIELD_STYLE                        0x00000008\n#define WINDOW_ORDER_FIELD_SHOW                         0x00000010\n#define WINDOW_ORDER_FIELD_TITLE                        0x00000004\n#define WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET           0x00004000\n#define WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE             0x00010000\n#define WINDOW_ORDER_FIELD_RP_CONTENT                   0x00020000\n#define WINDOW_ORDER_FIELD_ROOT_PARENT                  0x00040000\n#define WINDOW_ORDER_FIELD_WND_OFFSET                   0x00000800\n#define WINDOW_ORDER_FIELD_WND_CLIENT_DELTA             0x00008000\n#define WINDOW_ORDER_FIELD_WND_SIZE                     0x00000400\n#define WINDOW_ORDER_FIELD_WND_RECTS                    0x00000100\n#define WINDOW_ORDER_FIELD_VIS_OFFSET                   0x00001000\n#define WINDOW_ORDER_FIELD_VISIBILITY                   0x00000200\n#define WINDOW_ORDER_FIELD_ICON_BIG                     0x00002000\n#define WINDOW_ORDER_ICON                               0x40000000\n#define WINDOW_ORDER_CACHED_ICON                        0x80000000\n#define WINDOW_ORDER_FIELD_NOTIFY_VERSION               0x00000008\n#define WINDOW_ORDER_FIELD_NOTIFY_TIP                   0x00000001\n#define WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP              0x00000002\n#define WINDOW_ORDER_FIELD_NOTIFY_STATE                 0x00000004\n#define WINDOW_ORDER_FIELD_DESKTOP_NONE                 0x00000001\n#define WINDOW_ORDER_FIELD_DESKTOP_HOOKED               0x00000002\n#define WINDOW_ORDER_FIELD_DESKTOP_ARC_COMPLETED        0x00000004\n#define WINDOW_ORDER_FIELD_DESKTOP_ARC_BEGAN            0x00000008\n#define WINDOW_ORDER_FIELD_DESKTOP_ZORDER               0x00000010\n#define WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND           0x00000020\n\nstruct rail_icon_info\n{\n    int bpp;\n    int width;\n    int height;\n    int cmap_bytes;\n    int mask_bytes;\n    int data_bytes;\n    char *mask;\n    char *cmap;\n    char *data;\n};\n\nstruct rail_window_rect\n{\n    short left;\n    short top;\n    short right;\n    short bottom;\n};\n\nstruct rail_notify_icon_infotip\n{\n    int timeout;\n    int flags;\n    char *text;\n    char *title;\n};\n\nstruct rail_window_state_order\n{\n    int owner_window_id;\n    int style;\n    int extended_style;\n    int show_state;\n    char *title_info;\n    int client_offset_x;\n    int client_offset_y;\n    int client_area_width;\n    int client_area_height;\n    int rp_content;\n    int root_parent_handle;\n    int window_offset_x;\n    int window_offset_y;\n    int window_client_delta_x;\n    int window_client_delta_y;\n    int window_width;\n    int window_height;\n    int num_window_rects;\n    struct rail_window_rect *window_rects;\n    int visible_offset_x;\n    int visible_offset_y;\n    int num_visibility_rects;\n    struct rail_window_rect *visibility_rects;\n};\n\nstruct rail_notify_state_order\n{\n    int version;\n    char *tool_tip;\n    struct rail_notify_icon_infotip infotip;\n    int state;\n    int icon_cache_entry;\n    int icon_cache_id;\n    struct rail_icon_info icon_info;\n};\n\nstruct rail_monitored_desktop_order\n{\n    int active_window_id;\n    int num_window_ids;\n    int *window_ids;\n};\n\n#endif\n"
  },
  {
    "path": "common/xrdp_scancode_defs.h",
    "content": "/**\n * Copyright (C) 2024 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    common/xrdp_scancode_defs.h\n * @brief   Scancode global definitions, shared with xorgxrdp\n */\n\n#if !defined(XRDP_SCANCODE_DEFS_H)\n#define XRDP_SCANCODE_DEFS_H\n\nenum\n{\n    /**\n     * Scancodes for keys received from the RDP client\n     */\n    SCANCODE_LSHIFT_KEY = 0x2a,\n    SCANCODE_RSHIFT_KEY = 0x36,\n    SCANCODE_LCTRL_KEY = 0x1d,\n    SCANCODE_RCTRL_KEY = 0x11d,\n    SCANCODE_CAPS_KEY = 0x3a,\n    SCANCODE_NUMLOCK_KEY = 0x45,\n    SCANCODE_SCROLL_KEY = 0x46, // Scroll lock\n    SCANCODE_LALT_KEY = 0x38,\n    SCANCODE_RALT_KEY = 0x138,\n    SCANCODE_LWIN_KEY = 0x15b,\n    SCANCODE_RWIN_KEY = 0x15c,\n    SCANCODE_MENU_KEY = 0x15d,\n\n    SCANCODE_ESC_KEY = 0x01,\n    SCANCODE_BACKSPACE_KEY = 0x0e,\n    SCANCODE_ENTER_KEY = 0x1c,\n    SCANCODE_TAB_KEY = 0x0f,\n    SCANCODE_PAUSE_KEY = 0x21d,\n\n    SCANCODE_KP_ENTER_KEY = 0x11c,\n    SCANCODE_KP_DEL_KEY = 0x53,\n    SCANCODE_KP_1_KEY = 0x4f,\n    SCANCODE_KP_2_KEY = 0x50,\n    SCANCODE_KP_4_KEY = 0x4b,\n    SCANCODE_KP_6_KEY = 0x4d,\n    SCANCODE_KP_7_KEY = 0x47,\n    SCANCODE_KP_8_KEY = 0x48,\n\n    SCANCODE_LEFT_ARROW_KEY = 0x14b,\n    SCANCODE_RIGHT_ARROW_KEY = 0x14d,\n    SCANCODE_UP_ARROW_KEY = 0x148,\n    SCANCODE_DOWN_ARROW_KEY = 0x150,\n\n    SCANCODE_HOME_KEY = 0x147,\n    SCANCODE_DEL_KEY = 0x153,\n    SCANCODE_END_KEY = 0x14f,\n\n    /**\n     * Keys affected by numlock\n     * (this is not the whole keypad)\n     */\n    SCANCODE_MIN_NUMLOCK = SCANCODE_KP_7_KEY,\n    SCANCODE_MAX_NUMLOCK = SCANCODE_KP_DEL_KEY\n};\n\n// Convert key_code and flags values received from a TS_KEYBOARD_EVENT\n// into a value suitable for use by this module\n#define SCANCODE_FROM_KBD_EVENT(key_code,keyboard_flags) \\\n    (((key_code) & 0x7f) | ((keyboard_flags) & 0x300))\n\n// Convert a scancode used by this module back into a\n// TS_KEYBOARD_EVENT keyCode value\n#define SCANCODE_TO_KBD_EVENT_KEY_CODE(scancode) ((scancode) & 0x7f)\n\n// Convert a scancode used by this module back into a\n// TS_KEYBOARD_EVENT keyboardFlags value\n#define SCANCODE_TO_KBD_EVENT_KBD_FLAGS(scancode) ((scancode) & 0x300)\n\n#endif /* XRDP_SCANCODE_DEFS_H */\n"
  },
  {
    "path": "common/xrdp_sockets.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * names of UNIX sockets for inter-process communication\n */\n\n#if !defined(XRDP_SOCKETS_H)\n#define XRDP_SOCKETS_H\n\n/* XRDP_SOCKET_ROOT_PATH must be defined to include this file */\n#ifdef __cppcheck__\n/*   avoid syntax errors */\n#  define XRDP_SOCKET_ROOT_PATH \"/dummy\"\n#elif !defined(XRDP_SOCKET_ROOT_PATH)\n#  error \"XRDP_SOCKET_ROOT_PATH must be defined\"\n#endif\n\n/* Buffer size for code for fullpath declarations\n *\n * This needs to fit in the sun_path field of a sockaddr_un. POSIX\n * does not define this size, so the value below is the lower of\n * the FreeBSD/OpenBSD/NetBSD(104) and Linux(108) values */\n#define XRDP_SOCKETS_MAXPATH 104\n\n/* The socketdir is rooted at XRDP_SOCKET_ROOT_PATH. User-specific\n * sockets live in a user-specific sub-directory of this called\n * XRDP_SOCKET_PATH. The sub-directory is the UID of the user */\n#define XRDP_SOCKET_PATH      XRDP_SOCKET_ROOT_PATH \"/%d\"\n\n/* Sockets in XRDP_SOCKET_ROOT_PATH */\n#define SCP_LISTEN_PORT_BASE_STR   \"sesman.socket\"\n\n/* names of socket files within XRDP_SOCKET_PATH, qualified by\n * display name */\n#define XRDP_CHANSRV_BASE_STR      \"xrdp_chansrv_socket_%s\"\n#define CHANSRV_PORT_OUT_BASE_STR  \"xrdp_chansrv_audio_out_socket_%s\"\n#define CHANSRV_PORT_IN_BASE_STR   \"xrdp_chansrv_audio_in_socket_%s\"\n#define CHANSRV_API_BASE_STR       \"xrdpapi_%s\"\n#define XRDP_X11RDP_BASE_STR       \"xrdp_display_%s\"\n#define XRDP_DISCONNECT_BASE_STR   \"xrdp_disconnect_display_%s\"\n\n/* fullpath declarations */\n#define XRDP_CHANSRV_STR      XRDP_SOCKET_PATH \"/\" XRDP_CHANSRV_BASE_STR\n#define CHANSRV_PORT_OUT_STR  XRDP_SOCKET_PATH \"/\" CHANSRV_PORT_OUT_BASE_STR\n#define CHANSRV_PORT_IN_STR   XRDP_SOCKET_PATH \"/\" CHANSRV_PORT_IN_BASE_STR\n#define CHANSRV_API_STR       XRDP_SOCKET_PATH \"/\" CHANSRV_API_BASE_STR\n#define XRDP_X11RDP_STR       XRDP_SOCKET_PATH \"/\" XRDP_X11RDP_BASE_STR\n#define XRDP_DISCONNECT_STR   XRDP_SOCKET_PATH \"/\" XRDP_DISCONNECT_BASE_STR\n\n/* Where X11 stores its Unix Domain Sockets (unlikely to change) */\n#define X11_UNIX_SOCKET_DIRECTORY \"/tmp/.X11-unix\"\n\n/*  fullpath to an X11 display socket */\n#define X11_UNIX_SOCKET_STR X11_UNIX_SOCKET_DIRECTORY \"/X%d\"\n\n#endif\n"
  },
  {
    "path": "common/xup_client_info.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2025\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    common/xup_client_info.h\n * @brief   Data shared with xorgxrdp\n */\n\n#if !defined(XUP_CLIENT_INFO_H)\n#define XUP_CLIENT_INFO_H\n\n#include \"xrdp_client_info.h\"\n\n/**\n * Information about the xrdp client which is passed to xorgxrdp\n *\n * This is a subset of 'struct xrdp_client_info'\n *\n * @note If you change this structure, you MUST bump the\n *       XUP_CLIENT_INFO_CURRENT_VERSION number so that the mismatch\n *       can be detected.\n */\nstruct xup_client_info\n{\n    int size; /* bytes for this structure */\n    int version; /* Should be XUP_CLIENT_INFO_CURRENT_VERSION */\n    int bpp;\n    int jpeg; /* non standard bitmap cache v2 cap */\n    int offscreen_support_level;\n    int offscreen_cache_size;\n    int offscreen_cache_entries;\n\n    char orders[XR_PRIMARY_ORDER_COUNT];\n    int order_flags_ex;\n    int pointer_flags; /* 0 color, 1 new, 2 no new */\n    int large_pointer_support_flags;\n\n    struct display_size_description display_sizes;\n\n    enum xrdp_capture_code capture_code;\n    int capture_format;\n\n    /* X11 keyboard layout - inferred from keyboard type/subtype */\n    char model[CI_KBD_MODEL_SIZE];\n    char layout[CI_KBD_LAYOUT_SIZE];\n    char variant[CI_KBD_VARIANT_SIZE];\n    char options[CI_KBD_OPTIONS_SIZE];\n    char xkb_rules[CI_KBD_XKB_RULES_SIZE];\n    // A few x11 keycodes are needed by the xup module\n    int x11_keycode_caps_lock;\n    int x11_keycode_num_lock;\n    int x11_keycode_scroll_lock;\n\n    /* xorgxrdp: frame capture interval (milliseconds) */\n    int rfx_frame_interval;\n    int h264_frame_interval;\n    int normal_frame_interval;\n};\n\n/* yyyymmdd of last incompatible change to xup_client_info */\n#define XUP_CLIENT_INFO_CURRENT_VERSION 20250528\n\n#endif // XUP_CLIENT_INFO_H\n"
  },
  {
    "path": "configure.ac",
    "content": "# Process this file with autoconf to produce a configure script\n\nAC_PREREQ([2.69])\nAC_INIT([xrdp], [0.10.80], [xrdp-devel@googlegroups.com])\nAC_DEFINE([VERSION_YEAR], 2025, [Copyright year])\nAC_CONFIG_HEADERS(config_ac.h:config_ac-h.in)\nAM_INIT_AUTOMAKE([1.7.2 foreign])\nAC_CONFIG_MACRO_DIR([m4])\nAC_USE_SYSTEM_EXTENSIONS\nAC_PROG_CC\nAC_PROG_CXX\nAC_PROG_LN_S\nLT_INIT\n\nPKG_PROG_PKG_CONFIG\nif test \"x$PKG_CONFIG\" = \"x\"; then\n  AC_MSG_ERROR([please install pkg-config])\nfi\n\nAC_CONFIG_SUBDIRS([libpainter librfxcodec])\n\n# Use silent rules by default if supported by Automake\nm4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])\n\ncase $host_os in\n\t*linux*)\n\t\tlinux=yes\n\t\t;;\n\t*kfreebsd*)\n\t\tlinux=yes # only used in instfiles/ so that’s ok for us for now\n\t\t;;\n\t*freebsd*)\n\t\tfreebsd=yes\n\t\t;;\n\t*netbsd*)\n\t\tnetbsd=yes\n\t\t;;\n\t*openbsd*)\n\t\topenbsd=yes\n\t\t;;\n\t*darwin*)\n\t\tmacos=yes\n\t\t;;\nesac\n\nAM_CONDITIONAL(LINUX, [test \"x$linux\" = xyes])\nAM_CONDITIONAL(FREEBSD, [test \"x$freebsd\" = xyes])\nAM_CONDITIONAL(OPENBSD, [test \"x$openbsd\" = xyes])\nAM_CONDITIONAL(NETBSD, [test \"x$netbsd\" = xyes])\nAM_CONDITIONAL(MACOS, [test \"x$macos\" = xyes])\n\nAC_CHECK_SIZEOF([int])\nAC_CHECK_SIZEOF([long])\nAC_CHECK_SIZEOF([void *])\nAC_CHECK_SIZEOF([fsblkcnt_t],,[#include <sys/statvfs.h>])\n\n# runstatedir not available for autoconf <= 2.69\nif test \"x$runstatedir\" = \"x\" ; then\n    runstatedir='${localstatedir}/run'\nfi\n\nAC_ARG_WITH([socketdir],\n  [AS_HELP_STRING([--with-socketdir=DIR],\n                  [Use directory for UNIX sockets for XRDP sessions (default: RUNSTATEDIR/xrdp)])],\n                  [], [with_socketdir=\"$runstatedir/xrdp\"])\nAC_SUBST([socketdir], [$with_socketdir])\n\nAC_ARG_WITH([systemdsystemunitdir],\n        AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files, no to disable]),\n        [], [\nif test \"x$linux\" = xyes; then\n  with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)\nfi\n])\n\nif test \"x$with_systemdsystemunitdir\" != xno; then\n        AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])\nfi\nAM_CONDITIONAL(HAVE_SYSTEMD, [test -n \"$with_systemdsystemunitdir\" -a \"x$with_systemdsystemunitdir\" != xno ])\n\nAC_ARG_ENABLE(tests,\n              AS_HELP_STRING([--enable-tests],\n              [Ensure dependencies for the tests are installed]),\n              [ensure_tests_deps=yes], [])\nAC_ARG_ENABLE(pam, AS_HELP_STRING([--enable-pam],\n              [Build PAM support (default: yes)]),\n              [], [enable_pam=yes])\nAM_CONDITIONAL(SESMAN_NOPAM, [test x$enable_pam != xyes])\nAC_ARG_ENABLE(vsock, AS_HELP_STRING([--enable-vsock],\n              [Build AF_VSOCK support (default: no)]),\n              [], [enable_vsock=no])\nAC_ARG_ENABLE(ipv6, AS_HELP_STRING([--enable-ipv6],\n              [Build IPv6 support (default: no, experimental)]),\n              [], [enable_ipv6=no])\nAC_ARG_ENABLE(ipv6only, AS_HELP_STRING([--enable-ipv6only],\n              [Build IPv6-only (default: no)]),\n              [], [enable_ipv6only=no])\nAC_ARG_ENABLE(kerberos, AS_HELP_STRING([--enable-kerberos],\n              [Build kerberos support (prefer --enable-pam if available) (default: no)]),\n              [], [enable_kerberos=no])\nAM_CONDITIONAL(SESMAN_KERBEROS, [test x$enable_kerberos = xyes])\nAC_ARG_ENABLE(bsd, AS_HELP_STRING([--enable-bsd],\n              [Build BSD auth support (default: no)]),\n              [], [enable_bsd=no])\nAM_CONDITIONAL(SESMAN_BSD, [test x$enable_bsd = xyes])\nAC_ARG_ENABLE(pamuserpass, AS_HELP_STRING([--enable-pamuserpass],\n              [Build PAM userpass support (default: no)]),\n              [], [enable_pamuserpass=no])\nAM_CONDITIONAL(SESMAN_PAMUSERPASS, [test x$enable_pamuserpass = xyes])\nAC_ARG_ENABLE(pam-config, AS_HELP_STRING([--enable-pam-config=CONF],\n              [Select PAM config to install: arch, debian, redhat, suse, freebsd, macos, unix\n               (default: autodetect)]))\n\n# Development options. devel_all is first as this provides a default for\n# the others\nAC_ARG_ENABLE(devel_all, AS_HELP_STRING([--enable-devel-all],\n              [Enable all development options (default: no)]),\n              [devel_all=$enableval], [devel_all=no])\nAC_ARG_ENABLE(devel_debug, AS_HELP_STRING([--enable-devel-debug],\n              [Build exes with no optimisation and debugging symbols (default: no)]),\n              [devel_debug=$enableval], [devel_debug=$devel_all])\nAM_CONDITIONAL(DEVEL_DEBUG, [test x$devel_debug = xyes ])\nAC_ARG_ENABLE(devel_logging, AS_HELP_STRING([--enable-devel-logging],\n              [Enable development logging (default: no)]),\n              [devel_logging=$enableval], [devel_logging=$devel_all])\nAC_ARG_ENABLE(devel_streamcheck, AS_HELP_STRING([--enable-devel-streamcheck],\n              [Add range-check/abort to stream primitives (default: no)]),\n              [devel_streamcheck=$enableval], [devel_streamcheck=$devel_all])\n\nAC_ARG_ENABLE(neutrinordp, AS_HELP_STRING([--enable-neutrinordp],\n              [Build neutrinordp module (default: no)]),\n              [], [enable_neutrinordp=no])\nAM_CONDITIONAL(XRDP_NEUTRINORDP, [test x$enable_neutrinordp = xyes])\n\nAC_ARG_ENABLE(ulalaca, AS_HELP_STRING([--enable-ulalaca],\n              [Build ulalaca module (experimental) (default: no)]),\n              [], [enable_ulalaca=no])\nAM_CONDITIONAL(XRDP_ULALACA, [test x$enable_ulalaca = xyes])\n\nAC_ARG_ENABLE(jpeg, AS_HELP_STRING([--enable-jpeg],\n              [Build jpeg module (default: no)]),\n              [], [enable_jpeg=no])\nAM_CONDITIONAL(XRDP_JPEG, [test x$enable_jpeg = xyes])\nAC_ARG_ENABLE(tjpeg, AS_HELP_STRING([--enable-tjpeg],\n              [Build turbo jpeg module (default: no)]),\n              [], [enable_tjpeg=no])\nAM_CONDITIONAL(XRDP_TJPEG, [test x$enable_tjpeg = xyes])\nAC_ARG_ENABLE(fuse, AS_HELP_STRING([--enable-fuse],\n              [Build fuse(clipboard file / drive redir) (default: no)]),\n              [], [enable_fuse=no])\nAM_CONDITIONAL(XRDP_FUSE, [test x$enable_fuse = xyes])\nAC_ARG_ENABLE(xrdpvr, AS_HELP_STRING([--enable-xrdpvr],\n              [Build xrdpvr module (default: no)]),\n              [], [enable_xrdpvr=no])\nAM_CONDITIONAL(XRDP_XRDPVR, [test x$enable_xrdpvr = xyes])\nAC_ARG_ENABLE(fdkaac, AS_HELP_STRING([--enable-fdkaac],\n              [Build aac(audio codec) (default: no)]),\n              [], [enable_fdkaac=no])\nAM_CONDITIONAL(XRDP_FDK_AAC, [test x$enable_fdkaac = xyes])\nAC_ARG_ENABLE(opus, AS_HELP_STRING([--enable-opus],\n              [Build opus(audio codec) (default: no)]),\n              [], [enable_opus=no])\nAM_CONDITIONAL(XRDP_OPUS, [test x$enable_opus = xyes])\nAC_ARG_ENABLE(mp3lame, AS_HELP_STRING([--enable-mp3lame],\n              [Build lame mp3(audio codec) (default: no)]),\n              [], [enable_mp3lame=no])\nAM_CONDITIONAL(XRDP_MP3LAME, [test x$enable_mp3lame = xyes])\nAC_ARG_ENABLE(ibus, AS_HELP_STRING([--enable-ibus],\n              [Allow unicode input via IBus) (default: no)]),\n              [], [enable_ibus=no])\nAM_CONDITIONAL(XRDP_IBUS, [test x$enable_ibus = xyes])\nAC_ARG_ENABLE(pixman, AS_HELP_STRING([--enable-pixman],\n              [Use pixman library (default: no)]),\n              [], [enable_pixman=no])\nAM_CONDITIONAL(XRDP_PIXMAN, [test x$enable_pixman = xyes])\nAC_ARG_ENABLE(x264, AS_HELP_STRING([--enable-x264],\n              [Use x264 library (default: no)]),\n              [], [enable_x264=no])\nAM_CONDITIONAL(XRDP_X264, [test x$enable_x264 = xyes])\nAC_ARG_ENABLE(openh264, AS_HELP_STRING([--enable-openh264],\n              [Use Cisco OpenH264 library (default: no)]),\n              [], [enable_openh264=no])\nAM_CONDITIONAL(XRDP_OPENH264, [test x$enable_openh264 = xyes])\nAC_ARG_ENABLE(nvenc, AS_HELP_STRING([--enable-nvenc],\n              [Use nvenc library (default: no), env vars XRDP_NVENC_CFLAGS and\n               XRDP_NVENC_LIBS should be set if used]),\n              [], [enable_nvenc=no])\nAM_CONDITIONAL(XRDP_NVENC, [test x$enable_nvenc = xyes])\nAC_ARG_ENABLE(accel, AS_HELP_STRING([--enable-accel],\n              [Build xrdp_accel_assist (default: no, auto set if --enable-nvenc)]),\n              [], [enable_accel=no])\n# AM_CONDITIONAL(XRDP_ACCEL, [test x$enable_accel = xyes]) later in this file\nAC_ARG_ENABLE(painter, AS_HELP_STRING([--disable-painter],\n              [Do not use included painter library (default: no)]),\n              [], [enable_painter=yes])\nAM_CONDITIONAL(XRDP_PAINTER, [test x$enable_painter = xyes])\n\nAC_ARG_ENABLE(rfxcodec, AS_HELP_STRING([--disable-rfxcodec],\n              [Do not use included librfxcodec library (default: no)]),\n              [], [enable_rfxcodec=yes])\nAM_CONDITIONAL(XRDP_RFXCODEC, [test x$enable_rfxcodec = xyes])\n\nAC_ARG_ENABLE(rdpsndaudin, AS_HELP_STRING([--enable-rdpsndaudin],\n              [Use rdpsnd audio in (default: no)]),\n              [], [enable_rdpsndaudin=no])\nAM_CONDITIONAL(XRDP_RDPSNDAUDIN, [test x$enable_rdpsndaudin = xyes])\n\nAC_ARG_ENABLE(utmp, AS_HELP_STRING([--enable-utmp],\n              [Update utmp (default: no)]),\n              [], [enable_utmp=no])\nAM_CONDITIONAL(XRDP_UTMP, [test x$enable_utmp = xyes])\n\nAC_ARG_WITH(imlib2, AS_HELP_STRING([--with-imlib2=ARG], [imlib2 library to use for non-BMP backgrounds (ARG=yes/no/<abs-path>)]),,)\n\nAC_ARG_WITH(freetype2, AS_HELP_STRING([--with-freetype2=ARG], [freetype2 library to use for rendering fonts (ARG=yes/no/<abs-path>)]),,)\n\nAC_ARG_ENABLE(smartcard, AS_HELP_STRING([--enable-smartcard],\n              [Enable experimental smartcard code. Not for production. (default: no)]),\n              [], [enable_smartcard=no])\nAM_CONDITIONAL(XRDP_SMARTCARD, [test x$enable_smartcard = xyes])\n\n# Obsolete options\nAC_ARG_ENABLE(xrdpdebug, AS_HELP_STRING([--enable-xrdpdebug],\n              [This option is no longer supported - use --enable-devel-all]))\n\nif test \"x$enable_xrdpdebug\" != x; then\n  AC_MSG_ERROR([--enable-xrdpdebug must be replaced with one or more --enable-devel-* options])\nfi\n\n# configure compiler options and CFLAGS\nAX_GCC_FUNC_ATTRIBUTE([format])\nAX_TYPE_SOCKLEN_T\nAX_CFLAGS_WARN_ALL\nAX_APPEND_COMPILE_FLAGS([-Wwrite-strings])\nAX_APPEND_COMPILE_FLAGS([-Wmissing-prototypes], ,[-Werror])\nAX_APPEND_COMPILE_FLAGS([-Wextra])\n# xrdp uses many zero initializers (C99 6.7.8.21). These\n# require the warning regarding missing field initializers to\n# be disabled.\nAX_APPEND_COMPILE_FLAGS([-Wno-missing-field-initializers])\nAX_APPEND_COMPILE_FLAGS([-Wno-unused-parameter])\nAX_APPEND_COMPILE_FLAGS([-Wno-sign-compare])\n\nAM_COND_IF([LINUX],\n  [AX_APPEND_COMPILE_FLAGS([-Werror])]) # bsd has warnings that have not been fixed yet\n\nAM_COND_IF([DEVEL_DEBUG],\n  [AX_APPEND_COMPILE_FLAGS([-g -O0])],\n  [AX_APPEND_COMPILE_FLAGS([-O2])])\n\n# Function setusercontext() is in BSD -lutil but N/A on Solaris or GNU systems\nAC_SEARCH_LIBS([setusercontext], [util])\n\n# Define HAVE_XXXXX macros for some system functions\nAC_CHECK_FUNCS([setusercontext getgrouplist clearenv strlcpy])\n\n# The type used by getgrouplist() is the same type used by getgroups()\nAC_TYPE_GETGROUPS\n\n# Don't fail without working nasm if rfxcodec is not enabled\nif test \"x$enable_rfxcodec\" != xyes; then\n  with_simd=no\n  export with_simd\nfi\n\n# Check if -ldl is needed to use dlopen()\nDLOPEN_LIBS=\nAC_CHECK_FUNC(dlopen, [],\n              [AC_CHECK_LIB(dl, dlopen, [DLOPEN_LIBS=-ldl])])\nAC_SUBST(DLOPEN_LIBS)\n\n# checking for openssl\nPKG_CHECK_MODULES([OPENSSL], [openssl >= 0.9.8], [],\n  [AC_MSG_ERROR([please install libssl-dev or openssl-devel])])\n\n# look for openssl binary\nOPENSSL_BIN=`$PKG_CONFIG --variable=exec_prefix openssl`/bin\nAC_PATH_PROGS([OPENSSL], [openssl], [:], [$OPENSSL_BIN:$PATH])\n\n# checking for PAM variation\n# Linux-PAM is used in Linux systems\n# OpenPAM is used by FreeBSD, NetBSD, DragonFly BSD and OS X\n# OpenBSD uses BSD Authentication rather than both PAMs\nAC_CHECK_HEADER([security/_pam_types.h],\n                [AC_DEFINE([HAVE__PAM_TYPES_H], 1, [Using Linux-PAM], [])])\nAC_CHECK_HEADER([security/pam_constants.h],\n                [AC_DEFINE([HAVE_PAM_CONSTANTS_H], 1, [Using OpenPAM], [])])\n\n# shm_open may not be in the C library\nAC_SEARCH_LIBS([shm_open], [rt])\n\n# Find imlib2\ncase \"$with_imlib2\" in\n    '' | no) AC_MSG_NOTICE([imlib2 will not be supported])\n        use_imlib2=no\n        ;;\n    yes)\n        PKG_CHECK_MODULES([IMLIB2], [imlib2 >= 1.4.5],\n            [use_imlib2=yes],\n            [AC_MSG_ERROR([please install libimlib2-dev or imlib2-devel])])\n        ;;\n    /*) AC_MSG_CHECKING([for imlib2 in $with_imlib2])\n        if test -d $with_imlib2/lib; then\n            IMLIB2_LIBS=\"-L$with_imlib2/lib -lImlib2\"\n        elif test -d $with_imlib2/lib64; then\n            IMLIB2_LIBS=\"-L$with_imlib2/lib64 -lImlib2\"\n        else\n            AC_MSG_RESULT([no])\n            AC_MSG_ERROR([Can't find libImlib2 in $with_imlib2])\n        fi\n\n        if test -f $with_imlib2/include/Imlib2.h; then\n            IMLIB2_CFLAGS=\"-I $with_imlib2/include\"\n        else\n            AC_MSG_RESULT([no])\n            AC_MSG_ERROR([Can't find $with_imlib2/include/Imlib2.h])\n        fi\n        AC_MSG_RESULT([yes])\n        AC_SUBST([IMLIB2_LIBS])\n        AC_SUBST([IMLIB2_CFLAGS])\n        use_imlib2=yes\n        ;;\n    *)  AC_MSG_ERROR([--with-imlib2 needs yes/no or absolute path])\nesac\n\nif test x$use_imlib2 = xyes; then\n    AC_DEFINE([USE_IMLIB2],1, [Compile with imlib2 support])\nfi\n\n# Find freetype2\n#\n# The modversion used by pkgcheck does not correspond to the\n# freetype2 release. See docs/VERSIONS.TXT in the freetype2\n# source for a table of correspondences. If you change one\n# of the below defines, change both.\nm4_define([FT2_REQUIRED_VERSION], [2_8_0])\nm4_define([FT2_REQUIRED_MODVERSION], [20.0.14])\ncase \"$with_freetype2\" in\n    '' | no) AC_MSG_NOTICE([freetype2 will not be supported])\n        use_freetype2=no\n        ;;\n    yes)\n        PKG_CHECK_MODULES([FREETYPE2], [freetype2 >= FT2_REQUIRED_MODVERSION],\n            [use_freetype2=yes],\n            [AC_MSG_ERROR([please install version FT2_REQUIRED_VERSION or later of libfreetype6-dev or freetype-devel])])\n        ;;\n    /*) AC_MSG_CHECKING([for freetype2 in $with_freetype2])\n        if test -d $with_freetype2/lib; then\n            FREETYPE2_LIBS=\"-L$with_freetype2/lib -llibfreetype\"\n        elif test -d $with_freetype2/lib64; then\n            FREETYPE2_LIBS=\"-L$with_freetype2/lib64 -llibfreetype\"\n        else\n            AC_MSG_RESULT([no])\n            AC_MSG_ERROR([Can't find libfreetype in $with_freetype2])\n        fi\n\n        if test -f $with_freetype2/include/freetype2/ft2build.h; then\n            FREETYPE2_CFLAGS=\"-isystem $with_freetype2/include/freetype2\"\n        else\n            AC_MSG_RESULT([no])\n            AC_MSG_ERROR([Can't find $with_freetype2/include/freetype2/ft2build.h])\n        fi\n        AC_MSG_RESULT([yes])\n        AC_SUBST([FREETYPE2_LIBS])\n        AC_SUBST([FREETYPE2_CFLAGS])\n        use_freetype2=yes\n        ;;\n    *)  AC_MSG_ERROR([--with-freetype2 needs yes/no or absolute path])\nesac\nAM_CONDITIONAL([USE_FREETYPE2], [test \"x$use_freetype2\" = xyes])\n\n# Check only one auth mechanism is specified, and give it a name\nauth_cnt=0\nauth_mech=\"Builtin\"\nAUTHMOD_OBJ=verify_user.lo\nAUTHMOD_LIB=-lcrypt\nif test x$enable_pam = xyes\nthen\n  auth_cnt=`expr $auth_cnt + 1`\n  auth_mech=\"PAM\"\n  AUTHMOD_OBJ=verify_user_pam.lo\n  AUTHMOD_LIB=-lpam\nfi\nif test x$enable_bsd = xyes\nthen\n  auth_cnt=`expr $auth_cnt + 1`\n  auth_mech=\"BSD\"\n  AUTHMOD_OBJ=verify_user_bsd.lo\n  AUTHMOD_LIB=\nfi\nif test x$enable_kerberos = xyes\nthen\n  auth_cnt=`expr $auth_cnt + 1`\n  auth_mech=\"Kerberos\"\n  AUTHMOD_OBJ=verify_user_kerberos.lo\n  AUTHMOD_LIB=-lkrb5\nfi\nif test x$enable_pamuserpass = xyes\nthen\n  auth_cnt=`expr $auth_cnt + 1`\n  auth_mech=\"PAM userpass\"\n  AUTHMOD_OBJ=verify_user_pam_userpass.lo\n  AUTHMOD_LIB=\"-lpam -lpam_userpass\"\nfi\n\nif test $auth_cnt -gt 1\nthen\n  AC_MSG_ERROR([--enable-pam, --enable-bsd, --enable-pamuserpass and --enable-kerberos are mutually exclusive])\nfi\n\nAC_SUBST([AUTHMOD_OBJ])\nAC_SUBST([AUTHMOD_LIB])\n\n# checking if pam should be autodetected.\nif test \"x$enable_pam\" = \"xyes\"\nthen\n  AC_CHECK_HEADER([security/pam_appl.h], [],\n    [AC_MSG_ERROR([please install libpam0g-dev or pam-devel])])\n  if test \"x$enable_pam_config\" = \"x\"; then\n    PAM_RULES=\"auto\"\n  else\n    pam_config_file=\"$srcdir/instfiles/pam.d/xrdp-sesman.$enable_pam_config\"\n    if test -f \"$pam_config_file\"; then\n      PAM_RULES=\"$enable_pam_config\"\n    else\n      AC_MSG_ERROR([PAM file \"$pam_config_file\" is not available])\n    fi\n  fi\nfi\n\nAC_SUBST(PAM_RULES)\n\n# Add define for development options to config_ac.h\nAC_DEFINE([CONFIG_AC_H],1, [Allow sources to check config_ac.h is included])\nif test x$devel_logging = xyes\nthen\n  AC_DEFINE([USE_DEVEL_LOGGING],1,[Enable development logging])\nfi\n\nif test x$devel_streamcheck = xyes\nthen\n  AC_DEFINE([USE_DEVEL_STREAMCHECK],1,[Enable development stream checking])\nfi\n\nif test \"x$enable_vsock\" = \"xyes\"\nthen\n  enable_vsock=yes\n  if test \"x$freebsd\" = \"xyes\"\n  then\n    # Determine if we have AF_HYPERV defined (FreeBSD 13+)\n    AC_CHECK_DECL([AF_HYPERV], [AC_DEFINE([XRDP_ENABLE_VSOCK], 1, [Enable AF_HYPERV])], [], [#include <sys/socket.h>])\n  else\n    AC_CHECK_HEADERS([linux/socket.h linux/vm_sockets.h],\n                    [AC_DEFINE([XRDP_ENABLE_VSOCK], 1, [Enable AF_VSOCK])],\n                    [],\n                    [#include <sys/socket.h>])\n  fi\nfi\n\nif test \"x$enable_ipv6only\" = \"xyes\"\nthen\n  enable_ipv6=yes\n  AC_DEFINE([XRDP_ENABLE_IPV6ONLY],1,[Enable IPv6 only])\nfi\n\nif test \"x$enable_ipv6\" = \"xyes\"\nthen\n  AC_DEFINE([XRDP_ENABLE_IPV6],1,[Enable IPv6])\nfi\n\nAS_IF( [test \"x$enable_neutrinordp\" = \"xyes\"] , [PKG_CHECK_MODULES(FREERDP, freerdp >= 1.0.0)] )\n\n# checking for libjpeg\nif test \"x$enable_jpeg\" = \"xyes\"\nthen\n  AC_CHECK_HEADER([jpeglib.h], [],\n    [AC_MSG_ERROR([please install libjpeg-dev or libjpeg-devel])])\nfi\n\n# checking for fuse\nif test \"x$enable_fuse\" = \"xyes\"\nthen\n  PKG_CHECK_MODULES([FUSE], [fuse3 >= 3.1.0], [],\n    [AC_MSG_ERROR([please install libfuse3-dev or fuse3-devel])])\nfi\n\n# checking for fdk aac\nif test \"x$enable_fdkaac\" = \"xyes\"\nthen\n  PKG_CHECK_MODULES([FDKAAC], [fdk-aac >= 0.1.0], [],\n    [AC_MSG_ERROR([please install libfdk-aac-dev or fdk-aac-devel])])\nfi\n\n# checking for opus\nif test \"x$enable_opus\" = \"xyes\"\nthen\n  AC_CHECK_HEADER([opus/opus.h], [],\n    [AC_MSG_ERROR([please install libopus-dev or opus-devel])])\nfi\n\n# checking for lame mp3\nif test \"x$enable_mp3lame\" = \"xyes\"\nthen\n  AC_CHECK_HEADER([lame/lame.h], [],\n    [AC_MSG_ERROR([please install libmp3lame-dev or lame-devel])])\nfi\n\n# checking for ibus includes\nif test \"x$enable_ibus\" = \"xyes\"\nthen\n  PKG_CHECK_MODULES([IBUS], [ibus-1.0 >= 1.5], [],\n    [AC_MSG_ERROR([please install libibus-1.0-dev or ibus-devel])])\n\n  # ibus uses dbus which depends on glib\n  PKG_CHECK_MODULES([GLIB2], [glib-2.0 >= 2.56], [],\n    [AC_MSG_ERROR([please install libglib2.0-dev or glib2.0-devel])])\nfi\n\nAS_IF( [test \"x$enable_pixman\" = \"xyes\"] , [PKG_CHECK_MODULES(PIXMAN, pixman-1 >= 0.1.0)] )\n\nAS_IF( [test \"x$enable_x264\" = \"xyes\"] , [PKG_CHECK_MODULES(XRDP_X264, x264 >= 0.3.0)] )\n\nAS_IF( [test \"x$enable_openh264\" = \"xyes\"] , [PKG_CHECK_MODULES(XRDP_OPENH264, openh264 >= 2.0.0)] )\n\nif test \"x$enable_nvenc\" = \"xyes\"\nthen\nenable_accel=$enable_nvenc\nif test ! -z \"$XRDP_NVENC_CFLAGS\"\nthen\n  AC_SUBST(XRDP_NVENC_CFLAGS, [\"$XRDP_NVENC_CFLAGS\"])\nfi\nif test ! -z \"$XRDP_NVENC_LIBS\"\nthen\n  AC_SUBST(XRDP_NVENC_LIBS, [\"$XRDP_NVENC_LIBS\"])\nfi\nfi\n\nAM_CONDITIONAL(XRDP_ACCEL, [test x$enable_accel = xyes])\n\n# checking for TurboJPEG\nif test \"x$enable_tjpeg\" = \"xyes\"\nthen\nif test ! -z \"$TURBOJPEG_PATH\"\nthen\n  # env var TURBOJPEG_PATH has been defined, use that\n  AC_CHECK_HEADER([$TURBOJPEG_PATH/include/turbojpeg.h], [],\n    [AC_MSG_ERROR([could not find TurboJPEG in dir specified by env variable TURBOJPEG_PATH ($TURBOJPEG_PATH)])])\n\n   AC_SUBST(TurboJpegIncDir, [\"-I$TURBOJPEG_PATH/include\"])\n   AC_SUBST(TurboJpegLibDir, [\"-L$TURBOJPEG_PATH/lib -Wl,-rpath -Wl,$TURBOJPEG_PATH/lib\"])\nelif test -e /opt/libjpeg-turbo/lib64\nthen\n  # TurboJPEG has been installed to /opt on a 64 bit m/c\n  AC_SUBST(TurboJpegIncDir, [\"-I/opt/libjpeg-turbo/include\"])\n  AC_SUBST(TurboJpegLibDir, [\"-L/opt/libjpeg-turbo/lib64 -Wl,-rpath -Wl,/opt/libjpeg-turbo/lib64\"])\nelif test -e /opt/libjpeg-turbo/lib32\nthen\n  # TurboJPEG has been installed to /opt on a 32 bit m/c\n  AC_SUBST(TurboJpegIncDir, [\"-I/opt/libjpeg-turbo/include\"])\n  AC_SUBST(TurboJpegLibDir, [\"-L/opt/libjpeg-turbo/lib32 -Wl,-rpath -Wl,/opt/libjpeg-turbo/lib32\"])\nelse\n  # check in default location\n  AC_CHECK_HEADER([/usr/include/turbojpeg.h], [],\n    [AC_MSG_ERROR([please install TurboJPEG ])])\n  AC_SUBST(TurboJpegIncDir, [\"\"])\n  AC_SUBST(TurboJpegLibDir, [\"\"])\nfi\nfi\n\nAC_PATH_XTRA\nif test \"x$no_x\" == \"xyes\"; then\n  AC_MSG_ERROR([please install libx11-dev or libX11-devel])\nfi\n\nsave_CFLAGS=\"$CFLAGS\"\nCFLAGS=\"$CFLAGS $X_CFLAGS\"\n\n# checking for Xfixes\nAC_CHECK_HEADER([X11/extensions/Xfixes.h], [],\n  [AC_MSG_ERROR([please install libxfixes-dev or libXfixes-devel])],\n  [#include <X11/Xlib.h>])\n\n# checking for Xrandr\nAC_CHECK_HEADER([X11/extensions/Xrandr.h], [],\n  [AC_MSG_ERROR([please install libxrandr-dev or libXrandr-devel])],\n  [#include <X11/Xlib.h>])\n\n# checking for XKB\nAC_CHECK_HEADER([X11/extensions/XKBrules.h], [],\n  [AC_MSG_ERROR([please install libxkbfile-dev or libxkbfile-devel])],\n  [#include <X11/Xlib.h>\n#include <X11/XKBlib.h>\n#include <stdio.h>])\n\nif test \"x$enable_utmp\" = \"xyes\"\nthen\n    AC_CHECK_HEADERS(utmp.h utmpx.h)\n\n    # Test for non-standard extensions in struct utmpx\n    AXRDP_CHECK_UTMPX_MEMBER_EXISTS([ut_host], [HAVE_UTMPX_UT_HOST])\n    AXRDP_CHECK_UTMPX_MEMBER_EXISTS([ut_exit], [HAVE_UTMPX_UT_EXIT])\nfi\n\nCFLAGS=\"$save_CFLAGS\"\n\n# perform unit tests if libcheck and libmocka found\nperform_unit_tests=yes; # Assume packages will be found\nif test \"x$ensure_tests_deps\" == \"xyes\"; then\n    PKG_CHECK_MODULES([CHECK], [check >= 0.10.0],\n        [],\n        [AC_MSG_ERROR([please install check, the unit test framework])])\n    # Check if cmocka is available - needed for unit testing\n    PKG_CHECK_MODULES([CMOCKA], [cmocka],\n        [],\n        [AC_MSG_ERROR([please install cmocka, the mocking framework])])\nelse\n    PKG_CHECK_MODULES([CHECK], [check >= 0.10.0],\n        [],\n        [perform_unit_tests=no])\n    PKG_CHECK_MODULES([CMOCKA], [cmocka],\n        [],\n        [perform_unit_tests=no])\nfi\n\nif test \"x$perform_unit_tests\" == \"xyes\"; then\n    AC_MSG_NOTICE([libcheck found, unit tests will be performed])\nelse\n    AC_MSG_NOTICE([libcheck not found, unit tests will be skipped])\nfi\n# -- end perform unit tests\n\nAC_SUBST([moduledir], '${libdir}/xrdp')\n\nAC_ARG_ENABLE([strict-locations],\n  [AS_HELP_STRING([--enable-strict-locations],\n                  [Use standard Autoconf install directories unless overridden\n                   (default: use /etc and /var)])],\n                  [], [enable_strict_locations=no])\n\nif test \"x$enable_strict_locations\" != \"xyes\"; then\n  sysconfdir=\"/etc\";\n  localstatedir=\"/var\";\nfi\n\nAC_ARG_WITH([pamconfdir],\n  [AS_HELP_STRING([--with-pamconfdir=DIR],\n                  [Use directory for pam.d config (default: /etc/pam.d)])],\n                  [], [with_pamconfdir=\"$sysconfdir/pam.d\"])\nAC_SUBST([pamconfdir], [$with_pamconfdir])\n\nAC_ARG_WITH([sysconfsubdir],\n  [AS_HELP_STRING([--with-sysconfsubdir=DIR],\n                  [Use subdirectory for config files (default: xrdp)]))],\n                  [], [with_sysconfsubdir=\"xrdp\"])\nAC_SUBST([sysconfsubdir], [$with_sysconfsubdir])\n\nPKG_INSTALLDIR\n\nAC_CHECK_HEADERS([sys/prctl.h uchar.h])\n\nAC_CONFIG_FILES([\n  common/Makefile\n  docs/Makefile\n  docs/man/Makefile\n  fontutils/Makefile\n  genkeymap/Makefile\n  instfiles/default/Makefile\n  instfiles/init.d/Makefile\n  instfiles/Makefile\n  instfiles/pam.d/Makefile\n  instfiles/pulse/Makefile\n  instfiles/rc.d/Makefile\n  keygen/Makefile\n  waitforx/Makefile\n  libipm/Makefile\n  libxrdp/Makefile\n  Makefile\n  mc/Makefile\n  neutrinordp/Makefile\n  ulalaca/Makefile\n  pkgconfig/Makefile\n  pkgconfig/xrdp.pc\n  pkgconfig/xrdp-uninstalled.pc\n  sesman/libsesman/Makefile\n  sesman/chansrv/Makefile\n  sesman/Makefile\n  sesman/sesexec/Makefile\n  sesman/tools/Makefile\n  tests/Makefile\n  tests/common/Makefile\n  tests/libipm/Makefile\n  tests/libxrdp/Makefile\n  tests/memtest/Makefile\n  tests/xrdp/Makefile\n  tools/Makefile\n  tools/devel/Makefile\n  tools/devel/tcp_proxy/Makefile\n  tools/chkpriv/Makefile\n  vnc/Makefile\n  xrdpapi/Makefile\n  xrdp/Makefile\n  xrdpvr/Makefile\n  xup/Makefile\n  third_party/Makefile\n  third_party/tomlc99/Makefile\n  xrdp_accel_assist/Makefile\n\n])\n\nAC_REQUIRE_AUX_FILE([tap-driver.sh])\nAC_OUTPUT\n\necho \"\"\necho \"xrdp will be compiled with:\"\necho \"\"\necho \"  mp3lame                         $enable_mp3lame\"\necho \"  opus                            $enable_opus\"\necho \"  fdkaac                          $enable_fdkaac\"\necho \"  jpeg                            $enable_jpeg\"\necho \"  turbo jpeg                      $enable_tjpeg\"\necho \"  rfxcodec                        $enable_rfxcodec\"\necho \"  x264                            $enable_x264\"\necho \"  openh264                        $enable_openh264\"\necho \"  nvenc                           $enable_nvenc\"\necho \"  accel                           $enable_accel\"\necho \"  painter                         $enable_painter\"\necho \"  pixman                          $enable_pixman\"\necho \"  fuse                            $enable_fuse\"\necho \"  ipv6                            $enable_ipv6\"\necho \"  ipv6only                        $enable_ipv6only\"\necho \"  vsock                           $enable_vsock\"\necho \"  ibus                            $enable_ibus\"\necho \"  auth mechanism                  $auth_mech\"\necho \"  rdpsndaudin                     $enable_rdpsndaudin\"\necho \"  smartcard (not for production)  $enable_smartcard\"\necho \"  utmp support                    $enable_utmp\"\nif test x$enable_utmp = xyes; then\n    echo \"    utmpx.ut_host                 $ac_cv_utmpx_has_ut_host\"\n    echo \"    utmpx.ut_exit                 $ac_cv_utmpx_has_ut_exit\"\nfi\nif test -n \"$with_systemdsystemunitdir\" \\\n        -a \"x$with_systemdsystemunitdir\" != xno; then\n    echo \"  systemd support                 yes\"\n    echo \"    unit file directory           $with_systemdsystemunitdir\"\nelse\n    echo \"  systemd support                 no\"\nfi\n\necho\necho \"  with imlib2                     $use_imlib2\"\necho \"  with freetype2                  $use_freetype2\"\n\necho\necho \"  development logging             $devel_logging\"\necho \"  development streamcheck         $devel_streamcheck\"\necho \"\"\necho \"  strict_locations                $enable_strict_locations\"\necho \"  prefix                          $prefix\"\necho \"  exec_prefix                     $exec_prefix\"\necho \"  libdir                          $libdir\"\necho \"  bindir                          $bindir\"\necho \"  sysconfdir                      $sysconfdir\"\necho \"  sysconfdir+subdir               $sysconfdir/$sysconfsubdir\"\necho \"  pamconfdir                      $pamconfdir\"\necho \"  localstatedir                   $localstatedir\"\necho \"  runstatedir                     $runstatedir\"\necho \"  socketdir                       $socketdir\"\necho \"\"\necho \"  unit tests performable          $perform_unit_tests\"\necho \"\"\necho \"  CFLAGS = $CFLAGS\"\necho \"  LDFLAGS = $LDFLAGS\"\n\n# xrdp_configure_options.h will be written to the build directory, not the source directory\necho '#define XRDP_CONFIGURE_OPTIONS \\' > ./xrdp_configure_options.h\n./config.status --config | xargs -n 1 | sed -e 's/^/\"      /' -e 's/$/\\\\n\" \\\\/' >> ./xrdp_configure_options.h\necho '\"\"' >> ./xrdp_configure_options.h\n"
  },
  {
    "path": "docs/Makefile.am",
    "content": "\nSUBDIRS = \\\n  man\n"
  },
  {
    "path": "docs/man/.gitignore",
    "content": "*.[1-8]\n"
  },
  {
    "path": "docs/man/Makefile.am",
    "content": "man_MANS = \\\n  xrdp-dis.1 \\\n  gfx.toml.5 \\\n  sesman.ini.5 \\\n  xrdp.ini.5 \\\n  xrdp-km.toml.5 \\\n  xrdp.8 \\\n  xrdp-chansrv.8 \\\n  xrdp-genkeymap.8 \\\n  xrdp-keygen.8 \\\n  xrdp-sesadmin.8 \\\n  xrdp-sesman.8 \\\n  xrdp-sesrun.8 \\\n  xrdp-dumpfv1.8\n\nEXTRA_DIST = xrdp-mkfv1.8.in $(man_MANS:=.in)\n\nif USE_FREETYPE2\n  man_MANS += xrdp-mkfv1.8\nendif\n\nSUBST_VARS = sed \\\n   -e 's|@PACKAGE_VERSION[@]|$(PACKAGE_VERSION)|g' \\\n   -e 's|@bindir[@]|$(bindir)|g' \\\n   -e 's|@sbindir[@]|$(sbindir)|g' \\\n   -e 's|@localstatedir[@]|$(localstatedir)|g' \\\n   -e 's|@sysconfdir[@]|$(sysconfdir)|g' \\\n   -e 's|@sysconfsubdir[@]|$(sysconfsubdir)|g' \\\n   -e 's|@socketdir[@]|$(socketdir)|g' \\\n   -e 's|@xrdpconfdir[@]|$(sysconfdir)/xrdp|g' \\\n   -e 's|@xrdpdatadir[@]|$(datadir)/xrdp|g' \\\n   -e 's|@xrdphomeurl[@]|http://www.xrdp.org/|g'\n\nsubst_verbose = $(subst_verbose_@AM_V@)\nsubst_verbose_ = $(subst_verbose_@AM_DEFAULT_V@)\nsubst_verbose_0 = @echo \"  SUBST    $@\";\n\nSUFFIXES = .in\n.in:\n\t$(subst_verbose)$(SUBST_VARS) $< > $@\n\nCLEANFILES = $(man_MANS)\n"
  },
  {
    "path": "docs/man/gfx.toml.5.in",
    "content": ".\\\"\n.TH \"gfx.toml\" \"8\" \"@PACKAGE_VERSION@\" \"xrdp team\" \"\"\n.SH \"NAME\"\n\\fBgfx.toml\\fR \\- Configuration file for xrdp(8) graphics pipeline extension\n\n.SH \"DESCRIPTION\"\n\nThis file configures the detailed settings of the Graphics Pipeline Extension\nfor xrdp(8). The file format is TOML. See the link in the SEE ALSO section for\nTOML syntax.\n\nThe file contains following sections:\n\n.TP\n\\fB[codec]\\fR \\- configure preferred codec and encoders for \\fBxrdp\\fR(8).\n\n.TP\n\\fB[x264]\\fR \\- parameters for x264 encoder.\n\n.TP\n\\fB[OpenH264]\\fR \\- parameters for Cisco OpenH264 encoder.\n\n.LP\nAll options and values are case-sensitive, with some exception, and are\ndescribed in detail below.\n\n.SH \"CODEC\"\n\\fB[codec]\\fR section defines preferred codec order and encoder. The options\nto be specified in this section are the following:\n\n.TP\n\\fBorder\\fR = \\fI<array>\\fR\nDefine the order in which codecs should be used, \"H.264\" and \"RFX\".\nSpecify as an array of strings like \\fB[ \"H.264\", \"RFX ]\\fR.\nStrings in the array are case-insensitive, while others are case-sensitive.\n\n.TP\n\\fBh264_encoder\\fR = \\fI<string>\\fR\nSpecify a preferred H.264 encoder, \\fB\"x264\"\\fR or \\fB\"OpenH264\"\\fR.\nThis parameter takes effect only when more than one encoder is\nenabled at compile time. If only one H.264 encoder is enabled, the encoder\nwill be used regardless the value of this parameter. Defaults to \\fB\"x264\"\\fR\nif not specified or if an invalid encoder is specified. The encoder name is\ncase-insensitive.\n\n.SH \"X264\"\n\\fB[x264]\\fR section defines encoding parameters that will be passed to\nx264 encoder. See \\fBx264 --fullhelp\\fR for the detailed explanations of the\nparameters. The options to be specified in this section are following:\n\n.TP\n\\fBpreset\\fR = \\fI<string>\\fR\nSelect a preset encoding settings. Slower presets result in higher CPU usage\nbut offer better screen image quality and require lower network bandwidth.\nHere are available presets:\n\n.B ultrafast, superfast, veryfast, faster, fast, medium, slow, slower,\nveryslow, placebo\n\nPresets slower than \\fBmedium\\fR may not suitable for use with xrdp.\n\n.TP\n\\fBtune\\fR = \\fI<string>\\fR\nSelect a tune for source or situation. \\fBzerolatency\\fR is most appropriate\nfor use with xrdp. Here are available options:\n\n.B film, grain, stillimage, psnr, ssim, fastdecode, zerolatency\n\n.TP\n\\fBprofile\\fR = \\fI<string>\\fR\nSelect a profile. Here are available options:\n\n.B main, baseline, high, high10, high422, high444\n\n.TP\n\\fBvbv_max_bitrate\\fR = \\fI<integer>\\fR\nSet the maximum fill rate for the VBV (Video Buffering Vefifier) buffer\nin kbps.\n\n.TP\n\\fBvbv_buffer_size\\fR = \\fI<integer>\\fR\nSet the size of the VBV buffer size in kilobits.\n\n.TP\n\\fBfps_num\\fR = \\fI<integer>\\fR\nSet the fps numerator.\n\n.TP\n\\fBfps_den\\fR = \\fI<integer>\\fR\nSet the fps denominator.\n\n.TP\n\\fBthreads = \\fI<integer>\\fR\nSpecify how many CPU threads to use for H.264 encoding per screen (0 for\nauto). Carefully evaluate this value when configuring it to avoid exhausting\nthe available threads. For example, if 3 users are connected simultaneously\nwith dual screens, xrdp may use up to <threads> * 3 * 2 threads for H.264\nencoding. Please also note that too many threads can hurt quality.\n\n.SH \"OPENH264\"\n\n\\fB[OpenH264]\\fR section defines encoding parameters that will be passed to\nOpenH264 encoder. The options to be specified in this section are following:\n\n.TP\n\\fBEnableFrameSkip\\fR = \\fI<boolean>\\fR\nAllows the encoder to skip frames in order to keep the bitrate within the\nlimits if it is about to exceed the maximum bitrate set by MaxBitrate.\n\n.TP\n\\fBTargetBitrate\\fR = \\fI<integer>\\fR\nSets the target average bitrate (in bps) that the encoder will attempt to\nachieve throughout the encoding process.\n\n.TP\n\\fBMaxBitrate\\fR = \\fI<integer>\\fR\nSets an upper limit of the bitrate in bps.\n.TP\n\\fBMaxFrameRate\\fR = \\fI<float>\\fR\nSets the maximum frame rate that the encoder will process per second.\n\n.SH \"CONNECTION TYPES\"\n\n\\fB[x264]\\fR and \\fB[OpenH264]\\fR section are tables (also known as\ndictionaries) that have subtables with connection types in their keys.\nFor example, \\fB[x264.lan]\\fR, \\fB[OpenH264.wan]\\fR.\n\nYou can configure different parameters such as bitrate for the encoder\nper connection type. Define the default parameter set first, this will be\ninherited to all connection types unless explicitly overridden in each\nconnection type.\n\nList of available connection types are:\n\n.B lan, wan, broadband_high, satellite, broadband_low, modem, and default\n\nCurrently, xrdp does not support connection type autodetection. If autodetect\nis selected on the client side, it will be treated as if LAN is selected.\n\n.SH \"EXAMPLES\"\nThis is an example \\fBgfx.toml\\fR:\n\n.nf\n[codec]\norder = [ \"H.264\", \"RFX\" ]\nh264_encoder = \"x264\"\n\n[x264.default]\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 60\nfps_den = 1\n\n[x264.lan]\n# inherits default, everything is same with the default\n[x264.wan]\n# parameters that are not explicitly overridden inherit the default values\npreset = \"veryfast\"\nvbv_max_bitrate = 15_000\nvbv_buffer_size = 1_500\n.fi\n\nThere are multiple ways to represent the data structure in TOML format. The\nfollowing two representations are semantically equivalent but the latter is \ndiscouraged due to concerns about complexity and readability.\n\n.nf\n[x264.default]\npreset = \"ultrafast\"\ntune = \"zerolatency\"\n.fi\n\n.nf\nx264 = { default = { preset = \"ultrafast\", tune=\"zerolatency\" } }\n.fi\n\n.SH \"SEE ALSO\"\n\nFor more information on \\fBgfx.toml\\fR configuration, see the wiki page.\n\n.UR https://github.com/neutrinolabs/xrdp/wiki/H.264-encoding\n.UE\n\nThe syntax for TOML files can be found at the following page.\n\n.UR https://toml.io/en/v1.0.0\n.UE\n"
  },
  {
    "path": "docs/man/sesman.ini.5.in",
    "content": ".\\\"\n.TH \"sesman.ini\" \"5\" \"@PACKAGE_VERSION@\" \"xrdp team\" \"\"\n.SH \"NAME\"\n\\fBsesman.ini\\fR \\- Configuration file for \\fBxrdp-sesman\\fR(8)\n\n.SH \"DESCRIPTION\"\n\\fBsesman.ini\\fR consists of several sections. Each section starts with\nthe section name in square brackets, followed by a list of\n\\fIparameter\\fR=\\fIvalue\\fR lines. Following sections are recognized:\n\n.TP\n\\fB[Globals]\\fR\nGlobal configuration\n\n.TP\n\\fB[Logging]\\fR\nLogging subsystem\n\n.TP\n\\fB[Sessions]\\fR\nSession management\n\n.TP\n\\fB[Security]\\fR\nAccess control\n\n.TP\n\\fB[Chansrv]\\fR\nSettings for xrdp-chansrv(8)\n\n.TP\n\\fB[ChansrvLogging]\\fR\nLogging settings for xrdp-chansrv(8)\n\n.TP\n\\fB[SessionVariables]\\fR\nEnvironment variables for the session\n\n.LP\nAll parameters and values (except for file names and paths) are case\ninsensitive, and are described in detail below. If any parameter is\nspecified more than once, the last entry will be used. Options specified\noutside their proper section will be \\fIignored\\fR.\n\n.SH \"GLOBALS\"\nFollowing parameters can be used in the \\fB[Globals]\\fR section.\n\n.TP\n\\fBListenPort\\fR=\\fIpath-to-socket\\fR\nUNIX domain socket for xrdp-sesman(8) to listen on.\n.PP\n.RS\nThe default value of this setting is 'sesman.socket'.\n.PP\nAn absolute path can be specified by starting this parameter with a '/'.\nIn this instance, the system administrator is responsible for ensuring\nthe socket can only be created by a suitably privileged process.\n.PP\nIf the parameter does not start with a '/', a name within\n@socketdir@/\\fI<uid>\\fR is used.\n.RE\n\n.TP\n\\fBEnableUserWindowManager\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR, this option enables user\nspecific startup script. That is, xrdp-sesman will execute the script\nspecified by \\fBUserWindowManager\\fR if it exists.\n\n.TP\n\\fBUserWindowManager\\fR=\\fIfilename\\fR\nPath of the startup script relative to the user's home directory. If\npresent and enabled by \\fBEnableUserWindowManager\\fR, that script is\nexecuted instead of \\fBDefaultWindowManager\\fR.\n\n.TP\n\\fBDefaultWindowManager\\fR=\\fIfilename\\fR\nFull path or relative path of the default startup script used by xrdp-sesman\nto start a session.  If the path is not a full path, it will be resolved as\nrelative path to \\fI@xrdpconfdir@\\fR. If not specified, defaults to\n\\fI@xrdpconfdir@/startwm.sh\\fR.\n\n.TP\n\\fBReconnectScript\\fR=\\fIfilename\\fR\nFull path or relative path if the script which executed when users reconnects\nto the existing session. If the path is not a full path, it will be resolved as\nrelative path to \\fI@xrdpconfdir@\\fR. If not specified, defaults to\n\\fI@xrdpconfdir@/reconnectwm.sh\\fR.\n\n.TP\n\\fBAlwaysRunReconnect\\fR=\\fI[yes|no]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR, the \\fBReconnectScript\\fR will\nbe run for the initial connection to a session, as well as all reconnects.\n\n.SH \"LOGGING\"\nFollowing parameters can be used in the \\fB[Logging]\\fR and \\fB[ChansrvLogging]\\fR \nsections.\n\n.TP\n\\fBLogFile\\fR=\\fIfilename\\fR\nLog file path. It can be either absolute or relative. If not specified,\ndefaults to \\fI./sesman.log\\fR. If set to \\fB<stdout>\\fR, log will go to\nstdout. Use for debugging only\\fR\n\nIt is ignored in the [ChansrvLogging] section\nsince the channel server creates one log file per display and instead uses the\nfollowing log file naming convention \\fIxrdp-chansrv.${DISPLAY}.log\\fR. For\ndetails of the chansrv log file location, see \\fBLogFilePath\\fR.\n\n.TP\n\\fBLogFilePath\\fR=\\fIstring\\fR\nDirectory for storing the chansrv log file. This setting only applies to\nchansrv. The sesman log file is always created in \\fI@localstatedir@/log\\fR.\n\nCreated if it doesn't exist.\nIf first character is not a '/', this is relative to $HOME, where\nchansrv is normally started.\n\n.RS\nThe following substitutions are made in this string:-\n    %U - Username\n    %u - Numeric UID\n    %% - Percent character\n\nThis is most useful if you are using NFS-mounted home directories, and\nwish to move the chansrv log file to the local disk.\n\nIf this parameter isn't specified, the log file is stored in one of\nthe following locations :-\n    -   $CHANSRV_LOG_PATH\n    -   $XDG_DATA_HOME/xrdp\n    -   $HOME/.local/share/xrdp\n.RE\n\n.TP\n\\fBLogLevel\\fR=\\fIlevel\\fR\nThis option can have one of the following values:\n\n\\fBCORE\\fR or \\fB0\\fR \\- Log only core messages. Those messages are\nlogged \\fIregardless\\fR of the selected logging level.\n\n\\fBERROR\\fR or \\fB1\\fR \\- Log only error messages.\n\n\\fBWARNING\\fR, \\fBWARN\\fR or \\fB2\\fR \\- Logs warnings and error messages.\n\n\\fBINFO\\fR or \\fB3\\fR \\- Log errors, warnings and informational messages.\n\n\\fBDEBUG\\fR or \\fB4\\fR \\- Log everything. If xrdp-sesman is compiled in\ndebug mode, this options will output many more low\\-level messages.\n\n.TP\n\\fBEnableSyslog\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR, this option enables logging to\nsyslog.\n\n.TP\n\\fBSyslogLevel\\fR=\\fIlevel\\fR\nLogging level for syslog. It can have the same values as \\fBLogLevel\\fR.\nDefaults to \\fBDEBUG\\fR.\n\n.TP\n\\fBEnableConsole\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR, this option enables logging to\nthe console (ie. stdout).\n\n.TP\n\\fBConsoleLevel\\fR=\\fIlevel\\fR\nLogging level for the console. It can have the same values as \\fBLogLevel\\fR.\nDefaults to \\fBDEBUG\\fR.\n\n.TP\n\\fBEnableProcessId\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR, this option enables logging the\nprocess id in all log messages. Defaults to \\fBfalse\\fR.\n\n.SH \"SESSIONS\"\nFollowing parameters can be used in the \\fB[Sessions]\\fR section.\n\n.TP\n\\fBX11DisplayOffset\\fR=\\fInumber\\fR\nThe first X display number available for xrdp-sesman. This prevents\nxrdp-sesman from interfering with real X11 servers. If not specified,\ndefaults to \\fI10\\fR.\n\n.TP\n\\fBMaxSessions\\fR=\\fInumber\\fR\nSets the maximum number of simultaneous sessions. If not set or set to\n\\fI0\\fR, unlimited session are allowed.\n\n.TP\n\\fBMaxDisplayNumber\\fR=\\fInumber\\fR\nSets the maximum number which can be assigned to an X11 $DISPLAY. The\ndefault is compatible with IANA TCP port allocations. If you are not\nallowing TCP connections to your X servers you may safely increase this\nnumber.\n\n.TP\n\\fBKillDisconnected\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR, every session will be killed\nwithin \\fBDisconnectedTimeLimit\\fR seconds after the user disconnects.\nThis setting currently only works with xorgxrdp sessions.\n\n.TP\n\\fBDisconnectedTimeLimit\\fR=\\fInumber\\fR\nSets the time limit for \\fBKillDisconnected\\fR to a value greater than 60.\nValues less than 60 are to be overridden with 60.\nThis setting currently only works with xorgxrdp sessions.\n\n.TP\n\\fBIdleTimeLimit\\fR=\\fInumber\\fR\nSets the time limit (in seconds) before an idle session is disconnected.\nIdle means no keyboard inputs and no mouse moves/clicks here.\nIf set to \\fI0\\fR, idle sessions will never be disconnected by timeout.\nThis works only with xorgxrdp sessions. Moreover, xorgxrdp must be v0.2.9 or later.\n\n.TP\n\\fBPolicy\\fR=\\fI[Default|Separate|{UBDI}]\\fR\nSession allocation policy. Used to decide when to allocate a\nnew session. Set to one of the following values:\n.br\n\n.RS\n.HP 12\n\\fBDefault\\fR -   Currently the same as \"UB\" for all session types\n.HP 12\n\\fBSeparate\\fR -  All sessions are separate. Sessions can never be rejoined,\nand will need to be cleaned up manually, or automatically by setting other\nsesman options.\n.P\nAlternatively combine one-or-more of the following options\n.HP 4\n\\fBU\\fR - Sessions are separated per user\n.HP 4\n\\fBB\\fR - Sessions are separated by bits-per-pixel\n.HP 4\n\\fBD\\fR - Sessions are separated by initial display size\n.HP 4\n\\fBI\\fR - Sessions are separated by IP address\n.HP 4\n\\fBN\\fR - Sessions are separated by an instance name specified on startup\n.RE\n\n.IP\nNote that the \\fBU\\fR and \\fBB\\fR criteria cannot be turned\noff. \\fBDisplaySize\\fR refers to the initial geometry of a connection,\nas actual display sizes can change dynamically.\n\n.TP\n\\fBStartupWaitTime\\fR=\\fInumber\\fR\nMilliseconds to wait to ensure the session has started. The default is 1500\nmilli-seconds.\n.IP\nMaking this larger does not increase the session startup time, but\nwill increase the time for the first connection to a session.\nThe value can be set to zero. If this is done, sessions which fail\nearly will not be reported to the user.\n\n.SH \"SECURITY\"\nFollowing parameters can be used in the \\fB[Security]\\fR section.\n\n.TP\n\\fBAllowRootLogin\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR, enables root login on the\nterminal server.\n\n.TP\n\\fBMaxLoginRetry\\fR=\\fInumber\\fR\nThe number of login attempts that are allowed on terminal server. If set\nto \\fI0\\fR, unlimited attempts are allowed. If not specified, defaults to\n\\fI3\\fR.\n\n.TP\n\\fBXAuthorityInSystemDir\\fR=\\fI[no|yes]\\fR\nIf set to \\fBno\\fR (the default), \\fBXAUTHORITY\\fR will not be set for\nsessions, and the X11 authfile will be $HOME/.Xauthority.\n.br\nIf set to \\fByes\\fR, xrdp will point \\fBXAUTHORITY\\fR to a file\nin a system directory private to the logged-in user (currently\n@socketdir@/\\fI<uid>\\fR/Xauthority).\n.br\nYou may wish to use this if $HOME is NFS-mounted, or you are experiencing\nother applications overwriting the default file.\n\n.TP\n\\fBTerminalServerUsers\\fR=\\fIgroup\\fR\nOnly the users belonging to the specified group are allowed to login on\nterminal server. If unset or set to an invalid or non\\-existent group,\nlogin for all users is enabled.\n\n.TP\n\\fBTerminalServerAdmins\\fR=\\fIgroup\\fR\nMembers of this group can use the \\fBxrdp-sesadmin\\fR command to\nadminister sessions started by other users. The root user is always\nconsidered to be in this group.\n\n.TP\n\\fBRestrictOutboundClipboard\\fR=\\fI[all|none|text|file|image]\\fR\nIf set to \\fBall\\fR, will restrict the clipboard\noutbound from the server, to prevent data copied inside the xrdp session\nto be pasted in the client. Default value is \\fBnone\\fR.\nIn addition, you can control text/file/image transfer restrictions\nrespectively. It also accepts comma separated list such as text,file,image.\n.br\n\n.br\n\\fBnone\\fR - No restriction about copying inbound clipboard data.\n.br\n\\fBall\\fR - Restrict to copy inbound clipboard data.\n.br\n\\fBtext\\fR - Restrict to copy only inbound text clipboard data.\n.br\n\\fBfile\\fR - Restrict to copy only inbound file clipboard data.\n.br\n\\fBimage\\fR - Restrict to copy only inbound image clipboard data.\n.br\n\nTo keep compatibility, the following aliases are also available.\n.br\n\\fBtrue\\fR - an alias of \\fBall\\fR.\n.br\n\\fBfalse\\fR - an alias of \\fBnone\\fR.\n.br\n\\fByes\\fR - an alias of \\fBall\\fR.\n\n.TP\n\\fBRestrictInboundClipboard\\fR=\\fI[none|all|text|file|image]\\fR\nIf set to \\fBall\\fR, will restrict the clipboard\ninbound from the client, to prevent data copied inside the client\nto be pasted in the xrdp session. Default value is \\fBnone\\fR.\nIn addition, you can control text/file/image transfer restrictions\nrespectively. It also accepts comma separated list such as text,file,image.\n.br\n\n.br\n\\fBnone\\fR - No restriction about copying inbound clipboard data.\n.br\n\\fBall\\fR - Restrict to copy inbound clipboard data.\n.br\n\\fBtext\\fR - Restrict to copy only inbound text clipboard data.\n.br\n\\fBfile\\fR - Restrict to copy only inbound file clipboard data.\n.br\n\\fBimage\\fR - Restrict to copy only inbound image clipboard data.\n.br\n\nTo keep compatibility, the following aliases are also available.\n.br\n\\fBtrue\\fR - an alias of \\fBall\\fR.\n.br\n\\fBfalse\\fR - an alias of \\fBnone\\fR.\n.br\n\\fByes\\fR - an alias of \\fBall\\fR.\n\n.TP\n\\fBAlwaysGroupCheck\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR:-\n.RS\n.HP 3\n- For normal logins, require group membership even if the group specified\nin \\fBTerminalServerUsers\\fR doesn't exist.\n.HP 3\n- An error message may be generated when any user authenticates\nif the group specified in \\fBTerminalServerAdmins\\fR doesn't exist. This is\nbecause the system is unable to check whether the user is an administrator.\n.RE\n\n.TP\n\\fBAllowAlternateShell\\fR=\\fI[true|false]\\fR\nIf set to \\fB0\\fR, \\fBfalse\\fR or \\fBno\\fR, prevent usage of alternate shells by users.\n\n.TP\n\\fBPassShellAsEnv\\fR=\\fI<name-of-environment-variable>\\fR\nIf this is set, alternate shells are not actioned directly, but\npassed in to the default window manager in the specified environment\nvariable. This allows the system manager more control over exactly\nwhat alternate shells are permitted.\n\nThis will override any setting of the same environment variable\nin the \\fB[SessionVariables]\\fR section.\n\n.TP\n\\fBXorgNoNewPrivileges\\fR=\\fI[true|false]\\fR\nOnly applicable on Linux. If set to \\fB0\\fR, \\fBfalse\\fR or \\fBno\\fR, do\nnot use the kernel's \\fIno_new_privs\\fR restriction when invoking the Xorg\nX11 server. The use of \\fIno_new_privs\\fR is intended to prevent issues due\nto a setuid Xorg executable. However, if a kernel security module (such as\nAppArmor) is used to confine xrdp, \\fIno_new_privs\\fR may interfere with\ntransitions between confinement domains.\n\n.TP\n\\fBSessionSockdirGroup\\fR=\\fIgroup\\fR\nSets the group owner of the directories containing session sockets.\n\nFor normal operation with sesman, set this to 'root' for maximum security.\n\nIf you are using xrdp to connect to VNC sessions with X server\nsockets or chansrv sockets in the local sockets dir, set this to\nthe runtime_group in xrdp.ini. If you do not do this, xrdp will not\nbe able to connect to your sessions.\n\n.SH \"X11 SERVER\"\nFollowing parameters can be used in the \\fB[Xvnc]\\fR and\n\\fB[Xorg]\\fR sections.\n\n.TP\n\\fBparam\\fR=\\fIstring\\fR\nMultiple \\fIparam\\fR lines are supported. This first line specifies the\npath to the X11 server executable. Following lines specify command line\narguments passed to the X11 server.\n\n.SH \"CHANSRV\"\nFollowing parameters can be used in the \\fB[Chansrv]\\fR section.\n\n.TP\n\\fBFuseMountName\\fR=\\fIstring\\fR\nDirectory for drive redirection.\nCreated if it doesn't exist. If not specified, defaults to \\fIxrdp_client\\fR.\nIf first character is not a '/', this is relative to $HOME.\n.P\n.RS\nThe following substitutions are made in this string:-\n    %U - Username\n    %u - Numeric UID\n    %d - Display identifier (e.g. \"X11-10\" for X11, or \"wayland-1\" for Wayland)\n    %% - Percent character\n.HP 3\n1) The directory path permissions MUST be configured correctly by\nthe system administrator or the system itself - xrdp-chansrv will not\ndo this for you (although it will create the final directories owned by\nthe user).\n.HP 3\n2) The desktop may not automatically display a link for the redirected\ndrive. To fix this, consult the docs for your chosen desktop.\n.RE\n\n.TP\n\\fBFuseMountNameColonCharReplacement\\fR=\\fIstring\\fR\nCharacter to replace colon in redirected drive mount point names.\nIf not specified no colon will not be replaced.\nIf empty then colon will be replaced by null character.\nIf longer than one character, only first character used.\nOnly last colon replaced.\n.RE\n\n.TP\n\\fBFuseDirectIO\\fR=\\fI[false|true]\\fR\nDefaults to \\fIfalse\\fR. Set to \\fItrue\\fR to disable page caching in\nFUSE when opening files on a redirected drive. Direct I/O can impact\nthe performance of file operations.\n\n.TP\n\\fBFileUmask\\fR=\\fImode\\fR\nAdditional umask to apply to files in the \\fBFuseMountName\\fR directory.\nThe default value of 077 prevents other users on the system from reading\nfiles on your redirected drives. This may not be appropriate for all\nenvironments, and so you can change this value to allow other users to\naccess your remote files if required.\n\n.TP\n\\fBEnableFuseMount\\fR=\\fI[true|false]\\fR\nDefaults to \\fItrue\\fR.\nSet to \\fIfalse\\fR to disable xrdp-chansrv's use of the FUSE system\nfeature, even if it has been built with this feature enabled.\n.P\n.RS\nSetting this value to \\fIfalse\\fR will disable the following application\nfeatures:-\n.P\n-  drive redirection\n.P\n-  copying-and-pasting of files\n.RE\n.TP\n\\fBUseNautilus3FlistFormat\\fR=\\fI[false|true]\\fR\nDefaults to \\fIfalse\\fR.\nSet to \\fItrue\\fR to make file copy-paste compatible with Nautilus from\nGNOME 3 versions later than 3.29.92. Do not use this for any other reason.\n\nThis setting will be removed in a later version of xrdp, when GNOME 3 is\nno longer supported.\n\n.TP\n\\fBFuseRootReportMaxFree\\fR=\\fI[false|true]\\fR\nThe existing FUSE implementation reports free space on remote drives\nin a way which can confuse some file managers if they check for free\nspace at the FUSE mountpoint before copying files. KDE Dolphin is\naffected by this, and will report 'no space available' when trying to\ncopy to remote drives.\n\nSetting this option will cause the FUSE fileystem to report a\nvery large amount of free space for the root of the FUSE mountpoint.\nThis will allow Dolphin to copy files to remote drives, but introduces\na risk that the remote filesystem will run out of space during the copy.\n\nThis setting will be removed in a later version of xrdp, when remote drives\nreceive unique mountpoints.\n\n.TP\n\\fBSoundNumSilentFramesAAC\\fR=\\fInumber\\fR\nSets the \\fInumber\\fR of silent frames which are sent to client before close\nmessage is sent, when AAC is selected. If set to 0, no silent frame is sent.\nIf not specified, defaults to \\fI4\\fR.\n\n.TP\n\\fBSoundNumSilentFramesMP3\\fR=\\fInumber\\fR\nSets the \\fInumber\\fR of silent frames which are sent to client before close\nmessage is sent, when MP3 is selected. If set to 0, no silent frame is sent.\nIf not specified, defaults to \\fI2\\fR.\n\n.TP\n\\fBSoundMsecDoNotSend\\fR=\\fInumber\\fR\nSets the duration(msec). Sound data is not send to client during \\fInumber\\fR\nmillisecond(s) after close message is sent, when AAC/MP3 is selected.\nIf set to 0, all the data is sent. If not specified, defaults to \\fI1000\\fR.\n\n.SH \"SESSIONS VARIABLES\"\nAll entries in the \\fB[SessionVariables]\\fR section are set as\nenvironment variables in the user's session.\n\n.SH \"FILES\"\n@sysconfdir@/@sysconfsubdir@/sesman.ini\n\n.SH \"SEE ALSO\"\n.BR xrdp-sesman (8),\n.BR xrdp-sesrun (8),\n.BR xrdp (8),\n.BR xrdp.ini (5)\n\nFor more info on \\fBxrdp\\fR see\n.UR @xrdphomeurl@\n.UE\n"
  },
  {
    "path": "docs/man/xrdp-chansrv.8.in",
    "content": ".TH \"xrdp\\-chansrv\" \"8\" \"@PACKAGE_VERSION@\" \"xrdp team\" \"\"\n.SH \"NAME\"\n\\fBxrdp\\-chansrv\\fR \\- \\fBxrdp\\fR channel server\n\n.SH \"SYNTAX\"\n.B xrdp\\-chansrv\n\n.SH \"DESCRIPTION\"\n\\fBxrdp\\-chansrv\\fR is the \\fBxrdp\\fR(8) channel server, which manages the Remote Desktop Protocol (RDP) sub-channels.\n.PP\nThis program is only forked internally by \\fBxrdp\\-sesman\\fP(8).\n.PP\nCurrently \\fBxrdp\\-chansrv\\fP knows about the following channels:\n.RS 8\n.TP\n.B cliprdr\nClipboard Redirection\n.TP\n.B rdpsnd\nRemote Desktop Protocol Sound\n.TP\n.B rdpdr\nRemote Desktop Protocol Device Redirection\n.TP\n.B rail\nRemote Applications Integrated Locally\n.TP\n.B drdynvc\nDynamic Virtual Channel\n.RE\n\n.SH ENVIRONMENT\n.TP\n.I CHANSRV_LOG_PATH\nPath to the location where the log file is stored. If not specified,\n$\\fBXDG_DATA_HOME/xrdp\\fP or \\fB$HOME/.local/share/xrdp\\fP is used instead.\n.TP\n.I DISPLAY\nX11 display number. Must be specified.\n\n.SH FILES\n.TP\n.I @sysconfdir@/@sysconfsubdir@/sesman.ini\nContains some settings for this program.\n.TP\n.I @socketdir@/xrdp_chansrv_socket_*\nUNIX socket used by external programs to implement channels.\n.TP\n.I @socketdir@/xrdp_api_*\nUNIX socket used by \\fBxrdp\\-chansrv\\fP to communicate with \\fBxrdp\\-sesman\\fP.\n.TP\n.I xrdp-chansrv.%s.log\nLog file used by \\fBxrdp\\-chansrv\\fP(8). \\fB%s\\fP is display number. See the\ndescription of \\fBCHANSRV_LOG_PATH\\fP above for the file's location.\n\n.SH \"SEE ALSO\"\n.BR xrdp\\-sesman (8),\n.BR sesman.ini (5).\n\nFor more info on \\fBxrdp\\fR see\n.UR @xrdphomeurl@\n.UE\n"
  },
  {
    "path": "docs/man/xrdp-dis.1.in",
    "content": ".TH \"xrdp-dis\" \"1\" \"@PACKAGE_VERSION@\" \"xrdp team\"\n.SH NAME\nxrdp\\-dis \\- xrdp disconnect utility\n\n.SH SYNOPSIS\n.B xrdp\\-dis\n\n.SH DESCRIPTION\n.PP\n\\fBxrdp\\-dis\\fP is run with no parameters to disconnect your xrdp session.\n\n.SH ENVIRONMENT\n.TP\n.B DISPLAY\nto get the default host and display number.\n\n.SH FILES\n.TP\n.I @socketdir@/xrdp_disconnect_display_*\nUNIX socket used to communicate the disconnect request to xorgxrdp.\n\n.SH KNOWN ISSUES\n.TP\nThis utility doesn't support disconnecting Xvnc sessions so far.\n\n.SH SEE ALSO\n.BR xrdp (8).\n"
  },
  {
    "path": "docs/man/xrdp-dumpfv1.8.in",
    "content": ".TH \"xrdp-dumpfv1\" \"8\" \"@PACKAGE_VERSION@\" \"xrdp team\"\n.SH NAME\nxrdp\\-dumpfv1 \\- Display content of .fv1 font files\n\n.SH SYNOPSIS\n\\fBxrdp-dumpfv1\\fR [ options ] fv1_file\n\n.SH DESCRIPTION\n\\fBxrdp\\-dumpfv1\\fP can be used to display the contents of an fv1 file.\n\n.SH OPTIONS\nA summary of options is included below.\n\nOne of \\fB\\-i\\fR, \\fB\\-t\\fR, or \\fB\\-c\\fR must be specified.\n.TP\n\\fB\\-i\\fR\nDisplays general information about the fv1 file.\n\n.TP\n\\fB\\-t\\fR\nDisplays a CSV table of all the glyphs in the font. This table can be\nimported into a spreadsheet program for further manipulation.\n\n.TP\n\\fB\\-c\\fR <character>\nDisplays detailed information about a particular glyph in the font,\nincluding a representation of the bitmap for the glyph.\n\nSpecify the character using one of the following strings:\n\n\\fBU+<hex>\\fR - Unicode character, e.g. \\fBU+25\\fR for a percentage symbol (%).\n\n\\fB@<char>\\fR - Unicode character, e.g. \\fB@%\\fR for a percentage symbol.\n\n\\fBnumber\\fR - Unicode value as an integer, e.g. \\fB37\\fR for a\npercentage symbol\n\nNote that the row numbers shown in the font data are relative to the\nnatural font baseline. If comparing two fonts, be aware that when the\nglyph is drawn, the row number may be affected by the global descender\nvalue for the font (displayed with \\fB\\-i\\fR).\n\n.SH \"EXAMPLES\"\n.TP\n\\fBxrdp\\-dumpfv1 -i @xrdpdatadir@/sans-10.fv1\\fR\nDisplays global information about the sans 10 font file distributed with xrdp.\n\n.TP\n\\fBxrdp\\-dumpfv1 -c @'*' @xrdpdatadir@/sans-10.fv1\\fR\nDisplays information about the asterisk symbol in the sans 10 font file distributed with xrdp.\n\n.SH SEE ALSO\n.BR xrdp\\-mkfv1(8).\n\nMore info on \\fBxrdp\\fR can be found on the\n.UR @xrdphomeurl@\nxrdp homepage\n.UE\n"
  },
  {
    "path": "docs/man/xrdp-genkeymap.8.in",
    "content": ".TH \"xrdp\\-genkeymap\" \"8\" \"@PACKAGE_VERSION@\" \"xrdp team\" \"\"\n.de URL\n. \\\\$2 \\(laURL: \\\\$1 \\(ra\\\\$3\n..\n.if \\n[.g] .mso www.tmac\n\n.SH \"NAME\"\n\\fBxrdp\\-genkeymap\\fR \\- key map generator for XRDP\n\n.SH \"SYNTAX\"\n.B xrdp\\-genkeymap\n.I [ options ] file\n\n.SH \"DESCRIPTION\"\n\\fBxrdp\\-genkeymap\\fR extracts the current key map from the X server\nX session to generate a mapping from Remote Desktop Protocol (RDP)\nscan codes to X keysyms and Unicode code points.\n\nBefore running this utility, make sure the keymap is correct, by issuing\nthe correct \\fIsetxkbmap\\fP command(s).\n\n.SH OPTIONS\n.TP\n.B -k 'keycode_set'\nInform \\fBxrdp\\-genkeymap\\fR of the keycode set in operation (evdev or\nbase), so that the correct scan code to keycode mapping table is selected\nto generate the keymap.\n\nIf you omit this option, the XKB extension is asked to provide the\nname of the keycode set.\n\n.TP\n.B -c 'comment'\nAdds a comment to the top of the generated file.\n\nThis option may be repeated more than once to add multiple comments to\nthe top of the file.\n.TP\n.B outfile\nThe key map information is stored in the file named \\fIoutfile\\fP.\n\n.SH \"FILES\"\n.TP\n.I @sysconfdir@/@sysconfsubdir@/km-XXXXXXXX.toml\nFiles containing the keyboard mapping for country and language \\fIXXXXXXXX\\fP.\n\\fIXXXXXXXX\\fP is a 8 digit hexadecimal number, representing the \\fIinput\nlocale identifier\\fP.\n\nThe input locale identifier is passed from the RDP client when it connects.\n.RE\n\n.SH \"AUTHORS\"\nJay Sorg <jsorg71@users.sourceforge.net>\n.br\nSimone Fedele <ilsimo@users.sourceforge.net>\n\n.SH \"SEE ALSO\"\n.BR xrdp (8),\n.BR xrdp-km.toml (5),\n.BR setxkbmap (1),\n.BR unicode (7)\n\n.PP\nInput locale identifiers on the\n.UR https://go.microsoft.com/fwlink/?LinkId=202824\nMicrosoft website\n.UE\n.PP\nDescription of Keyboard Input mapping on the\n.UR https://github.com/FreeRDP/FreeRDP/wiki/Keyboard\nFreeRDP wiki\n.UE\n.PP\nFor more info on \\fBxrdp\\fR see\n.UR @xrdphomeurl@\n.UE\n"
  },
  {
    "path": "docs/man/xrdp-keygen.8.in",
    "content": ".\\\"                                      Hey, EMACS: -*- nroff -*-\n.\\\"-\n.\\\" Copyright © 2007, 2008 Vincent Bernat <bernat@debian.org>\n.\\\" License: GPL-2+\n.\\\"-\n.TH xrdp\\-keygen 8 \"@PACKAGE_VERSION@\" \"xrdp team\"\n.SH NAME\nxrdp\\-keygen \\- xrdp RSA key generation utility\n\n.SH SYNOPSIS\n.B xrdp\\-keygen xrdp\n< \\fIoutfile\\fP | \\fBauto\\fP >\n.br\n.B xrdp\\-keygen test\n\n.SH DESCRIPTION\n\\fBxrdp\\-keygen\\fP generates the file\n.I @sysconfdir@/@sysconfsubdir@/rsakeys.ini\nwhich contains the RSA key pair used to perform authentication to\nremote clients. The public key is self-signed.\n\n.SH OPTIONS\nThis program takes one of the following options:\n.TP\n\\fBxrdp\\fP \\fIoutfile\\fP\nGenerate a new key pair.\nThe key data is stored in the file named \\fIoutfile\\fP.\n.br\nIf \\fBauto\\fP is used as \\fIoutfile\\fP, the default file \\fI@sysconfdir@/@sysconfsubdir@/rsakeys.ini\\fP gets created if it does not yet exists.\n.TP\n.B test\nGenerate a test key pair and print information to standard output.\n\n.SH NOTES\nOn machines with FIPS enabled, this program will generate an empty file,\nand a warning. On these machines, xrdp cannot use Classic RDP encryption.\n\n.SH FILES\n.TP\n.I @sysconfdir@/@sysconfsubdir@/rsakeys.ini\nRSA public and private key pair used to identify this XRDP server.\n\n.SH SEE ALSO\n.BR xrdp (8),\n.BR xrdp\\-sesman (8).\n\n.SH AUTHOR\nThis manual page was originally written by Vincent Bernat <bernat@luffy.cx>.\n"
  },
  {
    "path": "docs/man/xrdp-km.toml.5.in",
    "content": ".\\\"\n.TH \"xrdp-km.toml\" \"5\" \"@PACKAGE_VERSION@\" \"xrdp team\" \"\"\n.SH \"NAME\"\n\\fBxrdp-km.toml\\fR \\- \\fBxrdp\\fP key mapping file\n\n.SH \"DESCRIPTION\"\nKey mapping files are located at \\fB@sysconfdir@/@sysconfsubdir@/km-XXXXXXXX.toml\\fP\nwhere \\fBXXXXXXXX\\fP is the input locale identifier sent by the RDP client.\n\nThe key mapping files are used to translate RDP scan codes into one of\nthe following forms:-\n.TP\n.B X11 KeySyms\nThese are used when \\fBxrdp\\fP connects to a VNC server.\n.TP\n.B Unicode characters\nThese are used on the \\fBxrdp\\fP login screen.\n.RE\n.PP\nEach keymap file consists of several sections. Each section starts with\nthe section name in square brackets, followed by a list of\n\\fIparameter\\fR=\\fIvalue\\fR lines.\n\n.SH \"SECTIONS\"\nThe following sections are recognized:\n.TP\n\\fB[Globals]\\fR\nGlobal configuration\n\n.TP\n\\fB[noshift]\\fR\nKey mappings if no modifier keys (i.e. shift, alt gr, caps lock) are down.\n.TP\n\\fB[shift]\\fR\nKey mappings if the shift key is down.\n.TP\n\\fB[altgr]\\fR\nKey mappings if the alt gr key is down.\n.TP\n\\fB[shiftaltgr]\\fR\nKey mappings if the shift and alt gr keys are down.\n.TP\n\\fB[capslock]\\fR\nKey mappings if the caps lock key is down.\n.TP\n\\fB[shiftcapslock]\\fR\nKey mappings if the caps lock and shift keys are down.\n.TP\n\\fB[shiftcapslockaltgr]\\fR\nKey mappings if the shift, caps lock and alt gr keys are down.\n.TP\n\\fB[numlock]\\fR\nKey mappings if the numlock key is down.\n\n.LP\nAll parameters and values are case\ninsensitive, and are described in detail below. If any parameter is\nspecified more than once, the last entry will be used. Options specified\noutside their proper section will be \\fIignored\\fR.\n\n.SH \"GLOBALS Section\"\nFollowing parameters can be used in the \\fB[Globals]\\fR section.\n\n.TP\n\\fBVersion\\fR=\\fInumber\\fR\nVersion of the file format in use.\nCan be used to check for file format mis-matches when a file is loaded.\n.RE\n\n.SH \"Keymap Sections\"\nAll other sections contain lines formatted in one of the following\nways:-\n\n.TP\n<scancode>=<KeySym>\n.TP\n<scancode>=<KeySymNum>:<unicode-char>\n.RE\n\nEach line may also be followed by a comment (preceded by '#') which\ncontains more information about the key, for example a KeySym string.\n\n.TP\n.B scancode\nA \\fBscancode\\fP is an RDP scancode received from the client. These\ncorrespond to Windows \"Scan Code Set 1\" scan codes, and can be displayed\nin Windows by using an appropriate utility.\n\nThe \\fBscancode\\fP is in one of these two forms:-\n\n.RS 8\n.TP\n.B <hex-digit><hex-digit>\nStandard scancodes. For example, '1C' refers to the enter key.\nThese are 'key down' scancodes, and so are always between 00 and 7F.\n.TP\n.B E0_<hex-digit><hex-digit>\nExtended scancodes. For example, 'E0_1C' refers to the enter key on the numeric keypad.\n.RE\n\n.TP\n.B KeySymNum\nA decimal number representing an X11 KeySym\n\n.TP\n.B unicode-char\nA string of the format \\fBU+XXXX\\fP \\fBU+XXXXX\\fP,, \\fBU+XXXXX\\fP,\nwhere \\fBX\\fP is a hexadecimal digit.\n.RE\n\n.SH \"Limitations\"\nThis file format has the following limitations.\n.IP \\(bu\nNot all combinations of shift keys are stored in the file. For example,\nat present there is no section for shift and numlock combined.\n.IP \\(bu\nModifier keys, other than the ones supported above, are not supported.\n\n.SH \"SEE ALSO\"\n.BR xrdp-genkeymap (8)\n\n.PP\nScancode mappings for most keyboards at\n.UR https://kbdlayout.info\n.UE\n\nFor more info on \\fBxrdp\\fR see\n.UR @xrdphomeurl@\n.UE\n"
  },
  {
    "path": "docs/man/xrdp-mkfv1.8.in",
    "content": ".TH \"xrdp-mkfv1\" \"8\" \"@PACKAGE_VERSION@\" \"xrdp team\"\n.SH NAME\nxrdp\\-mkfv1 \\- Create .fv1 font files from other font files\n\n.SH SYNOPSIS\n\\fBxrdp-mkfv1\\fR [ options ] font_file fv1_file\n\n.SH DESCRIPTION\n\\fBxrdp\\-mkfv1\\fP can be used to convert a font file such as a TrueType\nfont to a fv1 file.\n\n.SH OPTIONS\nA summary of options is included below.\n\n.TP\n\\fB\\-n\\fR <font_name>\nGive the font a name, which is stored in the font header.\n\nThe default is to use the font family name from the source font.\n\n.TP\n\\fB\\-p\\fR <number>\nSet the point size of the font. A fixed DPI value of 96 is used for\nconverting this value into a pixel size.\n\nThe default value for this option is '10'.\n\n.TP\n\\fB\\-m\\fR <glyph>\nSet the limit on the glyphs stored in the font file. The argument is the last\nglyph stored in the font file.\n\nSpecify the glyph using one of the following strings:\n\n\\fBU+<hex>\\fR - Unicode character, e.g. \\fBU+25\\fR for a percentage symbol (%).\n\n\\fB@<char>\\fR - Unicode character, e.g. \\fB@%\\fR for a percentage symbol.\n\n\\fBnumber\\fR - Unicode value as an integer, e.g. \\fB37\\fR for a\npercentage symbol\n\nThe default value for this option is 'U+4DFF'.\n\n.TP\n\\fB\\-C\\fR\nWhen used with the \"DejaVu Sans\" font at a point-size of 10, a small\nnumber of glyphs are assigned a different x-offset than they have\nwhen the original Windows font generation program is used.\n\nThis switch can be used to preserve the original x-offsets for glyphs in\nthe range U+0020 - U+00FF when a 10 point DajaVu Sans font is generated.\n\nUse one of the following arguments to this option:-\n\n\\fBauto\\fR - Automatic mode. Offsets are preserved if a \"DajaVu Sans\" 10-point font is converted.\n\n\\fBon / true / yes\\fR - Preserve offsets if automatic font detection does not work.\n\n\\fBoff / false / no\\fR - Do not tamper with the offsets generated by the program.\n\nThe default value of this switch is \\fRauto\\fR.\n\nTo see the effects of this switch, set the \\fBMKFV1_LOG_LEVEL\\fR environment\nvariable to \\fBinfo\\fR before running the program.\n\n.SH \"EXAMPLES\"\n.TP\n\\fBxrdp-mkfv1 -p18 /path/to/DejaVuSans.ttf ./sans-18.fv1\\fR\nGenerate an 18-point Deja Sans font.\n\n.TP\n\\fBxrdp-mkfv1 -C off -p10 /path/to/DejaVuSans.ttf ./sans-10.fv1\\fR\nGenerate a 10-point DajaVu Sans font using natural offsets.\n\n.SH SEE ALSO\n.BR xrdp\\-dumpfv1(8).\n\nMore info on \\fBxrdp\\fR can be found on the\n.UR @xrdphomeurl@\nxrdp homepage\n.UE\n"
  },
  {
    "path": "docs/man/xrdp-sesadmin.8.in",
    "content": ".TH \"xrdp-sesadmin\" \"8\" \"@PACKAGE_VERSION@\" \"xrdp team\"\n.SH NAME\nxrdp\\-sesadmin \\- console XRDP sessions administration tool\n\n.SH SYNOPSIS\n.B xrdp\\-sesadmin\n.RI [ options ]\n.BI -c= command\n\n.SH DESCRIPTION\nThis manual page documents briefly the\n.B xrdp\\-sesadmin\ncommand.\n.PP\n\\fBxrdp\\-sesadmin\\fP is a console program to administer running XRDP sessions.\n\n.SH OPTIONS\nA summary of options is included below.\n.TP\n.BI \\-u= username\nRetained for compatibility, but ignored.\n\n.TP\n.BI \\-p= password\nRetained for compatibility, but ignored.\n\n.TP\n.BI \\-i= port\nThe sesman \\fIUNIX domain socket\\fP to connect to.\nDefaults to \\fBsesman.socket\\fP.\nIf no path is specified for the socket, a default of @socketdir@ is used.\n\n.TP\n.BI \\-c= command\nSpecifies the \\fIcommand\\fP to execute on the server.\nValid commands are:\n.RS 4\n.TP\n.B list\nList active sessions for the current user.  Members of the\n\\fBTerminalServerAdmins\\fR group can view active sessions for all users.\n.TP\n.BI kill: sid\nKills the session specified the given \\fIsession id\\fP.\n(not yet implemented).\n.RE\n\n.SH FILES\nxrdp\\-sesadmin.log\n\n.SH SEE ALSO\n.BR xrdp (8).\n\nMore info on \\fBxrdp\\fR can be found on the\n.UR @xrdphomeurl@\nxrdp homepage\n.UE\n"
  },
  {
    "path": "docs/man/xrdp-sesman.8.in",
    "content": ".TH \"xrdp\\-sesman\" \"8\" \"@PACKAGE_VERSION@\" \"xrdp team\" \"\"\n.SH \"NAME\"\nxrdp\\-sesman \\- \\fBxrdp\\fR(8) session manager\n\n.SH \"SYNTAX\"\n.B xrdp\\-sesman\n\\-\\-kill\n.br\n.B xrdp\\-sesman\n\\-\\-reload\n.br\n.B xrdp\\-sesman\n\\-\\-help\n.br\n.B xrdp\\-sesman\n\\-\\-version\n.br\n.B xrdp\\-sesman\n[\\-\\-nodaemon] [\\-\\-dump\\-config] [\\-\\-config /path/to/sesman.ini]\n\n.SH \"DESCRIPTION\"\n\\fBxrdp\\-sesman\\fR is \\fBxrdp\\fR(8) session manager.\n.br\nIt manages user sessions by authenticating the user and starting the appropriate Xserver.\n\n.SH \"OPTIONS\"\n.TP\n\\fB\\-k\\fR, \\fB\\-\\-kill\\fR\nKills running \\fBxrdp\\-sesman\\fR daemon.\n.TP\n\\fB\\-r\\fR, \\fB\\-\\-reload\\fR\nReloads running \\fBxrdp\\-sesman\\fR daemon.\n.TP\n\\fB\\-h\\fR, \\fB\\-\\-help\\fR\nOutput help information and exit.\n.TP\n\\fB\\-v\\fR, \\fB\\-\\-version\\fR\nOutput version information and exit.\n.TP\n\\fB\\-n\\fR, \\fB\\-\\-nodaemon\\fR\nStarts \\fBxrdp\\-sesman\\fR in foreground instead of starting it as a daemon.\n.TP\n\\fB\\-\\-dump\\-config\\fR\nPrint the configuration on stdout before starting the daemon.\nThe default is not to do this.\n.TP\n\\fB\\-c\\fR, \\fB\\-\\-config\\fR\nSpecify a path to a different \\fIsesman.ini\\fR file. This option is intended\nto be used primarily for testing or for unusual configurations.\n.P\n.RS\nIf you use this option, be aware that you will have to have a\n\\fB@sysconfdir@/@sysconfsubdir@/sesman.ini\\fR in place too, as a few elements of\nthe system (notably \\fBxrdp(8)\\fR and \\fBxrdp\\-chansrv(8)\\fR) will want\nto read it.\n.RE\n.SH \"SIGNALS\"\n.TP\n\\fBSIGHUP\\fR\nCauses \\fBxrdp\\-sesman\\fR to reload its configuration. Needed if you're\nnot running \\fBxrdp\\-sesman\\fR as a daemon.\n.SH \"FILES\"\n@sbindir@/xrdp\\-sesman\n.br\n@bindir@/xrdp\\-sesrun\n.br\n@sysconfdir@/sysconfsubdir@/sesman.ini\n.br\n@localstatedir@/log/xrdp\\-sesman.log\n.br\n@localstatedir@/run/xrdp\\-sesman.pid\n.br\n@socketdir@/sesman.socket\n\n.SH \"AUTHORS\"\nJay Sorg <jsorg71@users.sourceforge.net>\n.br\nSimone Fedele <ilsimo@users.sourceforge.net>\n\n.SH \"SEE ALSO\"\n.BR sesman.ini (5),\n.BR xrdp\\-sesrun (8),\n.BR xrdp (8),\n.BR xrdp.ini (5)\n\nfor more info on \\fBxrdp\\fR see\n.UR @xrdphomeurl@\n.UE\n"
  },
  {
    "path": "docs/man/xrdp-sesrun.8.in",
    "content": ".TH \"xrdp\\-sesrun\" \"8\" \"@PACKAGE_VERSION@\" \"xrdp team\" \"\"\n.SH \"NAME\"\n\\fBxrdp\\-sesrun\\fR \\- \\fBxrdp\\-sesman\\fR(8) session launcher\n\n.SH \"SYNTAX\"\n.B xrdp\\-sesrun\n.I --help\n.br\n\n.B xrdp\\-sesrun\n.I [ options ] [ username ]\n\n.SH \"DESCRIPTION\"\n\\fBxrdp\\-sesrun\\fR starts a session using \\fBxrdp\\-sesman\\fR(8).\n.br\nThis is a tool useful for testing. It simply behaves like xrdp when some\nuser logs in a new session and authenticates, thus starting a new session.\n\nDefault values for the options are set at compile-time. Run the utility with\nthe '--help' option to see what the defaults are for your installation.\n\nIf no username is used, the current username is used, and no password\nneeds to be provided. In this instance, it is important that any necessary\nauthentication tokens for a GUI session (e.g. a Kerberos ticket) have\nalready been acquired.\n\nIf a username is provided, a password must also be provided. In this instance\nthe utility prompts for a password if neither \\fB-p\\fR or \\fB-F\\fR is used.\n\n.SH \"OPTIONS\"\n.TP\n.B -g <width>x<height>\nSet session geometry.\n.br\nNote that most configurations will resize the session on connection, so this\noption may not do what you expect.\n.TP\n.B -b <bits-per-pixel>\nSet session bits-per-pixel (colour depth). Some session types (i.e. Xorg)\nwill ignore this setting.\n.TP\n.B -t <session-type>\nSession type - one of Xorg or Xvnc. Alternatively, for testing\nonly, use the numeric session code.\n.TP\n.B -D <directory>\nDirectory to run the new session in. Defaults to $HOME for the specified user.\n.TP\n.B -S <shell>\nSpecify an alternate shell to run, instead of the default window manager.\n.TP\n.B -p <password>\nPassword for user. USE FOR TESTING ONLY - the password will be visible\nin the output of the \\fBps\\fR command.\n.TP\n.B -F <file-descriptor>\nSpecify a file descriptor (normally 0) to read the password in from. This\nis a secure way to pass the password in to the utility.\n.TP\n.B -c <sesman-ini>\nSpecify a different sesman.ini file. This file is used to find out how to\nconnect to \\fBxrdp\\-sesman\\fR.\n\n.SH \"ENVIRONMENT\"\n.TP\n.I SESRUN_LOG_LEVEL\nOverride the default logging level. One of \"error\", \"warn\", \"info\",\n\"debug\", \"trace\" or a number 1-5.\n\n.SH \"EXAMPLES\"\n.TP\n.B\nxrdp-sesrun\nCreate a default session for the current user.\n.TP\n.B\nxrdp-sesrun -F 0 user1 <passwd.txt\nCreate a default session for user \\fBuser1\\fR with a password from\na file\n.TP\n.B\nxrdp-sesrun -t Xvnc -S /usr/bin/xterm user1\nCreate an extremely minimal Xvnc session for user \\fBuser1\\fR. This\ncould be useful for debugging why the standard session is not starting\nproperly. Note you would need to install the \\fBxterm\\fR utility\nfirst. The \\fBgnome\\-terminal\\fR utility probably won't work here.\n\n.SH \"FILES\"\n@sbindir@/xrdp\\-sesman\n.br\n@bindir@/xrdp\\-sesrun\n.br\n@sysconfdir@/@sysconfsubdir@/sesman.ini\n\n.SH \"AUTHORS\"\nJay Sorg <jsorg71@users.sourceforge.net>\n.br\nSimone Fedele <ilsimo@users.sourceforge.net>\n\n.SH \"SEE ALSO\"\n.BR xrdp\\-sesman (8),\n.BR sesman.ini (5),\n.BR xrdp (8),\n.BR xrdp.ini (5)\n\nFor more info on \\fBxrdp\\fR see\n.UR @xrdphomeurl@\n.UE\n"
  },
  {
    "path": "docs/man/xrdp.8.in",
    "content": ".TH \"xrdp\" \"8\" \"@PACKAGE_VERSION@\" \"xrdp team\" \"\"\n.SH \"NAME\"\n\\fBxrdp\\fR \\- a Remote Desktop Protocol (RDP) server\n\n.SH \"SYNTAX\"\n.B xrdp\n\\-\\-kill\n.br\n.B xrdp\n\\-\\-help\n.br\n.B xrdp\n\\-\\-version\n.br\n.B xrdp\n[\\-\\-nodaemon] [\\-\\-port port] [\\-\\-fork] [\\-\\-dump\\-config] [\\-\\-config /path/to/xrdp.ini]\n\n.SH \"DESCRIPTION\"\n\\fBxrdp\\fR is a Remote Desktop Protocol (RDP) Server.\n.br\nUnlike Windows NT/2000/2003 server, \\fBxrdp\\fR will not display a Windows desktop but an X window desktop to the user.\n\nIt can also be used as a VNC\\->RDP bridge.\n\n.SH \"OPTIONS\"\n.TP\n\\fB\\-k\\fR, \\fB\\-\\-kill\\fR\nKill running \\fBxrdp\\fR daemon.\n.TP\n\\fB\\-h\\fR, \\fB\\-\\-help\\fR\nOutput help information and exit.\n.TP\n\\fB\\-v\\fR, \\fB\\-\\-version\\fR\nOutput version information and exit.\n.TP\n\\fB\\-n\\fR, \\fB\\-\\-nodaemon\\fR\nStart \\fBxrdp\\fR in foreground instead of starting it as a daemon.\n.TP\n\\fB\\-p\\fR, \\fB\\-\\-port\\fR\nSpecify TCP port to listen to. This overrides \\fIport\\fR setting in\n\\fIxrdp.ini\\fR file.\n.TP\n\\fB\\-f\\fR, \\fB\\-\\-fork\\fR\nFork a new process on a new connection. If not enabled, use a new thread\nfor every connection. This overrides \\fIfork\\fR setting in\n\\fIxrdp.ini\\fR file.\n.TP\n\\fB\\-\\-dump\\-config\\fR\nPrint the configuration on stdout before starting the daemon.\nThe default is not to do this.\n.TP\n\\fB\\-c\\fR, \\fB\\-\\-config\\fR\nSpecify a path to a different \\fIxrdp.ini\\fR file. This option is intended\nto be used primarily for testing or for unusual configurations.\n\n\n.SH \"FILES\"\n@sbindir@/xrdp\n.br\n@sysconfdir@/@sysconfsubdir@/xrdp.ini\n.br\n@localstatedir@/log/xrdp.log\n.br\n@localstatedir@/run/xrdp.pid\n\n.SH \"AUTHORS\"\nJay Sorg <jsorg71@users.sourceforge.net>\n.br\nSimone Fedele <ilsimo@users.sourceforge.net>\n\n.SH \"SEE ALSO\"\n.BR xrdp.ini (5),\n.BR xrdp\\-sesman (8),\n.BR sesman.ini (5),\n.BR xrdp\\-sesrun (8)\n\nfor more info on \\fBxrdp\\fR see\n.UR @xrdphomeurl@\n.UE\n"
  },
  {
    "path": "docs/man/xrdp.ini.5.in",
    "content": ".TH \"xrdp.ini\" \"5\" \"@PACKAGE_VERSION@\" \"xrdp team\" \"\"\n.SH \"NAME\"\n\\fBxrdp.ini\\fR \\- Configuration file for \\fBxrdp\\fR(8)\n\n.SH \"DESCRIPTION\"\nThis is the man page for \\fBxrdp.ini\\fR, \\fBxrdp\\fR(8) configuration file.\nIt is composed by a number of sections, each one composed by a section name, enclosed by square brackets, followed by a list of \\fI<parameter>\\fR=\\fI<value>\\fR lines.\n\n\\fBxrdp.ini\\fR supports the following sections:\n\n.TP\n\\fB[Globals]\\fP \\- sets some global configuration settings for \\fBxrdp\\fR(8).\n\n.TP\n\\fB[Logging]\\fP \\- logging subsystem parameters\n\n.TP\n\\fB[Channels]\\fP \\- channel subsystem parameters\n\n.LP\nAll options and values (except for file names and paths) are case insensitive, and are described in detail below.\n\n.SH \"GLOBALS\"\nThe options to be specified in the \\fB[Globals]\\fR section are the following:\n\n.TP\n\\fBport\\fR=\\fIport_specification [ port_specification ... ]\\fR\nSpecify the port(s) that xrdp should listen on. More instructions and\nexamples can be found within xrdp.ini itself.\n\n.TP\n\\fBinstance_name\\fR=\\fI<arbitrary-string>\\fR\nSpecify an arbitrary name for the xrdp instance that can be used to\nidentify sessions that this xrdp instance started, or which were\nspun up with the same name using \\fBxrdp-sesrun\\fR. When using the\n\\fBN\\fR policy in \\fBsesman.ini\\fR these sessions are kept distinct\nand can be reconnected to by connecting to the respective \\fBxrdp\\fR\ninstance.\n\n.TP\n\\fBvmconnect\\fR=\\fI[true|false]\\fR\n(Hyper-V VMs only). Enables a wider support of security protocols when a\nvirtual machine running xrdp is hosted on Hyper-V, and the user connects\nto it via the vmms service on TCP port 2179. In this configuration,\nRDP security is handled by the vmms service, and security features which\nare not yet added to xrdp itself can be supported.\n\nThis parameter is required in environments which do not support 'classic'\nRDP encryption.\n\nThe parameter is ignored for connections which are not made to the\nvirtual machine over the vsock transport.\n\n.TP\n\\fBautorun\\fP=\\fIsession_name\\fP\nSection name for automatic login. If set and the client supplies valid\nusername and password, the user will be logged in automatically using the\nconnection specified by \\fIsession_name\\fP.\n\nIf \\fIsession_name\\fP is empty, the \\fBLOGIN DOMAIN\\fR from the client\nwith be used to select the section. If no domain name is supplied, the\nfirst suitable section will be used for automatic login.\n\n.TP\n\\fBbitmap_cache\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR this option enables bitmap caching in \\fBxrdp\\fR(8).\n\n.TP\n\\fBbitmap_compression\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR this option enables bitmap compression in \\fBxrdp\\fR(8).\n\n.TP\n\\fBbulk_compression\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR this option enables compression of bulk data in \\fBxrdp\\fR(8).\n\n.TP\n\\fBcertificate\\fP=\\fI/path/to/certificate\\fP\n.TP\n\\fBkey_file\\fP=\\fI/path/to/private_key\\fP\nSet location of TLS certificate and private key. They must be written in PEM format.\nIf not specified, defaults to \\fB@sysconfdir@/@sysconfsubdir@/cert.pem\\fP, \\fB@sysconfdir@/@sysconfsubdir@/key.pem\\fP.\n\nThis parameter is effective only if \\fBsecurity_layer\\fP is set to \\fBtls\\fP or \\fBnegotiate\\fP.\n\n.TP\n\\fBtls_pms_log_file\\fR=\\fI<path-to-log-file>\\fR\nLogs TLS pre-master secrets to the specified file. This allows packet capture\ntools (e.g. Wireshark) to decrypt captured PDUs.\n\nThe file must be writeable by xrdp and readable by the packet capture tool.\nA good way to achive this is to create a temporary directory with\npermissions 2750 owned by the user running xrdp, and in the group used by\nthe packet sniffer.\n\nSETTING THIS OPTION IS A SECURITY RISK. ONLY SET THIS OPTION FOR DEBUGGING\nCOMMUNICATIONS BETWEEN XRDP AND A CLIENT.\n\n.TP\n\\fBchannel_code\\fP=\\fI[true|false]\\fP\nIf set to \\fB0\\fR, \\fBfalse\\fR or \\fBno\\fR this option disables all channels \\fBxrdp\\fR(8).\nSee section \\fBCHANNELS\\fP below for more fine grained options.\n\n.TP\n\\fBcrypt_level\\fP=\\fI[low|medium|high|fips]\\fP\n.\\\" <http://blogs.msdn.com/b/openspecification/archive/2011/12/08/encryption-negotiation-in-rdp-connection.aspx>\nRegulate encryption level of Classic RDP Security.\nThis parameter is effective only if \\fBsecurity_layer\\fP is set to \\fBrdp\\fP or \\fBnegotiate\\fP.\n\nEncryption in Classic RDP Security is controlled by two settings: \\fIEncryption Level\\fP\nand \\fIEncryption Method\\fP.  The only supported \\fIEncryption Method\\fP are \\fB40BIT_ENCRYPTION\\fP\nand \\fB128BIT_ENCRYPTION\\fP. \\fB56BIT_ENCRYPTION\\fP is not supported.\nThis option controls the \\fIEncryption Level\\fP:\n.RS 8\n.TP\n.B low\nAll data sent from the client to the server is protected by encryption based on\nthe maximum key strength supported by the client.\n.I This is the only level that the traffic sent by the server to client is not encrypted.\n.TP\n.B medium\nAll data sent between the client and the server is protected by encryption based on\nthe maximum key strength supported by the client (client compatible).\n.TP\n.B high\nAll data sent between the client and the server is protected by encryption based on\nthe server's maximum key strength (sever compatible).\n.TP\n.B fips\nAll data sent between the client and server is protected using Federal Information\nProcessing Standard 140-1 validated encryption methods. Note that FIPS 140-1 is\nno longer considered secure.\n.I This level is required for Windows clients (mstsc.exe) if the client's group policy\n.I enforces FIPS-compliance mode.\n.RE\n\n.TP\n\\fBfork\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR for each incoming connection \\fBxrdp\\fR(8) forks a sub-process instead of using threads.\n\n.TP\n\\fBhidelogwindow\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fP, \\fBtrue\\fP or \\fByes\\fP, \\fBxrdp\\fP will not show a window for log messages.\nIf not specified, defaults to \\fBfalse\\fP.\n\n.TP\n\\fBmax_bpp\\fP=\\fI[8|15|16|24|32]\\fP\nLimit the color depth by specifying the maximum number of bits per pixel.\nIf not specified or set to \\fB0\\fP, unlimited.\n\n.TP\n\\fBpamerrortxt\\fP=\\fIerror_text\\fP\nSpecify additional text displayed to user if authentication fails. The maximum length is \\fB256\\fP.\n\nThe use of 'pam' in the name of this option is historic\n\n.TP\n\\fBport\\fP=\\fIport\\fP\nSpecify TCP port and interface to listen on for incoming connections.\nSpecifying only the port means that xrdp will listen on all interfaces.\nThe default port for RDP is \\fB3389\\fP.\nMultiple address:port instances must be separated by spaces or commas. Check the .ini file for examples.\nSpecifying interfaces requires said interfaces to be UP before xrdp starts.\n\n.TP\n\\fBruntime_user\\fP=\\fIusername\\fP\n.TP\n\\fBruntime_group\\fP=\\fIgroupname\\fP\nUser name and group to run the xrdp daemon under.\n\nAfter xrdp starts, it sets its UID and GID to values derived from these\nsettings, so that it's running without system privilege.\n\nThe \\fBruntime_group\\fP MUST be set to the same value as\n\\fBSessionSockdirGroup\\fP in \\fBsesman.ini\\fP if you want to run sessions.\n\nA suitable user and group can be added with a command like this (Linux):-\n\nuseradd xrdp -d / -c 'xrdp daemon' -s /usr/sbin/nologin\n\nIn order to establish secure connections, the xrdp daemon needs permission\nto access sensitive cryptographic files. After changing either or both\nof these values, check that xrdp has access to required files by running\nthis script:-\n\n@xrdpdatadir@/xrdp-chkpriv\n\n.TP\n\\fBenable_token_login\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fP, \\fBtrue\\fP or \\fByes\\fP, \\fBxrdp\\fP will scan the user name provided by the\nclient for the ASCII field separator character (0x1F). It will then copy over what is after the\nseparator as the password supplied by the user and treats it as autologon. If not specified,\ndefaults to \\fBfalse\\fP.\n\n.TP\n\\fBdomain_user_separator\\fP=\\fBseparator\\fP\nIf specified the domain name supplied by the client is appended to the username separated\nby \\fBseparator\\fP.\n\n.TP\n\\fBrequire_credentials\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fP, \\fBtrue\\fP or \\fByes\\fP, \\fBxrdp\\fP requires clients\nto include username and password initial connection phase. In other\nwords, xrdp doesn't allow clients to show login screen if set to true.\nIt follows that an incorrect password will cause the login to immediately\nfail without displaying the login screen.  If not specified, defaults\nto \\fBfalse\\fP.\n\n.TP\n\\fBsecurity_layer\\fP=\\fI[tls|rdp|negotiate]\\fP\nRegulate security methods. If not specified, defaults to \\fBnegotiate\\fP.\n.RS 8\n.TP\n.B tls\nEnhanced RDP Security is used. All security operations (encryption, decryption, data integrity\nverification, and server authentication) are implemented by TLS.\n\n.TP\n.B rdp\nClassic RDP Security is used. The encryption level\nof Classic RDP Security is controlled by \\fBcrypt_level\\fP.\nUse this setting for testing only.\n\n.TP\n.B negotiate\nNegotiate these security methods with clients.\n.RE\n\n.TP\n\\fBssl_protocols\\fP=\\fI[SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2] [TLSv1.3]\\fP\nEnables the specified SSL/TLS protocols. Each value should be separated by comma.\nSSLv2 is always disabled. At least one protocol should be given to accept TLS connections.\nThis parameter is effective only if \\fBsecurity_layer\\fP is set to \\fBtls\\fP or \\fBnegotiate\\fP.\n\n.TP\n\\fBtcp_keepalive\\fP=\\fI[true|false]\\fP\nRegulate if the listening socket uses socket option \\fBSO_KEEPALIVE\\fP.\nIf set to \\fB1\\fP, \\fBtrue\\fP or \\fByes\\fP and the network connection disappears\nwithout closing messages, the connection will be closed.\n\n.TP\n\\fBtcp_nodelay\\fP=\\fI[true|false]\\fP\nRegulate if the listening socket uses socket option \\fBTCP_NODELAY\\fP.\nIf set to \\fB1\\fP, \\fBtrue\\fP or \\fByes\\fP, no buffering will be performed in the TCP stack.\n\n.TP\n\\fBtcp_send_buffer_bytes\\fP=\\fIbuffer_size\\fP\n.TP\n\\fBtcp_recv_buffer_bytes\\fP=\\fIbuffer_size\\fP\nSpecify send/recv buffer sizes in bytes.  The default value depends on\nthe operating system. It is recommended not to set these on systems with\ndynamic TCP buffer sizing\n\n.TP\n\\fBtls_ciphers\\fP=\\fIcipher_suite\\fP\nSpecifies TLS cipher suite. The format of this parameter is equivalent\nto which \\fBopenssl\\fP(1) ciphers subcommand accepts.\n\n(ex. $ openssl ciphers 'HIGH:!ADH:!SHA1')\n\nThis parameter is effective only if \\fBsecurity_layer\\fP is set to \\fBtls\\fP or \\fBnegotiate\\fP.\n\n.TP\n\\fBuse_fastpath\\fP=\\fI[input|output|both|none]\\fP\nIf not specified, defaults to \\fBnone\\fP.\n\n.TP\n\\fBblack\\fP=\\fI000000\\fP\n.TP\n\\fBgrey\\fP=\\fIc0c0c0\\fP\n.TP\n\\fBdark_grey\\fP=\\fI808080\\fP\n.TP\n\\fBblue\\fP=\\fI0000ff\\fP\n.TP\n\\fBdark_blue\\fP=\\fI00007f\\fP\n.TP\n\\fBwhite\\fP=\\fIffffff\\fP\n.TP\n\\fBred\\fP=\\fIff0000\\fP\n.TP\n\\fBgreen\\fP=\\fI00ff00\\fP\n.TP\n\\fBbackground\\fP=\\fI000000\\fP\nThese options override the colors used internally by \\fBxrdp\\fP(8) to draw the login and log windows.\nColors are defined using a hexadecimal (hex) notation for the combination of Red, Green, and Blue color values (RGB).\nThe lowest value that can be given to one of the light sources is 0 (hex 00).\nThe highest value is 255 (hex FF).\n.TP\n\\fBfv1_select\\fP=\\fI130:sans-18.fv1,0:sans-10.fv1\\fP\nSelects a default fv1 font.\nThis parameter is a comma-separated list of DPI:name pairs.  The list\nis scanned from left-to-right. The font used is the first font whose DPI\nvalue is less-than-or-equal to the vertical DPI of the monitor used for\nthe login screen.\n.TP\n\\fBdefault_dpi\\fP=\\fI96\\fP\nDefault DPI used for a monitor if the client does not send physical\nsize information.\n\n\n.SH \"LOGGING\"\nThe following parameters can be used in the \\fB[Logging]\\fR section:\n\n.TP\n\\fBLogFile\\fR=\\fI@localstatedir@/log/xrdp.log\\fR\nThis options contains the path to logfile. It can be either absolute or relative. If set to \\fB<stdout>\\fR, log will go to stdout. Use for debugging only\\fR\n\n.TP\n\\fBLogLevel\\fR=\\fIlevel\\fR\nThis option can have one of the following values:\n\n\\fBCORE\\fR or \\fB0\\fR \\- Log only core messages. these messages are _always_ logged, regardless the logging level selected.\n\n\\fBERROR\\fR or \\fB1\\fR \\- Log only error messages\n\n\\fBWARNING\\fR, \\fBWARN\\fR or \\fB2\\fR \\- Logs warnings and error messages\n\n\\fBINFO\\fR or \\fB3\\fR \\- Logs errors, warnings and informational messages\n\n\\fBDEBUG\\fR or \\fB4\\fR \\- Log everything. If \\fBxrdp-sesman\\fR is compiled in debug mode, this options will output many more low\\-level message, useful for developers\n\n.TP\n\\fBEnableSyslog\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR this option enables logging to syslog. Otherwise syslog is disabled.\n\n.TP\n\\fBSyslogLevel\\fR=\\fIlevel\\fR\nThis option sets the logging level for syslog. It can have the same values of \\fBLogLevel\\fR. If \\fBSyslogLevel\\fR is greater than \\fBLogLevel\\fR, its value is lowered to that of \\fBLogLevel\\fR.\n\n.TP\n\\fBEnableConsole\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR, this option enables logging to the console (ie. stdout).\n\n.TP\n\\fBConsoleLevel\\fR=\\fIlevel\\fR\nLogging level for the console. It can have the same values as \\fBLogLevel\\fR. Defaults to \\fBDEBUG\\fR.\n\n.TP\n\\fBEnableProcessId\\fR=\\fI[true|false]\\fR\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR, this option enables logging the process id in all log messages. Defaults to \\fBfalse\\fR.\n\n.SH \"CHANNELS\"\nThe Remote Desktop Protocol supports several channels, which are used to transfer additional data like sound, clipboard data and others.\nChannel names not listed here will be blocked by \\fBxrdp\\fP.\nNot all channels are supported in all cases, so setting a value to \\fItrue\\fP is a prerequisite, but does not force its use.\n.br\nChannels can also be enabled or disabled on a per connection basis by prefixing each setting with \\fBchannel.\\fP in the channel section.\n\n.TP\n\\fBrdpdr\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR using the RDP channel for device redirection is allowed.\n\n.TP\n\\fBrdpsnd\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR using the RDP channel for sound is allowed.\n\n.TP\n\\fBdrdynvc\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR using the RDP channel to initiate additional dynamic virtual channels is allowed.\n\n.TP\n\\fBcliprdr\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR using the RDP channel for clipboard redirection is allowed.\n\n.TP\n\\fBrail\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR using the RDP channel for remote applications integrated locally (RAIL) is allowed.\n\n.TP\n\\fBxrdpvr\\fP=\\fI[true|false]\\fP\nIf set to \\fB1\\fR, \\fBtrue\\fR or \\fByes\\fR using the RDP channel for XRDP Video streaming is allowed.\n\n.SH \"CONNECTIONS\"\nA connection section is made of a section name, enclosed in square brackets, and the following entries:\n\n.TP\n\\fBname\\fR=\\fI<session name>\\fR\nThe name displayed in \\fBxrdp\\fR(8) login window's combo box.\n\n.TP\n\\fBlib\\fR=\\fI../vnc/libvnc.so\\fR\nSets the library to be used with this connection.\n\n.TP\n\\fBusername\\fR=\\fI<username>\\fR|\\fI{base64}<base64-encoded-username>\\fR|\\fIask\\fR\nSpecifies the username used for authenticating in the connection.\nIf set to \\fIask\\fR, user name should be provided in the login window.\n\nIf the username includes comment out symbols such as '#', or ';', the username can be\nprovided in base64 form prefixing \"{base64}\".\n\n.TP\n\\fBpassword\\fR=\\fI<password>\\fR|\\fI{base64}<base64-encoded-password>\\fR|\\fIask\\fR\nSpecifies the password used for authenticating in the connection.\nIf set to \\fIask\\fR, password should be provided in the login window.\n\nThis parameter can be provided in base64 form as well as username. See also examples below.\n\n.TP\n\\fBip\\fR=\\fI127.0.0.1\\fR\nSpecifies the ip address of the host to connect to.\n\n.TP\n\\fBport\\fR=\\fI<number>\\fR|\\fI\\-1\\fR\nSpecifies the port number to connect to. If set to \\fI\\-1\\fR, the default port for the specified library is used.\n\n.TP\n\\fBxserverbpp\\fR=\\fI<number>\\fR\nSpecifies color depth of the backend X server. The default is the color\ndepth of the client. Only Xvnc uses that setting. Xorg runs at\n\\fI24\\fR bpp.\n\n.TP\n\\fBdisabled_encodings_mask\\fR=\\fI<number>\\fR\nSet this bitmask to a non-zero value to prevent \\fBxrdp\\fR(8) requesting\nsome features from the Xvnc server. You should only need to set this\nto  a non-zero value to work around bugs in your Xvnc server. The bit\nvalues supported for a particular release of \\fBxrdp\\fR(8) are documented in\n\\fBxrdp.ini\\fR.\n\n.TP\n\\fBcode\\fR=\\fI<number>\\fR|\\fI0\\fR\nSpecifies the session type. \\fI0\\fR is Xvnc over TCP,\n\\fI1\\fR is Xvnc over a UNIX domain socket,\nand \\fI20\\fR is Xorg with xorgxrdp modules.\nThe default is \\fI0\\fR on non-FIPS systems, and \\fI1\\fR on FIPS systems.\n.TP\n\\fBchansrvport\\fR=\\fBDISPLAY(\\fR\\fIn\\fR\\fB)\\fR|\\fBDISPLAY(\\fR\\fIn,u\\fR\\fB)\\fR||\\fI/path/to/domain-socket\\fR\nAsks xrdp to connect to a manually started \\fBxrdp-chansrv\\fR instance.\nThis can be useful if you wish to use to use xrdp to connect to a VNC session\nwhich has been started other than by \\fBxrdp-sesman\\fR, as you can then make\nuse of \\fBxrdp\\-chansrv\\fR facilities in the VNC session.\n\nEither the first or second form of this setting is recommended. Replace\n\\fIn\\fR with the X11 display number of the session, and (if applicable)\n\\fIu\\fR with the numeric ID of the session. The second form is only\nrequired if \\fBxrdp\\fR is unable to determine the session uid from the\nother values in the connection block.\n\nIf you use this setting, you must also set SessionSockdirGroup in\n\\fBsesman.ini\\fR to be the same as runtime_group in this file. This is\nnecessary to give \\fBxrdp\\fR the privilege to connect to \\fBxrdp\\-chansrv\\fR.\n\n.TP\n\\fBkeycode_set\\fR=\\fI<string>\\fR\n[Xorg only] Asks for the specified keycode set to be used by the X server.\nNormally \"evdev\" or \"base\". The default should be correct for your system.\n\n.TP\n\\fBh264_frame_interval\\fR=\\fI<integer>\\fR\n[Xorg only] Specify frame capture interval for H.264 captures in milliseconds.\n\n.TP\n\\fBrfx_frame_interval\\fR=\\fI<integer>\\fR\n[Xorg only] Specify frame capture interval for RemoteFX captures in milliseconds.\n\n.TP\n\\fBnormal_frame_interval\\fR=\\fI<integer>\\fR\n[Xorg only] Specify frame capture interval for normal captures in milliseconds.\n\n.SH \"EXAMPLES\"\nThis is an example \\fBxrdp.ini\\fR:\n\n.nf\n[Globals]\nbitmap_cache=true\nbitmap_compression=true\n\n[Xorg]\nname=Xorg\nlib=libxup.so\nusername=ask\npassword=ask\nip=127.0.0.1\nport=-1\ncode=20\nh264_frame_interval=16\nrfx_frame_interval=32\nnormal_frame_interval=40\n\n[vnc-any]\nname=vnc-any\nlib=libvnc.so\nip=ask\nport=ask5900\nusername=na\npassword={base64}cGFzc3dvcmQhCg==\n.fi\n\n.SH \"FILES\"\n@sysconfdir@/@sysconfsubdir@/xrdp.ini\n\n.SH \"SEE ALSO\"\n.BR xrdp (8),\n.BR xrdp\\-chansrv (8),\n.BR xrdp\\-sesman (8),\n.BR xrdp\\-sesrun (8),\n.BR sesman.ini (5)\n\nFor more info on \\fBxrdp\\fR see\n.UR @xrdphomeurl@\n.UE\n"
  },
  {
    "path": "fontutils/Makefile.am",
    "content": "EXTRA_DIST = windows\n\n# Some programs need freetype2 to build\nif USE_FREETYPE2\n  MKFV1 = xrdp-mkfv1\nelse\n  MKFV1 =\nendif\n\nAM_CPPFLAGS =  \\\n  -I$(top_builddir) \\\n  -I$(top_srcdir)/common \\\n  $(FREETYPE2_CFLAGS)\n\nbin_PROGRAMS = \\\n  $(MKFV1) \\\n  xrdp-dumpfv1\n\nxrdp_mkfv1_SOURCES = \\\n  mkfv1.c \\\n  fv1.c \\\n  fv1.h\n\nxrdp_mkfv1_LDADD = \\\n  $(top_builddir)/common/libcommon.la \\\n  $(FREETYPE2_LIBS)\n\nxrdp_dumpfv1_SOURCES = \\\n  dumpfv1.c \\\n  fv1.c \\\n  fv1.h\n\nxrdp_dumpfv1_LDADD = \\\n  $(top_builddir)/common/libcommon.la\n"
  },
  {
    "path": "fontutils/README_fv1.txt",
    "content": "The fv1 font format has the following characteristics:-\n\n1) Bitmap fonts (i.e. pixels are on or off)\n2) 96 DPI is assumed\n3) Glyphs from U+0020 up to a pre-defined limit are stored in the file.\n   At the time of writing this limit is U+4DFF. To change the limit\n   requires a change to xrdp/xrdp_types.h and (potentially)\n   fontutils/mkfv1.c\n4) Font format is header, plus a variable data area for each glyph.\n\nThe intention (over time) is to build support for the freetype2 library\ndirectly into xrdp. This will allow for modern font features like\nanti-aliasing and kerning to be supported.\n\nGeneral Info\n------------\nAll numeric values are 2 octets, and stored in twos-complement\nlittle-endian format.\n\nDimensions are all measured in pixels.\n\nFont header\n-----------\n\nsignature     4 octets   File signature - \"FNT1\"\nfont~name    32 octets   Null-terminated if less that 32 octets long\npoint_size    2 octets   Assumes 96 DPI.\nstyle         2 octets   Unused. Set to 1.\nbody_height   2 octets   Line spacing for font.\nmin_descender 2 octets   The common lowest descender value in the font\n                         glyphs (A few glyphs may be lower than\n                         this). Used to calculate where the font baseline\n                         is in relation to the text box for the font.\n<padding>     4 octets   Set to zero.\n\nOlder fonts, generated for xrdp v.0.9x and earlier, have zero values\nfor the body_height and min_descender. For these fonts, the body height is\ncalculated as (-baseline + 1) for the first glyph, and the glyphs are\nall offset so that a min_descender of 0 works OK.\n\nGlyph data\n----------\nThe header is followed by a number of glyphs representing U+0020 upwards. The\nglyphs have a variable size. The format of each glyph is as follows:-\n\nwidth         2 octets   Width of character data\nheight        2 octets   Height of character data\nbaseline      2 octets   Offset from font baseline to 1st row of glyph data\noffset        2 octets   Space before glyph is drawn (can be -ve)\ninc_by        2 octets   Total width of glyph + spacing. The width of\n                         a string is obtained by adding up all the inc_by\n                         fields for all the glyphs\ndata          <variable> Bitmap data.\n\nBitmap data is laid out in rows from top to bottom.  Within each row the\nmost significant bit of each octet is on the left.  Row data is padded\nto the nearest octet (e.g. a 14 bit width would be padded by 2 bits to\n16 bits (2 octets). The total data is padded out with between 0 and 3\noctets to end on a 4-octet boundary.\n\nExample glyph:-\n\nGlyph : U+0067\n  Width : 12\n  Height : 18\n  Baseline : -13\n  Offset : 1\n  Inc By : 15\n  Data :\n    -13: ...XXXXX..XX    1F 30\n    -12: ..XXXXXXXXXX    3F F0\n    -11: .XXX....XXXX    70 F0\n    -10: XXX......XXX    E0 70\n     -9: XX........XX    C0 30\n     -8: XX........XX    C0 30\n     -7: XX........XX    C0 30\n     -6: XX........XX    C0 30\n     -5: XX........XX    C0 30\n     -4: XXX......XXX    E0 70\n     -3: .XXX....XXXX    70 F0\n     -2: ..XXXXXXXXXX    3F F0\n     -1: ...XXXXX..XX    1F 30\n     +0: ..........XX    00 30\n     +1: .........XXX    00 70\n     +2: ..X.....XXX.    20 E0\n     +3: ..XXXXXXXX..    3F C0\n     +4: ...XXXXXX...    1F 80\n"
  },
  {
    "path": "fontutils/dumpfv1.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * fonts\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <limits.h>\n#include <unistd.h>\n#include <ctype.h>\n\n#include \"list.h\"\n#include \"os_calls.h\"\n#include \"parse.h\"\n#include \"string_calls.h\"\n#include \"fv1.h\"\n\n/**\n * What the program is doing\n */\nenum program_mode\n{\n    PM_UNSPECIFIED = 0,\n    PM_INFO,\n    PM_GLYPH_INFO_TABLE,\n    PM_SHOW_CHAR\n};\n\n/**\n * Parsed program arguments\n */\nstruct program_args\n{\n    const char *font_file;\n    enum program_mode mode;\n    int ucode; /* Unicode character to display in 'c' mode */\n};\n\n/**************************************************************************//**\n * Parses the program args\n *\n * @param argc Passed to main\n * @param argv Passed to main\n * @param pa program_pargs structure for resulting values\n * @return !=0 for success\n */\nstatic int\nparse_program_args(int argc, char *argv[], struct program_args *pa)\n{\n    int params_ok = 1;\n    int opt;\n\n    pa->font_file = NULL;\n    pa->mode = PM_UNSPECIFIED;\n    pa->ucode = 0;\n\n    while ((opt = getopt(argc, argv, \"c:it\")) != -1)\n    {\n        switch (opt)\n        {\n            case 'i':\n                if (pa->mode == PM_UNSPECIFIED)\n                {\n                    pa->mode = PM_INFO;\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Can't have two modes set\");\n                    params_ok = 0;\n                }\n                break;\n\n            case 't':\n                if (pa->mode == PM_UNSPECIFIED)\n                {\n                    pa->mode = PM_GLYPH_INFO_TABLE;\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Can't have two modes set\");\n                    params_ok = 0;\n                }\n                break;\n\n            case 'c':\n                if (pa->mode == PM_UNSPECIFIED)\n                {\n                    pa->mode = PM_SHOW_CHAR;\n                    if (toupper(optarg[0]) == 'U' && optarg[1] == '+')\n                    {\n                        char *hex = g_strdup(optarg);\n                        hex[0] = '0';\n                        hex[1] = 'x';\n                        pa->ucode = g_atoix(hex);\n                        g_free(hex);\n                    }\n                    else if (optarg[0] == '@')\n                    {\n                        pa->ucode = optarg[1];\n                    }\n                    else\n                    {\n                        pa->ucode = g_atoix(optarg);\n                    }\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Can't have two modes set\");\n                    params_ok = 0;\n                }\n                break;\n\n            default:\n                LOG(LOG_LEVEL_ERROR, \"Unrecognised switch '%c'\", (char)opt);\n                params_ok = 0;\n        }\n    }\n\n    if (argc <= optind)\n    {\n        LOG(LOG_LEVEL_ERROR, \"No font file specified\");\n        params_ok = 0;\n    }\n    else if ((argc - optind) > 1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unexpected arguments after font file\");\n        params_ok = 0;\n    }\n    else\n    {\n        pa->font_file = argv[optind];\n    }\n\n    return params_ok;\n}\n\n/**************************************************************************//**\n * Displays information about a font file\n *\n * @param fv1 loaded font file\n */\nstatic void\ndisplay_font_file_info(const struct fv1_file *fv1)\n{\n    g_printf(\"Font name : %s\\n\", fv1->font_name);\n    g_printf(\"Point size (%d DPI) : %d\\n\", FV1_DEVICE_DPI, fv1->point_size);\n    g_printf(\"Style : %d\\n\", fv1->style);\n    if (fv1->body_height == 0 && fv1->glyphs->count > 0)\n    {\n        const struct fv1_glyph *g =\n            (const struct fv1_glyph *)fv1->glyphs->items[0];\n        g_printf(\"Body height : %d (from 1st glyph)\\n\", -g->baseline + 1);\n    }\n    else\n    {\n        g_printf(\"Body height : %d\\n\", fv1->body_height);\n    }\n    g_printf(\"Descender : %d\\n\", fv1->min_descender);\n\n    if (fv1->glyphs->count == 0)\n    {\n        g_printf(\"\\nFile contains no glyphs\\n\");\n    }\n    else\n    {\n        g_printf(\"Min glyph index : U+%04X\\n\", FV1_MIN_CHAR);\n        g_printf(\"Max glyph index : U+%04X\\n\", FV1_GLYPH_END(fv1) - 1);\n\n        /* Work out the statistics */\n        unsigned short max_width = 0;\n        int max_width_ucode = 0;\n        unsigned short max_height = 0;\n        int max_height_ucode = 0;\n        short min_baseline = 0;\n        int min_baseline_ucode = 0;\n        short min_offset = 0;\n        int min_offset_ucode = 0;\n        short max_offset = 0;\n        int max_offset_ucode = 0;\n        unsigned short max_inc_by = 0;\n        int max_inc_by_ucode = 0;\n\n        /* Derived quantities */\n        short min_y_descender = SHRT_MAX;\n        int min_y_descender_ucode = 0;\n        int max_datasize = -1;\n        int max_datasize_ucode = 0;\n\n        /* Loop and output macros */\n#define SET_MIN(ucode,field,val) \\\n    if ((field) < (val)) \\\n    { \\\n        val = (field); \\\n        val##_ucode = (ucode); \\\n    }\n\n#define SET_MAX(ucode,field,val) \\\n    if ((field) > (val)) \\\n    { \\\n        val = (field); \\\n        val##_ucode = (ucode); \\\n    }\n\n#define OUTPUT_INFO(string, val) \\\n    if (val##_ucode > 0) \\\n    { \\\n        g_printf(string, val, val##_ucode); \\\n    }\n        int u;\n        for (u = FV1_MIN_CHAR ; u < FV1_GLYPH_END(fv1); ++u)\n        {\n            const struct fv1_glyph *g = FV1_GET_GLYPH(fv1, u);\n            if (g != NULL)\n            {\n                short y_descender = - (g->baseline + g->height);\n                int datasize = FONT_DATASIZE(g);\n\n                SET_MAX(u, g->width, max_width);\n                SET_MAX(u, g->height, max_height);\n                SET_MIN(u, g->baseline, min_baseline);\n                SET_MIN(u, g->offset, min_offset);\n                SET_MAX(u, g->offset, max_offset);\n                SET_MAX(u, g->inc_by, max_inc_by);\n                SET_MIN(u, y_descender, min_y_descender);\n                SET_MAX(u, datasize, max_datasize);\n            }\n        }\n\n        OUTPUT_INFO(\"Max glyph width : %d (U+%04X)\\n\", max_width);\n        OUTPUT_INFO(\"Max glyph height : %d (U+%04X)\\n\", max_height);\n        OUTPUT_INFO(\"Min glyph y-baseline : %d (U+%04X)\\n\", min_baseline);\n        OUTPUT_INFO(\"Min glyph y-descender : %d (U+%04X)\\n\", min_y_descender);\n        OUTPUT_INFO(\"Min glyph x-offset : %d (U+%04X)\\n\", min_offset);\n        OUTPUT_INFO(\"Max glyph x-offset : %d (U+%04X)\\n\", max_offset);\n        OUTPUT_INFO(\"Max glyph x-inc_by : %d (U+%04X)\\n\", max_inc_by);\n        OUTPUT_INFO(\"Max glyph datasize : %d (U+%04X)\\n\", max_datasize);\n\n#undef SET_MIN\n#undef SET_MAX\n#undef OUTPUT_INFO\n    }\n}\n\n/**************************************************************************//**\n * Display info in a table about all the glyphs\n * @param fv1 font file\n */\nstatic void\ndisplay_glyph_info_table(const struct fv1_file *fv1)\n{\n    int u;\n    g_printf(\"character,width,height,baseline,offset,inc_by,datasize\\n\");\n\n    for (u = FV1_MIN_CHAR; u < FV1_GLYPH_END(fv1); ++u)\n    {\n        const struct fv1_glyph *g = FV1_GET_GLYPH(fv1, u);\n        if (g != NULL)\n        {\n            int datasize = FONT_DATASIZE(g);\n            g_printf(\"%d,%hu,%hu,%hd,%hd,%hu,%d\\n\",\n                     u, g->width, g->height, g->baseline,\n                     g->offset, g->inc_by, datasize);\n        }\n    }\n}\n\n/**************************************************************************//**\n * Converts a font data row to a printable string\n *\n * @param rowdata Pointer to the first byte of the row data\n * @param width Number of pixels in the row\n * @param out Output buffer. Must be sized by the caller to be at\n *            least width+1 bytes\n */\nstatic void\nrow_to_str(const unsigned char *rowdata, int width, char *out)\n{\n    int x;\n    int mask = 1 << 7;\n    for (x = 0 ; x < width ; ++x)\n    {\n        out[x] = ((*rowdata & mask) != 0) ? 'X' : '.';\n        mask >>= 1;\n        if (mask == 0)\n        {\n            mask = 1 << 7;\n            ++rowdata;\n        }\n    }\n    out[width] = '\\0';\n}\n\n/**************************************************************************//**\n * Display info about a specific glyph\n * @param ucode Unicode character value\n * @param g Glyph\n */\nstatic void\ndisplay_glyph_info(int ucode, const struct fv1_glyph *g)\n{\n\n    char *row_buffer = (char *)g_malloc(g->width + 1, 0);\n    if (row_buffer == NULL)\n    {\n        g_printf(\"<No memory>\\n\");\n    }\n    else\n    {\n        g_printf(\"Glyph : U+%04X\\n\", ucode);\n        g_printf(\"  Width : %d\\n\", g->width);\n        g_printf(\"  Height : %d\\n\", g->height);\n        g_printf(\"  Baseline : %d\\n\", g->baseline);\n        g_printf(\"  Offset : %d\\n\", g->offset);\n        g_printf(\"  Inc By : %d\\n\", g->inc_by);\n\n        g_printf(\"  Data :\\n\");\n        int y;\n        const unsigned char *dataptr = g->data;\n\n        for (y = 0 ; y < g->height; ++y)\n        {\n            row_to_str(dataptr, g->width, row_buffer);\n            g_printf(\"    %+3d: %s\\n\", y + g->baseline, row_buffer);\n            dataptr += (g->width + 7) / 8;\n        }\n        g_free(row_buffer);\n    }\n}\n\n/**************************************************************************//**\n * Main\n *\n * @param argc Argument count\n * @param argv Arguments\n */\nint\nmain(int argc, char *argv[])\n{\n    struct fv1_file *fv1 = NULL;\n    struct log_config *logging;\n    struct program_args pa;\n    int rv = 1;\n\n    logging = log_config_init_for_console(LOG_LEVEL_WARNING,\n                                          g_getenv(\"DUMPFV1_LOG_LEVEL\"));\n    log_start_from_param(logging);\n    log_config_free(logging);\n\n    if (parse_program_args(argc, argv, &pa) &&\n            (fv1 = fv1_file_load(pa.font_file)) != NULL)\n    {\n        switch (pa.mode)\n        {\n            case PM_INFO:\n                display_font_file_info(fv1);\n                rv = 0;\n                break;\n\n            case PM_GLYPH_INFO_TABLE:\n                display_glyph_info_table(fv1);\n                rv = 0;\n                break;\n\n            case PM_SHOW_CHAR:\n                if (pa.ucode < FV1_MIN_CHAR)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Value for -c must be at least U+%04X\",\n                        FV1_MIN_CHAR);\n                }\n                else if (pa.ucode >= FV1_GLYPH_END(fv1))\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Value for -c must be less than U+%04X\",\n                        FV1_GLYPH_END(fv1));\n                }\n                else\n                {\n                    const struct fv1_glyph *g =\n                        (const struct fv1_glyph *)\n                        list_get_item(fv1->glyphs, pa.ucode - FV1_MIN_CHAR);\n                    display_glyph_info(pa.ucode, g);\n                    rv = 0;\n                }\n                break;\n\n            default:\n                LOG(LOG_LEVEL_ERROR, \"Specify one of '-i' or '-c'\");\n                break;\n        }\n    }\n\n    fv1_file_free(fv1);\n    log_end();\n\n    return rv;\n}\n"
  },
  {
    "path": "fontutils/fv1.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    fontutils/fv1.c\n * @brief   Definitions relating to fv1 font files\n */\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stddef.h>\n\n#include \"list.h\"\n#include \"os_calls.h\"\n#include \"parse.h\"\n#include \"string_calls.h\"\n#include \"fv1.h\"\n\nstatic const char FV1_SIGNATURE[] = {'F', 'N', 'T', '1'};\n\n/*****************************************************************************/\nstruct fv1_glyph *\nfv1_alloc_glyph(int ucode,\n                unsigned short width,\n                unsigned short height)\n{\n    int datasize = FONT_DATASIZE_FROM_GEOMETRY(width, height);\n    struct fv1_glyph *glyph = NULL;\n    char ucode_str[16] = {'\\0'};\n    if (ucode < 0)\n    {\n        g_snprintf(ucode_str, sizeof(ucode_str), \"Glyph\");\n    }\n    else\n    {\n        g_snprintf(ucode_str, sizeof(ucode_str), \"Glyph:U+%04X\", ucode);\n    }\n\n    if (datasize < 0 || datasize > FV1_MAX_GLYPH_DATASIZE)\n    {\n\n        /* shouldn't happen */\n        LOG(LOG_LEVEL_ERROR, \"%s - datasize %d out of bounds\",\n            ucode_str, datasize);\n    }\n    else\n    {\n        glyph = (struct fv1_glyph *)\n                g_malloc( offsetof(struct fv1_glyph, data) + datasize, 1);\n\n        if (glyph == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s - out of memory\", ucode_str);\n        }\n        else\n        {\n            glyph->width = width;\n            glyph->height = height;\n        }\n    }\n\n    return glyph;\n}\n\n/*****************************************************************************/\nstruct fv1_file *\nfv1_file_create(void)\n{\n    struct fv1_file *fv1 = (struct fv1_file *)g_new0(struct fv1_file, 1);\n    if (fv1 == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"fv1_file_create - out of memory\");\n    }\n    else\n    {\n        fv1->style = 1; /* Unused at present - compatibility value */\n        fv1->glyphs = list_create();\n        fv1->glyphs->auto_free = 1;\n    }\n    return fv1;\n}\n\n/*****************************************************************************/\nstatic void\nadd_glyphs_from_stream(struct fv1_file *fv1, struct stream *s)\n{\n    unsigned short width;\n    unsigned short height;\n    int datasize;\n\n    struct fv1_glyph *glyph;\n\n    while (s_check_rem(s, 4))\n    {\n        in_sint16_le(s, width);\n        in_sint16_le(s, height);\n\n        datasize = FONT_DATASIZE_FROM_GEOMETRY(width, height);\n\n        if (datasize < 0 || datasize > FV1_MAX_GLYPH_DATASIZE)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Font:%s Glyph:%d - datasize %d out of bounds\",\n                fv1->font_name, FV1_GLYPH_END(fv1), datasize);\n            break;\n        }\n\n        if (!s_check_rem(s, 6 + 6 + datasize))\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Font:%s Glyph:%d - not enough data for glyph\",\n                fv1->font_name, FV1_GLYPH_END(fv1));\n            break;\n        }\n\n        if ((glyph = fv1_alloc_glyph(FV1_GLYPH_END(fv1), width, height)) == NULL)\n        {\n            break;\n        }\n\n        in_sint16_le(s, glyph->baseline);\n        in_sint16_le(s, glyph->offset);\n        in_sint16_le(s, glyph->inc_by);\n        in_uint8s(s, 6);\n\n        in_uint8a(s, glyph->data, datasize);\n\n        list_add_item(fv1->glyphs, (tintptr)glyph);\n    }\n}\n\n/*****************************************************************************/\nstruct fv1_file *\nfv1_file_load(const char *filename)\n{\n    struct fv1_file *fv1 = NULL;\n\n    if (!g_file_exist(filename))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't find font file %s\", filename);\n    }\n    else\n    {\n        int file_size = g_file_get_size(filename);\n        if (file_size < FV1_MIN_FILE_SIZE || file_size > FV1_MAX_FILE_SIZE)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Font file %s has bad size %d\",\n                filename, file_size);\n        }\n        else\n        {\n            struct stream *s;\n            int fd;\n            make_stream(s);\n            init_stream(s, file_size + 1024);\n            fd = g_file_open_ro(filename);\n\n            if (fd < 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Can't open font file %s\", filename);\n            }\n            else\n            {\n                int b = g_file_read(fd, s->data, file_size + 1024);\n                g_file_close(fd);\n\n                if (b < FV1_MIN_FILE_SIZE)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Font file %s is too small\",\n                        filename);\n                }\n                else\n                {\n                    char sig[sizeof(FV1_SIGNATURE)];\n                    s->end = s->data + b;\n                    in_uint8a(s, sig, sizeof(FV1_SIGNATURE));\n                    if (g_memcmp(sig, FV1_SIGNATURE, sizeof(sig)) != 0)\n                    {\n                        LOG(LOG_LEVEL_ERROR,\n                            \"Font file %s has wrong signature\",\n                            filename);\n                    }\n                    else if ((fv1 = fv1_file_create()) != NULL)\n                    {\n                        in_uint8a(s, fv1->font_name, FV1_MAX_FONT_NAME_SIZE);\n                        fv1->font_name[FV1_MAX_FONT_NAME_SIZE] = '\\0';\n                        in_uint16_le(s, fv1->point_size);\n                        in_uint16_le(s, fv1->style);\n                        in_uint16_le(s, fv1->body_height);\n                        in_uint16_le(s, fv1->min_descender);\n                        in_uint8s(s, 4);\n\n                        add_glyphs_from_stream(fv1, s);\n                    }\n                }\n            }\n\n            free_stream(s);\n        }\n    }\n\n    return fv1;\n}\n\n/*****************************************************************************/\nvoid\nfv1_file_free(struct fv1_file *fv1)\n{\n    if (fv1 != NULL)\n    {\n        list_delete(fv1->glyphs);\n        g_free(fv1);\n    }\n}\n\n/*****************************************************************************/\nstatic int\nwrite_stream(int fd, struct stream *s)\n{\n    const char *p = s->data;\n    int rv = 1;\n\n    while (p < s->end)\n    {\n        int len = g_file_write(fd, p, s->end - p);\n        if (len <= 0)\n        {\n            rv = 0;\n            break;\n        }\n        p += len;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nfv1_file_save(const struct fv1_file *fv1, const char *filename)\n{\n    int fd;\n    struct fv1_glyph *blank_glyph; /* Needed for bad characters */\n\n    fd = g_file_open_ex(filename, 0, 1, 1, 1);\n    int rv = 1;\n    if (fd < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to open %s for writing [%s]\", filename,\n            g_get_strerror());\n    }\n    else\n    {\n        struct stream *s;\n        make_stream(s);\n        init_stream(s, 1024);\n\n        /* Write the header */\n        out_uint8a(s, FV1_SIGNATURE, sizeof(FV1_SIGNATURE));\n        int len = g_strlen(fv1->font_name);\n        if (len > FV1_MAX_FONT_NAME_SIZE)\n        {\n            len = FV1_MAX_FONT_NAME_SIZE;\n        }\n        out_uint8a(s, fv1->font_name,  len);\n        while (len++ < FV1_MAX_FONT_NAME_SIZE)\n        {\n            out_uint8(s, '\\0');\n        }\n        out_uint16_le(s, fv1->point_size);\n        out_uint16_le(s, fv1->style);\n        out_uint16_le(s, fv1->body_height);\n        out_uint16_le(s, fv1->min_descender);\n        out_uint8a(s, \"\\0\\0\\0\\0\", 4);\n        s_mark_end(s);\n        if (!write_stream(fd, s))\n        {\n            LOG(LOG_LEVEL_ERROR, \"Unable to write file header [%s]\",\n                g_get_strerror());\n        }\n        else if ((blank_glyph = fv1_alloc_glyph(-1, 0, 0)) == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Unable to allocate blank glyph\");\n        }\n        else\n        {\n            int u;\n\n            for (u = FV1_MIN_CHAR; u < FV1_GLYPH_END(fv1); ++u)\n            {\n                const struct fv1_glyph *g = FV1_GET_GLYPH(fv1, u);\n                int datasize;\n                if (g == NULL)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"Glyph %d is not set\", u);\n                    g = blank_glyph;\n                }\n                else\n                {\n                    datasize = FONT_DATASIZE(g);\n                    if (datasize > FV1_MAX_GLYPH_DATASIZE)\n                    {\n                        LOG(LOG_LEVEL_WARNING,\n                            \"glyph %d datasize %d exceeds max of %d\"\n                            \" - glyph will be blank\",\n                            u, datasize, FV1_MAX_GLYPH_DATASIZE);\n                        g = blank_glyph;\n                    }\n                }\n                init_stream(s, 16 + FONT_DATASIZE(g));\n                out_uint16_le(s, g->width);\n                out_uint16_le(s, g->height);\n                out_uint16_le(s, g->baseline);\n                out_uint16_le(s, g->offset);\n                out_uint16_le(s, g->inc_by);\n                out_uint8a(s, \"\\0\\0\\0\\0\\0\\0\", 6);\n                out_uint8a(s, g->data, FONT_DATASIZE(g));\n                s_mark_end(s);\n\n                if (!write_stream(fd, s))\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Unable to write glyph %d [%s]\",\n                        u, g_get_strerror());\n                    break;\n                }\n            }\n            g_free(blank_glyph);\n\n            rv = (u == FV1_GLYPH_END(fv1)) ? 0 : 1;\n        }\n        free_stream(s);\n        g_file_close(fd);\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "fontutils/fv1.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    fontutils/fv1.h\n * @brief   Definitions relating to fv1 font files\n */\n#if !defined(FV1_H)\n#define FV1_H\n\nstruct list;\n\n#define FV1_DEVICE_DPI 96\n\n#define FV1_MIN_CHAR 0x20  /* First character value in file */\n\n#define FV1_MIN_FILE_SIZE 48\n#define FV1_MAX_FILE_SIZE (10 * 1024 * 1024)\n#define FV1_MAX_FONT_NAME_SIZE 32\n\n#define FV1_MAX_GLYPH_DATASIZE 512\n\nstruct fv1_glyph\n{\n    unsigned short width;   /* Width of glyph */\n    unsigned short height;  /* Height of glyph */\n    short baseline; /* Offset from cursor pos to 1st row of glyph */\n    short offset; /* Space before glyph (can be -ve) */\n    unsigned short inc_by; /* Total width of glyph + spacing */\n    /* Standard C++ does not yet support C99 flexible array members */\n#ifdef __cplusplus\n    unsigned char data[1];\n#else\n    unsigned char data[];\n#endif\n};\n\nstruct fv1_file\n{\n    char font_name[FV1_MAX_FONT_NAME_SIZE + 1];\n    short point_size; /* Input point size (for reference) */\n    short style;\n    short body_height; /* Body height (pixels) */\n    short min_descender; /* Min descender of the glyphs in the font */\n    struct list *glyphs; /* Glyphs are struct fv1_glyph * */\n\n};\n\n/**\n * Get a glyph pointer for a unicode character\n */\n#define FV1_GET_GLYPH(fv1,ucode) \\\n    (((ucode) < FV1_MIN_CHAR) \\\n     ? NULL \\\n     : (struct fv1_glyph *)list_get_item(fv1->glyphs, (ucode) - FV1_MIN_CHAR))\n\n/**\n * First glyph not in file\n */\n#define FV1_GLYPH_END(fv1) (fv1->glyphs->count + FV1_MIN_CHAR)\n\nstruct fv1_file *\nfv1_file_load(const char *filename);\n\nvoid\nfv1_file_free(struct fv1_file *);\n\nstruct fv1_file *\nfv1_file_create(void);\n\nstruct fv1_glyph *\nfv1_alloc_glyph(int ucode, /* Unicode character for error reporting if known */\n                unsigned short width,\n                unsigned short height);\n\nenum fv1_realloc_mode\n{\n    FV1_AT_TOP,\n    FV1_AT_BOTTOM\n};\n\nint\nfv1_file_save(const struct fv1_file *fv1, const char *filename);\n\n#endif\n"
  },
  {
    "path": "fontutils/mkfv1.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <unistd.h>\n#include <ctype.h>\n#include <ft2build.h>\n#include FT_FREETYPE_H\n\n/* See the FT2 documentation - this builds an error table */\n#undef FTERRORS_H_\n#define FT_ERRORDEF( e, v, s )  { e, s },\n#define FT_ERROR_START_LIST     {\n#define FT_ERROR_END_LIST       { 0, NULL } };\n\nstatic const struct\n{\n    int          err_code;\n    const char  *err_msg;\n} ft_errors[] =\n#include <freetype/fterrors.h>\n#ifdef __cppcheck__\n    // avoid syntaxError by providing the array contents\n    {};\n#endif\n\n\n#include \"arch.h\"\n#include \"defines.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n#include \"fv1.h\"\n\n#define DEFAULT_POINT_SIZE 10\n#define DEFAULT_MAX_CHAR 0x4dff\n\n/**\n * sans10 compatibility choices\n */\nenum sans10_compat\n{\n    S10_OFF = 0,\n    S10_ON,\n    S10_AUTO\n};\n\n/**\n * Parsed program arguments\n */\nstruct program_args\n{\n    const char *input_file;\n    const char *output_file;\n    char font_name[FV1_MAX_FONT_NAME_SIZE + 1];\n    unsigned short point_size;\n    /** Last character value in file */\n    unsigned int max_ucode;\n    /** Are we generating san10 in compatibility mode? */\n    enum sans10_compat sans10_compatibility;\n};\n\nstruct x_dimensions\n{\n    unsigned short width;\n    short offset;\n    unsigned short inc_by;\n};\n\n/**\n * Table of some character settings in the original sans-10.fv1 font\n */\nstatic const struct x_dimensions\n    original_sans10_data[] =\n{\n    /* 0x20 - 0x3f */\n    {1, 0, 4}, {1, 2, 5}, {3, 1, 5}, {9, 1, 11},\n    {7, 1, 8}, {11, 0, 12}, {9, 1, 11}, {1, 1, 3},\n    {3, 1, 5}, {3, 1, 5}, {7, 0, 7}, {9, 1, 11},\n    {2, 1, 4}, {3, 1, 5}, {1, 2, 4}, {4, 0, 4},\n    {6, 1, 8}, {5, 2, 8}, {6, 1, 8}, {6, 1, 8},\n    {6, 1, 8}, {6, 1, 8}, {6, 1, 8}, {6, 1, 8},\n    {6, 1, 8}, {6, 1, 8}, {1, 2, 4}, {2, 1, 4},\n    {8, 1, 11}, {8, 1, 11}, {8, 1, 11}, {5, 1, 7},\n    /* 0x40 - 0x5f */\n    {11, 1, 13}, {9, 0, 9}, {7, 1, 9}, {7, 1, 9},\n    {8, 1, 10}, {6, 1, 8}, {5, 1, 7}, {8, 1, 10},\n    {8, 1, 10}, {1, 1, 3}, {3, -1, 3}, {7, 1, 8},\n    {6, 1, 7}, {9, 1, 11}, {8, 1, 10}, {8, 1, 10},\n    {6, 1, 8}, {8, 1, 10}, {7, 1, 8}, {7, 1, 9},\n    {7, 0, 7}, {8, 1, 10}, {9, 0, 9}, {11, 0, 11},\n    {8, 0, 8}, {7, 0, 7}, {8, 1, 10}, {3, 1, 5},\n    {4, 0, 4}, {3, 1, 5}, {8, 1, 11}, {7, 0, 7},\n    /* 0x60 - 0x7f */\n    {3, 1, 7}, {6, 1, 8}, {6, 1, 8}, {5, 1, 7},\n    {6, 1, 8}, {6, 1, 8}, {4, 0, 4}, {6, 1, 8},\n    {6, 1, 8}, {1, 1, 3}, {2, 0, 3}, {6, 1, 7},\n    {1, 1, 3}, {11, 1, 13}, {6, 1, 8}, {6, 1, 8},\n    {6, 1, 8}, {6, 1, 8}, {4, 1, 5}, {5, 1, 7},\n    {4, 0, 5}, {6, 1, 8}, {7, 0, 7}, {9, 0, 9},\n    {7, 0, 7}, {7, 0, 7}, {5, 1, 7}, {5, 2, 8},\n    {1, 2, 4}, {5, 2, 8}, {8, 1, 11}, {7, 1, 8},\n    /* 0x80 - 0x9f */\n    {7, 1, 8}, {7, 1, 8}, {7, 1, 8}, {7, 1, 8},\n    {7, 1, 8}, {7, 1, 8}, {7, 1, 8}, {7, 1, 8},\n    {7, 1, 8}, {7, 1, 8}, {7, 1, 8}, {7, 1, 8},\n    {7, 1, 8}, {7, 1, 8}, {7, 1, 8}, {7, 1, 8},\n    {7, 1, 8}, {7, 1, 8}, {7, 1, 8}, {7, 1, 8},\n    {7, 1, 8}, {7, 1, 8}, {7, 1, 8}, {7, 1, 8},\n    {7, 1, 8}, {7, 1, 8}, {7, 1, 8}, {7, 1, 8},\n    {7, 1, 8}, {7, 1, 8}, {7, 1, 8}, {7, 1, 8},\n    /* 0xa0 - 0xbf */\n    {1, 0, 4}, {1, 2, 5}, {6, 1, 8}, {7, 0, 8},\n    {7, 0, 8}, {7, 1, 8}, {1, 2, 4}, {5, 1, 7},\n    {3, 2, 7}, {9, 2, 13}, {5, 1, 6}, {6, 1, 8},\n    {8, 1, 11}, {3, 1, 5}, {9, 2, 13}, {4, 1, 7},\n    {4, 1, 7}, {9, 1, 11}, {4, 1, 5}, {4, 1, 5},\n    {3, 2, 7}, {7, 1, 8}, {6, 1, 8}, {1, 1, 4},\n    {3, 2, 7}, {3, 1, 5}, {5, 1, 6}, {6, 1, 8},\n    {12, 1, 13}, {11, 1, 13}, {12, 1, 13}, {5, 1, 7},\n    /* 0xc0 - 0xdf */\n    {9, 0, 9}, {9, 0, 9}, {9, 0, 9}, {9, 0, 9},\n    {9, 0, 9}, {9, 0, 9}, {12, 0, 13}, {7, 1, 9},\n    {6, 1, 8}, {6, 1, 8}, {6, 1, 8}, {6, 1, 8},\n    {2, 0, 3}, {2, 1, 3}, {5, -1, 3}, {3, 0, 3},\n    {9, 0, 10}, {8, 1, 10}, {8, 1, 10}, {8, 1, 10},\n    {8, 1, 10}, {8, 1, 10}, {8, 1, 10}, {7, 2, 11},\n    {8, 1, 10}, {8, 1, 10}, {8, 1, 10}, {8, 1, 10},\n    {8, 1, 10}, {7, 0, 7}, {6, 1, 8}, {6, 1, 8},\n    /* 0xe0 - 0xff */\n    {6, 1, 8}, {6, 1, 8}, {6, 1, 8}, {6, 1, 8},\n    {6, 1, 8}, {6, 1, 8}, {11, 1, 13}, {5, 1, 7},\n    {6, 1, 8}, {6, 1, 8}, {6, 1, 8}, {6, 1, 8},\n    {3, 0, 3}, {3, 1, 3}, {5, -1, 3}, {3, 0, 3},\n    {6, 1, 8}, {6, 1, 8}, {6, 1, 8}, {6, 1, 8},\n    {6, 1, 8}, {6, 1, 8}, {6, 1, 8}, {8, 1, 11},\n    {6, 1, 8}, {6, 1, 8}, {6, 1, 8}, {6, 1, 8},\n    {6, 1, 8}, {7, 0, 7}, {6, 1, 8}, {7, 0, 7}\n};\n\n\n/**************************************************************************//**\n * Parses a unicode character value\n *\n * @param str String containing value\n * @return Resulting character value\n */\nstatic unsigned int\nparse_ucode_name(const char *str)\n{\n    unsigned int rv;\n    if (toupper(str[0]) == 'U' && str[1] == '+')\n    {\n        char *hex = g_strdup(str);\n        hex[0] = '0';\n        hex[1] = 'x';\n        rv = g_atoix(hex);\n        g_free(hex);\n    }\n    else if (str[0] == '@')\n    {\n        rv = str[1];\n    }\n    else\n    {\n        rv = g_atoix(str);\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Parses the program args\n *\n * @param argc Passed to main\n * @param @argv Passed to main\n * @param pa program_pargs structure for resulting values\n * @return !=0 for success\n */\nstatic int\nparse_program_args(int argc, char *argv[], struct program_args *pa)\n{\n    int params_ok = 1;\n    int opt;\n\n    pa->input_file = NULL;\n    pa->output_file = NULL;\n    pa->font_name[0] = '\\0';\n    pa->point_size = DEFAULT_POINT_SIZE;\n    pa->max_ucode = DEFAULT_MAX_CHAR;\n    pa->sans10_compatibility = S10_AUTO;\n\n    while ((opt = getopt(argc, argv, \"n:p:m:C:\")) != -1)\n    {\n        switch (opt)\n        {\n            case 'n':\n                g_snprintf(pa->font_name, FV1_MAX_FONT_NAME_SIZE + 1, \"%s\",\n                           optarg);\n                break;\n\n            case 'p':\n                pa->point_size = g_atoi(optarg);\n                break;\n\n            case 'm':\n                pa->max_ucode = parse_ucode_name(optarg);\n                break;\n\n            case 'C':\n                if (toupper(optarg[0]) == 'A')\n                {\n                    pa->sans10_compatibility = S10_AUTO;\n                }\n                else if (g_text2bool(optarg))\n                {\n                    pa->sans10_compatibility = S10_ON;\n                }\n                else\n                {\n                    pa->sans10_compatibility = S10_OFF;\n                }\n                break;\n\n            default:\n                LOG(LOG_LEVEL_ERROR, \"Unrecognised switch '%c'\", (char)opt);\n                params_ok = 0;\n        }\n    }\n\n    if (pa->max_ucode < FV1_MIN_CHAR)\n    {\n        LOG(LOG_LEVEL_ERROR, \"-m argument must be at least %d\",\n            FV1_MIN_CHAR);\n        params_ok = 0;\n    }\n\n    switch (argc - optind)\n    {\n        case 0:\n            LOG(LOG_LEVEL_ERROR, \"No input file specified\");\n            params_ok = 0;\n            break;\n\n        case 1:\n            LOG(LOG_LEVEL_ERROR, \"No output file specified\");\n            params_ok = 0;\n            break;\n        case 2:\n            pa->input_file = argv[optind];\n            pa->output_file = argv[optind + 1];\n            break;\n\n        default:\n            LOG(LOG_LEVEL_ERROR, \"Unexpected arguments after output file\");\n            params_ok = 0;\n    }\n\n    return params_ok;\n}\n\n/**************************************************************************//**\n * Checks whether the specified glyph row is blank\n * @param g Glyph\n * @param row Row number between 0 and g->height - 1\n * @result Boolean\n */\nstatic int\nis_blank_glyph_row(const struct fv1_glyph *g, unsigned int row)\n{\n    if (g->width == 0 || row >= g->height)\n    {\n        return 1;\n    }\n\n    const unsigned int glyph_row_size = ((g->width + 7) / 8);\n    const unsigned char *dataptr = g->data + (row * glyph_row_size);\n    const unsigned int masks[] =\n    { 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };\n\n    /* Check for set pixels in all the leading bytes */\n    unsigned int x;\n    for (x = g->width ; x > 8 ; x -= 8)\n    {\n        if (*dataptr++ != 0)\n        {\n            return 0;\n        }\n    }\n\n    /* Use a single test to check the pixels in the last byte */\n    return ((*dataptr & masks[x - 1]) == 0);\n}\n\n/**************************************************************************//**\n * Returns a string for a freetype2 error\n * @param error Freetype2 error code\n * @param buff Pointer to buffer for error string\n * @param bufflen Length of above\n */\nstatic void\nget_ft_error(FT_Error error, char *buff, unsigned int bufflen)\n{\n    const char *errstr = NULL;\n    unsigned int i;\n    for (i = 0 ; i < (sizeof(ft_errors) / sizeof(ft_errors[0])); ++i)\n    {\n        if (ft_errors[i].err_code == error)\n        {\n            errstr = ft_errors[i].err_msg;\n            break;\n        }\n    }\n\n    if (errstr != NULL)\n    {\n        g_snprintf(buff, bufflen, \"[%s]\", errstr);\n    }\n    else\n    {\n        g_snprintf(buff, bufflen,\n                   \"[errorcode %d (no description)]\", (int)error);\n    }\n}\n\n/**************************************************************************//**\n * Implement sans10 compatibility for a glyph\n *\n * The original Windows font generator made a few different choices for the\n * character x offset than freetype2 does. These are particularly noticeable\n * with a small font.\n *\n * This routine checks the glyph, and implements the original offset size\n * for popular English characters, which are all that the user will probably\n * be displaying with xrdp v0.9.x\n *\n * @param g Glyph to check\n */\nstatic void\nimplement_sans10_compatibility(struct fv1_glyph *g, unsigned int ucode)\n{\n    const unsigned int max_index =\n        sizeof(original_sans10_data) / sizeof(original_sans10_data[0]);\n\n    if (ucode < FV1_MIN_CHAR || ucode >= max_index + FV1_MIN_CHAR)\n    {\n        return;\n    }\n\n    const struct x_dimensions *d =\n            &original_sans10_data[ucode - FV1_MIN_CHAR];\n\n    if (g->offset != d->offset)\n    {\n        if (g->width != d->width)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"Can't set compatibility offset for U+%04X: width %d != %d\",\n                ucode, g->width, d->width);\n        }\n        else if (g->inc_by != d->inc_by)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"Can't set compatibility offset for U+%04X: inc_by %d != %d\",\n                ucode, g->inc_by, d->inc_by);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_INFO,\n                \"Changing compatibility offset for U+%04X: from %d to %d\",\n                ucode, g->offset, d->offset);\n        }\n\n        g->offset = d->offset;\n    }\n}\n\n/**************************************************************************//**\n * Converts a freetype 2 bitmap to a fv1 glyph\n * @param ft_glyph Freetype2 glyph. Must be a monochrome bitmap\n * @param ucode Unicode character for error reporting\n * @param pa Program args\n * @return fv1 glyph, or NULL for error\n */\nstatic struct fv1_glyph *\nconvert_mono_glyph(FT_GlyphSlot ft_glyph, unsigned int ucode,\n                   const struct program_args *pa)\n{\n    short width = ft_glyph->bitmap.width;\n    short height =  ft_glyph->bitmap.rows;\n    struct fv1_glyph *g;\n\n    /* Number of bytes in a glyph row */\n    const unsigned int glyph_row_size = ((width + 7) / 8);\n\n    if ((g = fv1_alloc_glyph(ucode, width, height)) != NULL)\n    {\n        g->baseline = -(ft_glyph->metrics.horiBearingY / 64);\n        g->offset = ft_glyph->metrics.horiBearingX / 64;\n        g->inc_by = ft_glyph->metrics.horiAdvance / 64;\n\n        if (FONT_DATASIZE(g) > 0)\n        {\n            const unsigned char *srcptr = ft_glyph->bitmap.buffer;\n            unsigned char *dstptr = g->data;\n            unsigned int y;\n\n            for (y = 0; y < g->height; ++y)\n            {\n                g_memcpy(dstptr, srcptr, glyph_row_size);\n                dstptr += glyph_row_size;\n                srcptr += ft_glyph->bitmap.pitch;\n            }\n\n            /* Optimise the glyph by removing any blank lines at the bottom\n             * and top */\n            if (g->width > 0)\n            {\n                while (g->height > 0 &&\n                        is_blank_glyph_row(g, g->height - 1))\n                {\n                    --g->height;\n                }\n\n                y = 0;\n                while (y < g->height && is_blank_glyph_row(g, y))\n                {\n                    ++y;\n                }\n\n                if (y > 0)\n                {\n                    g->baseline += y;\n                    g->height -= y;\n                    g_memmove(g->data, g->data + (y * glyph_row_size),\n                              g->height * glyph_row_size);\n                }\n            }\n        }\n\n        if (pa->sans10_compatibility != S10_OFF)\n        {\n            implement_sans10_compatibility(g, ucode);\n        }\n    }\n\n    return g;\n}\n\n/**************************************************************************//**\n * Main\n *\n * @param argc Argument count\n * @param argv Arguments\n */\nint\nmain(int argc, char *argv[])\n{\n    FT_Library library = NULL;   /* handle to library     */\n    FT_Face face = NULL;      /* handle to face object */\n    FT_Error error;\n    struct fv1_glyph *g;\n    struct program_args pa;\n    struct log_config *logging;\n    int rv = 1;\n\n    logging = log_config_init_for_console(LOG_LEVEL_WARNING,\n                                          g_getenv(\"MKFV1_LOG_LEVEL\"));\n    log_start_from_param(logging);\n    log_config_free(logging);\n\n    struct fv1_file *fv1 = fv1_file_create();\n\n    if (fv1 == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Memory allocation failure\");\n    }\n    else if (parse_program_args(argc, argv, &pa))\n    {\n        char errstr[128];\n\n        if ((error = FT_Init_FreeType(&library)) != 0)\n        {\n            get_ft_error(error, errstr, sizeof(errstr));\n            LOG(LOG_LEVEL_ERROR, \"Error initializing freetype library %s\",\n                errstr);\n        }\n        else if ((error = FT_New_Face(library, pa.input_file, 0, &face)) != 0)\n        {\n            get_ft_error(error, errstr, sizeof(errstr));\n            LOG(LOG_LEVEL_ERROR, \"Error loading font file %s %s\",\n                pa.input_file, errstr);\n        }\n        else if ((error = FT_Set_Char_Size(face, 0,\n                                           pa.point_size * 64,\n                                           FV1_DEVICE_DPI, 0)) != 0)\n        {\n            get_ft_error(error, errstr, sizeof(errstr));\n            LOG(LOG_LEVEL_ERROR, \"Error setting point size to %u %s\",\n                pa.point_size, errstr);\n        }\n        else\n        {\n            const char *fname =\n                (pa.font_name[0] != '\\0') ?  pa.font_name :\n                (face->family_name != NULL) ? face->family_name :\n                /* Default */ \"\";\n\n            g_snprintf(fv1->font_name, FV1_MAX_FONT_NAME_SIZE + 1, \"%s\", fname);\n            fv1->point_size = pa.point_size;\n            fv1->body_height = face->size->metrics.height / 64;\n            fv1->min_descender = face->size->metrics.descender / 64;\n\n            if (pa.sans10_compatibility == S10_AUTO)\n            {\n                if (g_strcmp(fv1->font_name, \"DejaVu Sans\") == 0 &&\n                        fv1->point_size == 10)\n                {\n                    pa.sans10_compatibility = S10_ON;\n                }\n                else\n                {\n                    pa.sans10_compatibility = S10_OFF;\n                }\n            }\n\n            unsigned int u;\n            for (u = FV1_MIN_CHAR; u <= pa.max_ucode; ++u)\n            {\n                /* retrieve glyph index from character code */\n                FT_UInt glyph_index = FT_Get_Char_Index(face, u);\n\n                /* load glyph image into the slot (erase previous one) */\n                error = FT_Load_Glyph(face, glyph_index,\n                                      FT_LOAD_RENDER | FT_LOAD_TARGET_MONO);\n                if (error)\n                {\n                    get_ft_error(error, errstr, sizeof(errstr));\n                    LOG(LOG_LEVEL_WARNING,\n                        \"Unable to get bitmap for U+%04X %s\", u, errstr);\n                    g = NULL;\n                }\n                else if (face->glyph->format != FT_GLYPH_FORMAT_BITMAP ||\n                         face->glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO)\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"Internal error; U+%04X was not loaded as a bitmap\",\n                        u);\n                    g = NULL;\n                }\n                else\n                {\n                    g = convert_mono_glyph(face->glyph, u, &pa);\n                }\n                list_add_item(fv1->glyphs, (tintptr)g);\n            }\n\n            rv = fv1_file_save(fv1,  pa.output_file);\n        }\n    }\n\n    FT_Done_FreeType(library);\n    fv1_file_free(fv1);\n    log_end();\n\n    return rv;\n}\n"
  },
  {
    "path": "fontutils/windows/.gitignore",
    "content": "!Makefile\n"
  },
  {
    "path": "fontutils/windows/Makefile",
    "content": "\nOBJS = fontdump.obj os_calls.obj\n\n#CFLAGS = -O2 -I../common\nCFLAGS = -O2 -I../common -DUNICODE -D_UNICODE\nLDFLAGS = -W -efontdump.exe\n\nall: fontdump1\n\nfontdump1: $(OBJS)\n\t$(CC) $(LDFLAGS) $(OBJS)\n\nclean:\n\tdel $(OBJS) fontdump.exe *.tds\n\nos_calls.obj: ../common/os_calls.c\n\t$(CC) $(CFLAGS) -c ../common/os_calls.c\n"
  },
  {
    "path": "fontutils/windows/fontdump.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <windows.h>\n#include <tchar.h>\n#include <stdarg.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#include \"os_calls.h\"\n#include \"arch.h\"\n\nstatic HINSTANCE g_instance = 0;\nstatic HWND g_wnd = 0;\nstatic HWND g_lb = 0;\nstatic HWND g_exit_button = 0;\nstatic HWND g_go_button = 0;\nstatic HWND g_font_list = 0;\nstatic char g_font_name[512] = \"\";\nstatic int g_font_size = 10;\nstatic HFONT g_font = 0;\nstatic int g_running = 0;\n\n#define FONT_DATASIZE(_w, _h) (((_h * ((_w + 7) / 8)) + 3) & ~3)\n\n/*****************************************************************************/\nint\ncheck_messages(void)\n{\n    MSG msg;\n\n    while (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))\n    {\n        GetMessage(&msg, NULL, 0, 0);\n        TranslateMessage(&msg);\n        DispatchMessage(&msg);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nmsg(char *msg1, ...)\n{\n    va_list ap;\n    char text1[512];\n\n    va_start(ap, msg1);\n    vsnprintf(text1, 511, msg1, ap);\n    SendMessageA(g_lb, LB_ADDSTRING, 0, (LPARAM)text1);\n    va_end(ap);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nshow_last_error(void)\n{\n    LPVOID lpMsgBuf = NULL;\n    DWORD len;\n    len = FormatMessageA(\n              FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,\n              NULL, GetLastError(),\n              MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),\n              (LPSTR)&lpMsgBuf, 0, NULL);\n    if (len > 0)\n    {\n        msg(\"GetLastError - %s\", lpMsgBuf);\n        LocalFree(lpMsgBuf);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nfont_dump(void)\n{\n    HDC dc;\n    HDC dc1;\n    RECT rect;\n    HBRUSH brush;\n    HGDIOBJ saved;\n    HBITMAP bitmap;\n    BITMAPINFO bi;\n    char *bits;\n    ABC abc;\n    SIZE sz;\n    char filename[256];\n    TCHAR text[256];\n    char zero1;\n    char *bmtext;\n    int bmtextindex;\n    int fd;\n    int x1;\n    int strlen1;\n    int index1;\n    int index2;\n    int len;\n    int pixel;\n    int red;\n    int green;\n    int blue;\n    int width;\n    int height;\n    int roller;\n    int outlen;\n    tui8 b1;\n    short x2;\n\n    if (g_running)\n    {\n        return 0;\n    }\n\n    g_running = 1;\n    msg(\"starting\");\n    g_font_name[0] = 0;\n    SendMessageA(g_font_list, WM_GETTEXT, 255, (LPARAM)g_font_name);\n\n    if (g_strlen(g_font_name) == 0)\n    {\n        msg(\"error font not set\");\n        g_running = 0;\n        return 1;\n    }\n\n    dc = GetDC(g_wnd);\n    height = -MulDiv(g_font_size, GetDeviceCaps(dc, LOGPIXELSY), 72);\n    g_font = CreateFontA(height, 0, 0, 0, FW_DONTCARE, 0, 0, 0, 0, 0, 0,\n                         0, 0, g_font_name);\n    ReleaseDC(g_wnd, dc);\n\n    if (g_font == 0)\n    {\n        msg(\"error - Font creation failed\");\n    }\n\n    zero1 = 0;\n    g_snprintf(filename, 255, \"%s-%d.fv1\", g_font_name, g_font_size);\n    msg(\"creating file %s\", filename);\n    g_file_delete(filename);\n    fd = g_file_open_rw(filename);\n    g_file_write(fd, \"FNT1\", 4);\n    strlen1 = g_strlen(g_font_name);\n    g_file_write(fd, g_font_name, strlen1);\n    x1 = strlen1;\n\n    while (x1 < 32)\n    {\n        g_file_write(fd, &zero1, 1);\n        x1++;\n    }\n\n    x2 = g_font_size; /* font size */\n    g_file_write(fd, (char *)&x2, 2);\n    x2 = 1; /* style */\n    g_file_write(fd, (char *)&x2, 2);\n    /* pad */\n    index1 = 0;\n\n    while (index1 < 8)\n    {\n        g_file_write(fd, &zero1, 1);\n        index1++;\n    }\n\n    for (x1 = 32; x1 < 0x4e00; x1++)\n    {\n        check_messages();\n        dc = GetWindowDC(g_wnd);\n        saved = SelectObject(dc, g_font);\n\n        if (!GetCharABCWidths(dc, x1, x1, &abc))\n        {\n            show_last_error();\n        }\n\n        text[0] = (TCHAR)x1;\n        text[1] = 0;\n\n        if (!GetTextExtentPoint32(dc, text, 1, &sz))\n        {\n            show_last_error();\n        }\n\n        SelectObject(dc, saved);\n        ReleaseDC(g_wnd, dc);\n\n        if ((sz.cx > 0) && (sz.cy > 0))\n        {\n            dc = GetWindowDC(g_wnd);\n            saved = SelectObject(dc, g_font);\n            SetBkColor(dc, RGB(255, 255, 255));\n\n            if (!ExtTextOut(dc, 50, 50, ETO_OPAQUE, 0, text, 1, 0))\n            {\n                show_last_error();\n            }\n\n            SelectObject(dc, saved);\n            ReleaseDC(g_wnd, dc);\n            Sleep(10);\n            /* width */\n            x2 = abc.abcB;\n            g_file_write(fd, (char *)&x2, 2);\n            /* height */\n            x2 = sz.cy;\n            g_file_write(fd, (char *)&x2, 2);\n            /* baseline */\n            x2 = -sz.cy;\n            g_file_write(fd, (char *)&x2, 2);\n            /* offset */\n            x2 = abc.abcA;\n            g_file_write(fd, (char *)&x2, 2);\n            /* incby */\n            x2 = sz.cx;\n            g_file_write(fd, (char *)&x2, 2);\n            /* pad */\n            index1 = 0;\n\n            while (index1 < 6)\n            {\n                g_file_write(fd, &zero1, 1);\n                index1++;\n            }\n\n            dc = GetWindowDC(g_wnd);\n            rect.left = 50 + abc.abcA;\n            rect.top = 50;\n            rect.right = rect.left + abc.abcB;\n            rect.bottom = rect.top + sz.cy;\n            memset(&bi, 0, sizeof(bi));\n            width = (abc.abcB + 7) & (~7);\n            height = sz.cy;\n            bi.bmiHeader.biSize = sizeof(bi.bmiHeader);\n            bi.bmiHeader.biWidth = width;\n            bi.bmiHeader.biHeight = height;\n            bi.bmiHeader.biPlanes = 1;\n            bi.bmiHeader.biBitCount = 32;\n            bitmap = CreateDIBSection(dc, &bi, DIB_RGB_COLORS, (void *)&bits, 0, 0);\n\n            if (bitmap == 0)\n            {\n                msg(\"error - CreateDIBSection failed\");\n            }\n            else\n            {\n                memset(bits, 0, width * height * 4);\n                dc1 = CreateCompatibleDC(dc);\n                SelectObject(dc1, bitmap);\n\n                if (!BitBlt(dc1, 0, 0, width, height, dc, rect.left, rect.top, SRCCOPY))\n                {\n                    show_last_error();\n                }\n\n                bmtext = (char *)g_malloc(width * height + 16, 1);\n                bmtextindex = 0;\n\n                for (index1 = (height - 1); index1 >= 0; index1--)\n                {\n                    for (index2 = 0; index2 < width; index2++)\n                    {\n                        pixel = ((int *)bits)[index1 * width + index2];\n                        red = (pixel >> 16) & 0xff;\n                        green = (pixel >> 8) & 0xff;\n                        blue = (pixel >> 0) & 0xff;\n\n                        if (red == 0 && green == 0 && blue == 0)\n                        {\n                            bmtext[bmtextindex] = '1';\n                            bmtextindex++;\n                        }\n                        else\n                        {\n                            bmtext[bmtextindex] = '0';\n                            bmtextindex++;\n                        }\n                    }\n                }\n\n                outlen = 0;\n                b1 = 0;\n                roller = 0;\n                len = g_strlen(bmtext);\n\n                for (index2 = 0; index2 < len; index2++)\n                {\n                    if (bmtext[index2] == '1')\n                    {\n                        switch (roller)\n                        {\n                            case 0:\n                                b1 = b1 | 0x80;\n                                break;\n                            case 1:\n                                b1 = b1 | 0x40;\n                                break;\n                            case 2:\n                                b1 = b1 | 0x20;\n                                break;\n                            case 3:\n                                b1 = b1 | 0x10;\n                                break;\n                            case 4:\n                                b1 = b1 | 0x08;\n                                break;\n                            case 5:\n                                b1 = b1 | 0x04;\n                                break;\n                            case 6:\n                                b1 = b1 | 0x02;\n                                break;\n                            case 7:\n                                b1 = b1 | 0x01;\n                                break;\n                        }\n                    }\n\n                    roller++;\n\n                    if (roller == 8)\n                    {\n                        roller = 0;\n                        g_file_write(fd, &b1, 1);\n                        outlen++;\n                        b1 = 0;\n                    }\n                }\n\n                while ((outlen % 4) != 0)\n                {\n                    g_file_write(fd, &zero1, 1);\n                    outlen++;\n                }\n\n                free(bmtext);\n                DeleteDC(dc1);\n                DeleteObject(bitmap);\n            }\n\n            if (sz.cx != (long)(abc.abcA + abc.abcB + abc.abcC))\n            {\n                msg(\"error - width not right 1\");\n            }\n\n            brush = CreateSolidBrush(RGB(255, 255, 255));\n            FillRect(dc, &rect, brush);\n            DeleteObject(brush);\n            ReleaseDC(g_wnd, dc);\n        }\n        else\n        {\n            /* write out a blank glyph here */\n            /* width */\n            x2 = 1;\n            g_file_write(fd, (char *)&x2, 2);\n            /* height */\n            x2 = 1;\n            g_file_write(fd, (char *)&x2, 2);\n            /* baseline */\n            x2 = 0;\n            g_file_write(fd, (char *)&x2, 2);\n            /* offset */\n            x2 = 0;\n            g_file_write(fd, (char *)&x2, 2);\n            /* incby */\n            x2 = 1;\n            g_file_write(fd, (char *)&x2, 2);\n            /* pad */\n            index1 = 0;\n\n            while (index1 < 6)\n            {\n                g_file_write(fd, &zero1, 1);\n                index1++;\n            }\n\n            /* blank bitmap */\n            index1 = 0;\n\n            while (index1 < 4)\n            {\n                g_file_write(fd, &zero1, 1);\n                index1++;\n            }\n        }\n    }\n\n    g_file_close(fd);\n    msg(\"done\");\n    g_running = 0;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic LRESULT CALLBACK\nwnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\n{\n    PAINTSTRUCT ps;\n    HBRUSH brush;\n    RECT rect;\n\n    switch (message)\n    {\n        case WM_PAINT:\n            BeginPaint(hWnd, &ps);\n            brush = CreateSolidBrush(RGB(255, 255, 255));\n            rect = ps.rcPaint;\n            FillRect(ps.hdc, &rect, brush);\n            DeleteObject(brush);\n            EndPaint(hWnd, &ps);\n            break;\n        case WM_CLOSE:\n            DestroyWindow(g_wnd);\n            g_wnd = 0;\n            break;\n        case WM_DESTROY:\n            PostQuitMessage(0);\n            break;\n        case WM_TIMER:\n            KillTimer(g_wnd, 1);\n            font_dump();\n            break;\n        case WM_COMMAND:\n\n            if ((HWND)lParam == g_exit_button)\n            {\n                PostMessage(g_wnd, WM_CLOSE, 0, 0);\n            }\n            else if ((HWND)lParam == g_go_button)\n            {\n                while (SendMessage(g_lb, LB_GETCOUNT, 0, 0) > 0)\n                {\n                    SendMessage(g_lb, LB_DELETESTRING, 0, 0);\n                }\n\n                SetTimer(g_wnd, 1, 1000, 0);\n            }\n\n            break;\n    }\n\n    return DefWindowProc(hWnd, message, wParam, lParam);\n}\n\n/*****************************************************************************/\nstatic int\ncreate_window(void)\n{\n    WNDCLASS wc;\n    DWORD style;\n    int left;\n    int top;\n\n    ZeroMemory(&wc, sizeof(wc));\n    wc.lpfnWndProc = wnd_proc; /* points to window procedure */\n    /* name of window class */\n    wc.lpszClassName = _T(\"fontdump\");\n    wc.hCursor = LoadCursor(0, IDC_ARROW);\n\n    /* Register the window class. */\n    if (!RegisterClass(&wc))\n    {\n        return 0; /* Failed to register window class */\n    }\n\n    style = WS_OVERLAPPED | WS_CAPTION | WS_POPUP | WS_MINIMIZEBOX |\n            WS_SYSMENU | WS_SIZEBOX | WS_MAXIMIZEBOX;\n    left = GetSystemMetrics(SM_CXSCREEN) / 2 - 640 / 2;\n    top = GetSystemMetrics(SM_CYSCREEN) / 2 - 480 / 2;\n    g_wnd = CreateWindow(wc.lpszClassName, _T(\"fontdump\"),\n                         style, left, top, 640, 480,\n                         (HWND) NULL, (HMENU) NULL, g_instance,\n                         (LPVOID) NULL);\n    style = WS_CHILD | WS_VISIBLE | WS_BORDER;\n    g_lb = CreateWindow(_T(\"LISTBOX\"), _T(\"LISTBOX1\"), style,\n                        200, 10, 400, 400, g_wnd, 0, g_instance, 0);\n    style = WS_CHILD | WS_VISIBLE;\n    g_exit_button = CreateWindow(_T(\"BUTTON\"), _T(\"Exit\"), style,\n                                 540, 410, 75, 25, g_wnd, 0, g_instance, 0);\n    g_go_button = CreateWindow(_T(\"BUTTON\"), _T(\"Go\"), style,\n                               440, 410, 75, 25, g_wnd, 0, g_instance, 0);\n    style = WS_CHILD | WS_VISIBLE | CBS_DROPDOWN;\n    g_font_list = CreateWindow(_T(\"COMBOBOX\"), _T(\"COMBOBOX1\"), style,\n                               50, 250, 125, 125, g_wnd, 0, g_instance, 0);\n    ShowWindow(g_wnd, SW_SHOWNORMAL);\n    PostMessage(g_wnd, WM_SETFONT, (WPARAM)g_font, 0);\n    SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)\"Tahoma\");\n    SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)\"DejaVu Serif\");\n    SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)\"DejaVu Sans\");\n    SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)\"Arial\");\n    SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)\"Comic Sans MS\");\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nmain_loop(void)\n{\n    MSG msg;\n\n    while (GetMessage(&msg, NULL, 0, 0))\n    {\n        TranslateMessage(&msg);\n        DispatchMessage(&msg);\n    }\n\n    return (int)(msg.wParam);\n}\n\n/*****************************************************************************/\nint WINAPI\nWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,\n        LPSTR lpCmdLine, int nCmdShow)\n{\n    g_instance = hInstance;\n    create_window();\n    return main_loop();\n}\n"
  },
  {
    "path": "genkeymap/Makefile.am",
    "content": "EXTRA_DIST = \\\n  dump-keymaps.sh \\\n  readme.txt\n\nAM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -I$(top_srcdir)/common\n\nAM_CFLAGS = $(X_CFLAGS)\n\nbin_PROGRAMS = \\\n  xrdp-genkeymap\n\nxrdp_genkeymap_SOURCES = genkeymap.c\n\nxrdp_genkeymap_LDFLAGS = \\\n  $(X_LIBS)\n\nxrdp_genkeymap_LDADD = \\\n  $(top_builddir)/common/libcommon.la \\\n  $(X_PRE_LIBS) -lxkbfile -lX11 $(X_EXTRA_LIBS)\n"
  },
  {
    "path": "genkeymap/dump-keymaps.sh",
    "content": "#!/bin/sh\n\n# Use evdev rules to obtain the mappings\nXKB_RULES=evdev\n\n# -----------------------------------------------------------------------------\n# K B G E N\n#\n# Generates a keyboard mapping\n# $1 - LCID (See [MS-LCID])\n# $2 - Language tag (See [MS-LCID])\n# $3 - Current operating system\n# $4.. Arguments to setxkbmap to select the required keyboard\n# -----------------------------------------------------------------------------\nkbgen()\n{\n    file=$(printf \"../instfiles/km-%08s.toml\" \"$1\" | tr ' ' '0')\n    desc=\"$2\"\n    os=\"$3\"\n    shift 3\n    if ! setxkbmap \"$@\"; then\n        echo \"Failed to run setxkbmap $*\" >&2\n        return 1\n    fi\n    ./xrdp-genkeymap \\\n        -c \"Description: $desc\" \\\n        -c \"Operating system: $os\" \\\n        \"$file\"\n}\n\n# -----------------------------------------------------------------------------\n# M A I N\n# -----------------------------------------------------------------------------\n# Run the keymap extraction in a clean X session\nif [ \"$1\" != _IN_XVFB_SESSION_ ]; then\n    # All commands available?\n    ok=1\n    for cmd in setxkbmap xvfb-run xauth; do\n        if ! command -v $cmd >/dev/null\n        then\n          echo \"Error. $cmd not found\" >&2\n          ok=\n        fi\n    done\n    if [ -z \"$ok\" ]; then\n        exit 1\n    fi\n\n    xvfb-run --auto-servernum --server-args=\"-noreset\" \"$0\" _IN_XVFB_SESSION_\n    exit $?\nfi\n\nOLD_SETTINGS=$(setxkbmap -query -verbose 4 | sed \"s/^\\([a-z]\\+\\):\\s*\\(.*\\)$/-\\1 \\2/;s/^-options/-option \\\"\\\" -option/;s/,/ -option /g\" | xargs -d \\\\n)\n\nsetxkbmap -rules \"$XKB_RULES\"\n\n# Assign NumLock to mod2\nxmodmap -e \"clear mod2\" -e \"add mod2 = Num_Lock\"\n\n# Find the operating system\nif command -v hostnamectl >/dev/null; then\n    os=$(hostnamectl status | sed -ne 's/^i *Operating[^:]*: *//p')\nfi\nif [ -z \"$os\" ] && command -v lsb_release -v >/dev/null; then\n    os=$(lsb_release --description --short)\nfi\nif [ -z \"$os\" ]; then\n    os=\"Unknown\"\nfi\n\nkbgen 0405 \"cs-CZ\"        \"$os\" -model pc105 -layout cz\nkbgen 0406 \"da-DK\"        \"$os\" -model pc105 -layout dk\nkbgen 0407 \"de-DE\"        \"$os\" -model pc104 -layout de\nkbgen 0409 \"en-US\"        \"$os\" -model pc104 -layout us\nkbgen 10409 \"en-US\"       \"$os\" -model pc104 -layout us -variant dvorak\nkbgen 60409 \"en-US\"       \"$os\" -model pc104 -layout us -variant colemak\nkbgen 040a \"es-ES_tradnl\" \"$os\" -model pc105 -layout es\nkbgen 040b \"fi-FI\"        \"$os\" -model pc105 -layout 'fi'\nkbgen 040c \"fr-FR\"        \"$os\" -model pc105 -layout fr\nkbgen 040e \"hu-HU\"        \"$os\" -model pc105 -layout hu\nkbgen 0410 \"it-IT\"        \"$os\" -model pc104 -layout it\nkbgen 0411 \"ja-JP\"        \"$os\" -model pc105 -layout jp -variant OADG109A\nkbgen 0412 \"ko-KR\"        \"$os\" -model pc105 -layout kr\nkbgen 0414 \"nb-NO\"        \"$os\" -model pc105 -layout no\nkbgen 0415 \"pl-PL\"        \"$os\" -model pc104 -layout pl\nkbgen 0416 \"pt-BR\"        \"$os\" -model pc105 -layout br\nkbgen 0419 \"ru-RU\"        \"$os\" -model pc104 -layout ru\nkbgen 041d \"sv-SE\"        \"$os\" -model pc104 -layout se\nkbgen 0424 \"sl-SI\"        \"$os\" -model pc104 -layout si\nkbgen 0426 \"lv-LV\"        \"$os\" -model pc104 -layout lv -variant ergonomic\nkbgen 10426 \"lv-LV\"       \"$os\" -model pc104 -layout lv\n# 20426 Latvian(Standard) is symlinked to 10426 Latvian(QWERTY) elsewhere\nkbgen 0807 \"de-CH\"        \"$os\" -model pc105 -layout ch\nkbgen 0809 \"en-GB\"        \"$os\" -model pc105 -layout gb\nkbgen 080a \"es-MX\"        \"$os\" -model pc105 -layout latam\nkbgen 080c \"fr-BE\"        \"$os\" -model pc105 -layout be -variant oss\nkbgen 0813 \"nl-BE\"        \"$os\" -model pc105 -layout be\nkbgen 0816 \"pt-PT\"        \"$os\" -model pc104 -layout pt\nkbgen 100c \"fr-CH\"        \"$os\" -model pc105 -layout ch -variant fr\n\n# Put keyboards which change options below the ones that don't to\n# prevent unexpected things happening to keypads, etc\nkbgen 19360409 \"en-US\"    \"$os\" -model pc105 -layout us -variant dvp \\\n    -option \"\" -option compose:102 -option caps:shift -option numpad:sg \\\n    -option numpad:shift3 -option keypad:hex -option keypad:atm \\\n    -option kpdl:semi -option lv3:ralt_alt\n# set back to entry settings\n# shellcheck disable=SC2086\nsetxkbmap ${OLD_SETTINGS}\n"
  },
  {
    "path": "genkeymap/genkeymap.c",
    "content": "/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */\n/*\n * genkeymap.c\n * Copyright (C) Ádám Wallner 2008 <wallner@bitbaro.hu>\n *\n * You may redistribute it and/or modify it under the terms of the\n * GNU General Public License, as published by the Free Software\n * Foundation; either version 2 of the License, or (at your option)\n * any later version.\n *\n * main.cc is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n * See the GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with main.cc.  If not, write to:\n * The Free Software Foundation, Inc.,\n * 51 Franklin Street, Fifth Floor\n * Boston, MA  02110-1301, USA\n\n  Updated Jay Sorg 2009\n\n cs Czech 0x405\n de German 0x407\n en-us US English 0x409\n fr French 0x40c\n it Italian 0x410\n br Portuguese (Brazil) 0x416\n ru Russian 0x419\n se Swedish 0x41d\n en-uk UK English 0x809\n*/\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <X11/Xlib.h>\n#include <X11/Xutil.h>\n#include <X11/XKBlib.h>\n#include <X11/extensions/XKBrules.h>\n#include <locale.h>\n#include <unistd.h>\n\n#include \"scancode.h\"\n#include \"xrdp_constants.h\"\n\n// cppcheck doesn't always set this macro to something in double-quotes\n#if defined(__cppcheck__)\n#undef PACKAGE_VERSION\n#endif\n\n#if !defined(PACKAGE_VERSION)\n#define PACKAGE_VERSION \"???\"\n#endif\n\n#define NUM_STATES 9\n\n#define KEYMAP_FILE_FORMAT_VERSION \"2\"\n\n// Scancodes affected by numlock\n#define IS_KEYPAD_SCANCODE(s) \\\n    ((s) >= SCANCODE_MIN_NUMLOCK && (s) <= SCANCODE_MAX_NUMLOCK)\n\n#define MAX_COMMENTS 10\n\n/**\n * Contains info about the current keyboard setting\n */\nstruct kbd_info\n{\n    char *keycode_set; ///< See 'setxkbmap -v'\n    char *rules; ///< See 'setxkbmap -query'\n    char *model; ///< See 'setxkbmap -query'\n    char *layout; ///< See 'setxkbmap -query'\n    char *variant; ///< See 'setxkbmap -query'\n    char *options; ///< See 'setxkbmap -query' (comma separated)\n};\n\n/*****************************************************************************/\n/**\n * Print brief info about program usage and exit\n * @param programname Unqualified name of program\n * @param status Exit status\n */\nstatic void\nusage(const char *programname, int status)\n{\n    fprintf(stderr, \"Usage: %s [ -k keycode_set] [-c comment] [-c comment...]\"\n            \" out_filename\\n\", programname);\n    fprintf(stderr, \"Example: %s -r evdev -c \\\"en-US pc104 keyboard\\\" \", programname);\n    fprintf(stderr, XRDP_CFG_PATH \"/km-00000409.toml\\n\");\n    exit(status);\n}\n\n/*****************************************************************************/\n/**\n * Free a kbd_info struct\n * @param kbd_info struct to free. May be incomplete or NULL\n */\nstatic void\nfree_kbd_info(struct kbd_info *kbd_info)\n{\n    if (kbd_info != NULL)\n    {\n        free(kbd_info->keycode_set);\n        free(kbd_info->rules);\n        free(kbd_info->model);\n        free(kbd_info->layout);\n        free(kbd_info->variant);\n        free(kbd_info->options);\n        free(kbd_info);\n    }\n}\n\n/*****************************************************************************/\n/**\n * Queries the X server to get information about the current keyboard\n * @param dpy X11 Display\n * @param programname Unqualified name of program\n * @return kbd_info struct, or NULL\n *\n * The structure may be incomplete if some data could not be obtained\n */\nstatic struct kbd_info *\nget_kbd_info(Display *dpy, const char *programname)\n{\n    struct kbd_info *kbd_info;\n    char *rules;\n    XkbRF_VarDefsRec vd;\n    XkbDescPtr kbdesc = NULL;\n\n    if ((kbd_info = (struct kbd_info *)malloc( sizeof(*kbd_info))) == NULL)\n    {\n        fprintf(stderr, \"%s: Out of memory\\n\", programname);\n    }\n    else if ((kbdesc = XkbAllocKeyboard()) == NULL)\n    {\n        fprintf(stderr, \"%s:  unable to allocate keyboard desc\\n\",\n                programname);\n        free_kbd_info(kbd_info);\n        kbd_info = NULL;\n    }\n    else if (XkbGetNames(dpy, XkbKeycodesNameMask, kbdesc) != Success)\n    {\n        fprintf(stderr, \"%s:  unable to obtain keycode name for keyboard\\n\",\n                programname);\n        free_kbd_info(kbd_info);\n        kbd_info = NULL;\n    }\n    else\n    {\n        char *symatom = XGetAtomName(dpy, kbdesc->names->keycodes);\n        kbd_info->keycode_set = strdup(symatom);\n        XFree(symatom);\n\n        if (XkbRF_GetNamesProp(dpy, &rules, &vd) == 0 || rules == NULL)\n        {\n            fprintf(stderr, \"%s: Couldn't interpret %s property\\n\",\n                    programname, _XKB_RF_NAMES_PROP_ATOM);\n            kbd_info->rules = NULL;\n            kbd_info->model = NULL;\n            kbd_info->layout = NULL;\n            kbd_info->variant = NULL;\n            kbd_info->options = NULL;\n        }\n        else\n        {\n            kbd_info->rules = rules;\n            kbd_info->model = vd.model;\n            kbd_info->layout = vd.layout;\n            kbd_info->variant = vd.variant;\n            kbd_info->options = vd.options;\n        }\n    }\n\n    if (kbdesc != NULL)\n    {\n        XkbFreeKeyboard(kbdesc, 0, True);\n    }\n\n    return kbd_info;\n}\n\n/*****************************************************************************/\n/**\n * Outputs a comment containing the last setxkbmap command\n *\n * @param outf Output file\n * @param kbd_info Keyboard info struct\n *\n */\nstatic void\noutput_setxkbmap_comment(FILE *outf, const struct kbd_info *kbd_info)\n{\n    if (kbd_info->model != NULL || kbd_info->layout != NULL ||\n            kbd_info->variant != NULL || kbd_info->options != NULL)\n    {\n        fprintf(outf, \"# setxkbmap -rules %s\", kbd_info->rules);\n        if (kbd_info->model != NULL)\n        {\n            fprintf(outf, \" -model %s\", kbd_info->model);\n        }\n        if (kbd_info->layout != NULL)\n        {\n            fprintf(outf, \" -layout %s\", kbd_info->layout);\n        }\n        if (kbd_info->variant != NULL)\n        {\n            fprintf(outf, \" -variant %s\", kbd_info->variant);\n        }\n        if (kbd_info->options != NULL)\n        {\n            // Options is comma-separated, but to achieve the same effect\n            // with the command we need to use multiple '-option' args\n            char *optionstr = strdup(kbd_info->options);\n            if (optionstr != NULL)\n            {\n                char *p = strtok(optionstr, \",\");\n                fprintf(outf, \" -option \\\"\\\"\");\n                while (p != NULL)\n                {\n                    fprintf(outf, \" -option %s\", p);\n                    p = strtok(NULL, \",\");\n                }\n                free(optionstr);\n            }\n        }\n        putc('\\n', outf);\n    }\n}\n\n/*****************************************************************************/\n/**\n * Output a section of the keymap file\n * @param outf Output file\n * @param dpy X display\n * @param section_name name Section name (e.g. 'shift')\n * @param event_state Modifier state needed for XKeyPressedEvent\n */\nstatic void\noutput_file_section(FILE *outf,\n                    Display *dpy,\n                    const char *section_name,\n                    unsigned int event_state)\n{\n    XKeyPressedEvent e =\n    {\n        .type = KeyPress,\n        .serial = 16,\n        .send_event = True,\n        .display = dpy,\n        .state = event_state,\n        .same_screen = True\n    };\n    int char_count;\n    int nbytes = 0;\n    int unicode;\n    KeySym ks;\n    const char *ksstr;\n    unsigned short scancode;\n    unsigned int iter = 0;\n    char text[256];\n    wchar_t wtext[256];\n\n    int is_numlock_section = (strcmp(section_name, \"numlock\") == 0);\n\n    fprintf(outf, \"\\n[%s]\\n\", section_name);\n\n    while ((scancode = scancode_get_next(&iter)) != 0)\n    {\n        // Numlock state table can be very small\n        if (is_numlock_section && !IS_KEYPAD_SCANCODE(scancode))\n        {\n            continue;\n        }\n\n        e.keycode = scancode_to_x11_keycode(scancode);\n        nbytes = XLookupString(&e, text, 255, &ks, NULL);\n        if (ks == NoSymbol)\n        {\n            continue;\n        }\n        ksstr = XKeysymToString(ks);\n        if (ksstr == NULL)\n        {\n            continue;\n        }\n        text[nbytes] = 0;\n        char_count = mbstowcs(wtext, text, 255);\n        unicode = 0;\n\n        if (char_count == 1)\n        {\n            unicode = wtext[0];\n        }\n\n        if (scancode > 0x1ff)\n        {\n            fputs(\"E1_\", outf);\n        }\n        else if (scancode > 0xff)\n        {\n            fputs(\"E0_\", outf);\n        }\n        fprintf(outf, \"%02X=\\\"%d\", (scancode & 0xff), (int)ks);\n        if (unicode != 0)\n        {\n            fprintf(outf, \":U+%04X\", unicode);\n        }\n        fprintf(outf, \"\\\"  # %s\\n\", ksstr);\n    }\n}\n\n\n/*****************************************************************************/\n/**\n * Determine is caps-lock is supported. Some layouts (e.g. Colemak) do not\n * support this key.\n *\n * @param dpy X display\n * @return boolean\n */\nstatic int\nis_caps_lock_supported(Display *dpy)\n{\n    char dummy[4];\n    KeySym ks;\n    XKeyPressedEvent e =\n    {\n        .type = KeyPress,\n        .serial = 16,\n        .send_event = True,\n        .display = dpy,\n        .state = 0,\n        .keycode = scancode_to_x11_keycode(SCANCODE_CAPS_KEY),\n        .same_screen = True\n    };\n\n    (void)XLookupString(&e, dummy, sizeof(dummy), &ks, NULL);\n    return (ks == XK_Caps_Lock || ks == XK_Eisu_toggle);\n}\n\n/*****************************************************************************/\n/**\n * Main\n * @param argc Argument count\n * @param argv Pointers to arguments\n * @return 0 for success\n */\nint main(int argc, char **argv)\n{\n    const char *programname;\n    int opt;\n    char *displayname = NULL;\n    char *outfname;\n    const char *sections[NUM_STATES] =\n    {\n        \"noshift\", \"shift\", \"altgr\", \"shiftaltgr\",\n        \"capslock\", \"capslockaltgr\", \"shiftcapslock\", \"shiftcapslockaltgr\",\n        \"numlock\"\n    };\n    const int states[NUM_STATES] = {0, 1, 0x80, 0x81, 2, 0x82, 3, 0x83, 0x10};\n    int idx;\n    Display *dpy = NULL;\n    FILE *outf = NULL;\n    const char *comment[MAX_COMMENTS] = {0};\n    int comment_count = 0;\n    const char *keycode_set = NULL;\n    struct kbd_info *kbd_info = NULL;\n    int status = 1;\n    int caps_lock_supported;\n\n    setlocale(LC_CTYPE, \"\");\n    if (strrchr(argv[0], '/') != NULL)\n    {\n        programname = strrchr(argv[0], '/') + 1;\n    }\n    else\n    {\n        programname = argv[0];\n    }\n\n    while ((opt = getopt(argc, argv, \"c:k:\")) != -1)\n    {\n        switch (opt)\n        {\n            case 'c':\n                if (comment_count < MAX_COMMENTS)\n                {\n                    comment[comment_count++] = optarg;\n                }\n                break;\n\n            case 'k':\n                keycode_set = optarg;\n                break;\n\n            default: /* '?' */\n                usage(programname, 1);\n        }\n    }\n\n    if ((optind + 1) != argc)\n    {\n        usage(programname, 1);\n    }\n\n    outfname = argv[optind];\n\n    dpy = XOpenDisplay(displayname);\n    if (!dpy)\n    {\n        fprintf(stderr, \"%s:  unable to open display '%s'\\n\",\n                programname, XDisplayName(displayname));\n        goto finish;\n    }\n\n    if ((kbd_info = get_kbd_info(dpy, programname)) == 0)\n    {\n        // An error has already been logged\n        goto finish;\n    }\n\n    // If the keycode set isn't specified, use the one returned\n    // by the XKB extension\n    if (keycode_set == NULL)\n    {\n        keycode_set = kbd_info->keycode_set;\n    }\n\n    if (scancode_set_keycode_set(keycode_set) != 0)\n    {\n        fprintf(stderr, \"%s: keycode set '%s' is not recognised\\n\",\n                programname, keycode_set);\n        goto finish;\n    }\n\n    if ((outf = fopen(outfname, \"w\")) == NULL)\n    {\n        fprintf(stderr, \"%s:  unable to create file '%s'\\n\",\n                programname, outfname);\n        goto finish;\n    }\n\n    caps_lock_supported = is_caps_lock_supported(dpy);\n\n    fprintf(outf, \"# Created by %s V\" PACKAGE_VERSION\n            \"\\n# Key code set: %s\\n\",\n            programname, keycode_set);\n\n    output_setxkbmap_comment(outf, kbd_info);\n\n    for (idx = 0; idx < comment_count; ++idx)\n    {\n        fprintf(outf, \"# %s\\n\", comment[idx]);\n    }\n\n    fprintf(outf, \"\\n[General]\\nversion=\" KEYMAP_FILE_FORMAT_VERSION \"\\n\");\n    fprintf(outf, \"caps_lock_supported=%s\\n\",\n            (caps_lock_supported) ? \"true\" : \"false\");\n\n    for (idx = 0; idx < NUM_STATES; idx++) /* Sections and states */\n    {\n        int mod_state =  states[idx];\n        if (!caps_lock_supported && ((mod_state & 2) != 0))\n        {\n            // Skip this section as it's for caps lock\n            continue;\n        }\n        output_file_section(outf, dpy, sections[idx], mod_state);\n    }\n\n    status = 0; // Successful run\n\nfinish:\n    free_kbd_info(kbd_info);\n    if (dpy != NULL)\n    {\n        XCloseDisplay(dpy);\n    }\n    if (outf != NULL)\n    {\n        fclose(outf);\n    }\n    return status;\n}\n"
  },
  {
    "path": "genkeymap/readme.txt",
    "content": "Keymap file description\n-----------------------\n\nThe keymap files are used by the xrdp login screen, and also when\nsending keyboard input to a VNC server.\n\nThe names of the files are of the format;\n\nkm-xxxxxxxx.toml\n\nwhere the xxxxxxxx is replaced by the hex number of the layout of interest.\n\nThe contents of the files are documented in xrdp-km.toml(5)\n\nSee also xrdp-genkeymap(8) which describes the utility used to\ngenerate these files.\n\nCreating a new file\n-------------------\n\nTo create a new file:-\n1) Start an X server\n2) Use the 'setxkbmap' command to get the keyboard configured\n   for the X server.\n3) Run the 'xrdp-genkeymap' command to extract the keyboard\n   mappings\n\n   Example: ./xrdp-genkeymap ./km-00000409.toml\n\n4) Copy the generated file to /etc/xrdp/\n\nUsing the X server of your current session may not be a good idea, as\nsession and window managers can interfere with key bindings. A good option\nis to use an 'Xvfb' dummy X server to do this.\n\nGetting a file added to xrdp\n----------------------------\n\nThe file dump-keymaps.sh in this directory is used to auto-generate\nall keymap files. It runs on Linux currently, but will generate\nkeymap files suitable for any xrdp platform.\n\n1) Add a line towards the end of this file which causes your mapping to\n   be generated. Use the other lines in this file as a guide.\n2) Run the dump-keymaps.sh script to generate a new file in\n   instfiles/\n3) Add your mapping to the list in instfiless/Makefile.am\n4) Submit a pull request to the project containing the above three\n   changes.\n"
  },
  {
    "path": "instfiles/Makefile.am",
    "content": "EXTRA_DIST = \\\n   keymap-names.txt \\\n   xrdp-sesman.service.in \\\n   xrdp.service.in\n\n#\n# substitute directories in service file\n#\nCLEANFILES= \\\n  xrdp-sesman.service \\\n  xrdp.service\n\nSUBST_VARS = sed \\\n   -e 's|@sbindir[@]|$(sbindir)|g' \\\n   -e 's|@sysconfdir[@]|$(sysconfdir)|g' \\\n   -e 's|@sysconfsubdir[@]|$(sysconfsubdir)|g' \\\n   -e 's|@localstatedir[@]|$(localstatedir)|g'\n\nsubst_verbose = $(subst_verbose_@AM_V@)\nsubst_verbose_ = $(subst_verbose_@AM_DEFAULT_V@)\nsubst_verbose_0 = @echo \"  SUBST    $@\";\n\nSUFFIXES = .in\n.in:\n\t$(subst_verbose)$(SUBST_VARS) $< > $@\n\n#\n# files for all platforms\n#\nstartscriptdir=$(sysconfdir)/$(sysconfsubdir)\n\ndist_startscript_DATA = \\\n  km-00000405.toml \\\n  km-00000406.toml \\\n  km-00000407.toml \\\n  km-00000409.toml \\\n  km-0000040a.toml \\\n  km-0000040b.toml \\\n  km-0000040c.toml \\\n  km-0000040e.toml \\\n  km-00000410.toml \\\n  km-00000411.toml \\\n  km-00000412.toml \\\n  km-00000414.toml \\\n  km-00000415.toml \\\n  km-00000416.toml \\\n  km-00000419.toml \\\n  km-0000041d.toml \\\n  km-00000424.toml \\\n  km-00000426.toml \\\n  km-00010426.toml \\\n  km-00000807.toml \\\n  km-00000809.toml \\\n  km-0000080a.toml \\\n  km-0000080c.toml \\\n  km-00000813.toml \\\n  km-00000816.toml \\\n  km-0000100c.toml \\\n  km-00010409.toml \\\n  km-00060409.toml \\\n  km-19360409.toml\n\n#\n# platform specific files\n#\nSUBDIRS =\nif LINUX\nSUBDIRS += \\\n  pam.d \\\n  pulse\nif HAVE_SYSTEMD\nsystemdsystemunit_DATA = \\\n  xrdp-sesman.service \\\n  xrdp.service\nelse\nSUBDIRS += \\\n  default \\\n  init.d\nendif # HAVE_SYSTEMD\nendif # LINUX\n\nif FREEBSD\nSUBDIRS += \\\n  pam.d \\\n  rc.d \\\n  pulse\nendif\n\nif MACOS\nSUBDIRS += pam.d\nendif\n\n#\n# install-data-hook\n# TODO: subst these directories as well as service files\n#\n# must be tabs below\n# Note the section to soft-link keyboard files which share a definition\ninstall-data-hook:\nif LINUX\n\tif [ -f $(DESTDIR)$(sysconfdir)/init.d/xrdp ]; then \\\n\t\tsed -i 's|__BASE__|$(prefix)|' $(DESTDIR)$(sysconfdir)/init.d/xrdp; \\\n\tfi\nendif\nif FREEBSD\n\tsed -e 's|%%PREFIX%%|$(prefix)|g' \\\n\t    -e 's|%%LOCALSTATEDIR%%|$(localstatedir)|g' \\\n\t\t-i '' \\\n\t\t$(DESTDIR)$(sysconfdir)/rc.d/xrdp \\\n\t\t$(DESTDIR)$(sysconfdir)/rc.d/xrdp-sesman\nendif\n\t(cd $(DESTDIR)${startscriptdir} && \\\n\t\t$(LN_S) km-00010426.toml km-00020426.toml)\n"
  },
  {
    "path": "instfiles/default/Makefile.am",
    "content": "startscriptdir = $(sysconfdir)/default\ndist_startscript_DATA = xrdp\n"
  },
  {
    "path": "instfiles/default/xrdp",
    "content": "# Do we need to start sesman ?\nSESMAN_START=yes\n# Do we restart xrdp on upgrade ? If not set to no, any xrdp session will\n# be shutdown on upgrade.\n# RESTART_ON_UPGRADE=no\n"
  },
  {
    "path": "instfiles/init.d/Makefile.am",
    "content": "startscriptdir = $(sysconfdir)/init.d\ndist_startscript_SCRIPTS = xrdp\n"
  },
  {
    "path": "instfiles/init.d/xrdp",
    "content": "#!/bin/sh -e\n#\n# start/stop xrdp and sesman daemons\n#\n### BEGIN INIT INFO\n# Provides:          xrdp\n# Required-Start:    $network $remote_fs\n# Required-Stop:     $network $remote_fs\n# Default-Start:     2 3 4 5\n# Default-Stop:      0 1 6\n# Short-Description: Start xrdp and sesman daemons\n# Description:       XRDP uses the Remote Desktop Protocol to present a\n#                    graphical login to a remote client allowing connection\n#                    to a VNC server or another RDP server.\n### END INIT INFO\n\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\nBASE=__BASE__\nDAEMON=${BASE}/sbin/xrdp\nSDAEMON=${BASE}/sbin/xrdp-sesman\nPIDDIR=/var/run/\nSESMAN_START=yes\n#USERID=xrdp\n# the X11rdp backend only works as root at the moment - GH 20/03/2013\nUSERID=root\nNAME=xrdp\nDESC=\"Remote Desktop Protocol server\"\n\ntest -x $DAEMON || exit 0\n\n. /lib/lsb/init-functions\n\ncheck_root()  {\n    if [ \"$(id -u)\" != \"0\" ]; then\n        log_failure_msg \"You must be root to start, stop or restart $NAME.\"\n        exit 4\n    fi\n}\n\nforce_stop() {\n\nDELAY=1\nPROCLIST=\"xrdp-sesman xrdp-sessvc xrdp-chansrv X11rdp Xvnc\"\n\n    for p in $PROCLIST; do\n      pgrep -x $p >/dev/null && pkill  -x $p\n      sleep $DELAY\n      pgrep -x $p >/dev/null && pkill -9 -x $p\n    done\n    # let's not kill ourselves - the init script is called xrdp as well\n    pgrep -fx $DAEMON  >/dev/null && pkill -fx $DAEMON\n    sleep $DELAY\n    pgrep -fx $DAEMON  >/dev/null && pkill -9 -fx $DAEMON\n\n   rm -f $PIDDIR/xrdp*.pid\n}\n\nif [ -r /etc/default/$NAME ]; then\n   . /etc/default/$NAME\nfi\n\n# Tasks that can only be run as root\nif [ \"$(id -u)\" = \"0\" ]; then\n    # Check for pid dir\n    if [ ! -d $PIDDIR ] ; then\n        mkdir $PIDDIR\n    fi\n    chown $USERID:$USERID $PIDDIR\nfi\n\n\ncase \"$1\" in\n  start)\n        check_root\n        exitval=0\n        log_daemon_msg \"Starting $DESC \"\n        if pidofproc -p $PIDDIR/$NAME.pid $DAEMON > /dev/null; then\n            log_progress_msg \"$NAME apparently already running\"\n            log_end_msg 0\n            exit 0\n        fi\n        log_progress_msg $NAME\n        start-stop-daemon --start --quiet --oknodo  --pidfile $PIDDIR/$NAME.pid \\\n\t    --chuid $USERID:$USERID --exec $DAEMON >/dev/null\n        exitval=$?\n\tif [ \"$SESMAN_START\" = \"yes\" ] ; then\n            log_progress_msg \"sesman\"\n            start-stop-daemon --start --quiet --oknodo --pidfile $PIDDIR/xrdp-sesman.pid \\\n\t       --exec $SDAEMON >/dev/null\n            value=$?\n            [ $value -gt 0 ] && exitval=$value\n        fi\n        # Make pidfile readable for all users (for status to work)\n        [ -e $PIDDIR/xrdp-sesman.pid ] && chmod 0644 $PIDDIR/xrdp-sesman.pid\n        [ -e $PIDDIR/$NAME.pid ] && chmod 0644 $PIDDIR/$NAME.pid\n        # Note: Unfortunately, xrdp currently takes too long to create\n        # the pidfile unless properly patched\n        log_end_msg $exitval\n\t;;\n  stop)\n        check_root\n\t[ -n \"$XRDP_UPGRADE\" -a \"$RESTART_ON_UPGRADE\" = \"no\" ] && {\n\t    echo \"Upgrade in progress, no restart of xrdp.\"\n\t    exit 0\n\t}\n        exitval=0\n        log_daemon_msg \"Stopping RDP Session manager \"\n        log_progress_msg \"sesman\"\n        if pidofproc -p  $PIDDIR/xrdp-sesman.pid $SDAEMON  > /dev/null; then\n            start-stop-daemon --stop --quiet --oknodo --pidfile $PIDDIR/xrdp-sesman.pid \\\n                --chuid $USERID:$USERID --exec $SDAEMON\n            exitval=$?\n        else\n            log_progress_msg \"apparently not running\"\n        fi\n        log_progress_msg $NAME\n        if pidofproc -p  $PIDDIR/$NAME.pid $DAEMON  > /dev/null; then\n            start-stop-daemon --stop --quiet --oknodo --pidfile $PIDDIR/$NAME.pid \\\n\t    --remove-pidfile --exec $DAEMON\n            value=$?\n            [ $value -gt 0 ] && exitval=$value\n        else\n            log_progress_msg \"apparently not running\"\n        fi\n        log_end_msg $exitval\n\t;;\n  force-stop)\n\t$0 stop\n\t# because it doesn't always die the right way\n\tforce_stop\n\t;;\n  restart|force-reload)\n        check_root\n\t$0 stop\n        # Wait for things to settle down\n        sleep 1\n\t$0 start\n\t;;\n  reload)\n        log_warning_msg \"Reloading $NAME daemon: not implemented, as the daemon\"\n        log_warning_msg \"cannot re-read the config file (use restart).\"\n        ;;\n  status)\n        exitval=0\n        log_daemon_msg \"Checking status of $DESC\" \"$NAME\"\n        if pidofproc -p  $PIDDIR/$NAME.pid $DAEMON  > /dev/null; then\n            log_progress_msg \"running\"\n            log_end_msg 0\n        else\n            log_progress_msg \"apparently not running\"\n            log_end_msg 1 || true\n            exitval=1\n        fi\n\tif [ \"$SESMAN_START\" = \"yes\" ] ; then\n            log_daemon_msg \"Checking status of RDP Session Manager\" \"sesman\"\n            if pidofproc -p  $PIDDIR/xrdp-sesman.pid $SDAEMON  > /dev/null; then\n                log_progress_msg \"running\"\n                log_end_msg 0\n            else\n                log_progress_msg \"apparently not running\"\n                log_end_msg 1 || true\n                exitval=1\n            fi\n\tfi\n        exit $exitval\n        ;;\n  *)\n\tN=/etc/init.d/$NAME\n\techo \"Usage: $N {start|stop|force-stop|restart|force-reload|status}\" >&2\n\texit 1\n\t;;\nesac\n\nexit 0\n"
  },
  {
    "path": "instfiles/keymap-names.txt",
    "content": "\n0x00000436 af Afrikaans\n0x0000041C sq Albanian\n0x00000001 ar Arabic\n0x00000401 ar-sa Arabic (Saudi Arabia)\n0x00000801 ar-iq Arabic (Iraq)\n0x00000C01 ar-eg Arabic (Egypt)\n0x00001001 ar-ly Arabic (Libya)\n0x00001401 ar-dz Arabic (Algeria)\n0x00001801 ar-ma Arabic (Morocco)\n0x00001C01 ar-tn Arabic (Tunisia)\n0x00002001 ar-om Arabic (Oman)\n0x00002401 ar-ye Arabic (Yemen)\n0x00002801 ar-sy Arabic (Syria)\n0x00002C01 ar-jo Arabic (Jordan)\n0x00003001 ar-lb Arabic (Lebanon)\n0x00003401 ar-kw Arabic (Kuwait)\n0x00003801 ar-ae Arabic (U.A.E.)\n0x00003C01 ar-bh Arabic (Bahrain)\n0x00004001 ar-qa Arabic (Qatar)\n0x0000042D eu Basque\n0x00000402 bg Bulgarian\n0x00000423 be Belarusian\n0x00000403 ca Catalan\n0x00000004 zh Chinese\n0x00000404 zh-tw Chinese (Taiwan)\n0x00000804 zh-cn Chinese (China)\n0x00000C04 zh-hk Chinese (Hong Kong SAR)\n0x00001004 zh-sg Chinese (Singapore)\n0x0000041A hr Croatian\n0x00000405 cs Czech\n0x00000406 da Danish\n0x00000413 nl Dutch (Netherlands)\n0x00000813 nl-be Dutch (Belgium)\n0x00000009 en English\n0x00000409 en-us English (United States)\n0x00000809 en-gb English (United Kingdom)\n0x00000C09 en-au English (Australia)\n0x00001009 en-ca English (Canada)\n0x00001409 en-nz English (New Zealand)\n0x00001809 en-ie English (Ireland)\n0x00001C09 en-za English (South Africa)\n0x00002009 en-jm English (Jamaica)\n0x00002809 en-bz English (Belize)\n0x00002C09 en-tt English (Trinidad)\n0x00000425 et Estonian\n0x00000438 fo Faeroese\n0x00000429 fa Farsi\n0x0000040B fi Finnish\n0x0000040C fr French (France)\n0x0000080C fr-be French (Belgium)\n0x00000C0C fr-ca French (Canada)\n0x0000100C fr-ch French (Switzerland)\n0x0000140C fr-lu French (Luxembourg)\n0x0000043C gd Gaelic\n0x00000407 de German (Germany)\n0x00000807 de-ch German (Switzerland)\n0x00000C07 de-at German (Austria)\n0x00001007 de-lu German (Luxembourg)\n0x00001407 de-li German (Liechtenstein)\n0x00000408 el Greek\n0x0000040D he Hebrew\n0x00000439 hi Hindi\n0x0000040E hu Hungarian\n0x0000040F is Icelandic\n0x00000421 in Indonesian\n0x00000410 it Italian (Italy)\n0x00000810 it-ch Italian (Switzerland)\n0x00000411 ja Japanese\n0x00000412 ko Korean\n0x00000426 lv Latvian\n0x00000427 lt Lithuanian\n0x0000042F mk FYRO Macedonian\n0x0000043E ms Malay (Malaysia)\n0x0000043A mt Maltese\n0x00000414 no Norwegian (Bokmal)\n0x00000814 no Norwegian (Nynorsk)\n0x00000415 pl Polish\n0x00000416 pt-br Portuguese (Brazil)\n0x00000816 pt Portuguese (Portugal)\n0x00000417 rm Rhaeto-Romanic\n0x00000418 ro Romanian\n0x00000818 ro-mo Romanian (Moldova)\n0x00000419 ru Russian\n0x00000819 ru-mo Russian (Moldova)\n0x00000C1A sr Serbian (Cyrillic)\n0x0000081A sr Serbian (Latin)\n0x0000041B sk Slovak\n0x00000424 sl Slovenian\n0x0000042E sb Sorbian\n0x0000040A es Spanish (Traditional Sort)\n0x0000080A es-mx Spanish (Mexico)\n0x00000C0A es Spanish (International Sort)\n0x0000100A es-gt Spanish (Guatemala)\n0x0000140A es-cr Spanish (Costa Rica)\n0x0000180A es-pa Spanish (Panama)\n0x00001C0A es-do Spanish (Dominican Republic)\n0x0000200A es-ve Spanish (Venezuela)\n0x0000240A es-co Spanish (Colombia)\n0x0000280A es-pe Spanish (Peru)\n0x00002C0A es-ar Spanish (Argentina)\n0x0000300A es-ec Spanish (Ecuador)\n0x0000340A es-cl Spanish (Chile)\n0x0000380A es-uy Spanish (Uruguay)\n0x00003C0A es-py Spanish (Paraguay)\n0x0000400A es-bo Spanish (Bolivia)\n0x0000440A es-sv Spanish (El Salvador)\n0x0000480A es-hn Spanish (Honduras)\n0x00004C0A es-ni Spanish (Nicaragua)\n0x0000500A es-pr Spanish (Puerto Rico)\n0x00000430 sx Sutu\n0x0000041D sv Swedish\n0x0000081D sv-fi Swedish (Finland)\n0x0000041E th Thai\n0x00000431 ts Tsonga\n0x00000432 tn Tswana\n0x0000041F tr Turkish\n0x00000422 uk Ukrainian\n0x00000420 ur Urdu\n0x0000042A vi Vietnamese\n0x00000434 xh Xhosa\n0x0000043D ji Yiddish\n0x00000435 zu Zulu\n\n"
  },
  {
    "path": "instfiles/km-00000405.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwertz)\n# setxkbmap -rules evdev -model pc105 -layout cz\n# Description: cs-CZ\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"43:U+002B\"  # plus\n03=\"492:U+011B\"  # ecaron\n04=\"441:U+0161\"  # scaron\n05=\"488:U+010D\"  # ccaron\n06=\"504:U+0159\"  # rcaron\n07=\"446:U+017E\"  # zcaron\n08=\"253:U+00FD\"  # yacute\n09=\"225:U+00E1\"  # aacute\n0A=\"237:U+00ED\"  # iacute\n0B=\"233:U+00E9\"  # eacute\n0C=\"61:U+003D\"  # equal\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"250:U+00FA\"  # uacute\n1B=\"41:U+0029\"  # parenright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"505:U+016F\"  # uring\n28=\"167:U+00A7\"  # section\n29=\"59:U+003B\"  # semicolon\n2A=\"65505\"  # Shift_L\n2B=\"65111:U+00A8\"  # dead_diaeresis\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"37:U+0025\"  # percent\n0D=\"65114:U+02C7\"  # dead_caron\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"47:U+002F\"  # slash\n1B=\"40:U+0028\"  # parenleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"34:U+0022\"  # quotedbl\n28=\"33:U+0021\"  # exclam\n29=\"65112:U+00B0\"  # dead_abovering\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"63:U+003F\"  # question\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"123:U+007B\"  # braceleft\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65108:U+00AF\"  # dead_macron\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"92:U+005C\"  # backslash\n11=\"124:U+007C\"  # bar\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"126:U+007E\"  # asciitilde\n1F=\"496:U+0111\"  # dstroke\n20=\"464:U+0110\"  # Dstroke\n21=\"91:U+005B\"  # bracketleft\n22=\"93:U+005D\"  # bracketright\n23=\"96:U+0060\"  # grave\n24=\"39:U+0027\"  # apostrophe\n25=\"435:U+0142\"  # lstroke\n26=\"419:U+0141\"  # Lstroke\n27=\"36:U+0024\"  # dollar\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"176:U+00B0\"  # degree\n2D=\"35:U+0023\"  # numbersign\n2E=\"38:U+0026\"  # ampersand\n2F=\"64:U+0040\"  # at\n30=\"123:U+007B\"  # braceleft\n31=\"125:U+007D\"  # braceright\n32=\"94:U+005E\"  # asciicircum\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"42:U+002A\"  # asterisk\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"47:U+002F\"  # slash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"65107:U+007E\"  # dead_tilde\n03=\"65114:U+02C7\"  # dead_caron\n04=\"65106:U+005E\"  # dead_circumflex\n05=\"65109:U+02D8\"  # dead_breve\n06=\"65112:U+00B0\"  # dead_abovering\n07=\"65116:U+02DB\"  # dead_ogonek\n08=\"65104:U+0060\"  # dead_grave\n09=\"65110:U+02D9\"  # dead_abovedot\n0A=\"65105:U+00B4\"  # dead_acute\n0B=\"65113:U+02DD\"  # dead_doubleacute\n0C=\"65111:U+00A8\"  # dead_diaeresis\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"69:U+0045\"  # E\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"247:U+00F7\"  # division\n1B=\"215:U+00D7\"  # multiply\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"223:U+00DF\"  # ssharp\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"43:U+002B\"  # plus\n03=\"460:U+011A\"  # Ecaron\n04=\"425:U+0160\"  # Scaron\n05=\"456:U+010C\"  # Ccaron\n06=\"472:U+0158\"  # Rcaron\n07=\"430:U+017D\"  # Zcaron\n08=\"221:U+00DD\"  # Yacute\n09=\"193:U+00C1\"  # Aacute\n0A=\"205:U+00CD\"  # Iacute\n0B=\"201:U+00C9\"  # Eacute\n0C=\"61:U+003D\"  # equal\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"218:U+00DA\"  # Uacute\n1B=\"41:U+0029\"  # parenright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"473:U+016E\"  # Uring\n28=\"167:U+00A7\"  # section\n29=\"59:U+003B\"  # semicolon\n2A=\"65505\"  # Shift_L\n2B=\"65111:U+00A8\"  # dead_diaeresis\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"123:U+007B\"  # braceleft\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65108:U+00AF\"  # dead_macron\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"92:U+005C\"  # backslash\n11=\"124:U+007C\"  # bar\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"126:U+007E\"  # asciitilde\n1F=\"464:U+0110\"  # Dstroke\n20=\"464:U+0110\"  # Dstroke\n21=\"91:U+005B\"  # bracketleft\n22=\"93:U+005D\"  # bracketright\n23=\"96:U+0060\"  # grave\n24=\"39:U+0027\"  # apostrophe\n25=\"419:U+0141\"  # Lstroke\n26=\"419:U+0141\"  # Lstroke\n27=\"36:U+0024\"  # dollar\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"176:U+00B0\"  # degree\n2D=\"35:U+0023\"  # numbersign\n2E=\"38:U+0026\"  # ampersand\n2F=\"64:U+0040\"  # at\n30=\"123:U+007B\"  # braceleft\n31=\"125:U+007D\"  # braceright\n32=\"94:U+005E\"  # asciicircum\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"42:U+002A\"  # asterisk\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"47:U+002F\"  # slash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"37:U+0025\"  # percent\n0D=\"65114:U+02C7\"  # dead_caron\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"47:U+002F\"  # slash\n1B=\"40:U+0028\"  # parenleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"34:U+0022\"  # quotedbl\n28=\"33:U+0021\"  # exclam\n29=\"65112:U+00B0\"  # dead_abovering\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"63:U+003F\"  # question\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"65107:U+007E\"  # dead_tilde\n03=\"65114:U+02C7\"  # dead_caron\n04=\"65106:U+005E\"  # dead_circumflex\n05=\"65109:U+02D8\"  # dead_breve\n06=\"65112:U+00B0\"  # dead_abovering\n07=\"65116:U+02DB\"  # dead_ogonek\n08=\"65104:U+0060\"  # dead_grave\n09=\"65110:U+02D9\"  # dead_abovedot\n0A=\"65105:U+00B4\"  # dead_acute\n0B=\"65113:U+02DD\"  # dead_doubleacute\n0C=\"65111:U+00A8\"  # dead_diaeresis\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"69:U+0045\"  # E\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"247:U+00F7\"  # division\n1B=\"215:U+00D7\"  # multiply\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00000406.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout dk\n# Description: da-DK\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"43:U+002B\"  # plus\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"229:U+00E5\"  # aring\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"230:U+00E6\"  # ae\n28=\"248:U+00F8\"  # oslash\n29=\"189:U+00BD\"  # onehalf\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"164:U+00A4\"  # currency\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"197:U+00C5\"  # Aring\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"198:U+00C6\"  # AE\n28=\"216:U+00D8\"  # Oslash\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"189:U+00BD\"  # onehalf\n07=\"165:U+00A5\"  # yen\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"177:U+00B1\"  # plusminus\n0D=\"124:U+007C\"  # bar\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"254:U+00FE\"  # thorn\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"170:U+00AA\"  # ordfeminine\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"190:U+00BE\"  # threequarters\n2A=\"65505\"  # Shift_L\n2B=\"65113:U+02DD\"  # dead_doubleacute\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"65115:U+00B8\"  # dead_cedilla\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"162:U+00A2\"  # cent\n07=\"2757:U+215D\"  # fiveeighths\n08=\"247:U+00F7\"  # division\n09=\"171:U+00AB\"  # guillemotleft\n0A=\"187:U+00BB\"  # guillemotright\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"166:U+00A6\"  # brokenbar\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"222:U+00DE\"  # THORN\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65114:U+02C7\"  # dead_caron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"186:U+00BA\"  # masculine\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"182:U+00B6\"  # paragraph\n2A=\"65505\"  # Shift_L\n2B=\"215:U+00D7\"  # multiply\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"65116:U+02DB\"  # dead_ogonek\n34=\"65110:U+02D9\"  # dead_abovedot\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"172:U+00AC\"  # notsign\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"43:U+002B\"  # plus\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"197:U+00C5\"  # Aring\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"198:U+00C6\"  # AE\n28=\"216:U+00D8\"  # Oslash\n29=\"189:U+00BD\"  # onehalf\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"189:U+00BD\"  # onehalf\n07=\"165:U+00A5\"  # yen\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"177:U+00B1\"  # plusminus\n0D=\"124:U+007C\"  # bar\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"222:U+00DE\"  # THORN\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"170:U+00AA\"  # ordfeminine\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"190:U+00BE\"  # threequarters\n2A=\"65505\"  # Shift_L\n2B=\"65113:U+02DD\"  # dead_doubleacute\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"65115:U+00B8\"  # dead_cedilla\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"164:U+00A4\"  # currency\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"229:U+00E5\"  # aring\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"230:U+00E6\"  # ae\n28=\"248:U+00F8\"  # oslash\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"162:U+00A2\"  # cent\n07=\"2757:U+215D\"  # fiveeighths\n08=\"247:U+00F7\"  # division\n09=\"171:U+00AB\"  # guillemotleft\n0A=\"187:U+00BB\"  # guillemotright\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"166:U+00A6\"  # brokenbar\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"254:U+00FE\"  # thorn\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65114:U+02C7\"  # dead_caron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"186:U+00BA\"  # masculine\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"182:U+00B6\"  # paragraph\n2A=\"65505\"  # Shift_L\n2B=\"215:U+00D7\"  # multiply\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"65116:U+02DB\"  # dead_ogonek\n34=\"65110:U+02D9\"  # dead_abovedot\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"172:U+00AC\"  # notsign\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-00000407.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=223:223\nKey21=65105:180\nKey22=65288:8\nKey23=65289:9\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=122:122\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=252:252\nKey35=43:43\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=246:246\nKey48=228:228\nKey49=65106:94\nKey50=65505:0\nKey51=35:35\nKey52=121:121\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=44:44\nKey60=46:46\nKey61=45:45\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=167:167\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=47:47\nKey17=40:40\nKey18=41:41\nKey19=61:61\nKey20=63:63\nKey21=65104:96\nKey22=65288:8\nKey23=65056:0\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=90:90\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=220:220\nKey35=42:42\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=214:214\nKey48=196:196\nKey49=176:176\nKey50=65505:0\nKey51=39:39\nKey52=89:89\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=59:59\nKey60=58:58\nKey61=95:95\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=178:178\nKey12=179:179\nKey13=188:188\nKey14=189:189\nKey15=172:172\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=92:92\nKey21=65115:184\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=435:322\nKey26=8364:8364\nKey27=182:182\nKey28=956:359\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=248:248\nKey33=254:254\nKey34=65111:168\nKey35=126:126\nKey36=65293:13\nKey37=65507:0\nKey38=230:230\nKey39=16777599:383\nKey40=240:240\nKey41=496:273\nKey42=959:331\nKey43=689:295\nKey44=65120:0\nKey45=930:312\nKey46=435:322\nKey47=65113:733\nKey48=65106:94\nKey49=16785458:8242\nKey50=65505:0\nKey51=2769:8217\nKey52=187:187\nKey53=171:171\nKey54=162:162\nKey55=2814:8222\nKey56=2770:8220\nKey57=2771:8221\nKey58=181:181\nKey59=183:183\nKey60=16785446:8230\nKey61=2730:8211\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=2755:8539\nKey12=163:163\nKey13=164:164\nKey14=2756:8540\nKey15=2757:8541\nKey16=2758:8542\nKey17=2761:8482\nKey18=177:177\nKey19=176:176\nKey20=191:191\nKey21=65116:731\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=419:321\nKey26=8364:8364\nKey27=174:174\nKey28=940:358\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=216:216\nKey33=222:222\nKey34=65112:176\nKey35=175:175\nKey36=65293:13\nKey37=65507:0\nKey38=198:198\nKey39=16785054:7838\nKey40=208:208\nKey41=170:170\nKey42=957:330\nKey43=673:294\nKey44=65110:729\nKey45=38:38\nKey46=419:321\nKey47=65120:0\nKey48=65114:711\nKey49=16785459:8243\nKey50=65505:0\nKey51=65109:728\nKey52=16785466:8250\nKey53=16785465:8249\nKey54=169:169\nKey55=2813:8218\nKey56=2768:8216\nKey57=2769:8217\nKey58=186:186\nKey59=215:215\nKey60=247:247\nKey61=2729:8212\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=16785054:7838\nKey21=65105:180\nKey22=65288:8\nKey23=65289:9\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=90:90\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=220:220\nKey35=43:43\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=214:214\nKey48=196:196\nKey49=65106:94\nKey50=65505:0\nKey51=35:35\nKey52=89:89\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=44:44\nKey60=46:46\nKey61=45:45\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=178:178\nKey12=179:179\nKey13=188:188\nKey14=189:189\nKey15=172:172\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=92:92\nKey21=65115:184\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=419:321\nKey26=8364:8364\nKey27=182:182\nKey28=940:358\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=216:216\nKey33=222:222\nKey34=65111:168\nKey35=126:126\nKey36=65293:13\nKey37=65507:0\nKey38=198:198\nKey39=16777299:83\nKey40=208:208\nKey41=464:272\nKey42=957:330\nKey43=673:294\nKey44=65120:0\nKey45=930:312\nKey46=419:321\nKey47=65113:733\nKey48=65106:94\nKey49=16785458:8242\nKey50=65505:0\nKey51=2769:8217\nKey52=187:187\nKey53=171:171\nKey54=162:162\nKey55=2814:8222\nKey56=2770:8220\nKey57=2771:8221\nKey58=924:0\nKey59=183:183\nKey60=16785446:8230\nKey61=2730:8211\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=167:167\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=47:47\nKey17=40:40\nKey18=41:41\nKey19=61:61\nKey20=63:63\nKey21=65104:96\nKey22=65288:8\nKey23=65056:0\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=122:122\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=252:252\nKey35=42:42\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=246:246\nKey48=228:228\nKey49=176:176\nKey50=65505:0\nKey51=39:39\nKey52=121:121\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=59:59\nKey60=58:58\nKey61=95:95\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=2755:8539\nKey12=163:163\nKey13=164:164\nKey14=2756:8540\nKey15=2757:8541\nKey16=2758:8542\nKey17=2761:8482\nKey18=177:177\nKey19=176:176\nKey20=191:191\nKey21=65116:731\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=435:322\nKey26=8364:8364\nKey27=174:174\nKey28=956:359\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=248:248\nKey33=254:254\nKey34=65112:176\nKey35=175:175\nKey36=65293:13\nKey37=65507:0\nKey38=230:230\nKey39=16785054:7838\nKey40=240:240\nKey41=170:170\nKey42=959:331\nKey43=689:295\nKey44=65110:729\nKey45=38:38\nKey46=435:322\nKey47=65120:0\nKey48=65114:711\nKey49=16785459:8243\nKey50=65505:0\nKey51=65109:728\nKey52=16785466:8250\nKey53=16785465:8249\nKey54=169:169\nKey55=2813:8218\nKey56=2768:8216\nKey57=2769:8217\nKey58=186:186\nKey59=215:215\nKey60=247:247\nKey61=2729:8212\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n"
  },
  {
    "path": "instfiles/km-00000407.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwertz)\n# setxkbmap -rules evdev -model pc104 -layout de\n# Description: de-DE\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"223:U+00DF\"  # ssharp\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"252:U+00FC\"  # udiaeresis\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"246:U+00F6\"  # odiaeresis\n28=\"228:U+00E4\"  # adiaeresis\n29=\"65106:U+005E\"  # dead_circumflex\n2A=\"65505\"  # Shift_L\n2B=\"35:U+0023\"  # numbersign\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"167:U+00A7\"  # section\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"220:U+00DC\"  # Udiaeresis\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"196:U+00C4\"  # Adiaeresis\n29=\"176:U+00B0\"  # degree\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"126:U+007E\"  # asciitilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"16777599:U+017F\"  # U017F\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65120\"  # dead_belowdot\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"16785458:U+2032\"  # U2032\n2A=\"65505\"  # Shift_L\n2B=\"2769:U+2019\"  # rightsinglequotemark\n2C=\"187:U+00BB\"  # guillemotright\n2D=\"171:U+00AB\"  # guillemotleft\n2E=\"162:U+00A2\"  # cent\n2F=\"2814:U+201E\"  # doublelowquotemark\n30=\"2770:U+201C\"  # leftdoublequotemark\n31=\"2771:U+201D\"  # rightdoublequotemark\n32=\"181:U+00B5\"  # mu\n33=\"183:U+00B7\"  # periodcentered\n34=\"16785446:U+2026\"  # U2026\n35=\"2730:U+2013\"  # endash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"164:U+00A4\"  # currency\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"175:U+00AF\"  # macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"16785054:U+1E9E\"  # U1E9E\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65110:U+02D9\"  # dead_abovedot\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65120\"  # dead_belowdot\n28=\"65114:U+02C7\"  # dead_caron\n29=\"16785459:U+2033\"  # U2033\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"16785466:U+203A\"  # U203A\n2D=\"16785465:U+2039\"  # U2039\n2E=\"169:U+00A9\"  # copyright\n2F=\"2813:U+201A\"  # singlelowquotemark\n30=\"2768:U+2018\"  # leftsinglequotemark\n31=\"2769:U+2019\"  # rightsinglequotemark\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"2729:U+2014\"  # emdash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65128\"  # dead_belowmacron\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"16785054:U+1E9E\"  # U1E9E\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"220:U+00DC\"  # Udiaeresis\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"196:U+00C4\"  # Adiaeresis\n29=\"65106:U+005E\"  # dead_circumflex\n2A=\"65505\"  # Shift_L\n2B=\"35:U+0023\"  # numbersign\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"126:U+007E\"  # asciitilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"16785054:U+1E9E\"  # U1E9E\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65120\"  # dead_belowdot\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"16785458:U+2032\"  # U2032\n2A=\"65505\"  # Shift_L\n2B=\"2769:U+2019\"  # rightsinglequotemark\n2C=\"187:U+00BB\"  # guillemotright\n2D=\"171:U+00AB\"  # guillemotleft\n2E=\"162:U+00A2\"  # cent\n2F=\"2814:U+201E\"  # doublelowquotemark\n30=\"2770:U+201C\"  # leftdoublequotemark\n31=\"2771:U+201D\"  # rightdoublequotemark\n33=\"183:U+00B7\"  # periodcentered\n34=\"16785446:U+2026\"  # U2026\n35=\"2730:U+2013\"  # endash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"167:U+00A7\"  # section\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"252:U+00FC\"  # udiaeresis\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"246:U+00F6\"  # odiaeresis\n28=\"228:U+00E4\"  # adiaeresis\n29=\"176:U+00B0\"  # degree\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"164:U+00A4\"  # currency\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"175:U+00AF\"  # macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"16777599:U+017F\"  # U017F\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65110:U+02D9\"  # dead_abovedot\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65120\"  # dead_belowdot\n28=\"65114:U+02C7\"  # dead_caron\n29=\"16785459:U+2033\"  # U2033\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"16785466:U+203A\"  # U203A\n2D=\"16785465:U+2039\"  # U2039\n2E=\"169:U+00A9\"  # copyright\n2F=\"2813:U+201A\"  # singlelowquotemark\n30=\"2768:U+2018\"  # leftsinglequotemark\n31=\"2769:U+2019\"  # rightsinglequotemark\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"2729:U+2014\"  # emdash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65128\"  # dead_belowmacron\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-00000409.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout us\n# Description: en-US\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-0000040a.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout es\n# Description: es-ES_tradnl\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"161:U+00A1\"  # exclamdown\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65104:U+0060\"  # dead_grave\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"241:U+00F1\"  # ntilde\n28=\"65105:U+00B4\"  # dead_acute\n29=\"186:U+00BA\"  # masculine\n2A=\"65505\"  # Shift_L\n2B=\"231:U+00E7\"  # ccedilla\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"183:U+00B7\"  # periodcentered\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"191:U+00BF\"  # questiondown\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65106:U+005E\"  # dead_circumflex\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"209:U+00D1\"  # Ntilde\n28=\"65111:U+00A8\"  # dead_diaeresis\n29=\"170:U+00AA\"  # ordfeminine\n2A=\"65505\"  # Shift_L\n2B=\"199:U+00C7\"  # Ccedilla\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"126:U+007E\"  # asciitilde\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65107:U+007E\"  # dead_tilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"126:U+007E\"  # asciitilde\n28=\"123:U+007B\"  # braceleft\n29=\"92:U+005C\"  # backslash\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"126:U+007E\"  # asciitilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"123:U+007B\"  # braceleft\n29=\"92:U+005C\"  # backslash\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"161:U+00A1\"  # exclamdown\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65104:U+0060\"  # dead_grave\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"209:U+00D1\"  # Ntilde\n28=\"65105:U+00B4\"  # dead_acute\n29=\"186:U+00BA\"  # masculine\n2A=\"65505\"  # Shift_L\n2B=\"199:U+00C7\"  # Ccedilla\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"126:U+007E\"  # asciitilde\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65107:U+007E\"  # dead_tilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"126:U+007E\"  # asciitilde\n28=\"123:U+007B\"  # braceleft\n29=\"92:U+005C\"  # backslash\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"183:U+00B7\"  # periodcentered\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"191:U+00BF\"  # questiondown\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65106:U+005E\"  # dead_circumflex\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"241:U+00F1\"  # ntilde\n28=\"65111:U+00A8\"  # dead_diaeresis\n29=\"170:U+00AA\"  # ordfeminine\n2A=\"65505\"  # Shift_L\n2B=\"231:U+00E7\"  # ccedilla\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"126:U+007E\"  # asciitilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"123:U+007B\"  # braceleft\n29=\"92:U+005C\"  # backslash\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-0000040b.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout fi\n# Description: fi-FI\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"43:U+002B\"  # plus\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"229:U+00E5\"  # aring\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"246:U+00F6\"  # odiaeresis\n28=\"228:U+00E4\"  # adiaeresis\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"164:U+00A4\"  # currency\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"197:U+00C5\"  # Aring\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"196:U+00C4\"  # Adiaeresis\n29=\"189:U+00BD\"  # onehalf\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2773:U+2030\"  # permille\n07=\"2813:U+201A\"  # singlelowquotemark\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"8364:U+20AC\"  # EuroSign\n13=\"114:U+0072\"  # r\n14=\"254:U+00FE\"  # thorn\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"697:U+0131\"  # idotless\n18=\"5053:U+0153\"  # oe\n19=\"65122\"  # dead_horn\n1A=\"65113:U+02DD\"  # dead_doubleacute\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"16777817:U+0259\"  # schwa\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"930:U+0138\"  # kra\n26=\"65123\"  # dead_stroke\n27=\"248:U+00F8\"  # oslash\n28=\"230:U+00E6\"  # ae\n29=\"65123\"  # dead_stroke\n2A=\"65505\"  # Shift_L\n2B=\"65114:U+02C7\"  # dead_caron\n2C=\"16777874:U+0292\"  # ezh\n2D=\"215:U+00D7\"  # multiply\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"959:U+014B\"  # eng\n32=\"181:U+00B5\"  # mu\n33=\"2769:U+2019\"  # rightsinglequotemark\n34=\"65120\"  # dead_belowdot\n35=\"2730:U+2013\"  # endash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2771:U+201D\"  # rightdoublequotemark\n04=\"187:U+00BB\"  # guillemotright\n05=\"171:U+00AB\"  # guillemotleft\n06=\"2770:U+201C\"  # leftdoublequotemark\n07=\"2814:U+201E\"  # doublelowquotemark\n09=\"60:U+003C\"  # less\n0A=\"62:U+003E\"  # greater\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n13=\"82:U+0052\"  # R\n14=\"222:U+00DE\"  # THORN\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"124:U+007C\"  # bar\n18=\"5052:U+0152\"  # OE\n19=\"65121\"  # dead_hook\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"16777615:U+018F\"  # SCHWA\n1F=\"16785054:U+1E9E\"  # U1E9E\n20=\"208:U+00D0\"  # ETH\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"65164\"  # dead_greek\n26=\"65135\"  # dead_currency\n27=\"216:U+00D8\"  # Oslash\n28=\"198:U+00C6\"  # AE\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"16777655:U+01B7\"  # EZH\n2D=\"183:U+00B7\"  # periodcentered\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"957:U+014A\"  # ENG\n32=\"2729:U+2014\"  # emdash\n33=\"2768:U+2018\"  # leftsinglequotemark\n34=\"65110:U+02D9\"  # dead_abovedot\n35=\"65134\"  # dead_belowcomma\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"16785455:U+202F\"  # U202F\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"43:U+002B\"  # plus\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"197:U+00C5\"  # Aring\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"196:U+00C4\"  # Adiaeresis\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2773:U+2030\"  # permille\n07=\"2813:U+201A\"  # singlelowquotemark\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"8364:U+20AC\"  # EuroSign\n13=\"82:U+0052\"  # R\n14=\"222:U+00DE\"  # THORN\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"697:U+0131\"  # idotless\n18=\"5052:U+0152\"  # OE\n19=\"65122\"  # dead_horn\n1A=\"65113:U+02DD\"  # dead_doubleacute\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"16777615:U+018F\"  # SCHWA\n1F=\"16785054:U+1E9E\"  # U1E9E\n20=\"208:U+00D0\"  # ETH\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"930:U+0138\"  # kra\n26=\"65123\"  # dead_stroke\n27=\"216:U+00D8\"  # Oslash\n28=\"198:U+00C6\"  # AE\n29=\"65123\"  # dead_stroke\n2A=\"65505\"  # Shift_L\n2B=\"65114:U+02C7\"  # dead_caron\n2C=\"16777655:U+01B7\"  # EZH\n2D=\"215:U+00D7\"  # multiply\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"957:U+014A\"  # ENG\n33=\"2769:U+2019\"  # rightsinglequotemark\n34=\"65120\"  # dead_belowdot\n35=\"2730:U+2013\"  # endash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"164:U+00A4\"  # currency\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"229:U+00E5\"  # aring\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"246:U+00F6\"  # odiaeresis\n28=\"228:U+00E4\"  # adiaeresis\n29=\"189:U+00BD\"  # onehalf\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2771:U+201D\"  # rightdoublequotemark\n04=\"187:U+00BB\"  # guillemotright\n05=\"171:U+00AB\"  # guillemotleft\n06=\"2770:U+201C\"  # leftdoublequotemark\n07=\"2814:U+201E\"  # doublelowquotemark\n09=\"60:U+003C\"  # less\n0A=\"62:U+003E\"  # greater\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n13=\"114:U+0072\"  # r\n14=\"254:U+00FE\"  # thorn\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"124:U+007C\"  # bar\n18=\"5053:U+0153\"  # oe\n19=\"65121\"  # dead_hook\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"16777817:U+0259\"  # schwa\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"65164\"  # dead_greek\n26=\"65135\"  # dead_currency\n27=\"248:U+00F8\"  # oslash\n28=\"230:U+00E6\"  # ae\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"16777874:U+0292\"  # ezh\n2D=\"183:U+00B7\"  # periodcentered\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"959:U+014B\"  # eng\n32=\"2729:U+2014\"  # emdash\n33=\"2768:U+2018\"  # leftsinglequotemark\n34=\"65110:U+02D9\"  # dead_abovedot\n35=\"65134\"  # dead_belowcomma\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"16785455:U+202F\"  # U202F\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-0000040c.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(azerty)\n# setxkbmap -rules evdev -model pc105 -layout fr\n# Description: fr-FR\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n03=\"233:U+00E9\"  # eacute\n04=\"34:U+0022\"  # quotedbl\n05=\"39:U+0027\"  # apostrophe\n06=\"40:U+0028\"  # parenleft\n07=\"45:U+002D\"  # minus\n08=\"232:U+00E8\"  # egrave\n09=\"95:U+005F\"  # underscore\n0A=\"231:U+00E7\"  # ccedilla\n0B=\"224:U+00E0\"  # agrave\n0C=\"41:U+0029\"  # parenright\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"97:U+0061\"  # a\n11=\"122:U+007A\"  # z\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65106:U+005E\"  # dead_circumflex\n1B=\"36:U+0024\"  # dollar\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"113:U+0071\"  # q\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"109:U+006D\"  # m\n28=\"249:U+00F9\"  # ugrave\n29=\"178:U+00B2\"  # twosuperior\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"119:U+0077\"  # w\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"44:U+002C\"  # comma\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"33:U+0021\"  # exclam\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"176:U+00B0\"  # degree\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"65:U+0041\"  # A\n11=\"90:U+005A\"  # Z\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"163:U+00A3\"  # sterling\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"81:U+0051\"  # Q\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"77:U+004D\"  # M\n28=\"37:U+0025\"  # percent\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"181:U+00B5\"  # mu\n2C=\"87:U+0057\"  # W\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"63:U+003F\"  # question\n33=\"46:U+002E\"  # period\n34=\"47:U+002F\"  # slash\n35=\"167:U+00A7\"  # section\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"126:U+007E\"  # asciitilde\n04=\"35:U+0023\"  # numbersign\n05=\"123:U+007B\"  # braceleft\n06=\"91:U+005B\"  # bracketleft\n07=\"124:U+007C\"  # bar\n08=\"96:U+0060\"  # grave\n09=\"92:U+005C\"  # backslash\n0A=\"94:U+005E\"  # asciicircum\n0B=\"64:U+0040\"  # at\n0C=\"93:U+005D\"  # bracketright\n0D=\"125:U+007D\"  # braceright\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"230:U+00E6\"  # ae\n11=\"171:U+00AB\"  # guillemotleft\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"164:U+00A4\"  # currency\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"64:U+0040\"  # at\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"181:U+00B5\"  # mu\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"435:U+0142\"  # lstroke\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"65105:U+00B4\"  # dead_acute\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"198:U+00C6\"  # AE\n11=\"60:U+003C\"  # less\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"2009:U+03A9\"  # Greek_OMEGA\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"186:U+00BA\"  # masculine\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"419:U+0141\"  # Lstroke\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"65113:U+02DD\"  # dead_doubleacute\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n03=\"201:U+00C9\"  # Eacute\n04=\"34:U+0022\"  # quotedbl\n05=\"39:U+0027\"  # apostrophe\n06=\"40:U+0028\"  # parenleft\n07=\"45:U+002D\"  # minus\n08=\"200:U+00C8\"  # Egrave\n09=\"95:U+005F\"  # underscore\n0A=\"199:U+00C7\"  # Ccedilla\n0B=\"192:U+00C0\"  # Agrave\n0C=\"41:U+0029\"  # parenright\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"65:U+0041\"  # A\n11=\"90:U+005A\"  # Z\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65106:U+005E\"  # dead_circumflex\n1B=\"36:U+0024\"  # dollar\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"81:U+0051\"  # Q\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"77:U+004D\"  # M\n28=\"217:U+00D9\"  # Ugrave\n29=\"178:U+00B2\"  # twosuperior\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"87:U+0057\"  # W\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"44:U+002C\"  # comma\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"33:U+0021\"  # exclam\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"126:U+007E\"  # asciitilde\n04=\"35:U+0023\"  # numbersign\n05=\"123:U+007B\"  # braceleft\n06=\"91:U+005B\"  # bracketleft\n07=\"124:U+007C\"  # bar\n08=\"96:U+0060\"  # grave\n09=\"92:U+005C\"  # backslash\n0A=\"94:U+005E\"  # asciicircum\n0B=\"64:U+0040\"  # at\n0C=\"93:U+005D\"  # bracketright\n0D=\"125:U+007D\"  # braceright\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"198:U+00C6\"  # AE\n11=\"171:U+00AB\"  # guillemotleft\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"164:U+00A4\"  # currency\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"64:U+0040\"  # at\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"419:U+0141\"  # Lstroke\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n32=\"65105:U+00B4\"  # dead_acute\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"176:U+00B0\"  # degree\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"97:U+0061\"  # a\n11=\"122:U+007A\"  # z\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"163:U+00A3\"  # sterling\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"113:U+0071\"  # q\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"109:U+006D\"  # m\n28=\"37:U+0025\"  # percent\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2C=\"119:U+0077\"  # w\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"63:U+003F\"  # question\n33=\"46:U+002E\"  # period\n34=\"47:U+002F\"  # slash\n35=\"167:U+00A7\"  # section\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"230:U+00E6\"  # ae\n11=\"60:U+003C\"  # less\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"2009:U+03A9\"  # Greek_OMEGA\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"186:U+00BA\"  # masculine\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"435:U+0142\"  # lstroke\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"65113:U+02DD\"  # dead_doubleacute\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-0000040e.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwertz)\n# setxkbmap -rules evdev -model pc105 -layout hu\n# Description: hu-HU\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"246:U+00F6\"  # odiaeresis\n0C=\"252:U+00FC\"  # udiaeresis\n0D=\"243:U+00F3\"  # oacute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"501:U+0151\"  # odoubleacute\n1B=\"250:U+00FA\"  # uacute\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"233:U+00E9\"  # eacute\n28=\"225:U+00E1\"  # aacute\n29=\"48:U+0030\"  # 0\n2A=\"65505\"  # Shift_L\n2B=\"507:U+0171\"  # udoubleacute\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"237:U+00ED\"  # iacute\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"39:U+0027\"  # apostrophe\n03=\"34:U+0022\"  # quotedbl\n04=\"43:U+002B\"  # plus\n05=\"33:U+0021\"  # exclam\n06=\"37:U+0025\"  # percent\n07=\"47:U+002F\"  # slash\n08=\"61:U+003D\"  # equal\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"214:U+00D6\"  # Odiaeresis\n0C=\"220:U+00DC\"  # Udiaeresis\n0D=\"211:U+00D3\"  # Oacute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"469:U+0150\"  # Odoubleacute\n1B=\"218:U+00DA\"  # Uacute\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"201:U+00C9\"  # Eacute\n28=\"193:U+00C1\"  # Aacute\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"475:U+0170\"  # Udoubleacute\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"63:U+003F\"  # question\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"205:U+00CD\"  # Iacute\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"126:U+007E\"  # asciitilde\n03=\"65114:U+02C7\"  # dead_caron\n04=\"94:U+005E\"  # asciicircum\n05=\"65109:U+02D8\"  # dead_breve\n06=\"65112:U+00B0\"  # dead_abovering\n07=\"65116:U+02DB\"  # dead_ogonek\n08=\"96:U+0060\"  # grave\n09=\"65110:U+02D9\"  # dead_abovedot\n0A=\"65105:U+00B4\"  # dead_acute\n0B=\"65113:U+02DD\"  # dead_doubleacute\n0C=\"65111:U+00A8\"  # dead_diaeresis\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"92:U+005C\"  # backslash\n11=\"124:U+007C\"  # bar\n12=\"196:U+00C4\"  # Adiaeresis\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2730:U+2013\"  # endash\n16=\"8364:U+20AC\"  # EuroSign\n17=\"205:U+00CD\"  # Iacute\n18=\"2814:U+201E\"  # doublelowquotemark\n19=\"2771:U+201D\"  # rightdoublequotemark\n1A=\"247:U+00F7\"  # division\n1B=\"215:U+00D7\"  # multiply\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"228:U+00E4\"  # adiaeresis\n1F=\"496:U+0111\"  # dstroke\n20=\"464:U+0110\"  # Dstroke\n21=\"91:U+005B\"  # bracketleft\n22=\"93:U+005D\"  # bracketright\n23=\"689:U+0127\"  # hstroke\n24=\"237:U+00ED\"  # iacute\n25=\"435:U+0142\"  # lstroke\n26=\"419:U+0141\"  # Lstroke\n27=\"36:U+0024\"  # dollar\n28=\"223:U+00DF\"  # ssharp\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"164:U+00A4\"  # currency\n2C=\"62:U+003E\"  # greater\n2D=\"35:U+0023\"  # numbersign\n2E=\"38:U+0026\"  # ampersand\n2F=\"64:U+0040\"  # at\n30=\"123:U+007B\"  # braceleft\n31=\"125:U+007D\"  # braceright\n32=\"60:U+003C\"  # less\n33=\"59:U+003B\"  # semicolon\n34=\"62:U+003E\"  # greater\n35=\"42:U+002A\"  # asterisk\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"65107:U+007E\"  # dead_tilde\n03=\"439:U+02C7\"  # caron\n04=\"65106:U+005E\"  # dead_circumflex\n05=\"418:U+02D8\"  # breve\n06=\"176:U+00B0\"  # degree\n07=\"434:U+02DB\"  # ogonek\n08=\"65104:U+0060\"  # dead_grave\n09=\"511:U+02D9\"  # abovedot\n0A=\"180:U+00B4\"  # acute\n0B=\"445:U+02DD\"  # doubleacute\n0C=\"168:U+00A8\"  # diaeresis\n0D=\"184:U+00B8\"  # cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"69:U+0045\"  # E\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"237:U+00ED\"  # iacute\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"196:U+00C4\"  # Adiaeresis\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"205:U+00CD\"  # Iacute\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"162:U+00A2\"  # cent\n28=\"16785054:U+1E9E\"  # U1E9E\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"214:U+00D6\"  # Odiaeresis\n0C=\"220:U+00DC\"  # Udiaeresis\n0D=\"211:U+00D3\"  # Oacute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"469:U+0150\"  # Odoubleacute\n1B=\"218:U+00DA\"  # Uacute\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"201:U+00C9\"  # Eacute\n28=\"193:U+00C1\"  # Aacute\n29=\"48:U+0030\"  # 0\n2A=\"65505\"  # Shift_L\n2B=\"475:U+0170\"  # Udoubleacute\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"205:U+00CD\"  # Iacute\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"126:U+007E\"  # asciitilde\n03=\"65114:U+02C7\"  # dead_caron\n04=\"94:U+005E\"  # asciicircum\n05=\"65109:U+02D8\"  # dead_breve\n06=\"65112:U+00B0\"  # dead_abovering\n07=\"65116:U+02DB\"  # dead_ogonek\n08=\"96:U+0060\"  # grave\n09=\"65110:U+02D9\"  # dead_abovedot\n0A=\"65105:U+00B4\"  # dead_acute\n0B=\"65113:U+02DD\"  # dead_doubleacute\n0C=\"65111:U+00A8\"  # dead_diaeresis\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"92:U+005C\"  # backslash\n11=\"124:U+007C\"  # bar\n12=\"196:U+00C4\"  # Adiaeresis\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2730:U+2013\"  # endash\n16=\"8364:U+20AC\"  # EuroSign\n17=\"205:U+00CD\"  # Iacute\n18=\"2814:U+201E\"  # doublelowquotemark\n19=\"2771:U+201D\"  # rightdoublequotemark\n1A=\"247:U+00F7\"  # division\n1B=\"215:U+00D7\"  # multiply\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"196:U+00C4\"  # Adiaeresis\n1F=\"464:U+0110\"  # Dstroke\n20=\"464:U+0110\"  # Dstroke\n21=\"91:U+005B\"  # bracketleft\n22=\"93:U+005D\"  # bracketright\n23=\"673:U+0126\"  # Hstroke\n24=\"205:U+00CD\"  # Iacute\n25=\"419:U+0141\"  # Lstroke\n26=\"419:U+0141\"  # Lstroke\n27=\"36:U+0024\"  # dollar\n28=\"16785054:U+1E9E\"  # U1E9E\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"164:U+00A4\"  # currency\n2C=\"62:U+003E\"  # greater\n2D=\"35:U+0023\"  # numbersign\n2E=\"38:U+0026\"  # ampersand\n2F=\"64:U+0040\"  # at\n30=\"123:U+007B\"  # braceleft\n31=\"125:U+007D\"  # braceright\n32=\"60:U+003C\"  # less\n33=\"59:U+003B\"  # semicolon\n34=\"62:U+003E\"  # greater\n35=\"42:U+002A\"  # asterisk\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"39:U+0027\"  # apostrophe\n03=\"34:U+0022\"  # quotedbl\n04=\"43:U+002B\"  # plus\n05=\"33:U+0021\"  # exclam\n06=\"37:U+0025\"  # percent\n07=\"47:U+002F\"  # slash\n08=\"61:U+003D\"  # equal\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"246:U+00F6\"  # odiaeresis\n0C=\"252:U+00FC\"  # udiaeresis\n0D=\"243:U+00F3\"  # oacute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"501:U+0151\"  # odoubleacute\n1B=\"250:U+00FA\"  # uacute\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"233:U+00E9\"  # eacute\n28=\"225:U+00E1\"  # aacute\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"507:U+0171\"  # udoubleacute\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"63:U+003F\"  # question\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"237:U+00ED\"  # iacute\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"65107:U+007E\"  # dead_tilde\n03=\"439:U+02C7\"  # caron\n04=\"65106:U+005E\"  # dead_circumflex\n05=\"418:U+02D8\"  # breve\n06=\"176:U+00B0\"  # degree\n07=\"434:U+02DB\"  # ogonek\n08=\"65104:U+0060\"  # dead_grave\n09=\"511:U+02D9\"  # abovedot\n0A=\"180:U+00B4\"  # acute\n0B=\"445:U+02DD\"  # doubleacute\n0C=\"168:U+00A8\"  # diaeresis\n0D=\"184:U+00B8\"  # cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"69:U+0045\"  # E\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"205:U+00CD\"  # Iacute\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"228:U+00E4\"  # adiaeresis\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"689:U+0127\"  # hstroke\n24=\"237:U+00ED\"  # iacute\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"162:U+00A2\"  # cent\n28=\"223:U+00DF\"  # ssharp\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-00000410.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=39:39\nKey21=236:236\nKey22=65288:8\nKey23=65289:9\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=232:232\nKey35=43:43\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=242:242\nKey48=224:224\nKey49=92:92\nKey50=65505:0\nKey51=249:249\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=44:44\nKey60=46:46\nKey61=45:45\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=163:163\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=47:47\nKey17=40:40\nKey18=41:41\nKey19=61:61\nKey20=63:63\nKey21=94:94\nKey22=65288:8\nKey23=65056:0\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=233:233\nKey35=42:42\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=231:231\nKey48=176:176\nKey49=124:124\nKey50=65505:0\nKey51=167:167\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=59:59\nKey60=58:58\nKey61=95:95\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=178:178\nKey12=179:179\nKey13=188:188\nKey14=189:189\nKey15=172:172\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=96:96\nKey21=126:126\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=435:322\nKey26=8364:8364\nKey27=182:182\nKey28=956:359\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=248:248\nKey33=254:254\nKey34=91:91\nKey35=93:93\nKey36=65293:13\nKey37=65507:0\nKey38=230:230\nKey39=223:223\nKey40=240:240\nKey41=496:273\nKey42=959:331\nKey43=689:295\nKey44=65121:0\nKey45=930:312\nKey46=435:322\nKey47=64:64\nKey48=35:35\nKey49=172:172\nKey50=65505:0\nKey51=65104:96\nKey52=171:171\nKey53=187:187\nKey54=162:162\nKey55=2770:8220\nKey56=2771:8221\nKey57=241:241\nKey58=181:181\nKey59=65105:180\nKey60=183:183\nKey61=65108:175\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=65113:733\nKey12=65107:126\nKey13=2755:8539\nKey14=2756:8540\nKey15=2757:8541\nKey16=2758:8542\nKey17=2761:8482\nKey18=177:177\nKey19=65116:731\nKey20=191:191\nKey21=65106:94\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=419:321\nKey26=162:162\nKey27=174:174\nKey28=940:358\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=216:216\nKey33=222:222\nKey34=123:123\nKey35=125:125\nKey36=65293:13\nKey37=65507:0\nKey38=198:198\nKey39=167:167\nKey40=208:208\nKey41=170:170\nKey42=957:330\nKey43=673:294\nKey44=65122:0\nKey45=38:38\nKey46=419:321\nKey47=65115:184\nKey48=65112:176\nKey49=166:166\nKey50=65505:0\nKey51=65109:728\nKey52=60:60\nKey53=62:62\nKey54=169:169\nKey55=2768:8216\nKey56=2769:8217\nKey57=209:209\nKey58=186:186\nKey59=215:215\nKey60=65111:168\nKey61=247:247\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=39:39\nKey21=204:204\nKey22=65288:8\nKey23=65289:9\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=200:200\nKey35=43:43\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=210:210\nKey48=192:192\nKey49=92:92\nKey50=65505:0\nKey51=217:217\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=44:44\nKey60=46:46\nKey61=45:45\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=178:178\nKey12=179:179\nKey13=188:188\nKey14=189:189\nKey15=172:172\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=96:96\nKey21=126:126\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=419:321\nKey26=8364:8364\nKey27=182:182\nKey28=940:358\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=216:216\nKey33=222:222\nKey34=91:91\nKey35=93:93\nKey36=65293:13\nKey37=65507:0\nKey38=198:198\nKey39=223:223\nKey40=208:208\nKey41=464:272\nKey42=957:330\nKey43=673:294\nKey44=65121:0\nKey45=930:312\nKey46=419:321\nKey47=64:64\nKey48=35:35\nKey49=172:172\nKey50=65505:0\nKey51=65104:96\nKey52=171:171\nKey53=187:187\nKey54=162:162\nKey55=2770:8220\nKey56=2771:8221\nKey57=209:209\nKey58=924:0\nKey59=65105:180\nKey60=183:183\nKey61=65108:175\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=163:163\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=47:47\nKey17=40:40\nKey18=41:41\nKey19=61:61\nKey20=63:63\nKey21=94:94\nKey22=65288:8\nKey23=65056:0\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=201:201\nKey35=42:42\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=199:199\nKey48=176:176\nKey49=124:124\nKey50=65505:0\nKey51=167:167\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=59:59\nKey60=58:58\nKey61=95:95\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=65113:733\nKey12=65107:126\nKey13=2755:8539\nKey14=2756:8540\nKey15=2757:8541\nKey16=2758:8542\nKey17=2761:8482\nKey18=177:177\nKey19=65116:731\nKey20=191:191\nKey21=65106:94\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=435:322\nKey26=162:162\nKey27=174:174\nKey28=956:359\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=248:248\nKey33=254:254\nKey34=123:123\nKey35=125:125\nKey36=65293:13\nKey37=65507:0\nKey38=230:230\nKey39=167:167\nKey40=240:240\nKey41=170:170\nKey42=959:331\nKey43=689:295\nKey44=65122:0\nKey45=38:38\nKey46=435:322\nKey47=65115:184\nKey48=65112:176\nKey49=166:166\nKey50=65505:0\nKey51=65109:728\nKey52=60:60\nKey53=62:62\nKey54=169:169\nKey55=2768:8216\nKey56=2769:8217\nKey57=241:241\nKey58=186:186\nKey59=215:215\nKey60=65111:168\nKey61=247:247\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n"
  },
  {
    "path": "instfiles/km-00000410.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout it\n# Description: it-IT\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"236:U+00EC\"  # igrave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"232:U+00E8\"  # egrave\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"242:U+00F2\"  # ograve\n28=\"224:U+00E0\"  # agrave\n29=\"92:U+005C\"  # backslash\n2A=\"65505\"  # Shift_L\n2B=\"249:U+00F9\"  # ugrave\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"94:U+005E\"  # asciicircum\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"233:U+00E9\"  # eacute\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"231:U+00E7\"  # ccedilla\n28=\"176:U+00B0\"  # degree\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"167:U+00A7\"  # section\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"96:U+0060\"  # grave\n0D=\"126:U+007E\"  # asciitilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"64:U+0040\"  # at\n28=\"35:U+0023\"  # numbersign\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"241:U+00F1\"  # ntilde\n32=\"181:U+00B5\"  # mu\n33=\"65105:U+00B4\"  # dead_acute\n34=\"183:U+00B7\"  # periodcentered\n35=\"65108:U+00AF\"  # dead_macron\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"171:U+00AB\"  # guillemotleft\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"65113:U+02DD\"  # dead_doubleacute\n04=\"65107:U+007E\"  # dead_tilde\n05=\"2755:U+215B\"  # oneeighth\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"65116:U+02DB\"  # dead_ogonek\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65106:U+005E\"  # dead_circumflex\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65115:U+00B8\"  # dead_cedilla\n28=\"65112:U+00B0\"  # dead_abovering\n29=\"166:U+00A6\"  # brokenbar\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"209:U+00D1\"  # Ntilde\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"65111:U+00A8\"  # dead_diaeresis\n35=\"247:U+00F7\"  # division\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"187:U+00BB\"  # guillemotright\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"204:U+00CC\"  # Igrave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"200:U+00C8\"  # Egrave\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"210:U+00D2\"  # Ograve\n28=\"192:U+00C0\"  # Agrave\n29=\"92:U+005C\"  # backslash\n2A=\"65505\"  # Shift_L\n2B=\"217:U+00D9\"  # Ugrave\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"96:U+0060\"  # grave\n0D=\"126:U+007E\"  # asciitilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"64:U+0040\"  # at\n28=\"35:U+0023\"  # numbersign\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"209:U+00D1\"  # Ntilde\n33=\"65105:U+00B4\"  # dead_acute\n34=\"183:U+00B7\"  # periodcentered\n35=\"65108:U+00AF\"  # dead_macron\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"171:U+00AB\"  # guillemotleft\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"94:U+005E\"  # asciicircum\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"201:U+00C9\"  # Eacute\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"199:U+00C7\"  # Ccedilla\n28=\"176:U+00B0\"  # degree\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"167:U+00A7\"  # section\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"65113:U+02DD\"  # dead_doubleacute\n04=\"65107:U+007E\"  # dead_tilde\n05=\"2755:U+215B\"  # oneeighth\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"65116:U+02DB\"  # dead_ogonek\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65106:U+005E\"  # dead_circumflex\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65115:U+00B8\"  # dead_cedilla\n28=\"65112:U+00B0\"  # dead_abovering\n29=\"166:U+00A6\"  # brokenbar\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"241:U+00F1\"  # ntilde\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"65111:U+00A8\"  # dead_diaeresis\n35=\"247:U+00F7\"  # division\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"187:U+00BB\"  # guillemotright\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00000411.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=94:94\nKey22=65288:8\nKey23=65289:9\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=64:64\nKey35=91:91\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=59:59\nKey48=58:58\nKey49=65322:0\nKey50=65505:0\nKey51=93:93\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=44:44\nKey60=46:46\nKey61=47:47\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65328:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey133=165:165\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=39:39\nKey17=40:40\nKey18=41:41\nKey19=48:48\nKey20=61:61\nKey21=126:126\nKey22=65288:8\nKey23=65056:0\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=96:96\nKey35=123:123\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=43:43\nKey48=42:42\nKey49=65322:0\nKey50=65505:0\nKey51=125:125\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=60:60\nKey60=62:62\nKey61=63:63\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey133=124:124\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=94:94\nKey22=65288:8\nKey23=65289:9\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=64:64\nKey35=91:91\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=59:59\nKey48=58:58\nKey49=65322:0\nKey50=65505:0\nKey51=93:93\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=44:44\nKey60=46:46\nKey61=47:47\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65328:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey133=165:165\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=39:39\nKey17=40:40\nKey18=41:41\nKey19=48:48\nKey20=61:61\nKey21=126:126\nKey22=65288:8\nKey23=65056:0\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=96:96\nKey35=123:123\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=43:43\nKey48=42:42\nKey49=65322:0\nKey50=65505:0\nKey51=125:125\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=60:60\nKey60=62:62\nKey61=63:63\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey133=124:124\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=94:94\nKey22=65288:8\nKey23=65289:9\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=64:64\nKey35=91:91\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=59:59\nKey48=58:58\nKey49=65322:0\nKey50=65505:0\nKey51=93:93\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=44:44\nKey60=46:46\nKey61=47:47\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65328:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey133=165:165\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=94:94\nKey22=65288:8\nKey23=65289:9\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=64:64\nKey35=91:91\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=59:59\nKey48=58:58\nKey49=65322:0\nKey50=65505:0\nKey51=93:93\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=44:44\nKey60=46:46\nKey61=47:47\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65328:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey133=165:165\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=39:39\nKey17=40:40\nKey18=41:41\nKey19=48:48\nKey20=61:61\nKey21=126:126\nKey22=65288:8\nKey23=65056:0\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=96:96\nKey35=123:123\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=43:43\nKey48=42:42\nKey49=65322:0\nKey50=65505:0\nKey51=125:125\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=60:60\nKey60=62:62\nKey61=63:63\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey133=124:124\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=39:39\nKey17=40:40\nKey18=41:41\nKey19=48:48\nKey20=61:61\nKey21=126:126\nKey22=65288:8\nKey23=65056:0\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=96:96\nKey35=123:123\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=43:43\nKey48=42:42\nKey49=65322:0\nKey50=65505:0\nKey51=125:125\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=60:60\nKey60=62:62\nKey61=63:63\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey133=124:124\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n"
  },
  {
    "path": "instfiles/km-00000411.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout jp -variant OADG109A\n# Description: ja-JP\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"94:U+005E\"  # asciicircum\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"64:U+0040\"  # at\n1B=\"91:U+005B\"  # bracketleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"59:U+003B\"  # semicolon\n28=\"58:U+003A\"  # colon\n29=\"65322\"  # Zenkaku_Hankaku\n2A=\"65505\"  # Shift_L\n2B=\"93:U+005D\"  # bracketright\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65328\"  # Eisu_toggle\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"92:U+005C\"  # backslash\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7D=\"165:U+00A5\"  # yen\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"39:U+0027\"  # apostrophe\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"48:U+0030\"  # 0\n0C=\"61:U+003D\"  # equal\n0D=\"126:U+007E\"  # asciitilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"96:U+0060\"  # grave\n1B=\"123:U+007B\"  # braceleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"43:U+002B\"  # plus\n28=\"42:U+002A\"  # asterisk\n29=\"65322\"  # Zenkaku_Hankaku\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"95:U+005F\"  # underscore\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7D=\"124:U+007C\"  # bar\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"94:U+005E\"  # asciicircum\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"64:U+0040\"  # at\n1B=\"91:U+005B\"  # bracketleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"59:U+003B\"  # semicolon\n28=\"58:U+003A\"  # colon\n29=\"65322\"  # Zenkaku_Hankaku\n2A=\"65505\"  # Shift_L\n2B=\"93:U+005D\"  # bracketright\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65328\"  # Eisu_toggle\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"92:U+005C\"  # backslash\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7D=\"165:U+00A5\"  # yen\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"39:U+0027\"  # apostrophe\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"48:U+0030\"  # 0\n0C=\"61:U+003D\"  # equal\n0D=\"126:U+007E\"  # asciitilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"96:U+0060\"  # grave\n1B=\"123:U+007B\"  # braceleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"43:U+002B\"  # plus\n28=\"42:U+002A\"  # asterisk\n29=\"65322\"  # Zenkaku_Hankaku\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"95:U+005F\"  # underscore\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7D=\"124:U+007C\"  # bar\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"94:U+005E\"  # asciicircum\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"64:U+0040\"  # at\n1B=\"91:U+005B\"  # bracketleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"59:U+003B\"  # semicolon\n28=\"58:U+003A\"  # colon\n29=\"65322\"  # Zenkaku_Hankaku\n2A=\"65505\"  # Shift_L\n2B=\"93:U+005D\"  # bracketright\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65328\"  # Eisu_toggle\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"92:U+005C\"  # backslash\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7D=\"165:U+00A5\"  # yen\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"94:U+005E\"  # asciicircum\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"64:U+0040\"  # at\n1B=\"91:U+005B\"  # bracketleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"59:U+003B\"  # semicolon\n28=\"58:U+003A\"  # colon\n29=\"65322\"  # Zenkaku_Hankaku\n2A=\"65505\"  # Shift_L\n2B=\"93:U+005D\"  # bracketright\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65328\"  # Eisu_toggle\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"92:U+005C\"  # backslash\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7D=\"165:U+00A5\"  # yen\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"39:U+0027\"  # apostrophe\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"48:U+0030\"  # 0\n0C=\"61:U+003D\"  # equal\n0D=\"126:U+007E\"  # asciitilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"96:U+0060\"  # grave\n1B=\"123:U+007B\"  # braceleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"43:U+002B\"  # plus\n28=\"42:U+002A\"  # asterisk\n29=\"65322\"  # Zenkaku_Hankaku\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"95:U+005F\"  # underscore\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7D=\"124:U+007C\"  # bar\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"39:U+0027\"  # apostrophe\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"48:U+0030\"  # 0\n0C=\"61:U+003D\"  # equal\n0D=\"126:U+007E\"  # asciitilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"96:U+0060\"  # grave\n1B=\"123:U+007B\"  # braceleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"43:U+002B\"  # plus\n28=\"42:U+002A\"  # asterisk\n29=\"65322\"  # Zenkaku_Hankaku\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"95:U+005F\"  # underscore\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7D=\"124:U+007C\"  # bar\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00000412.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout kr\n# Description: ko-KR\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00000414.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout no\n# Description: nb-NO\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"43:U+002B\"  # plus\n0D=\"92:U+005C\"  # backslash\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"229:U+00E5\"  # aring\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"248:U+00F8\"  # oslash\n28=\"230:U+00E6\"  # ae\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"164:U+00A4\"  # currency\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"197:U+00C5\"  # Aring\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"216:U+00D8\"  # Oslash\n28=\"198:U+00C6\"  # AE\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"16786117:U+22C5\"  # U22C5\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"16785938:U+2212\"  # U2212\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"16785941:U+2215\"  # U2215\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"189:U+00BD\"  # onehalf\n07=\"165:U+00A5\"  # yen\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"177:U+00B1\"  # plusminus\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"254:U+00FE\"  # thorn\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5053:U+0153\"  # oe\n19=\"2032:U+03C0\"  # Greek_pi\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"170:U+00AA\"  # ordfeminine\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"166:U+00A6\"  # brokenbar\n2A=\"65505\"  # Shift_L\n2B=\"65113:U+02DD\"  # dead_doubleacute\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"65115:U+00B8\"  # dead_cedilla\n34=\"2734:U+2026\"  # ellipsis\n35=\"2730:U+2013\"  # endash\n36=\"65506\"  # Shift_R\n38=\"65513\"  # Alt_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"16785938:U+2212\"  # U2212\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"189:U+00BD\"  # onehalf\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"16785456:U+2030\"  # U2030\n07=\"2757:U+215D\"  # fiveeighths\n08=\"247:U+00F7\"  # division\n09=\"171:U+00AB\"  # guillemotleft\n0A=\"187:U+00BB\"  # guillemotright\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"172:U+00AC\"  # notsign\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"162:U+00A2\"  # cent\n13=\"2761:U+2122\"  # trademark\n14=\"222:U+00DE\"  # THORN\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5052:U+0152\"  # OE\n19=\"2000:U+03A0\"  # Greek_PI\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65114:U+02C7\"  # dead_caron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"186:U+00BA\"  # masculine\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"182:U+00B6\"  # paragraph\n2A=\"65505\"  # Shift_L\n2B=\"215:U+00D7\"  # multiply\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"65116:U+02DB\"  # dead_ogonek\n34=\"183:U+00B7\"  # periodcentered\n35=\"2729:U+2014\"  # emdash\n36=\"65506\"  # Shift_R\n37=\"16777215\"  # VoidSymbol\n38=\"65511\"  # Meta_L\n39=\"16785455:U+202F\"  # U202F\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"16777215\"  # VoidSymbol\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"16777215\"  # VoidSymbol\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"190:U+00BE\"  # threequarters\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"16777215\"  # VoidSymbol\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"43:U+002B\"  # plus\n0D=\"92:U+005C\"  # backslash\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"197:U+00C5\"  # Aring\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"216:U+00D8\"  # Oslash\n28=\"198:U+00C6\"  # AE\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"189:U+00BD\"  # onehalf\n07=\"165:U+00A5\"  # yen\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"177:U+00B1\"  # plusminus\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"222:U+00DE\"  # THORN\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5052:U+0152\"  # OE\n19=\"2000:U+03A0\"  # Greek_PI\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"170:U+00AA\"  # ordfeminine\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"166:U+00A6\"  # brokenbar\n2A=\"65505\"  # Shift_L\n2B=\"65113:U+02DD\"  # dead_doubleacute\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"65115:U+00B8\"  # dead_cedilla\n34=\"2734:U+2026\"  # ellipsis\n35=\"2730:U+2013\"  # endash\n36=\"65506\"  # Shift_R\n38=\"65513\"  # Alt_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"16785938:U+2212\"  # U2212\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"189:U+00BD\"  # onehalf\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"164:U+00A4\"  # currency\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"229:U+00E5\"  # aring\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"248:U+00F8\"  # oslash\n28=\"230:U+00E6\"  # ae\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"16786117:U+22C5\"  # U22C5\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"16785938:U+2212\"  # U2212\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"16785941:U+2215\"  # U2215\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"16785456:U+2030\"  # U2030\n07=\"2757:U+215D\"  # fiveeighths\n08=\"247:U+00F7\"  # division\n09=\"171:U+00AB\"  # guillemotleft\n0A=\"187:U+00BB\"  # guillemotright\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"172:U+00AC\"  # notsign\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"162:U+00A2\"  # cent\n13=\"2761:U+2122\"  # trademark\n14=\"254:U+00FE\"  # thorn\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5053:U+0153\"  # oe\n19=\"2032:U+03C0\"  # Greek_pi\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65114:U+02C7\"  # dead_caron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"186:U+00BA\"  # masculine\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"182:U+00B6\"  # paragraph\n2A=\"65505\"  # Shift_L\n2B=\"215:U+00D7\"  # multiply\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"65116:U+02DB\"  # dead_ogonek\n34=\"183:U+00B7\"  # periodcentered\n35=\"2729:U+2014\"  # emdash\n36=\"65506\"  # Shift_R\n37=\"16777215\"  # VoidSymbol\n38=\"65511\"  # Meta_L\n39=\"16785455:U+202F\"  # U202F\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"16777215\"  # VoidSymbol\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"16777215\"  # VoidSymbol\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"190:U+00BE\"  # threequarters\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"16777215\"  # VoidSymbol\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-00000415.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=61:61\nKey22=65288:8\nKey23=65289:9\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=91:91\nKey35=93:93\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=59:59\nKey48=39:39\nKey49=96:96\nKey50=65505:0\nKey51=92:92\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=44:44\nKey60=46:46\nKey61=47:47\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=64:64\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=94:94\nKey16=38:38\nKey17=42:42\nKey18=40:40\nKey19=41:41\nKey20=95:95\nKey21=43:43\nKey22=65288:8\nKey23=65056:0\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=123:123\nKey35=125:125\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=58:58\nKey48=34:34\nKey49=126:126\nKey50=65505:0\nKey51=124:124\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=60:60\nKey60=62:62\nKey61=63:63\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=2237:8800\nKey11=178:178\nKey12=179:179\nKey13=162:162\nKey14=8364:8364\nKey15=189:189\nKey16=167:167\nKey17=183:183\nKey18=171:171\nKey19=187:187\nKey20=2730:8211\nKey21=65115:184\nKey22=65288:8\nKey23=65289:9\nKey24=2032:960\nKey25=5053:339\nKey26=490:281\nKey27=169:169\nKey28=223:223\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=243:243\nKey33=254:254\nKey34=65111:168\nKey35=65107:126\nKey36=65293:13\nKey37=65507:0\nKey38=433:261\nKey39=438:347\nKey40=240:240\nKey41=230:230\nKey42=959:331\nKey43=2769:8217\nKey44=16777817:601\nKey45=2734:8230\nKey46=435:322\nKey47=65105:180\nKey48=65106:94\nKey49=172:172\nKey50=65505:0\nKey51=65104:96\nKey52=447:380\nKey53=444:378\nKey54=486:263\nKey55=2814:8222\nKey56=2771:8221\nKey57=497:324\nKey58=181:181\nKey59=2236:8804\nKey60=2238:8805\nKey61=65120:0\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=160:160\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=191:191\nKey12=163:163\nKey13=188:188\nKey14=16785456:8240\nKey15=2270:8743\nKey16=16785992:8776\nKey17=190:190\nKey18=177:177\nKey19=176:176\nKey20=2729:8212\nKey21=65116:731\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=5052:338\nKey26=458:280\nKey27=174:174\nKey28=2761:8482\nKey29=165:165\nKey30=2300:8593\nKey31=16785812:8596\nKey32=211:211\nKey33=222:222\nKey34=65112:176\nKey35=65108:175\nKey36=65293:13\nKey37=65507:0\nKey38=417:260\nKey39=422:346\nKey40=208:208\nKey41=198:198\nKey42=957:330\nKey43=16785442:8226\nKey44=16777615:399\nKey45=65123:0\nKey46=419:321\nKey47=65113:733\nKey48=65114:711\nKey49=2271:8744\nKey50=65505:0\nKey51=65109:728\nKey52=431:379\nKey53=428:377\nKey54=454:262\nKey55=2768:8216\nKey56=2770:8220\nKey57=465:323\nKey58=2242:8734\nKey59=215:215\nKey60=247:247\nKey61=65110:729\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=160:160\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=61:61\nKey22=65288:8\nKey23=65289:9\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=91:91\nKey35=93:93\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=59:59\nKey48=39:39\nKey49=96:96\nKey50=65505:0\nKey51=92:92\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=44:44\nKey60=46:46\nKey61=47:47\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=2237:8800\nKey11=178:178\nKey12=179:179\nKey13=162:162\nKey14=8364:8364\nKey15=189:189\nKey16=167:167\nKey17=183:183\nKey18=171:171\nKey19=187:187\nKey20=2730:8211\nKey21=65115:184\nKey22=65288:8\nKey23=65289:9\nKey24=2009:937\nKey25=5052:338\nKey26=458:280\nKey27=169:169\nKey28=223:223\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=211:211\nKey33=222:222\nKey34=65111:168\nKey35=65107:126\nKey36=65293:13\nKey37=65507:0\nKey38=417:260\nKey39=422:346\nKey40=208:208\nKey41=198:198\nKey42=957:330\nKey43=2769:8217\nKey44=16777615:399\nKey45=2734:8230\nKey46=419:321\nKey47=65105:180\nKey48=65106:94\nKey49=172:172\nKey50=65505:0\nKey51=65104:96\nKey52=431:379\nKey53=428:377\nKey54=454:262\nKey55=2814:8222\nKey56=2771:8221\nKey57=465:323\nKey58=924:0\nKey59=2236:8804\nKey60=2238:8805\nKey61=65120:0\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=160:160\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=64:64\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=94:94\nKey16=38:38\nKey17=42:42\nKey18=40:40\nKey19=41:41\nKey20=95:95\nKey21=43:43\nKey22=65288:8\nKey23=65056:0\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=123:123\nKey35=125:125\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=58:58\nKey48=34:34\nKey49=126:126\nKey50=65505:0\nKey51=124:124\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=60:60\nKey60=62:62\nKey61=63:63\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=191:191\nKey12=163:163\nKey13=188:188\nKey14=16785456:8240\nKey15=2270:8743\nKey16=16785992:8776\nKey17=190:190\nKey18=177:177\nKey19=176:176\nKey20=2729:8212\nKey21=65116:731\nKey22=65288:8\nKey23=65056:0\nKey24=2032:960\nKey25=5053:339\nKey26=490:281\nKey27=174:174\nKey28=2761:8482\nKey29=165:165\nKey30=2300:8593\nKey31=16785812:8596\nKey32=243:243\nKey33=254:254\nKey34=65112:176\nKey35=65108:175\nKey36=65293:13\nKey37=65507:0\nKey38=433:261\nKey39=438:347\nKey40=240:240\nKey41=230:230\nKey42=959:331\nKey43=16785442:8226\nKey44=16777817:601\nKey45=65123:0\nKey46=435:322\nKey47=65113:733\nKey48=65114:711\nKey49=2271:8744\nKey50=65505:0\nKey51=65109:728\nKey52=447:380\nKey53=444:378\nKey54=486:263\nKey55=2768:8216\nKey56=2770:8220\nKey57=497:324\nKey58=2242:8734\nKey59=215:215\nKey60=247:247\nKey61=65110:729\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=160:160\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n"
  },
  {
    "path": "instfiles/km-00000415.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout pl\n# Description: pl-PL\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"2237:U+2260\"  # notequal\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"162:U+00A2\"  # cent\n06=\"8364:U+20AC\"  # EuroSign\n07=\"189:U+00BD\"  # onehalf\n08=\"167:U+00A7\"  # section\n09=\"183:U+00B7\"  # periodcentered\n0A=\"171:U+00AB\"  # guillemotleft\n0B=\"187:U+00BB\"  # guillemotright\n0C=\"2730:U+2013\"  # endash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"2032:U+03C0\"  # Greek_pi\n11=\"5053:U+0153\"  # oe\n12=\"490:U+0119\"  # eogonek\n13=\"169:U+00A9\"  # copyright\n14=\"223:U+00DF\"  # ssharp\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"243:U+00F3\"  # oacute\n19=\"254:U+00FE\"  # thorn\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"433:U+0105\"  # aogonek\n1F=\"438:U+015B\"  # sacute\n20=\"240:U+00F0\"  # eth\n21=\"230:U+00E6\"  # ae\n22=\"959:U+014B\"  # eng\n23=\"2769:U+2019\"  # rightsinglequotemark\n24=\"16777817:U+0259\"  # schwa\n25=\"2734:U+2026\"  # ellipsis\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"447:U+017C\"  # zabovedot\n2D=\"444:U+017A\"  # zacute\n2E=\"486:U+0107\"  # cacute\n2F=\"2814:U+201E\"  # doublelowquotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"497:U+0144\"  # nacute\n32=\"181:U+00B5\"  # mu\n33=\"2236:U+2264\"  # lessthanequal\n34=\"2238:U+2265\"  # greaterthanequal\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"191:U+00BF\"  # questiondown\n04=\"163:U+00A3\"  # sterling\n05=\"188:U+00BC\"  # onequarter\n06=\"16785456:U+2030\"  # U2030\n07=\"2270:U+2227\"  # logicaland\n08=\"16785992:U+2248\"  # approxeq\n09=\"190:U+00BE\"  # threequarters\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"2729:U+2014\"  # emdash\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"5052:U+0152\"  # OE\n12=\"458:U+0118\"  # Eogonek\n13=\"174:U+00AE\"  # registered\n14=\"2761:U+2122\"  # trademark\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"16785812:U+2194\"  # U2194\n18=\"211:U+00D3\"  # Oacute\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"417:U+0104\"  # Aogonek\n1F=\"422:U+015A\"  # Sacute\n20=\"208:U+00D0\"  # ETH\n21=\"198:U+00C6\"  # AE\n22=\"957:U+014A\"  # ENG\n23=\"16785442:U+2022\"  # U2022\n24=\"16777615:U+018F\"  # SCHWA\n25=\"65123\"  # dead_stroke\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"2271:U+2228\"  # logicalor\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"431:U+017B\"  # Zabovedot\n2D=\"428:U+0179\"  # Zacute\n2E=\"454:U+0106\"  # Cacute\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2770:U+201C\"  # leftdoublequotemark\n31=\"465:U+0143\"  # Nacute\n32=\"2242:U+221E\"  # infinity\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"2237:U+2260\"  # notequal\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"162:U+00A2\"  # cent\n06=\"8364:U+20AC\"  # EuroSign\n07=\"189:U+00BD\"  # onehalf\n08=\"167:U+00A7\"  # section\n09=\"183:U+00B7\"  # periodcentered\n0A=\"171:U+00AB\"  # guillemotleft\n0B=\"187:U+00BB\"  # guillemotright\n0C=\"2730:U+2013\"  # endash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"5052:U+0152\"  # OE\n12=\"458:U+0118\"  # Eogonek\n13=\"169:U+00A9\"  # copyright\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"211:U+00D3\"  # Oacute\n19=\"222:U+00DE\"  # THORN\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"417:U+0104\"  # Aogonek\n1F=\"422:U+015A\"  # Sacute\n20=\"208:U+00D0\"  # ETH\n21=\"198:U+00C6\"  # AE\n22=\"957:U+014A\"  # ENG\n23=\"2769:U+2019\"  # rightsinglequotemark\n24=\"16777615:U+018F\"  # SCHWA\n25=\"2734:U+2026\"  # ellipsis\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"431:U+017B\"  # Zabovedot\n2D=\"428:U+0179\"  # Zacute\n2E=\"454:U+0106\"  # Cacute\n2F=\"2814:U+201E\"  # doublelowquotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"465:U+0143\"  # Nacute\n33=\"2236:U+2264\"  # lessthanequal\n34=\"2238:U+2265\"  # greaterthanequal\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"191:U+00BF\"  # questiondown\n04=\"163:U+00A3\"  # sterling\n05=\"188:U+00BC\"  # onequarter\n06=\"16785456:U+2030\"  # U2030\n07=\"2270:U+2227\"  # logicaland\n08=\"16785992:U+2248\"  # approxeq\n09=\"190:U+00BE\"  # threequarters\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"2729:U+2014\"  # emdash\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2032:U+03C0\"  # Greek_pi\n11=\"5053:U+0153\"  # oe\n12=\"490:U+0119\"  # eogonek\n13=\"174:U+00AE\"  # registered\n14=\"2761:U+2122\"  # trademark\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"16785812:U+2194\"  # U2194\n18=\"243:U+00F3\"  # oacute\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"433:U+0105\"  # aogonek\n1F=\"438:U+015B\"  # sacute\n20=\"240:U+00F0\"  # eth\n21=\"230:U+00E6\"  # ae\n22=\"959:U+014B\"  # eng\n23=\"16785442:U+2022\"  # U2022\n24=\"16777817:U+0259\"  # schwa\n25=\"65123\"  # dead_stroke\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"2271:U+2228\"  # logicalor\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"447:U+017C\"  # zabovedot\n2D=\"444:U+017A\"  # zacute\n2E=\"486:U+0107\"  # cacute\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2770:U+201C\"  # leftdoublequotemark\n31=\"497:U+0144\"  # nacute\n32=\"2242:U+221E\"  # infinity\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-00000416.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout br\n# Description: pt-BR\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65105:U+00B4\"  # dead_acute\n1B=\"91:U+005B\"  # bracketleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"231:U+00E7\"  # ccedilla\n28=\"65107:U+007E\"  # dead_tilde\n29=\"39:U+0027\"  # apostrophe\n2A=\"65505\"  # Shift_L\n2B=\"93:U+005D\"  # bracketright\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"59:U+003B\"  # semicolon\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"47:U+002F\"  # slash\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"65111:U+00A8\"  # dead_diaeresis\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65104:U+0060\"  # dead_grave\n1B=\"123:U+007B\"  # braceleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"199:U+00C7\"  # Ccedilla\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"34:U+0022\"  # quotedbl\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"58:U+003A\"  # colon\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"63:U+003F\"  # question\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"163:U+00A3\"  # sterling\n06=\"162:U+00A2\"  # cent\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"167:U+00A7\"  # section\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"47:U+002F\"  # slash\n11=\"63:U+003F\"  # question\n12=\"176:U+00B0\"  # degree\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"180:U+00B4\"  # acute\n1B=\"170:U+00AA\"  # ordfeminine\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"126:U+007E\"  # asciitilde\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"186:U+00BA\"  # masculine\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65114:U+02C7\"  # dead_caron\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"176:U+00B0\"  # degree\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"189:U+00BD\"  # onehalf\n04=\"190:U+00BE\"  # threequarters\n05=\"188:U+00BC\"  # onequarter\n06=\"2756:U+215C\"  # threeeighths\n07=\"168:U+00A8\"  # diaeresis\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"47:U+002F\"  # slash\n11=\"63:U+003F\"  # question\n12=\"176:U+00B0\"  # degree\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"96:U+0060\"  # grave\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"94:U+005E\"  # asciicircum\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"186:U+00BA\"  # masculine\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"181:U+00B5\"  # mu\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65109:U+02D8\"  # dead_breve\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"191:U+00BF\"  # questiondown\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65105:U+00B4\"  # dead_acute\n1B=\"91:U+005B\"  # bracketleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"199:U+00C7\"  # Ccedilla\n28=\"65107:U+007E\"  # dead_tilde\n29=\"39:U+0027\"  # apostrophe\n2A=\"65505\"  # Shift_L\n2B=\"93:U+005D\"  # bracketright\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"59:U+003B\"  # semicolon\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"47:U+002F\"  # slash\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"163:U+00A3\"  # sterling\n06=\"162:U+00A2\"  # cent\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"167:U+00A7\"  # section\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"47:U+002F\"  # slash\n11=\"63:U+003F\"  # question\n12=\"176:U+00B0\"  # degree\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"180:U+00B4\"  # acute\n1B=\"170:U+00AA\"  # ordfeminine\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"126:U+007E\"  # asciitilde\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"186:U+00BA\"  # masculine\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65114:U+02C7\"  # dead_caron\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"176:U+00B0\"  # degree\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"65111:U+00A8\"  # dead_diaeresis\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65104:U+0060\"  # dead_grave\n1B=\"123:U+007B\"  # braceleft\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"231:U+00E7\"  # ccedilla\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"34:U+0022\"  # quotedbl\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"58:U+003A\"  # colon\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"63:U+003F\"  # question\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"189:U+00BD\"  # onehalf\n04=\"190:U+00BE\"  # threequarters\n05=\"188:U+00BC\"  # onequarter\n06=\"2756:U+215C\"  # threeeighths\n07=\"168:U+00A8\"  # diaeresis\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"47:U+002F\"  # slash\n11=\"63:U+003F\"  # question\n12=\"176:U+00B0\"  # degree\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"96:U+0060\"  # grave\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"94:U+005E\"  # asciicircum\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"186:U+00BA\"  # masculine\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65109:U+02D8\"  # dead_breve\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n73=\"191:U+00BF\"  # questiondown\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-00000419.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=61:61\nKey22=65288:8\nKey23=65289:9\nKey24=1738:1081\nKey25=1731:1094\nKey26=1749:1091\nKey27=1739:1082\nKey28=1733:1077\nKey29=1742:1085\nKey30=1735:1075\nKey31=1755:1096\nKey32=1757:1097\nKey33=1754:1079\nKey34=1736:1093\nKey35=1759:1098\nKey36=65293:13\nKey37=65507:0\nKey38=1734:1092\nKey39=1753:1099\nKey40=1751:1074\nKey41=1729:1072\nKey42=1744:1087\nKey43=1746:1088\nKey44=1743:1086\nKey45=1740:1083\nKey46=1732:1076\nKey47=1750:1078\nKey48=1756:1101\nKey49=1699:1105\nKey50=65505:0\nKey51=92:92\nKey52=1745:1103\nKey53=1758:1095\nKey54=1747:1089\nKey55=1741:1084\nKey56=1737:1080\nKey57=1748:1090\nKey58=1752:1100\nKey59=1730:1073\nKey60=1728:1102\nKey61=46:46\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=1712:8470\nKey13=59:59\nKey14=37:37\nKey15=58:58\nKey16=63:63\nKey17=42:42\nKey18=40:40\nKey19=41:41\nKey20=95:95\nKey21=43:43\nKey22=65288:8\nKey23=65056:0\nKey24=1770:1049\nKey25=1763:1062\nKey26=1781:1059\nKey27=1771:1050\nKey28=1765:1045\nKey29=1774:1053\nKey30=1767:1043\nKey31=1787:1064\nKey32=1789:1065\nKey33=1786:1047\nKey34=1768:1061\nKey35=1791:1066\nKey36=65293:13\nKey37=65507:0\nKey38=1766:1060\nKey39=1785:1067\nKey40=1783:1042\nKey41=1761:1040\nKey42=1776:1055\nKey43=1778:1056\nKey44=1775:1054\nKey45=1772:1051\nKey46=1764:1044\nKey47=1782:1046\nKey48=1788:1069\nKey49=1715:1025\nKey50=65505:0\nKey51=47:47\nKey52=1777:1071\nKey53=1790:1063\nKey54=1779:1057\nKey55=1773:1052\nKey56=1769:1048\nKey57=1780:1058\nKey58=1784:1068\nKey59=1762:1041\nKey60=1760:1070\nKey61=44:44\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=16785597:8381\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=61:61\nKey22=65288:8\nKey23=65289:9\nKey24=1738:1081\nKey25=1731:1094\nKey26=1749:1091\nKey27=1739:1082\nKey28=1733:1077\nKey29=1742:1085\nKey30=1735:1075\nKey31=1755:1096\nKey32=1757:1097\nKey33=1754:1079\nKey34=1736:1093\nKey35=1759:1098\nKey36=65293:13\nKey37=65507:0\nKey38=1734:1092\nKey39=1753:1099\nKey40=1751:1074\nKey41=1729:1072\nKey42=1744:1087\nKey43=1746:1088\nKey44=1743:1086\nKey45=1740:1083\nKey46=1732:1076\nKey47=1750:1078\nKey48=1756:1101\nKey49=1699:1105\nKey50=65505:0\nKey51=92:92\nKey52=1745:1103\nKey53=1758:1095\nKey54=1747:1089\nKey55=1741:1084\nKey56=1737:1080\nKey57=1748:1090\nKey58=1752:1100\nKey59=1730:1073\nKey60=1728:1102\nKey61=46:46\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=1712:8470\nKey13=59:59\nKey14=37:37\nKey15=58:58\nKey16=63:63\nKey18=40:40\nKey19=41:41\nKey20=95:95\nKey21=43:43\nKey22=65288:8\nKey23=65056:0\nKey24=1770:1049\nKey25=1763:1062\nKey26=1781:1059\nKey27=1771:1050\nKey28=1765:1045\nKey29=1774:1053\nKey30=1767:1043\nKey31=1787:1064\nKey32=1789:1065\nKey33=1786:1047\nKey34=1768:1061\nKey35=1791:1066\nKey36=65293:13\nKey37=65507:0\nKey38=1766:1060\nKey39=1785:1067\nKey40=1783:1042\nKey41=1761:1040\nKey42=1776:1055\nKey43=1778:1056\nKey44=1775:1054\nKey45=1772:1051\nKey46=1764:1044\nKey47=1782:1046\nKey48=1788:1069\nKey49=1715:1025\nKey50=65505:0\nKey51=47:47\nKey52=1777:1071\nKey53=1790:1063\nKey54=1779:1057\nKey55=1773:1052\nKey56=1769:1048\nKey57=1780:1058\nKey58=1784:1068\nKey59=1762:1041\nKey60=1760:1070\nKey61=44:44\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=61:61\nKey22=65288:8\nKey23=65289:9\nKey24=1770:1049\nKey25=1763:1062\nKey26=1781:1059\nKey27=1771:1050\nKey28=1765:1045\nKey29=1774:1053\nKey30=1767:1043\nKey31=1787:1064\nKey32=1789:1065\nKey33=1786:1047\nKey34=1768:1061\nKey35=1791:1066\nKey36=65293:13\nKey37=65507:0\nKey38=1766:1060\nKey39=1785:1067\nKey40=1783:1042\nKey41=1761:1040\nKey42=1776:1055\nKey43=1778:1056\nKey44=1775:1054\nKey45=1772:1051\nKey46=1764:1044\nKey47=1782:1046\nKey48=1788:1069\nKey49=1715:1025\nKey50=65505:0\nKey51=92:92\nKey52=1777:1071\nKey53=1790:1063\nKey54=1779:1057\nKey55=1773:1052\nKey56=1769:1048\nKey57=1780:1058\nKey58=1784:1068\nKey59=1762:1041\nKey60=1760:1070\nKey61=46:46\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=16785597:8381\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=61:61\nKey22=65288:8\nKey23=65289:9\nKey24=1770:1049\nKey25=1763:1062\nKey26=1781:1059\nKey27=1771:1050\nKey28=1765:1045\nKey29=1774:1053\nKey30=1767:1043\nKey31=1787:1064\nKey32=1789:1065\nKey33=1786:1047\nKey34=1768:1061\nKey35=1791:1066\nKey36=65293:13\nKey37=65507:0\nKey38=1766:1060\nKey39=1785:1067\nKey40=1783:1042\nKey41=1761:1040\nKey42=1776:1055\nKey43=1778:1056\nKey44=1775:1054\nKey45=1772:1051\nKey46=1764:1044\nKey47=1782:1046\nKey48=1788:1069\nKey49=1715:1025\nKey50=65505:0\nKey51=92:92\nKey52=1777:1071\nKey53=1790:1063\nKey54=1779:1057\nKey55=1773:1052\nKey56=1769:1048\nKey57=1780:1058\nKey58=1784:1068\nKey59=1762:1041\nKey60=1760:1070\nKey61=46:46\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=1712:8470\nKey13=59:59\nKey14=37:37\nKey15=58:58\nKey16=63:63\nKey17=42:42\nKey18=40:40\nKey19=41:41\nKey20=95:95\nKey21=43:43\nKey22=65288:8\nKey23=65056:0\nKey24=1738:1081\nKey25=1731:1094\nKey26=1749:1091\nKey27=1739:1082\nKey28=1733:1077\nKey29=1742:1085\nKey30=1735:1075\nKey31=1755:1096\nKey32=1757:1097\nKey33=1754:1079\nKey34=1736:1093\nKey35=1759:1098\nKey36=65293:13\nKey37=65507:0\nKey38=1734:1092\nKey39=1753:1099\nKey40=1751:1074\nKey41=1729:1072\nKey42=1744:1087\nKey43=1746:1088\nKey44=1743:1086\nKey45=1740:1083\nKey46=1732:1076\nKey47=1750:1078\nKey48=1756:1101\nKey49=1699:1105\nKey50=65505:0\nKey51=47:47\nKey52=1745:1103\nKey53=1758:1095\nKey54=1747:1089\nKey55=1741:1084\nKey56=1737:1080\nKey57=1748:1090\nKey58=1752:1100\nKey59=1730:1073\nKey60=1728:1102\nKey61=44:44\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=1712:8470\nKey13=59:59\nKey14=37:37\nKey15=58:58\nKey16=63:63\nKey18=40:40\nKey19=41:41\nKey20=95:95\nKey21=43:43\nKey22=65288:8\nKey23=65056:0\nKey24=1738:1081\nKey25=1731:1094\nKey26=1749:1091\nKey27=1739:1082\nKey28=1733:1077\nKey29=1742:1085\nKey30=1735:1075\nKey31=1755:1096\nKey32=1757:1097\nKey33=1754:1079\nKey34=1736:1093\nKey35=1759:1098\nKey36=65293:13\nKey37=65507:0\nKey38=1734:1092\nKey39=1753:1099\nKey40=1751:1074\nKey41=1729:1072\nKey42=1744:1087\nKey43=1746:1088\nKey44=1743:1086\nKey45=1740:1083\nKey46=1732:1076\nKey47=1750:1078\nKey48=1756:1101\nKey49=1699:1105\nKey50=65505:0\nKey51=47:47\nKey52=1745:1103\nKey53=1758:1095\nKey54=1747:1089\nKey55=1741:1084\nKey56=1737:1080\nKey57=1748:1090\nKey58=1752:1100\nKey59=1730:1073\nKey60=1728:1102\nKey61=44:44\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n"
  },
  {
    "path": "instfiles/km-00000419.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout ru\n# Description: ru-RU\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"1738:U+0439\"  # Cyrillic_shorti\n11=\"1731:U+0446\"  # Cyrillic_tse\n12=\"1749:U+0443\"  # Cyrillic_u\n13=\"1739:U+043A\"  # Cyrillic_ka\n14=\"1733:U+0435\"  # Cyrillic_ie\n15=\"1742:U+043D\"  # Cyrillic_en\n16=\"1735:U+0433\"  # Cyrillic_ghe\n17=\"1755:U+0448\"  # Cyrillic_sha\n18=\"1757:U+0449\"  # Cyrillic_shcha\n19=\"1754:U+0437\"  # Cyrillic_ze\n1A=\"1736:U+0445\"  # Cyrillic_ha\n1B=\"1759:U+044A\"  # Cyrillic_hardsign\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"1734:U+0444\"  # Cyrillic_ef\n1F=\"1753:U+044B\"  # Cyrillic_yeru\n20=\"1751:U+0432\"  # Cyrillic_ve\n21=\"1729:U+0430\"  # Cyrillic_a\n22=\"1744:U+043F\"  # Cyrillic_pe\n23=\"1746:U+0440\"  # Cyrillic_er\n24=\"1743:U+043E\"  # Cyrillic_o\n25=\"1740:U+043B\"  # Cyrillic_el\n26=\"1732:U+0434\"  # Cyrillic_de\n27=\"1750:U+0436\"  # Cyrillic_zhe\n28=\"1756:U+044D\"  # Cyrillic_e\n29=\"1699:U+0451\"  # Cyrillic_io\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"1745:U+044F\"  # Cyrillic_ya\n2D=\"1758:U+0447\"  # Cyrillic_che\n2E=\"1747:U+0441\"  # Cyrillic_es\n2F=\"1741:U+043C\"  # Cyrillic_em\n30=\"1737:U+0438\"  # Cyrillic_i\n31=\"1748:U+0442\"  # Cyrillic_te\n32=\"1752:U+044C\"  # Cyrillic_softsign\n33=\"1730:U+0431\"  # Cyrillic_be\n34=\"1728:U+044E\"  # Cyrillic_yu\n35=\"46:U+002E\"  # period\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"47:U+002F\"  # slash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"1712:U+2116\"  # numerosign\n05=\"59:U+003B\"  # semicolon\n06=\"37:U+0025\"  # percent\n07=\"58:U+003A\"  # colon\n08=\"63:U+003F\"  # question\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"1770:U+0419\"  # Cyrillic_SHORTI\n11=\"1763:U+0426\"  # Cyrillic_TSE\n12=\"1781:U+0423\"  # Cyrillic_U\n13=\"1771:U+041A\"  # Cyrillic_KA\n14=\"1765:U+0415\"  # Cyrillic_IE\n15=\"1774:U+041D\"  # Cyrillic_EN\n16=\"1767:U+0413\"  # Cyrillic_GHE\n17=\"1787:U+0428\"  # Cyrillic_SHA\n18=\"1789:U+0429\"  # Cyrillic_SHCHA\n19=\"1786:U+0417\"  # Cyrillic_ZE\n1A=\"1768:U+0425\"  # Cyrillic_HA\n1B=\"1791:U+042A\"  # Cyrillic_HARDSIGN\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"1766:U+0424\"  # Cyrillic_EF\n1F=\"1785:U+042B\"  # Cyrillic_YERU\n20=\"1783:U+0412\"  # Cyrillic_VE\n21=\"1761:U+0410\"  # Cyrillic_A\n22=\"1776:U+041F\"  # Cyrillic_PE\n23=\"1778:U+0420\"  # Cyrillic_ER\n24=\"1775:U+041E\"  # Cyrillic_O\n25=\"1772:U+041B\"  # Cyrillic_EL\n26=\"1764:U+0414\"  # Cyrillic_DE\n27=\"1782:U+0416\"  # Cyrillic_ZHE\n28=\"1788:U+042D\"  # Cyrillic_E\n29=\"1715:U+0401\"  # Cyrillic_IO\n2A=\"65505\"  # Shift_L\n2B=\"47:U+002F\"  # slash\n2C=\"1777:U+042F\"  # Cyrillic_YA\n2D=\"1790:U+0427\"  # Cyrillic_CHE\n2E=\"1779:U+0421\"  # Cyrillic_ES\n2F=\"1773:U+041C\"  # Cyrillic_EM\n30=\"1769:U+0418\"  # Cyrillic_I\n31=\"1780:U+0422\"  # Cyrillic_TE\n32=\"1784:U+042C\"  # Cyrillic_SOFTSIGN\n33=\"1762:U+0411\"  # Cyrillic_BE\n34=\"1760:U+042E\"  # Cyrillic_YU\n35=\"44:U+002C\"  # comma\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"16785597:U+20BD\"  # U20BD\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"1738:U+0439\"  # Cyrillic_shorti\n11=\"1731:U+0446\"  # Cyrillic_tse\n12=\"1749:U+0443\"  # Cyrillic_u\n13=\"1739:U+043A\"  # Cyrillic_ka\n14=\"1733:U+0435\"  # Cyrillic_ie\n15=\"1742:U+043D\"  # Cyrillic_en\n16=\"1735:U+0433\"  # Cyrillic_ghe\n17=\"1755:U+0448\"  # Cyrillic_sha\n18=\"1757:U+0449\"  # Cyrillic_shcha\n19=\"1754:U+0437\"  # Cyrillic_ze\n1A=\"1736:U+0445\"  # Cyrillic_ha\n1B=\"1759:U+044A\"  # Cyrillic_hardsign\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"1734:U+0444\"  # Cyrillic_ef\n1F=\"1753:U+044B\"  # Cyrillic_yeru\n20=\"1751:U+0432\"  # Cyrillic_ve\n21=\"1729:U+0430\"  # Cyrillic_a\n22=\"1744:U+043F\"  # Cyrillic_pe\n23=\"1746:U+0440\"  # Cyrillic_er\n24=\"1743:U+043E\"  # Cyrillic_o\n25=\"1740:U+043B\"  # Cyrillic_el\n26=\"1732:U+0434\"  # Cyrillic_de\n27=\"1750:U+0436\"  # Cyrillic_zhe\n28=\"1756:U+044D\"  # Cyrillic_e\n29=\"1699:U+0451\"  # Cyrillic_io\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"1745:U+044F\"  # Cyrillic_ya\n2D=\"1758:U+0447\"  # Cyrillic_che\n2E=\"1747:U+0441\"  # Cyrillic_es\n2F=\"1741:U+043C\"  # Cyrillic_em\n30=\"1737:U+0438\"  # Cyrillic_i\n31=\"1748:U+0442\"  # Cyrillic_te\n32=\"1752:U+044C\"  # Cyrillic_softsign\n33=\"1730:U+0431\"  # Cyrillic_be\n34=\"1728:U+044E\"  # Cyrillic_yu\n35=\"46:U+002E\"  # period\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"1712:U+2116\"  # numerosign\n05=\"59:U+003B\"  # semicolon\n06=\"37:U+0025\"  # percent\n07=\"58:U+003A\"  # colon\n08=\"63:U+003F\"  # question\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"1770:U+0419\"  # Cyrillic_SHORTI\n11=\"1763:U+0426\"  # Cyrillic_TSE\n12=\"1781:U+0423\"  # Cyrillic_U\n13=\"1771:U+041A\"  # Cyrillic_KA\n14=\"1765:U+0415\"  # Cyrillic_IE\n15=\"1774:U+041D\"  # Cyrillic_EN\n16=\"1767:U+0413\"  # Cyrillic_GHE\n17=\"1787:U+0428\"  # Cyrillic_SHA\n18=\"1789:U+0429\"  # Cyrillic_SHCHA\n19=\"1786:U+0417\"  # Cyrillic_ZE\n1A=\"1768:U+0425\"  # Cyrillic_HA\n1B=\"1791:U+042A\"  # Cyrillic_HARDSIGN\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"1766:U+0424\"  # Cyrillic_EF\n1F=\"1785:U+042B\"  # Cyrillic_YERU\n20=\"1783:U+0412\"  # Cyrillic_VE\n21=\"1761:U+0410\"  # Cyrillic_A\n22=\"1776:U+041F\"  # Cyrillic_PE\n23=\"1778:U+0420\"  # Cyrillic_ER\n24=\"1775:U+041E\"  # Cyrillic_O\n25=\"1772:U+041B\"  # Cyrillic_EL\n26=\"1764:U+0414\"  # Cyrillic_DE\n27=\"1782:U+0416\"  # Cyrillic_ZHE\n28=\"1788:U+042D\"  # Cyrillic_E\n29=\"1715:U+0401\"  # Cyrillic_IO\n2A=\"65505\"  # Shift_L\n2B=\"47:U+002F\"  # slash\n2C=\"1777:U+042F\"  # Cyrillic_YA\n2D=\"1790:U+0427\"  # Cyrillic_CHE\n2E=\"1779:U+0421\"  # Cyrillic_ES\n2F=\"1773:U+041C\"  # Cyrillic_EM\n30=\"1769:U+0418\"  # Cyrillic_I\n31=\"1780:U+0422\"  # Cyrillic_TE\n32=\"1784:U+042C\"  # Cyrillic_SOFTSIGN\n33=\"1762:U+0411\"  # Cyrillic_BE\n34=\"1760:U+042E\"  # Cyrillic_YU\n35=\"44:U+002C\"  # comma\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"1770:U+0419\"  # Cyrillic_SHORTI\n11=\"1763:U+0426\"  # Cyrillic_TSE\n12=\"1781:U+0423\"  # Cyrillic_U\n13=\"1771:U+041A\"  # Cyrillic_KA\n14=\"1765:U+0415\"  # Cyrillic_IE\n15=\"1774:U+041D\"  # Cyrillic_EN\n16=\"1767:U+0413\"  # Cyrillic_GHE\n17=\"1787:U+0428\"  # Cyrillic_SHA\n18=\"1789:U+0429\"  # Cyrillic_SHCHA\n19=\"1786:U+0417\"  # Cyrillic_ZE\n1A=\"1768:U+0425\"  # Cyrillic_HA\n1B=\"1791:U+042A\"  # Cyrillic_HARDSIGN\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"1766:U+0424\"  # Cyrillic_EF\n1F=\"1785:U+042B\"  # Cyrillic_YERU\n20=\"1783:U+0412\"  # Cyrillic_VE\n21=\"1761:U+0410\"  # Cyrillic_A\n22=\"1776:U+041F\"  # Cyrillic_PE\n23=\"1778:U+0420\"  # Cyrillic_ER\n24=\"1775:U+041E\"  # Cyrillic_O\n25=\"1772:U+041B\"  # Cyrillic_EL\n26=\"1764:U+0414\"  # Cyrillic_DE\n27=\"1782:U+0416\"  # Cyrillic_ZHE\n28=\"1788:U+042D\"  # Cyrillic_E\n29=\"1715:U+0401\"  # Cyrillic_IO\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"1777:U+042F\"  # Cyrillic_YA\n2D=\"1790:U+0427\"  # Cyrillic_CHE\n2E=\"1779:U+0421\"  # Cyrillic_ES\n2F=\"1773:U+041C\"  # Cyrillic_EM\n30=\"1769:U+0418\"  # Cyrillic_I\n31=\"1780:U+0422\"  # Cyrillic_TE\n32=\"1784:U+042C\"  # Cyrillic_SOFTSIGN\n33=\"1762:U+0411\"  # Cyrillic_BE\n34=\"1760:U+042E\"  # Cyrillic_YU\n35=\"46:U+002E\"  # period\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"47:U+002F\"  # slash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"16785597:U+20BD\"  # U20BD\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"1770:U+0419\"  # Cyrillic_SHORTI\n11=\"1763:U+0426\"  # Cyrillic_TSE\n12=\"1781:U+0423\"  # Cyrillic_U\n13=\"1771:U+041A\"  # Cyrillic_KA\n14=\"1765:U+0415\"  # Cyrillic_IE\n15=\"1774:U+041D\"  # Cyrillic_EN\n16=\"1767:U+0413\"  # Cyrillic_GHE\n17=\"1787:U+0428\"  # Cyrillic_SHA\n18=\"1789:U+0429\"  # Cyrillic_SHCHA\n19=\"1786:U+0417\"  # Cyrillic_ZE\n1A=\"1768:U+0425\"  # Cyrillic_HA\n1B=\"1791:U+042A\"  # Cyrillic_HARDSIGN\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"1766:U+0424\"  # Cyrillic_EF\n1F=\"1785:U+042B\"  # Cyrillic_YERU\n20=\"1783:U+0412\"  # Cyrillic_VE\n21=\"1761:U+0410\"  # Cyrillic_A\n22=\"1776:U+041F\"  # Cyrillic_PE\n23=\"1778:U+0420\"  # Cyrillic_ER\n24=\"1775:U+041E\"  # Cyrillic_O\n25=\"1772:U+041B\"  # Cyrillic_EL\n26=\"1764:U+0414\"  # Cyrillic_DE\n27=\"1782:U+0416\"  # Cyrillic_ZHE\n28=\"1788:U+042D\"  # Cyrillic_E\n29=\"1715:U+0401\"  # Cyrillic_IO\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"1777:U+042F\"  # Cyrillic_YA\n2D=\"1790:U+0427\"  # Cyrillic_CHE\n2E=\"1779:U+0421\"  # Cyrillic_ES\n2F=\"1773:U+041C\"  # Cyrillic_EM\n30=\"1769:U+0418\"  # Cyrillic_I\n31=\"1780:U+0422\"  # Cyrillic_TE\n32=\"1784:U+042C\"  # Cyrillic_SOFTSIGN\n33=\"1762:U+0411\"  # Cyrillic_BE\n34=\"1760:U+042E\"  # Cyrillic_YU\n35=\"46:U+002E\"  # period\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"1712:U+2116\"  # numerosign\n05=\"59:U+003B\"  # semicolon\n06=\"37:U+0025\"  # percent\n07=\"58:U+003A\"  # colon\n08=\"63:U+003F\"  # question\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"1738:U+0439\"  # Cyrillic_shorti\n11=\"1731:U+0446\"  # Cyrillic_tse\n12=\"1749:U+0443\"  # Cyrillic_u\n13=\"1739:U+043A\"  # Cyrillic_ka\n14=\"1733:U+0435\"  # Cyrillic_ie\n15=\"1742:U+043D\"  # Cyrillic_en\n16=\"1735:U+0433\"  # Cyrillic_ghe\n17=\"1755:U+0448\"  # Cyrillic_sha\n18=\"1757:U+0449\"  # Cyrillic_shcha\n19=\"1754:U+0437\"  # Cyrillic_ze\n1A=\"1736:U+0445\"  # Cyrillic_ha\n1B=\"1759:U+044A\"  # Cyrillic_hardsign\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"1734:U+0444\"  # Cyrillic_ef\n1F=\"1753:U+044B\"  # Cyrillic_yeru\n20=\"1751:U+0432\"  # Cyrillic_ve\n21=\"1729:U+0430\"  # Cyrillic_a\n22=\"1744:U+043F\"  # Cyrillic_pe\n23=\"1746:U+0440\"  # Cyrillic_er\n24=\"1743:U+043E\"  # Cyrillic_o\n25=\"1740:U+043B\"  # Cyrillic_el\n26=\"1732:U+0434\"  # Cyrillic_de\n27=\"1750:U+0436\"  # Cyrillic_zhe\n28=\"1756:U+044D\"  # Cyrillic_e\n29=\"1699:U+0451\"  # Cyrillic_io\n2A=\"65505\"  # Shift_L\n2B=\"47:U+002F\"  # slash\n2C=\"1745:U+044F\"  # Cyrillic_ya\n2D=\"1758:U+0447\"  # Cyrillic_che\n2E=\"1747:U+0441\"  # Cyrillic_es\n2F=\"1741:U+043C\"  # Cyrillic_em\n30=\"1737:U+0438\"  # Cyrillic_i\n31=\"1748:U+0442\"  # Cyrillic_te\n32=\"1752:U+044C\"  # Cyrillic_softsign\n33=\"1730:U+0431\"  # Cyrillic_be\n34=\"1728:U+044E\"  # Cyrillic_yu\n35=\"44:U+002C\"  # comma\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"1712:U+2116\"  # numerosign\n05=\"59:U+003B\"  # semicolon\n06=\"37:U+0025\"  # percent\n07=\"58:U+003A\"  # colon\n08=\"63:U+003F\"  # question\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"1738:U+0439\"  # Cyrillic_shorti\n11=\"1731:U+0446\"  # Cyrillic_tse\n12=\"1749:U+0443\"  # Cyrillic_u\n13=\"1739:U+043A\"  # Cyrillic_ka\n14=\"1733:U+0435\"  # Cyrillic_ie\n15=\"1742:U+043D\"  # Cyrillic_en\n16=\"1735:U+0433\"  # Cyrillic_ghe\n17=\"1755:U+0448\"  # Cyrillic_sha\n18=\"1757:U+0449\"  # Cyrillic_shcha\n19=\"1754:U+0437\"  # Cyrillic_ze\n1A=\"1736:U+0445\"  # Cyrillic_ha\n1B=\"1759:U+044A\"  # Cyrillic_hardsign\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"1734:U+0444\"  # Cyrillic_ef\n1F=\"1753:U+044B\"  # Cyrillic_yeru\n20=\"1751:U+0432\"  # Cyrillic_ve\n21=\"1729:U+0430\"  # Cyrillic_a\n22=\"1744:U+043F\"  # Cyrillic_pe\n23=\"1746:U+0440\"  # Cyrillic_er\n24=\"1743:U+043E\"  # Cyrillic_o\n25=\"1740:U+043B\"  # Cyrillic_el\n26=\"1732:U+0434\"  # Cyrillic_de\n27=\"1750:U+0436\"  # Cyrillic_zhe\n28=\"1756:U+044D\"  # Cyrillic_e\n29=\"1699:U+0451\"  # Cyrillic_io\n2A=\"65505\"  # Shift_L\n2B=\"47:U+002F\"  # slash\n2C=\"1745:U+044F\"  # Cyrillic_ya\n2D=\"1758:U+0447\"  # Cyrillic_che\n2E=\"1747:U+0441\"  # Cyrillic_es\n2F=\"1741:U+043C\"  # Cyrillic_em\n30=\"1737:U+0438\"  # Cyrillic_i\n31=\"1748:U+0442\"  # Cyrillic_te\n32=\"1752:U+044C\"  # Cyrillic_softsign\n33=\"1730:U+0431\"  # Cyrillic_be\n34=\"1728:U+044E\"  # Cyrillic_yu\n35=\"44:U+002C\"  # comma\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-0000041d.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=43:43\nKey21=65105:180\nKey22=65288:8\nKey23=65289:9\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=229:229\nKey35=65111:168\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=246:246\nKey48=228:228\nKey49=167:167\nKey50=65505:0\nKey51=39:39\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=44:44\nKey60=46:46\nKey61=45:45\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=35:35\nKey13=164:164\nKey14=37:37\nKey15=38:38\nKey16=47:47\nKey17=40:40\nKey18=41:41\nKey19=61:61\nKey20=63:63\nKey21=65104:96\nKey22=65288:8\nKey23=65056:0\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=197:197\nKey35=65106:94\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=214:214\nKey48=196:196\nKey49=189:189\nKey50=65505:0\nKey51=42:42\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=59:59\nKey60=58:58\nKey61=95:95\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=64:64\nKey12=163:163\nKey13=36:36\nKey14=8364:8364\nKey15=165:165\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=92:92\nKey21=177:177\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=435:322\nKey26=8364:8364\nKey27=174:174\nKey28=254:254\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=5053:339\nKey33=254:254\nKey34=65111:168\nKey35=65107:126\nKey36=65293:13\nKey37=65507:0\nKey38=170:170\nKey39=223:223\nKey40=240:240\nKey41=496:273\nKey42=959:331\nKey43=689:295\nKey44=65121:0\nKey45=930:312\nKey46=435:322\nKey47=248:248\nKey48=230:230\nKey49=182:182\nKey50=65505:0\nKey51=180:180\nKey52=171:171\nKey53=187:187\nKey54=169:169\nKey55=2770:8220\nKey56=2771:8221\nKey57=110:110\nKey58=181:181\nKey59=65115:184\nKey60=183:183\nKey61=65120:0\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=178:178\nKey12=179:179\nKey13=188:188\nKey14=162:162\nKey15=2757:8541\nKey16=247:247\nKey17=171:171\nKey18=187:187\nKey19=176:176\nKey20=191:191\nKey21=172:172\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=419:321\nKey26=162:162\nKey27=174:174\nKey28=222:222\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=5052:338\nKey33=222:222\nKey34=65112:176\nKey35=65114:711\nKey36=65293:13\nKey37=65507:0\nKey38=186:186\nKey39=167:167\nKey40=208:208\nKey41=170:170\nKey42=957:330\nKey43=673:294\nKey44=65122:0\nKey45=38:38\nKey46=419:321\nKey47=216:216\nKey48=198:198\nKey49=190:190\nKey50=65505:0\nKey51=215:215\nKey52=60:60\nKey53=62:62\nKey54=169:169\nKey55=2768:8216\nKey56=2769:8217\nKey57=78:78\nKey58=186:186\nKey59=65116:731\nKey60=65110:729\nKey61=65110:729\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=160:160\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=43:43\nKey21=65105:180\nKey22=65288:8\nKey23=65289:9\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=197:197\nKey35=65111:168\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=214:214\nKey48=196:196\nKey49=167:167\nKey50=65505:0\nKey51=39:39\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=44:44\nKey60=46:46\nKey61=45:45\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=64:64\nKey12=163:163\nKey13=36:36\nKey14=8364:8364\nKey15=165:165\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=92:92\nKey21=177:177\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=419:321\nKey26=8364:8364\nKey27=174:174\nKey28=222:222\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=5052:338\nKey33=222:222\nKey34=65111:168\nKey35=65107:126\nKey36=65293:13\nKey37=65507:0\nKey38=170:170\nKey39=223:223\nKey40=208:208\nKey41=464:272\nKey42=957:330\nKey43=673:294\nKey44=65121:0\nKey45=930:312\nKey46=419:321\nKey47=216:216\nKey48=198:198\nKey49=182:182\nKey50=65505:0\nKey51=180:180\nKey52=171:171\nKey53=187:187\nKey54=169:169\nKey55=2770:8220\nKey56=2771:8221\nKey57=78:78\nKey58=924:0\nKey59=65115:184\nKey60=183:183\nKey61=65120:0\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=35:35\nKey13=164:164\nKey14=37:37\nKey15=38:38\nKey16=47:47\nKey17=40:40\nKey18=41:41\nKey19=61:61\nKey20=63:63\nKey21=65104:96\nKey22=65288:8\nKey23=65056:0\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=229:229\nKey35=65106:94\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=246:246\nKey48=228:228\nKey49=189:189\nKey50=65505:0\nKey51=42:42\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=59:59\nKey60=58:58\nKey61=95:95\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=178:178\nKey12=179:179\nKey13=188:188\nKey14=162:162\nKey15=2757:8541\nKey16=247:247\nKey17=171:171\nKey18=187:187\nKey19=176:176\nKey20=191:191\nKey21=172:172\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=435:322\nKey26=162:162\nKey27=174:174\nKey28=254:254\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=5053:339\nKey33=254:254\nKey34=65112:176\nKey35=65114:711\nKey36=65293:13\nKey37=65507:0\nKey38=186:186\nKey39=167:167\nKey40=240:240\nKey41=170:170\nKey42=959:331\nKey43=689:295\nKey44=65122:0\nKey45=38:38\nKey46=435:322\nKey47=248:248\nKey48=230:230\nKey49=190:190\nKey50=65505:0\nKey51=215:215\nKey52=60:60\nKey53=62:62\nKey54=169:169\nKey55=2768:8216\nKey56=2769:8217\nKey57=110:110\nKey58=186:186\nKey59=65116:731\nKey60=65110:729\nKey61=65110:729\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=160:160\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n"
  },
  {
    "path": "instfiles/km-0000041d.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout se\n# Description: sv-SE\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"43:U+002B\"  # plus\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"229:U+00E5\"  # aring\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"246:U+00F6\"  # odiaeresis\n28=\"228:U+00E4\"  # adiaeresis\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"164:U+00A4\"  # currency\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"197:U+00C5\"  # Aring\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"196:U+00C4\"  # Adiaeresis\n29=\"189:U+00BD\"  # onehalf\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"8364:U+20AC\"  # EuroSign\n07=\"165:U+00A5\"  # yen\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"177:U+00B1\"  # plusminus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"254:U+00FE\"  # thorn\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"170:U+00AA\"  # ordfeminine\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"248:U+00F8\"  # oslash\n28=\"230:U+00E6\"  # ae\n29=\"182:U+00B6\"  # paragraph\n2A=\"65505\"  # Shift_L\n2B=\"180:U+00B4\"  # acute\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"65115:U+00B8\"  # dead_cedilla\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"162:U+00A2\"  # cent\n07=\"2757:U+215D\"  # fiveeighths\n08=\"247:U+00F7\"  # division\n09=\"171:U+00AB\"  # guillemotleft\n0A=\"187:U+00BB\"  # guillemotright\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"172:U+00AC\"  # notsign\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"222:U+00DE\"  # THORN\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65114:U+02C7\"  # dead_caron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"186:U+00BA\"  # masculine\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"216:U+00D8\"  # Oslash\n28=\"198:U+00C6\"  # AE\n29=\"190:U+00BE\"  # threequarters\n2A=\"65505\"  # Shift_L\n2B=\"215:U+00D7\"  # multiply\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"65116:U+02DB\"  # dead_ogonek\n34=\"65110:U+02D9\"  # dead_abovedot\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"43:U+002B\"  # plus\n0D=\"65105:U+00B4\"  # dead_acute\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"197:U+00C5\"  # Aring\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"196:U+00C4\"  # Adiaeresis\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"39:U+0027\"  # apostrophe\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"8364:U+20AC\"  # EuroSign\n07=\"165:U+00A5\"  # yen\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"177:U+00B1\"  # plusminus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"222:U+00DE\"  # THORN\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"170:U+00AA\"  # ordfeminine\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"216:U+00D8\"  # Oslash\n28=\"198:U+00C6\"  # AE\n29=\"182:U+00B6\"  # paragraph\n2A=\"65505\"  # Shift_L\n2B=\"180:U+00B4\"  # acute\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"65115:U+00B8\"  # dead_cedilla\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"164:U+00A4\"  # currency\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"229:U+00E5\"  # aring\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"246:U+00F6\"  # odiaeresis\n28=\"228:U+00E4\"  # adiaeresis\n29=\"189:U+00BD\"  # onehalf\n2A=\"65505\"  # Shift_L\n2B=\"42:U+002A\"  # asterisk\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"188:U+00BC\"  # onequarter\n06=\"162:U+00A2\"  # cent\n07=\"2757:U+215D\"  # fiveeighths\n08=\"247:U+00F7\"  # division\n09=\"171:U+00AB\"  # guillemotleft\n0A=\"187:U+00BB\"  # guillemotright\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"172:U+00AC\"  # notsign\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"254:U+00FE\"  # thorn\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65114:U+02C7\"  # dead_caron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"186:U+00BA\"  # masculine\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"248:U+00F8\"  # oslash\n28=\"230:U+00E6\"  # ae\n29=\"190:U+00BE\"  # threequarters\n2A=\"65505\"  # Shift_L\n2B=\"215:U+00D7\"  # multiply\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"65116:U+02DB\"  # dead_ogonek\n34=\"65110:U+02D9\"  # dead_abovedot\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-00000424.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwertz)\n# setxkbmap -rules evdev -model pc104 -layout si\n# Description: sl-SI\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"441:U+0161\"  # scaron\n1B=\"496:U+0111\"  # dstroke\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"488:U+010D\"  # ccaron\n28=\"486:U+0107\"  # cacute\n29=\"184:U+00B8\"  # cedilla\n2A=\"65505\"  # Shift_L\n2B=\"446:U+017E\"  # zcaron\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"42:U+002A\"  # asterisk\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"425:U+0160\"  # Scaron\n1B=\"464:U+0110\"  # Dstroke\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"456:U+010C\"  # Ccaron\n28=\"454:U+0106\"  # Cacute\n29=\"168:U+00A8\"  # diaeresis\n2A=\"65505\"  # Shift_L\n2B=\"430:U+017D\"  # Zcaron\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"65107:U+007E\"  # dead_tilde\n03=\"65114:U+02C7\"  # dead_caron\n04=\"65106:U+005E\"  # dead_circumflex\n05=\"65109:U+02D8\"  # dead_breve\n06=\"65112:U+00B0\"  # dead_abovering\n07=\"65116:U+02DB\"  # dead_ogonek\n08=\"65104:U+0060\"  # dead_grave\n09=\"65110:U+02D9\"  # dead_abovedot\n0A=\"65105:U+00B4\"  # dead_acute\n0B=\"65113:U+02DD\"  # dead_doubleacute\n0C=\"65111:U+00A8\"  # dead_diaeresis\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"92:U+005C\"  # backslash\n11=\"124:U+007C\"  # bar\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"247:U+00F7\"  # division\n1B=\"215:U+00D7\"  # multiply\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"2814:U+201E\"  # doublelowquotemark\n20=\"2770:U+201C\"  # leftdoublequotemark\n21=\"91:U+005B\"  # bracketleft\n22=\"93:U+005D\"  # bracketright\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"435:U+0142\"  # lstroke\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"223:U+00DF\"  # ssharp\n29=\"184:U+00B8\"  # cedilla\n2A=\"65505\"  # Shift_L\n2B=\"164:U+00A4\"  # currency\n2C=\"2768:U+2018\"  # leftsinglequotemark\n2D=\"2769:U+2019\"  # rightsinglequotemark\n2E=\"162:U+00A2\"  # cent\n2F=\"64:U+0040\"  # at\n30=\"123:U+007B\"  # braceleft\n31=\"125:U+007D\"  # braceright\n32=\"167:U+00A7\"  # section\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"2729:U+2014\"  # emdash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"126:U+007E\"  # asciitilde\n03=\"439:U+02C7\"  # caron\n04=\"94:U+005E\"  # asciicircum\n05=\"418:U+02D8\"  # breve\n06=\"176:U+00B0\"  # degree\n07=\"434:U+02DB\"  # ogonek\n08=\"96:U+0060\"  # grave\n09=\"511:U+02D9\"  # abovedot\n0A=\"39:U+0027\"  # apostrophe\n0B=\"445:U+02DD\"  # doubleacute\n0C=\"168:U+00A8\"  # diaeresis\n0D=\"184:U+00B8\"  # cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"187:U+00BB\"  # guillemotright\n20=\"171:U+00AB\"  # guillemotleft\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"168:U+00A8\"  # diaeresis\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"187:U+00BB\"  # guillemotright\n2D=\"171:U+00AB\"  # guillemotleft\n2E=\"169:U+00A9\"  # copyright\n2F=\"96:U+0060\"  # grave\n30=\"39:U+0027\"  # apostrophe\n31=\"125:U+007D\"  # braceright\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"2730:U+2013\"  # endash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"425:U+0160\"  # Scaron\n1B=\"464:U+0110\"  # Dstroke\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"456:U+010C\"  # Ccaron\n28=\"454:U+0106\"  # Cacute\n29=\"184:U+00B8\"  # cedilla\n2A=\"65505\"  # Shift_L\n2B=\"430:U+017D\"  # Zcaron\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"65107:U+007E\"  # dead_tilde\n03=\"65114:U+02C7\"  # dead_caron\n04=\"65106:U+005E\"  # dead_circumflex\n05=\"65109:U+02D8\"  # dead_breve\n06=\"65112:U+00B0\"  # dead_abovering\n07=\"65116:U+02DB\"  # dead_ogonek\n08=\"65104:U+0060\"  # dead_grave\n09=\"65110:U+02D9\"  # dead_abovedot\n0A=\"65105:U+00B4\"  # dead_acute\n0B=\"65113:U+02DD\"  # dead_doubleacute\n0C=\"65111:U+00A8\"  # dead_diaeresis\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"92:U+005C\"  # backslash\n11=\"124:U+007C\"  # bar\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"247:U+00F7\"  # division\n1B=\"215:U+00D7\"  # multiply\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"2814:U+201E\"  # doublelowquotemark\n20=\"2770:U+201C\"  # leftdoublequotemark\n21=\"91:U+005B\"  # bracketleft\n22=\"93:U+005D\"  # bracketright\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"419:U+0141\"  # Lstroke\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n29=\"184:U+00B8\"  # cedilla\n2A=\"65505\"  # Shift_L\n2B=\"164:U+00A4\"  # currency\n2C=\"2768:U+2018\"  # leftsinglequotemark\n2D=\"2769:U+2019\"  # rightsinglequotemark\n2E=\"162:U+00A2\"  # cent\n2F=\"64:U+0040\"  # at\n30=\"123:U+007B\"  # braceleft\n31=\"125:U+007D\"  # braceright\n32=\"167:U+00A7\"  # section\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"2729:U+2014\"  # emdash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"42:U+002A\"  # asterisk\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"441:U+0161\"  # scaron\n1B=\"496:U+0111\"  # dstroke\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"488:U+010D\"  # ccaron\n28=\"486:U+0107\"  # cacute\n29=\"168:U+00A8\"  # diaeresis\n2A=\"65505\"  # Shift_L\n2B=\"446:U+017E\"  # zcaron\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"126:U+007E\"  # asciitilde\n03=\"439:U+02C7\"  # caron\n04=\"94:U+005E\"  # asciicircum\n05=\"418:U+02D8\"  # breve\n06=\"176:U+00B0\"  # degree\n07=\"434:U+02DB\"  # ogonek\n08=\"96:U+0060\"  # grave\n09=\"511:U+02D9\"  # abovedot\n0A=\"39:U+0027\"  # apostrophe\n0B=\"445:U+02DD\"  # doubleacute\n0C=\"168:U+00A8\"  # diaeresis\n0D=\"184:U+00B8\"  # cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"187:U+00BB\"  # guillemotright\n20=\"171:U+00AB\"  # guillemotleft\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"168:U+00A8\"  # diaeresis\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"187:U+00BB\"  # guillemotright\n2D=\"171:U+00AB\"  # guillemotleft\n2E=\"169:U+00A9\"  # copyright\n2F=\"96:U+0060\"  # grave\n30=\"39:U+0027\"  # apostrophe\n31=\"125:U+007D\"  # braceright\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"2730:U+2013\"  # endash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65452:U+002C\"  # KP_Separator\n"
  },
  {
    "path": "instfiles/km-00000426.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout lv -variant ergonomic\n# Description: lv-LV\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"102:U+0066\"  # f\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"1022:U+016B\"  # umacron\n11=\"103:U+0067\"  # g\n12=\"106:U+006A\"  # j\n13=\"114:U+0072\"  # r\n14=\"109:U+006D\"  # m\n15=\"118:U+0076\"  # v\n16=\"110:U+006E\"  # n\n17=\"122:U+007A\"  # z\n18=\"954:U+0113\"  # emacron\n19=\"488:U+010D\"  # ccaron\n1A=\"446:U+017E\"  # zcaron\n1B=\"104:U+0068\"  # h\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"441:U+0161\"  # scaron\n1F=\"117:U+0075\"  # u\n20=\"115:U+0073\"  # s\n21=\"105:U+0069\"  # i\n22=\"108:U+006C\"  # l\n23=\"100:U+0064\"  # d\n24=\"97:U+0061\"  # a\n25=\"116:U+0074\"  # t\n26=\"101:U+0065\"  # e\n27=\"99:U+0063\"  # c\n28=\"65028\"  # ISO_Level3_Latch\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"1011:U+0137\"  # kcedilla\n2C=\"1009:U+0146\"  # ncedilla\n2D=\"98:U+0062\"  # b\n2E=\"1007:U+012B\"  # imacron\n2F=\"107:U+006B\"  # k\n30=\"112:U+0070\"  # p\n31=\"111:U+006F\"  # o\n32=\"992:U+0101\"  # amacron\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"950:U+013C\"  # lcedilla\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"955:U+0123\"  # gcedilla\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"70:U+0046\"  # F\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"990:U+016A\"  # Umacron\n11=\"71:U+0047\"  # G\n12=\"74:U+004A\"  # J\n13=\"82:U+0052\"  # R\n14=\"77:U+004D\"  # M\n15=\"86:U+0056\"  # V\n16=\"78:U+004E\"  # N\n17=\"90:U+005A\"  # Z\n18=\"938:U+0112\"  # Emacron\n19=\"456:U+010C\"  # Ccaron\n1A=\"430:U+017D\"  # Zcaron\n1B=\"72:U+0048\"  # H\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"425:U+0160\"  # Scaron\n1F=\"85:U+0055\"  # U\n20=\"83:U+0053\"  # S\n21=\"73:U+0049\"  # I\n22=\"76:U+004C\"  # L\n23=\"68:U+0044\"  # D\n24=\"65:U+0041\"  # A\n25=\"84:U+0054\"  # T\n26=\"69:U+0045\"  # E\n27=\"67:U+0043\"  # C\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"979:U+0136\"  # Kcedilla\n2C=\"977:U+0145\"  # Ncedilla\n2D=\"66:U+0042\"  # B\n2E=\"975:U+012A\"  # Imacron\n2F=\"75:U+004B\"  # K\n30=\"80:U+0050\"  # P\n31=\"79:U+004F\"  # O\n32=\"960:U+0100\"  # Amacron\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"934:U+013B\"  # Lcedilla\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"939:U+0122\"  # Gcedilla\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"955:U+0123\"  # gcedilla\n04=\"179:U+00B3\"  # threesuperior\n05=\"8364:U+20AC\"  # EuroSign\n06=\"189:U+00BD\"  # onehalf\n07=\"190:U+00BE\"  # threequarters\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"2730:U+2013\"  # endash\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"103:U+0067\"  # g\n12=\"106:U+006A\"  # j\n13=\"947:U+0157\"  # rcedilla\n14=\"109:U+006D\"  # m\n15=\"119:U+0077\"  # w\n16=\"121:U+0079\"  # y\n17=\"122:U+007A\"  # z\n18=\"954:U+0113\"  # emacron\n19=\"488:U+010D\"  # ccaron\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"441:U+0161\"  # scaron\n1F=\"117:U+0075\"  # u\n20=\"115:U+0073\"  # s\n21=\"105:U+0069\"  # i\n22=\"108:U+006C\"  # l\n23=\"100:U+0064\"  # d\n24=\"97:U+0061\"  # a\n25=\"116:U+0074\"  # t\n26=\"101:U+0065\"  # e\n27=\"99:U+0063\"  # c\n28=\"39:U+0027\"  # apostrophe\n29=\"180:U+00B4\"  # acute\n2A=\"65505\"  # Shift_L\n2B=\"47:U+002F\"  # slash\n2C=\"1009:U+0146\"  # ncedilla\n2D=\"120:U+0078\"  # x\n2E=\"1007:U+012B\"  # imacron\n2F=\"107:U+006B\"  # k\n30=\"112:U+0070\"  # p\n31=\"1010:U+014D\"  # omacron\n32=\"992:U+0101\"  # amacron\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"39:U+0027\"  # apostrophe\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"955:U+0123\"  # gcedilla\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"939:U+0122\"  # Gcedilla\n04=\"163:U+00A3\"  # sterling\n05=\"162:U+00A2\"  # cent\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"2729:U+2014\"  # emdash\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"71:U+0047\"  # G\n12=\"74:U+004A\"  # J\n13=\"931:U+0156\"  # Rcedilla\n14=\"77:U+004D\"  # M\n15=\"87:U+0057\"  # W\n16=\"89:U+0059\"  # Y\n17=\"90:U+005A\"  # Z\n18=\"938:U+0112\"  # Emacron\n19=\"456:U+010C\"  # Ccaron\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"425:U+0160\"  # Scaron\n1F=\"85:U+0055\"  # U\n20=\"83:U+0053\"  # S\n21=\"73:U+0049\"  # I\n22=\"76:U+004C\"  # L\n23=\"68:U+0044\"  # D\n24=\"65:U+0041\"  # A\n25=\"84:U+0054\"  # T\n26=\"69:U+0045\"  # E\n27=\"67:U+0043\"  # C\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"977:U+0145\"  # Ncedilla\n2D=\"88:U+0058\"  # X\n2E=\"975:U+012A\"  # Imacron\n2F=\"75:U+004B\"  # K\n30=\"80:U+0050\"  # P\n31=\"978:U+014C\"  # Omacron\n32=\"960:U+0100\"  # Amacron\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"939:U+0122\"  # Gcedilla\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"70:U+0046\"  # F\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"990:U+016A\"  # Umacron\n11=\"71:U+0047\"  # G\n12=\"74:U+004A\"  # J\n13=\"82:U+0052\"  # R\n14=\"77:U+004D\"  # M\n15=\"86:U+0056\"  # V\n16=\"78:U+004E\"  # N\n17=\"90:U+005A\"  # Z\n18=\"938:U+0112\"  # Emacron\n19=\"456:U+010C\"  # Ccaron\n1A=\"430:U+017D\"  # Zcaron\n1B=\"72:U+0048\"  # H\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"425:U+0160\"  # Scaron\n1F=\"85:U+0055\"  # U\n20=\"83:U+0053\"  # S\n21=\"73:U+0049\"  # I\n22=\"76:U+004C\"  # L\n23=\"68:U+0044\"  # D\n24=\"65:U+0041\"  # A\n25=\"84:U+0054\"  # T\n26=\"69:U+0045\"  # E\n27=\"67:U+0043\"  # C\n28=\"65028\"  # ISO_Level3_Latch\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"979:U+0136\"  # Kcedilla\n2C=\"977:U+0145\"  # Ncedilla\n2D=\"66:U+0042\"  # B\n2E=\"975:U+012A\"  # Imacron\n2F=\"75:U+004B\"  # K\n30=\"80:U+0050\"  # P\n31=\"79:U+004F\"  # O\n32=\"960:U+0100\"  # Amacron\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"934:U+013B\"  # Lcedilla\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"939:U+0122\"  # Gcedilla\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"939:U+0122\"  # Gcedilla\n04=\"179:U+00B3\"  # threesuperior\n05=\"8364:U+20AC\"  # EuroSign\n06=\"189:U+00BD\"  # onehalf\n07=\"190:U+00BE\"  # threequarters\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"2730:U+2013\"  # endash\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"71:U+0047\"  # G\n12=\"74:U+004A\"  # J\n13=\"931:U+0156\"  # Rcedilla\n14=\"77:U+004D\"  # M\n15=\"87:U+0057\"  # W\n16=\"89:U+0059\"  # Y\n17=\"90:U+005A\"  # Z\n18=\"938:U+0112\"  # Emacron\n19=\"456:U+010C\"  # Ccaron\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"425:U+0160\"  # Scaron\n1F=\"85:U+0055\"  # U\n20=\"83:U+0053\"  # S\n21=\"73:U+0049\"  # I\n22=\"76:U+004C\"  # L\n23=\"68:U+0044\"  # D\n24=\"65:U+0041\"  # A\n25=\"84:U+0054\"  # T\n26=\"69:U+0045\"  # E\n27=\"67:U+0043\"  # C\n28=\"39:U+0027\"  # apostrophe\n29=\"180:U+00B4\"  # acute\n2A=\"65505\"  # Shift_L\n2B=\"47:U+002F\"  # slash\n2C=\"977:U+0145\"  # Ncedilla\n2D=\"88:U+0058\"  # X\n2E=\"975:U+012A\"  # Imacron\n2F=\"75:U+004B\"  # K\n30=\"80:U+0050\"  # P\n31=\"978:U+014C\"  # Omacron\n32=\"960:U+0100\"  # Amacron\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"39:U+0027\"  # apostrophe\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"939:U+0122\"  # Gcedilla\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"102:U+0066\"  # f\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"1022:U+016B\"  # umacron\n11=\"103:U+0067\"  # g\n12=\"106:U+006A\"  # j\n13=\"114:U+0072\"  # r\n14=\"109:U+006D\"  # m\n15=\"118:U+0076\"  # v\n16=\"110:U+006E\"  # n\n17=\"122:U+007A\"  # z\n18=\"954:U+0113\"  # emacron\n19=\"488:U+010D\"  # ccaron\n1A=\"446:U+017E\"  # zcaron\n1B=\"104:U+0068\"  # h\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"441:U+0161\"  # scaron\n1F=\"117:U+0075\"  # u\n20=\"115:U+0073\"  # s\n21=\"105:U+0069\"  # i\n22=\"108:U+006C\"  # l\n23=\"100:U+0064\"  # d\n24=\"97:U+0061\"  # a\n25=\"116:U+0074\"  # t\n26=\"101:U+0065\"  # e\n27=\"99:U+0063\"  # c\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"1011:U+0137\"  # kcedilla\n2C=\"1009:U+0146\"  # ncedilla\n2D=\"98:U+0062\"  # b\n2E=\"1007:U+012B\"  # imacron\n2F=\"107:U+006B\"  # k\n30=\"112:U+0070\"  # p\n31=\"111:U+006F\"  # o\n32=\"992:U+0101\"  # amacron\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"950:U+013C\"  # lcedilla\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"955:U+0123\"  # gcedilla\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"939:U+0122\"  # Gcedilla\n04=\"163:U+00A3\"  # sterling\n05=\"162:U+00A2\"  # cent\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"2729:U+2014\"  # emdash\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"103:U+0067\"  # g\n12=\"106:U+006A\"  # j\n13=\"947:U+0157\"  # rcedilla\n14=\"109:U+006D\"  # m\n15=\"119:U+0077\"  # w\n16=\"121:U+0079\"  # y\n17=\"122:U+007A\"  # z\n18=\"954:U+0113\"  # emacron\n19=\"488:U+010D\"  # ccaron\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"441:U+0161\"  # scaron\n1F=\"117:U+0075\"  # u\n20=\"115:U+0073\"  # s\n21=\"105:U+0069\"  # i\n22=\"108:U+006C\"  # l\n23=\"100:U+0064\"  # d\n24=\"97:U+0061\"  # a\n25=\"116:U+0074\"  # t\n26=\"101:U+0065\"  # e\n27=\"99:U+0063\"  # c\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"1009:U+0146\"  # ncedilla\n2D=\"120:U+0078\"  # x\n2E=\"1007:U+012B\"  # imacron\n2F=\"107:U+006B\"  # k\n30=\"112:U+0070\"  # p\n31=\"1010:U+014D\"  # omacron\n32=\"992:U+0101\"  # amacron\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"955:U+0123\"  # gcedilla\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00000807.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwertz)\n# setxkbmap -rules evdev -model pc105 -layout ch\n# Description: de-CH\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"65106:U+005E\"  # dead_circumflex\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"252:U+00FC\"  # udiaeresis\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"246:U+00F6\"  # odiaeresis\n28=\"228:U+00E4\"  # adiaeresis\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"36:U+0024\"  # dollar\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"43:U+002B\"  # plus\n03=\"34:U+0022\"  # quotedbl\n04=\"42:U+002A\"  # asterisk\n05=\"231:U+00E7\"  # ccedilla\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"232:U+00E8\"  # egrave\n1B=\"33:U+0021\"  # exclam\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"233:U+00E9\"  # eacute\n28=\"224:U+00E0\"  # agrave\n29=\"176:U+00B0\"  # degree\n2A=\"65505\"  # Shift_L\n2B=\"163:U+00A3\"  # sterling\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"124:U+007C\"  # bar\n09=\"162:U+00A2\"  # cent\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"65105:U+00B4\"  # dead_acute\n0D=\"65107:U+007E\"  # dead_tilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"123:U+007B\"  # braceleft\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"69:U+0045\"  # E\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"65106:U+005E\"  # dead_circumflex\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"220:U+00DC\"  # Udiaeresis\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"196:U+00C4\"  # Adiaeresis\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"36:U+0024\"  # dollar\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"124:U+007C\"  # bar\n09=\"162:U+00A2\"  # cent\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"65105:U+00B4\"  # dead_acute\n0D=\"65107:U+007E\"  # dead_tilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"123:U+007B\"  # braceleft\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"43:U+002B\"  # plus\n03=\"34:U+0022\"  # quotedbl\n04=\"42:U+002A\"  # asterisk\n05=\"199:U+00C7\"  # Ccedilla\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"200:U+00C8\"  # Egrave\n1B=\"33:U+0021\"  # exclam\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"201:U+00C9\"  # Eacute\n28=\"192:U+00C0\"  # Agrave\n29=\"176:U+00B0\"  # degree\n2A=\"65505\"  # Shift_L\n2B=\"163:U+00A3\"  # sterling\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"69:U+0045\"  # E\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00000809.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=61:61\nKey22=65288:8\nKey23=65289:9\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=91:91\nKey35=93:93\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=59:59\nKey48=39:39\nKey49=96:96\nKey50=65505:0\nKey51=35:35\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=44:44\nKey60=46:46\nKey61=47:47\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=163:163\nKey13=36:36\nKey14=37:37\nKey15=94:94\nKey16=38:38\nKey17=42:42\nKey18=40:40\nKey19=41:41\nKey20=95:95\nKey21=43:43\nKey22=65288:8\nKey23=65056:0\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=123:123\nKey35=125:125\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=58:58\nKey48=64:64\nKey49=172:172\nKey50=65505:0\nKey51=126:126\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=60:60\nKey60=62:62\nKey61=63:63\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=178:178\nKey12=179:179\nKey13=8364:8364\nKey14=189:189\nKey15=190:190\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=92:92\nKey21=65115:184\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=435:322\nKey26=101:101\nKey27=182:182\nKey28=956:359\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=248:248\nKey33=254:254\nKey34=65111:168\nKey35=65107:126\nKey36=65293:13\nKey37=65507:0\nKey38=230:230\nKey39=223:223\nKey40=240:240\nKey41=496:273\nKey42=959:331\nKey43=689:295\nKey44=65121:0\nKey45=930:312\nKey46=435:322\nKey47=65105:180\nKey48=65106:94\nKey49=124:124\nKey50=65505:0\nKey51=65104:96\nKey52=171:171\nKey53=187:187\nKey54=162:162\nKey55=2770:8220\nKey56=2771:8221\nKey57=110:110\nKey58=181:181\nKey59=2211:0\nKey60=183:183\nKey61=65120:0\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=2755:8539\nKey12=163:163\nKey13=188:188\nKey14=2756:8540\nKey15=2757:8541\nKey16=2758:8542\nKey17=2761:8482\nKey18=177:177\nKey19=176:176\nKey20=191:191\nKey21=65116:731\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=419:321\nKey26=69:69\nKey27=174:174\nKey28=940:358\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=216:216\nKey33=222:222\nKey34=65112:176\nKey35=65108:175\nKey36=65293:13\nKey37=65507:0\nKey38=198:198\nKey39=167:167\nKey40=208:208\nKey41=170:170\nKey42=957:330\nKey43=673:294\nKey44=65122:0\nKey45=38:38\nKey46=419:321\nKey47=65113:733\nKey48=65114:711\nKey49=124:124\nKey50=65505:0\nKey51=65109:728\nKey52=60:60\nKey53=62:62\nKey54=169:169\nKey55=2768:8216\nKey56=2769:8217\nKey57=78:78\nKey58=186:186\nKey59=215:215\nKey60=247:247\nKey61=65110:729\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=45:45\nKey21=61:61\nKey22=65288:8\nKey23=65289:9\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=91:91\nKey35=93:93\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=59:59\nKey48=39:39\nKey49=96:96\nKey50=65505:0\nKey51=35:35\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=44:44\nKey60=46:46\nKey61=47:47\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=178:178\nKey12=179:179\nKey13=8364:8364\nKey14=189:189\nKey15=190:190\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=92:92\nKey21=65115:184\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=419:321\nKey26=69:69\nKey27=182:182\nKey28=940:358\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=216:216\nKey33=222:222\nKey34=65111:168\nKey35=65107:126\nKey36=65293:13\nKey37=65507:0\nKey38=198:198\nKey39=223:223\nKey40=208:208\nKey41=464:272\nKey42=957:330\nKey43=673:294\nKey44=65121:0\nKey45=930:312\nKey46=419:321\nKey47=65105:180\nKey48=65106:94\nKey49=124:124\nKey50=65505:0\nKey51=65104:96\nKey52=171:171\nKey53=187:187\nKey54=162:162\nKey55=2770:8220\nKey56=2771:8221\nKey57=78:78\nKey58=924:0\nKey59=2211:0\nKey60=183:183\nKey61=65120:0\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=163:163\nKey13=36:36\nKey14=37:37\nKey15=94:94\nKey16=38:38\nKey17=42:42\nKey18=40:40\nKey19=41:41\nKey20=95:95\nKey21=43:43\nKey22=65288:8\nKey23=65056:0\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=123:123\nKey35=125:125\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=58:58\nKey48=64:64\nKey49=172:172\nKey50=65505:0\nKey51=126:126\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=60:60\nKey60=62:62\nKey61=63:63\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=2755:8539\nKey12=163:163\nKey13=188:188\nKey14=2756:8540\nKey15=2757:8541\nKey16=2758:8542\nKey17=2761:8482\nKey18=177:177\nKey19=176:176\nKey20=191:191\nKey21=65116:731\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=435:322\nKey26=101:101\nKey27=174:174\nKey28=956:359\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=248:248\nKey33=254:254\nKey34=65112:176\nKey35=65108:175\nKey36=65293:13\nKey37=65507:0\nKey38=230:230\nKey39=167:167\nKey40=240:240\nKey41=170:170\nKey42=959:331\nKey43=689:295\nKey44=65122:0\nKey45=38:38\nKey46=435:322\nKey47=65113:733\nKey48=65114:711\nKey49=124:124\nKey50=65505:0\nKey51=65109:728\nKey52=60:60\nKey53=62:62\nKey54=169:169\nKey55=2768:8216\nKey56=2769:8217\nKey57=110:110\nKey58=186:186\nKey59=215:215\nKey60=247:247\nKey61=65110:729\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n"
  },
  {
    "path": "instfiles/km-00000809.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout gb\n# Description: en-GB\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"35:U+0023\"  # numbersign\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"58:U+003A\"  # colon\n28=\"64:U+0040\"  # at\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"126:U+007E\"  # asciitilde\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"8364:U+20AC\"  # EuroSign\n06=\"189:U+00BD\"  # onehalf\n07=\"190:U+00BE\"  # threequarters\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"101:U+0065\"  # e\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"188:U+00BC\"  # onequarter\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"69:U+0045\"  # E\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"35:U+0023\"  # numbersign\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"8364:U+20AC\"  # EuroSign\n06=\"189:U+00BD\"  # onehalf\n07=\"190:U+00BE\"  # threequarters\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"69:U+0045\"  # E\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"58:U+003A\"  # colon\n28=\"64:U+0040\"  # at\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"126:U+007E\"  # asciitilde\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"188:U+00BC\"  # onequarter\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"101:U+0065\"  # e\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-0000080a.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout latam\n# Description: es-MX\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"191:U+00BF\"  # questiondown\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65105:U+00B4\"  # dead_acute\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"241:U+00F1\"  # ntilde\n28=\"123:U+007B\"  # braceleft\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"161:U+00A1\"  # exclamdown\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"209:U+00D1\"  # Ntilde\n28=\"91:U+005B\"  # bracketleft\n29=\"176:U+00B0\"  # degree\n2A=\"65505\"  # Shift_L\n2B=\"93:U+005D\"  # bracketright\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"183:U+00B7\"  # periodcentered\n05=\"126:U+007E\"  # asciitilde\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"126:U+007E\"  # asciitilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"126:U+007E\"  # asciitilde\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"123:U+007B\"  # braceleft\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"191:U+00BF\"  # questiondown\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65105:U+00B4\"  # dead_acute\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"209:U+00D1\"  # Ntilde\n28=\"123:U+007B\"  # braceleft\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"183:U+00B7\"  # periodcentered\n05=\"126:U+007E\"  # asciitilde\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"126:U+007E\"  # asciitilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"126:U+007E\"  # asciitilde\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"161:U+00A1\"  # exclamdown\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"241:U+00F1\"  # ntilde\n28=\"91:U+005B\"  # bracketleft\n29=\"176:U+00B0\"  # degree\n2A=\"65505\"  # Shift_L\n2B=\"93:U+005D\"  # bracketright\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"123:U+007B\"  # braceleft\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-0000080c.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(azerty)\n# setxkbmap -rules evdev -model pc105 -layout be -variant oss\n# Description: fr-BE\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n03=\"233:U+00E9\"  # eacute\n04=\"34:U+0022\"  # quotedbl\n05=\"39:U+0027\"  # apostrophe\n06=\"40:U+0028\"  # parenleft\n07=\"167:U+00A7\"  # section\n08=\"232:U+00E8\"  # egrave\n09=\"33:U+0021\"  # exclam\n0A=\"231:U+00E7\"  # ccedilla\n0B=\"224:U+00E0\"  # agrave\n0C=\"41:U+0029\"  # parenright\n0D=\"45:U+002D\"  # minus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"97:U+0061\"  # a\n11=\"122:U+007A\"  # z\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65106:U+005E\"  # dead_circumflex\n1B=\"36:U+0024\"  # dollar\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"113:U+0071\"  # q\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"109:U+006D\"  # m\n28=\"249:U+00F9\"  # ugrave\n29=\"178:U+00B2\"  # twosuperior\n2A=\"65505\"  # Shift_L\n2B=\"181:U+00B5\"  # mu\n2C=\"119:U+0077\"  # w\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"44:U+002C\"  # comma\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"61:U+003D\"  # equal\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"176:U+00B0\"  # degree\n0D=\"95:U+005F\"  # underscore\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"65:U+0041\"  # A\n11=\"90:U+005A\"  # Z\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"81:U+0051\"  # Q\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"77:U+004D\"  # M\n28=\"37:U+0025\"  # percent\n29=\"179:U+00B3\"  # threesuperior\n2A=\"65505\"  # Shift_L\n2B=\"163:U+00A3\"  # sterling\n2C=\"87:U+0057\"  # W\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"63:U+003F\"  # question\n33=\"46:U+002E\"  # period\n34=\"47:U+002F\"  # slash\n35=\"43:U+002B\"  # plus\n36=\"65506\"  # Shift_R\n37=\"16786117:U+22C5\"  # U22C5\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"16785938:U+2212\"  # U2212\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"46:U+002E\"  # period\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"16785941:U+2215\"  # U2215\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"65115:U+00B8\"  # dead_cedilla\n06=\"65114:U+02C7\"  # dead_caron\n07=\"94:U+005E\"  # asciicircum\n08=\"96:U+0060\"  # grave\n09=\"126:U+007E\"  # asciitilde\n0A=\"123:U+007B\"  # braceleft\n0B=\"125:U+007D\"  # braceright\n0C=\"248:U+00F8\"  # oslash\n0D=\"16785425:U+2011\"  # U2011\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"230:U+00E6\"  # ae\n11=\"226:U+00E2\"  # acircumflex\n12=\"8364:U+20AC\"  # EuroSign\n13=\"234:U+00EA\"  # ecircumflex\n14=\"254:U+00FE\"  # thorn\n15=\"255:U+00FF\"  # ydiaeresis\n16=\"251:U+00FB\"  # ucircumflex\n17=\"238:U+00EE\"  # icircumflex\n18=\"5053:U+0153\"  # oe\n19=\"244:U+00F4\"  # ocircumflex\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"228:U+00E4\"  # adiaeresis\n1F=\"223:U+00DF\"  # ssharp\n20=\"235:U+00EB\"  # ediaeresis\n21=\"2768:U+2018\"  # leftsinglequotemark\n22=\"2769:U+2019\"  # rightsinglequotemark\n23=\"240:U+00F0\"  # eth\n24=\"252:U+00FC\"  # udiaeresis\n25=\"239:U+00EF\"  # idiaeresis\n26=\"65123\"  # dead_stroke\n27=\"246:U+00F6\"  # odiaeresis\n28=\"65105:U+00B4\"  # dead_acute\n29=\"185:U+00B9\"  # onesuperior\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"16785455:U+202F\"  # U202F\n30=\"2302:U+2193\"  # downarrow\n31=\"172:U+00AC\"  # notsign\n32=\"191:U+00BF\"  # questiondown\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65107:U+007E\"  # dead_tilde\n36=\"65506\"  # Shift_R\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"16785814:U+2196\"  # U2196\n48=\"16785809:U+2191\"  # U2191\n49=\"16785815:U+2197\"  # U2197\n4A=\"16785938:U+2212\"  # U2212\n4B=\"16785808:U+2190\"  # U2190\n4C=\"16785812:U+2194\"  # U2194\n4D=\"16785810:U+2192\"  # U2192\n4F=\"16785817:U+2199\"  # U2199\n50=\"16785811:U+2193\"  # U2193\n51=\"16785816:U+2198\"  # U2198\n52=\"16785813:U+2195\"  # U2195\n53=\"44:U+002C\"  # comma\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"2238:U+2265\"  # greaterthanequal\n03=\"201:U+00C9\"  # Eacute\n04=\"65109:U+02D8\"  # dead_breve\n05=\"16785428:U+2014\"  # U2014\n06=\"16785427:U+2013\"  # U2013\n07=\"2761:U+2122\"  # trademark\n08=\"200:U+00C8\"  # Egrave\n09=\"161:U+00A1\"  # exclamdown\n0A=\"199:U+00C7\"  # Ccedilla\n0B=\"192:U+00C0\"  # Agrave\n0C=\"216:U+00D8\"  # Oslash\n0D=\"177:U+00B1\"  # plusminus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"198:U+00C6\"  # AE\n11=\"194:U+00C2\"  # Acircumflex\n12=\"162:U+00A2\"  # cent\n13=\"202:U+00CA\"  # Ecircumflex\n14=\"222:U+00DE\"  # THORN\n15=\"5054:U+0178\"  # Ydiaeresis\n16=\"219:U+00DB\"  # Ucircumflex\n17=\"206:U+00CE\"  # Icircumflex\n18=\"5052:U+0152\"  # OE\n19=\"212:U+00D4\"  # Ocircumflex\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65116:U+02DB\"  # dead_ogonek\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"196:U+00C4\"  # Adiaeresis\n1F=\"2814:U+201E\"  # doublelowquotemark\n20=\"203:U+00CB\"  # Ediaeresis\n21=\"2813:U+201A\"  # singlelowquotemark\n22=\"165:U+00A5\"  # yen\n23=\"208:U+00D0\"  # ETH\n24=\"220:U+00DC\"  # Udiaeresis\n25=\"207:U+00CF\"  # Idiaeresis\n26=\"16777535:U+013F\"  # U013F\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"217:U+00D9\"  # Ugrave\n29=\"2236:U+2264\"  # lessthanequal\n2A=\"65505\"  # Shift_L\n2B=\"65108:U+00AF\"  # dead_macron\n2C=\"2770:U+201C\"  # leftdoublequotemark\n2D=\"2771:U+201D\"  # rightdoublequotemark\n2E=\"174:U+00AE\"  # registered\n2F=\"2299:U+2190\"  # leftarrow\n30=\"2300:U+2191\"  # uparrow\n31=\"2301:U+2192\"  # rightarrow\n32=\"16785446:U+2026\"  # U2026\n33=\"16786117:U+22C5\"  # U22C5\n34=\"16785941:U+2215\"  # U2215\n35=\"16785938:U+2212\"  # U2212\n36=\"65506\"  # Shift_R\n37=\"16777215\"  # VoidSymbol\n38=\"65511\"  # Meta_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"16785878:U+21D6\"  # U21D6\n48=\"16785873:U+21D1\"  # U21D1\n49=\"16785879:U+21D7\"  # U21D7\n4A=\"16777215\"  # VoidSymbol\n4B=\"16785872:U+21D0\"  # U21D0\n4C=\"16785876:U+21D4\"  # U21D4\n4D=\"16785874:U+21D2\"  # U21D2\n4E=\"16777215\"  # VoidSymbol\n4F=\"16785881:U+21D9\"  # U21D9\n50=\"16785875:U+21D3\"  # U21D3\n51=\"16785880:U+21D8\"  # U21D8\n52=\"16785877:U+21D5\"  # U21D5\n53=\"16785455:U+202F\"  # U202F\n56=\"2237:U+2260\"  # notequal\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"16777215\"  # VoidSymbol\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n03=\"201:U+00C9\"  # Eacute\n04=\"34:U+0022\"  # quotedbl\n05=\"39:U+0027\"  # apostrophe\n06=\"40:U+0028\"  # parenleft\n07=\"167:U+00A7\"  # section\n08=\"200:U+00C8\"  # Egrave\n09=\"33:U+0021\"  # exclam\n0A=\"199:U+00C7\"  # Ccedilla\n0B=\"192:U+00C0\"  # Agrave\n0C=\"41:U+0029\"  # parenright\n0D=\"45:U+002D\"  # minus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"65:U+0041\"  # A\n11=\"90:U+005A\"  # Z\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65106:U+005E\"  # dead_circumflex\n1B=\"36:U+0024\"  # dollar\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"81:U+0051\"  # Q\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"77:U+004D\"  # M\n28=\"217:U+00D9\"  # Ugrave\n29=\"178:U+00B2\"  # twosuperior\n2A=\"65505\"  # Shift_L\n2C=\"87:U+0057\"  # W\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"44:U+002C\"  # comma\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"61:U+003D\"  # equal\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"65115:U+00B8\"  # dead_cedilla\n06=\"65114:U+02C7\"  # dead_caron\n07=\"94:U+005E\"  # asciicircum\n08=\"96:U+0060\"  # grave\n09=\"126:U+007E\"  # asciitilde\n0A=\"123:U+007B\"  # braceleft\n0B=\"125:U+007D\"  # braceright\n0C=\"216:U+00D8\"  # Oslash\n0D=\"16785425:U+2011\"  # U2011\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"198:U+00C6\"  # AE\n11=\"194:U+00C2\"  # Acircumflex\n12=\"8364:U+20AC\"  # EuroSign\n13=\"202:U+00CA\"  # Ecircumflex\n14=\"222:U+00DE\"  # THORN\n15=\"5054:U+0178\"  # Ydiaeresis\n16=\"219:U+00DB\"  # Ucircumflex\n17=\"206:U+00CE\"  # Icircumflex\n18=\"5052:U+0152\"  # OE\n19=\"212:U+00D4\"  # Ocircumflex\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"196:U+00C4\"  # Adiaeresis\n20=\"203:U+00CB\"  # Ediaeresis\n21=\"2768:U+2018\"  # leftsinglequotemark\n22=\"2769:U+2019\"  # rightsinglequotemark\n23=\"208:U+00D0\"  # ETH\n24=\"220:U+00DC\"  # Udiaeresis\n25=\"207:U+00CF\"  # Idiaeresis\n26=\"65123\"  # dead_stroke\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"65105:U+00B4\"  # dead_acute\n29=\"185:U+00B9\"  # onesuperior\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"169:U+00A9\"  # copyright\n2F=\"16785455:U+202F\"  # U202F\n30=\"2302:U+2193\"  # downarrow\n31=\"172:U+00AC\"  # notsign\n32=\"191:U+00BF\"  # questiondown\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65107:U+007E\"  # dead_tilde\n36=\"65506\"  # Shift_R\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"16785814:U+2196\"  # U2196\n48=\"16785809:U+2191\"  # U2191\n49=\"16785815:U+2197\"  # U2197\n4A=\"16785938:U+2212\"  # U2212\n4B=\"16785808:U+2190\"  # U2190\n4C=\"16785812:U+2194\"  # U2194\n4D=\"16785810:U+2192\"  # U2192\n4F=\"16785817:U+2199\"  # U2199\n50=\"16785811:U+2193\"  # U2193\n51=\"16785816:U+2198\"  # U2198\n52=\"16785813:U+2195\"  # U2195\n53=\"44:U+002C\"  # comma\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"176:U+00B0\"  # degree\n0D=\"95:U+005F\"  # underscore\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"97:U+0061\"  # a\n11=\"122:U+007A\"  # z\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"113:U+0071\"  # q\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"109:U+006D\"  # m\n28=\"37:U+0025\"  # percent\n29=\"179:U+00B3\"  # threesuperior\n2A=\"65505\"  # Shift_L\n2B=\"163:U+00A3\"  # sterling\n2C=\"119:U+0077\"  # w\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"63:U+003F\"  # question\n33=\"46:U+002E\"  # period\n34=\"47:U+002F\"  # slash\n35=\"43:U+002B\"  # plus\n36=\"65506\"  # Shift_R\n37=\"16786117:U+22C5\"  # U22C5\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"16785938:U+2212\"  # U2212\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"46:U+002E\"  # period\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"16785941:U+2215\"  # U2215\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"2238:U+2265\"  # greaterthanequal\n03=\"201:U+00C9\"  # Eacute\n04=\"65109:U+02D8\"  # dead_breve\n05=\"16785428:U+2014\"  # U2014\n06=\"16785427:U+2013\"  # U2013\n07=\"2761:U+2122\"  # trademark\n08=\"200:U+00C8\"  # Egrave\n09=\"161:U+00A1\"  # exclamdown\n0A=\"199:U+00C7\"  # Ccedilla\n0B=\"192:U+00C0\"  # Agrave\n0C=\"216:U+00D8\"  # Oslash\n0D=\"177:U+00B1\"  # plusminus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"230:U+00E6\"  # ae\n11=\"226:U+00E2\"  # acircumflex\n12=\"162:U+00A2\"  # cent\n13=\"234:U+00EA\"  # ecircumflex\n14=\"254:U+00FE\"  # thorn\n15=\"255:U+00FF\"  # ydiaeresis\n16=\"251:U+00FB\"  # ucircumflex\n17=\"238:U+00EE\"  # icircumflex\n18=\"5053:U+0153\"  # oe\n19=\"244:U+00F4\"  # ocircumflex\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65116:U+02DB\"  # dead_ogonek\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"228:U+00E4\"  # adiaeresis\n1F=\"2814:U+201E\"  # doublelowquotemark\n20=\"235:U+00EB\"  # ediaeresis\n21=\"2813:U+201A\"  # singlelowquotemark\n22=\"165:U+00A5\"  # yen\n23=\"240:U+00F0\"  # eth\n24=\"252:U+00FC\"  # udiaeresis\n25=\"239:U+00EF\"  # idiaeresis\n26=\"16777535:U+013F\"  # U013F\n27=\"246:U+00F6\"  # odiaeresis\n28=\"217:U+00D9\"  # Ugrave\n29=\"2236:U+2264\"  # lessthanequal\n2A=\"65505\"  # Shift_L\n2B=\"65108:U+00AF\"  # dead_macron\n2C=\"2770:U+201C\"  # leftdoublequotemark\n2D=\"2771:U+201D\"  # rightdoublequotemark\n2E=\"174:U+00AE\"  # registered\n2F=\"2299:U+2190\"  # leftarrow\n30=\"2300:U+2191\"  # uparrow\n31=\"2301:U+2192\"  # rightarrow\n32=\"16785446:U+2026\"  # U2026\n33=\"16786117:U+22C5\"  # U22C5\n34=\"16785941:U+2215\"  # U2215\n35=\"16785938:U+2212\"  # U2212\n36=\"65506\"  # Shift_R\n37=\"16777215\"  # VoidSymbol\n38=\"65511\"  # Meta_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"16785878:U+21D6\"  # U21D6\n48=\"16785873:U+21D1\"  # U21D1\n49=\"16785879:U+21D7\"  # U21D7\n4A=\"16777215\"  # VoidSymbol\n4B=\"16785872:U+21D0\"  # U21D0\n4C=\"16785876:U+21D4\"  # U21D4\n4D=\"16785874:U+21D2\"  # U21D2\n4E=\"16777215\"  # VoidSymbol\n4F=\"16785881:U+21D9\"  # U21D9\n50=\"16785875:U+21D3\"  # U21D3\n51=\"16785880:U+21D8\"  # U21D8\n52=\"16785877:U+21D5\"  # U21D5\n53=\"16785455:U+202F\"  # U202F\n56=\"2237:U+2260\"  # notequal\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"16777215\"  # VoidSymbol\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"46:U+002E\"  # period\n"
  },
  {
    "path": "instfiles/km-00000813.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(azerty)\n# setxkbmap -rules evdev -model pc105 -layout be\n# Description: nl-BE\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n03=\"233:U+00E9\"  # eacute\n04=\"34:U+0022\"  # quotedbl\n05=\"39:U+0027\"  # apostrophe\n06=\"40:U+0028\"  # parenleft\n07=\"167:U+00A7\"  # section\n08=\"232:U+00E8\"  # egrave\n09=\"33:U+0021\"  # exclam\n0A=\"231:U+00E7\"  # ccedilla\n0B=\"224:U+00E0\"  # agrave\n0C=\"41:U+0029\"  # parenright\n0D=\"45:U+002D\"  # minus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"97:U+0061\"  # a\n11=\"122:U+007A\"  # z\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65106:U+005E\"  # dead_circumflex\n1B=\"36:U+0024\"  # dollar\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"113:U+0071\"  # q\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"109:U+006D\"  # m\n28=\"249:U+00F9\"  # ugrave\n29=\"178:U+00B2\"  # twosuperior\n2A=\"65505\"  # Shift_L\n2B=\"181:U+00B5\"  # mu\n2C=\"119:U+0077\"  # w\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"44:U+002C\"  # comma\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"61:U+003D\"  # equal\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"176:U+00B0\"  # degree\n0D=\"95:U+005F\"  # underscore\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"65:U+0041\"  # A\n11=\"90:U+005A\"  # Z\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"81:U+0051\"  # Q\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"77:U+004D\"  # M\n28=\"37:U+0025\"  # percent\n29=\"179:U+00B3\"  # threesuperior\n2A=\"65505\"  # Shift_L\n2B=\"163:U+00A3\"  # sterling\n2C=\"87:U+0057\"  # W\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"63:U+003F\"  # question\n33=\"46:U+002E\"  # period\n34=\"47:U+002F\"  # slash\n35=\"43:U+002B\"  # plus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"94:U+005E\"  # asciicircum\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"123:U+007B\"  # braceleft\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65105:U+00B4\"  # dead_acute\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"65115:U+00B8\"  # dead_cedilla\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65107:U+007E\"  # dead_tilde\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n03=\"201:U+00C9\"  # Eacute\n04=\"34:U+0022\"  # quotedbl\n05=\"39:U+0027\"  # apostrophe\n06=\"40:U+0028\"  # parenleft\n07=\"167:U+00A7\"  # section\n08=\"200:U+00C8\"  # Egrave\n09=\"33:U+0021\"  # exclam\n0A=\"199:U+00C7\"  # Ccedilla\n0B=\"192:U+00C0\"  # Agrave\n0C=\"41:U+0029\"  # parenright\n0D=\"45:U+002D\"  # minus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"65:U+0041\"  # A\n11=\"90:U+005A\"  # Z\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"65106:U+005E\"  # dead_circumflex\n1B=\"36:U+0024\"  # dollar\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"81:U+0051\"  # Q\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"77:U+004D\"  # M\n28=\"217:U+00D9\"  # Ugrave\n29=\"178:U+00B2\"  # twosuperior\n2A=\"65505\"  # Shift_L\n2C=\"87:U+0057\"  # W\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"44:U+002C\"  # comma\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"61:U+003D\"  # equal\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"94:U+005E\"  # asciicircum\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"123:U+007B\"  # braceleft\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65105:U+00B4\"  # dead_acute\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n32=\"65115:U+00B8\"  # dead_cedilla\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65107:U+007E\"  # dead_tilde\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"176:U+00B0\"  # degree\n0D=\"95:U+005F\"  # underscore\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"97:U+0061\"  # a\n11=\"122:U+007A\"  # z\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"42:U+002A\"  # asterisk\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"113:U+0071\"  # q\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"109:U+006D\"  # m\n28=\"37:U+0025\"  # percent\n29=\"179:U+00B3\"  # threesuperior\n2A=\"65505\"  # Shift_L\n2B=\"163:U+00A3\"  # sterling\n2C=\"119:U+0077\"  # w\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"63:U+003F\"  # question\n33=\"46:U+002E\"  # period\n34=\"47:U+002F\"  # slash\n35=\"43:U+002B\"  # plus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00000816.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=39:39\nKey21=171:171\nKey22=65288:8\nKey23=65289:9\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=43:43\nKey35=65105:180\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=231:231\nKey48=186:186\nKey49=92:92\nKey50=65505:0\nKey51=65107:126\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=44:44\nKey60=46:46\nKey61=45:45\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=47:47\nKey17=40:40\nKey18=41:41\nKey19=61:61\nKey20=63:63\nKey21=187:187\nKey22=65288:8\nKey23=65056:0\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=42:42\nKey35=65104:96\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=199:199\nKey48=170:170\nKey49=124:124\nKey50=65505:0\nKey51=65106:94\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=59:59\nKey60=58:58\nKey61=95:95\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=64:64\nKey12=163:163\nKey13=167:167\nKey14=189:189\nKey15=172:172\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=92:92\nKey21=65115:184\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=435:322\nKey26=8364:8364\nKey27=182:182\nKey28=956:359\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=248:248\nKey33=254:254\nKey34=65111:168\nKey35=65107:126\nKey36=65293:13\nKey37=65507:0\nKey38=230:230\nKey39=223:223\nKey40=240:240\nKey41=496:273\nKey42=959:331\nKey43=689:295\nKey44=65121:0\nKey45=930:312\nKey46=435:322\nKey47=65105:180\nKey48=65106:94\nKey49=172:172\nKey50=65505:0\nKey51=65104:96\nKey52=171:171\nKey53=187:187\nKey54=162:162\nKey55=2770:8220\nKey56=2771:8221\nKey57=110:110\nKey58=181:181\nKey59=2211:0\nKey60=183:183\nKey61=65120:0\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=2755:8539\nKey12=163:163\nKey13=36:36\nKey14=2756:8540\nKey15=2757:8541\nKey16=2758:8542\nKey17=2761:8482\nKey18=177:177\nKey19=176:176\nKey20=191:191\nKey21=65116:731\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=419:321\nKey26=162:162\nKey27=174:174\nKey28=940:358\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=216:216\nKey33=222:222\nKey34=65112:176\nKey35=65108:175\nKey36=65293:13\nKey37=65507:0\nKey38=198:198\nKey39=167:167\nKey40=208:208\nKey41=170:170\nKey42=957:330\nKey43=673:294\nKey44=65122:0\nKey45=38:38\nKey46=419:321\nKey47=65113:733\nKey48=65114:711\nKey49=172:172\nKey50=65505:0\nKey51=65109:728\nKey52=60:60\nKey53=62:62\nKey54=169:169\nKey55=2768:8216\nKey56=2769:8217\nKey57=78:78\nKey58=186:186\nKey59=215:215\nKey60=247:247\nKey61=65110:729\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=39:39\nKey21=171:171\nKey22=65288:8\nKey23=65289:9\nKey24=81:81\nKey25=87:87\nKey26=69:69\nKey27=82:82\nKey28=84:84\nKey29=89:89\nKey30=85:85\nKey31=73:73\nKey32=79:79\nKey33=80:80\nKey34=43:43\nKey35=65105:180\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=83:83\nKey40=68:68\nKey41=70:70\nKey42=71:71\nKey43=72:72\nKey44=74:74\nKey45=75:75\nKey46=76:76\nKey47=199:199\nKey48=186:186\nKey49=92:92\nKey50=65505:0\nKey51=65107:126\nKey52=90:90\nKey53=88:88\nKey54=67:67\nKey55=86:86\nKey56=66:66\nKey57=78:78\nKey58=77:77\nKey59=44:44\nKey60=46:46\nKey61=45:45\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=185:185\nKey11=64:64\nKey12=163:163\nKey13=167:167\nKey14=189:189\nKey15=172:172\nKey16=123:123\nKey17=91:91\nKey18=93:93\nKey19=125:125\nKey20=92:92\nKey21=65115:184\nKey22=65288:8\nKey23=65289:9\nKey24=64:64\nKey25=419:321\nKey26=8364:8364\nKey27=182:182\nKey28=940:358\nKey29=2299:8592\nKey30=2302:8595\nKey31=2301:8594\nKey32=216:216\nKey33=222:222\nKey34=65111:168\nKey35=65107:126\nKey36=65293:13\nKey37=65507:0\nKey38=198:198\nKey39=223:223\nKey40=208:208\nKey41=464:272\nKey42=957:330\nKey43=673:294\nKey44=65121:0\nKey45=930:312\nKey46=419:321\nKey47=65105:180\nKey48=65106:94\nKey49=172:172\nKey50=65505:0\nKey51=65104:96\nKey52=171:171\nKey53=187:187\nKey54=162:162\nKey55=2770:8220\nKey56=2771:8221\nKey57=78:78\nKey58=924:0\nKey59=2211:0\nKey60=183:183\nKey61=65120:0\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=34:34\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=38:38\nKey16=47:47\nKey17=40:40\nKey18=41:41\nKey19=61:61\nKey20=63:63\nKey21=187:187\nKey22=65288:8\nKey23=65056:0\nKey24=113:113\nKey25=119:119\nKey26=101:101\nKey27=114:114\nKey28=116:116\nKey29=121:121\nKey30=117:117\nKey31=105:105\nKey32=111:111\nKey33=112:112\nKey34=42:42\nKey35=65104:96\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=115:115\nKey40=100:100\nKey41=102:102\nKey42=103:103\nKey43=104:104\nKey44=106:106\nKey45=107:107\nKey46=108:108\nKey47=231:231\nKey48=170:170\nKey49=124:124\nKey50=65505:0\nKey51=65106:94\nKey52=122:122\nKey53=120:120\nKey54=99:99\nKey55=118:118\nKey56=98:98\nKey57=110:110\nKey58=109:109\nKey59=59:59\nKey60=58:58\nKey61=95:95\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=161:161\nKey11=2755:8539\nKey12=163:163\nKey13=36:36\nKey14=2756:8540\nKey15=2757:8541\nKey16=2758:8542\nKey17=2761:8482\nKey18=177:177\nKey19=176:176\nKey20=191:191\nKey21=65116:731\nKey22=65288:8\nKey23=65056:0\nKey24=2009:937\nKey25=435:322\nKey26=162:162\nKey27=174:174\nKey28=956:359\nKey29=165:165\nKey30=2300:8593\nKey31=697:305\nKey32=248:248\nKey33=254:254\nKey34=65112:176\nKey35=65108:175\nKey36=65293:13\nKey37=65507:0\nKey38=230:230\nKey39=167:167\nKey40=240:240\nKey41=170:170\nKey42=959:331\nKey43=689:295\nKey44=65122:0\nKey45=38:38\nKey46=435:322\nKey47=65113:733\nKey48=65114:711\nKey49=172:172\nKey50=65505:0\nKey51=65109:728\nKey52=60:60\nKey53=62:62\nKey54=169:169\nKey55=2768:8216\nKey56=2769:8217\nKey57=110:110\nKey58=186:186\nKey59=215:215\nKey60=247:247\nKey61=65110:729\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n"
  },
  {
    "path": "instfiles/km-00000816.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout pt\n# Description: pt-PT\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"171:U+00AB\"  # guillemotleft\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"43:U+002B\"  # plus\n1B=\"65105:U+00B4\"  # dead_acute\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"231:U+00E7\"  # ccedilla\n28=\"186:U+00BA\"  # masculine\n29=\"92:U+005C\"  # backslash\n2A=\"65505\"  # Shift_L\n2B=\"65107:U+007E\"  # dead_tilde\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"187:U+00BB\"  # guillemotright\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"42:U+002A\"  # asterisk\n1B=\"65104:U+0060\"  # dead_grave\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"199:U+00C7\"  # Ccedilla\n28=\"170:U+00AA\"  # ordfeminine\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"65106:U+005E\"  # dead_circumflex\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"167:U+00A7\"  # section\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"171:U+00AB\"  # guillemotleft\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"43:U+002B\"  # plus\n1B=\"65105:U+00B4\"  # dead_acute\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"199:U+00C7\"  # Ccedilla\n28=\"186:U+00BA\"  # masculine\n29=\"92:U+005C\"  # backslash\n2A=\"65505\"  # Shift_L\n2B=\"65107:U+007E\"  # dead_tilde\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"64:U+0040\"  # at\n04=\"163:U+00A3\"  # sterling\n05=\"167:U+00A7\"  # section\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"65115:U+00B8\"  # dead_cedilla\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"216:U+00D8\"  # Oslash\n19=\"222:U+00DE\"  # THORN\n1A=\"65111:U+00A8\"  # dead_diaeresis\n1B=\"65107:U+007E\"  # dead_tilde\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"65106:U+005E\"  # dead_circumflex\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65104:U+0060\"  # dead_grave\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"34:U+0022\"  # quotedbl\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"187:U+00BB\"  # guillemotright\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"42:U+002A\"  # asterisk\n1B=\"65104:U+0060\"  # dead_grave\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"231:U+00E7\"  # ccedilla\n28=\"170:U+00AA\"  # ordfeminine\n29=\"124:U+007C\"  # bar\n2A=\"65505\"  # Shift_L\n2B=\"65106:U+005E\"  # dead_circumflex\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"162:U+00A2\"  # cent\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"248:U+00F8\"  # oslash\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-0000100c.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwertz)\n# setxkbmap -rules evdev -model pc105 -layout ch -variant fr\n# Description: fr-CH\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"65106:U+005E\"  # dead_circumflex\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"232:U+00E8\"  # egrave\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"233:U+00E9\"  # eacute\n28=\"224:U+00E0\"  # agrave\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"36:U+0024\"  # dollar\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"43:U+002B\"  # plus\n03=\"34:U+0022\"  # quotedbl\n04=\"42:U+002A\"  # asterisk\n05=\"231:U+00E7\"  # ccedilla\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"252:U+00FC\"  # udiaeresis\n1B=\"33:U+0021\"  # exclam\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"246:U+00F6\"  # odiaeresis\n28=\"228:U+00E4\"  # adiaeresis\n29=\"176:U+00B0\"  # degree\n2A=\"65505\"  # Shift_L\n2B=\"163:U+00A3\"  # sterling\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"124:U+007C\"  # bar\n09=\"162:U+00A2\"  # cent\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"65105:U+00B4\"  # dead_acute\n0D=\"65107:U+007E\"  # dead_tilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"435:U+0142\"  # lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"956:U+0167\"  # tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"223:U+00DF\"  # ssharp\n20=\"240:U+00F0\"  # eth\n21=\"496:U+0111\"  # dstroke\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"435:U+0142\"  # lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"123:U+007B\"  # braceleft\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"110:U+006E\"  # n\n32=\"181:U+00B5\"  # mu\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"419:U+0141\"  # Lstroke\n12=\"69:U+0045\"  # E\n13=\"174:U+00AE\"  # registered\n14=\"940:U+0166\"  # Tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n1F=\"167:U+00A7\"  # section\n20=\"208:U+00D0\"  # ETH\n21=\"170:U+00AA\"  # ordfeminine\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"419:U+0141\"  # Lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"78:U+004E\"  # N\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"39:U+0027\"  # apostrophe\n0D=\"65106:U+005E\"  # dead_circumflex\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"90:U+005A\"  # Z\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"200:U+00C8\"  # Egrave\n1B=\"65111:U+00A8\"  # dead_diaeresis\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"201:U+00C9\"  # Eacute\n28=\"192:U+00C0\"  # Agrave\n29=\"167:U+00A7\"  # section\n2A=\"65505\"  # Shift_L\n2B=\"36:U+0024\"  # dollar\n2C=\"89:U+0059\"  # Y\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"45:U+002D\"  # minus\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"124:U+007C\"  # bar\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"188:U+00BC\"  # onequarter\n06=\"189:U+00BD\"  # onehalf\n07=\"172:U+00AC\"  # notsign\n08=\"124:U+007C\"  # bar\n09=\"162:U+00A2\"  # cent\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"65105:U+00B4\"  # dead_acute\n0D=\"65107:U+007E\"  # dead_tilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"64:U+0040\"  # at\n11=\"419:U+0141\"  # Lstroke\n12=\"8364:U+20AC\"  # EuroSign\n13=\"182:U+00B6\"  # paragraph\n14=\"940:U+0166\"  # Tslash\n15=\"2299:U+2190\"  # leftarrow\n16=\"2302:U+2193\"  # downarrow\n17=\"2301:U+2192\"  # rightarrow\n18=\"5052:U+0152\"  # OE\n19=\"222:U+00DE\"  # THORN\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"198:U+00C6\"  # AE\n20=\"208:U+00D0\"  # ETH\n21=\"464:U+0110\"  # Dstroke\n22=\"957:U+014A\"  # ENG\n23=\"673:U+0126\"  # Hstroke\n24=\"65121\"  # dead_hook\n25=\"930:U+0138\"  # kra\n26=\"419:U+0141\"  # Lstroke\n27=\"65105:U+00B4\"  # dead_acute\n28=\"123:U+007B\"  # braceleft\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"125:U+007D\"  # braceright\n2C=\"171:U+00AB\"  # guillemotleft\n2D=\"187:U+00BB\"  # guillemotright\n2E=\"162:U+00A2\"  # cent\n2F=\"2770:U+201C\"  # leftdoublequotemark\n30=\"2771:U+201D\"  # rightdoublequotemark\n31=\"78:U+004E\"  # N\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"65120\"  # dead_belowdot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"92:U+005C\"  # backslash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"43:U+002B\"  # plus\n03=\"34:U+0022\"  # quotedbl\n04=\"42:U+002A\"  # asterisk\n05=\"199:U+00C7\"  # Ccedilla\n06=\"37:U+0025\"  # percent\n07=\"38:U+0026\"  # ampersand\n08=\"47:U+002F\"  # slash\n09=\"40:U+0028\"  # parenleft\n0A=\"41:U+0029\"  # parenright\n0B=\"61:U+003D\"  # equal\n0C=\"63:U+003F\"  # question\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"122:U+007A\"  # z\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"220:U+00DC\"  # Udiaeresis\n1B=\"33:U+0021\"  # exclam\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"214:U+00D6\"  # Odiaeresis\n28=\"196:U+00C4\"  # Adiaeresis\n29=\"176:U+00B0\"  # degree\n2A=\"65505\"  # Shift_L\n2B=\"163:U+00A3\"  # sterling\n2C=\"121:U+0079\"  # y\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"59:U+003B\"  # semicolon\n34=\"58:U+003A\"  # colon\n35=\"95:U+005F\"  # underscore\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"36:U+0024\"  # dollar\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"65116:U+02DB\"  # dead_ogonek\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"2009:U+03A9\"  # Greek_OMEGA\n11=\"435:U+0142\"  # lstroke\n12=\"69:U+0045\"  # E\n13=\"174:U+00AE\"  # registered\n14=\"956:U+0167\"  # tslash\n15=\"165:U+00A5\"  # yen\n16=\"2300:U+2191\"  # uparrow\n17=\"697:U+0131\"  # idotless\n18=\"5053:U+0153\"  # oe\n19=\"254:U+00FE\"  # thorn\n1A=\"65112:U+00B0\"  # dead_abovering\n1B=\"65108:U+00AF\"  # dead_macron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"230:U+00E6\"  # ae\n1F=\"167:U+00A7\"  # section\n20=\"240:U+00F0\"  # eth\n21=\"170:U+00AA\"  # ordfeminine\n22=\"959:U+014B\"  # eng\n23=\"689:U+0127\"  # hstroke\n24=\"65122\"  # dead_horn\n25=\"38:U+0026\"  # ampersand\n26=\"435:U+0142\"  # lstroke\n27=\"65113:U+02DD\"  # dead_doubleacute\n28=\"65114:U+02C7\"  # dead_caron\n29=\"172:U+00AC\"  # notsign\n2A=\"65505\"  # Shift_L\n2B=\"65109:U+02D8\"  # dead_breve\n2C=\"60:U+003C\"  # less\n2D=\"62:U+003E\"  # greater\n2E=\"169:U+00A9\"  # copyright\n2F=\"2768:U+2018\"  # leftsinglequotemark\n30=\"2769:U+2019\"  # rightsinglequotemark\n31=\"110:U+006E\"  # n\n32=\"186:U+00BA\"  # masculine\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"65110:U+02D9\"  # dead_abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00010409.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=91:91\nKey21=93:93\nKey22=65288:8\nKey23=65289:9\nKey24=39:39\nKey25=44:44\nKey26=46:46\nKey27=112:112\nKey28=121:121\nKey29=102:102\nKey30=103:103\nKey31=99:99\nKey32=114:114\nKey33=108:108\nKey34=47:47\nKey35=61:61\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=111:111\nKey40=101:101\nKey41=117:117\nKey42=105:105\nKey43=100:100\nKey44=104:104\nKey45=116:116\nKey46=110:110\nKey47=115:115\nKey48=45:45\nKey49=96:96\nKey50=65505:0\nKey51=92:92\nKey52=59:59\nKey53=113:113\nKey54=106:106\nKey55=107:107\nKey56=120:120\nKey57=98:98\nKey58=109:109\nKey59=119:119\nKey60=118:118\nKey61=122:122\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=60:60\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=64:64\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=94:94\nKey16=38:38\nKey17=42:42\nKey18=40:40\nKey19=41:41\nKey20=123:123\nKey21=125:125\nKey22=65288:8\nKey23=65056:0\nKey24=34:34\nKey25=60:60\nKey26=62:62\nKey27=80:80\nKey28=89:89\nKey29=70:70\nKey30=71:71\nKey31=67:67\nKey32=82:82\nKey33=76:76\nKey34=63:63\nKey35=43:43\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=79:79\nKey40=69:69\nKey41=85:85\nKey42=73:73\nKey43=68:68\nKey44=72:72\nKey45=84:84\nKey46=78:78\nKey47=83:83\nKey48=95:95\nKey49=126:126\nKey50=65505:0\nKey51=124:124\nKey52=58:58\nKey53=81:81\nKey54=74:74\nKey55=75:75\nKey56=88:88\nKey57=66:66\nKey58=77:77\nKey59=87:87\nKey60=86:86\nKey61=90:90\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65463:55\nKey80=65464:56\nKey81=65465:57\nKey82=65453:45\nKey83=65460:52\nKey84=65461:53\nKey85=65462:54\nKey86=65451:43\nKey87=65457:49\nKey88=65458:50\nKey89=65459:51\nKey90=65456:48\nKey91=65454:46\nKey92=65377:0\nKey94=62:62\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=65469:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=65106:94\nKey16=55:55\nKey17=56:56\nKey18=65104:96\nKey19=48:48\nKey20=91:91\nKey21=65107:126\nKey22=65288:8\nKey23=65289:9\nKey24=65105:180\nKey25=65115:184\nKey26=65110:729\nKey27=112:112\nKey28=121:121\nKey29=102:102\nKey30=103:103\nKey31=99:99\nKey32=114:114\nKey33=108:108\nKey34=47:47\nKey35=61:61\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=111:111\nKey40=101:101\nKey41=117:117\nKey42=105:105\nKey43=100:100\nKey44=104:104\nKey45=116:116\nKey46=110:110\nKey47=115:115\nKey48=45:45\nKey49=65104:96\nKey50=65505:0\nKey51=92:92\nKey52=65116:731\nKey53=113:113\nKey54=106:106\nKey55=107:107\nKey56=120:120\nKey57=98:98\nKey58=109:109\nKey59=119:119\nKey60=118:118\nKey61=122:122\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=124:124\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=64:64\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=65106:94\nKey16=38:38\nKey17=42:42\nKey19=41:41\nKey20=123:123\nKey22=65288:8\nKey23=65056:0\nKey24=65111:168\nKey25=65114:711\nKey26=183:183\nKey27=80:80\nKey28=89:89\nKey29=70:70\nKey30=71:71\nKey31=67:67\nKey32=82:82\nKey33=76:76\nKey34=63:63\nKey35=43:43\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=79:79\nKey40=69:69\nKey41=85:85\nKey42=73:73\nKey43=68:68\nKey44=72:72\nKey45=84:84\nKey46=78:78\nKey47=83:83\nKey48=95:95\nKey49=65107:126\nKey50=65505:0\nKey51=124:124\nKey52=65113:733\nKey53=81:81\nKey54=74:74\nKey55=75:75\nKey56=88:88\nKey57=66:66\nKey58=77:77\nKey59=87:87\nKey60=86:86\nKey61=90:90\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65463:55\nKey80=65464:56\nKey81=65465:57\nKey82=65453:45\nKey83=65460:52\nKey84=65461:53\nKey85=65462:54\nKey86=65451:43\nKey87=65457:49\nKey88=65458:50\nKey89=65459:51\nKey90=65456:48\nKey91=65454:46\nKey92=65377:0\nKey94=166:166\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=65469:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=54:54\nKey16=55:55\nKey17=56:56\nKey18=57:57\nKey19=48:48\nKey20=91:91\nKey21=93:93\nKey22=65288:8\nKey23=65289:9\nKey24=39:39\nKey25=44:44\nKey26=46:46\nKey27=80:80\nKey28=89:89\nKey29=70:70\nKey30=71:71\nKey31=67:67\nKey32=82:82\nKey33=76:76\nKey34=47:47\nKey35=61:61\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=79:79\nKey40=69:69\nKey41=85:85\nKey42=73:73\nKey43=68:68\nKey44=72:72\nKey45=84:84\nKey46=78:78\nKey47=83:83\nKey48=45:45\nKey49=96:96\nKey50=65505:0\nKey51=92:92\nKey52=59:59\nKey53=81:81\nKey54=74:74\nKey55=75:75\nKey56=88:88\nKey57=66:66\nKey58=77:77\nKey59=87:87\nKey60=86:86\nKey61=90:90\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=60:60\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=49:49\nKey11=50:50\nKey12=51:51\nKey13=52:52\nKey14=53:53\nKey15=65106:94\nKey16=55:55\nKey17=56:56\nKey18=65104:96\nKey19=48:48\nKey20=91:91\nKey21=65107:126\nKey22=65288:8\nKey23=65289:9\nKey24=65105:180\nKey25=65115:184\nKey26=65110:729\nKey27=80:80\nKey28=89:89\nKey29=70:70\nKey30=71:71\nKey31=67:67\nKey32=82:82\nKey33=76:76\nKey34=47:47\nKey35=61:61\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=79:79\nKey40=69:69\nKey41=85:85\nKey42=73:73\nKey43=68:68\nKey44=72:72\nKey45=84:84\nKey46=78:78\nKey47=83:83\nKey48=45:45\nKey49=65104:96\nKey50=65505:0\nKey51=92:92\nKey52=65116:731\nKey53=81:81\nKey54=74:74\nKey55=75:75\nKey56=88:88\nKey57=66:66\nKey58=77:77\nKey59=87:87\nKey60=86:86\nKey61=90:90\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey92=65377:0\nKey94=124:124\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey126=65469:61\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025044:0\nKey173=269025046:0\nKey174=269025045:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=64:64\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=94:94\nKey16=38:38\nKey17=42:42\nKey18=40:40\nKey19=41:41\nKey20=123:123\nKey21=125:125\nKey22=65288:8\nKey23=65056:0\nKey24=34:34\nKey25=60:60\nKey26=62:62\nKey27=112:112\nKey28=121:121\nKey29=102:102\nKey30=103:103\nKey31=99:99\nKey32=114:114\nKey33=108:108\nKey34=63:63\nKey35=43:43\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=111:111\nKey40=101:101\nKey41=117:117\nKey42=105:105\nKey43=100:100\nKey44=104:104\nKey45=116:116\nKey46=110:110\nKey47=115:115\nKey48=95:95\nKey49=126:126\nKey50=65505:0\nKey51=124:124\nKey52=58:58\nKey53=113:113\nKey54=106:106\nKey55=107:107\nKey56=120:120\nKey57=98:98\nKey58=109:109\nKey59=119:119\nKey60=118:118\nKey61=122:122\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65463:55\nKey80=65464:56\nKey81=65465:57\nKey82=65453:45\nKey83=65460:52\nKey84=65461:53\nKey85=65462:54\nKey86=65451:43\nKey87=65457:49\nKey88=65458:50\nKey89=65459:51\nKey90=65456:48\nKey91=65454:46\nKey92=65377:0\nKey94=62:62\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=65469:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=33:33\nKey11=64:64\nKey12=35:35\nKey13=36:36\nKey14=37:37\nKey15=65106:94\nKey16=38:38\nKey17=42:42\nKey19=41:41\nKey20=123:123\nKey22=65288:8\nKey23=65056:0\nKey24=65111:168\nKey25=65114:711\nKey26=183:183\nKey27=112:112\nKey28=121:121\nKey29=102:102\nKey30=103:103\nKey31=99:99\nKey32=114:114\nKey33=108:108\nKey34=63:63\nKey35=43:43\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=111:111\nKey40=101:101\nKey41=117:117\nKey42=105:105\nKey43=100:100\nKey44=104:104\nKey45=116:116\nKey46=110:110\nKey47=115:115\nKey48=95:95\nKey49=65107:126\nKey50=65505:0\nKey51=124:124\nKey52=65113:733\nKey53=113:113\nKey54=106:106\nKey55=107:107\nKey56=120:120\nKey57=98:98\nKey58=109:109\nKey59=119:119\nKey60=118:118\nKey61=122:122\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65463:55\nKey80=65464:56\nKey81=65465:57\nKey82=65453:45\nKey83=65460:52\nKey84=65461:53\nKey85=65462:54\nKey86=65451:43\nKey87=65457:49\nKey88=65458:50\nKey89=65459:51\nKey90=65456:48\nKey91=65454:46\nKey92=65377:0\nKey94=166:166\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey114=269025049:0\nKey115=65515:0\nKey116=65516:0\nKey118=269025153:0\nKey119=269025093:0\nKey120=269025094:0\nKey121=269025042:0\nKey122=269025041:0\nKey123=269025043:0\nKey124=65027:0\nKey125=65513:0\nKey126=65469:61\nKey127=65515:0\nKey128=65517:0\nKey136=65385:0\nKey156=269025089:0\nKey157=269025090:0\nKey163=269025049:0\nKey164=269025072:0\nKey166=269025062:0\nKey167=269025063:0\nKey171=269025047:0\nKey172=269025073:0\nKey173=269025046:0\nKey174=269025068:0\nKey180=269025048:0\nKey181=269025139:0\nKey225=269025051:0\nKey234=269025074:0\n"
  },
  {
    "path": "instfiles/km-00010409.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout us -variant dvorak\n# Description: en-US\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"91:U+005B\"  # bracketleft\n0D=\"93:U+005D\"  # bracketright\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"39:U+0027\"  # apostrophe\n11=\"44:U+002C\"  # comma\n12=\"46:U+002E\"  # period\n13=\"112:U+0070\"  # p\n14=\"121:U+0079\"  # y\n15=\"102:U+0066\"  # f\n16=\"103:U+0067\"  # g\n17=\"99:U+0063\"  # c\n18=\"114:U+0072\"  # r\n19=\"108:U+006C\"  # l\n1A=\"47:U+002F\"  # slash\n1B=\"61:U+003D\"  # equal\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"111:U+006F\"  # o\n20=\"101:U+0065\"  # e\n21=\"117:U+0075\"  # u\n22=\"105:U+0069\"  # i\n23=\"100:U+0064\"  # d\n24=\"104:U+0068\"  # h\n25=\"116:U+0074\"  # t\n26=\"110:U+006E\"  # n\n27=\"115:U+0073\"  # s\n28=\"45:U+002D\"  # minus\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"59:U+003B\"  # semicolon\n2D=\"113:U+0071\"  # q\n2E=\"106:U+006A\"  # j\n2F=\"107:U+006B\"  # k\n30=\"120:U+0078\"  # x\n31=\"98:U+0062\"  # b\n32=\"109:U+006D\"  # m\n33=\"119:U+0077\"  # w\n34=\"118:U+0076\"  # v\n35=\"122:U+007A\"  # z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"123:U+007B\"  # braceleft\n0D=\"125:U+007D\"  # braceright\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"34:U+0022\"  # quotedbl\n11=\"60:U+003C\"  # less\n12=\"62:U+003E\"  # greater\n13=\"80:U+0050\"  # P\n14=\"89:U+0059\"  # Y\n15=\"70:U+0046\"  # F\n16=\"71:U+0047\"  # G\n17=\"67:U+0043\"  # C\n18=\"82:U+0052\"  # R\n19=\"76:U+004C\"  # L\n1A=\"63:U+003F\"  # question\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"79:U+004F\"  # O\n20=\"69:U+0045\"  # E\n21=\"85:U+0055\"  # U\n22=\"73:U+0049\"  # I\n23=\"68:U+0044\"  # D\n24=\"72:U+0048\"  # H\n25=\"84:U+0054\"  # T\n26=\"78:U+004E\"  # N\n27=\"83:U+0053\"  # S\n28=\"95:U+005F\"  # underscore\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"58:U+003A\"  # colon\n2D=\"81:U+0051\"  # Q\n2E=\"74:U+004A\"  # J\n2F=\"75:U+004B\"  # K\n30=\"88:U+0058\"  # X\n31=\"66:U+0042\"  # B\n32=\"77:U+004D\"  # M\n33=\"87:U+0057\"  # W\n34=\"86:U+0056\"  # V\n35=\"90:U+005A\"  # Z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"65106:U+005E\"  # dead_circumflex\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"65104:U+0060\"  # dead_grave\n0B=\"48:U+0030\"  # 0\n0C=\"91:U+005B\"  # bracketleft\n0D=\"65107:U+007E\"  # dead_tilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"65105:U+00B4\"  # dead_acute\n11=\"65115:U+00B8\"  # dead_cedilla\n12=\"65110:U+02D9\"  # dead_abovedot\n13=\"112:U+0070\"  # p\n14=\"121:U+0079\"  # y\n15=\"102:U+0066\"  # f\n16=\"103:U+0067\"  # g\n17=\"99:U+0063\"  # c\n18=\"114:U+0072\"  # r\n19=\"108:U+006C\"  # l\n1A=\"47:U+002F\"  # slash\n1B=\"61:U+003D\"  # equal\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"111:U+006F\"  # o\n20=\"101:U+0065\"  # e\n21=\"117:U+0075\"  # u\n22=\"105:U+0069\"  # i\n23=\"100:U+0064\"  # d\n24=\"104:U+0068\"  # h\n25=\"116:U+0074\"  # t\n26=\"110:U+006E\"  # n\n27=\"115:U+0073\"  # s\n28=\"45:U+002D\"  # minus\n29=\"65104:U+0060\"  # dead_grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"65116:U+02DB\"  # dead_ogonek\n2D=\"113:U+0071\"  # q\n2E=\"106:U+006A\"  # j\n2F=\"107:U+006B\"  # k\n30=\"120:U+0078\"  # x\n31=\"98:U+0062\"  # b\n32=\"109:U+006D\"  # m\n33=\"119:U+0077\"  # w\n34=\"118:U+0076\"  # v\n35=\"122:U+007A\"  # z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"65106:U+005E\"  # dead_circumflex\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"65109:U+02D8\"  # dead_breve\n0B=\"41:U+0029\"  # parenright\n0C=\"123:U+007B\"  # braceleft\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"65111:U+00A8\"  # dead_diaeresis\n11=\"65114:U+02C7\"  # dead_caron\n12=\"183:U+00B7\"  # periodcentered\n13=\"80:U+0050\"  # P\n14=\"89:U+0059\"  # Y\n15=\"70:U+0046\"  # F\n16=\"71:U+0047\"  # G\n17=\"67:U+0043\"  # C\n18=\"82:U+0052\"  # R\n19=\"76:U+004C\"  # L\n1A=\"63:U+003F\"  # question\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"79:U+004F\"  # O\n20=\"69:U+0045\"  # E\n21=\"85:U+0055\"  # U\n22=\"73:U+0049\"  # I\n23=\"68:U+0044\"  # D\n24=\"72:U+0048\"  # H\n25=\"84:U+0054\"  # T\n26=\"78:U+004E\"  # N\n27=\"83:U+0053\"  # S\n28=\"95:U+005F\"  # underscore\n29=\"65107:U+007E\"  # dead_tilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"65113:U+02DD\"  # dead_doubleacute\n2D=\"81:U+0051\"  # Q\n2E=\"74:U+004A\"  # J\n2F=\"75:U+004B\"  # K\n30=\"88:U+0058\"  # X\n31=\"66:U+0042\"  # B\n32=\"77:U+004D\"  # M\n33=\"87:U+0057\"  # W\n34=\"86:U+0056\"  # V\n35=\"90:U+005A\"  # Z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"91:U+005B\"  # bracketleft\n0D=\"93:U+005D\"  # bracketright\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"39:U+0027\"  # apostrophe\n11=\"44:U+002C\"  # comma\n12=\"46:U+002E\"  # period\n13=\"80:U+0050\"  # P\n14=\"89:U+0059\"  # Y\n15=\"70:U+0046\"  # F\n16=\"71:U+0047\"  # G\n17=\"67:U+0043\"  # C\n18=\"82:U+0052\"  # R\n19=\"76:U+004C\"  # L\n1A=\"47:U+002F\"  # slash\n1B=\"61:U+003D\"  # equal\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"79:U+004F\"  # O\n20=\"69:U+0045\"  # E\n21=\"85:U+0055\"  # U\n22=\"73:U+0049\"  # I\n23=\"68:U+0044\"  # D\n24=\"72:U+0048\"  # H\n25=\"84:U+0054\"  # T\n26=\"78:U+004E\"  # N\n27=\"83:U+0053\"  # S\n28=\"45:U+002D\"  # minus\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"59:U+003B\"  # semicolon\n2D=\"81:U+0051\"  # Q\n2E=\"74:U+004A\"  # J\n2F=\"75:U+004B\"  # K\n30=\"88:U+0058\"  # X\n31=\"66:U+0042\"  # B\n32=\"77:U+004D\"  # M\n33=\"87:U+0057\"  # W\n34=\"86:U+0056\"  # V\n35=\"90:U+005A\"  # Z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"65106:U+005E\"  # dead_circumflex\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"65104:U+0060\"  # dead_grave\n0B=\"48:U+0030\"  # 0\n0C=\"91:U+005B\"  # bracketleft\n0D=\"65107:U+007E\"  # dead_tilde\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"65105:U+00B4\"  # dead_acute\n11=\"65115:U+00B8\"  # dead_cedilla\n12=\"65110:U+02D9\"  # dead_abovedot\n13=\"80:U+0050\"  # P\n14=\"89:U+0059\"  # Y\n15=\"70:U+0046\"  # F\n16=\"71:U+0047\"  # G\n17=\"67:U+0043\"  # C\n18=\"82:U+0052\"  # R\n19=\"76:U+004C\"  # L\n1A=\"47:U+002F\"  # slash\n1B=\"61:U+003D\"  # equal\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"79:U+004F\"  # O\n20=\"69:U+0045\"  # E\n21=\"85:U+0055\"  # U\n22=\"73:U+0049\"  # I\n23=\"68:U+0044\"  # D\n24=\"72:U+0048\"  # H\n25=\"84:U+0054\"  # T\n26=\"78:U+004E\"  # N\n27=\"83:U+0053\"  # S\n28=\"45:U+002D\"  # minus\n29=\"65104:U+0060\"  # dead_grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"65116:U+02DB\"  # dead_ogonek\n2D=\"81:U+0051\"  # Q\n2E=\"74:U+004A\"  # J\n2F=\"75:U+004B\"  # K\n30=\"88:U+0058\"  # X\n31=\"66:U+0042\"  # B\n32=\"77:U+004D\"  # M\n33=\"87:U+0057\"  # W\n34=\"86:U+0056\"  # V\n35=\"90:U+005A\"  # Z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"123:U+007B\"  # braceleft\n0D=\"125:U+007D\"  # braceright\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"34:U+0022\"  # quotedbl\n11=\"60:U+003C\"  # less\n12=\"62:U+003E\"  # greater\n13=\"112:U+0070\"  # p\n14=\"121:U+0079\"  # y\n15=\"102:U+0066\"  # f\n16=\"103:U+0067\"  # g\n17=\"99:U+0063\"  # c\n18=\"114:U+0072\"  # r\n19=\"108:U+006C\"  # l\n1A=\"63:U+003F\"  # question\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"111:U+006F\"  # o\n20=\"101:U+0065\"  # e\n21=\"117:U+0075\"  # u\n22=\"105:U+0069\"  # i\n23=\"100:U+0064\"  # d\n24=\"104:U+0068\"  # h\n25=\"116:U+0074\"  # t\n26=\"110:U+006E\"  # n\n27=\"115:U+0073\"  # s\n28=\"95:U+005F\"  # underscore\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"58:U+003A\"  # colon\n2D=\"113:U+0071\"  # q\n2E=\"106:U+006A\"  # j\n2F=\"107:U+006B\"  # k\n30=\"120:U+0078\"  # x\n31=\"98:U+0062\"  # b\n32=\"109:U+006D\"  # m\n33=\"119:U+0077\"  # w\n34=\"118:U+0076\"  # v\n35=\"122:U+007A\"  # z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"65106:U+005E\"  # dead_circumflex\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"65109:U+02D8\"  # dead_breve\n0B=\"41:U+0029\"  # parenright\n0C=\"123:U+007B\"  # braceleft\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"65111:U+00A8\"  # dead_diaeresis\n11=\"65114:U+02C7\"  # dead_caron\n12=\"183:U+00B7\"  # periodcentered\n13=\"112:U+0070\"  # p\n14=\"121:U+0079\"  # y\n15=\"102:U+0066\"  # f\n16=\"103:U+0067\"  # g\n17=\"99:U+0063\"  # c\n18=\"114:U+0072\"  # r\n19=\"108:U+006C\"  # l\n1A=\"63:U+003F\"  # question\n1B=\"43:U+002B\"  # plus\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"111:U+006F\"  # o\n20=\"101:U+0065\"  # e\n21=\"117:U+0075\"  # u\n22=\"105:U+0069\"  # i\n23=\"100:U+0064\"  # d\n24=\"104:U+0068\"  # h\n25=\"116:U+0074\"  # t\n26=\"110:U+006E\"  # n\n27=\"115:U+0073\"  # s\n28=\"95:U+005F\"  # underscore\n29=\"65107:U+007E\"  # dead_tilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"65113:U+02DD\"  # dead_doubleacute\n2D=\"113:U+0071\"  # q\n2E=\"106:U+006A\"  # j\n2F=\"107:U+006B\"  # k\n30=\"120:U+0078\"  # x\n31=\"98:U+0062\"  # b\n32=\"109:U+006D\"  # m\n33=\"119:U+0077\"  # w\n34=\"118:U+0076\"  # v\n35=\"122:U+007A\"  # z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00010426.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout lv\n# Description: lv-LV\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"8364:U+20AC\"  # EuroSign\n06=\"189:U+00BD\"  # onehalf\n07=\"190:U+00BE\"  # threequarters\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"2730:U+2013\"  # endash\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"954:U+0113\"  # emacron\n13=\"947:U+0157\"  # rcedilla\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"1022:U+016B\"  # umacron\n17=\"1007:U+012B\"  # imacron\n18=\"1010:U+014D\"  # omacron\n19=\"112:U+0070\"  # p\n1A=\"171:U+00AB\"  # guillemotleft\n1B=\"187:U+00BB\"  # guillemotright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"992:U+0101\"  # amacron\n1F=\"441:U+0161\"  # scaron\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"955:U+0123\"  # gcedilla\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"1011:U+0137\"  # kcedilla\n26=\"950:U+013C\"  # lcedilla\n27=\"59:U+003B\"  # semicolon\n28=\"2770:U+201C\"  # leftdoublequotemark\n29=\"180:U+00B4\"  # acute\n2A=\"65505\"  # Shift_L\n2B=\"96:U+0060\"  # grave\n2C=\"446:U+017E\"  # zcaron\n2D=\"120:U+0078\"  # x\n2E=\"488:U+010D\"  # ccaron\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"1009:U+0146\"  # ncedilla\n32=\"109:U+006D\"  # m\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"162:U+00A2\"  # cent\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"2729:U+2014\"  # emdash\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"938:U+0112\"  # Emacron\n13=\"931:U+0156\"  # Rcedilla\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"990:U+016A\"  # Umacron\n17=\"975:U+012A\"  # Imacron\n18=\"978:U+014C\"  # Omacron\n19=\"80:U+0050\"  # P\n1A=\"2770:U+201C\"  # leftdoublequotemark\n1B=\"2771:U+201D\"  # rightdoublequotemark\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"960:U+0100\"  # Amacron\n1F=\"425:U+0160\"  # Scaron\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"939:U+0122\"  # Gcedilla\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"979:U+0136\"  # Kcedilla\n26=\"934:U+013B\"  # Lcedilla\n27=\"58:U+003A\"  # colon\n28=\"2814:U+201E\"  # doublelowquotemark\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"418:U+02D8\"  # breve\n2C=\"430:U+017D\"  # Zcaron\n2D=\"88:U+0058\"  # X\n2E=\"456:U+010C\"  # Ccaron\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"977:U+0145\"  # Ncedilla\n32=\"77:U+004D\"  # M\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"511:U+02D9\"  # abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"69:U+0045\"  # E\n13=\"82:U+0052\"  # R\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"85:U+0055\"  # U\n17=\"73:U+0049\"  # I\n18=\"79:U+004F\"  # O\n19=\"80:U+0050\"  # P\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"83:U+0053\"  # S\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"71:U+0047\"  # G\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"75:U+004B\"  # K\n26=\"76:U+004C\"  # L\n27=\"59:U+003B\"  # semicolon\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"78:U+004E\"  # N\n32=\"77:U+004D\"  # M\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"60:U+003C\"  # less\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"8364:U+20AC\"  # EuroSign\n06=\"189:U+00BD\"  # onehalf\n07=\"190:U+00BE\"  # threequarters\n08=\"123:U+007B\"  # braceleft\n09=\"91:U+005B\"  # bracketleft\n0A=\"93:U+005D\"  # bracketright\n0B=\"125:U+007D\"  # braceright\n0C=\"92:U+005C\"  # backslash\n0D=\"2730:U+2013\"  # endash\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"938:U+0112\"  # Emacron\n13=\"931:U+0156\"  # Rcedilla\n14=\"84:U+0054\"  # T\n15=\"89:U+0059\"  # Y\n16=\"990:U+016A\"  # Umacron\n17=\"975:U+012A\"  # Imacron\n18=\"978:U+014C\"  # Omacron\n19=\"80:U+0050\"  # P\n1A=\"171:U+00AB\"  # guillemotleft\n1B=\"187:U+00BB\"  # guillemotright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"960:U+0100\"  # Amacron\n1F=\"425:U+0160\"  # Scaron\n20=\"68:U+0044\"  # D\n21=\"70:U+0046\"  # F\n22=\"939:U+0122\"  # Gcedilla\n23=\"72:U+0048\"  # H\n24=\"74:U+004A\"  # J\n25=\"979:U+0136\"  # Kcedilla\n26=\"934:U+013B\"  # Lcedilla\n27=\"59:U+003B\"  # semicolon\n28=\"2770:U+201C\"  # leftdoublequotemark\n29=\"180:U+00B4\"  # acute\n2A=\"65505\"  # Shift_L\n2B=\"96:U+0060\"  # grave\n2C=\"430:U+017D\"  # Zcaron\n2D=\"88:U+0058\"  # X\n2E=\"456:U+010C\"  # Ccaron\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"977:U+0145\"  # Ncedilla\n32=\"77:U+004D\"  # M\n33=\"2211\"  # horizconnector\n34=\"183:U+00B7\"  # periodcentered\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"124:U+007C\"  # bar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"101:U+0065\"  # e\n13=\"114:U+0072\"  # r\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"117:U+0075\"  # u\n17=\"105:U+0069\"  # i\n18=\"111:U+006F\"  # o\n19=\"112:U+0070\"  # p\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"115:U+0073\"  # s\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"103:U+0067\"  # g\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"107:U+006B\"  # k\n26=\"108:U+006C\"  # l\n27=\"58:U+003A\"  # colon\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"110:U+006E\"  # n\n32=\"109:U+006D\"  # m\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"62:U+003E\"  # greater\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"2755:U+215B\"  # oneeighth\n04=\"163:U+00A3\"  # sterling\n05=\"162:U+00A2\"  # cent\n06=\"2756:U+215C\"  # threeeighths\n07=\"2757:U+215D\"  # fiveeighths\n08=\"2758:U+215E\"  # seveneighths\n09=\"2761:U+2122\"  # trademark\n0A=\"177:U+00B1\"  # plusminus\n0B=\"176:U+00B0\"  # degree\n0C=\"191:U+00BF\"  # questiondown\n0D=\"2729:U+2014\"  # emdash\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"954:U+0113\"  # emacron\n13=\"947:U+0157\"  # rcedilla\n14=\"116:U+0074\"  # t\n15=\"121:U+0079\"  # y\n16=\"1022:U+016B\"  # umacron\n17=\"1007:U+012B\"  # imacron\n18=\"1010:U+014D\"  # omacron\n19=\"112:U+0070\"  # p\n1A=\"2770:U+201C\"  # leftdoublequotemark\n1B=\"2771:U+201D\"  # rightdoublequotemark\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"992:U+0101\"  # amacron\n1F=\"441:U+0161\"  # scaron\n20=\"100:U+0064\"  # d\n21=\"102:U+0066\"  # f\n22=\"955:U+0123\"  # gcedilla\n23=\"104:U+0068\"  # h\n24=\"106:U+006A\"  # j\n25=\"1011:U+0137\"  # kcedilla\n26=\"950:U+013C\"  # lcedilla\n27=\"58:U+003A\"  # colon\n28=\"2814:U+201E\"  # doublelowquotemark\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"418:U+02D8\"  # breve\n2C=\"446:U+017E\"  # zcaron\n2D=\"120:U+0078\"  # x\n2E=\"488:U+010D\"  # ccaron\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"1009:U+0146\"  # ncedilla\n32=\"109:U+006D\"  # m\n33=\"215:U+00D7\"  # multiply\n34=\"247:U+00F7\"  # division\n35=\"511:U+02D9\"  # abovedot\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"166:U+00A6\"  # brokenbar\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-00060409.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc104 -layout us -variant colemak\n# Description: en-US\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=false\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"49:U+0031\"  # 1\n03=\"50:U+0032\"  # 2\n04=\"51:U+0033\"  # 3\n05=\"52:U+0034\"  # 4\n06=\"53:U+0035\"  # 5\n07=\"54:U+0036\"  # 6\n08=\"55:U+0037\"  # 7\n09=\"56:U+0038\"  # 8\n0A=\"57:U+0039\"  # 9\n0B=\"48:U+0030\"  # 0\n0C=\"45:U+002D\"  # minus\n0D=\"61:U+003D\"  # equal\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"113:U+0071\"  # q\n11=\"119:U+0077\"  # w\n12=\"102:U+0066\"  # f\n13=\"112:U+0070\"  # p\n14=\"103:U+0067\"  # g\n15=\"106:U+006A\"  # j\n16=\"108:U+006C\"  # l\n17=\"117:U+0075\"  # u\n18=\"121:U+0079\"  # y\n19=\"59:U+003B\"  # semicolon\n1A=\"91:U+005B\"  # bracketleft\n1B=\"93:U+005D\"  # bracketright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"114:U+0072\"  # r\n20=\"115:U+0073\"  # s\n21=\"116:U+0074\"  # t\n22=\"100:U+0064\"  # d\n23=\"104:U+0068\"  # h\n24=\"110:U+006E\"  # n\n25=\"101:U+0065\"  # e\n26=\"105:U+0069\"  # i\n27=\"111:U+006F\"  # o\n28=\"39:U+0027\"  # apostrophe\n29=\"96:U+0060\"  # grave\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"122:U+007A\"  # z\n2D=\"120:U+0078\"  # x\n2E=\"99:U+0063\"  # c\n2F=\"118:U+0076\"  # v\n30=\"98:U+0062\"  # b\n31=\"107:U+006B\"  # k\n32=\"109:U+006D\"  # m\n33=\"44:U+002C\"  # comma\n34=\"46:U+002E\"  # period\n35=\"47:U+002F\"  # slash\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65288:U+0008\"  # BackSpace\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"45:U+002D\"  # minus\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"33:U+0021\"  # exclam\n03=\"64:U+0040\"  # at\n04=\"35:U+0023\"  # numbersign\n05=\"36:U+0024\"  # dollar\n06=\"37:U+0025\"  # percent\n07=\"94:U+005E\"  # asciicircum\n08=\"38:U+0026\"  # ampersand\n09=\"42:U+002A\"  # asterisk\n0A=\"40:U+0028\"  # parenleft\n0B=\"41:U+0029\"  # parenright\n0C=\"95:U+005F\"  # underscore\n0D=\"43:U+002B\"  # plus\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"81:U+0051\"  # Q\n11=\"87:U+0057\"  # W\n12=\"70:U+0046\"  # F\n13=\"80:U+0050\"  # P\n14=\"71:U+0047\"  # G\n15=\"74:U+004A\"  # J\n16=\"76:U+004C\"  # L\n17=\"85:U+0055\"  # U\n18=\"89:U+0059\"  # Y\n19=\"58:U+003A\"  # colon\n1A=\"123:U+007B\"  # braceleft\n1B=\"125:U+007D\"  # braceright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"82:U+0052\"  # R\n20=\"83:U+0053\"  # S\n21=\"84:U+0054\"  # T\n22=\"68:U+0044\"  # D\n23=\"72:U+0048\"  # H\n24=\"78:U+004E\"  # N\n25=\"69:U+0045\"  # E\n26=\"73:U+0049\"  # I\n27=\"79:U+004F\"  # O\n28=\"34:U+0022\"  # quotedbl\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"90:U+005A\"  # Z\n2D=\"88:U+0058\"  # X\n2E=\"67:U+0043\"  # C\n2F=\"86:U+0056\"  # V\n30=\"66:U+0042\"  # B\n31=\"75:U+004B\"  # K\n32=\"77:U+004D\"  # M\n33=\"60:U+003C\"  # less\n34=\"62:U+003E\"  # greater\n35=\"63:U+003F\"  # question\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65288:U+0008\"  # BackSpace\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"95:U+005F\"  # underscore\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"161:U+00A1\"  # exclamdown\n03=\"186:U+00BA\"  # masculine\n04=\"170:U+00AA\"  # ordfeminine\n05=\"162:U+00A2\"  # cent\n06=\"8364:U+20AC\"  # EuroSign\n07=\"689:U+0127\"  # hstroke\n08=\"240:U+00F0\"  # eth\n09=\"254:U+00FE\"  # thorn\n0A=\"2768:U+2018\"  # leftsinglequotemark\n0B=\"2769:U+2019\"  # rightsinglequotemark\n0C=\"2730:U+2013\"  # endash\n0D=\"215:U+00D7\"  # multiply\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"228:U+00E4\"  # adiaeresis\n11=\"229:U+00E5\"  # aring\n12=\"227:U+00E3\"  # atilde\n13=\"248:U+00F8\"  # oslash\n14=\"65116:U+02DB\"  # dead_ogonek\n15=\"496:U+0111\"  # dstroke\n16=\"435:U+0142\"  # lstroke\n17=\"250:U+00FA\"  # uacute\n18=\"252:U+00FC\"  # udiaeresis\n19=\"246:U+00F6\"  # odiaeresis\n1A=\"171:U+00AB\"  # guillemotleft\n1B=\"187:U+00BB\"  # guillemotright\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"225:U+00E1\"  # aacute\n1F=\"65104:U+0060\"  # dead_grave\n20=\"223:U+00DF\"  # ssharp\n21=\"65105:U+00B4\"  # dead_acute\n22=\"65111:U+00A8\"  # dead_diaeresis\n23=\"65114:U+02C7\"  # dead_caron\n24=\"241:U+00F1\"  # ntilde\n25=\"233:U+00E9\"  # eacute\n26=\"237:U+00ED\"  # iacute\n27=\"243:U+00F3\"  # oacute\n28=\"245:U+00F5\"  # otilde\n29=\"65107:U+007E\"  # dead_tilde\n2A=\"65505\"  # Shift_L\n2B=\"126:U+007E\"  # asciitilde\n2C=\"230:U+00E6\"  # ae\n2D=\"65106:U+005E\"  # dead_circumflex\n2E=\"231:U+00E7\"  # ccedilla\n2F=\"5053:U+0153\"  # oe\n30=\"65109:U+02D8\"  # dead_breve\n31=\"65112:U+00B0\"  # dead_abovering\n32=\"65108:U+00AF\"  # dead_macron\n33=\"65115:U+00B8\"  # dead_cedilla\n34=\"65110:U+02D9\"  # dead_abovedot\n35=\"191:U+00BF\"  # questiondown\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65288:U+0008\"  # BackSpace\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"2730:U+2013\"  # endash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"185:U+00B9\"  # onesuperior\n03=\"178:U+00B2\"  # twosuperior\n04=\"179:U+00B3\"  # threesuperior\n05=\"163:U+00A3\"  # sterling\n06=\"165:U+00A5\"  # yen\n07=\"673:U+0126\"  # Hstroke\n08=\"208:U+00D0\"  # ETH\n09=\"222:U+00DE\"  # THORN\n0A=\"2770:U+201C\"  # leftdoublequotemark\n0B=\"2771:U+201D\"  # rightdoublequotemark\n0C=\"2729:U+2014\"  # emdash\n0D=\"247:U+00F7\"  # division\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"196:U+00C4\"  # Adiaeresis\n11=\"197:U+00C5\"  # Aring\n12=\"195:U+00C3\"  # Atilde\n13=\"216:U+00D8\"  # Oslash\n14=\"126:U+007E\"  # asciitilde\n15=\"464:U+0110\"  # Dstroke\n16=\"419:U+0141\"  # Lstroke\n17=\"218:U+00DA\"  # Uacute\n18=\"220:U+00DC\"  # Udiaeresis\n19=\"214:U+00D6\"  # Odiaeresis\n1A=\"16785465:U+2039\"  # U2039\n1B=\"16785466:U+203A\"  # U203A\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"193:U+00C1\"  # Aacute\n1F=\"126:U+007E\"  # asciitilde\n20=\"16785054:U+1E9E\"  # U1E9E\n21=\"65113:U+02DD\"  # dead_doubleacute\n22=\"126:U+007E\"  # asciitilde\n23=\"126:U+007E\"  # asciitilde\n24=\"209:U+00D1\"  # Ntilde\n25=\"201:U+00C9\"  # Eacute\n26=\"205:U+00CD\"  # Iacute\n27=\"211:U+00D3\"  # Oacute\n28=\"213:U+00D5\"  # Otilde\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"126:U+007E\"  # asciitilde\n2C=\"198:U+00C6\"  # AE\n2D=\"126:U+007E\"  # asciitilde\n2E=\"199:U+00C7\"  # Ccedilla\n2F=\"5052:U+0152\"  # OE\n30=\"126:U+007E\"  # asciitilde\n31=\"126:U+007E\"  # asciitilde\n32=\"126:U+007E\"  # asciitilde\n33=\"126:U+007E\"  # asciitilde\n34=\"126:U+007E\"  # asciitilde\n35=\"126:U+007E\"  # asciitilde\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"160:U+00A0\"  # nobreakspace\n3A=\"65288:U+0008\"  # BackSpace\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"2729:U+2014\"  # emdash\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65027\"  # ISO_Level3_Shift\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65463:U+0037\"  # KP_7\n48=\"65464:U+0038\"  # KP_8\n49=\"65465:U+0039\"  # KP_9\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65457:U+0031\"  # KP_1\n50=\"65458:U+0032\"  # KP_2\n51=\"65459:U+0033\"  # KP_3\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/km-19360409.ini",
    "content": "[noshift]\nKey8=65406:0\nKey9=65307:27\nKey10=38:38\nKey11=91:91\nKey12=123:123\nKey13=125:125\nKey14=40:40\nKey15=61:61\nKey16=42:42\nKey17=41:41\nKey18=43:43\nKey19=93:93\nKey20=33:33\nKey21=35:35\nKey22=65288:8\nKey23=65289:9\nKey24=59:59\nKey25=44:44\nKey26=46:46\nKey27=112:112\nKey28=121:121\nKey29=102:102\nKey30=103:103\nKey31=99:99\nKey32=114:114\nKey33=108:108\nKey34=47:47\nKey35=64:64\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=111:111\nKey40=101:101\nKey41=117:117\nKey42=105:105\nKey43=100:100\nKey44=104:104\nKey45=116:116\nKey46=110:110\nKey47=115:115\nKey48=45:45\nKey49=36:36\nKey50=65505:0\nKey51=92:92\nKey52=39:39\nKey53=113:113\nKey54=106:106\nKey55=107:107\nKey56=120:120\nKey57=98:98\nKey58=109:109\nKey59=119:119\nKey60=118:118\nKey61=122:122\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey115=65515:0\nKey116=65516:0\nKey117=65383:0\nKey124=65027:0\nKey126=65469:61\nKey134=65454:46\nKey144=269025046:0\nKey150=269025071:0\nKey153=269025047:0\nKey160=269025042:0\nKey161=269025053:0\nKey162=269025044:0\nKey164=269025045:0\nKey170=269025068:0\nKey174=269025041:0\nKey176=269025043:0\nKey178=269025070:0\nKey204=269025068:0\nKey214=269025113:0\nKey215=269025028:0\nKey216=269025030:0\nKey217=269025029:0\nKey222=269025066:0\nKey223=269025040:0\nKey227=269025067:0\nKey229=269025051:0\nKey230=269025072:0\nKey231=269025139:0\nKey232=269025064:0\nKey233=269025063:0\nKey234=269025062:0\nKey235=269025075:0\nKey236=269025049:0\nKey237=269025074:0\nKey244=269025171:0\nKey246=269025173:0\n\n[shift]\nKey8=65406:0\nKey9=65307:27\nKey10=37:37\nKey11=55:55\nKey12=53:53\nKey13=51:51\nKey14=49:49\nKey15=57:57\nKey16=48:48\nKey17=50:50\nKey18=52:52\nKey19=54:54\nKey20=56:56\nKey21=96:96\nKey22=65288:8\nKey23=65056:0\nKey24=58:58\nKey25=60:60\nKey26=62:62\nKey27=80:80\nKey28=89:89\nKey29=70:70\nKey30=71:71\nKey31=67:67\nKey32=82:82\nKey33=76:76\nKey34=63:63\nKey35=94:94\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=79:79\nKey40=69:69\nKey41=85:85\nKey42=73:73\nKey43=68:68\nKey44=72:72\nKey45=84:84\nKey46=78:78\nKey47=83:83\nKey48=95:95\nKey49=126:126\nKey50=65505:0\nKey51=124:124\nKey52=34:34\nKey53=81:81\nKey54=74:74\nKey55=75:75\nKey56=88:88\nKey57=66:66\nKey58=77:77\nKey59=87:87\nKey60=86:86\nKey61=90:90\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey115=65515:0\nKey116=65516:0\nKey117=65383:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey134=65454:46\nKey144=269025046:0\nKey150=269025071:0\nKey153=269025047:0\nKey156=65511:0\nKey160=269025042:0\nKey161=269025053:0\nKey162=269025073:0\nKey164=269025068:0\nKey170=269025068:0\nKey174=269025041:0\nKey176=269025043:0\nKey178=269025070:0\nKey204=269025068:0\nKey214=269025113:0\nKey215=269025028:0\nKey216=269025030:0\nKey217=269025029:0\nKey222=269025066:0\nKey223=269025040:0\nKey227=269025067:0\nKey229=269025051:0\nKey230=269025072:0\nKey231=269025139:0\nKey232=269025064:0\nKey233=269025063:0\nKey234=269025062:0\nKey235=269025075:0\nKey236=269025049:0\nKey237=269025074:0\nKey244=269025171:0\nKey246=269025173:0\n\n[altgr]\nKey8=65406:0\nKey9=65307:27\nKey10=38:38\nKey11=164:164\nKey12=162:162\nKey13=165:165\nKey14=8364:8364\nKey15=163:163\nKey17=189:189\nKey20=161:161\nKey21=65104:96\nKey22=65288:8\nKey23=65289:9\nKey24=65111:168\nKey25=171:171\nKey26=187:187\nKey27=182:182\nKey28=252:252\nKey29=102:102\nKey30=103:103\nKey31=231:231\nKey32=174:174\nKey33=108:108\nKey34=191:191\nKey35=65106:94\nKey36=65293:13\nKey37=65507:0\nKey38=229:229\nKey39=248:248\nKey40=230:230\nKey41=233:233\nKey42=105:105\nKey43=240:240\nKey44=65105:180\nKey45=254:254\nKey46=241:241\nKey47=223:223\nKey48=173:173\nKey49=65107:126\nKey50=65505:0\nKey51=92:92\nKey52=65105:180\nKey53=113:113\nKey54=106:106\nKey55=107:107\nKey56=120:120\nKey57=98:98\nKey58=109:109\nKey59=119:119\nKey60=118:118\nKey61=122:122\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey115=65515:0\nKey116=65516:0\nKey117=65383:0\nKey124=65027:0\nKey126=65469:61\nKey134=65454:46\nKey144=269025046:0\nKey150=269025071:0\nKey153=269025047:0\nKey160=269025042:0\nKey161=269025053:0\nKey162=269025044:0\nKey164=269025045:0\nKey170=269025068:0\nKey174=269025041:0\nKey176=269025043:0\nKey178=269025070:0\nKey204=269025068:0\nKey214=269025113:0\nKey215=269025028:0\nKey216=269025030:0\nKey217=269025029:0\nKey222=269025066:0\nKey223=269025040:0\nKey227=269025067:0\nKey229=269025051:0\nKey230=269025072:0\nKey231=269025139:0\nKey232=269025064:0\nKey233=269025063:0\nKey234=269025062:0\nKey235=269025075:0\nKey236=269025049:0\nKey237=269025074:0\nKey244=269025171:0\nKey246=269025173:0\n\n[shiftaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=37:37\nKey20=16789016:11800\nKey22=65288:8\nKey23=65056:0\nKey24=65111:168\nKey25=16785436:8220\nKey26=16785437:8221\nKey27=167:167\nKey28=220:220\nKey29=70:70\nKey30=71:71\nKey31=199:199\nKey32=2761:8482\nKey33=76:76\nKey34=16785469:8253\nKey35=65114:711\nKey36=65293:13\nKey37=65507:0\nKey38=197:197\nKey39=216:216\nKey40=198:198\nKey41=201:201\nKey42=73:73\nKey43=208:208\nKey45=222:222\nKey46=209:209\nKey47=16785054:7838\nKey48=2730:8211\nKey49=65107:126\nKey50=65505:0\nKey51=124:124\nKey52=65113:733\nKey53=81:81\nKey54=74:74\nKey55=75:75\nKey56=88:88\nKey57=66:66\nKey58=77:77\nKey59=87:87\nKey60=86:86\nKey61=90:90\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey115=65515:0\nKey116=65516:0\nKey117=65383:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey134=65454:46\nKey144=269025046:0\nKey150=269025071:0\nKey153=269025047:0\nKey156=65511:0\nKey160=269025042:0\nKey161=269025053:0\nKey162=269025073:0\nKey164=269025068:0\nKey170=269025068:0\nKey174=269025041:0\nKey176=269025043:0\nKey178=269025070:0\nKey204=269025068:0\nKey214=269025113:0\nKey215=269025028:0\nKey216=269025030:0\nKey217=269025029:0\nKey222=269025066:0\nKey223=269025040:0\nKey227=269025067:0\nKey229=269025051:0\nKey230=269025072:0\nKey231=269025139:0\nKey232=269025064:0\nKey233=269025063:0\nKey234=269025062:0\nKey235=269025075:0\nKey236=269025049:0\nKey237=269025074:0\nKey244=269025171:0\nKey246=269025173:0\n\n[capslock]\nKey8=65406:0\nKey9=65307:27\nKey10=38:38\nKey11=55:55\nKey12=53:53\nKey13=51:51\nKey14=49:49\nKey15=57:57\nKey16=48:48\nKey17=50:50\nKey18=52:52\nKey19=54:54\nKey20=56:56\nKey21=35:35\nKey22=65288:8\nKey23=65289:9\nKey24=59:59\nKey25=44:44\nKey26=46:46\nKey27=80:80\nKey28=89:89\nKey29=70:70\nKey30=71:71\nKey31=67:67\nKey32=82:82\nKey33=76:76\nKey34=47:47\nKey35=64:64\nKey36=65293:13\nKey37=65507:0\nKey38=65:65\nKey39=79:79\nKey40=69:69\nKey41=85:85\nKey42=73:73\nKey43=68:68\nKey44=72:72\nKey45=84:84\nKey46=78:78\nKey47=83:83\nKey48=95:95\nKey49=36:36\nKey50=65505:0\nKey51=92:92\nKey52=39:39\nKey53=81:81\nKey54=74:74\nKey55=75:75\nKey56=88:88\nKey57=66:66\nKey58=77:77\nKey59=87:87\nKey60=86:86\nKey61=90:90\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey115=65515:0\nKey116=65516:0\nKey117=65383:0\nKey124=65027:0\nKey126=65469:61\nKey134=65454:46\nKey144=269025046:0\nKey150=269025071:0\nKey153=269025047:0\nKey160=269025042:0\nKey161=269025053:0\nKey162=269025044:0\nKey164=269025045:0\nKey170=269025068:0\nKey174=269025041:0\nKey176=269025043:0\nKey178=269025070:0\nKey204=269025068:0\nKey214=269025113:0\nKey215=269025028:0\nKey216=269025030:0\nKey217=269025029:0\nKey222=269025066:0\nKey223=269025040:0\nKey227=269025067:0\nKey229=269025051:0\nKey230=269025072:0\nKey231=269025139:0\nKey232=269025064:0\nKey233=269025063:0\nKey234=269025062:0\nKey235=269025075:0\nKey236=269025049:0\nKey237=269025074:0\nKey244=269025171:0\nKey246=269025173:0\n\n[capslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=38:38\nKey20=16789016:11800\nKey21=65104:96\nKey22=65288:8\nKey23=65289:9\nKey24=65111:168\nKey25=171:171\nKey26=187:187\nKey27=182:182\nKey28=220:220\nKey29=70:70\nKey30=71:71\nKey31=199:199\nKey32=174:174\nKey33=76:76\nKey34=191:191\nKey35=65106:94\nKey36=65293:13\nKey37=65507:0\nKey38=197:197\nKey39=216:216\nKey40=198:198\nKey41=201:201\nKey42=73:73\nKey43=208:208\nKey44=65105:180\nKey45=222:222\nKey46=209:209\nKey47=223:223\nKey48=2730:8211\nKey49=65107:126\nKey50=65505:0\nKey51=92:92\nKey52=65105:180\nKey53=81:81\nKey54=74:74\nKey55=75:75\nKey56=88:88\nKey57=66:66\nKey58=77:77\nKey59=87:87\nKey60=86:86\nKey61=90:90\nKey62=65506:0\nKey63=65450:42\nKey64=65513:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65514:0\nKey115=65515:0\nKey116=65516:0\nKey117=65383:0\nKey124=65027:0\nKey126=65469:61\nKey134=65454:46\nKey144=269025046:0\nKey150=269025071:0\nKey153=269025047:0\nKey160=269025042:0\nKey161=269025053:0\nKey162=269025044:0\nKey164=269025045:0\nKey170=269025068:0\nKey174=269025041:0\nKey176=269025043:0\nKey178=269025070:0\nKey204=269025068:0\nKey214=269025113:0\nKey215=269025028:0\nKey216=269025030:0\nKey217=269025029:0\nKey222=269025066:0\nKey223=269025040:0\nKey227=269025067:0\nKey229=269025051:0\nKey230=269025072:0\nKey231=269025139:0\nKey232=269025064:0\nKey233=269025063:0\nKey234=269025062:0\nKey235=269025075:0\nKey236=269025049:0\nKey237=269025074:0\nKey244=269025171:0\nKey246=269025173:0\n\n[shiftcapslock]\nKey8=65406:0\nKey9=65307:27\nKey10=37:37\nKey11=91:91\nKey12=123:123\nKey13=125:125\nKey14=40:40\nKey15=61:61\nKey16=42:42\nKey17=41:41\nKey18=43:43\nKey19=93:93\nKey20=33:33\nKey21=96:96\nKey22=65288:8\nKey23=65056:0\nKey24=58:58\nKey25=60:60\nKey26=62:62\nKey27=112:112\nKey28=121:121\nKey29=102:102\nKey30=103:103\nKey31=99:99\nKey32=114:114\nKey33=108:108\nKey34=63:63\nKey35=94:94\nKey36=65293:13\nKey37=65507:0\nKey38=97:97\nKey39=111:111\nKey40=101:101\nKey41=117:117\nKey42=105:105\nKey43=100:100\nKey44=104:104\nKey45=116:116\nKey46=110:110\nKey47=115:115\nKey48=45:45\nKey49=126:126\nKey50=65505:0\nKey51=124:124\nKey52=34:34\nKey53=113:113\nKey54=106:106\nKey55=107:107\nKey56=120:120\nKey57=98:98\nKey58=109:109\nKey59=119:119\nKey60=118:118\nKey61=122:122\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey115=65515:0\nKey116=65516:0\nKey117=65383:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey134=65454:46\nKey144=269025046:0\nKey150=269025071:0\nKey153=269025047:0\nKey156=65511:0\nKey160=269025042:0\nKey161=269025053:0\nKey162=269025073:0\nKey164=269025068:0\nKey170=269025068:0\nKey174=269025041:0\nKey176=269025043:0\nKey178=269025070:0\nKey204=269025068:0\nKey214=269025113:0\nKey215=269025028:0\nKey216=269025030:0\nKey217=269025029:0\nKey222=269025066:0\nKey223=269025040:0\nKey227=269025067:0\nKey229=269025051:0\nKey230=269025072:0\nKey231=269025139:0\nKey232=269025064:0\nKey233=269025063:0\nKey234=269025062:0\nKey235=269025075:0\nKey236=269025049:0\nKey237=269025074:0\nKey244=269025171:0\nKey246=269025173:0\n\n[shiftcapslockaltgr]\nKey8=65406:0\nKey9=65307:27\nKey10=37:37\nKey11=164:164\nKey12=162:162\nKey13=165:165\nKey14=8364:8364\nKey15=163:163\nKey17=189:189\nKey20=161:161\nKey22=65288:8\nKey23=65056:0\nKey24=65111:168\nKey25=16785436:8220\nKey26=16785437:8221\nKey27=167:167\nKey28=252:252\nKey29=102:102\nKey30=103:103\nKey31=231:231\nKey32=2761:8482\nKey33=108:108\nKey34=16785469:8253\nKey35=65114:711\nKey36=65293:13\nKey37=65507:0\nKey38=229:229\nKey39=248:248\nKey40=230:230\nKey41=233:233\nKey42=105:105\nKey43=240:240\nKey45=254:254\nKey46=241:241\nKey47=16785054:7838\nKey48=173:173\nKey49=65107:126\nKey50=65505:0\nKey51=124:124\nKey52=65113:733\nKey53=113:113\nKey54=106:106\nKey55=107:107\nKey56=120:120\nKey57=98:98\nKey58=109:109\nKey59=119:119\nKey60=118:118\nKey61=122:122\nKey62=65506:0\nKey63=65450:42\nKey64=65511:0\nKey65=32:32\nKey66=65509:0\nKey67=65470:0\nKey68=65471:0\nKey69=65472:0\nKey70=65473:0\nKey71=65474:0\nKey72=65475:0\nKey73=65476:0\nKey74=65477:0\nKey75=65478:0\nKey76=65479:0\nKey77=65407:0\nKey78=65300:0\nKey79=65429:0\nKey80=65431:0\nKey81=65434:0\nKey82=65453:45\nKey83=65430:0\nKey84=65437:0\nKey85=65432:0\nKey86=65451:43\nKey87=65436:0\nKey88=65433:0\nKey89=65435:0\nKey90=65438:0\nKey91=65439:0\nKey94=65312:0\nKey95=65480:0\nKey96=65481:0\nKey97=65360:0\nKey98=65362:0\nKey99=65365:0\nKey100=65361:0\nKey102=65363:0\nKey103=65367:0\nKey104=65364:0\nKey105=65366:0\nKey106=65379:0\nKey107=65535:127\nKey108=65421:13\nKey109=65508:0\nKey110=65299:0\nKey111=65377:0\nKey112=65455:47\nKey113=65512:0\nKey115=65515:0\nKey116=65516:0\nKey117=65383:0\nKey124=65027:0\nKey125=65513:0\nKey126=61:61\nKey127=65515:0\nKey128=65517:0\nKey134=65454:46\nKey144=269025046:0\nKey150=269025071:0\nKey153=269025047:0\nKey156=65511:0\nKey160=269025042:0\nKey161=269025053:0\nKey162=269025073:0\nKey164=269025068:0\nKey170=269025068:0\nKey174=269025041:0\nKey176=269025043:0\nKey178=269025070:0\nKey204=269025068:0\nKey214=269025113:0\nKey215=269025028:0\nKey216=269025030:0\nKey217=269025029:0\nKey222=269025066:0\nKey223=269025040:0\nKey227=269025067:0\nKey229=269025051:0\nKey230=269025072:0\nKey231=269025139:0\nKey232=269025064:0\nKey233=269025063:0\nKey234=269025062:0\nKey235=269025075:0\nKey236=269025049:0\nKey237=269025074:0\nKey244=269025171:0\nKey246=269025173:0\n"
  },
  {
    "path": "instfiles/km-19360409.toml",
    "content": "# Created by xrdp-genkeymap V0.10.80\n# Key code set: evdev+aliases(qwerty)\n# setxkbmap -rules evdev -model pc105 -layout us -variant dvp -option \"\" -option compose:102 -option caps:shift -option numpad:sg -option numpad:shift3 -option keypad:hex -option keypad:atm -option kpdl:semi -option lv3:ralt_alt\n# Description: en-US\n# Operating system: Ubuntu 22.04.5 LTS\n\n[General]\nversion=2\ncaps_lock_supported=true\n\n[noshift]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n03=\"91:U+005B\"  # bracketleft\n04=\"123:U+007B\"  # braceleft\n05=\"125:U+007D\"  # braceright\n06=\"40:U+0028\"  # parenleft\n07=\"61:U+003D\"  # equal\n08=\"42:U+002A\"  # asterisk\n09=\"41:U+0029\"  # parenright\n0A=\"43:U+002B\"  # plus\n0B=\"93:U+005D\"  # bracketright\n0C=\"33:U+0021\"  # exclam\n0D=\"35:U+0023\"  # numbersign\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"59:U+003B\"  # semicolon\n11=\"44:U+002C\"  # comma\n12=\"46:U+002E\"  # period\n13=\"112:U+0070\"  # p\n14=\"121:U+0079\"  # y\n15=\"102:U+0066\"  # f\n16=\"103:U+0067\"  # g\n17=\"99:U+0063\"  # c\n18=\"114:U+0072\"  # r\n19=\"108:U+006C\"  # l\n1A=\"47:U+002F\"  # slash\n1B=\"64:U+0040\"  # at\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"111:U+006F\"  # o\n20=\"101:U+0065\"  # e\n21=\"117:U+0075\"  # u\n22=\"105:U+0069\"  # i\n23=\"100:U+0064\"  # d\n24=\"104:U+0068\"  # h\n25=\"116:U+0074\"  # t\n26=\"110:U+006E\"  # n\n27=\"115:U+0073\"  # s\n28=\"45:U+002D\"  # minus\n29=\"36:U+0024\"  # dollar\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"39:U+0027\"  # apostrophe\n2D=\"113:U+0071\"  # q\n2E=\"106:U+006A\"  # j\n2F=\"107:U+006B\"  # k\n30=\"120:U+0078\"  # x\n31=\"98:U+0062\"  # b\n32=\"109:U+006D\"  # m\n33=\"119:U+0077\"  # w\n34=\"118:U+0076\"  # v\n35=\"122:U+007A\"  # z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65312\"  # Multi_key\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shift]\n01=\"65307:U+001B\"  # Escape\n02=\"37:U+0025\"  # percent\n03=\"55:U+0037\"  # 7\n04=\"53:U+0035\"  # 5\n05=\"51:U+0033\"  # 3\n06=\"49:U+0031\"  # 1\n07=\"57:U+0039\"  # 9\n08=\"48:U+0030\"  # 0\n09=\"50:U+0032\"  # 2\n0A=\"52:U+0034\"  # 4\n0B=\"54:U+0036\"  # 6\n0C=\"56:U+0038\"  # 8\n0D=\"96:U+0060\"  # grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"58:U+003A\"  # colon\n11=\"60:U+003C\"  # less\n12=\"62:U+003E\"  # greater\n13=\"80:U+0050\"  # P\n14=\"89:U+0059\"  # Y\n15=\"70:U+0046\"  # F\n16=\"71:U+0047\"  # G\n17=\"67:U+0043\"  # C\n18=\"82:U+0052\"  # R\n19=\"76:U+004C\"  # L\n1A=\"63:U+003F\"  # question\n1B=\"94:U+005E\"  # asciicircum\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"79:U+004F\"  # O\n20=\"69:U+0045\"  # E\n21=\"85:U+0055\"  # U\n22=\"73:U+0049\"  # I\n23=\"68:U+0044\"  # D\n24=\"72:U+0048\"  # H\n25=\"84:U+0054\"  # T\n26=\"78:U+004E\"  # N\n27=\"83:U+0053\"  # S\n28=\"95:U+005F\"  # underscore\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"34:U+0022\"  # quotedbl\n2D=\"81:U+0051\"  # Q\n2E=\"74:U+004A\"  # J\n2F=\"75:U+004B\"  # K\n30=\"88:U+0058\"  # X\n31=\"66:U+0042\"  # B\n32=\"77:U+004D\"  # M\n33=\"87:U+0057\"  # W\n34=\"86:U+0056\"  # V\n35=\"90:U+005A\"  # Z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65312\"  # Multi_key\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[altgr]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n03=\"164:U+00A4\"  # currency\n04=\"162:U+00A2\"  # cent\n05=\"165:U+00A5\"  # yen\n06=\"8364:U+20AC\"  # EuroSign\n07=\"163:U+00A3\"  # sterling\n09=\"189:U+00BD\"  # onehalf\n0C=\"161:U+00A1\"  # exclamdown\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"65111:U+00A8\"  # dead_diaeresis\n11=\"171:U+00AB\"  # guillemotleft\n12=\"187:U+00BB\"  # guillemotright\n13=\"182:U+00B6\"  # paragraph\n14=\"252:U+00FC\"  # udiaeresis\n15=\"102:U+0066\"  # f\n16=\"103:U+0067\"  # g\n17=\"231:U+00E7\"  # ccedilla\n18=\"174:U+00AE\"  # registered\n19=\"108:U+006C\"  # l\n1A=\"191:U+00BF\"  # questiondown\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"229:U+00E5\"  # aring\n1F=\"248:U+00F8\"  # oslash\n20=\"230:U+00E6\"  # ae\n21=\"233:U+00E9\"  # eacute\n22=\"105:U+0069\"  # i\n23=\"240:U+00F0\"  # eth\n24=\"65105:U+00B4\"  # dead_acute\n25=\"254:U+00FE\"  # thorn\n26=\"241:U+00F1\"  # ntilde\n27=\"223:U+00DF\"  # ssharp\n28=\"173:U+00AD\"  # hyphen\n29=\"65107:U+007E\"  # dead_tilde\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"65105:U+00B4\"  # dead_acute\n2D=\"113:U+0071\"  # q\n2E=\"106:U+006A\"  # j\n2F=\"107:U+006B\"  # k\n30=\"120:U+0078\"  # x\n31=\"98:U+0062\"  # b\n32=\"109:U+006D\"  # m\n33=\"119:U+0077\"  # w\n34=\"118:U+0076\"  # v\n35=\"122:U+007A\"  # z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65312\"  # Multi_key\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"37:U+0025\"  # percent\n0C=\"16789016:U+2E18\"  # U2E18\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"65111:U+00A8\"  # dead_diaeresis\n11=\"16785436:U+201C\"  # U201C\n12=\"16785437:U+201D\"  # U201D\n13=\"167:U+00A7\"  # section\n14=\"220:U+00DC\"  # Udiaeresis\n15=\"70:U+0046\"  # F\n16=\"71:U+0047\"  # G\n17=\"199:U+00C7\"  # Ccedilla\n18=\"2761:U+2122\"  # trademark\n19=\"76:U+004C\"  # L\n1A=\"16785469:U+203D\"  # U203D\n1B=\"65114:U+02C7\"  # dead_caron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"197:U+00C5\"  # Aring\n1F=\"216:U+00D8\"  # Oslash\n20=\"198:U+00C6\"  # AE\n21=\"201:U+00C9\"  # Eacute\n22=\"73:U+0049\"  # I\n23=\"208:U+00D0\"  # ETH\n25=\"222:U+00DE\"  # THORN\n26=\"209:U+00D1\"  # Ntilde\n27=\"16785054:U+1E9E\"  # U1E9E\n28=\"2730:U+2013\"  # endash\n29=\"65107:U+007E\"  # dead_tilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"65113:U+02DD\"  # dead_doubleacute\n2D=\"81:U+0051\"  # Q\n2E=\"74:U+004A\"  # J\n2F=\"75:U+004B\"  # K\n30=\"88:U+0058\"  # X\n31=\"66:U+0042\"  # B\n32=\"77:U+004D\"  # M\n33=\"87:U+0057\"  # W\n34=\"86:U+0056\"  # V\n35=\"90:U+005A\"  # Z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65312\"  # Multi_key\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslock]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n03=\"55:U+0037\"  # 7\n04=\"53:U+0035\"  # 5\n05=\"51:U+0033\"  # 3\n06=\"49:U+0031\"  # 1\n07=\"57:U+0039\"  # 9\n08=\"48:U+0030\"  # 0\n09=\"50:U+0032\"  # 2\n0A=\"52:U+0034\"  # 4\n0B=\"54:U+0036\"  # 6\n0C=\"56:U+0038\"  # 8\n0D=\"35:U+0023\"  # numbersign\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"59:U+003B\"  # semicolon\n11=\"44:U+002C\"  # comma\n12=\"46:U+002E\"  # period\n13=\"80:U+0050\"  # P\n14=\"89:U+0059\"  # Y\n15=\"70:U+0046\"  # F\n16=\"71:U+0047\"  # G\n17=\"67:U+0043\"  # C\n18=\"82:U+0052\"  # R\n19=\"76:U+004C\"  # L\n1A=\"47:U+002F\"  # slash\n1B=\"64:U+0040\"  # at\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"65:U+0041\"  # A\n1F=\"79:U+004F\"  # O\n20=\"69:U+0045\"  # E\n21=\"85:U+0055\"  # U\n22=\"73:U+0049\"  # I\n23=\"68:U+0044\"  # D\n24=\"72:U+0048\"  # H\n25=\"84:U+0054\"  # T\n26=\"78:U+004E\"  # N\n27=\"83:U+0053\"  # S\n28=\"95:U+005F\"  # underscore\n29=\"36:U+0024\"  # dollar\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"39:U+0027\"  # apostrophe\n2D=\"81:U+0051\"  # Q\n2E=\"74:U+004A\"  # J\n2F=\"75:U+004B\"  # K\n30=\"88:U+0058\"  # X\n31=\"66:U+0042\"  # B\n32=\"77:U+004D\"  # M\n33=\"87:U+0057\"  # W\n34=\"86:U+0056\"  # V\n35=\"90:U+005A\"  # Z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65312\"  # Multi_key\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[capslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"38:U+0026\"  # ampersand\n0C=\"16789016:U+2E18\"  # U2E18\n0D=\"65104:U+0060\"  # dead_grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65289:U+0009\"  # Tab\n10=\"65111:U+00A8\"  # dead_diaeresis\n11=\"171:U+00AB\"  # guillemotleft\n12=\"187:U+00BB\"  # guillemotright\n13=\"182:U+00B6\"  # paragraph\n14=\"220:U+00DC\"  # Udiaeresis\n15=\"70:U+0046\"  # F\n16=\"71:U+0047\"  # G\n17=\"199:U+00C7\"  # Ccedilla\n18=\"174:U+00AE\"  # registered\n19=\"76:U+004C\"  # L\n1A=\"191:U+00BF\"  # questiondown\n1B=\"65106:U+005E\"  # dead_circumflex\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"197:U+00C5\"  # Aring\n1F=\"216:U+00D8\"  # Oslash\n20=\"198:U+00C6\"  # AE\n21=\"201:U+00C9\"  # Eacute\n22=\"73:U+0049\"  # I\n23=\"208:U+00D0\"  # ETH\n24=\"65105:U+00B4\"  # dead_acute\n25=\"222:U+00DE\"  # THORN\n26=\"209:U+00D1\"  # Ntilde\n27=\"16785054:U+1E9E\"  # U1E9E\n28=\"2730:U+2013\"  # endash\n29=\"65107:U+007E\"  # dead_tilde\n2A=\"65505\"  # Shift_L\n2B=\"92:U+005C\"  # backslash\n2C=\"65105:U+00B4\"  # dead_acute\n2D=\"81:U+0051\"  # Q\n2E=\"74:U+004A\"  # J\n2F=\"75:U+004B\"  # K\n30=\"88:U+0058\"  # X\n31=\"66:U+0042\"  # B\n32=\"77:U+004D\"  # M\n33=\"87:U+0057\"  # W\n34=\"86:U+0056\"  # V\n35=\"90:U+005A\"  # Z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65513\"  # Alt_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65312\"  # Multi_key\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025044\"  # XF86AudioPlay\nE0_24=\"269025045\"  # XF86AudioStop\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65514\"  # Alt_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslock]\n01=\"65307:U+001B\"  # Escape\n02=\"37:U+0025\"  # percent\n03=\"91:U+005B\"  # bracketleft\n04=\"123:U+007B\"  # braceleft\n05=\"125:U+007D\"  # braceright\n06=\"40:U+0028\"  # parenleft\n07=\"61:U+003D\"  # equal\n08=\"42:U+002A\"  # asterisk\n09=\"41:U+0029\"  # parenright\n0A=\"43:U+002B\"  # plus\n0B=\"93:U+005D\"  # bracketright\n0C=\"33:U+0021\"  # exclam\n0D=\"96:U+0060\"  # grave\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"58:U+003A\"  # colon\n11=\"60:U+003C\"  # less\n12=\"62:U+003E\"  # greater\n13=\"112:U+0070\"  # p\n14=\"121:U+0079\"  # y\n15=\"102:U+0066\"  # f\n16=\"103:U+0067\"  # g\n17=\"99:U+0063\"  # c\n18=\"114:U+0072\"  # r\n19=\"108:U+006C\"  # l\n1A=\"63:U+003F\"  # question\n1B=\"94:U+005E\"  # asciicircum\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"97:U+0061\"  # a\n1F=\"111:U+006F\"  # o\n20=\"101:U+0065\"  # e\n21=\"117:U+0075\"  # u\n22=\"105:U+0069\"  # i\n23=\"100:U+0064\"  # d\n24=\"104:U+0068\"  # h\n25=\"116:U+0074\"  # t\n26=\"110:U+006E\"  # n\n27=\"115:U+0073\"  # s\n28=\"45:U+002D\"  # minus\n29=\"126:U+007E\"  # asciitilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"34:U+0022\"  # quotedbl\n2D=\"113:U+0071\"  # q\n2E=\"106:U+006A\"  # j\n2F=\"107:U+006B\"  # k\n30=\"120:U+0078\"  # x\n31=\"98:U+0062\"  # b\n32=\"109:U+006D\"  # m\n33=\"119:U+0077\"  # w\n34=\"118:U+0076\"  # v\n35=\"122:U+007A\"  # z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65312\"  # Multi_key\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[shiftcapslockaltgr]\n01=\"65307:U+001B\"  # Escape\n02=\"37:U+0025\"  # percent\n03=\"164:U+00A4\"  # currency\n04=\"162:U+00A2\"  # cent\n05=\"165:U+00A5\"  # yen\n06=\"8364:U+20AC\"  # EuroSign\n07=\"163:U+00A3\"  # sterling\n09=\"189:U+00BD\"  # onehalf\n0C=\"161:U+00A1\"  # exclamdown\n0E=\"65288:U+0008\"  # BackSpace\n0F=\"65056\"  # ISO_Left_Tab\n10=\"65111:U+00A8\"  # dead_diaeresis\n11=\"16785436:U+201C\"  # U201C\n12=\"16785437:U+201D\"  # U201D\n13=\"167:U+00A7\"  # section\n14=\"252:U+00FC\"  # udiaeresis\n15=\"102:U+0066\"  # f\n16=\"103:U+0067\"  # g\n17=\"231:U+00E7\"  # ccedilla\n18=\"2761:U+2122\"  # trademark\n19=\"108:U+006C\"  # l\n1A=\"16785469:U+203D\"  # U203D\n1B=\"65114:U+02C7\"  # dead_caron\n1C=\"65293:U+000D\"  # Return\n1D=\"65507\"  # Control_L\n1E=\"229:U+00E5\"  # aring\n1F=\"248:U+00F8\"  # oslash\n20=\"230:U+00E6\"  # ae\n21=\"233:U+00E9\"  # eacute\n22=\"105:U+0069\"  # i\n23=\"240:U+00F0\"  # eth\n25=\"254:U+00FE\"  # thorn\n26=\"241:U+00F1\"  # ntilde\n27=\"223:U+00DF\"  # ssharp\n28=\"173:U+00AD\"  # hyphen\n29=\"65107:U+007E\"  # dead_tilde\n2A=\"65505\"  # Shift_L\n2B=\"124:U+007C\"  # bar\n2C=\"65113:U+02DD\"  # dead_doubleacute\n2D=\"113:U+0071\"  # q\n2E=\"106:U+006A\"  # j\n2F=\"107:U+006B\"  # k\n30=\"120:U+0078\"  # x\n31=\"98:U+0062\"  # b\n32=\"109:U+006D\"  # m\n33=\"119:U+0077\"  # w\n34=\"118:U+0076\"  # v\n35=\"122:U+007A\"  # z\n36=\"65506\"  # Shift_R\n37=\"65450:U+002A\"  # KP_Multiply\n38=\"65511\"  # Meta_L\n39=\"32:U+0020\"  # space\n3A=\"65509\"  # Caps_Lock\n3B=\"65470\"  # F1\n3C=\"65471\"  # F2\n3D=\"65472\"  # F3\n3E=\"65473\"  # F4\n3F=\"65474\"  # F5\n40=\"65475\"  # F6\n41=\"65476\"  # F7\n42=\"65477\"  # F8\n43=\"65478\"  # F9\n44=\"65479\"  # F10\n45=\"65407\"  # Num_Lock\n46=\"65300\"  # Scroll_Lock\n47=\"65429\"  # KP_Home\n48=\"65431\"  # KP_Up\n49=\"65434\"  # KP_Prior\n4A=\"65453:U+002D\"  # KP_Subtract\n4B=\"65430\"  # KP_Left\n4C=\"65437\"  # KP_Begin\n4D=\"65432\"  # KP_Right\n4E=\"65451:U+002B\"  # KP_Add\n4F=\"65436\"  # KP_End\n50=\"65433\"  # KP_Down\n51=\"65435\"  # KP_Next\n52=\"65438\"  # KP_Insert\n53=\"65439\"  # KP_Delete\n56=\"65312\"  # Multi_key\n57=\"65480\"  # F11\n58=\"65481\"  # F12\n70=\"65319\"  # Hiragana_Katakana\n79=\"65315\"  # Henkan_Mode\n7B=\"65314\"  # Muhenkan\n7E=\"65454:U+002E\"  # KP_Decimal\nE0_10=\"269025046\"  # XF86AudioPrev\nE0_19=\"269025047\"  # XF86AudioNext\nE0_1C=\"65421:U+000D\"  # KP_Enter\nE0_1D=\"65508\"  # Control_R\nE0_20=\"269025042\"  # XF86AudioMute\nE0_21=\"269025053\"  # XF86Calculator\nE0_22=\"269025073\"  # XF86AudioPause\nE0_24=\"269025068\"  # XF86Eject\nE0_2E=\"269025041\"  # XF86AudioLowerVolume\nE0_30=\"269025043\"  # XF86AudioRaiseVolume\nE0_32=\"269025048\"  # XF86HomePage\nE0_35=\"65455:U+002F\"  # KP_Divide\nE0_37=\"65377\"  # Print\nE0_38=\"65512\"  # Meta_R\nE0_47=\"65360\"  # Home\nE0_48=\"65362\"  # Up\nE0_49=\"65365\"  # Prior\nE0_4B=\"65361\"  # Left\nE0_4D=\"65363\"  # Right\nE0_4F=\"65367\"  # End\nE0_50=\"65364\"  # Down\nE0_51=\"65366\"  # Next\nE0_52=\"65379\"  # Insert\nE0_53=\"65535:U+007F\"  # Delete\nE0_5B=\"65515\"  # Super_L\nE0_5C=\"65516\"  # Super_R\nE0_5D=\"65383\"  # Menu\nE0_65=\"269025051\"  # XF86Search\nE0_66=\"269025072\"  # XF86Favorites\nE0_6B=\"269025075\"  # XF86MyComputer\nE0_6C=\"269025049\"  # XF86Mail\nE1_1D=\"65299\"  # Pause\n\n[numlock]\n47=\"65457:U+0031\"  # KP_1\n48=\"65458:U+0032\"  # KP_2\n49=\"65459:U+0033\"  # KP_3\n4A=\"45:U+002D\"  # minus\n4B=\"65460:U+0034\"  # KP_4\n4C=\"65461:U+0035\"  # KP_5\n4D=\"65462:U+0036\"  # KP_6\n4E=\"43:U+002B\"  # plus\n4F=\"65463:U+0037\"  # KP_7\n50=\"65464:U+0038\"  # KP_8\n51=\"65465:U+0039\"  # KP_9\n52=\"65456:U+0030\"  # KP_0\n53=\"65454:U+002E\"  # KP_Decimal\n"
  },
  {
    "path": "instfiles/pam.d/Makefile.am",
    "content": "PAM_FILES = \\\n  xrdp-sesman.arch \\\n  xrdp-sesman.debian \\\n  xrdp-sesman.freebsd \\\n  xrdp-sesman.macos \\\n  xrdp-sesman.redhat \\\n  xrdp-sesman.suse \\\n  xrdp-sesman.system \\\n  xrdp-sesman.unix\n\nEXTRA_DIST = $(PAM_FILES) mkpamrules\n\nCLEANFILES = xrdp-sesman\n\nif SESMAN_NOPAM\nPAMFILE =\nelse\nif SESMAN_PAMUSERPASS\nPAMFILE =\nelse\nif SESMAN_KERBEROS\nPAMFILE =\nelse\nPAMFILE = xrdp-sesman\nendif\nendif\nendif\n\npamddir = $(pamconfdir)\n\npamd_DATA = \\\n  $(PAMFILE)\n\nxrdp-sesman: mkpamrules\n\t$(srcdir)/mkpamrules $(PAM_RULES) $(srcdir) $@\n"
  },
  {
    "path": "instfiles/pam.d/mkpamrules",
    "content": "#!/bin/sh\n\n# Find suitable PAM config file\n\nrules=\"$1\"\nsrcdir=\"$2\"\noutfile=\"$3\"\n\nservice=\"xrdp-sesman\"\npamdir=\"/etc/pam.d\"\npamdir_suse=\"/usr/lib/pam.d\"\nif [ ! -d $pamdir_suse ]; then\n   # Older SUSE distros uses /usr/etc/pam.d\n   pamdir_suse=\"/usr/etc/pam.d\"\nfi\n\n# Modules needed by xrdp-sesman.unix, if we get to that\nunix_modules_needed=\"pam_unix.so pam_env.so pam_nologin.so\"\n\n# Directories where pam modules might be installed\n# Add to this list as platforms are added\npam_module_dir_searchpath=\"/lib*/security /usr/lib*/security /lib/*/security /usr/lib/*/security\"\n\nfind_pam_module_dir()\n{\n  # Looks for the pam security module directory\n  set -- $pam_module_dir_searchpath\n  for d in \"$@\"; do\n    if [ -s \"$d/pam_unix.so\" ]; then\n      echo \"$d\"\n      break\n    fi\n  done\n}\n\ncan_apply_unix_config()\n{\n  result=0\n  module_dir=\"$1\"\n  for m in $unix_modules_needed; do\n    if [ ! -s \"$module_dir/$m\" ]; then\n      echo \"  ** $m not found\" >&2\n      result=1\n    fi\n  done\n\n  return $result\n}\n\nguess_rules ()\n{\n  rules=\n  if [ -s \"$pamdir/password-auth\" ]; then\n    rules=\"redhat\"\n\n  elif [ -s \"$pamdir_suse/common-account\" ]; then\n    rules=\"suse\"\n\n  elif [ -s \"$pamdir/common-account\" ]; then\n    if grep \"^@include\" \"$pamdir/passwd\" >/dev/null 2>&1; then\n      rules=\"debian\"\n    else\n      rules=\"suse\"\n    fi\n\n  elif [ ! -f \"$pamdir/system-auth\" -a -s \"$pamdir/system\" ]; then\n    rules=\"freebsd\"\n\n  elif [ -s \"$pamdir/authorization\" ]; then\n    rules=\"macos\"\n\n  elif [ -s \"$pamdir/system-remote-login\" ]; then\n    rules=\"arch\"\n\n  elif [ -s \"$pamdir/system-auth\" ]; then\n    rules=\"system\"\n\n  else\n    module_dir=`find_pam_module_dir`\n    if [ -d \"$module_dir\" ]; then\n      #echo \"- Found pam modules in $module_dir\" >&2\n      if can_apply_unix_config \"$module_dir\" ; then\n        rules=\"unix\"\n      fi\n    fi\n  fi\n}\n\nif [ \"$rules\" = \"auto\" ]; then\n  guess_rules\n  if [ -z \"$rules\" ]; then\n    echo \"** Can't guess PAM rules for this system\"\n    exit 1\n  fi\nfi\n\nif [ -s \"$srcdir/$service.$rules\" ]; then\n  ln -nsf \"$srcdir/$service.$rules\" \"$outfile\"\nelse\n  echo \"Cannot find $srcdir/$service.$rules\"\n  exit 1\nfi\n"
  },
  {
    "path": "instfiles/pam.d/xrdp-sesman.arch",
    "content": "auth        include  system-remote-login\n-auth       optional pam_gnome_keyring.so\n-auth       optional pam_kwallet5.so\n\naccount     include  system-remote-login\n\npassword    include  system-remote-login\n\nsession     include  system-remote-login\n# For wtmp/lastlog support uncomment one of the following lines:-\n#session     optional    pam_lastlog.so quiet\n#session     optional    pam_lastlog2.so silent\n-session    optional pam_gnome_keyring.so auto_start\n-session    optional pam_kwallet5.so auto_start\n"
  },
  {
    "path": "instfiles/pam.d/xrdp-sesman.debian",
    "content": "#%PAM-1.0\nauth     required  pam_env.so readenv=1\nauth     required  pam_env.so readenv=1 envfile=/etc/default/locale\n@include common-auth\n-auth    optional  pam_gnome_keyring.so\n-auth    optional  pam_kwallet5.so\n\n@include common-account\n\n@include common-password\n\n# Ensure resource limits are applied\nsession    required     pam_limits.so\n# Set the loginuid process attribute.\nsession    required     pam_loginuid.so\n# Update wtmp/lastlog\nsession    optional     pam_lastlog.so quiet\n@include common-session\n-session optional  pam_gnome_keyring.so auto_start\n-session optional  pam_kwallet5.so auto_start\n"
  },
  {
    "path": "instfiles/pam.d/xrdp-sesman.freebsd",
    "content": "#%PAM-1.0\nauth        include     system\naccount     include     system\npassword    include     system\nsession     include     system\n"
  },
  {
    "path": "instfiles/pam.d/xrdp-sesman.macos",
    "content": "# xrdp-sesman: auth account password session\n# based on Apple's sshd PAM configuration\nauth       optional       pam_krb5.so use_kcminit\nauth       optional       pam_ntlm.so try_first_pass\nauth       optional       pam_mount.so try_first_pass\nauth       required       pam_opendirectory.so try_first_pass\naccount    required       pam_nologin.so\naccount    required       pam_sacl.so sacl_service=ssh\naccount    required       pam_opendirectory.so\npassword   required       pam_opendirectory.so\nsession    required       pam_launchd.so\nsession    optional       pam_mount.so\n"
  },
  {
    "path": "instfiles/pam.d/xrdp-sesman.redhat",
    "content": "#%PAM-1.0\nauth        include     password-auth\naccount     include     password-auth\n\n# Set the loginuid process attribute.\nsession     required    pam_loginuid.so\n# Update wtmp/lastlog\nsession    optional     pam_lastlog.so quiet\n\nsession     include     password-auth\npassword    include     password-auth\n"
  },
  {
    "path": "instfiles/pam.d/xrdp-sesman.suse",
    "content": "#%PAM-1.0\nauth        include     common-auth\naccount     include     common-account\n\n# Set the loginuid process attribute.\nsession    required     pam_loginuid.so\n# Update lastlog database\nsession    optional     pam_lastlog2.so silent\n\nsession     include     common-session\npassword    include     common-password\n"
  },
  {
    "path": "instfiles/pam.d/xrdp-sesman.system",
    "content": "#%PAM-1.0\nauth        include     system-auth\naccount     include     system-auth\npassword    include     system-auth\n\n# For wtmp/lastlog support uncomment one of the following lines:-\n#session     optional    pam_lastlog.so quiet\n#session     optional    pam_lastlog2.so silent\nsession     include     system-auth\n"
  },
  {
    "path": "instfiles/pam.d/xrdp-sesman.unix",
    "content": "#%PAM-1.0\n#\n# Really basic authentication set when nothing else is available\n#\n# You may need to edit this to suit your system depending on the\n# required functionality.\n#\nauth       required     pam_unix.so shadow\nauth       required     pam_env.so\n\npassword    required    pam_unix.so\n\naccount     required    pam_unix.so\naccount     required    pam_nologin.so\n\nsession     required    pam_unix.so\n"
  },
  {
    "path": "instfiles/pulse/Makefile.am",
    "content": "pulsedir = $(sysconfdir)/$(sysconfsubdir)/pulse\ndist_pulse_DATA = default.pa\n"
  },
  {
    "path": "instfiles/pulse/default.pa",
    "content": ".nofail\n.fail\nload-module module-augment-properties\nload-module module-always-sink\n.ifexists module-xrdp-sink.so\nload-module module-xrdp-sink\n.endif\n.ifexists module-xrdp-source.so\nload-module module-xrdp-source\n.endif\nload-module module-native-protocol-unix\n\n"
  },
  {
    "path": "instfiles/rc.d/Makefile.am",
    "content": "startscriptdir = $(sysconfdir)/rc.d\ndist_startscript_SCRIPTS = xrdp xrdp-sesman\n"
  },
  {
    "path": "instfiles/rc.d/xrdp",
    "content": "#!/bin/sh\n#\n# Copyright (c) 1992-2018 The FreeBSD Project. All rights reserved.\n# Copyright (c) 2015-2018 Koichiro Iwao <meta@FreeBSD.org>\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions\n# are met:\n# 1. Redistributions of source code must retain the above copyright\n#    notice, this list of conditions and the following disclaimer.\n# 2. Redistributions in binary form must reproduce the above copyright\n#    notice, this list of conditions and the following disclaimer in the\n#    documentation and/or other materials provided with the distribution.\n#\n# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n# SUCH DAMAGE.\n#\n# $FreeBSD$\n#\n# REQUIRE: DAEMON\n# PROVIDE: xrdp\n#\n# Add the following line to /etc/rc.conf to enable xrdp:\n#\n#  xrdp_enable=\"YES\"\n#  xrdp_sesman_enable=\"YES\"\n\n. /etc/rc.subr\n\nname=\"xrdp\"\nrcvar=\"xrdp_enable\"\n\nload_rc_config \"$name\"\n: ${xrdp_enable=\"NO\"}\n\nextra_commands=\"status allstart allstop allrestart\"\ncommand=\"%%PREFIX%%/sbin/xrdp\"\n\nallstart_cmd=\"xrdp_allstart\"\nallstop_cmd=\"xrdp_allstop\"\nallrestart_cmd=\"xrdp_allrestart\"\nstop_postcmd=\"xrdp_poststop\"\n\nxrdp_allstart()\n{\n     run_rc_command \"start\"\n\n    if checkyesno \"xrdp_sesman_enable\" && \\\n        ! %%PREFIX%%/etc/rc.d/xrdp-sesman forcestatus 1>/dev/null 2>&1; then\n        %%PREFIX%%/etc/rc.d/xrdp-sesman start || return 1\n    fi\n}\n\nxrdp_allstop()\n{\n    if checkyesno \"xrdp_sesman_enable\" && \\\n        %%PREFIX%%/etc/rc.d/xrdp-sesman forcestatus 1>/dev/null 2>&1; then\n        %%PREFIX%%/etc/rc.d/xrdp-sesman stop || return 1\n    fi\n\n    run_rc_command \"stop\"\n}\n\nxrdp_allrestart()\n{\n    if checkyesno \"xrdp_sesman_enable\" && \\\n        %%PREFIX%%/etc/rc.d/xrdp-sesman forcestatus 1>/dev/null 2>&1; then\n        %%PREFIX%%/etc/rc.d/xrdp-sesman restart || return 1\n    fi\n\n    run_rc_command \"restart\"\n}\n\nxrdp_poststop()\n{\n    # If running with dropped privileges, xrdp can't delete its own\n    # PID file\n    rm -f %%LOCALSTATEDIR%%/run/xrdp.pid\n}\nrun_rc_command \"$1\"\n"
  },
  {
    "path": "instfiles/rc.d/xrdp-sesman",
    "content": "#!/bin/sh\n#\n# Copyright (c) 1992-2015 The FreeBSD Project. All rights reserved.\n# Copyright (c) 2015-2018 Koichiro Iwao <meta@FreeBSD.org>\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions\n# are met:\n# 1. Redistributions of source code must retain the above copyright\n#    notice, this list of conditions and the following disclaimer.\n# 2. Redistributions in binary form must reproduce the above copyright\n#    notice, this list of conditions and the following disclaimer in the\n#    documentation and/or other materials provided with the distribution.\n#\n# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n# SUCH DAMAGE.\n#\n# $FreeBSD$\n#\n# REQUIRE: LOGIN\n# PROVIDE: xrdp_sesman\n#\n\n. /etc/rc.subr\n\nname=\"xrdp_sesman\"\nrcvar=\"xrdp_sesman_enable\"\n\nload_rc_config \"$name\"\n: ${xrdp_sesman_enable=\"NO\"}\n\nextra_commands=\"status\"\ncommand=\"%%PREFIX%%/sbin/xrdp-sesman\"\n\nrun_rc_command \"$1\"\n"
  },
  {
    "path": "instfiles/xrdp-sesman.service.in",
    "content": "[Unit]\nDescription=xrdp session manager\nDocumentation=man:xrdp-sesman(8) man:sesman.ini(5)\nAfter=network.target\nStopWhenUnneeded=true\nBindsTo=xrdp.service\n\n[Service]\nType=exec\nEnvironmentFile=-@sysconfdir@/sysconfig/xrdp\nEnvironmentFile=-@sysconfdir@/default/xrdp\nExecStart=@sbindir@/xrdp-sesman $SESMAN_OPTIONS --nodaemon\nExecReload=kill -HUP $MAINPID\n\n[Install]\nWantedBy=multi-user.target\n"
  },
  {
    "path": "instfiles/xrdp.service.in",
    "content": "[Unit]\nDescription=xrdp daemon\nDocumentation=man:xrdp(8) man:xrdp.ini(5)\nRequires=xrdp-sesman.service\nAfter=network-online.target xrdp-sesman.service\n\n[Service]\nType=exec\nEnvironmentFile=-@sysconfdir@/sysconfig/xrdp\nEnvironmentFile=-@sysconfdir@/default/xrdp\nExecStart=@sbindir@/xrdp $XRDP_OPTIONS --nodaemon\nSystemCallArchitectures=native\nSystemCallFilter=@system-service\n# Uncomment the following line if you wish xrdp connections to survive\n# an xrdp restart.\n#\n# This is not recommended, as the xrdp and xrdp-sesman processes can\n# end up with API differences if the restart was caused by an upgrade. It\n# may however be useful for some use cases.\n#KillMode=process\n\n[Install]\nWantedBy=multi-user.target\n"
  },
  {
    "path": "keygen/Makefile.am",
    "content": "EXTRA_DIST = openssl.conf\n\nAM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -I$(top_srcdir)/common\n\nbin_PROGRAMS = \\\n  xrdp-keygen\n\nxrdp_keygen_SOURCES = keygen.c\n\nxrdp_keygen_LDADD = \\\n  $(top_builddir)/common/libcommon.la\n\nxrdpsysconfdir = $(sysconfdir)/$(sysconfsubdir)\n\ninstall-data-hook:\n\tumask 077 && \\\n\tif [ ! -f $(DESTDIR)$(xrdpsysconfdir)/rsakeys.ini ]; then \\\n\t  ./xrdp-keygen xrdp $(DESTDIR)$(xrdpsysconfdir)/rsakeys.ini; \\\n\tfi && \\\n\tif [ ! -f $(DESTDIR)$(xrdpsysconfdir)/cert.pem ]; then \\\n\t  $(OPENSSL) req -x509 -newkey rsa:2048 -sha256 -nodes \\\n\t    -keyout $(DESTDIR)$(xrdpsysconfdir)/key.pem -out \\\n\t    $(DESTDIR)$(xrdpsysconfdir)/cert.pem -days 365 \\\n\t    -subj /C=US/ST=CA/L=Sunnyvale/O=xrdp/CN=www.xrdp.org \\\n\t    -config $(srcdir)/openssl.conf; \\\n\tfi\n\nuninstall-hook:\n\trm -f $(DESTDIR)$(xrdpsysconfdir)/rsakeys.ini\n\trm -f $(DESTDIR)$(xrdpsysconfdir)/cert.pem\n\trm -f $(DESTDIR)$(xrdpsysconfdir)/key.pem\n"
  },
  {
    "path": "keygen/keygen.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * rsa key generator for xrdp\n */\n\n/*\n   references:\n\n   http://www.securiteam.com/windowsntfocus/5EP010KG0G.html\n\n*/\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"ssl_calls.h\"\n#include \"arch.h\"\n#include \"list.h\"\n#include \"file.h\"\n\n/* this is the signature size in bytes */\n#define TSSK_KEY_LENGTH 64\n\n/* default to 2048 bit key size, can set changed, set */\nstatic int g_key_size_bits = 2048;\n\nstatic tui8 g_exponent[4] =\n{\n    0x01, 0x00, 0x01, 0x00\n};\n\n/* 4 bytes public exponent */\nstatic tui8 g_ppk_e[4] =\n{\n    0x5B, 0x7B, 0x88, 0xC0\n};\n\n/* 64 byte modulus */\nstatic tui8 g_ppk_n[72] = /* 64 bytes + 8 bytes pad */\n{\n    0x3D, 0x3A, 0x5E, 0xBD, 0x72, 0x43, 0x3E, 0xC9,\n    0x4D, 0xBB, 0xC1, 0x1E, 0x4A, 0xBA, 0x5F, 0xCB,\n    0x3E, 0x88, 0x20, 0x87, 0xEF, 0xF5, 0xC1, 0xE2,\n    0xD7, 0xB7, 0x6B, 0x9A, 0xF2, 0x52, 0x45, 0x95,\n    0xCE, 0x63, 0x65, 0x6B, 0x58, 0x3A, 0xFE, 0xEF,\n    0x7C, 0xE7, 0xBF, 0xFE, 0x3D, 0xF6, 0x5C, 0x7D,\n    0x6C, 0x5E, 0x06, 0x09, 0x1A, 0xF5, 0x61, 0xBB,\n    0x20, 0x93, 0x09, 0x5F, 0x05, 0x6D, 0xEA, 0x87,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n};\n\n/* 64 bytes private exponent */\nstatic tui8 g_ppk_d[108] = /* 64 bytes + 44 bytes pad */\n{\n    0x87, 0xA7, 0x19, 0x32, 0xDA, 0x11, 0x87, 0x55,\n    0x58, 0x00, 0x16, 0x16, 0x25, 0x65, 0x68, 0xF8,\n    0x24, 0x3E, 0xE6, 0xFA, 0xE9, 0x67, 0x49, 0x94,\n    0xCF, 0x92, 0xCC, 0x33, 0x99, 0xE8, 0x08, 0x60,\n    0x17, 0x9A, 0x12, 0x9F, 0x24, 0xDD, 0xB1, 0x24,\n    0x99, 0xC7, 0x3A, 0xB8, 0x0A, 0x7B, 0x0D, 0xDD,\n    0x35, 0x07, 0x79, 0x17, 0x0B, 0x51, 0x9B, 0xB3,\n    0xC7, 0x10, 0x01, 0x13, 0xE7, 0x3F, 0xF3, 0x5F,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00\n};\n\n/* 512 bit proprietary certificate\n  dwVersion            0   4  bytes always 0x00000001\n  dwSigAlgId           4   4  bytes always 0x00000001\n  dwKeyAlgId           8   4  bytes always 0x00000001\n  wPublicKeyBlobType  12   2  bytes always 0x0006\n  wPublicKeyBlobLen   14   2  bytes        0x005C      92  bytes\n    magic             16   4  bytes always 0x31415352\n    keylen            20   4  bytes        0x0048      72  bytes\n    bitlen            24   4  bytes        0x0200     512  bits\n    datalen           28   4  bytes        0x003F      63  bytes\n    pubExp            32   4  bytes        0x00010001\n    modulus           36  72  bytes\n  wSignatureBlobType 108   2  bytes always 0x0008\n  wSignatureBlobLen  110   2  bytes        0x0048      72 bytes\n    SignatureBlob    112  72  bytes */\n\nstatic tui8 g_testkey512[184] = /* 512 bit test key */\n{\n    0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, /* 0 */\n    0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5c, 0x00,\n    0x52, 0x53, 0x41, 0x31, 0x48, 0x00, 0x00, 0x00,\n    0x00, 0x02, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,\n    0x01, 0x00, 0x01, 0x00, 0x79, 0x6f, 0xb4, 0xdf, /* 32 */\n    0xa6, 0x95, 0xb9, 0xa9, 0x61, 0xe3, 0xc4, 0x5e,\n    0xff, 0x6b, 0xd8, 0x81, 0x8a, 0x12, 0x4a, 0x93,\n    0x42, 0x97, 0x18, 0x93, 0xac, 0xd1, 0x3a, 0x38,\n    0x3c, 0x68, 0x50, 0x19, 0x31, 0xb6, 0x84, 0x51, /* 64 */\n    0x79, 0xfb, 0x1c, 0xe7, 0xe3, 0x99, 0x20, 0xc7,\n    0x84, 0xdf, 0xd1, 0xaa, 0xb5, 0x15, 0xef, 0x47,\n    0x7e, 0xfc, 0x88, 0xeb, 0x29, 0xc3, 0x27, 0x5a,\n    0x35, 0xf8, 0xfd, 0xaa, 0x00, 0x00, 0x00, 0x00, /* 96 */\n    0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x48, 0x00,\n    0x32, 0x3b, 0xde, 0x6f, 0x18, 0x97, 0x1e, 0xc3,\n    0x6b, 0x2b, 0x2d, 0xe4, 0xfc, 0x2d, 0xa2, 0x8e,\n    0x32, 0x3c, 0xf3, 0x1b, 0x24, 0x90, 0x57, 0x4d, /* 128 */\n    0x8e, 0xe4, 0x69, 0xfc, 0x16, 0x8d, 0x41, 0x92,\n    0x78, 0xc7, 0x9c, 0xb4, 0x26, 0xff, 0xe8, 0x3e,\n    0xa1, 0x8a, 0xf5, 0x57, 0xc0, 0x7f, 0x3e, 0x21,\n    0x17, 0x32, 0x30, 0x6f, 0x79, 0xe1, 0x36, 0xcd, /* 160 */\n    0xb6, 0x8e, 0xbe, 0x57, 0x57, 0xd2, 0xa9, 0x36,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n};\n\n/* 2048 bit proprietary certificate\n  dwVersion            0   4  bytes always 0x00000001\n  dwSigAlgId           4   4  bytes always 0x00000001\n  dwKeyAlgId           8   4  bytes always 0x00000001\n  wPublicKeyBlobType  12   2  bytes always 0x0006\n  wPublicKeyBlobLen   14   2  bytes        0x011C     284  bytes\n    magic             16   4  bytes always 0x31415352\n    keylen            20   4  bytes        0x0108     264  bytes\n    bitlen            24   4  bytes        0x0800    2048  bits\n    datalen           28   4  bytes        0x00FF     255  bytes\n    pubExp            32   4  bytes        0x00010001\n    modulus           36 264  bytes\n  wSignatureBlobType 300   2  bytes always 0x0008\n  wSignatureBlobLen  302   2  bytes        0x0048      72 bytes\n    SignatureBlob    304  72  bytes */\n\nstatic tui8 g_testkey2048[376] = /* 2048 bit test key */\n{\n    0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, /* 0 */\n    0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x1c, 0x01,\n    0x52, 0x53, 0x41, 0x31, 0x08, 0x01, 0x00, 0x00,\n    0x00, 0x08, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,\n    0x01, 0x00, 0x01, 0x00, 0x13, 0x77, 0x6d, 0xd8, /* 32 */\n    0x7b, 0x6e, 0x6f, 0xb4, 0x27, 0x6d, 0x70, 0x3a,\n    0x97, 0x5f, 0xcb, 0x50, 0x9b, 0x13, 0x6b, 0xc7,\n    0xba, 0xdf, 0x73, 0x54, 0x17, 0x35, 0xf0, 0x09,\n    0x9e, 0x9d, 0x0b, 0x6a, 0x2c, 0x9f, 0xd1, 0x0c, /* 64 */\n    0xc6, 0x47, 0x83, 0xde, 0xca, 0x90, 0x20, 0xac,\n    0x70, 0x63, 0x9b, 0xb7, 0x49, 0x07, 0x0b, 0xf5,\n    0xf2, 0x38, 0x2a, 0x40, 0xff, 0xf1, 0xba, 0x97,\n    0x79, 0x3e, 0xd4, 0xd1, 0xf3, 0x41, 0x0f, 0x91, /* 96 */\n    0xfe, 0x1a, 0x86, 0xf4, 0x1b, 0xef, 0xcc, 0x29,\n    0xa3, 0x35, 0x6f, 0x60, 0xfa, 0x98, 0x53, 0x51,\n    0x80, 0x57, 0x15, 0x2f, 0xe1, 0x8b, 0xd7, 0x86,\n    0x15, 0x2d, 0xb5, 0xec, 0x7a, 0xdd, 0xc5, 0x1d, /* 128 */\n    0x1b, 0x88, 0x53, 0x67, 0x86, 0xe1, 0x6e, 0xcd,\n    0x4e, 0x2e, 0xfd, 0xd2, 0x49, 0x04, 0xfb, 0x1d,\n    0x95, 0xf0, 0xe9, 0x7f, 0x97, 0xa3, 0x1b, 0xb2,\n    0x92, 0x2e, 0x62, 0x2a, 0x96, 0xd4, 0xea, 0x18, /* 160 */\n    0x8e, 0x99, 0x41, 0xea, 0x83, 0xb5, 0xf1, 0x0e,\n    0xea, 0x53, 0x70, 0x99, 0xd7, 0x9e, 0x0c, 0x65,\n    0x2b, 0xf4, 0xdc, 0x0e, 0xe7, 0x9e, 0xce, 0x04,\n    0x25, 0x01, 0x88, 0xc4, 0xc1, 0xd2, 0xa4, 0x18, /* 192 */\n    0xc2, 0x8a, 0x52, 0x0f, 0x01, 0xb2, 0x71, 0x30,\n    0x44, 0x3f, 0x5b, 0x11, 0x2e, 0xe7, 0x53, 0xa0,\n    0xc8, 0x1f, 0x77, 0xaf, 0xb5, 0xbb, 0xaf, 0x12,\n    0xe8, 0x19, 0x0c, 0xf6, 0x1f, 0xa8, 0x3e, 0x11, /* 224 */\n    0x34, 0xe4, 0xac, 0x1c, 0x1c, 0x00, 0xbb, 0xb9,\n    0x2f, 0xbb, 0x81, 0x76, 0x4e, 0x46, 0xda, 0x73,\n    0x00, 0x82, 0x71, 0xa4, 0x62, 0xc3, 0xd4, 0x3f,\n    0xda, 0x34, 0x54, 0x27, 0xe3, 0xd0, 0x3a, 0x73, /* 256 */\n    0x2f, 0x99, 0xc4, 0x91, 0x56, 0x12, 0x98, 0xa8,\n    0x3b, 0x8d, 0x61, 0x83, 0x62, 0xb7, 0x20, 0x61,\n    0x4d, 0xc9, 0x41, 0xd1, 0x40, 0x02, 0x11, 0x4b,\n    0x63, 0x46, 0xc7, 0xc1, 0x00, 0x00, 0x00, 0x00, /* 288 */\n    0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x48, 0x00,\n    0x00, 0x50, 0xb7, 0x75, 0xf3, 0x77, 0x99, 0xb2,\n    0xd3, 0xdd, 0xcd, 0x83, 0x6e, 0xdb, 0x0a, 0x29,\n    0x88, 0x05, 0xb5, 0x8a, 0x49, 0xd5, 0xa8, 0x5a, /* 320 */\n    0xc3, 0xb7, 0x18, 0xc2, 0x3c, 0x1e, 0xde, 0xd3,\n    0x8f, 0xdd, 0x21, 0x27, 0x84, 0xa0, 0xc8, 0x8d,\n    0x65, 0xce, 0x5d, 0x3d, 0x46, 0x65, 0x88, 0xfc,\n    0x35, 0x0a, 0x04, 0xa0, 0xda, 0xc1, 0xab, 0xbf, /* 352 */\n    0xcd, 0xf1, 0x7e, 0x71, 0x7b, 0xf8, 0x4a, 0x78,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n};\n\n/*****************************************************************************/\nstatic int\nout_params(void)\n{\n    g_writeln(\"%s\", \"\");\n    g_writeln(\"xrdp rsa key gen utility examples\");\n    g_writeln(\"  xrdp-keygen xrdp ['path and file name' | auto] [512 or 2048]\");\n    g_writeln(\"  xrdp-keygen test\");\n    g_writeln(\"%s\", \"\");\n    return 0;\n}\n\n/*****************************************************************************/\n/* this is the special key signing algorithm */\nstatic int\nsign_key(const char *e_data, int e_len, const char *n_data, int n_len,\n         char *sign_data, int sign_len)\n{\n    char *key;\n    char *md5_final;\n    void *md5;\n\n    if ((e_len != 4) || ((n_len != 64) && (n_len != 256)) || (sign_len != 64))\n    {\n        return 1;\n    }\n\n    if (n_len == 64)\n    {\n        key = (char *)g_malloc(184, 0);\n        md5_final = (char *)g_malloc(64, 0);\n        md5 = ssl_md5_info_create();\n        /* copy the test key */\n        g_memcpy(key, g_testkey512, 184);\n        /* replace e and n */\n        g_memcpy(key + 32, e_data, e_len);\n        g_memcpy(key + 36, n_data, n_len);\n        ssl_md5_clear(md5);\n        /* the first 108 bytes */\n        ssl_md5_transform(md5, key, 108);\n        /* set the whole thing with 0xff */\n        g_memset(md5_final, 0xff, 64);\n        /* digest 16 bytes */\n        ssl_md5_complete(md5, md5_final);\n        /* set non 0xff array items */\n        md5_final[16] = 0;\n        md5_final[62] = 1;\n        md5_final[63] = 0;\n        /* encrypt */\n        ssl_mod_exp(sign_data, sign_len, md5_final, 64, (char *)g_ppk_n, 64,\n                    (char *)g_ppk_d, 64);\n        /* cleanup */\n        ssl_md5_info_delete(md5);\n        g_free(key);\n        g_free(md5_final);\n    }\n    else if (n_len == 256)\n    {\n        key = (char *)g_malloc(376, 0);\n        md5_final = (char *)g_malloc(64, 0);\n        md5 = ssl_md5_info_create();\n        /* copy the test key */\n        g_memcpy(key, g_testkey2048, 376);\n        /* replace e and n */\n        g_memcpy(key + 32, e_data, e_len);\n        g_memcpy(key + 36, n_data, n_len);\n        ssl_md5_clear(md5);\n        /* the first 300 bytes */\n        ssl_md5_transform(md5, key, 300);\n        /* set the whole thing with 0xff */\n        g_memset(md5_final, 0xff, 64);\n        /* digest 16 bytes */\n        ssl_md5_complete(md5, md5_final);\n        /* set non 0xff array items */\n        md5_final[16] = 0;\n        md5_final[62] = 1;\n        md5_final[63] = 0;\n        /* encrypt */\n        ssl_mod_exp(sign_data, sign_len, md5_final, 64, (char *)g_ppk_n, 64,\n                    (char *)g_ppk_d, 64);\n        /* cleanup */\n        ssl_md5_info_delete(md5);\n        g_free(key);\n        g_free(md5_final);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nwrite_out_line(int fd, const char *name, const char *data, int len)\n{\n    int max;\n    int error;\n    int index;\n    int data_item;\n    int buf_pos;\n    char *buf;\n    char *text;\n\n    text = (char *)g_malloc(256, 0);\n    max = len;\n    max = max * 10;\n    buf_pos = g_strlen(name);\n    max = max + buf_pos + 16;\n    buf = (char *)g_malloc(max, 0);\n    g_strncpy(buf, name, max - 1);\n    buf[buf_pos] = '=';\n    buf_pos++;\n\n    for (index = 0; index < len; index++)\n    {\n        data_item = (tui8)(data[index]);\n        g_snprintf(text, 255, \"0x%2.2x\", data_item);\n\n        if (index != 0)\n        {\n            buf[buf_pos] = ',';\n            buf_pos++;\n        }\n\n        buf[buf_pos] = text[0];\n        buf_pos++;\n        buf[buf_pos] = text[1];\n        buf_pos++;\n        buf[buf_pos] = text[2];\n        buf_pos++;\n        buf[buf_pos] = text[3];\n        buf_pos++;\n    }\n\n    buf[buf_pos] = '\\n';\n    buf_pos++;\n    buf[buf_pos] = 0;\n    error = g_file_write(fd, buf, buf_pos) == -1;\n    g_free(buf);\n    g_free(text);\n    return error;\n}\n\n/*****************************************************************************/\nstatic int\nsave_all(const char *e_data, int e_len, const char *n_data, int n_len,\n         const char *d_data, int d_len, const char *sign_data, int sign_len,\n         const char *path_and_file_name)\n{\n    int fd;\n    char filename[256];\n\n    if (path_and_file_name == 0)\n    {\n        g_strncpy(filename, \"rsakeys.ini\", 255);\n    }\n    else\n    {\n        g_strncpy(filename, path_and_file_name, 255);\n    }\n\n    g_writeln(\"saving to %s\", filename);\n    g_writeln(\"%s\", \"\");\n\n    if (g_file_exist(filename))\n    {\n        if (g_file_delete(filename) == 0)\n        {\n            g_writeln(\"problem deleting %s, maybe no rights\", filename);\n            return 1;\n        }\n    }\n\n    fd = g_file_open_rw(filename);\n\n    if (fd != -1)\n    {\n        if (e_data == NULL)\n        {\n            /* FIPS mode */\n            g_file_close(fd);\n            return 0;\n        }\n\n        if (g_file_write(fd, \"[keys]\\n\", 7) == -1)\n        {\n            g_writeln(\"problem writing to %s, maybe no rights\", filename);\n            g_file_close(fd);\n            return 1;\n        }\n\n        write_out_line(fd, \"pub_exp\", e_data, e_len);\n        write_out_line(fd, \"pub_mod\", n_data, n_len);\n        write_out_line(fd, \"pub_sig\", sign_data, sign_len);\n        write_out_line(fd, \"pri_exp\", d_data, d_len);\n    }\n    else\n    {\n        g_writeln(\"problem opening %s, maybe no rights\", filename);\n        return 1;\n    }\n\n    g_file_close(fd);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nkey_gen(const char *path_and_file_name)\n{\n    char *e_data = NULL;\n    char n_data[256] = {0};\n    char d_data[256] = {0};\n    char sign_data[64] = {0};\n    int e_len = 4;\n    int n_len = g_key_size_bits / 8;\n    int d_len = n_len;\n    int sign_len = sizeof(sign_data);\n    int error = 0;\n\n    if (g_fips_mode_enabled())\n    {\n        g_writeln(\"%s\", \"\");\n        g_writeln(\"This machine is running in FIPS mode - keys will not be generated\");\n        g_writeln(\"%s\", \"\");\n    }\n    else\n    {\n        e_data = (char *)g_exponent;\n        g_writeln(\"%s\", \"\");\n        g_writeln(\"Generating %d bit rsa key...\", g_key_size_bits);\n        g_writeln(\"%s\", \"\");\n\n        if (error == 0)\n        {\n            error = ssl_gen_key_xrdp1(g_key_size_bits, e_data, e_len, n_data, n_len,\n                                      d_data, d_len);\n            if (error != 0)\n            {\n                g_writeln(\"error %d in key_gen, ssl_gen_key_xrdp1\", error);\n            }\n        }\n\n        if (error == 0)\n        {\n            g_writeln(\"ssl_gen_key_xrdp1 ok\");\n            g_writeln(\"%s\", \"\");\n            error = sign_key(e_data, e_len, n_data, n_len, sign_data, sign_len);\n\n            if (error != 0)\n            {\n                g_writeln(\"error %d in key_gen, sign_key\", error);\n            }\n        }\n    }\n\n    if (error == 0)\n    {\n        error = save_all(e_data, e_len, n_data, n_len, d_data, d_len,\n                         sign_data, sign_len, path_and_file_name);\n\n        if (error != 0)\n        {\n            g_writeln(\"error %d in key_gen, save_all\", error);\n        }\n    }\n\n    return error;\n}\n\n/*****************************************************************************/\nstatic int\nkey_gen_auto(void)\n{\n    return key_gen(XRDP_CFG_PATH \"/rsakeys.ini\");\n}\n\n/*****************************************************************************/\nstatic int\nkey_test512(void)\n{\n    char *md5_final;\n    char *sig;\n    void *md5;\n\n    md5_final = (char *)g_malloc(64, 0);\n    sig = (char *)g_malloc(64, 0);\n    md5 = ssl_md5_info_create();\n    g_writeln(\"original key is:\");\n    g_hexdump((char *)g_testkey512, 184);\n    g_writeln(\"original exponent is:\");\n    g_hexdump((char *)g_testkey512 + 32, 4);\n    g_writeln(\"original modulus is:\");\n    g_hexdump((char *)g_testkey512 + 36, 64);\n    g_writeln(\"original signature is:\");\n    g_hexdump((char *)g_testkey512 + 112, 64);\n    ssl_md5_clear(md5);\n    ssl_md5_transform(md5, (char *)g_testkey512, 108);\n    g_memset(md5_final, 0xff, 64);\n    ssl_md5_complete(md5, md5_final);\n    g_writeln(\"md5 hash of first 108 bytes of this key is:\");\n    g_hexdump(md5_final, 16);\n    md5_final[16] = 0;\n    md5_final[62] = 1;\n    md5_final[63] = 0;\n    ssl_mod_exp(sig, 64, md5_final, 64, (char *)g_ppk_n, 64, (char *)g_ppk_d, 64);\n    g_writeln(\"produced signature(this should match original \"\n              \"signature above) is:\");\n    g_hexdump(sig, 64);\n    g_memset(md5_final, 0, 64);\n    ssl_mod_exp(md5_final, 64, (char *)g_testkey512 + 112, 64, (char *)g_ppk_n, 64,\n                (char *)g_ppk_e, 4);\n    g_writeln(\"decrypted hash of first 108 bytes of this key is:\");\n    g_hexdump(md5_final, 64);\n    ssl_md5_info_delete(md5);\n    g_free(md5_final);\n    g_free(sig);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nkey_test2048(void)\n{\n    char *md5_final;\n    char *sig;\n    void *md5;\n\n    md5_final = (char *)g_malloc(64, 0);\n    sig = (char *)g_malloc(64, 0);\n    md5 = ssl_md5_info_create();\n    g_writeln(\"original key is:\");\n    g_hexdump((char *)g_testkey2048, 376);\n    g_writeln(\"original exponent is:\");\n    g_hexdump((char *)g_testkey2048 + 32, 4);\n    g_writeln(\"original modulus is:\");\n    g_hexdump((char *)g_testkey2048 + 36, 256);\n    g_writeln(\"original signature is:\");\n    g_hexdump((char *)g_testkey2048 + 304, 64);\n    ssl_md5_clear(md5);\n    ssl_md5_transform(md5, (char *)g_testkey2048, 300);\n    g_memset(md5_final, 0xff, 64);\n    ssl_md5_complete(md5, md5_final);\n    g_writeln(\"md5 hash of first 300 bytes of this key is:\");\n    g_hexdump(md5_final, 16);\n    md5_final[16] = 0;\n    md5_final[62] = 1;\n    md5_final[63] = 0;\n    ssl_mod_exp(sig, 64, md5_final, 64, (char *)g_ppk_n, 64, (char *)g_ppk_d, 64);\n    g_writeln(\"produced signature(this should match original \"\n              \"signature above) is:\");\n    g_hexdump(sig, 64);\n    g_memset(md5_final, 0, 64);\n    ssl_mod_exp(md5_final, 64, (char *)g_testkey2048 + 304, 64, (char *)g_ppk_n, 64,\n                (char *)g_ppk_e, 4);\n    g_writeln(\"decrypted hash of first 108 bytes of this key is:\");\n    g_hexdump(md5_final, 64);\n    ssl_md5_info_delete(md5);\n    g_free(md5_final);\n    g_free(sig);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    if (argc > 1)\n    {\n        if (g_strcasecmp(argv[1], \"xrdp\") == 0)\n        {\n            if (argc > 2)\n            {\n                if (argc > 3)\n                {\n                    g_key_size_bits = g_atoi(argv[3]);\n                    if ((g_key_size_bits != 512) && (g_key_size_bits != 2048))\n                    {\n                        out_params();\n                        return 0;\n                    }\n                }\n                if (g_strcasecmp(argv[2], \"auto\") == 0)\n                {\n                    if (g_getuid() != 0)\n                    {\n                        g_writeln(\"must run as root\");\n                        return 0;\n                    }\n\n                    return key_gen_auto();\n                }\n                else\n                {\n                    return key_gen(argv[2]);\n                }\n            }\n            else\n            {\n                return key_gen(0);\n            }\n        }\n        else if (g_strcasecmp(argv[1], \"test\") == 0)\n        {\n            g_writeln(\"%s\", \"\");\n            g_writeln(\"testing 512 bit key\");\n            key_test512();\n            g_writeln(\"%s\", \"\");\n            g_writeln(\"testing 2048 bit key\");\n            key_test2048();\n            return 0;\n        }\n    }\n\n    out_params();\n    return 0;\n}\n"
  },
  {
    "path": "keygen/openssl.conf",
    "content": "[req]\ndistinguished_name = req_distinguished_name\n# The extensions to add to the self signed cert\nx509_extensions = v3_ca\n\n[req_distinguished_name]\n\n[v3_ca]\n# Extensions for a typical CA - PKIX recommendation.\nsubjectKeyIdentifier = hash\nauthorityKeyIdentifier = keyid:always, issuer\n\n# This is what PKIX recommends but some broken software chokes on critical\n# extensions.\n#basicConstraints = critical, CA:true\n# So we do this instead.\nbasicConstraints = CA:true\n\n# Key usage: this is typical for a CA certificate. However since it will\n# prevent it being used as an test self-signed certificate it is best\n# left out by default.\n#keyUsage = cRLSign, keyCertSign\n\n# Some might want this also\n#nsCertType = sslCA, emailCA\n\n# Include email address in subject alt name: another PKIX recommendation\n#subjectAltName = email:copy\n# Copy issuer details\n#issuerAltName = issuer:copy\n\n# DER hex encoding of an extension: experts only!\n#obj = DER:02:03\n# Where 'obj' is a standard or added object\n# You can even override a supported extension:\n#basicConstraints = critical, DER:30:03:01:01:FF\n"
  },
  {
    "path": "libipm/Doxyfile",
    "content": "# Doxyfile 1.8.17\n\n# This file describes the settings to be used by the documentation system\n# doxygen (www.doxygen.org) for a project.\n#\n# All text after a double hash (##) is considered a comment and is placed in\n# front of the TAG it is preceding.\n#\n# All text after a single hash (#) is considered a comment and will be ignored.\n# The format is:\n# TAG = value [value, ...]\n# For lists, items can also be appended using:\n# TAG += value [value, ...]\n# Values that contain spaces should be placed between quotes (\\\" \\\").\n\n#---------------------------------------------------------------------------\n# Project related configuration options\n#---------------------------------------------------------------------------\n\n# This tag specifies the encoding used for all characters in the configuration\n# file that follow. The default is UTF-8 which is also the encoding used for all\n# text before the first occurrence of this tag. Doxygen uses libiconv (or the\n# iconv built into libc) for the transcoding. See\n# https://www.gnu.org/software/libiconv/ for the list of possible encodings.\n# The default value is: UTF-8.\n\nDOXYFILE_ENCODING      = UTF-8\n\n# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by\n# double-quotes, unless you are using Doxywizard) that should identify the\n# project for which the documentation is generated. This name is used in the\n# title of most generated pages and in a few other places.\n# The default value is: My Project.\n\nPROJECT_NAME           = xrdp/libipm\n\n# The PROJECT_NUMBER tag can be used to enter a project or revision number. This\n# could be handy for archiving the generated documentation or if some version\n# control system is used.\n\nPROJECT_NUMBER         =\n\n# Using the PROJECT_BRIEF tag one can provide an optional one line description\n# for a project that appears at the top of each page and should give viewer a\n# quick idea about the purpose of the project. Keep the description short.\n\nPROJECT_BRIEF          =\n\n# With the PROJECT_LOGO tag one can specify a logo or an icon that is included\n# in the documentation. The maximum height of the logo should not exceed 55\n# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy\n# the logo to the output directory.\n\nPROJECT_LOGO           =\n\n# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path\n# into which the generated documentation will be written. If a relative path is\n# entered, it will be relative to the location where doxygen was started. If\n# left blank the current directory will be used.\n\nOUTPUT_DIRECTORY       = ../docs/libipm\n\n# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-\n# directories (in 2 levels) under the output directory of each output format and\n# will distribute the generated files over these directories. Enabling this\n# option can be useful when feeding doxygen a huge amount of source files, where\n# putting all generated files in the same directory would otherwise causes\n# performance problems for the file system.\n# The default value is: NO.\n\nCREATE_SUBDIRS         = NO\n\n# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII\n# characters to appear in the names of generated files. If set to NO, non-ASCII\n# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode\n# U+3044.\n# The default value is: NO.\n\nALLOW_UNICODE_NAMES    = NO\n\n# The OUTPUT_LANGUAGE tag is used to specify the language in which all\n# documentation generated by doxygen is written. Doxygen will use this\n# information to generate all constant output in the proper language.\n# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,\n# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),\n# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,\n# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),\n# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,\n# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,\n# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,\n# Ukrainian and Vietnamese.\n# The default value is: English.\n\nOUTPUT_LANGUAGE        = English\n\n# The OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all\n# documentation generated by doxygen is written. Doxygen will use this\n# information to generate all generated output in the proper direction.\n# Possible values are: None, LTR, RTL and Context.\n# The default value is: None.\n\nOUTPUT_TEXT_DIRECTION  = None\n\n# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member\n# descriptions after the members that are listed in the file and class\n# documentation (similar to Javadoc). Set to NO to disable this.\n# The default value is: YES.\n\nBRIEF_MEMBER_DESC      = YES\n\n# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief\n# description of a member or function before the detailed description\n#\n# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the\n# brief descriptions will be completely suppressed.\n# The default value is: YES.\n\nREPEAT_BRIEF           = NO\n\n# This tag implements a quasi-intelligent brief description abbreviator that is\n# used to form the text in various listings. Each string in this list, if found\n# as the leading text of the brief description, will be stripped from the text\n# and the result, after processing the whole list, is used as the annotated\n# text. Otherwise, the brief description is used as-is. If left blank, the\n# following values are used ($name is automatically replaced with the name of\n# the entity):The $name class, The $name widget, The $name file, is, provides,\n# specifies, contains, represents, a, an and the.\n\nABBREVIATE_BRIEF       =\n\n# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then\n# doxygen will generate a detailed section even if there is only a brief\n# description.\n# The default value is: NO.\n\nALWAYS_DETAILED_SEC    = NO\n\n# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all\n# inherited members of a class in the documentation of that class as if those\n# members were ordinary class members. Constructors, destructors and assignment\n# operators of the base classes will not be shown.\n# The default value is: NO.\n\nINLINE_INHERITED_MEMB  = NO\n\n# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path\n# before files name in the file list and in the header files. If set to NO the\n# shortest path that makes the file name unique will be used\n# The default value is: YES.\n\nFULL_PATH_NAMES        = YES\n\n# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.\n# Stripping is only done if one of the specified strings matches the left-hand\n# part of the path. The tag can be used to show relative paths in the file list.\n# If left blank the directory from which doxygen is run is used as the path to\n# strip.\n#\n# Note that you can specify absolute paths here, but also relative paths, which\n# will be relative from the directory where doxygen is started.\n# This tag requires that the tag FULL_PATH_NAMES is set to YES.\n\nSTRIP_FROM_PATH        =\n\n# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the\n# path mentioned in the documentation of a class, which tells the reader which\n# header file to include in order to use a class. If left blank only the name of\n# the header file containing the class definition is used. Otherwise one should\n# specify the list of include paths that are normally passed to the compiler\n# using the -I flag.\n\nSTRIP_FROM_INC_PATH    =\n\n# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but\n# less readable) file names. This can be useful is your file systems doesn't\n# support long names like on DOS, Mac, or CD-ROM.\n# The default value is: NO.\n\nSHORT_NAMES            = NO\n\n# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the\n# first line (until the first dot) of a Javadoc-style comment as the brief\n# description. If set to NO, the Javadoc-style will behave just like regular Qt-\n# style comments (thus requiring an explicit @brief command for a brief\n# description.)\n# The default value is: NO.\n\nJAVADOC_AUTOBRIEF      = NO\n\n# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line\n# such as\n# /***************\n# as being the beginning of a Javadoc-style comment \"banner\". If set to NO, the\n# Javadoc-style will behave just like regular comments and it will not be\n# interpreted by doxygen.\n# The default value is: NO.\n\nJAVADOC_BANNER         = NO\n\n# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first\n# line (until the first dot) of a Qt-style comment as the brief description. If\n# set to NO, the Qt-style will behave just like regular Qt-style comments (thus\n# requiring an explicit \\brief command for a brief description.)\n# The default value is: NO.\n\nQT_AUTOBRIEF           = NO\n\n# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a\n# multi-line C++ special comment block (i.e. a block of //! or /// comments) as\n# a brief description. This used to be the default behavior. The new default is\n# to treat a multi-line C++ comment block as a detailed description. Set this\n# tag to YES if you prefer the old behavior instead.\n#\n# Note that setting this tag to YES also means that rational rose comments are\n# not recognized any more.\n# The default value is: NO.\n\nMULTILINE_CPP_IS_BRIEF = NO\n\n# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the\n# documentation from any documented member that it re-implements.\n# The default value is: YES.\n\nINHERIT_DOCS           = YES\n\n# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new\n# page for each member. If set to NO, the documentation of a member will be part\n# of the file/class/namespace that contains it.\n# The default value is: NO.\n\nSEPARATE_MEMBER_PAGES  = NO\n\n# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen\n# uses this value to replace tabs by spaces in code fragments.\n# Minimum value: 1, maximum value: 16, default value: 4.\n\nTAB_SIZE               = 8\n\n# This tag can be used to specify a number of aliases that act as commands in\n# the documentation. An alias has the form:\n# name=value\n# For example adding\n# \"sideeffect=@par Side Effects:\\n\"\n# will allow you to put the command \\sideeffect (or @sideeffect) in the\n# documentation, which will result in a user-defined paragraph with heading\n# \"Side Effects:\". You can put \\n's in the value part of an alias to insert\n# newlines (in the resulting output). You can put ^^ in the value part of an\n# alias to insert a newline as if a physical newline was in the original file.\n# When you need a literal { or } or , in the value part of an alias you have to\n# escape them by means of a backslash (\\), this can lead to conflicts with the\n# commands \\{ and \\} for these it is advised to use the version @{ and @} or use\n# a double escape (\\\\{ and \\\\})\n\nALIASES                =\n\n# This tag can be used to specify a number of word-keyword mappings (TCL only).\n# A mapping has the form \"name=value\". For example adding \"class=itcl::class\"\n# will allow you to use the command class in the itcl::class meaning.\n\nTCL_SUBST              =\n\n# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources\n# only. Doxygen will then generate output that is more tailored for C. For\n# instance, some of the names that are used will be different. The list of all\n# members will be omitted, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_FOR_C  = YES\n\n# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or\n# Python sources only. Doxygen will then generate output that is more tailored\n# for that language. For instance, namespaces will be presented as packages,\n# qualified scopes will look different, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_JAVA   = NO\n\n# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran\n# sources. Doxygen will then generate output that is tailored for Fortran.\n# The default value is: NO.\n\nOPTIMIZE_FOR_FORTRAN   = NO\n\n# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL\n# sources. Doxygen will then generate output that is tailored for VHDL.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_VHDL   = NO\n\n# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice\n# sources only. Doxygen will then generate output that is more tailored for that\n# language. For instance, namespaces will be presented as modules, types will be\n# separated into more groups, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_SLICE  = NO\n\n# Doxygen selects the parser to use depending on the extension of the files it\n# parses. With this tag you can assign which parser to use for a given\n# extension. Doxygen has a built-in mapping, but you can override or extend it\n# using this tag. The format is ext=language, where ext is a file extension, and\n# language is one of the parsers supported by doxygen: IDL, Java, JavaScript,\n# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice,\n# Fortran (fixed format Fortran: FortranFixed, free formatted Fortran:\n# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser\n# tries to guess whether the code is fixed or free formatted code, this is the\n# default for Fortran type files), VHDL, tcl. For instance to make doxygen treat\n# .inc files as Fortran files (default is PHP), and .f files as C (default is\n# Fortran), use: inc=Fortran f=C.\n#\n# Note: For files without extension you can use no_extension as a placeholder.\n#\n# Note that for custom extensions you also need to set FILE_PATTERNS otherwise\n# the files are not read by doxygen.\n\nEXTENSION_MAPPING      =\n\n# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments\n# according to the Markdown format, which allows for more readable\n# documentation. See https://daringfireball.net/projects/markdown/ for details.\n# The output of markdown processing is further processed by doxygen, so you can\n# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in\n# case of backward compatibilities issues.\n# The default value is: YES.\n\nMARKDOWN_SUPPORT       = YES\n\n# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up\n# to that level are automatically included in the table of contents, even if\n# they do not have an id attribute.\n# Note: This feature currently applies only to Markdown headings.\n# Minimum value: 0, maximum value: 99, default value: 5.\n# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.\n\nTOC_INCLUDE_HEADINGS   = 5\n\n# When enabled doxygen tries to link words that correspond to documented\n# classes, or namespaces to their corresponding documentation. Such a link can\n# be prevented in individual cases by putting a % sign in front of the word or\n# globally by setting AUTOLINK_SUPPORT to NO.\n# The default value is: YES.\n\nAUTOLINK_SUPPORT       = YES\n\n# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want\n# to include (a tag file for) the STL sources as input, then you should set this\n# tag to YES in order to let doxygen match functions declarations and\n# definitions whose arguments contain STL classes (e.g. func(std::string);\n# versus func(std::string) {}). This also make the inheritance and collaboration\n# diagrams that involve STL classes more complete and accurate.\n# The default value is: NO.\n\nBUILTIN_STL_SUPPORT    = NO\n\n# If you use Microsoft's C++/CLI language, you should set this option to YES to\n# enable parsing support.\n# The default value is: NO.\n\nCPP_CLI_SUPPORT        = NO\n\n# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:\n# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen\n# will parse them like normal C++ but will assume all classes use public instead\n# of private inheritance when no explicit protection keyword is present.\n# The default value is: NO.\n\nSIP_SUPPORT            = NO\n\n# For Microsoft's IDL there are propget and propput attributes to indicate\n# getter and setter methods for a property. Setting this option to YES will make\n# doxygen to replace the get and set methods by a property in the documentation.\n# This will only work if the methods are indeed getting or setting a simple\n# type. If this is not the case, or you want to show the methods anyway, you\n# should set this option to NO.\n# The default value is: YES.\n\nIDL_PROPERTY_SUPPORT   = YES\n\n# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC\n# tag is set to YES then doxygen will reuse the documentation of the first\n# member in the group (if any) for the other members of the group. By default\n# all members of a group must be documented explicitly.\n# The default value is: NO.\n\nDISTRIBUTE_GROUP_DOC   = NO\n\n# If one adds a struct or class to a group and this option is enabled, then also\n# any nested class or struct is added to the same group. By default this option\n# is disabled and one has to add nested compounds explicitly via \\ingroup.\n# The default value is: NO.\n\nGROUP_NESTED_COMPOUNDS = NO\n\n# Set the SUBGROUPING tag to YES to allow class member groups of the same type\n# (for instance a group of public functions) to be put as a subgroup of that\n# type (e.g. under the Public Functions section). Set it to NO to prevent\n# subgrouping. Alternatively, this can be done per class using the\n# \\nosubgrouping command.\n# The default value is: YES.\n\nSUBGROUPING            = YES\n\n# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions\n# are shown inside the group in which they are included (e.g. using \\ingroup)\n# instead of on a separate page (for HTML and Man pages) or section (for LaTeX\n# and RTF).\n#\n# Note that this feature does not work in combination with\n# SEPARATE_MEMBER_PAGES.\n# The default value is: NO.\n\nINLINE_GROUPED_CLASSES = NO\n\n# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions\n# with only public data fields or simple typedef fields will be shown inline in\n# the documentation of the scope in which they are defined (i.e. file,\n# namespace, or group documentation), provided this scope is documented. If set\n# to NO, structs, classes, and unions are shown on a separate page (for HTML and\n# Man pages) or section (for LaTeX and RTF).\n# The default value is: NO.\n\nINLINE_SIMPLE_STRUCTS  = NO\n\n# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or\n# enum is documented as struct, union, or enum with the name of the typedef. So\n# typedef struct TypeS {} TypeT, will appear in the documentation as a struct\n# with name TypeT. When disabled the typedef will appear as a member of a file,\n# namespace, or class. And the struct will be named TypeS. This can typically be\n# useful for C code in case the coding convention dictates that all compound\n# types are typedef'ed and only the typedef is referenced, never the tag name.\n# The default value is: NO.\n\nTYPEDEF_HIDES_STRUCT   = NO\n\n# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This\n# cache is used to resolve symbols given their name and scope. Since this can be\n# an expensive process and often the same symbol appears multiple times in the\n# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small\n# doxygen will become slower. If the cache is too large, memory is wasted. The\n# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range\n# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536\n# symbols. At the end of a run doxygen will report the cache usage and suggest\n# the optimal cache size from a speed point of view.\n# Minimum value: 0, maximum value: 9, default value: 0.\n\nLOOKUP_CACHE_SIZE      = 0\n\n#---------------------------------------------------------------------------\n# Build related configuration options\n#---------------------------------------------------------------------------\n\n# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in\n# documentation are documented, even if no documentation was available. Private\n# class members and static file members will be hidden unless the\n# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.\n# Note: This will also disable the warnings about undocumented members that are\n# normally produced when WARNINGS is set to YES.\n# The default value is: NO.\n\nEXTRACT_ALL            = YES\n\n# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will\n# be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PRIVATE        = NO\n\n# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual\n# methods of a class will be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PRIV_VIRTUAL   = NO\n\n# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal\n# scope will be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PACKAGE        = NO\n\n# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be\n# included in the documentation.\n# The default value is: NO.\n\nEXTRACT_STATIC         = YES\n\n# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined\n# locally in source files will be included in the documentation. If set to NO,\n# only classes defined in header files are included. Does not have any effect\n# for Java sources.\n# The default value is: YES.\n\nEXTRACT_LOCAL_CLASSES  = NO\n\n# This flag is only useful for Objective-C code. If set to YES, local methods,\n# which are defined in the implementation section but not in the interface are\n# included in the documentation. If set to NO, only methods in the interface are\n# included.\n# The default value is: NO.\n\nEXTRACT_LOCAL_METHODS  = NO\n\n# If this flag is set to YES, the members of anonymous namespaces will be\n# extracted and appear in the documentation as a namespace called\n# 'anonymous_namespace{file}', where file will be replaced with the base name of\n# the file that contains the anonymous namespace. By default anonymous namespace\n# are hidden.\n# The default value is: NO.\n\nEXTRACT_ANON_NSPACES   = NO\n\n# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all\n# undocumented members inside documented classes or files. If set to NO these\n# members will be included in the various overviews, but no documentation\n# section is generated. This option has no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_MEMBERS     = YES\n\n# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all\n# undocumented classes that are normally visible in the class hierarchy. If set\n# to NO, these classes will be included in the various overviews. This option\n# has no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_CLASSES     = YES\n\n# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend\n# declarations. If set to NO, these declarations will be included in the\n# documentation.\n# The default value is: NO.\n\nHIDE_FRIEND_COMPOUNDS  = NO\n\n# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any\n# documentation blocks found inside the body of a function. If set to NO, these\n# blocks will be appended to the function's detailed documentation block.\n# The default value is: NO.\n\nHIDE_IN_BODY_DOCS      = NO\n\n# The INTERNAL_DOCS tag determines if documentation that is typed after a\n# \\internal command is included. If the tag is set to NO then the documentation\n# will be excluded. Set it to YES to include the internal documentation.\n# The default value is: NO.\n\nINTERNAL_DOCS          = NO\n\n# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file\n# names in lower-case letters. If set to YES, upper-case letters are also\n# allowed. This is useful if you have classes or files whose names only differ\n# in case and if your file system supports case sensitive file names. Windows\n# (including Cygwin) ands Mac users are advised to set this option to NO.\n# The default value is: system dependent.\n\nCASE_SENSE_NAMES       = YES\n\n# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with\n# their full class and namespace scopes in the documentation. If set to YES, the\n# scope will be hidden.\n# The default value is: NO.\n\nHIDE_SCOPE_NAMES       = NO\n\n# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will\n# append additional text to a page's title, such as Class Reference. If set to\n# YES the compound reference will be hidden.\n# The default value is: NO.\n\nHIDE_COMPOUND_REFERENCE= NO\n\n# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of\n# the files that are included by a file in the documentation of that file.\n# The default value is: YES.\n\nSHOW_INCLUDE_FILES     = YES\n\n# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each\n# grouped member an include statement to the documentation, telling the reader\n# which file to include in order to use the member.\n# The default value is: NO.\n\nSHOW_GROUPED_MEMB_INC  = NO\n\n# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include\n# files with double quotes in the documentation rather than with sharp brackets.\n# The default value is: NO.\n\nFORCE_LOCAL_INCLUDES   = NO\n\n# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the\n# documentation for inline members.\n# The default value is: YES.\n\nINLINE_INFO            = YES\n\n# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the\n# (detailed) documentation of file and class members alphabetically by member\n# name. If set to NO, the members will appear in declaration order.\n# The default value is: YES.\n\nSORT_MEMBER_DOCS       = YES\n\n# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief\n# descriptions of file, namespace and class members alphabetically by member\n# name. If set to NO, the members will appear in declaration order. Note that\n# this will also influence the order of the classes in the class list.\n# The default value is: NO.\n\nSORT_BRIEF_DOCS        = NO\n\n# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the\n# (brief and detailed) documentation of class members so that constructors and\n# destructors are listed first. If set to NO the constructors will appear in the\n# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.\n# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief\n# member documentation.\n# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting\n# detailed member documentation.\n# The default value is: NO.\n\nSORT_MEMBERS_CTORS_1ST = NO\n\n# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy\n# of group names into alphabetical order. If set to NO the group names will\n# appear in their defined order.\n# The default value is: NO.\n\nSORT_GROUP_NAMES       = NO\n\n# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by\n# fully-qualified names, including namespaces. If set to NO, the class list will\n# be sorted only by class name, not including the namespace part.\n# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.\n# Note: This option applies only to the class list, not to the alphabetical\n# list.\n# The default value is: NO.\n\nSORT_BY_SCOPE_NAME     = NO\n\n# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper\n# type resolution of all parameters of a function it will reject a match between\n# the prototype and the implementation of a member function even if there is\n# only one candidate or it is obvious which candidate to choose by doing a\n# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still\n# accept a match between prototype and implementation in such cases.\n# The default value is: NO.\n\nSTRICT_PROTO_MATCHING  = NO\n\n# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo\n# list. This list is created by putting \\todo commands in the documentation.\n# The default value is: YES.\n\nGENERATE_TODOLIST      = YES\n\n# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test\n# list. This list is created by putting \\test commands in the documentation.\n# The default value is: YES.\n\nGENERATE_TESTLIST      = YES\n\n# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug\n# list. This list is created by putting \\bug commands in the documentation.\n# The default value is: YES.\n\nGENERATE_BUGLIST       = YES\n\n# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)\n# the deprecated list. This list is created by putting \\deprecated commands in\n# the documentation.\n# The default value is: YES.\n\nGENERATE_DEPRECATEDLIST= YES\n\n# The ENABLED_SECTIONS tag can be used to enable conditional documentation\n# sections, marked by \\if <section_label> ... \\endif and \\cond <section_label>\n# ... \\endcond blocks.\n\nENABLED_SECTIONS       =\n\n# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the\n# initial value of a variable or macro / define can have for it to appear in the\n# documentation. If the initializer consists of more lines than specified here\n# it will be hidden. Use a value of 0 to hide initializers completely. The\n# appearance of the value of individual variables and macros / defines can be\n# controlled using \\showinitializer or \\hideinitializer command in the\n# documentation regardless of this setting.\n# Minimum value: 0, maximum value: 10000, default value: 30.\n\nMAX_INITIALIZER_LINES  = 30\n\n# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at\n# the bottom of the documentation of classes and structs. If set to YES, the\n# list will mention the files that were used to generate the documentation.\n# The default value is: YES.\n\nSHOW_USED_FILES        = YES\n\n# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This\n# will remove the Files entry from the Quick Index and from the Folder Tree View\n# (if specified).\n# The default value is: YES.\n\nSHOW_FILES             = YES\n\n# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces\n# page. This will remove the Namespaces entry from the Quick Index and from the\n# Folder Tree View (if specified).\n# The default value is: YES.\n\nSHOW_NAMESPACES        = YES\n\n# The FILE_VERSION_FILTER tag can be used to specify a program or script that\n# doxygen should invoke to get the current version for each file (typically from\n# the version control system). Doxygen will invoke the program by executing (via\n# popen()) the command command input-file, where command is the value of the\n# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided\n# by doxygen. Whatever the program writes to standard output is used as the file\n# version. For an example see the documentation.\n\nFILE_VERSION_FILTER    =\n\n# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed\n# by doxygen. The layout file controls the global structure of the generated\n# output files in an output format independent way. To create the layout file\n# that represents doxygen's defaults, run doxygen with the -l option. You can\n# optionally specify a file name after the option, if omitted DoxygenLayout.xml\n# will be used as the name of the layout file.\n#\n# Note that if you run doxygen from a directory containing a file called\n# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE\n# tag is left empty.\n\nLAYOUT_FILE            =\n\n# The CITE_BIB_FILES tag can be used to specify one or more bib files containing\n# the reference definitions. This must be a list of .bib files. The .bib\n# extension is automatically appended if omitted. This requires the bibtex tool\n# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info.\n# For LaTeX the style of the bibliography can be controlled using\n# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the\n# search path. See also \\cite for info how to create references.\n\nCITE_BIB_FILES         =\n\n#---------------------------------------------------------------------------\n# Configuration options related to warning and progress messages\n#---------------------------------------------------------------------------\n\n# The QUIET tag can be used to turn on/off the messages that are generated to\n# standard output by doxygen. If QUIET is set to YES this implies that the\n# messages are off.\n# The default value is: NO.\n\nQUIET                  = NO\n\n# The WARNINGS tag can be used to turn on/off the warning messages that are\n# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES\n# this implies that the warnings are on.\n#\n# Tip: Turn warnings on while writing the documentation.\n# The default value is: YES.\n\nWARNINGS               = YES\n\n# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate\n# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag\n# will automatically be disabled.\n# The default value is: YES.\n\nWARN_IF_UNDOCUMENTED   = YES\n\n# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for\n# potential errors in the documentation, such as not documenting some parameters\n# in a documented function, or documenting parameters that don't exist or using\n# markup commands wrongly.\n# The default value is: YES.\n\nWARN_IF_DOC_ERROR      = YES\n\n# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that\n# are documented, but have no documentation for their parameters or return\n# value. If set to NO, doxygen will only warn about wrong or incomplete\n# parameter documentation, but not about the absence of documentation. If\n# EXTRACT_ALL is set to YES then this flag will automatically be disabled.\n# The default value is: NO.\n\nWARN_NO_PARAMDOC       = NO\n\n# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when\n# a warning is encountered.\n# The default value is: NO.\n\nWARN_AS_ERROR          = NO\n\n# The WARN_FORMAT tag determines the format of the warning messages that doxygen\n# can produce. The string should contain the $file, $line, and $text tags, which\n# will be replaced by the file and line number from which the warning originated\n# and the warning text. Optionally the format may contain $version, which will\n# be replaced by the version of the file (if it could be obtained via\n# FILE_VERSION_FILTER)\n# The default value is: $file:$line: $text.\n\nWARN_FORMAT            = \"$file:$line: $text\"\n\n# The WARN_LOGFILE tag can be used to specify a file to which warning and error\n# messages should be written. If left blank the output is written to standard\n# error (stderr).\n\nWARN_LOGFILE           =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the input files\n#---------------------------------------------------------------------------\n\n# The INPUT tag is used to specify the files and/or directories that contain\n# documented source files. You may enter file names like myfile.cpp or\n# directories like /usr/src/myproject. Separate the files or directories with\n# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING\n# Note: If this tag is empty the current directory is searched.\n\nINPUT                  =\n\n# This tag can be used to specify the character encoding of the source files\n# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses\n# libiconv (or the iconv built into libc) for the transcoding. See the libiconv\n# documentation (see: https://www.gnu.org/software/libiconv/) for the list of\n# possible encodings.\n# The default value is: UTF-8.\n\nINPUT_ENCODING         = UTF-8\n\n# If the value of the INPUT tag contains directories, you can use the\n# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and\n# *.h) to filter out the source-files in the directories.\n#\n# Note that for custom extensions or not directly supported extensions you also\n# need to set EXTENSION_MAPPING for the extension otherwise the files are not\n# read by doxygen.\n#\n# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,\n# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,\n# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,\n# *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C comment),\n# *.doc (to be provided as doxygen C comment), *.txt (to be provided as doxygen\n# C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f, *.for, *.tcl, *.vhd,\n# *.vhdl, *.ucf, *.qsf and *.ice.\n\nFILE_PATTERNS          =\n\n# The RECURSIVE tag can be used to specify whether or not subdirectories should\n# be searched for input files as well.\n# The default value is: NO.\n\nRECURSIVE              = NO\n\n# The EXCLUDE tag can be used to specify files and/or directories that should be\n# excluded from the INPUT source files. This way you can easily exclude a\n# subdirectory from a directory tree whose root is specified with the INPUT tag.\n#\n# Note that relative paths are relative to the directory from which doxygen is\n# run.\n\nEXCLUDE                =\n\n# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or\n# directories that are symbolic links (a Unix file system feature) are excluded\n# from the input.\n# The default value is: NO.\n\nEXCLUDE_SYMLINKS       = NO\n\n# If the value of the INPUT tag contains directories, you can use the\n# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude\n# certain files from those directories.\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories for example use the pattern */test/*\n\nEXCLUDE_PATTERNS       =\n\n# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names\n# (namespaces, classes, functions, etc.) that should be excluded from the\n# output. The symbol name can be a fully qualified name, a word, or if the\n# wildcard * is used, a substring. Examples: ANamespace, AClass,\n# AClass::ANamespace, ANamespace::*Test\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories use the pattern */test/*\n\nEXCLUDE_SYMBOLS        =\n\n# The EXAMPLE_PATH tag can be used to specify one or more files or directories\n# that contain example code fragments that are included (see the \\include\n# command).\n\nEXAMPLE_PATH           =\n\n# If the value of the EXAMPLE_PATH tag contains directories, you can use the\n# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and\n# *.h) to filter out the source-files in the directories. If left blank all\n# files are included.\n\nEXAMPLE_PATTERNS       =\n\n# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be\n# searched for input files to be used with the \\include or \\dontinclude commands\n# irrespective of the value of the RECURSIVE tag.\n# The default value is: NO.\n\nEXAMPLE_RECURSIVE      = NO\n\n# The IMAGE_PATH tag can be used to specify one or more files or directories\n# that contain images that are to be included in the documentation (see the\n# \\image command).\n\nIMAGE_PATH             =\n\n# The INPUT_FILTER tag can be used to specify a program that doxygen should\n# invoke to filter for each input file. Doxygen will invoke the filter program\n# by executing (via popen()) the command:\n#\n# <filter> <input-file>\n#\n# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the\n# name of an input file. Doxygen will then use the output that the filter\n# program writes to standard output. If FILTER_PATTERNS is specified, this tag\n# will be ignored.\n#\n# Note that the filter must not add or remove lines; it is applied before the\n# code is scanned, but not when the output code is generated. If lines are added\n# or removed, the anchors will not be placed correctly.\n#\n# Note that for custom extensions or not directly supported extensions you also\n# need to set EXTENSION_MAPPING for the extension otherwise the files are not\n# properly processed by doxygen.\n\nINPUT_FILTER           =\n\n# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern\n# basis. Doxygen will compare the file name with each pattern and apply the\n# filter if there is a match. The filters are a list of the form: pattern=filter\n# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how\n# filters are used. If the FILTER_PATTERNS tag is empty or if none of the\n# patterns match the file name, INPUT_FILTER is applied.\n#\n# Note that for custom extensions or not directly supported extensions you also\n# need to set EXTENSION_MAPPING for the extension otherwise the files are not\n# properly processed by doxygen.\n\nFILTER_PATTERNS        =\n\n# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using\n# INPUT_FILTER) will also be used to filter the input files that are used for\n# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).\n# The default value is: NO.\n\nFILTER_SOURCE_FILES    = NO\n\n# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file\n# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and\n# it is also possible to disable source filtering for a specific pattern using\n# *.ext= (so without naming a filter).\n# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.\n\nFILTER_SOURCE_PATTERNS =\n\n# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that\n# is part of the input, its contents will be placed on the main page\n# (index.html). This can be useful if you have a project on for instance GitHub\n# and want to reuse the introduction page also for the doxygen output.\n\nUSE_MDFILE_AS_MAINPAGE =\n\n#---------------------------------------------------------------------------\n# Configuration options related to source browsing\n#---------------------------------------------------------------------------\n\n# If the SOURCE_BROWSER tag is set to YES then a list of source files will be\n# generated. Documented entities will be cross-referenced with these sources.\n#\n# Note: To get rid of all source code in the generated output, make sure that\n# also VERBATIM_HEADERS is set to NO.\n# The default value is: NO.\n\nSOURCE_BROWSER         = YES\n\n# Setting the INLINE_SOURCES tag to YES will include the body of functions,\n# classes and enums directly into the documentation.\n# The default value is: NO.\n\nINLINE_SOURCES         = NO\n\n# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any\n# special comment blocks from generated source code fragments. Normal C, C++ and\n# Fortran comments will always remain visible.\n# The default value is: YES.\n\nSTRIP_CODE_COMMENTS    = YES\n\n# If the REFERENCED_BY_RELATION tag is set to YES then for each documented\n# entity all documented functions referencing it will be listed.\n# The default value is: NO.\n\nREFERENCED_BY_RELATION = YES\n\n# If the REFERENCES_RELATION tag is set to YES then for each documented function\n# all documented entities called/used by that function will be listed.\n# The default value is: NO.\n\nREFERENCES_RELATION    = YES\n\n# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set\n# to YES then the hyperlinks from functions in REFERENCES_RELATION and\n# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will\n# link to the documentation.\n# The default value is: YES.\n\nREFERENCES_LINK_SOURCE = YES\n\n# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the\n# source code will show a tooltip with additional information such as prototype,\n# brief description and links to the definition and documentation. Since this\n# will make the HTML file larger and loading of large files a bit slower, you\n# can opt to disable this feature.\n# The default value is: YES.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nSOURCE_TOOLTIPS        = YES\n\n# If the USE_HTAGS tag is set to YES then the references to source code will\n# point to the HTML generated by the htags(1) tool instead of doxygen built-in\n# source browser. The htags tool is part of GNU's global source tagging system\n# (see https://www.gnu.org/software/global/global.html). You will need version\n# 4.8.6 or higher.\n#\n# To use it do the following:\n# - Install the latest version of global\n# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file\n# - Make sure the INPUT points to the root of the source tree\n# - Run doxygen as normal\n#\n# Doxygen will invoke htags (and that will in turn invoke gtags), so these\n# tools must be available from the command line (i.e. in the search path).\n#\n# The result: instead of the source browser generated by doxygen, the links to\n# source code will now point to the output of htags.\n# The default value is: NO.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nUSE_HTAGS              = NO\n\n# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a\n# verbatim copy of the header file for each class for which an include is\n# specified. Set to NO to disable this.\n# See also: Section \\class.\n# The default value is: YES.\n\nVERBATIM_HEADERS       = YES\n\n# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the\n# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the\n# cost of reduced performance. This can be particularly helpful with template\n# rich C++ code for which doxygen's built-in parser lacks the necessary type\n# information.\n# Note: The availability of this option depends on whether or not doxygen was\n# generated with the -Duse_libclang=ON option for CMake.\n# The default value is: NO.\n\nCLANG_ASSISTED_PARSING = NO\n\n# If clang assisted parsing is enabled you can provide the compiler with command\n# line options that you would normally use when invoking the compiler. Note that\n# the include paths will already be set by doxygen for the files and directories\n# specified with INPUT and INCLUDE_PATH.\n# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.\n\nCLANG_OPTIONS          =\n\n# If clang assisted parsing is enabled you can provide the clang parser with the\n# path to the compilation database (see:\n# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) used when the files\n# were built. This is equivalent to specifying the \"-p\" option to a clang tool,\n# such as clang-check. These options will then be passed to the parser.\n# Note: The availability of this option depends on whether or not doxygen was\n# generated with the -Duse_libclang=ON option for CMake.\n\nCLANG_DATABASE_PATH    =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the alphabetical class index\n#---------------------------------------------------------------------------\n\n# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all\n# compounds will be generated. Enable this if the project contains a lot of\n# classes, structs, unions or interfaces.\n# The default value is: YES.\n\nALPHABETICAL_INDEX     = YES\n\n# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in\n# which the alphabetical index list will be split.\n# Minimum value: 1, maximum value: 20, default value: 5.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nCOLS_IN_ALPHA_INDEX    = 5\n\n# In case all classes in a project start with a common prefix, all classes will\n# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag\n# can be used to specify a prefix (or a list of prefixes) that should be ignored\n# while generating the index headers.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nIGNORE_PREFIX          =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the HTML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output\n# The default value is: YES.\n\nGENERATE_HTML          = YES\n\n# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_OUTPUT            = html\n\n# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each\n# generated HTML page (for example: .htm, .php, .asp).\n# The default value is: .html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FILE_EXTENSION    = .html\n\n# The HTML_HEADER tag can be used to specify a user-defined HTML header file for\n# each generated HTML page. If the tag is left blank doxygen will generate a\n# standard header.\n#\n# To get valid HTML the header file that includes any scripts and style sheets\n# that doxygen needs, which is dependent on the configuration options used (e.g.\n# the setting GENERATE_TREEVIEW). It is highly recommended to start with a\n# default header using\n# doxygen -w html new_header.html new_footer.html new_stylesheet.css\n# YourConfigFile\n# and then modify the file new_header.html. See also section \"Doxygen usage\"\n# for information on how to generate the default header that doxygen normally\n# uses.\n# Note: The header is subject to change so you typically have to regenerate the\n# default header when upgrading to a newer version of doxygen. For a description\n# of the possible markers and block names see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_HEADER            =\n\n# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each\n# generated HTML page. If the tag is left blank doxygen will generate a standard\n# footer. See HTML_HEADER for more information on how to generate a default\n# footer and what special commands can be used inside the footer. See also\n# section \"Doxygen usage\" for information on how to generate the default footer\n# that doxygen normally uses.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FOOTER            =\n\n# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style\n# sheet that is used by each HTML page. It can be used to fine-tune the look of\n# the HTML output. If left blank doxygen will generate a default style sheet.\n# See also section \"Doxygen usage\" for information on how to generate the style\n# sheet that doxygen normally uses.\n# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as\n# it is more robust and this tag (HTML_STYLESHEET) will in the future become\n# obsolete.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_STYLESHEET        =\n\n# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined\n# cascading style sheets that are included after the standard style sheets\n# created by doxygen. Using this option one can overrule certain style aspects.\n# This is preferred over using HTML_STYLESHEET since it does not replace the\n# standard style sheet and is therefore more robust against future updates.\n# Doxygen will copy the style sheet files to the output directory.\n# Note: The order of the extra style sheet files is of importance (e.g. the last\n# style sheet in the list overrules the setting of the previous ones in the\n# list). For an example see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_STYLESHEET  =\n\n# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the HTML output directory. Note\n# that these files will be copied to the base HTML output directory. Use the\n# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these\n# files. In the HTML_STYLESHEET file, use the file name only. Also note that the\n# files will be copied as-is; there are no commands or markers available.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_FILES       =\n\n# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen\n# will adjust the colors in the style sheet and background images according to\n# this color. Hue is specified as an angle on a colorwheel, see\n# https://en.wikipedia.org/wiki/Hue for more information. For instance the value\n# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300\n# purple, and 360 is red again.\n# Minimum value: 0, maximum value: 359, default value: 220.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_HUE    = 220\n\n# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors\n# in the HTML output. For a value of 0 the output will use grayscales only. A\n# value of 255 will produce the most vivid colors.\n# Minimum value: 0, maximum value: 255, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_SAT    = 100\n\n# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the\n# luminance component of the colors in the HTML output. Values below 100\n# gradually make the output lighter, whereas values above 100 make the output\n# darker. The value divided by 100 is the actual gamma applied, so 80 represents\n# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not\n# change the gamma.\n# Minimum value: 40, maximum value: 240, default value: 80.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_GAMMA  = 80\n\n# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML\n# page will contain the date and time when the page was generated. Setting this\n# to YES can help to show when doxygen was last run and thus if the\n# documentation is up to date.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_TIMESTAMP         = NO\n\n# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML\n# documentation will contain a main index with vertical navigation menus that\n# are dynamically created via JavaScript. If disabled, the navigation index will\n# consists of multiple levels of tabs that are statically embedded in every HTML\n# page. Disable this option to support browsers that do not have JavaScript,\n# like the Qt help browser.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_DYNAMIC_MENUS     = YES\n\n# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML\n# documentation will contain sections that can be hidden and shown after the\n# page has loaded.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_DYNAMIC_SECTIONS  = NO\n\n# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries\n# shown in the various tree structured indices initially; the user can expand\n# and collapse entries dynamically later on. Doxygen will expand the tree to\n# such a level that at most the specified number of entries are visible (unless\n# a fully collapsed tree already exceeds this amount). So setting the number of\n# entries 1 will produce a full collapsed tree by default. 0 is a special value\n# representing an infinite number of entries and will result in a full expanded\n# tree by default.\n# Minimum value: 0, maximum value: 9999, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_INDEX_NUM_ENTRIES = 100\n\n# If the GENERATE_DOCSET tag is set to YES, additional index files will be\n# generated that can be used as input for Apple's Xcode 3 integrated development\n# environment (see: https://developer.apple.com/xcode/), introduced with OSX\n# 10.5 (Leopard). To create a documentation set, doxygen will generate a\n# Makefile in the HTML output directory. Running make will produce the docset in\n# that directory and running make install will install the docset in\n# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at\n# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy\n# genXcode/_index.html for more information.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_DOCSET        = NO\n\n# This tag determines the name of the docset feed. A documentation feed provides\n# an umbrella under which multiple documentation sets from a single provider\n# (such as a company or product suite) can be grouped.\n# The default value is: Doxygen generated docs.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_FEEDNAME        = \"Doxygen generated docs\"\n\n# This tag specifies a string that should uniquely identify the documentation\n# set bundle. This should be a reverse domain-name style string, e.g.\n# com.mycompany.MyDocSet. Doxygen will append .docset to the name.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_BUNDLE_ID       = org.doxygen.Project\n\n# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify\n# the documentation publisher. This should be a reverse domain-name style\n# string, e.g. com.mycompany.MyDocSet.documentation.\n# The default value is: org.doxygen.Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_ID    = org.doxygen.Publisher\n\n# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.\n# The default value is: Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_NAME  = Publisher\n\n# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three\n# additional HTML index files: index.hhp, index.hhc, and index.hhk. The\n# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop\n# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on\n# Windows.\n#\n# The HTML Help Workshop contains a compiler that can convert all HTML output\n# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML\n# files are now used as the Windows 98 help format, and will replace the old\n# Windows help format (.hlp) on all Windows platforms in the future. Compressed\n# HTML files also contain an index, a table of contents, and you can search for\n# words in the documentation. The HTML workshop also contains a viewer for\n# compressed HTML files.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_HTMLHELP      = NO\n\n# The CHM_FILE tag can be used to specify the file name of the resulting .chm\n# file. You can add a path in front of the file if the result should not be\n# written to the html output directory.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_FILE               =\n\n# The HHC_LOCATION tag can be used to specify the location (absolute path\n# including file name) of the HTML help compiler (hhc.exe). If non-empty,\n# doxygen will try to run the HTML help compiler on the generated index.hhp.\n# The file has to be specified with full path.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nHHC_LOCATION           =\n\n# The GENERATE_CHI flag controls if a separate .chi index file is generated\n# (YES) or that it should be included in the master .chm file (NO).\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nGENERATE_CHI           = NO\n\n# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)\n# and project file content.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_INDEX_ENCODING     =\n\n# The BINARY_TOC flag controls whether a binary table of contents is generated\n# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it\n# enables the Previous and Next buttons.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nBINARY_TOC             = NO\n\n# The TOC_EXPAND flag can be set to YES to add extra items for group members to\n# the table of contents of the HTML help documentation and to the tree view.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nTOC_EXPAND             = NO\n\n# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and\n# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that\n# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help\n# (.qch) of the generated HTML documentation.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_QHP           = NO\n\n# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify\n# the file name of the resulting .qch file. The path specified is relative to\n# the HTML output folder.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQCH_FILE               =\n\n# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help\n# Project output. For more information please see Qt Help Project / Namespace\n# (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_NAMESPACE          = org.doxygen.Project\n\n# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt\n# Help Project output. For more information please see Qt Help Project / Virtual\n# Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-\n# folders).\n# The default value is: doc.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_VIRTUAL_FOLDER     = doc\n\n# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom\n# filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_NAME   =\n\n# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the\n# custom filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_ATTRS  =\n\n# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this\n# project's filter section matches. Qt Help Project / Filter Attributes (see:\n# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_SECT_FILTER_ATTRS  =\n\n# The QHG_LOCATION tag can be used to specify the location of Qt's\n# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the\n# generated .qhp file.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHG_LOCATION           =\n\n# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be\n# generated, together with the HTML files, they form an Eclipse help plugin. To\n# install this plugin and make it available under the help contents menu in\n# Eclipse, the contents of the directory containing the HTML and XML files needs\n# to be copied into the plugins directory of eclipse. The name of the directory\n# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.\n# After copying Eclipse needs to be restarted before the help appears.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_ECLIPSEHELP   = NO\n\n# A unique identifier for the Eclipse help plugin. When installing the plugin\n# the directory name containing the HTML and XML files should also have this\n# name. Each documentation set should have its own identifier.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.\n\nECLIPSE_DOC_ID         = org.doxygen.Project\n\n# If you want full control over the layout of the generated HTML pages it might\n# be necessary to disable the index and replace it with your own. The\n# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top\n# of each HTML page. A value of NO enables the index and the value YES disables\n# it. Since the tabs in the index contain the same information as the navigation\n# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nDISABLE_INDEX          = NO\n\n# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index\n# structure should be generated to display hierarchical information. If the tag\n# value is set to YES, a side panel will be generated containing a tree-like\n# index structure (just like the one that is generated for HTML Help). For this\n# to work a browser that supports JavaScript, DHTML, CSS and frames is required\n# (i.e. any modern browser). Windows users are probably better off using the\n# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can\n# further fine-tune the look of the index. As an example, the default style\n# sheet generated by doxygen has an example that shows how to put an image at\n# the root of the tree instead of the PROJECT_NAME. Since the tree basically has\n# the same information as the tab index, you could consider setting\n# DISABLE_INDEX to YES when enabling this option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_TREEVIEW      = NO\n\n# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that\n# doxygen will group on one line in the generated HTML documentation.\n#\n# Note that a value of 0 will completely suppress the enum values from appearing\n# in the overview section.\n# Minimum value: 0, maximum value: 20, default value: 4.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nENUM_VALUES_PER_LINE   = 4\n\n# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used\n# to set the initial width (in pixels) of the frame in which the tree is shown.\n# Minimum value: 0, maximum value: 1500, default value: 250.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nTREEVIEW_WIDTH         = 250\n\n# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to\n# external symbols imported via tag files in a separate window.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nEXT_LINKS_IN_WINDOW    = NO\n\n# Use this tag to change the font size of LaTeX formulas included as images in\n# the HTML documentation. When you change the font size after a successful\n# doxygen run you need to manually remove any form_*.png images from the HTML\n# output directory to force them to be regenerated.\n# Minimum value: 8, maximum value: 50, default value: 10.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_FONTSIZE       = 10\n\n# Use the FORMULA_TRANSPARENT tag to determine whether or not the images\n# generated for formulas are transparent PNGs. Transparent PNGs are not\n# supported properly for IE 6.0, but are supported on all modern browsers.\n#\n# Note that when changing this option you need to delete any form_*.png files in\n# the HTML output directory before the changes have effect.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_TRANSPARENT    = YES\n\n# The FORMULA_MACROFILE can contain LaTeX \\newcommand and \\renewcommand commands\n# to create new LaTeX commands to be used in formulas as building blocks. See\n# the section \"Including formulas\" for details.\n\nFORMULA_MACROFILE      =\n\n# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see\n# https://www.mathjax.org) which uses client side JavaScript for the rendering\n# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX\n# installed or if you want to formulas look prettier in the HTML output. When\n# enabled you may also need to install MathJax separately and configure the path\n# to it using the MATHJAX_RELPATH option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nUSE_MATHJAX            = NO\n\n# When MathJax is enabled you can set the default output format to be used for\n# the MathJax output. See the MathJax site (see:\n# http://docs.mathjax.org/en/latest/output.html) for more details.\n# Possible values are: HTML-CSS (which is slower, but has the best\n# compatibility), NativeMML (i.e. MathML) and SVG.\n# The default value is: HTML-CSS.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_FORMAT         = HTML-CSS\n\n# When MathJax is enabled you need to specify the location relative to the HTML\n# output directory using the MATHJAX_RELPATH option. The destination directory\n# should contain the MathJax.js script. For instance, if the mathjax directory\n# is located at the same level as the HTML output directory, then\n# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax\n# Content Delivery Network so you can quickly see the result without installing\n# MathJax. However, it is strongly recommended to install a local copy of\n# MathJax from https://www.mathjax.org before deployment.\n# The default value is: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_RELPATH        = https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/\n\n# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax\n# extension names that should be enabled during MathJax rendering. For example\n# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_EXTENSIONS     =\n\n# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces\n# of code that will be used on startup of the MathJax code. See the MathJax site\n# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an\n# example see the documentation.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_CODEFILE       =\n\n# When the SEARCHENGINE tag is enabled doxygen will generate a search box for\n# the HTML output. The underlying search engine uses javascript and DHTML and\n# should work on any modern browser. Note that when using HTML help\n# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)\n# there is already a search function so this one should typically be disabled.\n# For large projects the javascript based search engine can be slow, then\n# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to\n# search using the keyboard; to jump to the search box use <access key> + S\n# (what the <access key> is depends on the OS and browser, but it is typically\n# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down\n# key> to jump into the search results window, the results can be navigated\n# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel\n# the search. The filter options can be selected when the cursor is inside the\n# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>\n# to select a filter and <Enter> or <escape> to activate or cancel the filter\n# option.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nSEARCHENGINE           = NO\n\n# When the SERVER_BASED_SEARCH tag is enabled the search engine will be\n# implemented using a web server instead of a web client using JavaScript. There\n# are two flavors of web server based searching depending on the EXTERNAL_SEARCH\n# setting. When disabled, doxygen will generate a PHP script for searching and\n# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing\n# and searching needs to be provided by external tools. See the section\n# \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSERVER_BASED_SEARCH    = NO\n\n# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP\n# script for searching. Instead the search results are written to an XML file\n# which needs to be processed by an external indexer. Doxygen will invoke an\n# external search engine pointed to by the SEARCHENGINE_URL option to obtain the\n# search results.\n#\n# Doxygen ships with an example indexer (doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: https://xapian.org/).\n#\n# See the section \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH        = NO\n\n# The SEARCHENGINE_URL should point to a search engine hosted by a web server\n# which will return the search results when EXTERNAL_SEARCH is enabled.\n#\n# Doxygen ships with an example indexer (doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: https://xapian.org/). See the section \"External Indexing and\n# Searching\" for details.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHENGINE_URL       =\n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed\n# search data is written to a file for indexing by an external tool. With the\n# SEARCHDATA_FILE tag the name of this file can be specified.\n# The default file is: searchdata.xml.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHDATA_FILE        = searchdata.xml\n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the\n# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is\n# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple\n# projects and redirect the results back to the right project.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH_ID     =\n\n# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen\n# projects other than the one defined by this configuration file, but that are\n# all added to the same external search index. Each project needs to have a\n# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of\n# to a relative location where the documentation can be found. The format is:\n# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTRA_SEARCH_MAPPINGS  =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the LaTeX output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.\n# The default value is: YES.\n\nGENERATE_LATEX         = NO\n\n# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: latex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_OUTPUT           = latex\n\n# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be\n# invoked.\n#\n# Note that when not enabling USE_PDFLATEX the default is latex when enabling\n# USE_PDFLATEX the default is pdflatex and when in the later case latex is\n# chosen this is overwritten by pdflatex. For specific output languages the\n# default can have been set differently, this depends on the implementation of\n# the output language.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_CMD_NAME         = latex\n\n# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate\n# index for LaTeX.\n# Note: This tag is used in the Makefile / make.bat.\n# See also: LATEX_MAKEINDEX_CMD for the part in the generated output file\n# (.tex).\n# The default file is: makeindex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nMAKEINDEX_CMD_NAME     = makeindex\n\n# The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to\n# generate index for LaTeX. In case there is no backslash (\\) as first character\n# it will be automatically added in the LaTeX code.\n# Note: This tag is used in the generated output file (.tex).\n# See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat.\n# The default value is: makeindex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_MAKEINDEX_CMD    = makeindex\n\n# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nCOMPACT_LATEX          = NO\n\n# The PAPER_TYPE tag can be used to set the paper type that is used by the\n# printer.\n# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x\n# 14 inches) and executive (7.25 x 10.5 inches).\n# The default value is: a4.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPAPER_TYPE             = a4wide\n\n# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names\n# that should be included in the LaTeX output. The package can be specified just\n# by its name or with the correct syntax as to be used with the LaTeX\n# \\usepackage command. To get the times font for instance you can specify :\n# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}\n# To use the option intlimits with the amsmath package you can specify:\n# EXTRA_PACKAGES=[intlimits]{amsmath}\n# If left blank no extra packages will be included.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nEXTRA_PACKAGES         =\n\n# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the\n# generated LaTeX document. The header should contain everything until the first\n# chapter. If it is left blank doxygen will generate a standard header. See\n# section \"Doxygen usage\" for information on how to let doxygen write the\n# default header to a separate file.\n#\n# Note: Only use a user-defined header if you know what you are doing! The\n# following commands have a special meaning inside the header: $title,\n# $datetime, $date, $doxygenversion, $projectname, $projectnumber,\n# $projectbrief, $projectlogo. Doxygen will replace $title with the empty\n# string, for the replacement values of the other commands the user is referred\n# to HTML_HEADER.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HEADER           =\n\n# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the\n# generated LaTeX document. The footer should contain everything after the last\n# chapter. If it is left blank doxygen will generate a standard footer. See\n# LATEX_HEADER for more information on how to generate a default footer and what\n# special commands can be used inside the footer.\n#\n# Note: Only use a user-defined footer if you know what you are doing!\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_FOOTER           =\n\n# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined\n# LaTeX style sheets that are included after the standard style sheets created\n# by doxygen. Using this option one can overrule certain style aspects. Doxygen\n# will copy the style sheet files to the output directory.\n# Note: The order of the extra style sheet files is of importance (e.g. the last\n# style sheet in the list overrules the setting of the previous ones in the\n# list).\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EXTRA_STYLESHEET =\n\n# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the LATEX_OUTPUT output\n# directory. Note that the files will be copied as-is; there are no commands or\n# markers available.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EXTRA_FILES      =\n\n# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is\n# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will\n# contain links (just like the HTML output) instead of page references. This\n# makes the output suitable for online browsing using a PDF viewer.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPDF_HYPERLINKS         = NO\n\n# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate\n# the PDF file directly from the LaTeX files. Set this option to YES, to get a\n# higher quality PDF documentation.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nUSE_PDFLATEX           = NO\n\n# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode\n# command to the generated LaTeX files. This will instruct LaTeX to keep running\n# if errors occur, instead of asking the user for help. This option is also used\n# when generating formulas in HTML.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BATCHMODE        = NO\n\n# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the\n# index chapters (such as File Index, Compound Index, etc.) in the output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HIDE_INDICES     = NO\n\n# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source\n# code with syntax highlighting in the LaTeX output.\n#\n# Note that which sources are shown also depends on other settings such as\n# SOURCE_BROWSER.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_SOURCE_CODE      = NO\n\n# The LATEX_BIB_STYLE tag can be used to specify the style to use for the\n# bibliography, e.g. plainnat, or ieeetr. See\n# https://en.wikipedia.org/wiki/BibTeX and \\cite for more info.\n# The default value is: plain.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BIB_STYLE        = plain\n\n# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated\n# page will contain the date and time when the page was generated. Setting this\n# to NO can help when comparing the output of multiple runs.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_TIMESTAMP        = NO\n\n# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute)\n# path from which the emoji images will be read. If a relative path is entered,\n# it will be relative to the LATEX_OUTPUT directory. If left blank the\n# LATEX_OUTPUT directory will be used.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EMOJI_DIRECTORY  =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the RTF output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The\n# RTF output is optimized for Word 97 and may not look too pretty with other RTF\n# readers/editors.\n# The default value is: NO.\n\nGENERATE_RTF           = NO\n\n# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: rtf.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_OUTPUT             = rtf\n\n# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nCOMPACT_RTF            = NO\n\n# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will\n# contain hyperlink fields. The RTF file will contain links (just like the HTML\n# output) instead of page references. This makes the output suitable for online\n# browsing using Word or some other Word compatible readers that support those\n# fields.\n#\n# Note: WordPad (write) and others do not support links.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_HYPERLINKS         = NO\n\n# Load stylesheet definitions from file. Syntax is similar to doxygen's\n# configuration file, i.e. a series of assignments. You only have to provide\n# replacements, missing definitions are set to their default value.\n#\n# See also section \"Doxygen usage\" for information on how to generate the\n# default style sheet that doxygen normally uses.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_STYLESHEET_FILE    =\n\n# Set optional variables used in the generation of an RTF document. Syntax is\n# similar to doxygen's configuration file. A template extensions file can be\n# generated using doxygen -e rtf extensionFile.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_EXTENSIONS_FILE    =\n\n# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code\n# with syntax highlighting in the RTF output.\n#\n# Note that which sources are shown also depends on other settings such as\n# SOURCE_BROWSER.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_SOURCE_CODE        = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the man page output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for\n# classes and files.\n# The default value is: NO.\n\nGENERATE_MAN           = NO\n\n# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it. A directory man3 will be created inside the directory specified by\n# MAN_OUTPUT.\n# The default directory is: man.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_OUTPUT             = man\n\n# The MAN_EXTENSION tag determines the extension that is added to the generated\n# man pages. In case the manual section does not start with a number, the number\n# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is\n# optional.\n# The default value is: .3.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_EXTENSION          = .3\n\n# The MAN_SUBDIR tag determines the name of the directory created within\n# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by\n# MAN_EXTENSION with the initial . removed.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_SUBDIR             =\n\n# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it\n# will generate one additional man file for each entity documented in the real\n# man page(s). These additional files only source the real man page, but without\n# them the man command would be unable to find the correct page.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_LINKS              = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the XML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that\n# captures the structure of the code including all documentation.\n# The default value is: NO.\n\nGENERATE_XML           = NO\n\n# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: xml.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_OUTPUT             = xml\n\n# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program\n# listings (including syntax highlighting and cross-referencing information) to\n# the XML output. Note that enabling this will significantly increase the size\n# of the XML output.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_PROGRAMLISTING     = YES\n\n# If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include\n# namespace members in file scope as well, matching the HTML output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_NS_MEMB_FILE_SCOPE = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the DOCBOOK output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files\n# that can be used to generate PDF.\n# The default value is: NO.\n\nGENERATE_DOCBOOK       = NO\n\n# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.\n# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in\n# front of it.\n# The default directory is: docbook.\n# This tag requires that the tag GENERATE_DOCBOOK is set to YES.\n\nDOCBOOK_OUTPUT         = docbook\n\n# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the\n# program listings (including syntax highlighting and cross-referencing\n# information) to the DOCBOOK output. Note that enabling this will significantly\n# increase the size of the DOCBOOK output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_DOCBOOK is set to YES.\n\nDOCBOOK_PROGRAMLISTING = NO\n\n#---------------------------------------------------------------------------\n# Configuration options for the AutoGen Definitions output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an\n# AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures\n# the structure of the code including all documentation. Note that this feature\n# is still experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_AUTOGEN_DEF   = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the Perl module output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module\n# file that captures the structure of the code including all documentation.\n#\n# Note that this feature is still experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_PERLMOD       = NO\n\n# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary\n# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI\n# output from the Perl module output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_LATEX          = NO\n\n# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely\n# formatted so it can be parsed by a human reader. This is useful if you want to\n# understand what is going on. On the other hand, if this tag is set to NO, the\n# size of the Perl module output will be much smaller and Perl will parse it\n# just the same.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_PRETTY         = YES\n\n# The names of the make variables in the generated doxyrules.make file are\n# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful\n# so different doxyrules.make files included by the same Makefile don't\n# overwrite each other's variables.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_MAKEVAR_PREFIX =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the preprocessor\n#---------------------------------------------------------------------------\n\n# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all\n# C-preprocessor directives found in the sources and include files.\n# The default value is: YES.\n\nENABLE_PREPROCESSING   = YES\n\n# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names\n# in the source code. If set to NO, only conditional compilation will be\n# performed. Macro expansion can be done in a controlled way by setting\n# EXPAND_ONLY_PREDEF to YES.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nMACRO_EXPANSION        = YES\n\n# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then\n# the macro expansion is limited to the macros specified with the PREDEFINED and\n# EXPAND_AS_DEFINED tags.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_ONLY_PREDEF     = NO\n\n# If the SEARCH_INCLUDES tag is set to YES, the include files in the\n# INCLUDE_PATH will be searched if a #include is found.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSEARCH_INCLUDES        = YES\n\n# The INCLUDE_PATH tag can be used to specify one or more directories that\n# contain include files that are not input files but should be processed by the\n# preprocessor.\n# This tag requires that the tag SEARCH_INCLUDES is set to YES.\n\nINCLUDE_PATH           = ../common ..\n\n# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard\n# patterns (like *.h and *.hpp) to filter out the header-files in the\n# directories. If left blank, the patterns specified with FILE_PATTERNS will be\n# used.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nINCLUDE_FILE_PATTERNS  =\n\n# The PREDEFINED tag can be used to specify one or more macro names that are\n# defined before the preprocessor is started (similar to the -D option of e.g.\n# gcc). The argument of the tag is a list of macros of the form: name or\n# name=definition (no spaces). If the definition and the \"=\" are omitted, \"=1\"\n# is assumed. To prevent a macro definition from being undefined via #undef or\n# recursively expanded use the := operator instead of the = operator.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nPREDEFINED             = DOXYGEN\n\n# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this\n# tag can be used to specify a list of macro names that should be expanded. The\n# macro definition that is found in the sources will be used. Use the PREDEFINED\n# tag if you want to use a different macro definition that overrules the\n# definition found in the source code.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_AS_DEFINED      =\n\n# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will\n# remove all references to function-like macros that are alone on a line, have\n# an all uppercase name, and do not end with a semicolon. Such function macros\n# are typically used for boiler-plate code, and will confuse the parser if not\n# removed.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSKIP_FUNCTION_MACROS   = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to external references\n#---------------------------------------------------------------------------\n\n# The TAGFILES tag can be used to specify one or more tag files. For each tag\n# file the location of the external documentation should be added. The format of\n# a tag file without this location is as follows:\n# TAGFILES = file1 file2 ...\n# Adding location for the tag files is done as follows:\n# TAGFILES = file1=loc1 \"file2 = loc2\" ...\n# where loc1 and loc2 can be relative or absolute paths or URLs. See the\n# section \"Linking to external documentation\" for more information about the use\n# of tag files.\n# Note: Each tag file must have a unique name (where the name does NOT include\n# the path). If a tag file is not located in the directory in which doxygen is\n# run, you must also specify the path to the tagfile here.\n\nTAGFILES               =\n\n# When a file name is specified after GENERATE_TAGFILE, doxygen will create a\n# tag file that is based on the input files it reads. See section \"Linking to\n# external documentation\" for more information about the usage of tag files.\n\nGENERATE_TAGFILE       =\n\n# If the ALLEXTERNALS tag is set to YES, all external class will be listed in\n# the class index. If set to NO, only the inherited external classes will be\n# listed.\n# The default value is: NO.\n\nALLEXTERNALS           = NO\n\n# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed\n# in the modules index. If set to NO, only the current project's groups will be\n# listed.\n# The default value is: YES.\n\nEXTERNAL_GROUPS        = YES\n\n# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in\n# the related pages index. If set to NO, only the current project's pages will\n# be listed.\n# The default value is: YES.\n\nEXTERNAL_PAGES         = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to the dot tool\n#---------------------------------------------------------------------------\n\n# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram\n# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to\n# NO turns the diagrams off. Note that this option also works with HAVE_DOT\n# disabled, but it is recommended to install and use dot, since it yields more\n# powerful graphs.\n# The default value is: YES.\n\nCLASS_DIAGRAMS         = NO\n\n# You can include diagrams made with dia in doxygen documentation. Doxygen will\n# then run dia to produce the diagram and insert it in the documentation. The\n# DIA_PATH tag allows you to specify the directory where the dia binary resides.\n# If left empty dia is assumed to be found in the default search path.\n\nDIA_PATH               =\n\n# If set to YES the inheritance and collaboration graphs will hide inheritance\n# and usage relations if the target is undocumented or is not a class.\n# The default value is: YES.\n\nHIDE_UNDOC_RELATIONS   = YES\n\n# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is\n# available from the path. This tool is part of Graphviz (see:\n# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent\n# Bell Labs. The other options in this section have no effect if this option is\n# set to NO\n# The default value is: YES.\n\nHAVE_DOT               = NO\n\n# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed\n# to run in parallel. When set to 0 doxygen will base this on the number of\n# processors available in the system. You can set it explicitly to a value\n# larger than 0 to get control over the balance between CPU load and processing\n# speed.\n# Minimum value: 0, maximum value: 32, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_NUM_THREADS        = 0\n\n# When you want a differently looking font in the dot files that doxygen\n# generates you can specify the font name using DOT_FONTNAME. You need to make\n# sure dot is able to find the font, which can be done by putting it in a\n# standard location or by setting the DOTFONTPATH environment variable or by\n# setting DOT_FONTPATH to the directory containing the font.\n# The default value is: Helvetica.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTNAME           = Helvetica\n\n# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of\n# dot graphs.\n# Minimum value: 4, maximum value: 24, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTSIZE           = 10\n\n# By default doxygen will tell dot to use the default font as specified with\n# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set\n# the path where dot can find it using this tag.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTPATH           =\n\n# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for\n# each documented class showing the direct and indirect inheritance relations.\n# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCLASS_GRAPH            = YES\n\n# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a\n# graph for each documented class showing the direct and indirect implementation\n# dependencies (inheritance, containment, and class references variables) of the\n# class with other documented classes.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCOLLABORATION_GRAPH    = YES\n\n# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for\n# groups, showing the direct groups dependencies.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGROUP_GRAPHS           = YES\n\n# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and\n# collaboration diagrams in a style similar to the OMG's Unified Modeling\n# Language.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LOOK               = NO\n\n# If the UML_LOOK tag is enabled, the fields and methods are shown inside the\n# class node. If there are many fields or methods and many nodes the graph may\n# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the\n# number of items for each type to make the size more manageable. Set this to 0\n# for no limit. Note that the threshold may be exceeded by 50% before the limit\n# is enforced. So when you set the threshold to 10, up to 15 fields may appear,\n# but if the number exceeds 15, the total amount of fields shown is limited to\n# 10.\n# Minimum value: 0, maximum value: 100, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LIMIT_NUM_FIELDS   = 10\n\n# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and\n# collaboration graphs will show the relations between templates and their\n# instances.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nTEMPLATE_RELATIONS     = NO\n\n# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to\n# YES then doxygen will generate a graph for each documented file showing the\n# direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDE_GRAPH          = YES\n\n# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are\n# set to YES then doxygen will generate a graph for each documented file showing\n# the direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDED_BY_GRAPH      = YES\n\n# If the CALL_GRAPH tag is set to YES then doxygen will generate a call\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable call graphs for selected\n# functions only using the \\callgraph command. Disabling a call graph can be\n# accomplished by means of the command \\hidecallgraph.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALL_GRAPH             = NO\n\n# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable caller graphs for selected\n# functions only using the \\callergraph command. Disabling a caller graph can be\n# accomplished by means of the command \\hidecallergraph.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALLER_GRAPH           = NO\n\n# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical\n# hierarchy of all classes instead of a textual one.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGRAPHICAL_HIERARCHY    = YES\n\n# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the\n# dependencies a directory has on other directories in a graphical way. The\n# dependency relations are determined by the #include relations between the\n# files in the directories.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDIRECTORY_GRAPH        = YES\n\n# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images\n# generated by dot. For an explanation of the image formats see the section\n# output formats in the documentation of the dot tool (Graphviz (see:\n# http://www.graphviz.org/)).\n# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order\n# to make the SVG files visible in IE 9+ (other browsers do not have this\n# requirement).\n# Possible values are: png, png:cairo, png:cairo:cairo, png:cairo:gd, png:gd,\n# png:gd:gd, jpg, jpg:cairo, jpg:cairo:gd, jpg:gd, jpg:gd:gd, gif, gif:cairo,\n# gif:cairo:gd, gif:gd, gif:gd:gd, svg, png:gd, png:gd:gd, png:cairo,\n# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and\n# png:gdiplus:gdiplus.\n# The default value is: png.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_IMAGE_FORMAT       = png\n\n# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to\n# enable generation of interactive SVG images that allow zooming and panning.\n#\n# Note that this requires a modern browser other than Internet Explorer. Tested\n# and working are Firefox, Chrome, Safari, and Opera.\n# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make\n# the SVG files visible. Older versions of IE do not have SVG support.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINTERACTIVE_SVG        = NO\n\n# The DOT_PATH tag can be used to specify the path where the dot tool can be\n# found. If left blank, it is assumed the dot tool can be found in the path.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_PATH               =\n\n# The DOTFILE_DIRS tag can be used to specify one or more directories that\n# contain dot files that are included in the documentation (see the \\dotfile\n# command).\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOTFILE_DIRS           =\n\n# The MSCFILE_DIRS tag can be used to specify one or more directories that\n# contain msc files that are included in the documentation (see the \\mscfile\n# command).\n\nMSCFILE_DIRS           =\n\n# The DIAFILE_DIRS tag can be used to specify one or more directories that\n# contain dia files that are included in the documentation (see the \\diafile\n# command).\n\nDIAFILE_DIRS           =\n\n# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the\n# path where java can find the plantuml.jar file. If left blank, it is assumed\n# PlantUML is not used or called during a preprocessing step. Doxygen will\n# generate a warning when it encounters a \\startuml command in this case and\n# will not generate output for the diagram.\n\nPLANTUML_JAR_PATH      =\n\n# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a\n# configuration file for plantuml.\n\nPLANTUML_CFG_FILE      =\n\n# When using plantuml, the specified paths are searched for files specified by\n# the !include statement in a plantuml block.\n\nPLANTUML_INCLUDE_PATH  =\n\n# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes\n# that will be shown in the graph. If the number of nodes in a graph becomes\n# larger than this value, doxygen will truncate the graph, which is visualized\n# by representing a node as a red box. Note that doxygen if the number of direct\n# children of the root node in a graph is already larger than\n# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that\n# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.\n# Minimum value: 0, maximum value: 10000, default value: 50.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_GRAPH_MAX_NODES    = 50\n\n# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs\n# generated by dot. A depth value of 3 means that only nodes reachable from the\n# root by following a path via at most 3 edges will be shown. Nodes that lay\n# further from the root node will be omitted. Note that setting this option to 1\n# or 2 may greatly reduce the computation time needed for large code bases. Also\n# note that the size of a graph can be further restricted by\n# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.\n# Minimum value: 0, maximum value: 1000, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nMAX_DOT_GRAPH_DEPTH    = 0\n\n# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent\n# background. This is disabled by default, because dot on Windows does not seem\n# to support this out of the box.\n#\n# Warning: Depending on the platform used, enabling this option may lead to\n# badly anti-aliased labels on the edges of a graph (i.e. they become hard to\n# read).\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_TRANSPARENT        = NO\n\n# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output\n# files in one run (i.e. multiple -o and -T options on the command line). This\n# makes dot run faster, but since only newer versions of dot (>1.8.10) support\n# this, this feature is disabled by default.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_MULTI_TARGETS      = NO\n\n# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page\n# explaining the meaning of the various boxes and arrows in the dot generated\n# graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGENERATE_LEGEND        = YES\n\n# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot\n# files that are used to generate the various graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_CLEANUP            = YES\n"
  },
  {
    "path": "libipm/Makefile.am",
    "content": "\nAM_CPPFLAGS = \\\n  -DXRDP_SOCKET_ROOT_PATH=\\\"${socketdir}\\\" \\\n  -I$(top_srcdir)/common\n\nmodule_LTLIBRARIES = \\\n  libipm.la\n\nlibipm_la_SOURCES = \\\n  libipm.h \\\n  libipm.c \\\n  libipm_send.c \\\n  libipm_recv.c \\\n  libipm_facilities.h \\\n  libipm_private.h \\\n  ccp.h \\\n  ccp.c \\\n  ccp_application_types.h \\\n  ccp_application_types.c \\\n  eicp.h \\\n  eicp.c \\\n  ercp.h \\\n  ercp.c \\\n  scp.h \\\n  scp.c \\\n  scp_sync.h \\\n  scp_sync.c \\\n  scp_application_types.h \\\n  scp_application_types.c\n\nlibipm_la_LIBADD = \\\n  $(top_builddir)/common/libcommon.la\n"
  },
  {
    "path": "libipm/ccp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/ccp.c\n * @brief CCP definitions\n * @author Matt Burt\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"ccp.h\"\n#include \"libipm.h\"\n#include \"trans.h\"\n\n/*****************************************************************************/\nstatic const char *\nmsgno_to_str(unsigned short n)\n{\n    return\n        (n == E_CCP_CLOSE_CONNECTION_REQUEST) ? \"E_CCP_CLOSE_CONNECTION_REQUEST\" :\n        NULL;\n}\n\n/*****************************************************************************/\nconst char *\nccp_msgno_to_str(enum ccp_msg_code n, char *buff, unsigned int buff_size)\n{\n    const char *str = msgno_to_str((unsigned short)n);\n\n    if (str == NULL)\n    {\n        (void)snprintf(buff, buff_size, \"[code #%d]\", (int)n);\n    }\n    else\n    {\n        (void)snprintf(buff, buff_size, \"%s\", str);\n    }\n\n    return buff;\n}\n\n/*****************************************************************************/\nvoid\nccp_trans_from_scp_trans(struct trans *trans,\n                         ttrans_data_in callback_func,\n                         void *callback_data)\n{\n    libipm_change_facility(trans, LIBIPM_FAC_SCP, LIBIPM_FAC_CCP);\n    trans->trans_data_in = callback_func;\n    trans->callback_data = callback_data;\n}\n\n/*****************************************************************************/\nint\nccp_msg_in_check_available(struct trans *trans, int *available)\n{\n    return libipm_msg_in_check_available(trans, available);\n}\n\n/*****************************************************************************/\nenum ccp_msg_code\nccp_msg_in_get_msgno(const struct trans *trans)\n{\n    return (enum ccp_msg_code)libipm_msg_in_get_msgno(trans);\n}\n\n/*****************************************************************************/\nvoid\nccp_msg_in_reset(struct trans *trans)\n{\n    libipm_msg_in_reset(trans);\n}\n\n/*****************************************************************************/\nint\nccp_send_close_connection_request(struct trans *trans,\n                                  enum ccp_close_reason_type reason)\n{\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_CCP_CLOSE_CONNECTION_REQUEST,\n               \"i\", reason);\n}\n\n/*****************************************************************************/\nint\nccp_get_close_connection_request(struct trans *trans,\n                                 enum ccp_close_reason_type *reason)\n{\n    /* Intermediate values */\n    int32_t i_reason;\n\n    int rv = libipm_msg_in_parse( trans, \"i\", &i_reason);\n    if (rv == 0)\n    {\n        *reason = (enum ccp_close_reason_type)i_reason;\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "libipm/ccp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2025, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/ccp.h\n * @brief CCP declarations\n * @author Matt Burt\n *\n * Functions in this file use the following naming conventions:-\n *\n * E_CCP_{msg}_REQUEST is sent by ccp_send_{msg}_request()\n * E_CCP_{msg}_REQUEST is parsed by ccp_get_{msg}_request()\n * E_CCP_{msg}_RESPONSE is sent by ccp_send_{msg}_response()\n * E_CCP_{msg}_RESPONSE is parsed by ccp_get_{msg}_response()\n * E_CCP_{msg}_EVENT is sent by ccp_send_{msg}_event()\n * E_CCP_{msg}_EVENT is parsed by ccp_get_{msg}_event()\n */\n\n#ifndef CCP_H\n#define CCP_H\n\n#include \"arch.h\"\n#include \"trans.h\"\n#include \"ccp_application_types.h\"\n\n/* Message codes */\nenum ccp_msg_code\n{\n    E_CCP_CLOSE_CONNECTION_REQUEST // sesexec -> xrdp\n    // No E_CCP_CLOSE_CONNECTION_RESPONSE\n};\n\n/* Common facilities */\n\n/**\n * Convert a message code to a string for output\n * @param n Message code\n * @param buff to contain string\n * @param buff_size length of buff\n * @return buff is returned for convenience.\n */\nconst char *\nccp_msgno_to_str(enum ccp_msg_code n, char *buff, unsigned int buff_size);\n\n/* Connection management facilities */\n\n/**\n * Converts an SCP transport to an CCP transport.\n *\n * This is done following successful transmission or receipt of an\n * E_SCP_CONNECT_SESSION_RESPONSE\n *\n * @param trans connected endpoint\n * @param callback_func New callback function for CCP messages.\n * @param callback_data New argument for callback function\n */\nvoid\nccp_trans_from_scp_trans(struct trans *trans,\n                         ttrans_data_in callback_func,\n                         void *callback_data);\n\n/**\n * Checks an CCP transport to see if a complete message is\n * available for parsing\n *\n * @param trans CCP transport\n * @param[out] available != 0 if a complete message is available\n * @return != 0 for error\n */\nint\nccp_msg_in_check_available(struct trans *trans, int *available);\n\n/**\n * Gets the CCP message number of an incoming message\n *\n * @param trans CCP transport\n * @return message in the buffer\n *\n * The results of calling this routine before ccp_msg_in_check_available()\n * states a message is available are undefined.\n */\nenum ccp_msg_code\nccp_msg_in_get_msgno(const struct trans *trans);\n\n/**\n * Resets an CCP message buffer ready to receive the next message\n *\n * @param trans libipm transport\n */\nvoid\nccp_msg_in_reset(struct trans *trans);\n\n/* -------------------- Session messages--------------------  */\n/**\n * Send an E_CCP_CLOSE_CONNECTION_REQUEST\n *\n * Direction : sesexec -> xrdp\n *\n * @param trans CCP transport\n * @param reason reason_code\n * @return != 0 for error\n */\nint\nccp_send_close_connection_request(struct trans *trans,\n                                  enum ccp_close_reason_type reason);\n\n/**\n * Parse an incoming E_CCP_CLOSE_CONNECTION_REQUEST\n *\n * Direction : sesexec -> xrdp\n *\n * @param trans CCP transport\n * @param[out] reason reason_code\n * @return != 0 for error\n */\nint\nccp_get_close_connection_request(struct trans *trans,\n                                 enum ccp_close_reason_type *reason);\n\n#endif /* CCP_H */\n"
  },
  {
    "path": "libipm/ccp_application_types.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/ccp_application_types.c\n * @brief Support routines for types in ccp_application_types.h\n * @author Matt Burt\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n\n#include \"ccp_application_types.h\"\n\n/*****************************************************************************/\nconst char *\nccp_close_reason_to_str(enum ccp_close_reason_type n,\n                        char *buff, unsigned int buff_size)\n{\n    const char *str =\n        (n == CCP_CLOSE_RPC_INITIATED_DISCONNECT)\n        ? \"Connection closed by administrator request\" :\n        (n == CCP_CLOSE_DISCONNECTED_BY_OTHERCONNECTION)\n        ? \"Another connection was made to the session\" :\n        (n == CCP_CLOSE_LOGOFF_BY_USER)\n        ? \"The user logged out of the session\" :\n        (n == CCP_CLOSE_SOFTWARE_FAILURE)\n        ? \"A software failure has occurred\" :\n        /* Default */ NULL;\n\n    if (str == NULL)\n    {\n        (void)snprintf(buff, buff_size, \"[ccp reason code #%d]\", (int)n);\n    }\n    else\n    {\n        (void)snprintf(buff, buff_size, \"%s\", str);\n    }\n\n    return buff;\n}\n"
  },
  {
    "path": "libipm/ccp_application_types.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/ccp_application_types.h\n * @brief ccp type declarations intended for use in the application\n * @author Simone Fedele/ Matt Burt\n */\n\n#ifndef CCP_APPLICATION_TYPES_H\n#define CCP_APPLICATION_TYPES_H\n\n#include <sys/types.h>\n\n/**\n * Select the reason for a close connection request\n */\nenum ccp_close_reason_type\n{\n    CCP_CLOSE_RPC_INITIATED_DISCONNECT = 1,\n    CCP_CLOSE_DISCONNECTED_BY_OTHERCONNECTION,\n    CCP_CLOSE_LOGOFF_BY_USER,\n    CCP_CLOSE_SOFTWARE_FAILURE\n};\n\n/**\n * Convert an ccp_close_reason_type to a readable string for output\n * @param n Message code\n * @param buff to contain string\n * @param buff_size length of buff\n * @return buff is returned for convenience.\n */\nconst char *\nccp_close_reason_to_str(enum ccp_close_reason_type n,\n                        char *buff, unsigned int buff_size);\n\n#endif /* CCP_APPLICATION_TYPES_H */\n"
  },
  {
    "path": "libipm/eicp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/eicp.c\n * @brief EICP definitions\n * @author Matt Burt\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"eicp.h\"\n#include \"libipm.h\"\n#include \"guid.h\"\n#include \"os_calls.h\"\n#include \"trans.h\"\n\n/*****************************************************************************/\nstatic const char *\nmsgno_to_str(unsigned short n)\n{\n    return\n        (n == E_EICP_SYS_LOGIN_REQUEST) ? \"EICP_SYS_LOGIN_REQUEST\" :\n        (n == E_EICP_SYS_LOGIN_RESPONSE) ? \"EICP_SYS_LOGIN_RESPONSE\" :\n\n        (n == E_EICP_LOGOUT_REQUEST) ? \"EICP_LOGOUT_REQUEST\" :\n\n        (n == E_EICP_CREATE_SESSION_REQUEST) ? \"EICP_CREATE_SESSION_REQUEST\" :\n        (n == E_EICP_CREATE_SESSION_RESPONSE) ? \"EICP_CREATE_SESSION_RESPONSE\" :\n\n        NULL;\n}\n\n/*****************************************************************************/\nconst char *\neicp_msgno_to_str(enum eicp_msg_code n, char *buff, unsigned int buff_size)\n{\n    const char *str = msgno_to_str((unsigned short)n);\n\n    if (str == NULL)\n    {\n        g_snprintf(buff, buff_size, \"[code #%d]\", (int)n);\n    }\n    else\n    {\n        g_snprintf(buff, buff_size, \"%s\", str);\n    }\n\n    return buff;\n}\n\n/*****************************************************************************/\nint\neicp_init_trans(struct trans *trans)\n{\n    return libipm_init_trans(trans, LIBIPM_FAC_EICP, msgno_to_str);\n}\n\n/*****************************************************************************/\nstruct trans *\neicp_init_trans_from_fd(int fd, int trans_type, int (*term_func)(void))\n{\n    struct trans *result;\n    if ((result = trans_create(TRANS_MODE_UNIX, 128, 128)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't create ECP transport [%s]\",\n            g_get_strerror());\n    }\n    else\n    {\n        result->sck = fd;\n        result->type1 = trans_type;\n        result->status = TRANS_STATUS_UP;\n        result->is_term = term_func;\n\n        // Make sure child processes don't inherit our FD\n        (void)g_file_set_cloexec(result->sck, 1);\n\n        if (eicp_init_trans(result) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"eicp_init_trans() call failed\");\n            trans_delete(result);\n            result = NULL;\n        }\n    }\n\n    return result;\n}\n\n\n/*****************************************************************************/\n\nint\neicp_msg_in_check_available(struct trans *trans, int *available)\n{\n    return libipm_msg_in_check_available(trans, available);\n}\n\n/*****************************************************************************/\n\nint\neicp_msg_in_wait_available(struct trans *trans)\n{\n    return libipm_msg_in_wait_available(trans);\n}\n\n/*****************************************************************************/\n\nenum eicp_msg_code\neicp_msg_in_get_msgno(const struct trans *trans)\n{\n    return (enum eicp_msg_code)libipm_msg_in_get_msgno(trans);\n}\n\n/*****************************************************************************/\n\nvoid\neicp_msg_in_reset(struct trans *trans)\n{\n    libipm_msg_in_reset(trans);\n}\n\n/*****************************************************************************/\nint\neicp_send_sys_login_request(struct trans *trans,\n                            const char *username,\n                            const char *password,\n                            const char *ip_addr,\n                            int scp_fd)\n{\n    int rv;\n\n    rv = libipm_msg_out_simple_send(\n             trans,\n             (int)E_EICP_SYS_LOGIN_REQUEST,\n             \"sssh\",\n             username,\n             password,\n             ip_addr,\n             scp_fd);\n\n    /* Wipe the output buffer to remove the password */\n    libipm_msg_out_erase(trans);\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\neicp_get_sys_login_request(struct trans *trans,\n                           const char **username,\n                           const char **password,\n                           const char **ip_addr,\n                           int *scp_fd)\n{\n    /* Make sure the buffer is cleared after processing this message */\n    libipm_set_flags(trans, LIBIPM_E_MSG_IN_ERASE_AFTER_USE);\n\n    return libipm_msg_in_parse( trans, \"sssh\",\n                                username, password, ip_addr, scp_fd);\n}\n\n/*****************************************************************************/\n\nint\neicp_send_sys_login_response(struct trans *trans,\n                             int is_logged_in,\n                             uid_t uid,\n                             int scp_fd)\n{\n    int rv;\n\n    if (is_logged_in)\n    {\n        rv = libipm_msg_out_simple_send(\n                 trans,\n                 (int)E_EICP_SYS_LOGIN_RESPONSE,\n                 \"bih\",\n                 1,\n                 uid,\n                 scp_fd);\n    }\n    else\n    {\n        rv = libipm_msg_out_simple_send(\n                 trans, (int)E_EICP_SYS_LOGIN_RESPONSE, \"b\", 0);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\neicp_get_sys_login_response(struct trans *trans,\n                            int *is_logged_in,\n                            uid_t *uid,\n                            int *scp_fd)\n{\n    int rv;\n\n    if ((rv = libipm_msg_in_parse(trans, \"b\", is_logged_in)) == 0)\n    {\n        if (*is_logged_in)\n        {\n            int32_t i_uid;\n\n            rv = libipm_msg_in_parse(\n                     trans,\n                     \"ih\",\n                     &i_uid,\n                     scp_fd);\n\n            if (rv == 0)\n            {\n                *uid = (uid_t)i_uid;\n            }\n        }\n        else\n        {\n            *uid = (uid_t) -1;\n            *scp_fd = -1;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\neicp_send_uds_login_request(struct trans *trans,\n                            int scp_fd)\n{\n    return libipm_msg_out_simple_send(\n               trans, (int)E_EICP_UDS_LOGIN_REQUEST, \"h\", scp_fd);\n}\n\n/*****************************************************************************/\nint\neicp_get_uds_login_request(struct trans *trans,\n                           int *scp_fd)\n{\n    return libipm_msg_in_parse( trans, \"h\", scp_fd);\n}\n\n/*****************************************************************************/\nint\neicp_send_logout_request(struct trans *trans)\n{\n    return libipm_msg_out_simple_send(trans, (int)E_EICP_LOGOUT_REQUEST, NULL);\n}\n\n/*****************************************************************************/\n\nint\neicp_send_create_session_request(struct trans *trans,\n                                 int x11_display,\n                                 enum scp_session_type type,\n                                 unsigned short width,\n                                 unsigned short height,\n                                 unsigned char bpp,\n                                 const char *shell,\n                                 const char *directory,\n                                 const char *instance_name)\n{\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_EICP_CREATE_SESSION_REQUEST,\n               \"iyqqysss\",\n               x11_display,\n               type,\n               width,\n               height,\n               bpp,\n               shell,\n               directory,\n               instance_name);\n}\n\n/*****************************************************************************/\n\nint\neicp_get_create_session_request(struct trans *trans,\n                                int *x11_display,\n                                enum scp_session_type *type,\n                                unsigned short *width,\n                                unsigned short *height,\n                                unsigned char *bpp,\n                                const char **shell,\n                                const char **directory,\n                                const char **instance_name)\n{\n    /* Intermediate values */\n    int32_t i_x11_display;\n    uint8_t i_type;\n    uint16_t i_width;\n    uint16_t i_height;\n    uint8_t i_bpp;\n\n    int rv = libipm_msg_in_parse(\n                 trans,\n                 \"iyqqysss\",\n                 &i_x11_display,\n                 &i_type,\n                 &i_width,\n                 &i_height,\n                 &i_bpp,\n                 shell,\n                 directory,\n                 instance_name);\n\n    if (rv == 0)\n    {\n        *x11_display = i_x11_display;\n        *type = (enum scp_session_type)i_type;\n        *width = i_width;\n        *height = i_height;\n        /* bpp is fixed for Xorg session types */\n        *bpp = (*type == SCP_SESSION_TYPE_XORG) ? 24 : i_bpp;\n    }\n\n    return rv;\n}\n/*****************************************************************************/\n\nint\neicp_send_create_session_response(struct trans *trans,\n                                  enum scp_screate_status status,\n                                  const char *display,\n                                  const struct guid *guid)\n{\n    struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };\n    return libipm_msg_out_simple_send(\n               trans, (int)E_EICP_CREATE_SESSION_RESPONSE,\n               \"isB\", status, display, &guid_descriptor);\n}\n\n/*****************************************************************************/\n\nint\neicp_get_create_session_response(struct trans *trans,\n                                 enum scp_screate_status *status,\n                                 const char **display,\n                                 struct guid *guid)\n{\n    /* Intermediate values */\n    int32_t i_status;\n\n    const struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };\n    int rv = libipm_msg_in_parse(\n                 trans,\n                 \"isB\",\n                 &i_status,\n                 display,\n                 &guid_descriptor);\n\n    if (rv == 0)\n    {\n        *status = (enum scp_screate_status)i_status;\n    }\n    else\n    {\n        *display = \"\";\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "libipm/eicp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/eicp.h\n * @brief EICP declarations\n * @author Matt Burt\n *\n * Functions in this file use the following naming conventions:-\n *\n * E_EICP_{msg}_REQUEST is sent by eicp_send_{msg}_request()\n * E_EICP_{msg}_REQUEST is parsed by eicp_get_{msg}_request()\n * E_EICP_{msg}_RESPONSE is sent by eicp_send_{msg}_response()\n * E_EICP_{msg}_RESPONSE is parsed by eicp_get_{msg}_response()\n */\n\n#ifndef EICP_H\n#define EICP_H\n\n#include \"arch.h\"\n#include \"scp_application_types.h\"\n\nstruct trans;\nstruct guid;\n\n/* Message codes */\nenum eicp_msg_code\n{\n    E_EICP_SYS_LOGIN_REQUEST,\n    E_EICP_SYS_LOGIN_RESPONSE,\n\n    E_EICP_UDS_LOGIN_REQUEST,\n    // No E_EIC_UDS_LOGIN response\n\n    E_EICP_LOGOUT_REQUEST,\n    // No E_EICP_LOGOUT_RESPONSE\n\n    E_EICP_CREATE_SESSION_REQUEST,\n    E_EICP_CREATE_SESSION_RESPONSE\n};\n\n/* Common facilities */\n\n/**\n * Convert a message code to a string for output\n * @param n Message code\n * @param buff to contain string\n * @param buff_size length of buff\n * @return buff is returned for convenience.\n */\nconst char *\neicp_msgno_to_str(enum eicp_msg_code n, char *buff, unsigned int buff_size);\n\n/* Connection management facilities */\n\n/**\n * Converts a standard trans connected to an EICP endpoint to an EICP transport\n *\n * @param trans connected endpoint\n * @return != 0 for error\n */\nint\neicp_init_trans(struct trans *trans);\n\n/**\n * Creates an EICP transport from a file descriptor\n *\n * @param fd file descriptor\n * @param trans_type TRANS_TYPE_SERVER or TRANS_TYPE_CLIENT\n * @param term_func Function to poll during connection for program\n *         termination, or NULL for none.\n * @return SCP transport, or NULL\n */\nstruct trans *\neicp_init_trans_from_fd(int fd, int trans_type, int (*term_func)(void));\n\n\n/**\n * Checks an EICP transport to see if a complete message is\n * available for parsing\n *\n * @param trans EICP transport\n * @param[out] available != 0 if a complete message is available\n * @return != 0 for error\n */\nint\neicp_msg_in_check_available(struct trans *trans, int *available);\n\n/**\n * Waits on a single transport for an EICP message to be available for\n * parsing\n *\n * @param trans libipm transport\n * @return != 0 for error\n *\n * While the call is active, data-in callbacks for the transport are\n * disabled.\n *\n * Only use this call if you have nothing to do until a message\n * arrives on the transport. If you have other transports to service, use\n * eicp_msg_in_check_available()\n */\nint\neicp_msg_in_wait_available(struct trans *trans);\n\n\n/**\n * Gets the EICP message number of an incoming message\n *\n * @param trans EICP transport\n * @return message in the buffer\n *\n * The results of calling this routine before eicp_msg_in_check_available()\n * states a message is available are undefined.\n */\nenum eicp_msg_code\neicp_msg_in_get_msgno(const struct trans *trans);\n\n/**\n * Resets an EICP message buffer ready to receive the next message\n *\n * @param trans libipm transport\n */\nvoid\neicp_msg_in_reset(struct trans *trans);\n\n/* -------------------- Connect messages--------------------  */\n\n/**\n * Send an E_EICP_SYS_LOGIN_REQUEST\n *\n * @param trans EICP transport\n * @param username Username\n * @param password Password\n * @param ip_addr IP address for the client (or \"\" if not known)\n * @param scp_fd SCP file descriptor from sesman client\n * @return != 0 for error\n *\n * sesexec replies (eventually) with E_EICP_SYS_LOGIN_RESPONSE\n *\n * Once this message has been sent, sesman can close its own SCP transport\n * down, as sesexec is responsible for client communication. When sesexec\n * responds, sesman can recreate the SCP transport if necessary.\n *\n * While E_EICP_SYS_LOGIN_REQUEST is being processed, sesman must assume\n * sesexec will be unresponsive to other EICP messages (although a\n * SIGTERM should be effective).\n */\nint\neicp_send_sys_login_request(struct trans *trans,\n                            const char *username,\n                            const char *password,\n                            const char *ip_addr,\n                            int scp_fd);\n\n/**\n * Parse an incoming E_EICP_SYS_LOGIN_REQUEST message (sesexec)\n *\n * @param trans EICP transport\n * @param[out] username Username\n * @param[out] password Password\n * @param[out] ip_addr IP address for the client (or \"\" if not known)\n * @param [out] scp_fd SCP file descriptor from sesman client\n * @return != 0 for error\n */\nint\neicp_get_sys_login_request(struct trans *trans,\n                           const char **username,\n                           const char **password,\n                           const char **ip_addr,\n                           int *scp_fd);\n\n/**\n * Send an E_EICP_SYS_LOGIN_RESPONSE (sesexec)\n *\n * @param trans EICP transport\n * @param is_logged_in true if the SCP client is logged in\n * @param uid UID of connected user\n * @param scp_fd File descriptor of sesman client\n * @return != 0 for error\n *\n * The uid and scp_fd are ignored unless is_logged_in is true.\n *\n * If is_logged_in is false, it is assumed that sesexec has properly\n * closed the connection to the SCP client.\n */\nint\neicp_send_sys_login_response(struct trans *trans,\n                             int is_logged_in,\n                             uid_t uid,\n                             int scp_fd);\n\n/**\n * Parses an incoming E_EICP_SYS_LOGIN_RESPONSE (sesman)\n *\n * @param trans EICP transport\n * @param[out] is_logged_in true if the SCP client is logged in\n * @param[out] uid UID of connected user\n * @param[out] scp_fd File descriptor of sesman client\n * @return != 0 for error\n *\n * The uid and client_fd are returned as (uid_t)-1 and -1 respectively\n * unless is_logged_in is true\n */\nint\neicp_get_sys_login_response(struct trans *trans,\n                            int *is_logged_in,\n                            uid_t *uid,\n                            int *scp_fd);\n\n/**\n * Send an E_EICP_UDS_LOGIN_REQUEST (sesman)\n *\n * @param trans EICP transport\n * @param scp_fd File descriptor attached to the client\n * @return != 0 for error\n *\n * This call is needed if the sesexec process is created after\n * the UID is known already. It generates no response. It is expected to\n * succeed, as sesman is expected to have already vetted the caller.\n *\n * The file descriptor is closed immediately after it is used by the\n * recipient.\n */\nint\neicp_send_uds_login_request(struct trans *trans,\n                            int scp_fd);\n\n\n/**\n * Get a E_EICP_UDS_LOGIN_REQUEST (sesexec)\n *\n * @param trans EICP transport\n * @param[out] scp_fd File descriptor attached to the client\n * @return != 0 for error\n */\nint\neicp_get_uds_login_request(struct trans *trans,\n                           int *scp_fd);\n\n\n/**\n * Send an E_EICP_LOGOUT_REQUEST (sesexec)\n *\n * @param trans EICP transport\n * @return != 0 for error\n *\n * The sesexec process will exit normally\n */\nint\neicp_send_logout_request(struct trans *trans);\n\n/* -------------------- Session messages--------------------  */\n\n/**\n * Send an E_EICP_CREATE_SESSION_REQUEST (sesman)\n *\n * @param trans EICP transport\n * @param x11_display X display number to use, or -1 if not X11\n * @param type Session type\n * @param width Initial session width\n * @param height Initial session height\n * @param bpp Session bits-per-pixel (ignored for Xorg sessions)\n * @param shell User program to run. May be \"\"\n * @param directory Directory to run the program in. May be \"\"\n * @param instance_name Name of xrdp instance. May be \"\"\n * @return != 0 for error\n *\n * The UID for the session must have been set by a previous call.\n *\n * Following a successful request, the session creation can be\n * considered to be underway. The result of this operation is\n * conveyed back to the caller as one or more ERCP messages. The caller\n * must use ercp_trans_from_eicp_trans() on 'trans' to convert the\n * transport to an ERCP transport to receive this (and other) session\n * run-time events.\n */\nint\neicp_send_create_session_request(struct trans *trans,\n                                 int x11_display,\n                                 enum scp_session_type type,\n                                 unsigned short width,\n                                 unsigned short height,\n                                 unsigned char bpp,\n                                 const char *shell,\n                                 const char *directory,\n                                 const char *instance_name);\n\n\n/**\n * Parse an incoming E_EICP_CREATE_SESSION_REQUEST (sesexec)\n *\n * @param trans EICP transport\n * @param[out] x11_display X display number to use\n * @param[out] type Session type\n * @param[out] width Initial session width\n * @param[out] height Initial session height\n * @param[out] bpp Session bits-per-pixel (ignored for Xorg sessions)\n * @param[out] shell User program to run. May be \"\"\n * @param[out] directory Directory to run the program in. May be \"\"\n * @param[out] instance_name Name of xrdp instance. May be \"\"\n * @return != 0 for error\n *\n * Returned string pointers are valid until scp_msg_in_reset() is\n * called for the transport\n */\nint\neicp_get_create_session_request(struct trans *trans,\n                                int *x11_display,\n                                enum scp_session_type *type,\n                                unsigned short *width,\n                                unsigned short *height,\n                                unsigned char *bpp,\n                                const char **shell,\n                                const char **directory,\n                                const char **instance_name);\n\n/**\n * Send an E_EICP_CREATE_SESSION_RESPONSE\n *\n * Direction : sesexec -> sesman\n *\n * This event is in response to an E_EICP_CREATE_SESSION_REQUEST\n *\n * @param trans EICP transport\n * @param status Status of creation request\n * @param display Display name, either (e.g.) \"X11-n\" (X11)\n *        or \"wayland-n\" (Wayland)\n * @param guid GUID of session\n * @return != 0 for error\n */\nint\neicp_send_create_session_response(struct trans *trans,\n                                  enum scp_screate_status status,\n                                  const char *display,\n                                  const struct guid *guid);\n\n\n/**\n * Parse an E_EICP_CREATE_SESSION_RESPONSE\n *\n * Direction : sesexec -> sesman\n *\n * This event is in response to an E_EICP_CREATE_SESSION_REQUEST\n *\n * @param trans EICP transport\n * @param[out] status Status of creation request\n * @param[out]  display Display name, either (e.g.) \"X11-n\" (X11)\n *              or \"wayland-n\" (Wayland)\n * @param[out] guid GUID of session\n * @return != 0 for error\n */\nint\neicp_get_create_session_response(struct trans *trans,\n                                 enum scp_screate_status *status,\n                                 const char **display,\n                                 struct guid *guid);\n\n#endif /* EICP_H */\n"
  },
  {
    "path": "libipm/ercp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/ercp.c\n * @brief ERCP definitions\n * @author Matt Burt\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"ercp.h\"\n#include \"libipm.h\"\n#include \"guid.h\"\n#include \"os_calls.h\"\n#include \"trans.h\"\n\n/*****************************************************************************/\nstatic const char *\nmsgno_to_str(unsigned short n)\n{\n    return\n        (n == E_ERCP_SESSION_ANNOUNCE_EVENT) ? \"ERCP_SESSION_ANNOUNCE_EVENT\" :\n        (n == E_ERCP_SESSION_FINISHED_EVENT) ? \"ERCP_SESSION_FINISHED_EVENT\" :\n\n        (n == E_ERCP_CONNECT_SESSION_REQUEST) ? \"ERCP_CONNECT_SESSION_REQUEST\" :\n\n        (n == E_ERCP_CLIENT_CONNECT_EVENT) ? \"ERCP_CLIENT_CONNECT_EVENT\" :\n        (n == E_ERCP_CLIENT_DISCONNECT_EVENT) ? \"ERCP_CLIENT_DISCONNECT_EVENT\" :\n\n        NULL;\n}\n\n/*****************************************************************************/\nconst char *\nercp_msgno_to_str(enum ercp_msg_code n, char *buff, unsigned int buff_size)\n{\n    const char *str = msgno_to_str((unsigned short)n);\n\n    if (str == NULL)\n    {\n        g_snprintf(buff, buff_size, \"[code #%d]\", (int)n);\n    }\n    else\n    {\n        g_snprintf(buff, buff_size, \"%s\", str);\n    }\n\n    return buff;\n}\n\n/*****************************************************************************/\nint\nercp_init_trans(struct trans *trans)\n{\n    return libipm_init_trans(trans, LIBIPM_FAC_ERCP, msgno_to_str);\n}\n\n/*****************************************************************************/\nvoid\nercp_trans_from_eicp_trans(struct trans *trans,\n                           ttrans_data_in callback_func,\n                           void *callback_data)\n{\n    libipm_change_facility(trans, LIBIPM_FAC_EICP, LIBIPM_FAC_ERCP);\n    trans->trans_data_in = callback_func;\n    trans->callback_data = callback_data;\n}\n\n/*****************************************************************************/\n\nstruct trans *\nercp_connect(const  char *port, int (*term_func)(void))\n{\n    struct trans *t;\n\n    if ((t = trans_create(TRANS_MODE_UNIX, 128, 128)) != NULL)\n    {\n        t->is_term = term_func;\n\n        if (trans_connect(t, NULL, port, 3000) != 0)\n        {\n            trans_delete(t);\n            t = NULL;\n        }\n        else if (ercp_init_trans(t) != 0)\n        {\n            trans_delete(t);\n            t = NULL;\n        }\n    }\n\n    return t;\n}\n\n/*****************************************************************************/\n\nint\nercp_msg_in_check_available(struct trans *trans, int *available)\n{\n    return libipm_msg_in_check_available(trans, available);\n}\n\n/*****************************************************************************/\n\nint\nercp_msg_in_wait_available(struct trans *trans)\n{\n    return libipm_msg_in_wait_available(trans);\n}\n\n/*****************************************************************************/\n\nenum ercp_msg_code\nercp_msg_in_get_msgno(const struct trans *trans)\n{\n    return (enum ercp_msg_code)libipm_msg_in_get_msgno(trans);\n}\n\n/*****************************************************************************/\n\nvoid\nercp_msg_in_reset(struct trans *trans)\n{\n    libipm_msg_in_reset(trans);\n}\n\n/*****************************************************************************/\n\nint\nercp_send_session_announce_event(struct trans *trans,\n                                 const char *display,\n                                 uid_t uid,\n                                 enum scp_session_type type,\n                                 unsigned short start_width,\n                                 unsigned short start_height,\n                                 unsigned char bpp,\n                                 const struct guid *guid,\n                                 const char *start_ip_addr,\n                                 time_t start_time,\n                                 const char *instance_name)\n{\n    struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };\n\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_ERCP_SESSION_ANNOUNCE_EVENT,\n               \"siyqqyBsxs\",\n               display,\n               uid,\n               type,\n               start_width,\n               start_height,\n               bpp,\n               &guid_descriptor,\n               start_ip_addr,\n               (int64_t)start_time,\n               instance_name);\n}\n\n/*****************************************************************************/\n\nint\nercp_get_session_announce_event(struct trans *trans,\n                                const char **display,\n                                uid_t *uid,\n                                enum scp_session_type *type,\n                                unsigned short *start_width,\n                                unsigned short *start_height,\n                                unsigned char *bpp,\n                                struct guid *guid,\n                                const char **start_ip_addr,\n                                time_t *start_time,\n                                const char **instance_name)\n{\n    /* Intermediate values */\n    int32_t i_uid;\n    uint8_t i_type;\n    uint16_t i_width;\n    uint16_t i_height;\n    uint8_t i_bpp;\n    int64_t i_start_time;\n\n    const struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };\n\n    int rv = libipm_msg_in_parse(\n                 trans,\n                 \"siyqqyBsxs\",\n                 display,\n                 &i_uid,\n                 &i_type,\n                 &i_width,\n                 &i_height,\n                 &i_bpp,\n                 &guid_descriptor,\n                 start_ip_addr,\n                 &i_start_time,\n                 instance_name);\n\n    if (rv == 0)\n    {\n        *uid = (uid_t)i_uid;\n        *type = (enum scp_session_type)i_type;\n        *start_width = i_width;\n        *start_height = i_height;\n        *bpp = i_bpp;\n        *start_time = (time_t)i_start_time;\n    }\n    else\n    {\n        *display = \"\";\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nercp_send_session_finished_event(struct trans *trans)\n{\n    return libipm_msg_out_simple_send(\n               trans, (int)E_ERCP_SESSION_FINISHED_EVENT, NULL);\n}\n\n/*****************************************************************************/\n\nint\nercp_send_connect_session_request(struct trans *trans,\n                                  int scp_fd,\n                                  const char *client_ip,\n                                  const char *client_name,\n                                  unsigned int scp_flags)\n{\n    return libipm_msg_out_simple_send(\n               trans, (int)E_ERCP_CONNECT_SESSION_REQUEST,\n               \"hssu\", scp_fd, client_ip, client_name, scp_flags);\n}\n\n/*****************************************************************************/\nint\nercp_get_connect_session_request(struct trans *trans,\n                                 int *scp_fd,\n                                 const char **client_ip,\n                                 const char **client_name,\n                                 unsigned int *scp_flags)\n{\n    /* Intermediate values */\n    uint32_t i_flags;\n\n    int rv = libipm_msg_in_parse(trans, \"hssu\",\n                                 scp_fd, client_ip, client_name, &i_flags);\n    if (rv == 0)\n    {\n        *scp_flags = i_flags;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nercp_send_client_connect_event(struct trans *trans,\n                               const char *client_ip,\n                               const char *client_name,\n                               time_t connect_time)\n{\n    return libipm_msg_out_simple_send(\n               trans, (int)E_ERCP_CLIENT_CONNECT_EVENT,\n               \"ssx\", client_ip, client_name, (int64_t)connect_time);\n}\n\n/*****************************************************************************/\n\nint\nercp_get_client_connect_event(struct trans *trans,\n                              const char **client_ip,\n                              const char **client_name,\n                              time_t *connect_time)\n{\n    /* Intermediate values */\n    int64_t i_connect_time;\n\n    int rv = libipm_msg_in_parse(trans, \"ssx\",\n                                 client_ip, client_name, &i_connect_time);\n    if (rv == 0)\n    {\n        *connect_time = i_connect_time;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nercp_send_client_disconnect_event(struct trans *trans,\n                                  time_t disconnect_time)\n{\n    return libipm_msg_out_simple_send(\n               trans, (int)E_ERCP_CLIENT_DISCONNECT_EVENT,\n               \"x\", (int64_t)disconnect_time);\n}\n\n/*****************************************************************************/\n\nint\nercp_get_client_disconnect_event(struct trans *trans,\n                                 time_t *disconnect_time)\n{\n    /* Intermediate values */\n    int64_t i_disconnect_time;\n\n    int rv = libipm_msg_in_parse(trans, \"x\", &i_disconnect_time);\n    if (rv == 0)\n    {\n        *disconnect_time = i_disconnect_time;\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "libipm/ercp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/ercp.h\n * @brief ERCP declarations\n * @author Matt Burt\n *\n * Functions in this file use the following naming conventions:-\n *\n * E_ERCP_{msg}_REQUEST is sent by ercp_send_{msg}_request()\n * E_ERCP_{msg}_REQUEST is parsed by ercp_get_{msg}_request()\n * E_ERCP_{msg}_RESPONSE is sent by ercp_send_{msg}_response()\n * E_ERCP_{msg}_RESPONSE is parsed by ercp_get_{msg}_response()\n * E_ERCP_{msg}_EVENT is sent by ercp_send_{msg}_event()\n * E_ERCP_{msg}_EVENT is parsed by ercp_get_{msg}_event()\n */\n\n#ifndef ERCP_H\n#define ERCP_H\n\n#include \"arch.h\"\n#include \"scp_application_types.h\"\n#include \"trans.h\"\n\nstruct guid;\n\n/* Message codes */\nenum ercp_msg_code\n{\n    E_ERCP_SESSION_ANNOUNCE_EVENT, // sesexec -> sesman\n    E_ERCP_SESSION_FINISHED_EVENT, // sesexec -> sesman\n\n    // A connect session request has no matching response, but if\n    // successful, a client connect event will be generated.\n    E_ERCP_CONNECT_SESSION_REQUEST, // sesman -> sesexec\n    // No E_ERCP_CONNECT_SESSION_RESPONSE\n\n    E_ERCP_CLIENT_CONNECT_EVENT,    // sesexec -> sesman\n    E_ERCP_CLIENT_DISCONNECT_EVENT  // sesexec -> sesman\n};\n\n/* Common facilities */\n\n/**\n * Convert a message code to a string for output\n * @param n Message code\n * @param buff to contain string\n * @param buff_size length of buff\n * @return buff is returned for convenience.\n */\nconst char *\nercp_msgno_to_str(enum ercp_msg_code n, char *buff, unsigned int buff_size);\n\n/* Connection management facilities */\n\n/**\n * Converts a standard trans connected to an ERCP endpoint to an ERCP transport\n *\n * @param trans connected endpoint\n * @return != 0 for error\n */\nint\nercp_init_trans(struct trans *trans);\n\n/**\n * Converts an EICP transport to an ERCP transport.\n *\n * This is done following successful transmission or receipt of an\n * E_EICP_CREATE_SESSION_REQUEST.\n *\n * @param trans connected endpoint\n * @param callback_func New callback function for ERCP messages.\n * @param callback_data New argument for callback function\n */\nvoid\nercp_trans_from_eicp_trans(struct trans *trans,\n                           ttrans_data_in callback_func,\n                           void *callback_data);\n\n/**\n * Connects to an ERCP endpoint.\n *\n * @param port Path to UDS object in filesystem\n * @param term_func Function to poll during connection for program\n *         termination, or NULL for none.\n */\nstruct trans *\nercp_connect(const char *port,\n             int (*term_func)(void));\n\n/**\n * Checks an ERCP transport to see if a complete message is\n * available for parsing\n *\n * @param trans ERCP transport\n * @param[out] available != 0 if a complete message is available\n * @return != 0 for error\n */\nint\nercp_msg_in_check_available(struct trans *trans, int *available);\n\n/**\n * Waits on a single transport for an ERCP message to be available for\n * parsing\n *\n * @param trans libipm transport\n * @return != 0 for error\n *\n * While the call is active, data-in callbacks for the transport are\n * disabled.\n *\n * Only use this call if you have nothing to do until a message\n * arrives on the transport. If you have other transports to service, use\n * ercp_msg_in_check_available()\n */\nint\nercp_msg_in_wait_available(struct trans *trans);\n\n\n/**\n * Gets the ERCP message number of an incoming message\n *\n * @param trans ERCP transport\n * @return message in the buffer\n *\n * The results of calling this routine before ercp_msg_in_check_available()\n * states a message is available are undefined.\n */\nenum ercp_msg_code\nercp_msg_in_get_msgno(const struct trans *trans);\n\n/**\n * Resets an ERCP message buffer ready to receive the next message\n *\n * @param trans libipm transport\n */\nvoid\nercp_msg_in_reset(struct trans *trans);\n\n/* -------------------- Session event messages--------------------  */\n/**\n * Send an E_ERCP_SESSION_ANNOUNCE_EVENT\n *\n * Direction : sesexec -> sesman\n *\n * This event contains all the information known about a session\n *\n * @param trans ERCP transport\n * @param display Display used by session\n * @param uid UID of user logged in to session\n * @param type Session type\n * @param start_width Starting width of seenio\n * @param start_height Starting height of session\n * @param bpp Bits-per-pixel for session\n * @param guid Session GUID\n * @param start_ip_addr Starting IP address of client\n * @param start_time Session start time\n * @param instance_name Name of xrdp instance\n * * @return != 0 for error\n */\nint\nercp_send_session_announce_event(struct trans *trans,\n                                 const char *display,\n                                 uid_t uid,\n                                 enum scp_session_type type,\n                                 unsigned short start_width,\n                                 unsigned short start_height,\n                                 unsigned char bpp,\n                                 const struct guid *guid,\n                                 const char *start_ip_addr,\n                                 time_t start_time,\n                                 const char *instance_name);\n\n\n/**\n * Parse an incoming E_ERCP_SESSION_ANNOUNCE_EVENT\n *\n * This event contains all the information known about a session\n *\n * @param trans ERCP transport\n * @param[out] display Display used by session.\n * @param[out] uid UID of user logged in to session\n * @param[out] type Session type\n * @param[out] start_width Starting width of seenio\n * @param[out] start_height Starting height of session\n * @param[out] bpp Bits-per-pixel for session\n * @param[out] guid Session GUID\n * @param[out] start_ip_addr Starting IP address of client\n * @param[out] start_time Session start time\n * @param[out] instance_name Name of xrdp instance\n * @return != 0 for error\n */\nint\nercp_get_session_announce_event(struct trans *trans,\n                                const char **display,\n                                uid_t *uid,\n                                enum scp_session_type *type,\n                                unsigned short *start_width,\n                                unsigned short *start_height,\n                                unsigned char *bpp,\n                                struct guid *guid,\n                                const char **start_ip_addr,\n                                time_t *start_time,\n                                const char **instance_name);\n\n\n/**\n * Send an E_ERCP_SESSION_FINISHED_EVENT\n *\n * Direction : sesexec -> sesman\n *\n * This event simply states the attached session has finished and can be\n * removed from any data structures held by sesman\n *\n * @param trans ERCP transport\n * @return != 0 for error\n */\nint\nercp_send_session_finished_event(struct trans *trans);\n\n/**\n * Send an E_ERCP_CONNECT_SESSION_REQUEST\n *\n * Direction : sesman -> sesexec\n *\n * This request tells sesexec to handle a session connection\n *\n * A response is sent directly to the SCP client, rather than back\n * to sesman\n *\n * @param trans ERCP transport\n * @param scp_fd SCP file descriptor for a response\n * @param client_ip IP address of connecting client\n * @param client_name Name of connecting client (from RDP client core info)\n * @param scp_flags Flags from scp_send_connect_session_request()\n * @return != 0 for error\n */\nint\nercp_send_connect_session_request(struct trans *trans,\n                                  int scp_fd,\n                                  const char *client_ip,\n                                  const char *client_name,\n                                  unsigned int scp_flags);\n\n/**\n * Get an E_ERCP_CONNECT_SESSION_REQUEST\n *\n * Direction : sesman -> sesexec\n *\n * This request tells sesexec to handle a session connection\n *\n * A response is sent directly to the SCP client, rather than back\n * to sesman\n *\n * @param trans ERCP transport\n * @param[out] scp_fd SCP file descriptor for a response\n * @param[out] client_ip IP address of connecting client\n * @param[out] client_name Name of connecting client\n * @param[out] scp_flags Flags from scp_send_connect_session_request()\n * @return != 0 for error\n */\nint\nercp_get_connect_session_request(struct trans *trans,\n                                 int *scp_fd,\n                                 const char **client_ip,\n                                 const char **client_name,\n                                 unsigned int *scp_flags);\n\n/**\n * Send an E_ERCP_CLIENT_CONNECT_EVENT\n *\n * Direction : sesexec -> sesman\n *\n * This request tells sesman to update its connected client information\n *\n * @param trans ERCP transport\n * @param client_ip IP address of connecting client\n * @param client_name Name of connecting client (from RDP client core info)\n * @param connect_time Time at which the connect event occurred\n * @return != 0 for error\n */\nint\nercp_send_client_connect_event(struct trans *trans,\n                               const char *client_ip,\n                               const char *client_name,\n                               time_t connect_time);\n\n/**\n * Get an E_ERCP_CLIENT_CONNECT_EVENT\n *\n * Direction : sesexec -> sesman\n *\n * This request tells sesman to update its connected client information\n *\n * @param trans ERCP transport\n * @param[out] client_ip IP address of connecting client\n * @param[out] client_name Name of connecting client (from RDP client core info)\n * @param[out] connect_time Time at which the connect event occurred\n * @return != 0 for error\n */\nint\nercp_get_client_connect_event(struct trans *trans,\n                              const char **client_ip,\n                              const char **client_name,\n                              time_t *connect_time);\n\n/**\n * Send an E_ERCP_CLIENT_DISCONNECT_EVENT\n *\n * Direction : sesexec -> sesman\n *\n * This request tells sesman to update its connected client information\n *\n * @param trans ERCP transport\n * @param disconnect_time Time at which the disconnect event occurred\n * @return != 0 for error\n */\nint\nercp_send_client_disconnect_event(struct trans *trans,\n                                  time_t disconnect_time);\n\n/**\n * Get an E_ERCP_CLIENT_DISCONNECT_EVENT\n *\n * Direction : sesexec -> sesman\n *\n * This request tells sesman to update its connected client information\n *\n * @param trans ERCP transport\n * @param[out] disconnect_time Time at which the disconnect event occurred\n * @return != 0 for error\n */\nint\nercp_get_client_disconnect_event(struct trans *trans,\n                                 time_t *disconnect_time);\n\n#endif /* ERCP_H */\n"
  },
  {
    "path": "libipm/libipm.c",
    "content": "/**\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    libipm/libipm.c\n * @brief   Inter-Process Messaging building and parsing definitions\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libipm.h\"\n#include \"libipm_private.h\"\n#include \"libipm_facilities.h\"\n#include \"trans.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n\nconst char *libipm_valid_type_chars = \"ybnqiuxtsdhogB\";\n\n/*****************************************************************************/\nvoid\nlibipm_msg_in_close_file_descriptors(struct trans *self)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)self->extra_data;\n    if (priv != NULL)\n    {\n        unsigned int i;\n        for (i = priv->in_fd_index ; i < priv->in_fd_count; ++i)\n        {\n            g_file_close(priv->in_fds[i]);\n        }\n        priv->in_fd_count = 0;\n        priv->in_fd_index = 0;\n    }\n}\n\n/**************************************************************************//**\n * Send function for a struct trans initialised with libipm_init_trans()\n *\n * @param self Transport to send on\n * @param data pointer to data to send\n * @param len Length of data to send\n * @return As for write(2)\n */\nstatic int\nlibipm_trans_send_proc(struct trans *self, const char *data, int len)\n{\n    int rv;\n    struct libipm_priv *priv = (struct libipm_priv *)self->extra_data;\n    if (priv != NULL && data == self->out_s->data)\n    {\n        /* We're sending the message header. Send any file descriptors\n         * as ancillary data */\n        rv = g_sck_send_fd_set(self->sck, data, len,\n                               priv->out_fds, priv->out_fd_count);\n    }\n    else\n    {\n        rv = g_sck_send(self->sck, data, len, 0);\n    }\n\n    return rv;\n}\n\n/**************************************************************************//**\n * Receive function for a struct trans initialised with libipm_init_trans()\n *\n * @param self Transport to receive on\n * @param data pointer to receive data buffer\n * @param len Length of data to read\n * @return As for read(2)\n */\nstatic int\nlibipm_trans_recv_proc(struct trans *self, char *data, int len)\n{\n    int rv;\n    struct libipm_priv *priv = (struct libipm_priv *)self->extra_data;\n    if (priv != NULL && data == self->in_s->data)\n    {\n        /* We're receiving the message header */\n        unsigned int fdcount;\n\n        /* Check there are no live file descriptors in the input\n         * buffer from a previous message. This shouldn't happen, but\n         * if by some chance it does, we could leak file descriptors */\n        if (priv->in_fd_count > 0)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Unconsumed file descriptors detected\");\n            libipm_msg_in_close_file_descriptors(self);\n        }\n        rv = g_sck_recv_fd_set(self->sck, data, len,\n                               priv->in_fds, MAX_FD_PER_MSG,\n                               &fdcount);\n        if (fdcount > MAX_FD_PER_MSG)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"%d file descriptors were discarded on recvmsg()\",\n                fdcount - MAX_FD_PER_MSG);\n            fdcount = MAX_FD_PER_MSG;\n        }\n        priv->in_fd_count = fdcount;\n    }\n    else\n    {\n        rv = g_sck_recv(self->sck, data, len, 0);\n    }\n\n    return rv;\n}\n\n\n/**************************************************************************//**\n * Destructor for a struct trans initialised with libipm_init_trans()\n *\n * @param trans Transport to destroy\n */\nstatic void\nlibipm_trans_destructor(struct trans *trans)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n\n    libipm_msg_in_close_file_descriptors(trans);\n    if (priv != NULL)\n    {\n        if ((priv->flags & LIBIPM_E_MSG_IN_ERASE_AFTER_USE) != 0 &&\n                trans->in_s->data != NULL)\n        {\n            g_memset(trans->in_s->data, '\\0',\n                     trans->in_s->end - trans->in_s->data);\n        }\n\n        g_free(priv);\n        trans->extra_data = NULL;\n        trans->extra_destructor = NULL;\n    }\n}\n\n/*****************************************************************************/\n\nenum libipm_status\nlibipm_init_trans(struct trans *trans,\n                  enum libipm_facility facility,\n                  const char *(*msgno_to_str)(unsigned short msgno))\n{\n    struct libipm_priv *priv;\n    enum libipm_status rv;\n\n    if (trans->extra_data != NULL || trans->extra_destructor != NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s() called with sub-classed transport\",\n            __func__);\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else if ((priv = g_new0(struct libipm_priv, 1)) == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s() out of memory\", __func__);\n        rv = E_LI_NO_MEMORY;\n    }\n    else\n    {\n        priv->facility = facility;\n        priv->msgno_to_str = msgno_to_str;\n\n        trans->trans_send = libipm_trans_send_proc;\n        trans->trans_recv = libipm_trans_recv_proc;\n        trans->extra_data = priv;\n        trans->extra_destructor = libipm_trans_destructor;\n\n        g_sck_set_non_blocking(trans->sck);\n\n        libipm_msg_in_reset(trans);\n\n        rv = E_LI_SUCCESS;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nvoid\nlibipm_set_flags(struct trans *trans, unsigned int flags)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n\n    if (priv != NULL)\n    {\n        priv->flags |= flags;\n    }\n}\n\n/*****************************************************************************/\n\nvoid\nlibipm_clear_flags(struct trans *trans, unsigned int flags)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n\n    if (priv != NULL)\n    {\n        priv->flags &= ~flags;\n    }\n}\n\n/*****************************************************************************/\n\nvoid\nlibipm_change_facility(struct trans *trans,\n                       enum libipm_facility old_facility,\n                       enum libipm_facility new_facility)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n\n    if (priv != NULL)\n    {\n        if (priv->facility != old_facility)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Not changing libipm facility - bad value\");\n        }\n        else\n        {\n            priv->facility = new_facility;\n        }\n    }\n}\n"
  },
  {
    "path": "libipm/libipm.h",
    "content": "/**\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    libipm/libipm.h\n * @brief   Inter-Process Messaging building and parsing - public declarations\n *\n * The functions in this file are inspired by the D-Bus type system\n * (see https://dbus.freedesktop.org/doc/dbus-specification.html),\n * and the sd-bus library API.\n */\n\n#if !defined(LIBIPM_H)\n#define LIBIPM_H\n\n#include \"arch.h\"\n#include \"libipm_facilities.h\"\n\nstruct trans;\n\n/**\n * Fixed-size block descriptor for sending blocks of data using libipm\n *\n * Use with the type code 'B'\n *\n * See the descriptions of libipm_msg_out_append() and libipm_msg_in_parse()\n * for instructions on how to use this type.\n */\nstruct libipm_fsb\n{\n    void *data;\n    unsigned int datalen;\n};\n\n/**\n * Status code for library calls\n *\n * These are mainly intended so that the test suite can check the expected\n * codepath has been followed.\n *\n * Wrappers around libipm may assume success is 0, and anything else\n * is an error.\n */\nenum libipm_status\n{\n    E_LI_SUCCESS = 0,\n    E_LI_PROGRAM_ERROR, /***< Programming error */\n    E_LI_NO_MEMORY, /***< Memory allocation failure */\n    E_LI_UNSUPPORTED_TYPE, /***< Specified type code is unsupported */\n    E_LI_UNIMPLEMENTED_TYPE, /***< Specified type code is unimplemented */\n    E_LI_UNEXPECTED_TYPE, /***< Encountered unexpected type on input */\n    E_LI_BUFFER_OVERFLOW, /***< End of buffer reached unexpectedly */\n    E_LI_TOO_MANY_FDS, /***< Too many file descriptors encountered */\n    E_LI_BAD_VALUE, /***< Specified (or incoming) value is out of range */\n    E_LI_BAD_HEADER, /***< Bad incoming message header */\n    E_LI_TRANSPORT_ERROR /***< Error detected at the transport level */\n};\n\n/* Flags values for libipm_[set/clear]_flags() */\n\n/**\n * Input buffer contains sensitive information and must be\n * erased by libipm_msg_in_reset(). The flag is one-shot, and\n * is cleared after use.\n *\n * There is no corresponding flag for the output buffer -\n * use libipm_msg_out_erase() explicitly\n */\n#define LIBIPM_E_MSG_IN_ERASE_AFTER_USE (1u<<0)\n\n/**\n * Prepare a standard 'struct trans' for use with libipm\n *\n * @param trans libipm transport\n * @param facility Facility number from libipm_facilities.h\n * @param msgno_to_str Function to turn a message number into a string\n * @return != 0 for error.\n *\n * The msgno_to_str() function is used for error logging. If the routine\n * is not specified, or the routine returns NULL, a numeric code is\n * logged instead.\n */\nenum libipm_status\nlibipm_init_trans(struct trans *trans,\n                  enum libipm_facility facility,\n                  const char *(*msgno_to_str)(unsigned short msgno));\n\n/**\n * Set the flag(s) specified for the transport\n * @param trans libipm transport\n * @param flags flags to set. Multiple flags should be or'd together.\n */\nvoid\nlibipm_set_flags(struct trans *trans, unsigned int flags);\n\n\n/**\n * Clear the flag(s) specified for the transport\n * @param trans libipm transport\n * @param flags flags to clear. Multiple flags should be or'd together.\n */\nvoid\nlibipm_clear_flags(struct trans *trans, unsigned int flags);\n\n\n/**\n * Change the facility number for the transport\n * @param trans libipm transport\n * @param old_facility old transport facility\n * @param new_facility new transport facility\n *\n * This call is required if a libipm transport changes a facility number.\n * This can be used to implement switches from one functional server state to\n * another.\n *\n * The caller must be aware of the previous facility to change the facility.\n * In the event of a mismatch, a message is logged and no action is taken.\n */\nvoid\nlibipm_change_facility(struct trans *trans,\n                       enum libipm_facility old_facility,\n                       enum libipm_facility new_facility);\n\n\n/**\n * Initialise an output message\n *\n * @param trans libipm transport\n * @param msgno message number\n * @param format a description of any arguments to add to the buffer, or\n *               NULL if no arguments are to be added at this time.\n *\n * See libipm_msg_out_append() for details of the format string. The format\n * string is followed immediately by the arguments it describes */\nenum libipm_status\nlibipm_msg_out_init(struct trans *trans, unsigned short msgno,\n                    const char *format, ...);\n\n/**\n * Append more arguments to an output message\n *\n * @param trans libipm transport\n * @param format a description of any arguments to add to the buffer.\n * @return != 0 if an error occurs\n *\n * The format string is followed immediately by the arguments it\n * describes. The format string may contain these characters (from the\n * D-Bus type system):-\n *\n * Char | C Type  | Description\n * ---- |------   | -----------\n *   y  |uint8_t  | Unsigned 8-bit integer\n *   b  |int      | Boolean value (see below)\n *   n  |int16_t  | Signed (two's complement) 16-bit integer\n *   q  |uint16_t | Unsigned 16-bit integer\n *   i  |int32_t  | Signed (two's complement) 32-bit integer\n *   u  |uint32_t | Unsigned 32-bit integer\n *   x  |int64_t  | Signed (two's complement) 64-bit integer\n *   t  |uint64_t | Unsigned 64-bit integer\n *   s  |char *   | NULL-terminated string\n *   h  |int      | File descriptor\n *   d  |  -      | (reserved)\n *   o  |  -      | (reserved)\n *   g  |  -      | (reserved)\n *\n * For the 'b' type, only values 0 and 1 are allowed. Other values\n * generate an error.\n *\n * The 'h' type can only be used where the underlying transport is a\n * UNIX domain socket.\n *\n *  The following additions to the D-Bus type system are also supported:-\n *\n * Char |C Type                    | Description\n * -----|------                    | -----------\n *   B  |const struct libipm_fsb * | Fixed-size block pointer\n *\n * For the 'B' type, pass in the address of a descriptor containing the\n * address and size of the object. The object is copied to the output\n * stream, along with its length.\n */\nenum libipm_status\nlibipm_msg_out_append(struct trans *trans, const char *format, ...);\n\n/**\n * Marks a message as complete and ready for transmission\n *\n * @param trans libipm transport\n */\nvoid\nlibipm_msg_out_mark_end(struct trans *trans);\n\n/**\n * Convenience sending function\n *\n * Constructs a simple message and sends it immediately using\n * libipm_msg_out_init() / libipm_msg_out_mark_end() and\n * trans_force_write()\n *\n * @param trans libipm transport\n * @param msgno message number\n * @param format a description of any arguments to add to the buffer, or\n *               NULL if no arguments are to be added at this time.\n *\n * See libipm_msg_out_append() for details of the format string. The format\n * string is followed immediately by the arguments it describes\n */\nenum libipm_status\nlibipm_msg_out_simple_send(struct trans *trans, unsigned short msgno,\n                           const char *format, ...);\n\n/**\n * Erase (rather than just ignore) the contents of an output buffer\n *\n * Use after sending a message containing data which should not be\n * kept in memory (e.g. passwords)`\n * @param trans libipm transport\n */\nvoid\nlibipm_msg_out_erase(struct trans *trans);\n\n/**\n * Checks a transport to see if a complete libipm message is\n * available for parsing\n *\n * @param trans libipm transport\n * @param[out] available != 0 if a complete message is available\n * @return != 0 for error\n *\n * When 'available' becomes set, the buffer is guaranteed to\n * be in a parseable state.\n *\n * The results of calling this function after starting to parse a message\n * and before calling libipm_msg_in_reset() are undefined.\n */\nenum libipm_status\nlibipm_msg_in_check_available(struct trans *trans, int *available);\n\n/**\n * Waits on a single transport for a libipm message to be available for\n * parsing\n *\n * @param trans libipm transport\n * @return != 0 for error\n *\n * While the call is active, data-in callbacks for the transport are\n * disabled.\n *\n * The results of calling this function after starting to parse a message\n * and before calling libipm_msg_in_reset() are undefined.\n *\n * Only use this call if you have nothing to do until a message\n * arrives on the transport. If you have other transports to service, use\n * libipm_msg_in_check_available()\n */\nenum libipm_status\nlibipm_msg_in_wait_available(struct trans *trans);\n\n/**\n * Get the message number for a message in the input buffer.\n *\n * @param trans libipm transport\n * @return message number in the buffer\n *\n * The results of calling this routine after a call to\n * libipm_msg_in_reset() and before a successful call to\n * libipm_msg_in_check_available() (or libipm_msg_wait_available())\n * are undefined.\n */\nunsigned short\nlibipm_msg_in_get_msgno(const struct trans *trans);\n\n/**\n * Returns a letter corresponding to the next available type in the\n * input stream.\n *\n * @param trans libipm transport\n * @return letter of the type, '\\0' for end of message, or '?' for\n *          an unrecognised type\n */\nchar\nlibipm_msg_in_peek_type(struct trans *trans);\n\n/**\n * Reads arguments from an input message\n *\n * @param trans libipm transport\n * @param format a description of the arguments to read from the buffer.\n * @return != 0 if an error occurs\n *\n * The format string is followed immediately by the arguments it\n * describes. The format string may contain these characters (from the\n * D-Bus type system):-\n *\n * Char | C Type     | Description\n * ---- | ------     | -----------\n *   y  | uint8_t *  | Unsigned 8-bit integer\n *   b  | int *      | Boolean value (0 or 1 only)\n *   n  | int16_t *  | Signed (two's complement) 16-bit integer\n *   q  | uint16_t * | Unsigned 16-bit integer\n *   i  | int32_t *  | Signed (two's complement) 32-bit integer\n *   u  | uint32_t * | Unsigned 32-bit integer\n *   x  | int64_t *  | Signed (two's complement) 64-bit integer\n *   t  | uint64_t * | Unsigned 64-bit integer\n *   s  | char **    | NULL-terminated string\n *   h  | int *      | File descriptor\n *   d  |   -        | (reserved)\n *   o  |   -        | (reserved)\n *   g  |   -        | (reserved)\n *\n *  The following additions to the D-Bus type system are also supported:-\n *\n * Char | C Type                    | Description\n * -----| ------                    | -----------\n *   B  | const struct libipm_fsb * | Fixed-size block pointer\n *\n * For the 's' type, a pointer into the string in the input buffer is\n * returned. This pointer will only be valid until the next call to\n * libipm_msg_in_reset()\n *\n * The 'h' type can only be used where the underlying transport is a\n * UNIX domain socket.\n *\n * For the 'B' type, pass in the address of an initialised descriptor\n * containing the address and size of the object to copy the data\n * to. The size in the descriptor must match the size of the object\n * on-the-wire. Unlike 's', the data is copied out of the input buffer.\n *\n */\nenum libipm_status\nlibipm_msg_in_parse(struct trans *trans, const char *format, ...);\n\n/**\n * Resets a message buffer ready to receive the next message\n *\n * If the LIBIPM_E_MSG_IN_ERASE_AFTER_USE flag is set for the transport,\n * the entire buffer is erased, and the flag is cleared\n *\n * Any file descriptors received from the other end but not parsed\n * by the application are closed.\n *\n * @param trans libipm transport\n */\nvoid\nlibipm_msg_in_reset(struct trans *trans);\n\n\n#endif /* LIBIPM_H */\n"
  },
  {
    "path": "libipm/libipm_facilities.h",
    "content": "/**\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    libipm/libipm_facilities.h\n * @brief   Facilities numbers for facilities built on top of libipm\n */\n\n#if !defined(LIBIPM__FACILITIES_H)\n#define LIBIPM__FACILITIES_H\n\n/**\n * Facilities layered on top of libipm (16 bits)\n */\nenum libipm_facility\n{\n    LIBIPM_FAC_SCP = 1, /**< SCP - Sesman Control Protocol */\n    LIBIPM_FAC_EICP, /**< EICP - Executive Initialization Control Protocol */\n    LIBIPM_FAC_ERCP, /**< ERCP - Executive Run-time Control Protocol */\n    LIBIPM_FAC_CCP,  /**< CCP - Connection Control Protocol */\n\n    LIBIPM_FAC_TEST = 65535 /**< Used for unit testing */\n};\n\n#endif /* LIBIPM_FACILITIES_H */\n"
  },
  {
    "path": "libipm/libipm_private.h",
    "content": "/**\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    libipm/libipm_private.h\n * @brief   Inter-Process Messaging building and parsing - private declarations\n */\n\n#if !defined(LIBIPM_PRIVATE_H)\n#define LIBIPM_PRIVATE_H\n\n#include \"libipm_facilities.h\"\n\nenum\n{\n    /**\n     * Max size of a libipm message\n     */\n    LIBIPM_MAX_MSG_SIZE = 8192,\n\n    /**\n     * Version of libipm wire protocol\n     */\n    LIBIPM_VERSION = 2,\n\n    /**\n     * Size of libipm header\n     */\n    HEADER_SIZE = 12,\n\n    /**\n     * Max number of file descriptors in a message\n     */\n    MAX_FD_PER_MSG = 8\n};\n\n/**\n * Private class data stored in the trans 'extra_data' field\n */\nstruct libipm_priv\n{\n    enum libipm_facility facility;\n    unsigned int flags;\n    const char *(*msgno_to_str)(unsigned short msgno);\n    unsigned short out_msgno;\n    unsigned short out_param_count;\n    unsigned short out_fd_count;\n    int out_fds[MAX_FD_PER_MSG];\n    unsigned short in_msgno;\n    unsigned short in_param_count;\n    /** Pointer to next fd to be consumed by the app */\n    unsigned short in_fd_index;\n    /** Number of fds in the incoming message */\n    unsigned short in_fd_count;\n    int in_fds[MAX_FD_PER_MSG];\n};\n\n/**\n * Valid type-system characters\n *\n * Contains a list of all the types accepted by libipm_msg_out_append() and\n * libipm_msg_in_parse()\n */\nextern const char *libipm_valid_type_chars;\n\n/**\n * Close input file descriptors for an input message\n *\n * If file descriptors are read from the other end, but not passed to the\n * application, they must be closed to prevent file descriptor leaks\n *\n * @param self Transport to close file descriptors for\n */\nvoid\nlibipm_msg_in_close_file_descriptors(struct trans *self);\n\n#endif /* LIBIPM__PRIVATE_H */\n"
  },
  {
    "path": "libipm/libipm_recv.c",
    "content": "/**\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    libipm/libipm.c\n * @brief   Inter-Process Messaging building and parsing definitions\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdarg.h>\n\n#include \"libipm.h\"\n#include \"libipm_private.h\"\n#include \"libipm_facilities.h\"\n#include \"trans.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n/**************************************************************************//**\n * Checks the message header in the input stream, and gets the size\n */\nstatic enum libipm_status\nvalidate_msg_header(struct trans *trans, int *size)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    enum libipm_status rv = E_LI_BAD_HEADER;\n\n    int version;\n    int facility;\n    int reserved;\n\n    in_uint16_le(trans->in_s, version);\n    in_uint16_le(trans->in_s, *size);\n    in_uint16_le(trans->in_s, facility);\n    in_uint16_le(trans->in_s, priv->in_msgno);\n    in_uint32_le(trans->in_s, reserved);\n\n    if (version != LIBIPM_VERSION)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Unexpected version number %d from IPM\", version);\n    }\n    else if (*size < HEADER_SIZE || *size > LIBIPM_MAX_MSG_SIZE)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Invalid message length %d from IPM\", *size);\n    }\n    else if (facility != priv->facility)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Invalid facility %d from IPM - expected %d\",\n            facility, priv->facility);\n    }\n    else if (reserved != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Invalid reserved field %d from IPM\", reserved);\n    }\n    else\n    {\n        rv = E_LI_SUCCESS;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nenum libipm_status\nlibipm_msg_in_check_available(struct trans *trans, int *available)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n\n    *available = 0;\n\n    if (trans == NULL || trans->extra_data == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"Failed devel check\");\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else if (trans->status != TRANS_STATUS_UP)\n    {\n        rv = E_LI_PROGRAM_ERROR; /* Caller should have checked this */\n    }\n    else\n    {\n        unsigned int len = trans->in_s->end - trans->in_s->data; /* Data read so far */\n\n        if (len == trans->header_size)\n        {\n            if (trans->extra_flags == 0)\n            {\n                /* We've read the header so far - validate it */\n                int size;\n                rv = validate_msg_header(trans, &size);\n                if (rv == 0)\n                {\n                    /* Header is OK */\n                    trans->extra_flags = 1;\n                    trans->header_size = size;\n\n                    *available = (size == HEADER_SIZE);\n                }\n            }\n            else\n            {\n                *available = 1;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nenum libipm_status\nlibipm_msg_in_wait_available(struct trans *trans)\n{\n    tbus wobj[2]; // trans_get_wait_objs() can return at most 2 elements\n    int ocnt = 0;\n    enum libipm_status rv = E_LI_SUCCESS;\n\n    if (trans == NULL || trans->extra_data == NULL ||\n            trans->status != TRANS_STATUS_UP)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"Failed devel check\");\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else if (trans_get_wait_objs(trans, wobj, &ocnt) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't get wait object for libipm transport\");\n        rv = E_LI_TRANSPORT_ERROR;\n    }\n    else\n    {\n        int gotmsg = 0;\n        /* Prevent trans_check_wait_objs() actioning any callcacks\n         * when the message is complete */\n        ttrans_data_in saved_trans_data_in = trans->trans_data_in;\n        trans->trans_data_in = NULL;\n\n        while (rv == E_LI_SUCCESS && !gotmsg)\n        {\n            if (g_obj_wait(wobj, ocnt, NULL, 0, -1) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Error waiting on libipm transport\");\n                rv = E_LI_TRANSPORT_ERROR;\n            }\n            else if (trans_check_wait_objs(trans) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Error reading libipm transport\");\n                rv = E_LI_TRANSPORT_ERROR;\n            }\n            else\n            {\n                /* This call logs errors already */\n                rv = libipm_msg_in_check_available(trans, &gotmsg);\n            }\n        }\n\n        /* Restore transport callback operation */\n        trans->trans_data_in = saved_trans_data_in;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nunsigned short\nlibipm_msg_in_get_msgno(const struct trans *trans)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n\n    return (priv == NULL) ? 0 : priv->in_msgno;\n}\n\n/*****************************************************************************/\n\nchar\nlibipm_msg_in_peek_type(struct trans *trans)\n{\n    int result;\n\n    if (s_check_rem(trans->in_s, 1))\n    {\n        char c;\n        in_uint8_peek(trans->in_s, c);\n        if (g_strchr(libipm_valid_type_chars, c) != NULL)\n        {\n            result = c; /* Only return valid characters */\n        }\n        else\n        {\n            result = '?';\n        }\n    }\n    else\n    {\n        result = '\\0';\n    }\n\n    return result;\n}\n\n/**************************************************************************//**\n * Log an input parsing error\n *\n * @param trans libipm transport\n * @param format printf-like format descriptor\n */\nprintflike(2, 3) static void\nlog_parse_error(struct trans *trans, const char *format, ...)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    const char *msgno_str = NULL;\n    char msgno_str_buff[32];\n\n    char buff[256];\n    unsigned int len;\n\n    /* Find a string for the message number */\n    if (priv->msgno_to_str != NULL)\n    {\n        msgno_str = priv->msgno_to_str(priv->in_msgno);\n    }\n    if (msgno_str == NULL)\n    {\n        g_snprintf(msgno_str_buff, sizeof(msgno_str_buff),\n                   \"[code #%d]\", priv->in_msgno);\n        msgno_str = msgno_str_buff;\n    }\n\n    len = g_snprintf(buff, sizeof(buff),\n                     \"Error parsing ipm message for %s, parameter %d :\",\n                     msgno_str, priv->in_param_count);\n    if (len < sizeof(buff))\n    {\n        va_list ap;\n\n        va_start(ap, format);\n        vsnprintf(&buff[len], sizeof(buff) - len, format, ap);\n        va_end(ap);\n    }\n    LOG(LOG_LEVEL_ERROR, \"%s\", buff);\n}\n\n/* Common format string for overflow reporting */\nstatic const char *\nnot_enough_input_msg = \"Input buffer overflow for '%c'\";\n\n/**************************************************************************//**\n * Extract a bool from the input stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr Pointer to pointer to receive the value\n * @return != 0 for error\n *\n * The value must be a 0 or 1 on-the-wire, or an error is returned.\n */\nstatic enum libipm_status\nextract_bool_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->in_s;\n    int b;\n\n    if (!s_check_rem(s, 1))\n    {\n        log_parse_error(trans, not_enough_input_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        in_uint8(s, b);\n        if (b < 0 || b > 1)\n        {\n            log_parse_error(trans, \"Boolean has value other than 0/1\");\n            rv = E_LI_BAD_VALUE;\n        }\n        else\n        {\n            int *tmp = va_arg(*argptr, int *);\n            *tmp = b;\n        }\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Extract an octet from the input stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr argptr to pointer to receive the value\n * @return != 0 for error\n */\nstatic enum libipm_status\nextract_int8_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->in_s;\n\n    if (!s_check_rem(s, 1))\n    {\n        log_parse_error(trans, not_enough_input_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        unsigned char *tmp = va_arg(*argptr, unsigned char *);\n        in_uint8(s, *tmp);\n    }\n    return rv;\n}\n\n\n/**************************************************************************//**\n * Extract a 16-bit integer from the input stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr argptr to pointer to receive the value\n * @return != 0 for error\n */\nstatic enum libipm_status\nextract_int16_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->in_s;\n\n    if (!s_check_rem(s, 2))\n    {\n        log_parse_error(trans, not_enough_input_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        uint16_t *tmp = va_arg(*argptr, uint16_t *);\n        /*\n         * C99 7.18.1.1 requires int16_t (if present) to be a two's\n         * complement representation, so this line is valid for both\n         * int16_t and uint16_t */\n        in_uint16_le(s, *tmp);\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Extract a 32-bit integer from the input stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr argptr to pointer to receive the value\n * @return != 0 for error\n */\nstatic enum libipm_status\nextract_int32_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->in_s;\n\n    if (!s_check_rem(s, 4))\n    {\n        log_parse_error(trans, not_enough_input_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        uint32_t *tmp = va_arg(*argptr, uint32_t *);\n        /*\n         * C99 7.18.1.1 requires int32_t (if present) to be a two's\n         * complement representation, so this line is valid for both\n         * int32_t and uint32_t */\n        in_uint32_le(s, *tmp);\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Extract a 64-bit integer from the input stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr argptr to pointer to receive the value\n * @return != 0 for error\n */\nstatic enum libipm_status\nextract_int64_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->in_s;\n\n    if (!s_check_rem(s, 8))\n    {\n        log_parse_error(trans, not_enough_input_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        uint64_t *tmp = va_arg(*argptr, uint64_t *);\n        /*\n         * C99 7.18.1.1 requires int64_t (if present) to be a two's\n         * complement representation, so this line is valid for both\n         * int64_t and uint64_t */\n        in_uint64_le(s, *tmp);\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Extract a char * pointer from the input stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr argptr to pointer to receive the value\n * @return != 0 for error\n */\nstatic enum libipm_status\nextract_char_ptr_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->in_s;\n\n    /* Look for a string terminator in the rest of the input stream */\n    char *termptr = g_strnchr(s->p,  '\\0', s->end - s->p);\n\n    if (termptr == NULL)\n    {\n        log_parse_error(trans, \"Unterminated string value\");\n        rv = E_LI_BAD_VALUE;\n    }\n    else\n    {\n        char **tmp = va_arg(*argptr, char **);\n\n        *tmp = s->p;\n        s->p = termptr + 1;\n    }\n    return rv;\n}\n\n\n/**************************************************************************//**\n * Extract a file descriptor from the input stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr argptr to pointer to receive the value\n * @return != 0 for error\n */\nstatic enum libipm_status\nextract_fd_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n\n    /* File descriptor available? */\n    if (priv->in_fd_index >= priv->in_fd_count)\n    {\n        log_parse_error(trans, \"No file descriptors available\");\n        rv = E_LI_TOO_MANY_FDS;\n    }\n    else\n    {\n        int *tmp = va_arg(*argptr, int *);\n\n        *tmp = priv->in_fds[priv->in_fd_index++];\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Extract a fixed size block from the input stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr argptr to pointer to block descriptor\n * @return != 0 for error\n */\nstatic enum libipm_status\nextract_fsb_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->in_s;\n    const struct libipm_fsb *fsb = va_arg(*argptr, const struct libipm_fsb *);\n\n    if (fsb == NULL || fsb->data == NULL)\n    {\n        log_parse_error(trans, \"Malformed descriptor for '%c'\", c);\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else if (!s_check_rem(s, 2))\n    {\n        log_parse_error(trans, not_enough_input_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        unsigned int len;\n        in_uint16_le(s, len);\n\n        if (len != fsb->datalen)\n        {\n            log_parse_error(trans, \"Type '%c'. Expected %u bytes, but got %u\",\n                            c, fsb->datalen, len);\n            rv = E_LI_BAD_VALUE;\n        }\n        else if (!s_check_rem(s, len))\n        {\n            log_parse_error(trans, not_enough_input_msg, c);\n            rv = E_LI_BUFFER_OVERFLOW;\n        }\n        else\n        {\n            in_uint8a(s, fsb->data, len);\n            rv = E_LI_SUCCESS;\n        }\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Local function to pull data from the input stream\n *\n * @param trans libipm transport\n * @param format type-system compatible string\n * @param argptr Pointers to variables to receive extracted data\n * @pre - trans->priv has been checked to be non-NULL\n * @return != 0 for error\n */\nstatic enum libipm_status\nlibipm_msg_in_parsev(struct trans *trans, const char *format, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->in_s;\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    const char *cp;\n\n    if (format != NULL)\n    {\n        for (cp = format; rv == 0 && *cp != '\\0' ; ++cp)\n        {\n            char c = *cp;\n            char actual_c;\n            ++priv->in_param_count; /* Count the parameter */\n\n            /* Check the type of the input is supported */\n            if (g_strchr(libipm_valid_type_chars, c) == NULL)\n            {\n                log_parse_error(trans,\n                                \"Type code '%c' is not supported\", c);\n                rv = E_LI_UNSUPPORTED_TYPE;\n                break;\n            }\n\n            /* Check the type of the input matches the stream */\n            if (!s_check_rem(s, 1))\n            {\n                log_parse_error(trans, not_enough_input_msg, c);\n                rv = E_LI_BUFFER_OVERFLOW;\n                break;\n            }\n            in_uint8(s, actual_c);\n            if (c != actual_c)\n            {\n                log_parse_error(trans, \"Expected '%c', got '%c'\", c, actual_c);\n                rv = E_LI_UNEXPECTED_TYPE;\n                break;\n            }\n\n            switch (c)\n            {\n                case 'y':\n                    rv = extract_int8_type(c, trans, argptr);\n                    break;\n\n                case 'b':\n                    rv = extract_bool_type(c, trans, argptr);\n                    break;\n\n                case 'n':\n                case 'q':\n                    rv = extract_int16_type(c, trans, argptr);\n                    break;\n\n                case 'i':\n                case 'u':\n                    rv = extract_int32_type(c, trans, argptr);\n                    break;\n\n                case 'x':\n                case 't':\n                    rv = extract_int64_type(c, trans, argptr);\n                    break;\n\n                case 's':\n                    rv = extract_char_ptr_type(c, trans, argptr);\n                    break;\n\n                case 'h':\n                    rv = extract_fd_type(c, trans, argptr);\n                    break;\n\n                case 'B':\n                    rv = extract_fsb_type(c, trans, argptr);\n                    break;\n\n                default:\n                    log_parse_error(trans,\n                                    \"Reserved type code '%c' \"\n                                    \"is unimplemented\", c);\n                    rv = E_LI_UNIMPLEMENTED_TYPE;\n                    break;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nenum libipm_status\nlibipm_msg_in_parse(struct trans *trans, const char *format, ...)\n{\n    enum libipm_status rv;\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    if (priv == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"uninitialised transport\");\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else\n    {\n        va_list argptr;\n\n        va_start(argptr, format);\n        rv = libipm_msg_in_parsev(trans, format, &argptr);\n        va_end(argptr);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nvoid\nlibipm_msg_in_reset(struct trans *trans)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n\n    if (priv == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"uninitialised transport\");\n    }\n    else\n    {\n        if ((priv->flags & LIBIPM_E_MSG_IN_ERASE_AFTER_USE) != 0)\n        {\n            struct stream *s = trans->in_s;\n            g_memset(s->data, '\\0', s->end - s->data);\n            priv->flags &= ~LIBIPM_E_MSG_IN_ERASE_AFTER_USE;\n        }\n        priv->in_msgno = 0;\n        priv->in_param_count = 0;\n        libipm_msg_in_close_file_descriptors(trans);\n    }\n\n    trans->extra_flags = 0;\n    trans->header_size = HEADER_SIZE;\n    trans->no_stream_init_on_data_in = 1;\n    init_stream(trans->in_s, LIBIPM_MAX_MSG_SIZE);\n}\n"
  },
  {
    "path": "libipm/libipm_send.c",
    "content": "/**\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @file    libipm/libipm.c\n * @brief   Inter-Process Messaging building and parsing definitions\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdarg.h>\n\n#include \"libipm.h\"\n#include \"libipm_private.h\"\n#include \"libipm_facilities.h\"\n#include \"trans.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n/**************************************************************************//**\n * Log an output appending error\n *\n * @param trans libipm transport\n * @param format printf-like format descriptor\n */\nprintflike(2, 3) static void\nlog_append_error(struct trans *trans, const char *format, ...)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    const char *msgno_str = NULL;\n    char msgno_str_buff[32];\n\n    char buff[256];\n    unsigned int len;\n\n    /* Find a string for the message number */\n    if (priv->msgno_to_str != NULL)\n    {\n        msgno_str = priv->msgno_to_str(priv->out_msgno);\n    }\n    if (msgno_str == NULL)\n    {\n        g_snprintf(msgno_str_buff, sizeof(msgno_str_buff),\n                   \"[code #%d]\", priv->out_msgno);\n        msgno_str = msgno_str_buff;\n    }\n\n    len = g_snprintf(buff, sizeof(buff),\n                     \"Error creating ipm message for %s, parameter %d :\",\n                     msgno_str, priv->out_param_count);\n    if (len < sizeof(buff))\n    {\n        va_list ap;\n\n        va_start(ap, format);\n        vsnprintf(&buff[len], sizeof(buff) - len, format, ap);\n        va_end(ap);\n    }\n    LOG(LOG_LEVEL_ERROR, \"%s\", buff);\n}\n\n/* Common format string for overflow reporting */\nstatic const char *\nnot_enough_output_msg = \"Not enough space in output buffer for '%c'\";\n/* Common format string for bad value reporting */\nstatic const char *\nbad_value_msg = \"Type '%c' has unsupported value '%d'\";\n\n/**************************************************************************//**\n * Add a bool to the output stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr Pointer to value in argument stack (promoted to int)\n * @return != 0 for error\n *\n * The boolean value must be a 0 or a 1.\n */\nstatic enum libipm_status\nappend_bool_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->out_s;\n    if (!s_check_rem_out(s, 1 + 1))\n    {\n        log_append_error(trans, not_enough_output_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        int tmp = va_arg(*argptr, int);\n        if (tmp < 0 || tmp > 1)\n        {\n            log_append_error(trans, bad_value_msg, c, tmp);\n            rv = E_LI_BAD_VALUE;\n        }\n        else\n        {\n            out_uint8(s, c);\n            out_uint8(s, tmp);\n        }\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Add an octet to the output stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr Pointer to value in argument stack (promoted to int)\n * @return != 0 for error\n */\nstatic enum libipm_status\nappend_int8_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->out_s;\n    if (!s_check_rem_out(s, 1 + 1))\n    {\n        log_append_error(trans, not_enough_output_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        int tmp = va_arg(*argptr, int);\n        if (tmp < 0 || tmp > 255)\n        {\n            log_append_error(trans, bad_value_msg, c, tmp);\n            rv = E_LI_BAD_VALUE;\n        }\n        else\n        {\n            out_uint8(s, c);\n            out_uint8(s, tmp);\n        }\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Add an 16-bit integer to the output stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr Pointer to value in argument stack (promoted to int)\n * @return != 0 for error\n */\nstatic enum libipm_status\nappend_int16_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->out_s;\n    if (!s_check_rem_out(s, 1 + 2))\n    {\n        log_append_error(trans, not_enough_output_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        int tmp = va_arg(*argptr, int);\n        if ((c == 'n' && (tmp < -0x8000 || tmp > 0x7fff)) ||\n                (c == 'q' && (tmp < 0 || tmp > 0xffff)))\n        {\n            log_append_error(trans, bad_value_msg, c, tmp);\n            rv = E_LI_BAD_VALUE;\n        }\n        else\n        {\n            out_uint8(s, c);\n            out_uint16_le(s, tmp);\n        }\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Add a 32-bit integer to the output stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr Pointer to value in argument stack\n * @return != 0 for error\n */\nstatic enum libipm_status\nappend_int32_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->out_s;\n    if (!s_check_rem_out(s, 1 + 4))\n    {\n        log_append_error(trans, not_enough_output_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        /* If int is bigger than 4 bytes, the argument will be\n         * promoted to 'int' rather than 'int32_t'/'uint32_t',\n         * and we will need to check the specified value is in range.\n         */\n#if SIZEOF_INT > 4\n        int tmp = va_arg(*argptr, int);\n        if ((c == 'i' && (tmp < -0x80000000 || tmp > 0x7fffffff)) ||\n                (c == 'u' && (tmp < 0 || tmp > 0xffffffff)))\n        {\n            log_append_error(trans, bad_value_msg, c, tmp);\n            rv = E_LI_BAD_VALUE;\n        }\n        else\n        {\n            out_uint8(s, c);\n            out_uint32_le(s, tmp);\n        }\n#else\n        uint32_t tmp = va_arg(*argptr, uint32_t);\n        out_uint8(s, c);\n        out_uint32_le(s, tmp);\n#endif\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Add a 64-bit integer to the output stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr Pointer to value in argument stack\n * @return != 0 for error\n */\nstatic enum libipm_status\nappend_int64_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->out_s;\n    if (!s_check_rem_out(s, 1 + 8))\n    {\n        log_append_error(trans, not_enough_output_msg, c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else\n    {\n        uint64_t tmp = va_arg(*argptr, uint64_t);\n        out_uint8(s, c);\n        out_uint64_le(s, tmp);\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Add a terminated string to the output stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr Pointer to value in argument stack (promoted to int)\n * @return != 0 for error\n *\n * NULL pointers are not allowed for the string.\n */\nstatic enum libipm_status\nappend_char_ptr_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->out_s;\n    const char *str = va_arg(*argptr, const char *);\n    if (str == NULL)\n    {\n        log_append_error(trans, \"String cannot be NULL\");\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else\n    {\n        unsigned int len = g_strlen(str);\n\n        if ((len > (LIBIPM_MAX_MSG_SIZE - HEADER_SIZE - 1)) ||\n                (!s_check_rem_out(s, 1 + 1 + len)))\n        {\n            log_append_error(trans,\n                             \"Not enough space in output buffer for \"\n                             \"'%c'[len=%u]\", c, len);\n            rv = E_LI_BUFFER_OVERFLOW;\n        }\n        else\n        {\n            out_uint8(s, c);\n            out_uint8p(s, str, len + 1);\n        }\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Add a file descriptor to the output stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr Pointer to value in argument stack (promoted to int)\n * @return != 0 for error\n */\nstatic enum libipm_status\nappend_fd_type(char c, va_list *argptr, struct trans *trans)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->out_s;\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    int fd = va_arg(*argptr, int);\n    if (fd < 0)\n    {\n        log_append_error(trans, \"File descriptor cannot be < 0\");\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else if (!s_check_rem_out(s, 1))\n    {\n        log_append_error(trans,\n                         \"Not enough space in output buffer for '%c'\", c);\n        rv = E_LI_BUFFER_OVERFLOW;\n    }\n    else if (priv->out_fd_count >= MAX_FD_PER_MSG)\n    {\n        log_append_error(trans,\n                         \"Too many file descriptors for '%c'\", c);\n        rv = E_LI_TOO_MANY_FDS;\n    }\n    else\n    {\n        out_uint8(s, c);\n        priv->out_fds[priv->out_fd_count++] = fd;\n    }\n\n    return rv;\n}\n\n/**************************************************************************//**\n * Append a fixed size block to the output stream\n *\n * @param c Type letter which triggered the call\n * @param trans libipm transport\n * @param argptr argptr to pointer to block descriptor\n * @return != 0 for error\n */\nstatic enum libipm_status\nappend_fsb_type(char c, struct trans *trans, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct stream *s = trans->out_s;\n    const struct libipm_fsb *fsb = va_arg(*argptr, const struct libipm_fsb *);\n    if (fsb == NULL || fsb->data == NULL)\n    {\n        log_append_error(trans, \"Malformed descriptor for '%c'\", c);\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else\n    {\n        unsigned int len = fsb->datalen;\n\n        if ((len > (LIBIPM_MAX_MSG_SIZE - HEADER_SIZE - 2)) ||\n                (!s_check_rem_out(s, 1 + 2 + len)))\n        {\n            log_append_error(trans, \"Not enough space in output buffer\"\n                             \" for '%c'[len=%u]\", c, len);\n            rv = E_LI_BUFFER_OVERFLOW;\n        }\n        else\n        {\n            out_uint8(s, c);\n            out_uint16_le(s, len);\n            out_uint8a(s, fsb->data, len);\n        }\n    }\n    return rv;\n}\n\n/**************************************************************************//**\n * Local function to append data to the output stream\n *\n * @param trans libipm transport\n * @param format type-system compatible string\n * @param argptr Variables containing data to append\n * @pre - trans->priv has been checked to be non-NULL\n * @return != 0 for error\n */\nstatic enum libipm_status\nlibipm_msg_out_appendv(struct trans *trans, const char *format, va_list *argptr)\n{\n    enum libipm_status rv = E_LI_SUCCESS;\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    const char *cp;\n\n    if (format != NULL)\n    {\n        for (cp = format; rv == 0 && *cp != '\\0' ; ++cp)\n        {\n            char c = *cp;\n            ++priv->out_param_count; /* Count the parameter */\n            if (g_strchr(libipm_valid_type_chars, c) == NULL)\n            {\n                log_append_error(trans,\n                                 \"Type code '%c' is not supported\", c);\n                rv = E_LI_UNSUPPORTED_TYPE;\n                break;\n            }\n\n            switch (c)\n            {\n                case 'y':\n                    rv = append_int8_type(c, trans, argptr);\n                    break;\n\n                case 'b':\n                    rv = append_bool_type(c, trans, argptr);\n                    break;\n\n                case 'n':\n                case 'q':\n                    rv = append_int16_type(c, trans, argptr);\n                    break;\n\n                case 'i':\n                case 'u':\n                    rv = append_int32_type(c, trans, argptr);\n                    break;\n\n                case 'x':\n                case 't':\n                    rv = append_int64_type(c, trans, argptr);\n                    break;\n\n                case 's':\n                    rv = append_char_ptr_type(c, trans, argptr);\n                    break;\n\n                case 'h':\n                    rv = append_fd_type(c, argptr, trans);\n                    break;\n\n                case 'B':\n                    rv = append_fsb_type(c, trans, argptr);\n                    break;\n\n                default:\n                    log_append_error(trans,\n                                     \"Reserved type code '%c' \"\n                                     \"is unimplemented\", c);\n                    rv = E_LI_UNIMPLEMENTED_TYPE;\n                    break;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/**************************************************************************//**\n * Prepare the transport to build an output message\n * @param trans libipm trans\n * @param msgno Number of message\n */\nstatic void\ninit_output_buffer(struct trans *trans, unsigned short msgno)\n{\n    struct stream *s = trans->out_s;\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n\n    init_stream(s, LIBIPM_MAX_MSG_SIZE);\n\n    /* Leave space for header */\n    s_push_layer(s, iso_hdr, HEADER_SIZE);\n\n    priv->out_msgno = msgno;\n    priv->out_param_count = 0;\n    priv->out_fd_count = 0;\n}\n\n/*****************************************************************************/\n\nenum libipm_status\nlibipm_msg_out_init(struct trans *trans, unsigned short msgno,\n                    const char *format, ...)\n{\n    enum libipm_status rv;\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    if (priv == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"uninitialised transport\");\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else\n    {\n        va_list argptr;\n\n        init_output_buffer(trans, msgno);\n\n        va_start(argptr, format);\n        rv = libipm_msg_out_appendv(trans, format, &argptr);\n        va_end(argptr);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nenum libipm_status\nlibipm_msg_out_append(struct trans *trans, const char *format, ...)\n{\n    enum libipm_status rv;\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    if (priv == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"uninitialised transport\");\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else\n    {\n        va_list argptr;\n\n        va_start(argptr, format);\n        rv = libipm_msg_out_appendv(trans, format, &argptr);\n        va_end(argptr);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nvoid\nlibipm_msg_out_mark_end(struct trans *trans)\n{\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    if (priv == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"uninitialised transport\");\n    }\n    else\n    {\n        struct stream *s = trans->out_s;\n        s_mark_end(s);\n        s_pop_layer(s, iso_hdr);\n\n        /* Write the message header */\n        out_uint16_le(s, LIBIPM_VERSION);\n        out_uint16_le(s, s->end - s->data);\n        out_uint16_le(s, priv->facility);\n        out_uint16_le(s, priv->out_msgno);\n        out_uint32_le(s, 0); /* Reserved */\n\n        /* Move the output pointer back to the end so another\n         * append works, and so libipm_msg_out_erase() knows\n         * exactly what to do */\n        s->p = s->end;\n    }\n}\n\n/*****************************************************************************/\nenum libipm_status\nlibipm_msg_out_simple_send(struct trans *trans, unsigned short msgno,\n                           const char *format, ...)\n{\n    enum libipm_status rv;\n    struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;\n    if (priv == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"uninitialised transport\");\n        rv = E_LI_PROGRAM_ERROR;\n    }\n    else\n    {\n        va_list argptr;\n\n        va_start(argptr, format);\n        init_output_buffer(trans, msgno);\n\n        rv = libipm_msg_out_appendv(trans, format, &argptr);\n        if (rv == E_LI_SUCCESS)\n        {\n            libipm_msg_out_mark_end(trans);\n            if (trans_force_write(trans) != 0)\n            {\n                rv = E_LI_TRANSPORT_ERROR;\n            }\n        }\n        va_end(argptr);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nvoid\nlibipm_msg_out_erase(struct trans *trans)\n{\n    struct stream *s = trans->out_s;\n    if (s->size > 0 && s->data != 0)\n    {\n        g_memset(s->data, '\\0', s->p - s->data);\n    }\n}\n"
  },
  {
    "path": "libipm/scp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/scp.c\n * @brief scp definitions\n * @author Simone Fedele/ Matt Burt\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <ctype.h>\n\n#include \"scp.h\"\n#include \"libipm.h\"\n#include \"guid.h\"\n#include \"trans.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"xrdp_sockets.h\"\n\n/*****************************************************************************/\nstatic const char *\nmsgno_to_str(unsigned short n)\n{\n    return\n        (n == E_SCP_SET_PEERNAME_REQUEST) ? \"SCP_SET_PEERNAME_REQUEST\" :\n\n        (n == E_SCP_SYS_LOGIN_REQUEST) ? \"SCP_SYS_LOGIN_REQUEST\" :\n        (n == E_SCP_UDS_LOGIN_REQUEST) ? \"SCP_UDS_LOGIN_REQUEST\" :\n        (n == E_SCP_LOGIN_RESPONSE) ? \"SCP_LOGIN_RESPONSE\" :\n\n        (n == E_SCP_LOGOUT_REQUEST) ? \"SCP_LOGOUT_REQUEST\" :\n\n        (n == E_SCP_CREATE_SESSION_REQUEST) ? \"SCP_CREATE_SESSION_REQUEST\" :\n        (n == E_SCP_CREATE_SESSION_RESPONSE) ? \"SCP_CREATE_SESSION_RESPONSE\" :\n\n        (n == E_SCP_CONNECT_SESSION_REQUEST) ? \"SCP_CONNECT_SESSION_REQUEST\" :\n        (n == E_SCP_CONNECT_SESSION_RESPONSE) ? \"SCP_CONNECT_SESSION_RESPONSE\" :\n\n        (n == E_SCP_LIST_SESSIONS_REQUEST) ? \"SCP_LIST_SESSIONS_REQUEST\" :\n        (n == E_SCP_LIST_SESSIONS_RESPONSE) ? \"SCP_LIST_SESSIONS_RESPONSE\" :\n\n        (n == E_SCP_CLOSE_CONNECTION_REQUEST) ? \"SCP_CLOSE_CONNECTION_REQUEST\" :\n        NULL;\n}\n\n/*****************************************************************************/\nconst char *\nscp_msgno_to_str(enum scp_msg_code n, char *buff, unsigned int buff_size)\n{\n    const char *str = msgno_to_str((unsigned short)n);\n\n    if (str == NULL)\n    {\n        g_snprintf(buff, buff_size, \"[code #%d]\", (int)n);\n    }\n    else\n    {\n        g_snprintf(buff, buff_size, \"%s\", str);\n    }\n\n    return buff;\n}\n\n/*****************************************************************************/\n/**\n * Helper function returning 1 if the passed-in string is an integer >= 0\n */\nstatic int is_positive_int(const char *s)\n{\n    for ( ; *s != '\\0' ; ++s)\n    {\n        if (!isdigit(*s))\n        {\n            return 0;\n        }\n    }\n\n    return 1;\n}\n\n/*****************************************************************************/\nint\nscp_port_to_unix_domain_path(const char *port, char *buff,\n                             unsigned int bufflen)\n{\n    /* GOTCHA: Changes to this logic should be mirrored in\n     * scp_port_to_display_string() */\n\n    int result;\n\n    /* Make sure we can safely de-reference 'port' */\n    if (port == NULL)\n    {\n        port = \"\";\n    }\n\n    if (port[0] == '/')\n    {\n        result = g_snprintf(buff, bufflen, \"%s\", port);\n    }\n    else\n    {\n        const char *sep;\n        if ((sep = g_strrchr(port, '/')) != NULL && sep != port)\n        {\n            /* We allow the user to specify an absolute path, but not\n             * a relative one with embedded '/' characters */\n            LOG(LOG_LEVEL_WARNING, \"Ignoring path elements of '%s'\", port);\n            port = sep + 1;\n        }\n\n        if (port[0] == '\\0')\n        {\n            port = SCP_LISTEN_PORT_BASE_STR;\n        }\n        else if (is_positive_int(port))\n        {\n            /* Version v0.9.x and earlier of xrdp used a TCP port\n             * number. If we come across this, we'll ignore it for\n             * compatibility with old config files */\n            LOG(LOG_LEVEL_WARNING,\n                \"Ignoring obsolete SCP port value '%s'\", port);\n            port = SCP_LISTEN_PORT_BASE_STR;\n        }\n\n        result = g_snprintf(buff, bufflen, XRDP_SOCKET_ROOT_PATH \"/%s\", port);\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nint\nscp_port_to_display_string(const char *port, char *buff, unsigned int bufflen)\n{\n    /* Make sure we can safely de-reference 'port' */\n    if (port == NULL)\n    {\n        port = \"\";\n    }\n\n    /* Ignore any directories for the display */\n    const char *sep;\n    if ((sep = g_strrchr(port, '/')) != NULL)\n    {\n        port = sep + 1;\n    }\n\n    /* Check for a default */\n    if (port[0] == '\\0' || g_strcmp(port, \"3350\") == 0)\n    {\n        port = SCP_LISTEN_PORT_BASE_STR;\n    }\n\n    return g_snprintf(buff, bufflen, \"%s\", port);\n}\n\n/*****************************************************************************/\nstruct trans *\nscp_connect(const  char *port,\n            const char *peername,\n            int (*term_func)(void))\n{\n    char sock_path[256];\n    struct trans *t;\n\n    (void)scp_port_to_unix_domain_path(port, sock_path, sizeof(sock_path));\n    if ((t = trans_create(TRANS_MODE_UNIX, 128, 128)) != NULL)\n    {\n        t->is_term = term_func;\n\n        if (trans_connect(t, NULL, sock_path, 3000) != 0)\n        {\n            trans_delete(t);\n            t = NULL;\n        }\n        else if (scp_init_trans(t) != 0)\n        {\n            trans_delete(t);\n            t = NULL;\n        }\n        else if (scp_send_set_peername_request(t, peername) != 0)\n        {\n            trans_delete(t);\n            t = NULL;\n        }\n    }\n\n    return t;\n}\n\n/*****************************************************************************/\nint\nscp_init_trans(struct trans *trans)\n{\n    return libipm_init_trans(trans, LIBIPM_FAC_SCP, msgno_to_str);\n}\n\n/*****************************************************************************/\nstruct trans *\nscp_init_trans_from_fd(int fd, int trans_type, int (*term_func)(void))\n{\n    struct trans *result;\n    if ((result = trans_create(TRANS_MODE_UNIX, 128, 128)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't create SCP transport [%s]\",\n            g_get_strerror());\n    }\n    else\n    {\n        result->sck = fd;\n        result->type1 = trans_type;\n        result->status = TRANS_STATUS_UP;\n        result->is_term = term_func;\n\n        // Make sure child processes don't inherit our FD\n        (void)g_file_set_cloexec(result->sck, 1);\n\n        if (scp_init_trans(result) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"scp_init_trans() call failed\");\n            trans_delete(result);\n            result = NULL;\n        }\n    }\n\n    return result;\n}\n\n\n/*****************************************************************************/\nint\nscp_msg_in_check_available(struct trans *trans, int *available)\n{\n    return libipm_msg_in_check_available(trans, available);\n}\n\n/*****************************************************************************/\n\nint\nscp_msg_in_wait_available(struct trans *trans)\n{\n    return libipm_msg_in_wait_available(trans);\n}\n\n/*****************************************************************************/\n\nenum scp_msg_code\nscp_msg_in_get_msgno(const struct trans *trans)\n{\n    return (enum scp_msg_code)libipm_msg_in_get_msgno(trans);\n}\n\n/*****************************************************************************/\n\nvoid\nscp_msg_in_reset(struct trans *trans)\n{\n    libipm_msg_in_reset(trans);\n}\n\n/*****************************************************************************/\nint\nscp_send_set_peername_request(struct trans *trans,\n                              const char *peername)\n{\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_SCP_SET_PEERNAME_REQUEST,\n               \"s\",\n               peername);\n}\n\n/*****************************************************************************/\n\nint\nscp_get_set_peername_request(struct trans *trans,\n                             const char **peername)\n{\n    return libipm_msg_in_parse( trans, \"s\", peername);\n}\n\n\n/*****************************************************************************/\nint\nscp_send_uds_login_request(struct trans *trans)\n{\n    return libipm_msg_out_simple_send(trans,\n                                      (int)E_SCP_UDS_LOGIN_REQUEST,\n                                      NULL);\n}\n\n\n/*****************************************************************************/\nint\nscp_send_sys_login_request(struct trans *trans,\n                           const char *username,\n                           const char *password,\n                           const char *ip_addr)\n{\n    int rv;\n\n    rv = libipm_msg_out_simple_send(\n             trans,\n             (int)E_SCP_SYS_LOGIN_REQUEST,\n             \"sss\",\n             username,\n             password,\n             ip_addr);\n\n    /* Wipe the output buffer to remove the password */\n    libipm_msg_out_erase(trans);\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nscp_get_sys_login_request(struct trans *trans,\n                          const char **username,\n                          const char **password,\n                          const char **ip_addr)\n{\n    /* Make sure the buffer is cleared after processing this message */\n    libipm_set_flags(trans, LIBIPM_E_MSG_IN_ERASE_AFTER_USE);\n\n    return libipm_msg_in_parse( trans, \"sss\",\n                                username, password, ip_addr);\n}\n\n/*****************************************************************************/\n\nint\nscp_send_login_response(struct trans *trans,\n                        enum scp_login_status login_result,\n                        int server_closed,\n                        int uid)\n{\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_SCP_LOGIN_RESPONSE,\n               \"ibi\",\n               login_result,\n               (server_closed != 0), /* Convert to 0/1 */\n               uid);\n}\n\n/*****************************************************************************/\n\nint\nscp_get_login_response(struct trans *trans,\n                       enum scp_login_status *login_result,\n                       int *server_closed,\n                       int *uid)\n{\n    int32_t i_login_result = 0;\n    int32_t i_uid = 0;\n    int dummy;\n\n    /* User can pass in NULL for server_closed if they're trying an\n     * login method like UDS for which all fails are fatal. Likewise\n     * they may be uninterested in the uid */\n    if (server_closed == NULL)\n    {\n        server_closed = &dummy;\n    }\n    if (uid == NULL)\n    {\n        uid = &dummy;\n    }\n\n    int rv = libipm_msg_in_parse(trans, \"ibi\",\n                                 &i_login_result, server_closed, &i_uid);\n    if (rv == 0)\n    {\n        *login_result = (enum scp_login_status)i_login_result;\n        *uid = i_uid;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nscp_send_logout_request(struct trans *trans)\n{\n    return libipm_msg_out_simple_send( trans, (int)E_SCP_LOGOUT_REQUEST, NULL);\n}\n\n\n/*****************************************************************************/\n\nint\nscp_send_create_session_request(struct trans *trans,\n                                enum scp_session_type type,\n                                unsigned short width,\n                                unsigned short height,\n                                unsigned char bpp,\n                                const char *shell,\n                                const char *directory,\n                                const char *instance_name)\n{\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_SCP_CREATE_SESSION_REQUEST,\n               \"yqqysss\",\n               type,\n               width,\n               height,\n               bpp,\n               shell,\n               directory,\n               instance_name);\n}\n\n/*****************************************************************************/\n\nint\nscp_get_create_session_request(struct trans *trans,\n                               enum scp_session_type *type,\n                               unsigned short *width,\n                               unsigned short *height,\n                               unsigned char *bpp,\n                               const char **shell,\n                               const char **directory,\n                               const char **instance_name)\n{\n    /* Intermediate values */\n    uint8_t i_type;\n    uint16_t i_width;\n    uint16_t i_height;\n    uint8_t i_bpp;\n\n    int rv = libipm_msg_in_parse(\n                 trans,\n                 \"yqqysss\",\n                 &i_type,\n                 &i_width,\n                 &i_height,\n                 &i_bpp,\n                 shell,\n                 directory,\n                 instance_name);\n\n    if (rv == 0)\n    {\n        *type = (enum scp_session_type)i_type;\n        *width = i_width;\n        *height = i_height;\n        /* bpp is fixed for Xorg session types */\n        *bpp = (*type == SCP_SESSION_TYPE_XORG) ? 24 : i_bpp;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nscp_send_create_session_response(struct trans *trans,\n                                 enum scp_screate_status status,\n                                 const char *display,\n                                 const struct guid *guid)\n{\n    struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };\n\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_SCP_CREATE_SESSION_RESPONSE,\n               \"isB\",\n               status,\n               display,\n               &guid_descriptor);\n}\n\n/*****************************************************************************/\n\nint\nscp_get_create_session_response(struct trans *trans,\n                                enum scp_screate_status *status,\n                                const char **display,\n                                struct guid *guid)\n{\n    /* Intermediate values */\n    int32_t i_status;\n\n    const struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };\n\n    int rv = libipm_msg_in_parse(\n                 trans,\n                 \"isB\",\n                 &i_status,\n                 display,\n                 &guid_descriptor);\n    if (rv == 0)\n    {\n        *status = (enum scp_screate_status)i_status;\n    }\n    else\n    {\n        *display = \"\";\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nscp_send_connect_session_request(struct trans *trans,\n                                 const struct guid *guid,\n                                 const char *client_ip,\n                                 const char *client_name,\n                                 unsigned int flags)\n{\n    struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };\n\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_SCP_CONNECT_SESSION_REQUEST,\n               \"Bssu\", &guid_descriptor, client_ip, client_name, flags);\n}\n\n/*****************************************************************************/\n\nint\nscp_get_connect_session_request(struct trans *trans,\n                                struct guid *guid,\n                                const char **client_ip,\n                                const char **client_name,\n                                unsigned int *flags)\n{\n    struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };\n    /* Intermediate values */\n    uint32_t i_flags;\n\n    int rv = libipm_msg_in_parse(trans, \"Bssu\",\n                                 &guid_descriptor, client_ip, client_name,\n                                 &i_flags);\n\n    if (rv == 0)\n    {\n        *flags = i_flags;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nscp_send_connect_session_response(struct trans *trans,\n                                  enum scp_sconnect_status status,\n                                  int display_fd,\n                                  int chan_fd)\n{\n    int rv = libipm_msg_out_init(\n                 trans, (int)E_SCP_CONNECT_SESSION_RESPONSE,\n                 \"i\", status);\n    // Send the display file descriptor, guarded by a boolean\n    if (rv == 0)\n    {\n        if (display_fd >= 0)\n        {\n            rv = libipm_msg_out_append(\n                     trans, \"bh\", 1, display_fd);\n        }\n        else\n        {\n            rv = libipm_msg_out_append(trans, \"b\", 0);\n        }\n    }\n\n    // Send the chansrv file descriptor, guarded by a boolean\n    if (rv == 0)\n    {\n        if (chan_fd >= 0)\n        {\n            rv = libipm_msg_out_append(\n                     trans, \"bh\", 1, chan_fd);\n        }\n        else\n        {\n            rv = libipm_msg_out_append(trans, \"b\", 0);\n        }\n    }\n\n    if (rv == 0)\n    {\n        libipm_msg_out_mark_end(trans);\n        if (trans_force_write(trans) != 0)\n        {\n            rv = E_LI_TRANSPORT_ERROR;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/**\n * Helper function to get the file descriptors for a connect\n *\n * @param trans SCP trans\n * @param[out] display_fd Display server file descriptor\n * @param[out] chan_fd Chansrv file descriptor\n * @return != 0 for error\n *\n * This wrapper is nneded as libipm doesn't currently guarantee to\n * handle received file descriptors well if an error is encountered\n * mid-message.\n *\n * If an error is returned, some file descriptors may be valid.\n */\nstatic int\nget_connect_session_response_fds(struct trans *trans,\n                                 int *display_fd,\n                                 int *chan_fd)\n{\n    int rv;\n    int fd_present;\n\n    // Read the display server file descriptor and guard\n    if ((rv = libipm_msg_in_parse(trans, \"b\", &fd_present)) != 0)\n    {\n        return rv;\n    }\n    if (fd_present)\n    {\n        if ((rv = libipm_msg_in_parse(trans, \"h\", display_fd)) != 0)\n        {\n            return rv;\n        }\n    }\n\n    // Read the chansrv file descriptor and guard\n    if ((rv = libipm_msg_in_parse(trans, \"b\", &fd_present)) != 0)\n    {\n        return rv;\n    }\n    if (fd_present)\n    {\n        if ((rv = libipm_msg_in_parse(trans, \"h\", chan_fd)) != 0)\n        {\n            return rv;\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n\nint\nscp_get_connect_session_response(struct trans *trans,\n                                 enum scp_sconnect_status *status,\n                                 int *display_fd,\n                                 int *chan_fd)\n{\n    int rv;\n    /* Intermediate values */\n    int32_t i_status;\n\n    /* Set the returned FDs to nonsensical values to stop valid\n     * FDs getting clobbered */\n    *display_fd = -1;\n    *chan_fd = -1;\n\n    if ((rv = libipm_msg_in_parse( trans, \"i\", &i_status)) == 0)\n    {\n        // Us a helper function to get the file descriptors as this\n        // makes flow control easier.\n        rv = get_connect_session_response_fds(trans, display_fd, chan_fd);\n        if (rv == 0)\n        {\n            *status = (enum scp_sconnect_status)i_status;\n        }\n        else\n        {\n            // Close any fds we did receive to stop leaks\n            if (*display_fd >= 0)\n            {\n                g_file_close(*display_fd);\n                *display_fd = -1;\n            }\n            if (*chan_fd >= 0)\n            {\n                g_file_close(*chan_fd);\n                *chan_fd = -1;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nscp_send_list_sessions_request(struct trans *trans)\n{\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_SCP_LIST_SESSIONS_REQUEST,\n               NULL);\n}\n\n/*****************************************************************************/\n\nint\nscp_send_list_sessions_response(\n    struct trans *trans,\n    enum scp_list_sessions_status status,\n    const struct scp_session_info *info)\n{\n    int rv;\n\n    if (status != E_SCP_LS_SESSION_INFO)\n    {\n        rv = libipm_msg_out_simple_send(\n                 trans,\n                 (int)E_SCP_LIST_SESSIONS_RESPONSE,\n                 \"i\", status);\n    }\n    else\n    {\n        rv = libipm_msg_out_simple_send(\n                 trans,\n                 (int)E_SCP_LIST_SESSIONS_RESPONSE,\n                 \"iisyqqyxisssxs\",\n                 status,\n                 info->sid,\n                 info->display,\n                 info->type,\n                 info->width,\n                 info->height,\n                 info->bpp,\n                 (int64_t)info->start_time,\n                 info->uid,\n                 info->start_ip_addr,\n                 info->client_ip,\n                 info->client_name,\n                 (int64_t)info->last_connect_disconnect,\n                 info->xrdp_instance_name);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nscp_get_list_sessions_response(\n    struct trans *trans,\n    enum scp_list_sessions_status *status,\n    struct scp_session_info **info)\n{\n    int32_t i_status;\n    int rv;\n\n    if (info == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"Bad pointer in %s\", __func__);\n        rv = 1;\n    }\n    else if ((rv = libipm_msg_in_parse(trans, \"i\", &i_status)) == 0)\n    {\n        *status = (enum scp_list_sessions_status)i_status;\n        struct scp_session_info *p = NULL;\n\n        if (*status == E_SCP_LS_SESSION_INFO)\n        {\n            int32_t i_sid;\n            char *i_display;\n            uint8_t i_type;\n            uint16_t i_width;\n            uint16_t i_height;\n            uint8_t i_bpp;\n            int64_t i_start_time;\n            int32_t i_uid;\n            char *i_start_ip_addr;\n            char *i_client_ip;\n            char *i_client_name;\n            int64_t i_last_connect_disconnect;\n            char *i_instance_name;\n\n            rv = libipm_msg_in_parse(\n                     trans,\n                     \"isyqqyxisssxs\",\n                     &i_sid,\n                     &i_display,\n                     &i_type,\n                     &i_width,\n                     &i_height,\n                     &i_bpp,\n                     &i_start_time,\n                     &i_uid,\n                     &i_start_ip_addr,\n                     &i_client_ip,\n                     &i_client_name,\n                     &i_last_connect_disconnect,\n                     &i_instance_name);\n\n            if (rv == 0)\n            {\n                /* Allocate a block of memory large enough for the\n                 * structure result, and the strings it contains */\n                unsigned int len = sizeof(struct scp_session_info) +\n                                   g_strlen(i_display) + 1 +\n                                   g_strlen(i_start_ip_addr) + 1 +\n                                   g_strlen(i_client_ip) + 1 +\n                                   g_strlen(i_client_name) + 1 +\n                                   g_strlen(i_instance_name) + 1;\n                if ((p = (struct scp_session_info *)g_malloc(len, 1)) == NULL)\n                {\n                    *status = E_SCP_LS_NO_MEMORY;\n                }\n                else\n                {\n                    /* Set a pointer to access the strings after the block */\n                    char *memptr =\n                        (char *)p + sizeof(struct scp_session_info);\n#define COPY_STRING(ptr,src) \\\n    { \\\n        size_t len = strlen(src) + 1; \\\n        (ptr) = memptr; \\\n        memcpy(memptr, src, len); \\\n        memptr += len; \\\n    }\n                    /* Copy the data over */\n                    p->sid = i_sid;\n                    COPY_STRING(p->display, i_display);\n                    p->type = (enum scp_session_type)i_type;\n                    p->width = i_width;\n                    p->height = i_height;\n                    p->bpp = i_bpp;\n                    p->start_time = i_start_time;\n                    p->uid = i_uid;\n                    COPY_STRING(p->start_ip_addr, i_start_ip_addr);\n                    COPY_STRING(p->client_ip, i_client_ip);\n                    COPY_STRING(p->client_name, i_client_name);\n                    p->last_connect_disconnect = i_last_connect_disconnect;\n                    COPY_STRING(p->xrdp_instance_name, i_instance_name);\n#undef COPY_STRING\n                }\n            }\n        }\n        *info = p;\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nscp_send_create_sockdir_request(struct trans *trans)\n{\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_SCP_CREATE_SOCKDIR_REQUEST,\n               NULL);\n}\n\n\n/*****************************************************************************/\n\nint\nscp_send_create_sockdir_response(struct trans *trans,\n                                 enum scp_create_sockdir_status status)\n{\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_SCP_CREATE_SOCKDIR_RESPONSE,\n               \"i\", status);\n}\n\n/*****************************************************************************/\n\nint\nscp_get_create_sockdir_response(struct trans *trans,\n                                enum scp_create_sockdir_status *status)\n{\n    int32_t i_status = 0;\n    int rv = libipm_msg_in_parse(trans, \"i\", &i_status);\n    if (rv == 0)\n    {\n        *status = (enum scp_create_sockdir_status)i_status;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n\nint\nscp_send_close_connection_request(struct trans *trans)\n{\n    return libipm_msg_out_simple_send(\n               trans,\n               (int)E_SCP_CLOSE_CONNECTION_REQUEST,\n               NULL);\n}\n"
  },
  {
    "path": "libipm/scp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/scp.h\n * @brief scp declarations\n * @author Simone Fedele/ Matt Burt\n *\n * Functions in this file use the following naming conventions:-\n *\n * E_SCP_{msg}_REQUEST is sent by scp_send_{msg}_request()\n * E_SCP_{msg}_REQUEST is parsed by scp_get_{msg}_request()\n * E_SCP_{msg}_RESPONSE is sent by scp_send_{msg}_response()\n * E_SCP_{msg}_RESPONSE is parsed by scp_get_{msg}_response()\n */\n\n#ifndef SCP_H\n#define SCP_H\n\n#include \"arch.h\"\n\nstruct guid;\nstruct trans;\n\n#include \"scp_application_types.h\"\n\n/* Message codes */\nenum scp_msg_code\n{\n    E_SCP_SET_PEERNAME_REQUEST = 1,\n    // No E_SCP_SET_PEERNAME_RESPONSE\n\n    E_SCP_SYS_LOGIN_REQUEST,\n    E_SCP_UDS_LOGIN_REQUEST,\n    E_SCP_LOGIN_RESPONSE, /* Shared between login request types */\n\n    E_SCP_LOGOUT_REQUEST,\n    // No S_SCP_LOGOUT_RESPONSE\n\n    E_SCP_CREATE_SESSION_REQUEST,\n    E_SCP_CREATE_SESSION_RESPONSE,\n\n    E_SCP_CONNECT_SESSION_REQUEST,\n    E_SCP_CONNECT_SESSION_RESPONSE,\n\n    E_SCP_LIST_SESSIONS_REQUEST,\n    E_SCP_LIST_SESSIONS_RESPONSE,\n\n    E_SCP_CREATE_SOCKDIR_REQUEST,\n    E_SCP_CREATE_SOCKDIR_RESPONSE,\n\n    E_SCP_CLOSE_CONNECTION_REQUEST\n    // No E_SCP_CLOSE_CONNECTION_RESPONSE\n};\n\n/* Common facilities */\n\n/**\n * Convert a message code to a string for output\n * @param n Message code\n * @param buff to contain string\n * @param buff_size length of buff\n * @return buff is returned for convenience.\n */\nconst char *\nscp_msgno_to_str(enum scp_msg_code n, char *buff, unsigned int buff_size);\n\n/* Connection management facilities */\n\n/**\n * Maps a port definition to a UNIX domain socket path\n * @param port Port definition (e.g. from sesman.ini). Can be \"\" or NULL\n * @param buff Buffer for result\n * @param bufflen Length of buff\n *\n * @return Number of chars needed for result, excluding the '\\0'\n */\nint\nscp_port_to_unix_domain_path(const char *port, char *buff,\n                             unsigned int bufflen);\n\n/**\n * Maps a port definition to a displayable string\n * @param port Port definition (e.g. from sesman.ini). Can be \"\" or NULL\n * @param buff Buffer for result\n * @param bufflen Length of buff\n *\n * @return Number of chars needed for result, excluding the '\\0'\n *\n * This differs from scp_port_to_unix_domain_path() in that the result is\n * for displaying to the user (i.e. in a status message), rather than for\n * connecting to. For log messages, use the result of\n * scp_port_to_unix_domain_path()\n */\nint\nscp_port_to_display_string(const char *port, char *buff, unsigned int bufflen);\n\n/**\n * Connect to an SCP server\n *\n * @param port Port definition (e.g. from sesman.ini)\n * @param peername Name of this program or object (e.g. \"xrdp-sesadmin\")\n * @param term_func Function to poll during connection for program\n *         termination, or NULL for none.\n * @return Initialised SCP transport\n *\n * The returned transport has the is_term member set to term_func.\n */\nstruct trans *\nscp_connect(const char *port,\n            const char *peername,\n            int (*term_func)(void));\n\n/**\n * Converts a standard trans connected to an SCP endpoint to an SCP transport\n *\n * If you are running on a client, you may wish to use\n * scp_send_set_peername_request() after the connect to inform the\n * server who you are.\n *\n * @param trans connected endpoint\n * @return != 0 for error\n */\nint\nscp_init_trans(struct trans *trans);\n\n/**\n * Creates an SCP transport from a file descriptor\n *\n * If you are running on a client, you may wish to use\n * scp_send_set_peername_request() after the connect to inform the\n * server who you are.\n *\n * @param fd file descriptor\n * @param trans_type TRANS_TYPE_SERVER or TRANS_TYPE_CLIENT\n * @param term_func Function to poll during connection for program\n *         termination, or NULL for none.\n * @return SCP transport, or NULL\n */\nstruct trans *\nscp_init_trans_from_fd(int fd, int trans_type, int (*term_func)(void));\n\n/**\n * Checks an SCP transport to see if a complete message is\n * available for parsing\n *\n * @param trans SCP transport\n * @param[out] available != 0 if a complete message is available\n * @return != 0 for error\n */\nint\nscp_msg_in_check_available(struct trans *trans, int *available);\n\n/**\n * Waits on a single transport for an SCP message to be available for\n * parsing\n *\n * @param trans libipm transport\n * @return != 0 for error\n *\n * While the call is active, data-in callbacks for the transport are\n * disabled.\n *\n * Only use this call if you have nothing to do until a message\n * arrives on the transport. If you have other transports to service, use\n * scp_msg_in_check_available()\n */\nint\nscp_msg_in_wait_available(struct trans *trans);\n\n\n/**\n * Gets the SCP message number of an incoming message\n *\n * @param trans SCP transport\n * @return message in the buffer\n *\n * The results of calling this routine before scp_msg_in_check_available()\n * states a message is available are undefined.\n */\nenum scp_msg_code\nscp_msg_in_get_msgno(const struct trans *trans);\n\n/**\n * Resets an SCP message buffer ready to receive the next message\n *\n * @param trans libipm transport\n */\nvoid\nscp_msg_in_reset(struct trans *trans);\n\n/* -------------------- Setup messages--------------------  */\n\n/**\n * Send an E_SCP_SET_PEERNAME_REQUEST (SCP client)\n *\n * @param trans SCP transport\n * @param peername Peername\n * @return != 0 for error\n *\n * Server does not send a response\n *\n * This message is sent automatically by scp_connect(), but it can\n * be sent at any time.\n */\nint\nscp_send_set_peername_request(struct trans *trans,\n                              const char *peername);\n\n/**\n * Parse an incoming E_SCP_SET_PEERNAME_REQUEST message (SCP server)\n *\n * @param trans SCP transport\n * @param[out] peername peername\n * @return != 0 for error\n */\nint\nscp_get_set_peername_request(struct trans *trans,\n                             const char **peername);\n\n/* -------------------- Login messages--------------------  */\n\n/**\n * Send an E_SCP_UDS_LOGIN_REQUEST (SCP client)\n *\n * User is logged in using their socket details\n *\n * @param trans SCP transport\n * @return != 0 for error\n *\n * Server replies with E_SCP_LOGIN_RESPONSE\n */\nint\nscp_send_uds_login_request(struct trans *trans);\n\n/**\n * Send an E_SCP_SYS_LOGIN_REQUEST (SCP client)\n *\n * User is logged in using explicit credentials\n *\n * @param trans SCP transport\n * @param username Username\n * @param password Password\n * @param ip_addr IP address for the client (or \"\" if not known)\n * @return != 0 for error\n *\n * Server replies with E_SCP_LOGIN_RESPONSE\n */\nint\nscp_send_sys_login_request(struct trans *trans,\n                           const char *username,\n                           const char *password,\n                           const char *ip_addr);\n\n/**\n * Parse an incoming E_SCP_SYS_LOGIN_REQUEST message (SCP server)\n *\n * @param trans SCP transport\n * @param[out] username Username\n * @param[out] password Password\n * @param[out] ip_addr IP address for the client. May be \"\"\n * @return != 0 for error\n */\nint\nscp_get_sys_login_request(struct trans *trans,\n                          const char **username,\n                          const char **password,\n                          const char **ip_addr);\n\n/**\n * Send an E_SCP_LOGIN_RESPONSE (SCP server)\n *\n * @param trans SCP transport\n * @param login_result What happened to the login\n * @param server_closed If login fails, whether server has closed connection.\n *        If not, a retry can be made.\n * @param uid UID for a successful login\n * @return != 0 for error\n */\nint\nscp_send_login_response(struct trans *trans,\n                        enum scp_login_status login_result,\n                        int server_closed,\n                        int uid);\n\n/**\n * Parses an incoming E_SCP_LOGIN_RESPONSE (SCP client)\n *\n * @param trans SCP transport\n * @param[out] login_result 0 for success, PAM error code otherwise\n * @param[out] server_closed If login fails, whether server has closed\n *             connection. If not a retry can be made.\n * @param[out] uid UID for a successful login\n *\n * server_closed and uid can be passed NULL if the caller isn't interested.\n *\n * @return != 0 for error\n */\nint\nscp_get_login_response(struct trans *trans,\n                       enum scp_login_status *login_result,\n                       int *server_closed,\n                       int *uid);\n\n/**\n * Send an E_SCP_LOGOUT_REQUEST (SCP client)\n *\n * @param trans SCP transport\n * @return != 0 for error\n *\n * Logs the user out (if they are logged in), so that another\n * login request can be sent, maybe with a different user.\n *\n * A reply is not sent\n */\nint\nscp_send_logout_request(struct trans *trans);\n\n/* -------------------- Session messages--------------------  */\n\n/**\n * Send an E_SCP_CREATE_SESSION_REQUEST (SCP client)\n *\n * @param trans SCP transport\n * @param type Session type\n * @param width Initial session width\n * @param height Initial session height\n * @param bpp Session bits-per-pixel (ignored for Xorg sessions)\n * @param shell User program to run. May be \"\"\n * @param directory Directory to run the program in. May be \"\"\n * @param instance_name Name of xrdp instance. May be \"\"\n * @return != 0 for error\n *\n * Server replies with E_SCP_CREATE_SESSION_RESPONSE\n */\nint\nscp_send_create_session_request(struct trans *trans,\n                                enum scp_session_type type,\n                                unsigned short width,\n                                unsigned short height,\n                                unsigned char bpp,\n                                const char *shell,\n                                const char *directory,\n                                const char *instance_name);\n\n\n/**\n * Parse an incoming E_SCP_CREATE_SESSION_REQUEST (SCP server)\n *\n * @param trans SCP transport\n * @param[out] type Session type\n * @param[out] width Initial session width\n * @param[out] height Initial session height\n * @param[out] bpp Session bits-per-pixel (ignored for Xorg sessions)\n * @param[out] shell User program to run. May be \"\"\n * @param[out] directory Directory to run the program in. May be \"\"\n * @param[out] instance_name Name of xrdp instance. May be \"\"\n * @return != 0 for error\n *\n * Returned string pointers are valid until scp_msg_in_reset() is\n * called for the transport\n */\nint\nscp_get_create_session_request(struct trans *trans,\n                               enum scp_session_type *type,\n                               unsigned short *width,\n                               unsigned short *height,\n                               unsigned char *bpp,\n                               const char **shell,\n                               const char **directory,\n                               const char **instance_name);\n\n/**\n * Send an E_SCP_CREATE_SESSION_RESPONSE (SCP server)\n *\n * @param trans SCP transport\n * @param status Status of creation request\n * @param display Will be \"\" if create session failed\n * @param guid Guid for session. Should be all zeros if create session failed\n *\n * @return != 0 for error\n *\n * The display will be either \"X11-n\" (X11) or (e.g) \"wayland-0\" (Wayland)\n */\nint\nscp_send_create_session_response(struct trans *trans,\n                                 enum scp_screate_status status,\n                                 const char *display,\n                                 const struct guid *guid);\n\n\n/**\n * Parse an incoming E_SCP_CREATE_SESSION_RESPONSE (SCP client)\n *\n * @param trans SCP transport\n * @param[out] status Status of creation request\n * @param[out] display Will be \"\" if create session failed\n * @param[out] guid Guid for session. Should be all zeros if create session\n *                  failed\n *\n * @return != 0 for error\n */\nint\nscp_get_create_session_response(struct trans *trans,\n                                enum scp_screate_status *status,\n                                const char **display,\n                                struct guid *guid);\n\n/**\n * Send an E_SCP_CONNECT_SESSION_REQUEST (SCP client)\n *\n * @param trans SCP transport\n * @param guid Session guid\n * @param client_ip IP address of connecting client\n * @param client_name Name of connecting client (from RDP client core info)\n * @param flags Flags which affect the returned FDs\n * @return != 0 for error\n *\n * Server replies with E_SCP_CONNECT_SESSION_RESPONSE\n */\nint\nscp_send_connect_session_request(struct trans *trans,\n                                 const struct guid *guid,\n                                 const char *client_ip,\n                                 const char *client_name,\n                                 unsigned int flags);\n\n\n/**\n * Parse an incoming E_SCP_CONNECT_SESSION_REQUEST (SCP server)\n *\n * @param trans SCP transport\n * @param[out] guid Session guid\n * @param[out] client_ip IP address of connecting client\n * @param[out] client_name Name of connecting client\n * @param[out] flags Flags which affect the returned FDs\n * @return != 0 for error\n */\nint\nscp_get_connect_session_request(struct trans *trans,\n                                struct guid *guid,\n                                const char **client_ip,\n                                const char **client_name,\n                                unsigned int *flags);\n\n/**\n * Send an E_SCP_CONNECT_SESSION_RESPONSE (SCP server)\n *\n * @param trans SCP transport\n * @param status Status of connection request\n * @param display_fd File descriptor for display server\n * @param chan_fd File descriptor for chansrv, or -1 for no chansrv\n *\n * @return != 0 for error\n */\nint\nscp_send_connect_session_response(struct trans *trans,\n                                  enum scp_sconnect_status status,\n                                  int display_fd,\n                                  int chan_fd);\n\n\n/**\n * Parse an incoming E_SCP_CONNECT_SESSION_RESPONSE (SCP client)\n *\n * @param trans SCP transport\n * @param[out] status Status of connection request\n * @param[out] display_fd File descriptor for display server\n * @param[out] chan_fd File descriptor for chansrv, or -1 for no chansrv\n *\n * @return != 0 for error\n */\nint\nscp_get_connect_session_response(struct trans *trans,\n                                 enum scp_sconnect_status *status,\n                                 int *display_fd,\n                                 int *chan_fd);\n\n/**\n * Send an E_SCP_LIST_SESSIONS_REQUEST (SCP client)\n *\n * @param trans SCP transport\n * @return != 0 for error\n *\n * Server replies with one or more E_SCP_LIST_SESSIONS_RESPONSE\n */\nint\nscp_send_list_sessions_request(struct trans *trans);\n\n/**\n * Send an E_SCP_LIST_SESSIONS_RESPONSE (SCP server)\n *\n * @param trans SCP transport\n * @param status Status of request\n * @param info Session to send if status == E_SCL_LS_SESSION_INFO\n * @return != 0 for error\n */\nint\nscp_send_list_sessions_response(\n    struct trans *trans,\n    enum scp_list_sessions_status status,\n    const struct scp_session_info *info);\n\n/**\n * Parse an incoming E_SCP_LIST_SESSIONS_RESPONSE (SCP client)\n *\n * @param trans SCP transport\n * @param[out] status Status of request\n * @param[out] info Session if status == E_SCL_LS_SESSION_INFO\n * @return != 0 for error\n *\n * The session info is returned as a dynamically allocated structure.\n * After use the structure (and its members) can be de-allocated with\n * a single call to g_free()\n *\n * The info structures can be added to a 'struct list' with auto_free set.\n * When the list is de-allocated, all the structures will be de-allocated too.\n */\nint\nscp_get_list_sessions_response(\n    struct trans *trans,\n    enum scp_list_sessions_status *status,\n    struct scp_session_info **info);\n\n/**\n * Send an E_SCP_CREATE_SOCKDIR_REQUEST (SCP client)\n *\n * @param trans SCP transport\n * @return != 0 for error\n *\n * In some configurations, chansrv is not started by sesman. In this\n * instance, it may be necessary for the unprivileged sesman process to\n * ask sesman to create the sockets dir so sesman can populate it.\n *\n * Server replies with E_SCP_CREATE_SOCKDIR_RESPONSE\n */\nint\nscp_send_create_sockdir_request(struct trans *trans);\n\n/**\n * Send an E_SCP_CREATE_SOCKDIR_RESPONSE (SCP server)\n *\n * @param trans SCP transport\n * @param status Status of request\n * @return != 0 for error\n */\nint\nscp_send_create_sockdir_response(struct trans *trans,\n                                 enum scp_create_sockdir_status status);\n\n/**\n * Parse an incoming E_SCP_CREATE_SOCKDIR_RESPONSE (SCP client)\n *\n * @param trans SCP transport\n * @param[out] status Status of request\n * @return != 0 for error\n */\nint\nscp_get_create_sockdir_response(struct trans *trans,\n                                enum scp_create_sockdir_status *status);\n\n/**\n * Send an E_CLOSE_CONNECTION_REQUEST (SCP client)\n *\n * @param trans SCP transport\n * @return != 0 for error\n *\n * Server closes the connection quietly.\n */\nint\nscp_send_close_connection_request(struct trans *trans);\n\n\n#endif /* SCP_H */\n"
  },
  {
    "path": "libipm/scp_application_types.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/scp_application_types.c\n * @brief Support routines for types in scp_application_types.h\n * @author Matt Burt\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"scp_application_types.h\"\n#include \"os_calls.h\"\n\n/*****************************************************************************/\nconst char *\nscp_login_status_to_str(enum scp_login_status n,\n                        char *buff, unsigned int buff_size)\n{\n    const char *str =\n        (n == E_SCP_LOGIN_OK) ?  \"OK\" :\n        (n == E_SCP_LOGIN_ALREADY_LOGGED_IN) ? \"A user is already logged in\" :\n        (n == E_SCP_LOGIN_NO_MEMORY) ? \"No memory for login\" :\n        (n == E_SCP_LOGIN_NOT_AUTHENTICATED) ? \"User does not exist, or could not be authenticated\" :\n        (n == E_SCP_LOGIN_NOT_AUTHORIZED) ? \"User is not authorized\" :\n        (n == E_SCP_LOGIN_GENERAL_ERROR) ? \"General login error\" :\n        /* Default */ NULL;\n\n    if (str == NULL)\n    {\n        g_snprintf(buff, buff_size, \"[login error code #%d]\", (int)n);\n    }\n    else\n    {\n        g_snprintf(buff, buff_size, \"%s\", str);\n    }\n\n    return buff;\n}\n\n/*****************************************************************************/\nconst char *\nscp_screate_status_to_str(enum scp_screate_status n,\n                          char *buff, unsigned int buff_size)\n{\n    const char *str =\n        (n == E_SCP_SCREATE_OK) ? \"OK\" :\n        (n == E_SCP_SCREATE_NO_MEMORY) ? \"No memory for session\" :\n        (n == E_SCP_SCREATE_NOT_LOGGED_IN) ? \"Connection is not logged in\" :\n        (n == E_SCP_SCREATE_MAX_REACHED) ? \"Max session limit reached\" :\n        (n == E_SCP_SCREATE_NO_DISPLAY) ? \"No X displays are available\" :\n        (n == E_SCP_SCREATE_X_SERVER_FAIL) ? \"X server could not be started\" :\n        (n == E_SCP_SCREATE_SESSION_FAIL) ? \"Session failed immediately\" :\n        (n == E_SCP_SCREATE_IN_PROGRESS) ? \"Session creation is already in progress\" :\n        (n == E_SCP_SCREATE_GENERAL_ERROR) ? \"General session creation error\" :\n        /* Default */ NULL;\n\n    if (str == NULL)\n    {\n        g_snprintf(buff, buff_size, \"[session creation error code #%d]\",\n                   (int)n);\n    }\n    else\n    {\n        g_snprintf(buff, buff_size, \"%s\", str);\n    }\n\n    return buff;\n}\n\n/*****************************************************************************/\nconst char *\nscp_sconnect_status_to_str(enum scp_sconnect_status n,\n                           char *buff, unsigned int buff_size)\n{\n    const char *str =\n        (n == E_SCP_SCONNECT_OK) ? \"OK\" :\n        (n == E_SCP_SCONNECT_NOT_LOGGED_IN) ? \"Connection is not logged in\" :\n        (n == E_SCP_SCONNECT_NO_SUCH_GUID) ? \"No such session for this user\" :\n        (n == E_SCP_SCONNECT_NO_MEMORY) ? \"No memory for connection\" :\n        (n == E_SCP_SCONNECT_SERVER_FAIL) ? \"Can't connect to X server\" :\n        (n == E_SCP_SCONNECT_GENERAL_ERROR) ? \"General session connection error\" :\n\n        /* Default */ NULL;\n\n    if (str == NULL)\n    {\n        g_snprintf(buff, buff_size, \"[session connection error code #%d]\",\n                   (int)n);\n    }\n    else\n    {\n        g_snprintf(buff, buff_size, \"%s\", str);\n    }\n\n    return buff;\n}\n"
  },
  {
    "path": "libipm/scp_application_types.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/scp_application_types.h\n * @brief scp type declarations intended for use in the application\n * @author Simone Fedele/ Matt Burt\n */\n\n#ifndef SCP_APPLICATION_TYPES_H\n#define SCP_APPLICATION_TYPES_H\n\n#include <sys/types.h>\n\n/**\n * Select the desktop application session type\n */\nenum scp_session_type\n{\n    SCP_SESSION_TYPE_XVNC = 0,  ///< Session used Xvnc\n    SCP_SESSION_TYPE_XVNC_UDS,  ///< Session used Xvnc with UDS connection\n    SCP_SESSION_TYPE_XORG  ///< Session used Xorg + xorgxrdp\n};\n\n#define SCP_SESSION_TYPE_TO_STR(t) \\\n    ((t) == SCP_SESSION_TYPE_XVNC ? \"Xvnc\" : \\\n     (t) == SCP_SESSION_TYPE_XVNC_UDS ? \"Xvnc-UDS\" : \\\n     (t) == SCP_SESSION_TYPE_XORG ? \"Xorg\" : \\\n     \"unknown\" \\\n    )\n\n#define SCP_SESSION_TYPE_IS_X11(t) \\\n    ((t) >= SCP_SESSION_TYPE_XVNC && (t) <= SCP_SESSION_TYPE_XORG)\n\n/**\n * @brief Information to display about a particular sesman session\n */\nstruct scp_session_info\n{\n    int sid; ///< Session ID\n    char *display; ///< Display name (\"X11-n\" or \"wayland-n\")\n    enum scp_session_type type; ///< Session type\n    unsigned short width; ///< Initial session width\n    unsigned short height; ///< Initial session height\n    unsigned char bpp;  ///< Session bits-per-pixel\n    time_t start_time;  ///< When session was created\n    uid_t uid;     ///< Username for session\n    char *start_ip_addr; ///< IP address of starting client\n    char *client_ip;  ///< Current client IP\n    char *client_name; ///< Current client name\n    time_t last_connect_disconnect; ///< Time of last client connect/disconnect}\n    char *xrdp_instance_name; ///< Name of xrdp instance\n};\n\n/**\n * Status of a login request\n */\nenum scp_login_status\n{\n    E_SCP_LOGIN_OK = 0, ///< The connection is now loggned in\n    E_SCP_LOGIN_ALREADY_LOGGED_IN, ///< A user is currently logged in\n    E_SCP_LOGIN_NO_MEMORY, ///< Memory allocation failure\n    /**\n     * User couldn't be authenticated, or user doesn't exist */\n    E_SCP_LOGIN_NOT_AUTHENTICATED,\n    E_SCP_LOGIN_NOT_AUTHORIZED, ///< User is authenticated, but not authorized\n    E_SCP_LOGIN_GENERAL_ERROR ///< An unspecific error has occurred\n};\n\n/**\n * Convert an scp_login_status code to a readable string for output\n * @param n Message code\n * @param buff to contain string\n * @param buff_size length of buff\n * @return buff is returned for convenience.\n */\nconst char *\nscp_login_status_to_str(enum scp_login_status n,\n                        char *buff, unsigned int buff_size);\n\n/**\n * Status of a session creation request\n */\nenum scp_screate_status\n{\n    E_SCP_SCREATE_OK = 0, ///< Session created\n    E_SCP_SCREATE_NO_MEMORY, ///< Memory allocation failure\n    E_SCP_SCREATE_NOT_LOGGED_IN, ///< Connection is not logged in\n    E_SCP_SCREATE_MAX_REACHED, ///< Max number of sessions already reached\n    E_SCP_SCREATE_NO_DISPLAY, ///< No X server display number is available\n    E_SCP_SCREATE_X_SERVER_FAIL, ///< X server could not be started\n    E_SCP_SCREATE_SESSION_FAIL, ///< The session failed quickly\n    E_SCP_SCREATE_IN_PROGRESS, ///< A create session request is in progress\n    E_SCP_SCREATE_GENERAL_ERROR ///< An unspecific error has occurred\n};\n\n/**\n * Convert an scp_session creation code to a readable string for output\n * @param n Message code\n * @param buff to contain string\n * @param buff_size length of buff\n * @return buff is returned for convenience.\n */\nconst char *\nscp_screate_status_to_str(enum scp_screate_status n,\n                          char *buff, unsigned int buff_size);\n\n/*\n * Flags passed to scp_send_connect_session_request()\n */\n\n/**\n * Set this to get an FD for chansrv\n */\n#define E_SCP_SCONNECT_FLAG_NEED_CHANSRV (1<<0)\n\n/**\n * Status of a session connection request\n */\nenum scp_sconnect_status\n{\n    E_SCP_SCONNECT_OK = 0, ///< Session created\n    E_SCP_SCONNECT_NOT_LOGGED_IN, ///< Connection is not logged in\n    E_SCP_SCONNECT_NO_SUCH_GUID, ///< GUID does not exist for this user\n    E_SCP_SCONNECT_NO_MEMORY, ///< Memory allocation failure\n    E_SCP_SCONNECT_SERVER_FAIL, ///< Can't connect to X server\n    E_SCP_SCONNECT_GENERAL_ERROR ///< An unspecific error has occurred\n};\n\n/**\n * Convert an scp_session connection code to a readable string for output\n * @param n Message code\n * @param buff to contain string\n * @param buff_size length of buff\n * @return buff is returned for convenience.\n */\nconst char *\nscp_sconnect_status_to_str(enum scp_sconnect_status n,\n                           char *buff, unsigned int buff_size);\n\n/**\n * Status of an list sessions message\n */\nenum scp_list_sessions_status\n{\n    /**\n     * This message contains a valid session, and other messages\n     * will be sent\n     */\n    E_SCP_LS_SESSION_INFO = 0,\n\n    /**\n     * This message indicates the end of a list of sessions. No session\n     * is contained in the message */\n    E_SCP_LS_END_OF_LIST,\n\n    /**\n     * Client hasn't logged in yet\n     */\n    E_SCP_LS_NOT_LOGGED_IN = 100,\n    /**\n     * A client-side error occurred allocating memory for the session\n     */\n    E_SCP_LS_NO_MEMORY\n};\n\n/**\n * Status of a create sockdir message\n */\nenum scp_create_sockdir_status\n{\n    E_SCP_CS_OK = 0,\n\n    /**\n     * Client hasn't logged in yet\n     */\n    E_SCP_CS_NOT_LOGGED_IN = 100,\n\n    /**\n     * sesman failed to create the directory\n     */\n    E_SCP_CS_OTHER_ERROR\n};\n\n#endif /* SCP_APPLICATION_TYPES_H */\n"
  },
  {
    "path": "libipm/scp_sync.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file scp_sync.c\n * @brief scp definitions (synchronous calls)\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n//nclude \"tools_common.h\"\n//nclude \"trans.h\"\n#include \"os_calls.h\"\n#include \"log.h\"\n#include \"scp.h\"\n#include \"scp_sync.h\"\n\n/*****************************************************************************/\nint\nscp_sync_wait_specific(struct trans *t, enum scp_msg_code wait_msgno)\n{\n\n    int rv = 0;\n    int available = 0;\n\n    while (rv == 0 && !available)\n    {\n        if ((rv = scp_msg_in_wait_available(t)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Error waiting on sesman transport\");\n        }\n        else\n        {\n            enum scp_msg_code reply_msgno = scp_msg_in_get_msgno(t);\n\n            available = 1;\n            if (reply_msgno != wait_msgno)\n            {\n                char buff[64];\n                scp_msgno_to_str(reply_msgno, buff, sizeof(buff));\n\n                LOG(LOG_LEVEL_WARNING,\n                    \"Ignoring unexpected message %s\", buff);\n                scp_msg_in_reset(t);\n                available = 0;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nscp_sync_uds_login_request(struct trans *t)\n{\n    int rv = scp_send_uds_login_request(t);\n    if (rv == 0)\n    {\n        if ((rv = scp_sync_wait_specific(t, E_SCP_LOGIN_RESPONSE)) == 0)\n        {\n            enum scp_login_status login_result;\n            int server_closed;\n            rv = scp_get_login_response(t, &login_result, &server_closed, NULL);\n            if (rv == 0 && login_result != E_SCP_LOGIN_OK)\n            {\n                char msg[256];\n                scp_login_status_to_str(login_result, msg, sizeof(msg));\n                g_printf(\"Login failed; %s\\n\", msg);\n                rv = 1;\n                if (!server_closed)\n                {\n                    (void)scp_send_close_connection_request(t);\n                }\n            }\n            scp_msg_in_reset(t); // Done with this message\n        }\n\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nstruct list *\nscp_sync_list_sessions_request(struct trans *t)\n{\n    struct list *sessions = list_create();\n    if (sessions == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Out of memory for sessions list\");\n    }\n    else\n    {\n        int end_of_list = 0;\n\n        enum scp_list_sessions_status status;\n        struct scp_session_info *p;\n\n        int rv = scp_send_list_sessions_request(t);\n\n        sessions->auto_free = 1;\n\n        while (rv == 0 && !end_of_list)\n        {\n            rv = scp_sync_wait_specific(t, E_SCP_LIST_SESSIONS_RESPONSE);\n            if (rv != 0)\n            {\n                break;\n            }\n\n            rv = scp_get_list_sessions_response(t, &status, &p);\n            if (rv != 0)\n            {\n                break;\n            }\n\n            switch (status)\n            {\n                case E_SCP_LS_SESSION_INFO:\n                    if (!list_add_item(sessions, (tintptr)p))\n                    {\n                        g_free(p);\n                        LOG(LOG_LEVEL_ERROR, \"Out of memory for session item\");\n                        rv = 1;\n                    }\n                    break;\n\n                case E_SCP_LS_END_OF_LIST:\n                    end_of_list = 1;\n                    break;\n\n                default:\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Unexpected return code %d for session item\", status);\n                    rv = 1;\n            }\n            scp_msg_in_reset(t);\n        }\n\n        if (rv != 0)\n        {\n            list_delete(sessions);\n            sessions = NULL;\n        }\n    }\n\n    return sessions;\n}\n\n/*****************************************************************************/\nint\nscp_sync_create_sockdir_request(struct trans *t)\n{\n    int rv = scp_send_create_sockdir_request(t);\n    if (rv == 0)\n    {\n        rv = scp_sync_wait_specific(t, E_SCP_CREATE_SOCKDIR_RESPONSE);\n        if (rv == 0)\n        {\n            enum scp_create_sockdir_status status;\n            rv = scp_get_create_sockdir_response(t, &status);\n            if (rv == 0)\n            {\n                switch (status)\n                {\n                    case E_SCP_CS_OK:\n                        break;\n\n                    case E_SCP_CS_NOT_LOGGED_IN:\n                        LOG(LOG_LEVEL_ERROR, \"sesman reported not-logged-in\");\n                        rv = 1;\n                        break;\n\n                    case E_SCP_CS_OTHER_ERROR:\n                        LOG(LOG_LEVEL_ERROR,\n                            \"sesman reported fail on create directory\");\n                        rv = 1;\n                        break;\n                }\n            }\n            scp_msg_in_reset(t); // Done with this message\n            if (!rv)\n            {\n                (void)scp_send_close_connection_request(t);\n            }\n        }\n\n    }\n    return rv;\n}\n"
  },
  {
    "path": "libipm/scp_sync.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2022, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file libipm/scp_sync.h\n * @brief scp declarations (synchronous calls)\n * @author Simone Fedele/ Matt Burt\n *\n * This module places a synchronous wrapper on top of some of the\n * calls in scp.h. It is intended to be used for simple SCP applications\n * which do not need to handle SCP messages along with other messages\n * using the xrdp transport mechanism.\n *\n */\n\n#ifndef SCP_SYNC_H\n#define SCP_SYNC_H\n\n#include <scp.h>\n\n/**\n * Waits on a single transport for a specific SCP message to be available for\n * parsing\n *\n * @param t libipm transport\n * @param wait_msgno Message number to wait for\n * @return != 0 for error\n *\n * This is a convenience function, used to implement synchronous calls.\n *\n * While the call is active, data-in callbacks for the transport are\n * disabled.\n *\n * Unexpected messages are ignored and logged.\n *\n * Only use this call if you have nothing to do until a message\n * arrives on the transport.\n * - If you have other transports to service, use\n *   scp_msg_in_check_available()\n * - If you can process any incoming message, use\n *   scp_msg_in_wait_available()\n */\nint\nscp_sync_wait_specific(struct trans *t, enum scp_msg_code wait_msgno);\n\n/**\n * Send UDS login request to sesman and wait for answer\n *\n * @param t SCP transport\n * @return 0 for successful login\n *\n * If non-zero is returned, the scp_connection has been closed (if\n * appropriate) and simply remains to be deleted.\n */\nint\nscp_sync_uds_login_request(struct trans *t);\n\n/**\n * Send list sessions request to sesman and wait for answer(s)\n *\n * @param t SCP transport\n * @return list of sessions\n *\n * If NULL is returned, the scp_connection has been closed (if\n * appropriate) and simply remains to be deleted.\n *\n * If NULL is not returned, the caller must call list_delete() to\n * free it.\n */\nstruct list *\nscp_sync_list_sessions_request(struct trans *t);\n\n/**\n * Send sockdir creation request to sesman and wait for answer\n *\n * @param t SCP transport\n * @return 0 for successful response from sesman\n *\n * If non-zero is returned, the scp_connection has been closed (if\n * appropriate) and simply remains to be deleted.\n */\nint\nscp_sync_create_sockdir_request(struct trans *t);\n\n#endif /* SCP_SYNC_H */\n"
  },
  {
    "path": "libxrdp/Makefile.am",
    "content": "EXTRA_DIST = \\\n  xrdp_surface.c\n\nAM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -I$(top_srcdir)/common\n\nAM_CFLAGS = $(OPENSSL_CFLAGS)\n\nAM_LDFLAGS =\n\nLIBXRDP_EXTRA_LIBS =\n\nif XRDP_NEUTRINORDP\nAM_CPPFLAGS += -DXRDP_NEUTRINORDP\nLIBXRDP_EXTRA_LIBS += $(FREERDP_LIBS)\nendif\n\nif XRDP_RFXCODEC\nAM_CPPFLAGS += -DXRDP_RFXCODEC\nendif\n\nif XRDP_TJPEG\nAM_CPPFLAGS += -DXRDP_JPEG -DXRDP_TJPEG @TurboJpegIncDir@\nAM_LDFLAGS += @TurboJpegLibDir@\nLIBXRDP_EXTRA_LIBS += -lturbojpeg\nelse\nif XRDP_JPEG\nAM_CPPFLAGS += -DXRDP_JPEG\nLIBXRDP_EXTRA_LIBS += -ljpeg\nendif\nendif\n\nmodule_LTLIBRARIES = \\\n  libxrdp.la\n\nlibxrdp_la_SOURCES = \\\n  libxrdp.c \\\n  libxrdp.h \\\n  libxrdpinc.h \\\n  xrdp_bitmap32_compress.c \\\n  xrdp_bitmap_compress.c \\\n  xrdp_caps.c \\\n  xrdp_channel.c \\\n  xrdp_channel.h \\\n  xrdp_fastpath.c \\\n  xrdp_iso.c \\\n  xrdp_jpeg_compress.c \\\n  xrdp_mcs.c \\\n  xrdp_mppc_enc.c \\\n  xrdp_orders.c \\\n  xrdp_orders_rail.c \\\n  xrdp_orders_rail.h \\\n  xrdp_rdp.c \\\n  xrdp_sec.c\n\nlibxrdp_la_LIBADD = \\\n  $(top_builddir)/common/libcommon.la \\\n  $(LIBXRDP_EXTRA_LIBS)\n"
  },
  {
    "path": "libxrdp/libxrdp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * this is the interface to libxrdp\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n#include \"string_calls.h\"\n#include \"xrdp_orders_rail.h\"\n#include \"ms-rdpedisp.h\"\n#include \"ms-rdpbcgr.h\"\n\n#define MAX_BITMAP_BUF_SIZE (16 * 1024) /* 16K */\n#define TS_MONITOR_ATTRIBUTES_SIZE 20 /* [MS-RDPBCGR] 2.2.1.3.9 */\n\n/******************************************************************************/\nstruct xrdp_session *EXPORT_CC\nlibxrdp_init(struct xrdp_process *id, struct trans *trans, const char *xrdp_ini)\n{\n    struct xrdp_session *session;\n\n    session = (struct xrdp_session *)g_malloc(sizeof(struct xrdp_session), 1);\n    session->id = id;\n    session->trans = trans;\n    if (xrdp_ini != NULL)\n    {\n        session->xrdp_ini = g_strdup(xrdp_ini);\n    }\n    else\n    {\n        session->xrdp_ini = g_strdup(XRDP_CFG_PATH \"/xrdp.ini\");\n    }\n    session->rdp = xrdp_rdp_create(session, trans);\n    session->orders = xrdp_orders_create(session, session->rdp);\n    session->client_info = &session->rdp->client_info;\n    session->check_for_app_input = 1;\n    return session;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_exit(struct xrdp_session *session)\n{\n    if (session == 0)\n    {\n        return 0;\n    }\n\n    xrdp_orders_delete(session->orders);\n    xrdp_rdp_delete(session->rdp);\n    g_free(session->xrdp_ini);\n    g_free(session);\n    return 0;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_disconnect(struct xrdp_session *session, int errinfo)\n{\n    int rv = 0;\n    struct trans *trans = NULL;\n    struct xrdp_rdp *rdp = NULL;\n    int early_capability_flags = 0;\n\n    if (session != NULL)\n    {\n        trans = session->trans;\n        rdp = session->rdp;\n        if (session->client_info != NULL)\n        {\n            early_capability_flags =\n                session->client_info->mcs_early_capability_flags;\n        }\n    }\n\n    if (trans != NULL && trans->status == TRANS_STATUS_UP &&\n            trans->sck >= 0 && rdp != NULL)\n    {\n        /* Only send the error info PDU if the client has\n         * indicated it can receive it */\n        if ((early_capability_flags & RNS_UD_CS_SUPPORT_ERRINFO_PDU) != 0)\n        {\n            rv = xrdp_rdp_send_set_error(rdp, errinfo);\n        }\n\n        if (rv == 0)\n        {\n            rv = xrdp_rdp_send_deactivate(rdp);\n        }\n\n        if (rv == 0)\n        {\n            rv = xrdp_rdp_disconnect(rdp);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_process_incoming(struct xrdp_session *session)\n{\n    int rv;\n\n    rv = xrdp_rdp_incoming(session->rdp);\n    return rv;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_get_pdu_bytes(const char *aheader)\n{\n    int rv;\n    const tui8 *header;\n\n    rv = -1;\n    header = (const tui8 *) aheader;\n\n    if (header[0] == 0x03)\n    {\n        /* TPKT */\n        rv = (header[2] << 8) | header[3];\n    }\n    else\n    {\n        /* Fast-Path */\n        if (header[1] & 0x80)\n        {\n            rv = ((header[1] & 0x7F) << 8) | header[2];\n        }\n        else\n        {\n            rv = header[1];\n        }\n    }\n    return rv;\n}\n\n/******************************************************************************/\n/* only used during connection */\nstruct stream *\nlibxrdp_force_read(struct trans *trans)\n{\n    int bytes;\n    struct stream *s;\n\n    s = trans->in_s;\n    init_stream(s, 32 * 1024);\n\n    if (trans_force_read(trans, 4) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_force_read: header read error\");\n        return NULL;\n    }\n    bytes = libxrdp_get_pdu_bytes(s->data);\n    if (bytes < 4 || bytes > s->size)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_force_read: bad header length %d\", bytes);\n        return NULL;\n    }\n    if (trans_force_read(trans, bytes - 4) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_force_read: Can't read PDU\");\n        return NULL;\n    }\n    return s;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_process_data(struct xrdp_session *session, struct stream *s)\n{\n    int cont;\n    int rv;\n    int code;\n    int term;\n    int dead_lock_counter;\n    int do_read;\n    struct xrdp_rdp *rdp = session->rdp;\n\n    do_read = s == 0;\n    if (do_read && session->up_and_running)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_process_data: error logic\");\n        return 1;\n    }\n    if (session->in_process_data != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_process_data: error reentry\");\n        return 1;\n    }\n    session->in_process_data++;\n\n    term = 0;\n    cont = 1;\n    rv = 0;\n    dead_lock_counter = 0;\n\n    while ((cont || !session->up_and_running) && !term)\n    {\n        if (session->is_term != 0)\n        {\n            if (session->is_term())\n            {\n                term = 1;\n                break;\n            }\n        }\n\n        code = 0;\n\n        if (do_read)\n        {\n            if (s == 0)\n            {\n                s = libxrdp_force_read(session->trans);\n            }\n            else\n            {\n                if ((s->next_packet == 0) || (s->next_packet >= s->end))\n                {\n                    s = libxrdp_force_read(session->trans);\n                }\n            }\n            if (s == 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"libxrdp_process_data: libxrdp_force_read failed\");\n                rv = 1;\n                break;\n            }\n        }\n\n        if (xrdp_rdp_recv(rdp, s, &code) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"libxrdp_process_data: xrdp_rdp_recv failed\");\n            rv = 1;\n            break;\n        }\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_process_data code %d\", code);\n\n        switch (code)\n        {\n            case -1:\n                xrdp_caps_send_demand_active(rdp);\n                session->up_and_running = 0;\n                break;\n            case 0:\n                dead_lock_counter++;\n                break;\n            case PDUTYPE_CONFIRMACTIVEPDU:\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"Processing received \"\n                          \"[MS-RDPBCGR] PDUTYPE_CONFIRMACTIVEPDU\");\n                xrdp_caps_process_confirm_active(rdp, s);\n                break;\n            case PDUTYPE_DATAPDU:\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"Processing received \"\n                          \"[MS-RDPBCGR] PDUTYPE_DATAPDU\");\n                if (xrdp_rdp_process_data(rdp, s) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"libxrdp_process_data: xrdp_rdp_process_data failed\");\n                    cont = 0;\n                    term = 1;\n                }\n                break;\n            case 2: /* FASTPATH_INPUT_EVENT */\n                if (xrdp_fastpath_process_input_event(rdp->sec_layer->fastpath_layer, s) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"libxrdp_process_data: xrdp_fastpath_process_input_event failed\");\n                    cont = 0;\n                    term = 1;\n                }\n                break;\n            default:\n                LOG(LOG_LEVEL_WARNING, \"unknown code = %d (ignored)\", code);\n                dead_lock_counter++;\n                break;\n        }\n\n        if (dead_lock_counter > 100000)\n        {\n            /*This situation can happen and this is a workaround*/\n            cont = 0;\n            LOG(LOG_LEVEL_WARNING,\n                \"Serious programming error: we were locked in a deadly loop. \"\n                \"Remaining bytes: %d\", (int) (s->end - s->next_packet));\n            s->next_packet = 0;\n        }\n\n        if (cont)\n        {\n            cont = (s->next_packet != 0) && (s->next_packet < s->end);\n        }\n    }\n\n    session->in_process_data--;\n\n    return rv;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_send_palette(struct xrdp_session *session, int *palette)\n{\n    int rv;\n    int i = 0;\n    int color;\n    struct stream *s = (struct stream *)NULL;\n\n    if (session->client_info->bpp > 8)\n    {\n        return 0;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sending palette (%s)\",\n              ((session->client_info->use_fast_path & 1) ?\n               \"fastpath\" : \"slowpath\"));\n\n    /* clear orders */\n    libxrdp_orders_force_send(session);\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (session->client_info->use_fast_path & 1) /* fastpath output supported */\n    {\n        if (xrdp_rdp_init_fastpath(session->rdp, s) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"libxrdp_send_palette: xrdp_rdp_init_fastpath failed\");\n            free_stream(s);\n            return 1;\n        }\n    }\n    else\n    {\n        xrdp_rdp_init_data(session->rdp, s);\n    }\n\n    /* TS_UPDATE_PALETTE_DATA */\n    out_uint16_le(s, UPDATETYPE_PALETTE); /* updateType */\n    out_uint16_le(s, 0);   /* pad2Octets */\n    out_uint16_le(s, 256); /* # of colors (low-bytes) */\n    out_uint16_le(s, 0);   /* # of colors (high-bytes) */\n\n    /* paletteEntries */\n    for (i = 0; i < 256; i++)\n    {\n        color = palette[i];\n        out_uint8(s, color >> 16);\n        out_uint8(s, color >> 8);\n        out_uint8(s, color);\n    }\n\n    s_mark_end(s);\n    if (session->client_info->use_fast_path & 1) /* fastpath output supported */\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FP_UPDATE_PALETTE \"\n                  \"paletteUpdateData = { updateType %d (UPDATETYPE_PALETTE), \"\n                  \"pad2Octets <ignored>, numberColors 256, \"\n                  \"paletteEntries <omitted from log> }\", UPDATETYPE_PALETTE);\n        if (xrdp_rdp_send_fastpath(session->rdp, s,\n                                   FASTPATH_UPDATETYPE_PALETTE) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"libxrdp_send_palette: xrdp_rdp_send_fastpath failed\");\n            free_stream(s);\n            return 1;\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_UPDATE_PALETTE_DATA \"\n                  \"updateType %d (UPDATETYPE_PALETTE), pad2Octets <ignored>, \"\n                  \"numberColors 256, paletteEntries <omitted from log>\",\n                  UPDATETYPE_PALETTE);\n        xrdp_rdp_send_data(session->rdp, s, PDUTYPE2_UPDATE);\n    }\n    free_stream(s);\n    /* send the orders palette too */\n    rv = libxrdp_orders_init(session);\n    if (rv == 0)\n    {\n        rv = libxrdp_orders_send_palette(session, palette, 0);\n    }\n    if (rv == 0)\n    {\n        rv = libxrdp_orders_send(session);\n    }\n    return rv;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_send_bell(struct xrdp_session *session)\n{\n    struct stream *s = (struct stream *)NULL;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_rdp_init_data(session->rdp, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_send_bell: xrdp_rdp_init_data failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    out_uint32_le(s, 100); /* duration (ms) */\n    out_uint32_le(s, 440); /* frequency */\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_PLAY_SOUND_PDU_DATA \"\n              \"duration 100 ms, frequency 440 Hz\");\n\n    if (xrdp_rdp_send_data(session->rdp, s, PDUTYPE2_PLAY_SOUND) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_send_bell: xrdp_rdp_send_data failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Initialises either a TS_UPDATE_BITMAP or a TS_FP_UPDATE_BITMAP\n * PDU, depending on the fastpath output setting\n * @param session RDP session\n * @param s stream for PDU\n * @return != 0  for error\n */\nstatic int\ninit_bitmap_pdu(struct xrdp_session *session, struct stream *s)\n{\n    int rv;\n    if (session->client_info->use_fast_path & 1)\n    {\n        rv = xrdp_rdp_init_fastpath(session->rdp, s);\n        if (rv != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s: xrdp_rdp_init_fastpath failed\", __func__);\n        }\n    }\n    else\n    {\n        rv = xrdp_rdp_init_data(session->rdp, s);\n        if (rv != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s: xrdp_rdp_init_data failed\", __func__);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/**\n * Sends either a TS_UPDATE_BITMAP or a TS_FP_UPDATE_BITMAP\n * PDU, depending on the fastpath output setting\n * @param session RDP session\n * @param s stream for PDU\n * @return != 0  for error\n */\nstatic int\nsend_bitmap_pdu(struct xrdp_session *session, struct stream *s)\n{\n    int rv;\n    if (session->client_info->use_fast_path & 1)\n    {\n        rv = xrdp_rdp_send_fastpath(session->rdp, s,\n                                    FASTPATH_UPDATETYPE_BITMAP);\n        if (rv != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s: xrdp_rdp_send_fastpath failed\", __func__);\n        }\n    }\n    else\n    {\n        rv = xrdp_rdp_send_data(session->rdp, s, PDUTYPE2_UPDATE);\n        if (rv != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s: xrdp_rdp_send_data failed\", __func__);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_send_bitmap(struct xrdp_session *session, int width, int height,\n                    int bpp, char *data, int x, int y, int cx, int cy)\n{\n    int line_bytes = 0;\n    int i = 0;\n    int j = 0;\n    int k;\n    int total_lines = 0;\n    int lines_sending = 0;\n    int Bpp = 0;\n    int e = 0;\n    int bufsize = 0;\n    int total_bufsize = 0;\n    int num_updates = 0;\n    int line_pad_bytes;\n    int server_line_bytes;\n    char *p_num_updates = (char *)NULL;\n    char *p = (char *)NULL;\n    char *q = (char *)NULL;\n    struct stream *s = (struct stream *)NULL;\n    struct stream *temp_s = (struct stream *)NULL;\n    tui32 pixel;\n    int rv = 0;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: sending bitmap\");\n    Bpp = (bpp + 7) / 8;\n    e = (4 - width) & 3;\n    switch (bpp)\n    {\n        case 15:\n        case 16:\n            server_line_bytes = width * 2;\n            break;\n        case 24:\n        case 32:\n            server_line_bytes = width * 4;\n            break;\n        default: /* 8 bpp */\n            server_line_bytes = width;\n            break;\n    }\n    line_bytes = width * Bpp;\n    line_pad_bytes = line_bytes + e * Bpp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: bpp %d Bpp %d line_bytes %d \"\n              \"server_line_bytes %d\", bpp, Bpp, line_bytes, server_line_bytes);\n    make_stream(s);\n    init_stream(s, MAX_BITMAP_BUF_SIZE);\n\n    if (session->client_info->use_bitmap_comp)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: compression\");\n        make_stream(temp_s);\n        init_stream(temp_s, 65536);\n        i = 0;\n\n        if (cy <= height)\n        {\n            i = cy;\n        }\n\n        while (i > 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: i %d\", i);\n\n            total_bufsize = 0;\n            num_updates = 0;\n            if ((rv = init_bitmap_pdu(session, s)) != 0)\n            {\n                break;\n            }\n            out_uint16_le(s, UPDATETYPE_BITMAP); /* updateType */\n            p_num_updates = s->p;\n            out_uint8s(s, 2); /* num_updates set later */\n\n            do\n            {\n                if (session->client_info->op1)\n                {\n                    s_push_layer(s, channel_hdr, 18);\n                }\n                else\n                {\n                    s_push_layer(s, channel_hdr, 26);\n                }\n\n                p = s->p;\n\n                if (bpp > 24)\n                {\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: 32 bpp\");\n                    lines_sending = xrdp_bitmap32_compress(data, width, height,\n                                                           s, 32,\n                                                           (MAX_BITMAP_BUF_SIZE - 100) - total_bufsize,\n                                                           i - 1, temp_s, e, 0x10);\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: i %d lines_sending %d\",\n                              i, lines_sending);\n                }\n                else\n                {\n                    lines_sending = xrdp_bitmap_compress(data, width, height,\n                                                         s, bpp,\n                                                         (MAX_BITMAP_BUF_SIZE - 100) - total_bufsize,\n                                                         i - 1, temp_s, e);\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: i %d lines_sending %d\",\n                              i, lines_sending);\n                }\n\n                if (lines_sending == 0)\n                {\n                    break;\n                }\n\n                num_updates++;\n                bufsize = s->p - p;\n                total_bufsize += bufsize;\n                i = i - lines_sending;\n                s_mark_end(s);\n                s_pop_layer(s, channel_hdr);\n                out_uint16_le(s, x); /* left */\n                out_uint16_le(s, y + i); /* top */\n                out_uint16_le(s, (x + cx) - 1); /* right */\n                out_uint16_le(s, (y + i + lines_sending) - 1); /* bottom */\n                out_uint16_le(s, width + e); /* width */\n                out_uint16_le(s, lines_sending); /* height */\n                out_uint16_le(s, bpp); /* bpp */\n\n                if (session->client_info->op1)\n                {\n                    out_uint16_le(s, 0x401); /* compress */\n                    out_uint16_le(s, bufsize); /* compressed size */\n                    j = (width + e) * Bpp;\n                    j = j * lines_sending;\n                    total_bufsize += 18; /* bytes since pop layer */\n                }\n                else\n                {\n                    out_uint16_le(s, 0x1); /* compress */\n                    out_uint16_le(s, bufsize + 8);\n                    out_uint8s(s, 2); /* pad */\n                    out_uint16_le(s, bufsize); /* compressed size */\n                    j = (width + e) * Bpp;\n                    out_uint16_le(s, j); /* line size */\n                    j = j * lines_sending;\n                    out_uint16_le(s, j); /* final size */\n                    total_bufsize += 26; /* bytes since pop layer */\n                }\n\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: decompressed pixels %d \"\n                          \"decompressed bytes %d compressed bytes %d\",\n                          lines_sending * (width + e),\n                          line_pad_bytes * lines_sending, bufsize);\n\n                if (j > MAX_BITMAP_BUF_SIZE)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"libxrdp_send_bitmap: error, decompressed \"\n                        \"size too big: %d bytes\", j);\n                }\n\n                if (bufsize > MAX_BITMAP_BUF_SIZE)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"libxrdp_send_bitmap: error, compressed size \"\n                        \"too big: %d bytes\", bufsize);\n                }\n\n                s->p = s->end;\n            }\n            while (total_bufsize < MAX_BITMAP_BUF_SIZE && i > 0);\n\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: num_updates %d total_bufsize %d\",\n                      num_updates, total_bufsize);\n\n            p_num_updates[0] = num_updates;\n            p_num_updates[1] = num_updates >> 8;\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_UPDATE_BITMAP_DATA \"\n                      \"updateType %d (UPDATETYPE_BITMAP), numberRectangles %d, \"\n                      \"rectangles <omitted from log>\",\n                      UPDATETYPE_BITMAP, num_updates);\n            if ((rv = send_bitmap_pdu(session, s)) != 0)\n            {\n                break;\n            }\n\n            if (total_bufsize > MAX_BITMAP_BUF_SIZE)\n            {\n                LOG(LOG_LEVEL_WARNING, \"libxrdp_send_bitmap: error, total compressed \"\n                    \"size too big: %d bytes\", total_bufsize);\n            }\n        }\n\n        free_stream(temp_s);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_bitmap: no compression\");\n        total_lines = height;\n        i = 0;\n        p = data;\n\n        if (line_bytes > 0 && total_lines > 0)\n        {\n            while (i < total_lines)\n            {\n\n                lines_sending = (MAX_BITMAP_BUF_SIZE - 100) / line_pad_bytes;\n\n                if (i + lines_sending > total_lines)\n                {\n                    lines_sending = total_lines - i;\n                }\n\n                if (lines_sending == 0)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"libxrdp_send_bitmap: error, lines_sending == zero\");\n                    break;\n                }\n\n                p += server_line_bytes * lines_sending;\n                if ((rv = init_bitmap_pdu(session, s)) != 0)\n                {\n                    break;\n                }\n                out_uint16_le(s, UPDATETYPE_BITMAP);\n                out_uint16_le(s, 1); /* num updates */\n                out_uint16_le(s, x);\n                out_uint16_le(s, y + i);\n                out_uint16_le(s, (x + cx) - 1);\n                out_uint16_le(s, (y + i + lines_sending) - 1);\n                out_uint16_le(s, width + e);\n                out_uint16_le(s, lines_sending);\n                out_uint16_le(s, bpp); /* bpp */\n                out_uint16_le(s, 0); /* compress */\n                out_uint16_le(s, line_pad_bytes * lines_sending); /* bufsize */\n                q = p;\n\n                switch (bpp)\n                {\n                    case 8:\n                        for (j = 0; j < lines_sending; j++)\n                        {\n                            q = q - line_bytes;\n                            out_uint8a(s, q, line_bytes);\n                            out_uint8s(s, e);\n                        }\n                        break;\n                    case 15:\n                    case 16:\n                        for (j = 0; j < lines_sending; j++)\n                        {\n                            q = q - server_line_bytes;\n                            for (k = 0; k < width; k++)\n                            {\n                                pixel = *((tui16 *)(q + k * 2));\n                                out_uint16_le(s, pixel);\n                            }\n                            out_uint8s(s, e * 2);\n                        }\n                        break;\n                    case 24:\n                        for (j = 0; j < lines_sending; j++)\n                        {\n                            q = q - server_line_bytes;\n                            for (k = 0; k < width; k++)\n                            {\n                                pixel = *((tui32 *)(q + k * 4));\n                                out_uint8(s, pixel);\n                                out_uint8(s, pixel >> 8);\n                                out_uint8(s, pixel >> 16);\n                            }\n                            out_uint8s(s, e * 3);\n                        }\n                        break;\n                    case 32:\n                        for (j = 0; j < lines_sending; j++)\n                        {\n                            q = q - server_line_bytes;\n                            for (k = 0; k < width; k++)\n                            {\n                                pixel = *((int *)(q + k * 4));\n                                out_uint32_le(s, pixel);\n                            }\n                            out_uint8s(s, e * 4);\n                        }\n                        break;\n                }\n\n                s_mark_end(s);\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_UPDATE_BITMAP_DATA \"\n                          \"updateType %d (UPDATETYPE_BITMAP), numberRectangles 1, \"\n                          \"rectangles <omitted from log>\",\n                          UPDATETYPE_BITMAP);\n                if ((rv = send_bitmap_pdu(session, s)) != 0)\n                {\n                    break;\n                }\n                i = i + lines_sending;\n            }\n        }\n    }\n\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_send_pointer_system(struct xrdp_session *session, int pointer_type)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    xrdp_rdp_init_data(session->rdp, s);\n    out_uint16_le(s, TS_PTRMSGTYPE_SYSTEM);\n    out_uint16_le(s, 0); /* pad */\n    out_uint32_le(s, pointer_type);\n    s_mark_end(s);\n    xrdp_rdp_send_data(session->rdp, s, PDUTYPE2_POINTER);\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_send_pointer_position(struct xrdp_session *session, int x, int y)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    xrdp_rdp_init_data(session->rdp, s);\n    out_uint16_le(s, TS_PTRMSGTYPE_POSITION);\n    out_uint16_le(s, 0); /* pad */\n    out_uint16_le(s, x);\n    out_uint16_le(s, y);\n    s_mark_end(s);\n    xrdp_rdp_send_data(session->rdp, s, PDUTYPE2_POINTER);\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_send_pointer(struct xrdp_session *session, int cache_idx,\n                     char *data, char *mask, int x, int y, int bpp,\n                     int width, int height)\n{\n    struct stream *s;\n    char *p;\n    tui16 *p16;\n    tui32 *p32;\n    int i;\n    int j;\n    int data_bytes;\n    int mask_bytes;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sending cursor\");\n    if (bpp == 0)\n    {\n        bpp = 24;\n    }\n    if (width == 0)\n    {\n        width = 32;\n    }\n    if (height == 0)\n    {\n        height = 32;\n    }\n    /* error check */\n    if ((session->client_info->pointer_flags & 1) == 0)\n    {\n        if (bpp != 24)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Send pointer: client does not support \"\n                \"new cursors. The only valid bpp is 24, received %d\", bpp);\n            return 1;\n        }\n    }\n\n    if ((bpp != 15) && (bpp != 16) && (bpp != 24) && (bpp != 32))\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Send pointer: invalid bpp value. Expected 15, 16, 24 or 32, \"\n            \"received %d\", bpp);\n        return 1;\n    }\n    make_stream(s);\n    data_bytes = width * height * ((bpp + 7) / 8);\n    mask_bytes = width * height / 8;\n    init_stream(s, data_bytes + mask_bytes + 8192);\n    if (session->client_info->use_fast_path & 1) /* fastpath output supported */\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_pointer: fastpath\");\n        if (xrdp_rdp_init_fastpath(session->rdp, s) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"libxrdp_send_pointer: xrdp_rdp_init_fastpath failed\");\n            free_stream(s);\n            return 1;\n        }\n\n        if ((session->client_info->pointer_flags & 1) != 0)\n        {\n            out_uint16_le(s, bpp); /* TS_FP_POINTERATTRIBUTE -> newPointerUpdateData.xorBpp */\n        }\n    }\n    else /* slowpath */\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_send_pointer: slowpath\");\n        xrdp_rdp_init_data(session->rdp, s);\n        if ((session->client_info->pointer_flags & 1) == 0)\n        {\n            out_uint16_le(s, TS_PTRMSGTYPE_COLOR);\n            out_uint16_le(s, 0); /* pad */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_POINTER_PDU \"\n                      \"messageType %d (TS_PTRMSGTYPE_COLOR), pad2Octets <ignored>\",\n                      TS_PTRMSGTYPE_COLOR);\n        }\n        else\n        {\n            out_uint16_le(s, TS_PTRMSGTYPE_POINTER);\n            out_uint16_le(s, 0); /* pad */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_POINTER_PDU \"\n                      \"messageType %d (TS_PTRMSGTYPE_POINTER), pad2Octets <ignored>\",\n                      TS_PTRMSGTYPE_POINTER);\n\n            out_uint16_le(s, bpp); /* TS_POINTERATTRIBUTE -> xorBpp */\n        }\n    }\n\n    /* the TS_COLORPOINTERATTRIBUTE field which is shared by\n       all of the pointer attribute PDU types */\n    out_uint16_le(s, cache_idx);  /* cache_idx */\n    out_uint16_le(s, x);          /* hotSpot.xPos */\n    out_uint16_le(s, y);          /* hotSpot.yPos */\n    out_uint16_le(s, width);      /* width */\n    out_uint16_le(s, height);     /* height */\n    out_uint16_le(s, mask_bytes); /* lengthAndMask */\n    out_uint16_le(s, data_bytes); /* lengthXorMask */\n\n    /* xorMaskData */\n    switch (bpp)\n    {\n        case 15:\n        /* fallthrough */\n        case 16:\n            p16 = (tui16 *) data;\n            for (i = 0; i < height; i++)\n            {\n                for (j = 0; j < width; j++)\n                {\n                    out_uint16_le(s, *p16);\n                    p16++;\n                }\n            }\n            break;\n        case 24:\n            p = data;\n            for (i = 0; i < height; i++)\n            {\n                for (j = 0; j < width; j++)\n                {\n                    out_uint8(s, *p);\n                    p++;\n                    out_uint8(s, *p);\n                    p++;\n                    out_uint8(s, *p);\n                    p++;\n                }\n            }\n            break;\n        case 32:\n            p32 = (tui32 *) data;\n            for (i = 0; i < height; i++)\n            {\n                for (j = 0; j < width; j++)\n                {\n                    out_uint32_le(s, *p32);\n                    p32++;\n                }\n            }\n            break;\n    }\n\n    out_uint8a(s, mask, mask_bytes); /* andMaskData */\n    out_uint8(s, 0); /* pad */\n    s_mark_end(s);\n    if (session->client_info->use_fast_path & 1) /* fastpath output supported */\n    {\n        if ((session->client_info->pointer_flags & 1) == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FP_COLORPOINTERATTRIBUTE \"\n                      \"cachedPointerUpdateData = { cacheIndex %d, \"\n                      \"hotSpot.xPos %d, hotSpot.yPos %d, width %d, \"\n                      \"height %d, lengthAndMask %d, lengthXorMask %d, \"\n                      \"xorMaskData <omitted from log>, \"\n                      \"andMaskData <omitted from log> }\",\n                      cache_idx, x, y, width, height, mask_bytes, data_bytes);\n            if (xrdp_rdp_send_fastpath(session->rdp, s,\n                                       FASTPATH_UPDATETYPE_COLOR) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"libxrdp_send_pointer: xrdp_rdp_send_fastpath failed\");\n                free_stream(s);\n                return 1;\n            }\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FP_POINTERATTRIBUTE \"\n                      \"newPointerUpdateData.xorBpp %d, \"\n                      \"newPointerUpdateData.colorPtrAttr = { cacheIndex %d, \"\n                      \"hotSpot.xPos %d, hotSpot.yPos %d, width %d, \"\n                      \"height %d, lengthAndMask %d, lengthXorMask %d, \"\n                      \"xorMaskData <omitted from log>, \"\n                      \"andMaskData <omitted from log> }\",\n                      bpp, cache_idx, x, y, width, height, mask_bytes, data_bytes);\n            if (xrdp_rdp_send_fastpath(session->rdp, s,\n                                       FASTPATH_UPDATETYPE_POINTER) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"libxrdp_send_pointer: xrdp_rdp_send_fastpath failed\");\n                free_stream(s);\n                return 1;\n            }\n        }\n    }\n    else\n    {\n        if ((session->client_info->pointer_flags & 1) == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_COLORPOINTERATTRIBUTE \"\n                      \"cacheIndex %d, \"\n                      \"hotSpot.xPos %d, hotSpot.yPos %d, width %d, \"\n                      \"height %d, lengthAndMask %d, lengthXorMask %d, \"\n                      \"xorMaskData <omitted from log>, \"\n                      \"andMaskData <omitted from log>\",\n                      cache_idx, x, y, width, height, mask_bytes, data_bytes);\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_POINTERATTRIBUTE \"\n                      \"xorBpp %d, colorPtrAttr = { cacheIndex %d, \"\n                      \"hotSpot.xPos %d, hotSpot.yPos %d, width %d, \"\n                      \"height %d, lengthAndMask %d, lengthXorMask %d, \"\n                      \"xorMaskData <omitted from log>, \"\n                      \"andMaskData <omitted from log> }\",\n                      bpp, cache_idx, x, y, width, height, mask_bytes, data_bytes);\n        }\n        xrdp_rdp_send_data((struct xrdp_rdp *)session->rdp, s,\n                           PDUTYPE2_POINTER);\n    }\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_set_pointer(struct xrdp_session *session, int cache_idx)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (session->client_info->use_fast_path & 1) /* fastpath output supported */\n    {\n        if (xrdp_rdp_init_fastpath(session->rdp, s) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"libxrdp_set_pointer: xrdp_rdp_init_fastpath failed\");\n            free_stream(s);\n            return 1;\n        }\n    }\n    else\n    {\n        xrdp_rdp_init_data(session->rdp, s);\n        out_uint16_le(s, TS_PTRMSGTYPE_CACHED);\n        out_uint16_le(s, 0); /* pad */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_POINTER_PDU \"\n                  \"messageType %d (TS_PTRMSGTYPE_CACHED), pad2Octets <ignored>\",\n                  TS_PTRMSGTYPE_CACHED);\n    }\n\n    out_uint16_le(s, cache_idx); /* cache_idx */\n    s_mark_end(s);\n\n    if (session->client_info->use_fast_path & 1) /* fastpath output supported */\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FP_CACHEDPOINTERATTRIBUTE \"\n                  \"cachedPointerUpdateData.cacheIndex %d\", cache_idx);\n        if (xrdp_rdp_send_fastpath(session->rdp, s,\n                                   FASTPATH_UPDATETYPE_CACHED) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"libxrdp_set_pointer: xrdp_rdp_send_fastpath failed\");\n            free_stream(s);\n            return 1;\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_CACHEDPOINTERATTRIBUTE \"\n                  \"cacheIndex %d\", cache_idx);\n        xrdp_rdp_send_data(session->rdp, s, PDUTYPE2_POINTER);\n    }\n    free_stream(s);\n    return 0;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_init(struct xrdp_session *session)\n{\n    return xrdp_orders_init(session->orders);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send(struct xrdp_session *session)\n{\n    return xrdp_orders_send(session->orders);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_force_send(struct xrdp_session *session)\n{\n    return xrdp_orders_force_send(session->orders);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_rect(struct xrdp_session *session, int x, int y,\n                    int cx, int cy, int color, struct xrdp_rect *rect)\n{\n    return xrdp_orders_rect(session->orders, x, y, cx, cy, color, rect);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_screen_blt(struct xrdp_session *session, int x, int y,\n                          int cx, int cy, int srcx, int srcy,\n                          int rop, struct xrdp_rect *rect)\n{\n    return xrdp_orders_screen_blt(session->orders,\n                                  x, y, cx, cy, srcx, srcy, rop, rect);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_pat_blt(struct xrdp_session *session, int x, int y,\n                       int cx, int cy, int rop, int bg_color,\n                       int fg_color, struct xrdp_brush *brush,\n                       struct xrdp_rect *rect)\n{\n    return xrdp_orders_pat_blt(session->orders,\n                               x, y, cx, cy, rop, bg_color, fg_color,\n                               brush, rect);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_dest_blt(struct xrdp_session *session, int x, int y,\n                        int cx, int cy, int rop,\n                        struct xrdp_rect *rect)\n{\n    return xrdp_orders_dest_blt(session->orders, x, y, cx, cy, rop, rect);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_line(struct xrdp_session *session, int mix_mode,\n                    int startx, int starty,\n                    int endx, int endy, int rop, int bg_color,\n                    struct xrdp_pen *pen,\n                    struct xrdp_rect *rect)\n{\n    return xrdp_orders_line(session->orders,\n                            mix_mode, startx, starty, endx, endy,\n                            rop, bg_color, pen, rect);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_mem_blt(struct xrdp_session *session, int cache_id,\n                       int color_table, int x, int y, int cx, int cy,\n                       int rop, int srcx, int srcy,\n                       int cache_idx, struct xrdp_rect *rect)\n{\n    return xrdp_orders_mem_blt(session->orders,\n                               cache_id, color_table, x, y, cx, cy, rop,\n                               srcx, srcy, cache_idx, rect);\n}\n\n/******************************************************************************/\nint\nlibxrdp_orders_composite_blt(struct xrdp_session *session, int srcidx,\n                             int srcformat, int srcwidth, int srcrepeat,\n                             int *srctransform, int mskflags,\n                             int mskidx, int mskformat, int mskwidth,\n                             int mskrepeat, int op, int srcx, int srcy,\n                             int mskx, int msky, int dstx, int dsty,\n                             int width, int height, int dstformat,\n                             struct xrdp_rect *rect)\n{\n    return xrdp_orders_composite_blt(session->orders,\n                                     srcidx, srcformat, srcwidth, srcrepeat,\n                                     srctransform, mskflags,\n                                     mskidx, mskformat, mskwidth, mskrepeat,\n                                     op, srcx, srcy, mskx, msky, dstx, dsty,\n                                     width, height, dstformat, rect);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_text(struct xrdp_session *session,\n                    int font, int flags, int mixmode,\n                    int fg_color, int bg_color,\n                    int clip_left, int clip_top,\n                    int clip_right, int clip_bottom,\n                    int box_left, int box_top,\n                    int box_right, int box_bottom,\n                    int x, int y, char *data, int data_len,\n                    struct xrdp_rect *rect)\n{\n    return xrdp_orders_text(session->orders,\n                            font, flags, mixmode, fg_color, bg_color,\n                            clip_left, clip_top, clip_right, clip_bottom,\n                            box_left, box_top, box_right, box_bottom,\n                            x, y, data, data_len, rect);\n}\n\n/******************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_palette(struct xrdp_session *session, int *palette,\n                            int cache_id)\n{\n    return xrdp_orders_send_palette(session->orders,\n                                    palette, cache_id);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_raw_bitmap(struct xrdp_session *session,\n                               int width, int height, int bpp, char *data,\n                               int cache_id, int cache_idx)\n{\n    return xrdp_orders_send_raw_bitmap(session->orders,\n                                       width, height, bpp, data,\n                                       cache_id, cache_idx);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_bitmap(struct xrdp_session *session,\n                           int width, int height, int bpp, char *data,\n                           int cache_id, int cache_idx)\n{\n    return xrdp_orders_send_bitmap(session->orders,\n                                   width, height, bpp, data,\n                                   cache_id, cache_idx);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_font(struct xrdp_session *session,\n                         struct xrdp_font_char *font_char,\n                         int font_index, int char_index)\n{\n    return xrdp_orders_send_font(session->orders,\n                                 font_char, font_index, char_index);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_reset(struct xrdp_session *session)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_reset:\");\n\n    /* this will send any lingering orders */\n    if (xrdp_orders_reset(session->orders) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_reset: xrdp_orders_reset failed\");\n        return 1;\n    }\n\n    /*\n     * Stop output from the client during the deactivation-reactivation\n     * sequence [MS-RDPBCGR] 1.3.1.3 */\n    xrdp_rdp_suppress_output(session->rdp, 1,\n                             XSO_REASON_DEACTIVATE_REACTIVATE, 0, 0, 0, 0);\n\n    /* shut down the rdp client\n     *\n     * When resetting the lib, disable application input checks, as\n     * otherwise we can send a channel message to the other end while\n     * the channels are inactive ([MS-RDPBCGR] 3.2.5.5.1 */\n    session->check_for_app_input = 0;\n    if (xrdp_rdp_send_deactivate(session->rdp) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_reset: xrdp_rdp_send_deactivate failed\");\n        return 1;\n    }\n\n    /* this should do the resizing */\n    if (xrdp_caps_send_demand_active(session->rdp) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_reset: xrdp_caps_send_demand_active failed\");\n        return 1;\n    }\n\n    /* Re-enable application input checks */\n    session->check_for_app_input = 1;\n\n    return 0;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_raw_bitmap2(struct xrdp_session *session,\n                                int width, int height, int bpp, char *data,\n                                int cache_id, int cache_idx)\n{\n    return xrdp_orders_send_raw_bitmap2(session->orders,\n                                        width, height, bpp, data,\n                                        cache_id, cache_idx);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_bitmap2(struct xrdp_session *session,\n                            int width, int height, int bpp, char *data,\n                            int cache_id, int cache_idx, int hints)\n{\n    return xrdp_orders_send_bitmap2(session->orders,\n                                    width, height, bpp, data,\n                                    cache_id, cache_idx, hints);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_bitmap3(struct xrdp_session *session,\n                            int width, int height, int bpp, char *data,\n                            int cache_id, int cache_idx, int hints)\n{\n    return xrdp_orders_send_bitmap3(session->orders,\n                                    width, height, bpp, data,\n                                    cache_id, cache_idx, hints);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_get_channel_count(const struct xrdp_session *session)\n{\n    int count = 0;\n    const struct xrdp_rdp *rdp = (const struct xrdp_rdp *)session->rdp;\n    const struct xrdp_mcs *mcs = rdp->sec_layer->mcs_layer;\n\n    if (mcs->channel_list == NULL)\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"libxrdp_get_channel_count - No channel initialized\");\n    }\n    else\n    {\n        count = mcs->channel_list->count;\n    }\n\n    return count;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* this function gets the channel name and its flags, index is zero\n   based.  either channel_name or channel_flags can be passed in nil if\n   they are not needed */\nint EXPORT_CC\nlibxrdp_query_channel(struct xrdp_session *session, int channel_id,\n                      char *channel_name, int *channel_flags)\n{\n    int count = 0;\n    struct xrdp_rdp *rdp = session->rdp;\n    struct xrdp_mcs *mcs = rdp->sec_layer->mcs_layer;\n    struct mcs_channel_item *channel_item = (struct mcs_channel_item *)NULL;\n\n\n    if (mcs->channel_list == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_query_channel - No channel initialized\");\n        return 1 ;\n    }\n\n    count = mcs->channel_list->count;\n\n    if (channel_id < 0 || channel_id >= count)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_query_channel: Channel index out of range. \"\n            \"max channel index %d, received channel index %d\",\n            count, channel_id);\n        return 1;\n    }\n\n    channel_item = (struct mcs_channel_item *)\n                   list_get_item(mcs->channel_list, channel_id);\n\n    if (channel_item == NULL)\n    {\n        /* this should not happen */\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_query_channel - channel item is NULL\");\n        return 1;\n    }\n\n    if (channel_name != 0)\n    {\n        strlcpy(channel_name, channel_item->name, CHANNEL_NAME_LEN + 1);\n        LOG(LOG_LEVEL_DEBUG, \"libxrdp_query_channel - Channel %d name %s\",\n            channel_id, channel_name);\n    }\n\n    if (channel_flags != 0)\n    {\n        *channel_flags = channel_item->flags;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns a zero based index of the channel, -1 if error or it doesn't\n   exist */\nint EXPORT_CC\nlibxrdp_get_channel_id(struct xrdp_session *session, const char *name)\n{\n    int index = 0;\n    int count = 0;\n    struct xrdp_rdp *rdp = session->rdp;\n    struct xrdp_mcs *mcs = rdp->sec_layer->mcs_layer;\n    struct mcs_channel_item *channel_item = NULL;\n\n\n    if (mcs->channel_list == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_get_channel_id No channel initialized\");\n        return -1 ;\n    }\n\n    count = mcs->channel_list->count;\n\n    for (index = 0; index < count; index++)\n    {\n        channel_item = (struct mcs_channel_item *)\n                       list_get_item(mcs->channel_list, index);\n\n        if (channel_item != 0)\n        {\n            if (g_strcasecmp(name, channel_item->name) == 0)\n            {\n                return index;\n            }\n        }\n    }\n\n    return -1;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_send_to_channel(struct xrdp_session *session, int channel_id,\n                        char *data, int data_len,\n                        int total_data_len, int flags)\n{\n    struct xrdp_rdp *rdp = session->rdp;\n    struct xrdp_sec *sec = rdp->sec_layer;\n    struct xrdp_channel *chan = sec->chan_layer;\n    struct stream *s = NULL;\n\n    make_stream(s);\n    init_stream(s, data_len + 1024); /* this should be big enough */\n\n    if (xrdp_channel_init(chan, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_send_to_channel: xrdp_channel_init failed\");\n        free_stream(s);\n        return 1;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_TRACE, \"libxrdp_send_to_channel: xrdp_channel_init successful!\");\n    }\n\n    /* here we make a copy of the data */\n    out_uint8a(s, data, data_len);\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] Virtual Channel PDU \"\n              \"data <omitted from log>\");\n\n    if (xrdp_channel_send(chan, s, channel_id, total_data_len, flags) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_send_to_channel: xrdp_channel_send failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nlibxrdp_disable_channel(struct xrdp_session *session, int channel_id,\n                        int is_disabled)\n{\n    struct xrdp_rdp *rdp = session->rdp;\n    struct xrdp_mcs *mcs = rdp->sec_layer->mcs_layer;\n    struct mcs_channel_item *channel_item;\n\n    if (mcs->channel_list == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Channel list is NULL\");\n        return 1;\n    }\n    channel_item = (struct mcs_channel_item *)\n                   list_get_item(mcs->channel_list, channel_id);\n    if (channel_item == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Channel item is NULL\");\n        return 1;\n    }\n    channel_item->disabled = is_disabled;\n    LOG(LOG_LEVEL_DEBUG, \"%s channel %d (%s)\",\n        (is_disabled ? \"Disabling\" : \"Enabling\"), channel_item->chanid,\n        channel_item->name);\n    return 1;\n}\n\n/*****************************************************************************/\nint\nlibxrdp_drdynvc_start(struct xrdp_session *session)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_drdynvc_start:\");\n\n    struct xrdp_rdp *rdp = session->rdp;\n    struct xrdp_sec *sec = rdp->sec_layer;\n    struct xrdp_channel *chan = sec->chan_layer;\n\n    return xrdp_channel_drdynvc_start(chan);\n}\n\n\n/*****************************************************************************/\nint\nlibxrdp_drdynvc_open(struct xrdp_session *session, const char *name,\n                     int flags, struct xrdp_drdynvc_procs *procs,\n                     int *chan_id)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_drdynvc_open:\");\n\n    struct xrdp_rdp *rdp = session->rdp;\n    struct xrdp_sec *sec = rdp->sec_layer;\n    struct xrdp_channel *chan = sec->chan_layer;\n\n    return xrdp_channel_drdynvc_open(chan, name, flags, procs, chan_id);\n}\n\n/*****************************************************************************/\nint\nlibxrdp_drdynvc_close(struct xrdp_session *session, int chan_id)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_drdynvc_close:\");\n\n    struct xrdp_rdp *rdp = session->rdp;\n    struct xrdp_sec *sec = rdp->sec_layer;\n    struct xrdp_channel *chan = sec->chan_layer;\n\n    return xrdp_channel_drdynvc_close(chan, chan_id);\n}\n\n/*****************************************************************************/\nint\nlibxrdp_drdynvc_data_first(struct xrdp_session *session, int chan_id,\n                           const char *data, int data_bytes,\n                           int total_data_bytes)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_drdynvc_data_first:\");\n\n    struct xrdp_rdp *rdp = session->rdp;\n    struct xrdp_sec *sec = rdp->sec_layer;\n    struct xrdp_channel *chan = sec->chan_layer;\n\n    return xrdp_channel_drdynvc_data_first(chan, chan_id, data, data_bytes,\n                                           total_data_bytes);\n}\n\n/*****************************************************************************/\nint\nlibxrdp_drdynvc_data(struct xrdp_session *session, int chan_id,\n                     const char *data, int data_bytes)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_drdynvc_data:\");\n\n    struct xrdp_rdp *rdp = session->rdp;\n    struct xrdp_sec *sec = rdp->sec_layer;\n    struct xrdp_channel *chan = sec->chan_layer;\n\n    return xrdp_channel_drdynvc_data(chan, chan_id, data, data_bytes);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_brush(struct xrdp_session *session,\n                          int width, int height, int bpp, int type,\n                          int size, char *data, int cache_id)\n{\n    return xrdp_orders_send_brush(session->orders,\n                                  width, height, bpp, type, size, data,\n                                  cache_id);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_create_os_surface(struct xrdp_session *session, int id,\n                                      int width, int height,\n                                      struct list *del_list)\n{\n    return xrdp_orders_send_create_os_surface(session->orders, id,\n            width, height, del_list);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_orders_send_switch_os_surface(struct xrdp_session *session, int id)\n{\n    return xrdp_orders_send_switch_os_surface(session->orders, id);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_window_new_update(struct xrdp_session *session, int window_id,\n                          struct rail_window_state_order *window_state,\n                          int flags)\n{\n    return xrdp_orders_send_window_new_update(session->orders, window_id,\n            window_state, flags);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_window_delete(struct xrdp_session *session, int window_id)\n{\n    return xrdp_orders_send_window_delete(session->orders, window_id);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_window_icon(struct xrdp_session *session, int window_id,\n                    int cache_entry, int cache_id,\n                    struct rail_icon_info *icon_info, int flags)\n{\n    return xrdp_orders_send_window_icon(session->orders, window_id,\n                                        cache_entry, cache_id,\n                                        icon_info, flags);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_window_cached_icon(struct xrdp_session *session, int window_id,\n                           int cache_entry, int cache_id,\n                           int flags)\n{\n    return xrdp_orders_send_window_cached_icon(session->orders, window_id,\n            cache_entry, cache_id, flags);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_notify_new_update(struct xrdp_session *session,\n                          int window_id, int notify_id,\n                          struct rail_notify_state_order *notify_state,\n                          int flags)\n{\n    return xrdp_orders_send_notify_new_update(session->orders, window_id,\n            notify_id, notify_state, flags);\n}\n\n/*****************************************************************************/\nint\nlibxrdp_notify_delete(struct xrdp_session *session,\n                      int window_id, int notify_id)\n{\n    return xrdp_orders_send_notify_delete(session->orders, window_id,\n                                          notify_id);\n}\n\n/*****************************************************************************/\nint\nlibxrdp_monitored_desktop(struct xrdp_session *session,\n                          struct rail_monitored_desktop_order *mdo,\n                          int flags)\n{\n    return xrdp_orders_send_monitored_desktop(session->orders, mdo, flags);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_codec_jpeg_compress(struct xrdp_session *session,\n                            int format, char *inp_data,\n                            int width, int height,\n                            int stride, int x, int y,\n                            int cx, int cy, int quality,\n                            char *out_data, int *io_len)\n{\n    void *jpeg_han;\n\n    jpeg_han = session->orders->jpeg_han;\n    return xrdp_codec_jpeg_compress(jpeg_han, format, inp_data,\n                                    width, height, stride, x, y,\n                                    cx, cy, quality, out_data, io_len);\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_fastpath_send_surface(struct xrdp_session *session,\n                              char *data_pad, int pad_bytes,\n                              int data_bytes,\n                              int destLeft, int destTop,\n                              int destRight, int destBottom, int bpp,\n                              int codecID, int width, int height)\n{\n    struct stream ls;\n    struct stream *s;\n    struct xrdp_rdp *rdp = session->rdp;\n    int sec_bytes;\n    int rdp_bytes;\n    int max_bytes;\n    int cmd_bytes;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_fastpath_send_surface:\");\n    if ((session->client_info->use_fast_path & 1) == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Sending data via fastpath is disabled\");\n        return 1;\n    }\n    max_bytes = session->client_info->max_fastpath_frag_bytes;\n    if (max_bytes < 32 * 1024)\n    {\n        max_bytes = 32 * 1024;\n    }\n    rdp_bytes = xrdp_rdp_get_fastpath_bytes(rdp);\n    sec_bytes = xrdp_sec_get_fastpath_bytes(rdp->sec_layer);\n    cmd_bytes = 10 + 12;\n    if (data_bytes + rdp_bytes + sec_bytes + cmd_bytes > max_bytes)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Too much data to send via fastpath. \"\n            \"Max fastpath bytes %d, received bytes %d\",\n            max_bytes, (data_bytes + rdp_bytes + sec_bytes + cmd_bytes));\n        return 1;\n    }\n    if (sec_bytes + rdp_bytes + cmd_bytes > pad_bytes)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Too much header to send via fastpath. \"\n            \"Max fastpath header bytes %d, received bytes %d\",\n            pad_bytes, (rdp_bytes + sec_bytes + cmd_bytes));\n        return 1;\n    }\n    g_memset(&ls, 0, sizeof(ls));\n    s = &ls;\n    s->data = (data_pad + pad_bytes) - (rdp_bytes + sec_bytes + cmd_bytes);\n    s->sec_hdr = s->data;\n    s->rdp_hdr = s->sec_hdr + sec_bytes;\n    s->end = data_pad + pad_bytes + data_bytes;\n    s->size = s->end - s->data;\n    s->p = s->data + (rdp_bytes + sec_bytes);\n    /* TS_SURFCMD_STREAM_SURF_BITS */\n    out_uint16_le(s, CMDTYPE_STREAM_SURFACE_BITS);\n    out_uint16_le(s, destLeft);\n    out_uint16_le(s, destTop);\n    out_uint16_le(s, destRight);\n    out_uint16_le(s, destBottom);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_SURFCMD_STREAM_SURF_BITS \"\n              \"cmdType 0x%4.4x (CMDTYPE_STREAM_SURFACE_BITS), destLeft %d, \"\n              \"destTop %d, destRight %d, destBottom %d, \"\n              \"bitmapData <see TS_BITMAP_DATA_EX>\",\n              CMDTYPE_STREAM_SURFACE_BITS, destLeft, destTop, destRight,\n              destBottom);\n\n    /* TS_BITMAP_DATA_EX */\n    out_uint8(s, bpp);\n    out_uint8(s, 0);\n    out_uint8(s, 0);\n    out_uint8(s, codecID);\n    out_uint16_le(s, width);\n    out_uint16_le(s, height);\n    out_uint32_le(s, data_bytes);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding field bitmapData [MS-RDPBCGR] TS_BITMAP_DATA_EX \"\n              \"bpp %d, flags 0x00, reserved 0, codecID %d, width %d, \"\n              \"height %d, bitmapDataLength %d, exBitmapDataHeader <not present>, \"\n              \"bitmapData <omitted from log>\",\n              bpp, codecID, width, height, data_bytes);\n\n    if (xrdp_rdp_send_fastpath(rdp, s, FASTPATH_UPDATETYPE_SURFCMDS) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"libxrdp_fastpath_send_surface: xrdp_rdp_send_fastpath failed\");\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_fastpath_send_frame_marker(struct xrdp_session *session,\n                                   int frame_action, int frame_id)\n{\n    struct stream *s;\n    struct xrdp_rdp *rdp = session->rdp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"libxrdp_fastpath_send_frame_marker:\");\n    if ((session->client_info->use_fast_path & 1) == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Sending data via fastpath is disabled\");\n        return 1;\n    }\n    if (session->client_info->use_frame_acks == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Fastpath frame acks is disabled\");\n        return 1;\n    }\n    make_stream(s);\n    init_stream(s, 8192);\n    xrdp_rdp_init_fastpath(rdp, s);\n    out_uint16_le(s, CMDTYPE_FRAME_MARKER);\n    out_uint16_le(s, frame_action);\n    out_uint32_le(s, frame_id);\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FRAME_MARKER \"\n              \"cmdType 0x%4.4x (CMDTYPE_FRAME_MARKER), frameAction 0x%4.4x, \"\n              \"frameId %d\",\n              CMDTYPE_FRAME_MARKER, frame_action, frame_id);\n\n    if (xrdp_rdp_send_fastpath(rdp, s, FASTPATH_UPDATETYPE_SURFCMDS) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"libxrdp_fastpath_send_frame_marker: xrdp_rdp_send_fastpath failed\");\n        free_stream(s);\n        return 1;\n    }\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_send_session_info(struct xrdp_session *session, const char *data,\n                          int data_bytes)\n{\n    return xrdp_rdp_send_session_info(session->rdp, data, data_bytes);\n}\n\n/*****************************************************************************/\n/*\n   Sanitise extended monitor attributes\n\n   The extended attributes are received from either\n   [MS-RDPEDISP] 2.2.2.2.1 (DISPLAYCONTROL_MONITOR_LAYOUT), or\n   [MS-RDPBCGR] 2.2.1.3.9.1 (TS_MONITOR_ATTRIBUTES)\n\n   @param monitor_layout struct containing extended attributes\n*/\nstatic void\nsanitise_extended_monitor_attributes(struct monitor_info *monitor_layout)\n{\n    if (monitor_layout->physical_width == 0\n            && monitor_layout->physical_width == 0\n            && monitor_layout->orientation == 0\n            && monitor_layout->desktop_scale_factor == 0\n            && monitor_layout->device_scale_factor == 0)\n    {\n        /* Module expects us to provide defaults */\n        monitor_layout->orientation = ORIENTATION_LANDSCAPE;\n        monitor_layout->desktop_scale_factor = 100;\n        monitor_layout->device_scale_factor = 100;\n        return;\n    }\n\n    /* if EITHER physical_width or physical_height are\n     * out of range, BOTH must be ignored.\n     */\n    if (monitor_layout->physical_width > 10000\n            || monitor_layout->physical_width < 10)\n    {\n        LOG(LOG_LEVEL_WARNING, \"sanitise_extended_monitor_attributes:\"\n            \" physical_width is not within valid range.\"\n            \" Setting physical_width to 0mm,\"\n            \" Setting physical_height to 0mm,\"\n            \" physical_width was: %d\",\n            monitor_layout->physical_width);\n        monitor_layout->physical_width = 0;\n        monitor_layout->physical_height = 0;\n    }\n\n    if (monitor_layout->physical_height > 10000\n            || monitor_layout->physical_height < 10)\n    {\n        LOG(LOG_LEVEL_WARNING, \"sanitise_extended_monitor_attributes:\"\n            \" physical_height is not within valid range.\"\n            \" Setting physical_width to 0mm,\"\n            \" Setting physical_height to 0mm,\"\n            \" physical_height was: %d\",\n            monitor_layout->physical_height);\n        monitor_layout->physical_width = 0;\n        monitor_layout->physical_height = 0;\n    }\n\n    switch (monitor_layout->orientation)\n    {\n        case ORIENTATION_LANDSCAPE:\n        case ORIENTATION_PORTRAIT:\n        case ORIENTATION_LANDSCAPE_FLIPPED:\n        case ORIENTATION_PORTRAIT_FLIPPED:\n            break;\n        default:\n            LOG(LOG_LEVEL_WARNING, \"sanitise_extended_monitor_attributes:\"\n                \" Orientation is not one of %d, %d, %d, or %d.\"\n                \" Value was %d and ignored and set to default value of LANDSCAPE.\",\n                ORIENTATION_LANDSCAPE,\n                ORIENTATION_PORTRAIT,\n                ORIENTATION_LANDSCAPE_FLIPPED,\n                ORIENTATION_PORTRAIT_FLIPPED,\n                monitor_layout->orientation);\n            monitor_layout->orientation = ORIENTATION_LANDSCAPE;\n    }\n\n    int check_desktop_scale_factor\n        = monitor_layout->desktop_scale_factor < 100\n          || monitor_layout->desktop_scale_factor > 500;\n    if (check_desktop_scale_factor)\n    {\n        LOG(LOG_LEVEL_WARNING, \"sanitise_extended_monitor_attributes:\"\n            \" desktop_scale_factor is not within valid range\"\n            \" of [100, 500]. Assuming 100. Value was: %d\",\n            monitor_layout->desktop_scale_factor);\n    }\n\n    int check_device_scale_factor\n        = monitor_layout->device_scale_factor != 100\n          && monitor_layout->device_scale_factor != 140\n          && monitor_layout->device_scale_factor != 180;\n    if (check_device_scale_factor)\n    {\n        LOG(LOG_LEVEL_WARNING, \"sanitise_extended_monitor_attributes:\"\n            \" device_scale_factor a valid value (One of 100, 140, 180).\"\n            \" Assuming 100. Value was: %d\",\n            monitor_layout->device_scale_factor);\n    }\n\n    if (check_desktop_scale_factor || check_device_scale_factor)\n    {\n        monitor_layout->desktop_scale_factor = 100;\n        monitor_layout->device_scale_factor = 100;\n    }\n}\n\n/*****************************************************************************/\n/*\n   Process a [MS-RDPBCGR] TS_UD_CS_MONITOR message.\n   reads the client monitors data\n*/\nint\nlibxrdp_process_monitor_stream(struct stream *s,\n                               struct display_size_description *description,\n                               int full_parameters)\n{\n    uint32_t num_monitor;\n    uint32_t monitor_index;\n    struct monitor_info monitors[CLIENT_MONITOR_DATA_MAXIMUM_MONITORS];\n    struct monitor_info *monitor_layout;\n    int monitor_struct_stream_check_bytes;\n    const char *monitor_struct_stream_check_message;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_process_monitor_stream:\");\n    if (description == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR,\n                  \"libxrdp_process_monitor_stream: description was\"\n                  \" null. Valid pointer to allocated description expected.\");\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n\n    if (!s_check_rem_and_log(s, 4,\n                             \"libxrdp_process_monitor_stream:\"\n                             \" Parsing [MS-RDPBCGR] TS_UD_CS_MONITOR\"))\n    {\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n\n    in_uint32_le(s, num_monitor);\n    LOG(LOG_LEVEL_DEBUG, \"libxrdp_process_monitor_stream:\"\n        \" The number of monitors received is: %d\",\n        num_monitor);\n\n    if (num_monitor >= CLIENT_MONITOR_DATA_MAXIMUM_MONITORS)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"libxrdp_process_monitor_stream: [MS-RDPBCGR] Protocol\"\n            \" error: TS_UD_CS_MONITOR monitorCount\"\n            \" MUST be less than %d, received: %d\",\n            CLIENT_MONITOR_DATA_MAXIMUM_MONITORS, num_monitor);\n        return SEC_PROCESS_MONITORS_ERR_TOO_MANY_MONITORS;\n    }\n\n    /*\n     * Unfortunately the structure length values aren't directly defined in the\n     * Microsoft specifications. They are derived from the lengths of the\n     * specific structures referenced below.\n     */\n    if (full_parameters == 0)\n    {\n        monitor_struct_stream_check_bytes = 20;\n        monitor_struct_stream_check_message =\n            \"libxrdp_process_monitor_stream: Parsing monitor definitions\"\n            \" from [MS-RDPBCGR] 2.2.1.3.6.1 Monitor Definition\"\n            \" (TS_MONITOR_DEF).\";\n    }\n    else\n    {\n        monitor_struct_stream_check_bytes = 40;\n        monitor_struct_stream_check_message =\n            \"libxrdp_process_monitor_stream: Parsing monitor definitions\"\n            \" from [MS-RDPEDISP] 2.2.2.2.1 DISPLAYCONTROL_MONITOR_LAYOUT.\";\n    }\n\n    memset(monitors, 0, sizeof(monitors[0]) * num_monitor);\n\n    for (monitor_index = 0; monitor_index < num_monitor; ++monitor_index)\n    {\n        if (!s_check_rem_and_log(\n                    s,\n                    monitor_struct_stream_check_bytes,\n                    monitor_struct_stream_check_message))\n        {\n            return SEC_PROCESS_MONITORS_ERR;\n        }\n\n        monitor_layout = &monitors[monitor_index];\n\n        if (full_parameters != 0)\n        {\n            in_uint32_le(s, monitor_layout->flags);\n        }\n        in_uint32_le(s, monitor_layout->left);\n        in_uint32_le(s, monitor_layout->top);\n\n        if (full_parameters == 0)\n        {\n            in_uint32_le(s, monitor_layout->right);\n            in_uint32_le(s, monitor_layout->bottom);\n            in_uint32_le(s, monitor_layout->is_primary);\n\n            /*\n             * 2.2.1.3.6.1 Monitor Definition (TS_MONITOR_DEF)\n             */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_process_monitor_stream:\"\n                      \" Received [MS-RDPBCGR] 2.2.1.3.6.1\"\n                      \" TS_UD_CS_MONITOR.TS_MONITOR_DEF\"\n                      \" Index: %d, Left %d, Top %d, Right %d, Bottom %d,\"\n                      \" Flags 0x%8.8x\",\n                      monitor_index,\n                      monitor_layout->left,\n                      monitor_layout->top,\n                      monitor_layout->right,\n                      monitor_layout->bottom,\n                      monitor_layout->is_primary);\n        }\n        else\n        {\n            /* Per spec (2.2.2.2.1 DISPLAYCONTROL_MONITOR_LAYOUT),\n             * this is the width.\n             * 200 <= width <= 8192 and must not be odd.\n             * Ex: in_uint32_le(s, monitor_layout->width);\n             */\n            int width;\n            in_uint32_le(s, width);\n            if (width > CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_MONITOR_WIDTH ||\n                    width < CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_MONITOR_WIDTH ||\n                    width % 2 != 0)\n            {\n                return SEC_PROCESS_MONITORS_ERR_INVALID_MONITOR;\n            }\n            monitor_layout->right = monitor_layout->left + width - 1;\n\n            /* Per spec (2.2.2.2.1 DISPLAYCONTROL_MONITOR_LAYOUT),\n             * this is the height.\n             * 200 <= height <= 8192\n             * Ex: in_uint32_le(s, monitor_layout->height);\n             */\n            int height;\n            in_uint32_le(s, height);\n            if (height > CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_MONITOR_HEIGHT ||\n                    height < CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_MONITOR_HEIGHT)\n            {\n                return SEC_PROCESS_MONITORS_ERR_INVALID_MONITOR;\n            }\n            monitor_layout->bottom = monitor_layout->top + height - 1;\n\n            in_uint32_le(s, monitor_layout->physical_width);\n            in_uint32_le(s, monitor_layout->physical_height);\n            in_uint32_le(s, monitor_layout->orientation);\n            in_uint32_le(s, monitor_layout->desktop_scale_factor);\n            in_uint32_le(s, monitor_layout->device_scale_factor);\n\n            /*\n             * 2.2.2.2.1 DISPLAYCONTROL_MONITOR_LAYOUT\n             */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"libxrdp_process_monitor_stream:\"\n                      \" Received [MS-RDPEDISP] 2.2.2.2.1\"\n                      \" DISPLAYCONTROL_MONITOR_LAYOUT_PDU\"\n                      \".DISPLAYCONTROL_MONITOR_LAYOUT\"\n                      \" Index: %d, Flags 0x%8.8x, Left %d, Top %d, Width %d,\"\n                      \" Height %d, PhysicalWidth %d, PhysicalHeight %d,\"\n                      \" Orientation %d, DesktopScaleFactor %d,\"\n                      \" DeviceScaleFactor %d\",\n                      monitor_index,\n                      monitor_layout->flags,\n                      monitor_layout->left,\n                      monitor_layout->top,\n                      width,\n                      height,\n                      monitor_layout->physical_width,\n                      monitor_layout->physical_height,\n                      monitor_layout->orientation,\n                      monitor_layout->desktop_scale_factor,\n                      monitor_layout->device_scale_factor);\n\n            if (monitor_layout->flags == DISPLAYCONTROL_MONITOR_PRIMARY)\n            {\n                monitor_layout->is_primary = TS_MONITOR_PRIMARY;\n            }\n        }\n    }\n\n    return libxrdp_init_display_size_description(\n               num_monitor, monitors, description);\n}\n\n/*****************************************************************************/\nint\nlibxrdp_process_monitor_ex_stream(struct stream *s,\n                                  struct display_size_description *description)\n{\n    uint32_t num_monitor;\n    uint32_t monitor_index;\n    uint32_t attribute_size;\n    struct monitor_info *monitor_layout;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"libxrdp_process_monitor_ex_stream:\");\n    if (description == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"libxrdp_process_monitor_ex_stream: \"\n                  \"description was null. \"\n                  \" Valid pointer to allocated description expected.\");\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n\n    if (!s_check_rem_and_log(s, 4,\n                             \"libxrdp_process_monitor_ex_stream:\"\n                             \" Parsing [MS-RDPBCGR] TS_UD_CS_MONITOR_EX\"))\n    {\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n\n    in_uint32_le(s, attribute_size);\n    if (attribute_size != TS_MONITOR_ATTRIBUTES_SIZE)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"libxrdp_process_monitor_ex_stream: [MS-RDPBCGR] Protocol\"\n            \" error: TS_UD_CS_MONITOR_EX monitorAttributeSize\"\n            \" MUST be %d, received: %d\",\n            TS_MONITOR_ATTRIBUTES_SIZE, attribute_size);\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n\n    in_uint32_le(s, num_monitor);\n    LOG(LOG_LEVEL_DEBUG, \"libxrdp_process_monitor_ex_stream:\"\n        \" The number of monitors received is: %d\",\n        num_monitor);\n\n    if (num_monitor != description->monitorCount)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"libxrdp_process_monitor_ex_stream: [MS-RDPBCGR] Protocol\"\n            \" error: TS_UD_CS_MONITOR monitorCount\"\n            \" MUST be %d, received: %d\",\n            description->monitorCount, num_monitor);\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n\n    for (monitor_index = 0; monitor_index < num_monitor; ++monitor_index)\n    {\n        if (!s_check_rem_and_log(s, attribute_size,\n                                 \"libxrdp_process_monitor_ex_stream:\"\n                                 \" Parsing TS_UD_CS_MONITOR_EX\"))\n        {\n            return SEC_PROCESS_MONITORS_ERR;\n        }\n\n        monitor_layout = description->minfo + monitor_index;\n\n        in_uint32_le(s, monitor_layout->physical_width);\n        in_uint32_le(s, monitor_layout->physical_height);\n        in_uint32_le(s, monitor_layout->orientation);\n        in_uint32_le(s, monitor_layout->desktop_scale_factor);\n        in_uint32_le(s, monitor_layout->device_scale_factor);\n\n        sanitise_extended_monitor_attributes(monitor_layout);\n\n        LOG_DEVEL(LOG_LEVEL_INFO, \"libxrdp_process_monitor_ex_stream:\"\n                  \" Received [MS-RDPBCGR] 2.2.1.3.9.1 \"\n                  \" TS_MONITOR_ATTRIBUTES\"\n                  \" Index: %d, PhysicalWidth %d, PhysicalHeight %d,\"\n                  \" Orientation %d, DesktopScaleFactor %d,\"\n                  \" DeviceScaleFactor %d\",\n                  monitor_index,\n                  monitor_layout->physical_width,\n                  monitor_layout->physical_height,\n                  monitor_layout->orientation,\n                  monitor_layout->desktop_scale_factor,\n                  monitor_layout->device_scale_factor);\n    }\n\n    /* Update non negative monitor info values */\n    const struct monitor_info *src = description->minfo;\n    struct monitor_info *dst = description->minfo_wm;\n    for (monitor_index = 0; monitor_index < num_monitor; ++monitor_index)\n    {\n        dst->physical_width = src->physical_width;\n        dst->physical_height = src->physical_height;\n        dst->orientation = src->orientation;\n        dst->desktop_scale_factor = src->desktop_scale_factor;\n        dst->device_scale_factor = src->device_scale_factor;\n        ++src;\n        ++dst;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nlibxrdp_init_display_size_description(\n    unsigned int num_monitor,\n    const struct monitor_info *monitors,\n    struct display_size_description *description)\n{\n    unsigned int monitor_index;\n    struct monitor_info *monitor_layout;\n    struct xrdp_rect all_monitors_encompassing_bounds = {0};\n    int got_primary = 0;\n\n    /* Caller should have checked this, so don't log an error */\n    if (num_monitor > CLIENT_MONITOR_DATA_MAXIMUM_MONITORS)\n    {\n        return SEC_PROCESS_MONITORS_ERR_TOO_MANY_MONITORS;\n    }\n\n    description->monitorCount = num_monitor;\n    for (monitor_index = 0 ; monitor_index < num_monitor; ++monitor_index)\n    {\n        monitor_layout = &description->minfo[monitor_index];\n        *monitor_layout = monitors[monitor_index];\n        sanitise_extended_monitor_attributes(monitor_layout);\n\n        if (monitor_index == 0)\n        {\n            all_monitors_encompassing_bounds.left = monitor_layout->left;\n            all_monitors_encompassing_bounds.top = monitor_layout->top;\n            all_monitors_encompassing_bounds.right = monitor_layout->right;\n            all_monitors_encompassing_bounds.bottom = monitor_layout->bottom;\n        }\n        else\n        {\n            all_monitors_encompassing_bounds.left =\n                MIN(monitor_layout->left,\n                    all_monitors_encompassing_bounds.left);\n            all_monitors_encompassing_bounds.top =\n                MIN(monitor_layout->top,\n                    all_monitors_encompassing_bounds.top);\n            all_monitors_encompassing_bounds.right =\n                MAX(all_monitors_encompassing_bounds.right,\n                    monitor_layout->right);\n            all_monitors_encompassing_bounds.bottom =\n                MAX(all_monitors_encompassing_bounds.bottom,\n                    monitor_layout->bottom);\n        }\n\n        if (monitor_layout->is_primary == TS_MONITOR_PRIMARY)\n        {\n            if (got_primary)\n            {\n                // Already got one - don't have two\n                monitor_layout->is_primary = 0;\n            }\n            else\n            {\n                got_primary = 1;\n            }\n        }\n    }\n\n    if (!got_primary)\n    {\n        /* no primary monitor was set,\n         * choose the leftmost monitor as primary.\n         */\n        for (monitor_index = 0; monitor_index < num_monitor; ++monitor_index)\n        {\n            monitor_layout = description->minfo + monitor_index;\n            if (monitor_layout->left\n                    == all_monitors_encompassing_bounds.left\n                    && monitor_layout->top\n                    == all_monitors_encompassing_bounds.top)\n            {\n                monitor_layout->is_primary = TS_MONITOR_PRIMARY;\n                break;\n            }\n        }\n    }\n\n    /* set wm geometry if the encompassing area is well formed.\n       Otherwise, log and return an error.\n    */\n    if (all_monitors_encompassing_bounds.right\n            > all_monitors_encompassing_bounds.left\n            && all_monitors_encompassing_bounds.bottom\n            > all_monitors_encompassing_bounds.top)\n    {\n        description->session_width =\n            all_monitors_encompassing_bounds.right\n            - all_monitors_encompassing_bounds.left + 1;\n        description->session_height =\n            all_monitors_encompassing_bounds.bottom\n            - all_monitors_encompassing_bounds.top + 1;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"libxrdp_init_display_size_description:\"\n            \" The area encompassing the monitors is not a\"\n            \" well-formed rectangle. Received\"\n            \" (top: %d, left: %d, right: %d, bottom: %d).\"\n            \" This will prevent initialization.\",\n            all_monitors_encompassing_bounds.top,\n            all_monitors_encompassing_bounds.left,\n            all_monitors_encompassing_bounds.right,\n            all_monitors_encompassing_bounds.bottom);\n        return SEC_PROCESS_MONITORS_ERR_INVALID_DESKTOP;\n    }\n\n    /* Make sure virtual desktop size is OK\n     * 2.2.1.3.6 Client Monitor Data (TS_UD_CS_MONITOR)\n     */\n    if (description->session_width\n            > CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_DESKTOP_WIDTH\n            || description->session_width\n            < CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_DESKTOP_WIDTH\n            || description->session_height\n            > CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_DESKTOP_HEIGHT\n            || description->session_height\n            < CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_DESKTOP_HEIGHT)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"libxrdp_init_display_size_description: Calculated virtual\"\n            \" desktop width or height is invalid.\"\n            \" Allowed width range: min %d, max %d. Width received: %d.\"\n            \" Allowed height range: min %d, max %d. Height received: %d\",\n            CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_DESKTOP_WIDTH,\n            CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_DESKTOP_WIDTH,\n            description->session_width,\n            CLIENT_MONITOR_DATA_MINIMUM_VIRTUAL_DESKTOP_HEIGHT,\n            CLIENT_MONITOR_DATA_MAXIMUM_VIRTUAL_DESKTOP_HEIGHT,\n            description->session_width);\n        return SEC_PROCESS_MONITORS_ERR_INVALID_DESKTOP;\n    }\n\n    /* keep a copy of non negative monitor info values for xrdp_wm usage */\n    for (monitor_index = 0; monitor_index < num_monitor; ++monitor_index)\n    {\n        monitor_layout = description->minfo_wm + monitor_index;\n\n        *monitor_layout = description->minfo[monitor_index];\n\n        monitor_layout->left =\n            monitor_layout->left - all_monitors_encompassing_bounds.left;\n        monitor_layout->top =\n            monitor_layout->top - all_monitors_encompassing_bounds.top;\n        monitor_layout->right =\n            monitor_layout->right - all_monitors_encompassing_bounds.left;\n        monitor_layout->bottom =\n            monitor_layout->bottom - all_monitors_encompassing_bounds.top;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint EXPORT_CC\nlibxrdp_planar_compress(char *in_data, int width, int height,\n                        struct stream *s, int bpp, int byte_limit,\n                        int start_line, struct stream *temp_s,\n                        int e, int flags)\n{\n    return xrdp_bitmap32_compress(in_data, width, height,\n                                  s, bpp, byte_limit,\n                                  start_line, temp_s,\n                                  e, flags);\n}\n"
  },
  {
    "path": "libxrdp/libxrdp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libxrdp header\n */\n\n#if !defined(LIBXRDP_H)\n#define LIBXRDP_H\n\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"trans.h\"\n#include \"xrdp_constants.h\"\n#include \"defines.h\"\n#include \"os_calls.h\"\n#include \"ssl_calls.h\"\n#include \"list.h\"\n#include \"log.h\"\n#include \"file.h\"\n#include \"libxrdpinc.h\"\n#include \"xrdp_client_info.h\"\n#include \"log.h\"\n\n\n/* iso */\nstruct xrdp_iso\n{\n    struct xrdp_mcs *mcs_layer; /* owner */\n    int rdpNegData; /* bool */\n    int requestedProtocol;\n    int selectedProtocol;\n    int failureCode;\n    struct trans *trans;\n};\n\n/* used in mcs */\nstruct mcs_channel_item\n{\n    char name[CHANNEL_NAME_LEN + 1];\n    int flags;\n    int chanid;\n    int disabled;\n    int pad0;\n};\n\n/* mcs */\nstruct xrdp_mcs\n{\n    struct xrdp_sec *sec_layer; /* owner */\n    struct xrdp_iso *iso_layer;\n    int userid;\n    int chanid;\n    struct stream *client_mcs_data;\n    struct stream *server_mcs_data;\n    struct list *channel_list;\n    /* This boolean is set to indicate we're expecting channel join\n     * requests as part of the connect sequence */\n    int expecting_channel_join_requests;\n};\n\n/* fastpath */\nstruct xrdp_fastpath\n{\n    struct xrdp_sec *sec_layer; /* owner */\n    struct trans *trans;\n    struct xrdp_session *session;\n    int numEvents;\n    int secFlags;\n};\n\n/* Encryption Methods */\n#define CRYPT_METHOD_NONE              0x00000000\n#define CRYPT_METHOD_40BIT             0x00000001\n#define CRYPT_METHOD_128BIT            0x00000002\n#define CRYPT_METHOD_56BIT             0x00000008\n#define CRYPT_METHOD_FIPS              0x00000010\n\n/* Encryption Levels */\n#define CRYPT_LEVEL_NONE               0x00000000\n#define CRYPT_LEVEL_LOW                0x00000001\n#define CRYPT_LEVEL_CLIENT_COMPATIBLE  0x00000002\n#define CRYPT_LEVEL_HIGH               0x00000003\n#define CRYPT_LEVEL_FIPS               0x00000004\n\n\n/* sec */\nstruct xrdp_sec\n{\n    struct xrdp_rdp *rdp_layer; /* owner */\n    struct xrdp_mcs *mcs_layer;\n    struct xrdp_fastpath *fastpath_layer;\n    struct xrdp_channel *chan_layer;\n    char server_random[32];\n    char client_random[256];\n    char client_crypt_random[256 + 8]; /* 64 + 8, 256 + 8 */\n    struct stream client_mcs_data;\n    struct stream server_mcs_data;\n    int decrypt_use_count;\n    int encrypt_use_count;\n    char decrypt_key[16];\n    char encrypt_key[16];\n    char decrypt_update_key[16];\n    char encrypt_update_key[16];\n    int crypt_method;\n    int rc4_key_len; /* 8 = 40 bit, 16 = 128 bit */\n    int crypt_level;\n    char sign_key[16];\n    void *decrypt_rc4_info;\n    void *encrypt_rc4_info;\n    char pub_exp[4];\n    char pub_mod[256];\n    char pub_sig[64];\n    char pri_exp[256];\n    int rsa_key_bytes; /* 64 or 256 , 0 = no rdp security */\n    char fips_encrypt_key[24];\n    char fips_decrypt_key[24];\n    char fips_sign_key[20];\n    void *encrypt_fips_info;\n    void *decrypt_fips_info;\n    void *sign_fips_info;\n    int is_security_header_present; /* boolean */\n};\n\nstruct xrdp_process;\n\nstruct xrdp_drdynvc\n{\n    int chan_id;\n    int status; /* see XRDP_DRDYNVC_STATUS_* */\n    int flags;\n    int pad0;\n    int (*open_response)(struct xrdp_process *id, int chan_id,\n                         int creation_status);\n    int (*close_response)(struct xrdp_process *id, int chan_id);\n    int (*data_first)(struct xrdp_process *id, int chan_id, char *data,\n                      int bytes, int total_bytes);\n    int (*data)(struct xrdp_process *id, int chan_id, char *data, int bytes);\n};\n\n/* channel */\nstruct xrdp_channel\n{\n    struct xrdp_sec *sec_layer;\n    struct xrdp_mcs *mcs_layer;\n    int drdynvc_channel_id;\n    int drdynvc_state;\n    struct stream *s;\n    struct xrdp_drdynvc drdynvcs[256];\n};\n\n/* rdp */\nstruct xrdp_rdp\n{\n    struct xrdp_session *session;\n    struct xrdp_sec *sec_layer;\n    int share_id;\n    int mcs_channel;\n    struct xrdp_client_info client_info;\n    struct xrdp_mppc_enc *mppc_enc;\n    void *rfx_enc;\n};\n\n/* state */\nstruct xrdp_orders_state\n{\n    int last_order; /* last order sent */\n\n    int clip_left;  /* RDP_ORDER_BOUNDS, RDP_ORDER_LASTBOUNDS */\n    int clip_top;\n    int clip_right;\n    int clip_bottom;\n\n    int rect_x; /* RDP_ORDER_RECT */\n    int rect_y;\n    int rect_cx;\n    int rect_cy;\n    int rect_color;\n\n    int scr_blt_x; /* RDP_ORDER_SCREENBLT */\n    int scr_blt_y;\n    int scr_blt_cx;\n    int scr_blt_cy;\n    int scr_blt_rop;\n    int scr_blt_srcx;\n    int scr_blt_srcy;\n\n    int pat_blt_x; /* RDP_ORDER_PATBLT */\n    int pat_blt_y;\n    int pat_blt_cx;\n    int pat_blt_cy;\n    int pat_blt_rop;\n    int pat_blt_bg_color;\n    int pat_blt_fg_color;\n    struct xrdp_brush pat_blt_brush;\n\n    int dest_blt_x; /* RDP_ORDER_DESTBLT */\n    int dest_blt_y;\n    int dest_blt_cx;\n    int dest_blt_cy;\n    int dest_blt_rop;\n\n    int line_mix_mode; /* RDP_ORDER_LINE */\n    int line_startx;\n    int line_starty;\n    int line_endx;\n    int line_endy;\n    int line_bg_color;\n    int line_rop;\n    struct xrdp_pen line_pen;\n\n    int mem_blt_color_table; /* RDP_ORDER_MEMBLT */\n    int mem_blt_cache_id;\n    int mem_blt_x;\n    int mem_blt_y;\n    int mem_blt_cx;\n    int mem_blt_cy;\n    int mem_blt_rop;\n    int mem_blt_srcx;\n    int mem_blt_srcy;\n    int mem_blt_cache_idx;\n\n    int text_font; /* RDP_ORDER_TEXT2 */\n    int text_flags;\n    int text_unknown;\n    int text_mixmode;\n    int text_fg_color;\n    int text_bg_color;\n    int text_clip_left;\n    int text_clip_top;\n    int text_clip_right;\n    int text_clip_bottom;\n    int text_box_left;\n    int text_box_top;\n    int text_box_right;\n    int text_box_bottom;\n    int text_x;\n    int text_y;\n    int text_len;\n    char *text_data;\n\n    int com_blt_srcidx;    /* RDP_ORDER_COMPOSITE */  /* 2 */\n    int com_blt_srcformat;                            /* 2 */\n    int com_blt_srcwidth;                             /* 2 */\n    int com_blt_srcrepeat;                            /* 1 */\n    int com_blt_srctransform[10];                     /* 40 */\n    int com_blt_mskflags;                             /* 1 */\n    int com_blt_mskidx;                               /* 2 */\n    int com_blt_mskformat;                            /* 2 */\n    int com_blt_mskwidth;                             /* 2 */\n    int com_blt_mskrepeat;                            /* 1 */\n    int com_blt_op;                                   /* 1 */\n    int com_blt_srcx;                                 /* 2 */\n    int com_blt_srcy;                                 /* 2 */\n    int com_blt_mskx;                                 /* 2 */\n    int com_blt_msky;                                 /* 2 */\n    int com_blt_dstx;                                 /* 2 */\n    int com_blt_dsty;                                 /* 2 */\n    int com_blt_width;                                /* 2 */\n    int com_blt_height;                               /* 2 */\n    int com_blt_dstformat;                            /* 2 */\n\n};\n\n/* orders */\nstruct xrdp_orders\n{\n    struct stream *out_s;\n    struct xrdp_rdp *rdp_layer;\n    struct xrdp_session *session;\n    struct xrdp_wm *wm;\n\n    char *order_count_ptr; /* pointer to count, set when sending */\n    int order_count;\n    int order_level; /* inc for every call to xrdp_orders_init */\n    struct xrdp_orders_state orders_state;\n    void *jpeg_han;\n    int rfx_min_pixel;\n    /* shared */\n    struct stream *s;\n    struct stream *temp_s;\n};\n\n#define PROTO_RDP_40 1\n#define PROTO_RDP_50 2\n\nstruct xrdp_mppc_enc\n{\n    int    protocol_type;    /* PROTO_RDP_40, PROTO_RDP_50 etc */\n    char  *historyBuffer;    /* contains uncompressed data */\n    char  *outputBuffer;     /* contains compressed data */\n    char  *outputBufferPlus;\n    int    historyOffset;    /* next free slot in historyBuffer */\n    int    buf_len;          /* length of historyBuffer, protocol dependent */\n    int    bytes_in_opb;     /* compressed bytes available in outputBuffer */\n    int    flags;            /* PACKET_COMPRESSED, PACKET_AT_FRONT, PACKET_FLUSHED etc */\n    int    flagsHold;\n    int    first_pkt;        /* this is the first pkt passing through enc */\n    tui16 *hash_table;\n};\n\nint\ncompress_rdp(struct xrdp_mppc_enc *enc, tui8 *srcData, int len);\nstruct xrdp_mppc_enc *\nmppc_enc_new(int protocol_type);\nvoid\nmppc_enc_free(struct xrdp_mppc_enc *enc);\n\n/* xrdp_tcp.c */\nstruct xrdp_tcp *\nxrdp_tcp_create(struct xrdp_iso *owner, struct trans *trans);\nvoid\nxrdp_tcp_delete(struct xrdp_tcp *self);\nint\nxrdp_tcp_init(struct xrdp_tcp *self, struct stream *s);\nint\nxrdp_tcp_recv(struct xrdp_tcp *self, struct stream *s, int len);\nint\nxrdp_tcp_send(struct xrdp_tcp *self, struct stream *s);\n\n/* xrdp_iso.c */\nstruct xrdp_iso *\nxrdp_iso_create(struct xrdp_mcs *owner, struct trans *trans);\nvoid\nxrdp_iso_delete(struct xrdp_iso *self);\nint\nxrdp_iso_init(struct xrdp_iso *self, struct stream *s);\nint\nxrdp_iso_recv(struct xrdp_iso *self, struct stream *s);\nint\nxrdp_iso_send(struct xrdp_iso *self, struct stream *s);\nint\nxrdp_iso_incoming(struct xrdp_iso *self);\nint\nxrdp_iso_detect_tpkt(struct xrdp_iso *self, struct stream *s);\n\n/* xrdp_mcs.c */\nstruct xrdp_mcs *\nxrdp_mcs_create(struct xrdp_sec *owner, struct trans *trans,\n                struct stream *client_mcs_data,\n                struct stream *server_mcs_data);\nvoid\nxrdp_mcs_delete(struct xrdp_mcs *self);\nint\nxrdp_mcs_init(struct xrdp_mcs *self, struct stream *s);\nint\nxrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan);\nint\nxrdp_mcs_send(struct xrdp_mcs *self, struct stream *s, int chan);\nint\nxrdp_mcs_incoming(struct xrdp_mcs *self);\nint\nxrdp_mcs_disconnect(struct xrdp_mcs *self);\n\n/* xrdp_sec.c */\n\n/*\n    These are error return codes for:-\n        1. xrdp_sec_process_mcs_data_monitors\n        2. libxrdp_process_monitor_stream\n        3. libxrdp_process_monitor_ex_stream\n    To clarify any reason for a non-zero response code.\n*/\n#define SEC_PROCESS_MONITORS_ERR 1\n#define SEC_PROCESS_MONITORS_ERR_TOO_MANY_MONITORS 2\n#define SEC_PROCESS_MONITORS_ERR_INVALID_DESKTOP 3\n#define SEC_PROCESS_MONITORS_ERR_INVALID_MONITOR 4\n\nstruct xrdp_sec *\nxrdp_sec_create(struct xrdp_rdp *owner, struct trans *trans);\nvoid\nxrdp_sec_delete(struct xrdp_sec *self);\nint\nxrdp_sec_init(struct xrdp_sec *self, struct stream *s);\nint\nxrdp_sec_get_fastpath_bytes(struct xrdp_sec *self);\nint\nxrdp_sec_init_fastpath(struct xrdp_sec *self, struct stream *s);\nint\nxrdp_sec_send_fastpath(struct xrdp_sec *self, struct stream *s);\nint\nxrdp_sec_recv_fastpath(struct xrdp_sec *self, struct stream *s);\nint\nxrdp_sec_recv(struct xrdp_sec *self, struct stream *s, int *chan);\nint\nxrdp_sec_send(struct xrdp_sec *self, struct stream *s, int chan);\nint\nxrdp_sec_process_mcs_data(struct xrdp_sec *self);\nint\nxrdp_sec_incoming(struct xrdp_sec *self);\nint\nxrdp_sec_disconnect(struct xrdp_sec *self);\nint\nxrdp_sec_process_mcs_data_monitors(struct xrdp_sec *self, struct stream *s);\n\n/* xrdp_rdp.c */\n\n/**\n * Reasons why output is being suppressed or restarted\n */\nenum suppress_output_reason\n{\n    /// Client has requested suppress via TS_SUPPRESS_OUTPUT_PDU\n    XSO_REASON_CLIENT_REQUEST = (1 << 0),\n    /// Deactivation-Reactivation Sequence [MS-RDPBCGR] 1.3.1.3\n    XSO_REASON_DEACTIVATE_REACTIVATE = (1 << 1),\n    /// Dynamic resize in progress\n    XSO_REASON_DYNAMIC_RESIZE = (1 << 2)\n};\n\nstruct xrdp_rdp *\nxrdp_rdp_create(struct xrdp_session *session, struct trans *trans);\nvoid\nxrdp_rdp_delete(struct xrdp_rdp *self);\nint\nxrdp_rdp_init(struct xrdp_rdp *self, struct stream *s);\nint\nxrdp_rdp_init_data(struct xrdp_rdp *self, struct stream *s);\nint\nxrdp_rdp_get_fastpath_bytes(struct xrdp_rdp *self);\nint\nxrdp_rdp_init_fastpath(struct xrdp_rdp *self, struct stream *s);\nint\nxrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code);\nint\nxrdp_rdp_send(struct xrdp_rdp *self, struct stream *s, int pdu_type);\nint\nxrdp_rdp_send_data(struct xrdp_rdp *self, struct stream *s,\n                   int data_pdu_type);\nint\nxrdp_rdp_send_data_from_channel(struct xrdp_rdp *self, struct stream *s,\n                                int data_pdu_type, int channel_id,\n                                int compress);\nint\nxrdp_rdp_send_fastpath(struct xrdp_rdp *self, struct stream *s,\n                       int data_pdu_type);\nint\nxrdp_rdp_send_data_update_sync(struct xrdp_rdp *self);\nint\nxrdp_rdp_incoming(struct xrdp_rdp *self);\nint\nxrdp_rdp_process_data(struct xrdp_rdp *self, struct stream *s);\nint\nxrdp_rdp_disconnect(struct xrdp_rdp *self);\nint\nxrdp_rdp_send_deactivate(struct xrdp_rdp *self);\nint\nxrdp_rdp_send_session_info(struct xrdp_rdp *self, const char *data,\n                           int data_bytes);\n/**\n * Send a [MS-RDPBCGR] TS_SET_ERROR_INFO_PDU message\n * @param self xrdp_rdp struct\n * @param reason errinfo code ([MS-RDPBCGR] 2.2.5.1.1)\n * @return != 0 for error\n\n * The caller is responsible for checking the client supports\n * reception of this message (see 2.2.5.1)\n */\nint\nxrdp_rdp_send_set_error(struct xrdp_rdp *self, int reason);\n\n/**\n * Request output suppress or resume\n *\n * @param self RDP struct\n * @param suppress (!= 0 for suppress, 0 for resume)\n * @param reason Why the output is being suppressed or resumed\n * @param left Left pixel of repaint area (ignored for suppress)\n * @param top Top pixel of repaint area (ignored for suppress)\n * @param right Right pixel of inclusive repaint area (ignored for suppress)\n * @param bottom Bottom pixel of inclusive repaint area (ignored for suppress)\n */\nvoid\nxrdp_rdp_suppress_output(struct xrdp_rdp *self, int suppress,\n                         enum suppress_output_reason reason,\n                         int left, int top, int right, int bottom);\n\n/* xrdp_orders.c */\nstruct xrdp_orders *\nxrdp_orders_create(struct xrdp_session *session,\n                   struct xrdp_rdp *rdp_layer);\nvoid\nxrdp_orders_delete(struct xrdp_orders *self);\nint\nxrdp_orders_reset(struct xrdp_orders *self);\nint\nxrdp_orders_init(struct xrdp_orders *self);\nint\nxrdp_orders_send(struct xrdp_orders *self);\nint\nxrdp_orders_force_send(struct xrdp_orders *self);\nint\nxrdp_orders_check(struct xrdp_orders *self, int max_size);\nint\nxrdp_orders_rect(struct xrdp_orders *self, int x, int y, int cx, int cy,\n                 int color, struct xrdp_rect *rect);\nint\nxrdp_orders_screen_blt(struct xrdp_orders *self, int x, int y,\n                       int cx, int cy, int srcx, int srcy,\n                       int rop, struct xrdp_rect *rect);\nint\nxrdp_orders_pat_blt(struct xrdp_orders *self, int x, int y,\n                    int cx, int cy, int rop, int bg_color,\n                    int fg_color, struct xrdp_brush *brush,\n                    struct xrdp_rect *rect);\nint\nxrdp_orders_dest_blt(struct xrdp_orders *self, int x, int y,\n                     int cx, int cy, int rop,\n                     struct xrdp_rect *rect);\nint\nxrdp_orders_line(struct xrdp_orders *self, int mix_mode,\n                 int startx, int starty,\n                 int endx, int endy, int rop, int bg_color,\n                 struct xrdp_pen *pen,\n                 struct xrdp_rect *rect);\nint\nxrdp_orders_mem_blt(struct xrdp_orders *self, int cache_id,\n                    int color_table, int x, int y, int cx, int cy,\n                    int rop, int srcx, int srcy,\n                    int cache_idx, struct xrdp_rect *rect);\nint\nxrdp_orders_composite_blt(struct xrdp_orders *self, int srcidx,\n                          int srcformat, int srcwidth,\n                          int srcrepeat, int *srctransform, int mskflags,\n                          int mskidx, int mskformat, int mskwidth,\n                          int mskrepeat, int op, int srcx, int srcy,\n                          int mskx, int msky, int dstx, int dsty,\n                          int width, int height, int dstformat,\n                          struct xrdp_rect *rect);\nint\nxrdp_orders_text(struct xrdp_orders *self,\n                 int font, int flags, int mixmode,\n                 int fg_color, int bg_color,\n                 int clip_left, int clip_top,\n                 int clip_right, int clip_bottom,\n                 int box_left, int box_top,\n                 int box_right, int box_bottom,\n                 int x, int y, char *data, int data_len,\n                 struct xrdp_rect *rect);\nint\nxrdp_orders_send_palette(struct xrdp_orders *self, int *palette,\n                         int cache_id);\nint\nxrdp_orders_send_raw_bitmap(struct xrdp_orders *self,\n                            int width, int height, int bpp, char *data,\n                            int cache_id, int cache_idx);\nint\nxrdp_orders_send_bitmap(struct xrdp_orders *self,\n                        int width, int height, int bpp, char *data,\n                        int cache_id, int cache_idx);\nint\nxrdp_orders_send_font(struct xrdp_orders *self,\n                      struct xrdp_font_char *font_char,\n                      int font_index, int char_index);\nint\nxrdp_orders_send_raw_bitmap2(struct xrdp_orders *self,\n                             int width, int height, int bpp, char *data,\n                             int cache_id, int cache_idx);\nint\nxrdp_orders_send_bitmap2(struct xrdp_orders *self,\n                         int width, int height, int bpp, char *data,\n                         int cache_id, int cache_idx, int hints);\nint\nxrdp_orders_send_bitmap3(struct xrdp_orders *self,\n                         int width, int height, int bpp, char *data,\n                         int cache_id, int cache_idx, int hints);\nint\nxrdp_orders_send_brush(struct xrdp_orders *self, int width, int height,\n                       int bpp, int type, int size, char *data, int cache_id);\nint\nxrdp_orders_send_create_os_surface(struct xrdp_orders *self, int id,\n                                   int width, int height,\n                                   struct list *del_list);\nint\nxrdp_orders_send_switch_os_surface(struct xrdp_orders *self, int id);\n\n/* xrdp_bitmap_compress.c */\nint\nxrdp_bitmap_compress(char *in_data, int width, int height,\n                     struct stream *s, int bpp, int byte_limit,\n                     int start_line, struct stream *temp_s,\n                     int e);\nint\nxrdp_bitmap32_compress(char *in_data, int width, int height,\n                       struct stream *s, int bpp, int byte_limit,\n                       int start_line, struct stream *temp_s,\n                       int e, int flags);\nint\nxrdp_jpeg_compress(void *handle, char *in_data, int width, int height,\n                   struct stream *s, int bpp, int byte_limit,\n                   int start_line, struct stream *temp_s,\n                   int e, int quality);\n\nint\nxrdp_codec_jpeg_compress(void *handle,\n                         int   format,   /* input data format */\n                         char *inp_data, /* input data */\n                         int   width,    /* width of inp_data */\n                         int   height,   /* height of inp_data */\n                         int   stride,   /* inp_data stride, in bytes*/\n                         int   x,        /* x loc in inp_data */\n                         int   y,        /* y loc in inp_data */\n                         int   cx,       /* width of area to compress */\n                         int   cy,       /* height of area to compress */\n                         int   quality,  /* higher numbers compress less */\n                         char *out_data, /* dest for jpg image */\n                         int  *io_len    /* length of out_data and on return\n                                            len of compressed data */\n                        );\n\nvoid *\nxrdp_jpeg_init(void);\nint\nxrdp_jpeg_deinit(void *handle);\n\n/* xrdp_channel.c */\nstruct xrdp_channel *\nxrdp_channel_create(struct xrdp_sec *owner, struct xrdp_mcs *mcs_layer);\nvoid\nxrdp_channel_delete(struct xrdp_channel *self);\nint\nxrdp_channel_init(struct xrdp_channel *self, struct stream *s);\nint\nxrdp_channel_send(struct xrdp_channel *self, struct stream *s, int channel_id,\n                  int total_data_len, int flags);\nint\nxrdp_channel_process(struct xrdp_channel *self, struct stream *s,\n                     int chanid);\nint\nxrdp_channel_drdynvc_start(struct xrdp_channel *self);\nint\nxrdp_channel_drdynvc_open(struct xrdp_channel *self, const char *name,\n                          int flags, struct xrdp_drdynvc_procs *procs,\n                          int *chan_id);\nint\nxrdp_channel_drdynvc_close(struct xrdp_channel *self, int chan_id);\nint\nxrdp_channel_drdynvc_data_first(struct xrdp_channel *self, int chan_id,\n                                const char *data, int data_bytes,\n                                int total_data_bytes);\nint\nxrdp_channel_drdynvc_data(struct xrdp_channel *self, int chan_id,\n                          const char *data, int data_bytes);\n\n/* xrdp_fastpath.c */\nstruct xrdp_fastpath *\nxrdp_fastpath_create(struct xrdp_sec *owner, struct trans *trans);\nvoid\nxrdp_fastpath_delete(struct xrdp_fastpath *self);\nint\nxrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s);\nint\nxrdp_fastpath_process_input_event(struct xrdp_fastpath *self, struct stream *s);\nint\nxrdp_fastpath_init(struct xrdp_fastpath *self, struct stream *s);\nint\nxrdp_fastpath_send(struct xrdp_fastpath *self, struct stream *s);\n\n/* xrdp_caps.c */\nint\nxrdp_caps_send_demand_active(struct xrdp_rdp *self);\nint\nxrdp_caps_process_confirm_active(struct xrdp_rdp *self, struct stream *s);\n#endif\n"
  },
  {
    "path": "libxrdp/libxrdpinc.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * header file for use with libxrdp.so / xrdp.dll\n */\n\n#ifndef LIBXRDPINC_H\n#define LIBXRDPINC_H\n\n#include \"xrdp_rail.h\"\n\nstruct list;\nstruct monitor_info;\n\n/* struct xrdp_client_info moved to xrdp_client_info.h */\n\nstruct xrdp_brush\n{\n    int x_origin;\n    int y_origin;\n    int style;\n    char pattern[8];\n};\n\nstruct xrdp_pen\n{\n    int style;\n    int width;\n    int color;\n};\n\n/* 2.2.2.2.1.2.5.1 Cache Glyph Data (TS_CACHE_GLYPH_DATA) */\nstruct xrdp_font_char\n{\n    int offset;    /* x */\n    int baseline;  /* y */\n    int width;     /* cx */\n    int height;    /* cy */\n    int incby;\n    int bpp;\n    char *data;\n};\n\nstruct xrdp_rect\n{\n    int left;\n    int top;\n    int right;\n    int bottom;\n};\n\nstruct xrdp_rdp;\nstruct xrdp_orders;\nstruct xrdp_process;\n\nstruct xrdp_session\n{\n    struct xrdp_process *id;\n    struct trans *trans;\n    int (*callback)(struct xrdp_process *id, int msg,\n                    intptr_t param1, intptr_t param2,\n                    intptr_t param3, intptr_t param4);\n    int check_for_app_input;\n    struct xrdp_rdp *rdp;\n    struct xrdp_orders *orders;\n    struct xrdp_client_info *client_info;\n    int up_and_running;\n    int (*is_term)(void);\n    int in_process_data; /* inc / dec libxrdp_process_data calls */\n\n    struct source_info si;\n    char *xrdp_ini; /* path to xrdp.ini */\n};\n\nstruct xrdp_drdynvc_procs\n{\n    int (*open_response)(struct xrdp_process *id, int chan_id,\n                         int creation_status);\n    int (*close_response)(struct xrdp_process *id, int chan_id);\n    int (*data_first)(struct xrdp_process *id, int chan_id,\n                      char *data, int bytes, int total_bytes);\n    int (*data)(struct xrdp_process *id, int chan_id, char *data, int bytes);\n};\n\n/* Defined in xrdp_client_info.h */\nstruct display_size_description;\n\n/***\n * Initialise the XRDP library\n *\n * @param proc XRDP instance to use with this library\n * @param trans Transport object to use for this instance\n * @param xrdp_ini Path to xrdp.ini config file, or NULL for default\n * @return an allocated xrdp_session object\n */\nstruct xrdp_session *\nlibxrdp_init(struct xrdp_process *id,\n             struct trans *trans, const char *xrdp_ini);\nint\nlibxrdp_exit(struct xrdp_session *session);\n/**\n * Sends a disconnect sequence from the server ([MS-RDPBCGR] 1.3.1.4.x)\n * @param session xrdp session\n * @param errinfo Reason ([MS-RDPBCGR] 2.2.5.1.1)\n * @return != 0 for an error\n *\n * After this call, the rdp channel is closed and cannot be re-used. This\n * routine can be called more than once, but only the first call is\n * effective.\n */\nint\nlibxrdp_disconnect(struct xrdp_session *session, int errinfo);\nint\nlibxrdp_process_incoming(struct xrdp_session *session);\nint EXPORT_CC\nlibxrdp_get_pdu_bytes(const char *aheader);\nstruct stream *\nlibxrdp_force_read(struct trans *trans);\nint\nlibxrdp_process_data(struct xrdp_session *session, struct stream *s);\nint\nlibxrdp_send_palette(struct xrdp_session *session, int *palette);\nint\nlibxrdp_send_bell(struct xrdp_session *session);\nint\nlibxrdp_send_bitmap(struct xrdp_session *session, int width, int height,\n                    int bpp, char *data, int x, int y, int cx, int cy);\nint\nlibxrdp_send_pointer_system(struct xrdp_session *session, int pointer_type);\nint\nlibxrdp_send_pointer_position(struct xrdp_session *session, int x, int y);\nint\nlibxrdp_send_pointer(struct xrdp_session *session, int cache_idx,\n                     char *data, char *mask, int x, int y, int bpp,\n                     int width, int height);\nint\nlibxrdp_set_pointer(struct xrdp_session *session, int cache_idx);\nint\nlibxrdp_orders_init(struct xrdp_session *session);\nint\nlibxrdp_orders_send(struct xrdp_session *session);\nint\nlibxrdp_orders_force_send(struct xrdp_session *session);\nint\nlibxrdp_orders_rect(struct xrdp_session *session, int x, int y,\n                    int cx, int cy, int color, struct xrdp_rect *rect);\nint\nlibxrdp_orders_screen_blt(struct xrdp_session *session, int x, int y,\n                          int cx, int cy, int srcx, int srcy,\n                          int rop, struct xrdp_rect *rect);\nint\nlibxrdp_orders_pat_blt(struct xrdp_session *session, int x, int y,\n                       int cx, int cy, int rop, int bg_color,\n                       int fg_color, struct xrdp_brush *brush,\n                       struct xrdp_rect *rect);\nint\nlibxrdp_orders_dest_blt(struct xrdp_session *session, int x, int y,\n                        int cx, int cy, int rop,\n                        struct xrdp_rect *rect);\nint\nlibxrdp_orders_line(struct xrdp_session *session, int mix_mode,\n                    int startx, int starty,\n                    int endx, int endy, int rop, int bg_color,\n                    struct xrdp_pen *pen,\n                    struct xrdp_rect *rect);\nint\nlibxrdp_orders_mem_blt(struct xrdp_session *session, int cache_id,\n                       int color_table, int x, int y, int cx, int cy,\n                       int rop, int srcx, int srcy,\n                       int cache_idx, struct xrdp_rect *rect);\nint\nlibxrdp_orders_composite_blt(struct xrdp_session *session, int srcidx,\n                             int srcformat, int srcwidth, int srcrepeat,\n                             int *srctransform, int mskflags,\n                             int mskidx, int mskformat, int mskwidth,\n                             int mskrepeat, int op, int srcx, int srcy,\n                             int mskx, int msky, int dstx, int dsty,\n                             int width, int height, int dstformat,\n                             struct xrdp_rect *rect);\n\nint\nlibxrdp_orders_text(struct xrdp_session *session,\n                    int font, int flags, int mixmode,\n                    int fg_color, int bg_color,\n                    int clip_left, int clip_top,\n                    int clip_right, int clip_bottom,\n                    int box_left, int box_top,\n                    int box_right, int box_bottom,\n                    int x, int y, char *data, int data_len,\n                    struct xrdp_rect *rect);\nint\nlibxrdp_orders_send_palette(struct xrdp_session *session, int *palette,\n                            int cache_id);\nint\nlibxrdp_orders_send_raw_bitmap(struct xrdp_session *session,\n                               int width, int height, int bpp, char *data,\n                               int cache_id, int cache_idx);\nint\nlibxrdp_orders_send_bitmap(struct xrdp_session *session,\n                           int width, int height, int bpp, char *data,\n                           int cache_id, int cache_idx);\nint\nlibxrdp_orders_send_font(struct xrdp_session *session,\n                         struct xrdp_font_char *font_char,\n                         int font_index, int char_index);\nint\nlibxrdp_reset(struct xrdp_session *session);\nint\nlibxrdp_orders_send_raw_bitmap2(struct xrdp_session *session,\n                                int width, int height, int bpp, char *data,\n                                int cache_id, int cache_idx);\nint\nlibxrdp_orders_send_bitmap2(struct xrdp_session *session,\n                            int width, int height, int bpp, char *data,\n                            int cache_id, int cache_idx, int hints);\nint\nlibxrdp_orders_send_bitmap3(struct xrdp_session *session,\n                            int width, int height, int bpp, char *data,\n                            int cache_id, int cache_idx, int hints);\n/**\n * Returns the number of channels in the session\n *\n * This value is one more than the last valid channel ID\n *\n * @param session RDP session\n * @return Number of available channels\n */\nint\nlibxrdp_get_channel_count(const struct xrdp_session *session);\nint\nlibxrdp_query_channel(struct xrdp_session *session, int channel_id,\n                      char *channel_name, int *channel_flags);\n/**\n * Gets the channel ID for the named channel\n *\n * Channel IDs are in the range 0..(channel_count-1)\n *\n * @param session RDP session\n * @param name name of channel\n * @return channel ID, or -1 if the channel cannot be found\n */\nint\nlibxrdp_get_channel_id(struct xrdp_session *session, const char *name);\nint\nlibxrdp_send_to_channel(struct xrdp_session *session, int channel_id,\n                        char *data, int data_len,\n                        int total_data_len, int flags);\nint\nlibxrdp_disable_channel(struct xrdp_session *session, int channel_id,\n                        int is_disabled);\nint\nlibxrdp_drdynvc_start(struct xrdp_session *session);\nint\nlibxrdp_drdynvc_open(struct xrdp_session *session, const char *name,\n                     int flags, struct xrdp_drdynvc_procs *procs,\n                     int *chan_id);\nint\nlibxrdp_drdynvc_close(struct xrdp_session *session, int chan_id);\nint\nlibxrdp_drdynvc_data_first(struct xrdp_session *session, int chan_id,\n                           const char *data, int data_bytes,\n                           int total_data_bytes);\nint\nlibxrdp_drdynvc_data(struct xrdp_session *session, int chan_id,\n                     const char *data, int data_bytes);\nint\nlibxrdp_orders_send_brush(struct xrdp_session *session,\n                          int width, int height, int bpp, int type,\n                          int size, char *data, int cache_id);\nint\nlibxrdp_orders_send_create_os_surface(struct xrdp_session *session, int id,\n                                      int width, int height,\n                                      struct list *del_list);\nint\nlibxrdp_orders_send_switch_os_surface(struct xrdp_session *session, int id);\nint\nlibxrdp_window_new_update(struct xrdp_session *session, int window_id,\n                          struct rail_window_state_order *window_state,\n                          int flags);\nint\nlibxrdp_window_delete(struct xrdp_session *session, int window_id);\nint\nlibxrdp_window_icon(struct xrdp_session *session, int window_id,\n                    int cache_entry, int cache_id,\n                    struct rail_icon_info *icon_info, int flags);\nint\nlibxrdp_window_cached_icon(struct xrdp_session *session, int window_id,\n                           int cache_entry, int cache_id,\n                           int flags);\nint\nlibxrdp_notify_new_update(struct xrdp_session *session,\n                          int window_id, int notify_id,\n                          struct rail_notify_state_order *notify_state,\n                          int flags);\nint\nlibxrdp_notify_delete(struct xrdp_session *session,\n                      int window_id, int notify_id);\nint\nlibxrdp_monitored_desktop(struct xrdp_session *session,\n                          struct rail_monitored_desktop_order *mdo,\n                          int flags);\nint\nlibxrdp_codec_jpeg_compress(struct xrdp_session *session,\n                            int format, char *inp_data,\n                            int width, int height,\n                            int stride, int x, int y,\n                            int cx, int cy, int quality,\n                            char *out_data, int *io_len);\nint\nlibxrdp_fastpath_send_surface(struct xrdp_session *session,\n                              char *data_pad, int pad_bytes,\n                              int data_bytes,\n                              int destLeft, int dst_Top,\n                              int destRight, int destBottom, int bpp,\n                              int codecID, int width, int height);\nint EXPORT_CC\nlibxrdp_fastpath_send_frame_marker(struct xrdp_session *session,\n                                   int frame_action, int frame_id);\nint EXPORT_CC\nlibxrdp_send_session_info(struct xrdp_session *session, const char *data,\n                          int data_bytes);\nint EXPORT_CC\nlibxrdp_planar_compress(char *in_data, int width, int height,\n                        struct stream *s, int bpp, int byte_limit,\n                        int start_line, struct stream *temp_s,\n                        int e, int flags);\n/**\n * Processes a stream that is based on either\n *  2.2.1.3.6 Client Monitor Data (TS_UD_CS_MONITOR) or 2.2.2.2 DISPLAYCONTROL_MONITOR_LAYOUT_PDU\n *  and then stores the processed monitor data into the description parameter.\n * @param s\n *      The stream to process.\n * @param description\n *      Must be pre-allocated. Monitor data is filled in as part of processing the stream.\n * @param full_parameters\n *      0 if the monitor stream is from 2.2.1.3.6 Client Monitor Data (TS_UD_CS_MONITOR)\n *      1 if the monitor stream is from 2.2.2.2 DISPLAYCONTROL_MONITOR_LAYOUT_PDU\n * @return 0 if the data is processed, non-zero if there is an error.\n */\nint EXPORT_CC\nlibxrdp_process_monitor_stream(struct stream *s, struct display_size_description *description,\n                               int full_parameters);\n\n/**\n * Processes a stream that is based on [MS-RDPBCGR] 2.2.1.3.9 Client\n * Monitor Extended Data (TS_UD_CS_MONITOR_EX)\n *\n * Data is stored in a struct which has already been read by\n * libxrdp_process_monitor_stream() withj full_parameters set to 0.\n *\n * @param s Stream to read data from. Stream is read up to monitorAttributeSize\n * @param description Result of reading TS_UD_CS_MONITOR PDU\n * @return 0 if the data is processed, non-zero if there is an error.\n */\nint EXPORT_CC\nlibxrdp_process_monitor_ex_stream(struct stream *s,\n                                  struct display_size_description *description);\n\n/**\n * Convert a list of monitors into a full description\n *\n * Monitor data is sanitised during the conversion\n *\n * @param num_monitor Monitor count (> 0)\n * @param monitors List of monitors\n * @param[out] description Display size description\n *\n * @return 0 if the data is processed, non-zero if there is an error.\n */\nint\nlibxrdp_init_display_size_description(\n    unsigned int num_monitor,\n    const struct monitor_info *monitors,\n    struct display_size_description *description);\n\n#endif\n"
  },
  {
    "path": "libxrdp/xrdp_bitmap32_compress.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * planar bitmap compressor\n * 32 bpp compression\n */\n\n/*\nRDP 6.0 Bitmap Compression\nhttp://msdn.microsoft.com/en-us/library/cc241877.aspx\n*/\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n\n#define FLAGS_RLE     0x10\n#define FLAGS_NOALPHA 0x20\n\n\n\n/*****************************************************************************/\n/* split RGB */\nstatic int\nfsplit3(char *in_data, int start_line, int width, int e,\n        char *r_data, char *g_data, char *b_data)\n{\n#if defined(L_ENDIAN)\n    int rp;\n    int gp;\n    int bp;\n#endif\n    int index;\n    int out_index;\n    int pixel;\n    int cy;\n    int *ptr32;\n\n    cy = 0;\n    out_index = 0;\n    while (start_line >= 0)\n    {\n        ptr32 = (int *) (in_data + start_line * width * 4);\n        index = 0;\n#if defined(L_ENDIAN)\n        while (index + 4 <= width)\n        {\n            pixel = *ptr32;\n            ptr32++;\n            rp  = (pixel >> 16) & 0x000000ff;\n            gp  = (pixel >>  8) & 0x000000ff;\n            bp  = (pixel >>  0) & 0x000000ff;\n            pixel  = *ptr32;\n            ptr32++;\n            rp |= (pixel >>  8) & 0x0000ff00;\n            gp |= (pixel <<  0) & 0x0000ff00;\n            bp |= (pixel <<  8) & 0x0000ff00;\n            pixel = *ptr32;\n            ptr32++;\n            rp |= (pixel >>  0) & 0x00ff0000;\n            gp |= (pixel <<  8) & 0x00ff0000;\n            bp |= (pixel << 16) & 0x00ff0000;\n            pixel = *ptr32;\n            ptr32++;\n            rp |= (pixel <<  8) & 0xff000000;\n            gp |= (pixel << 16) & 0xff000000;\n            bp |= (pixel << 24) & 0xff000000;\n            *((int *)(r_data + out_index)) = rp;\n            *((int *)(g_data + out_index)) = gp;\n            *((int *)(b_data + out_index)) = bp;\n            out_index += 4;\n            index += 4;\n        }\n#endif\n        while (index < width)\n        {\n            pixel = *ptr32;\n            ptr32++;\n            r_data[out_index] = pixel >> 16;\n            g_data[out_index] = pixel >> 8;\n            b_data[out_index] = pixel >> 0;\n            out_index++;\n            index++;\n        }\n        for (index = 0; index < e; index++)\n        {\n            r_data[out_index] = r_data[out_index - 1];\n            g_data[out_index] = g_data[out_index - 1];\n            b_data[out_index] = b_data[out_index - 1];\n            out_index++;\n        }\n        start_line--;\n        cy++;\n        if (out_index + width + e > 64 * 64)\n        {\n            break;\n        }\n    }\n    return cy;\n}\n\n/*****************************************************************************/\n/* split ARGB */\nstatic int\nfsplit4(char *in_data, int start_line, int width, int e,\n        char *a_data, char *r_data, char *g_data, char *b_data)\n{\n#if defined(L_ENDIAN)\n    int ap;\n    int rp;\n    int gp;\n    int bp;\n#endif\n    int index;\n    int out_index;\n    int pixel;\n    int cy;\n    int *ptr32;\n\n    cy = 0;\n    out_index = 0;\n    while (start_line >= 0)\n    {\n        ptr32 = (int *) (in_data + start_line * width * 4);\n        index = 0;\n#if defined(L_ENDIAN)\n        while (index + 4 <= width)\n        {\n            pixel = *ptr32;\n            ptr32++;\n            ap  = (pixel >> 24) & 0x000000ff;\n            rp  = (pixel >> 16) & 0x000000ff;\n            gp  = (pixel >>  8) & 0x000000ff;\n            bp  = (pixel >>  0) & 0x000000ff;\n            pixel  = *ptr32;\n            ptr32++;\n            ap |= (pixel >> 16) & 0x0000ff00;\n            rp |= (pixel >>  8) & 0x0000ff00;\n            gp |= (pixel <<  0) & 0x0000ff00;\n            bp |= (pixel <<  8) & 0x0000ff00;\n            pixel = *ptr32;\n            ptr32++;\n            ap |= (pixel >>  8) & 0x00ff0000;\n            rp |= (pixel >>  0) & 0x00ff0000;\n            gp |= (pixel <<  8) & 0x00ff0000;\n            bp |= (pixel << 16) & 0x00ff0000;\n            pixel = *ptr32;\n            ptr32++;\n            ap |= (pixel <<  0) & 0xff000000;\n            rp |= (pixel <<  8) & 0xff000000;\n            gp |= (pixel << 16) & 0xff000000;\n            bp |= (pixel << 24) & 0xff000000;\n            *((int *)(a_data + out_index)) = ap;\n            *((int *)(r_data + out_index)) = rp;\n            *((int *)(g_data + out_index)) = gp;\n            *((int *)(b_data + out_index)) = bp;\n            out_index += 4;\n            index += 4;\n        }\n#endif\n        while (index < width)\n        {\n            pixel = *ptr32;\n            ptr32++;\n            a_data[out_index] = pixel >> 24;\n            r_data[out_index] = pixel >> 16;\n            g_data[out_index] = pixel >> 8;\n            b_data[out_index] = pixel >> 0;\n            out_index++;\n            index++;\n        }\n        for (index = 0; index < e; index++)\n        {\n            a_data[out_index] = a_data[out_index - 1];\n            r_data[out_index] = r_data[out_index - 1];\n            g_data[out_index] = g_data[out_index - 1];\n            b_data[out_index] = b_data[out_index - 1];\n            out_index++;\n        }\n        start_line--;\n        cy++;\n        if (out_index + width + e > 64 * 64)\n        {\n            break;\n        }\n    }\n    return cy;\n}\n\n/*****************************************************************************/\n#define DELTA_ONE \\\n    do { \\\n        delta = src8[cx] - src8[0]; \\\n        is_neg = (delta >> 7) & 1; \\\n        dst8[cx] = (((delta ^ -is_neg) + is_neg) << 1) - is_neg; \\\n        src8++; \\\n        dst8++; \\\n    } while (0)\n\n/*****************************************************************************/\nstatic int\nfdelta(char *in_plane, char *out_plane, int cx, int cy)\n{\n    char delta;\n    char is_neg;\n    char *src8;\n    char *dst8;\n    char *src8_end;\n\n    g_memcpy(out_plane, in_plane, cx);\n    src8 = in_plane;\n    dst8 = out_plane;\n    src8_end = src8 + (cx * cy - cx);\n    while (src8 + 8 <= src8_end)\n    {\n        DELTA_ONE;\n        DELTA_ONE;\n        DELTA_ONE;\n        DELTA_ONE;\n        DELTA_ONE;\n        DELTA_ONE;\n        DELTA_ONE;\n        DELTA_ONE;\n    }\n    while (src8 < src8_end)\n    {\n        DELTA_ONE;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nfout(int collen, int replen, char *colptr, struct stream *s)\n{\n    int code;\n    int lcollen;\n    int lreplen;\n    int cont;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"fout: collen %d replen %d\", collen, replen);\n    cont = collen > 13;\n    while (cont)\n    {\n        lcollen = collen;\n        if (lcollen > 15)\n        {\n            lcollen = 15;\n        }\n        code = lcollen << 4;\n        out_uint8(s, code);\n        out_uint8a(s, colptr, lcollen);\n        colptr += lcollen;\n        collen -= lcollen;\n        cont = collen > 13;\n    }\n    cont = (collen > 0) || (replen > 0);\n    while (cont)\n    {\n        lreplen = replen;\n        if ((collen == 0) && (lreplen > 15))\n        {\n            /* big run */\n            if (lreplen > 47)\n            {\n                lreplen = 47;\n            }\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"fout: big run lreplen %d\", lreplen);\n            replen -= lreplen;\n            code = ((lreplen & 0xF) << 4) | ((lreplen & 0xF0) >> 4);\n            out_uint8(s, code);\n            colptr += lreplen;\n        }\n        else\n        {\n            if (lreplen > 15)\n            {\n                lreplen = 15;\n            }\n            replen -= lreplen;\n            if (lreplen < 3)\n            {\n                collen += lreplen;\n                lreplen = 0;\n            }\n            code = (collen << 4) | lreplen;\n            out_uint8(s, code);\n            out_uint8a(s, colptr, collen);\n            colptr += collen + lreplen;\n            collen = 0;\n        }\n        cont = replen > 0;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nfpack(char *plane, int cx, int cy, struct stream *s)\n{\n    char *ptr8;\n    char *colptr;\n    char *lend;\n    char *holdp;\n    int jndex;\n    int collen;\n    int replen;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"fpack:\");\n    holdp = s->p;\n    for (jndex = 0; jndex < cy; jndex++)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"line start line %d cx %d cy %d\", jndex, cx, cy);\n        ptr8 = plane + jndex * cx;\n        LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"line content\", ptr8, cx);\n        lend = ptr8 + (cx - 1);\n        colptr = ptr8;\n        if (colptr[0] == 0)\n        {\n            collen = 0;\n            replen = 1;\n        }\n        else\n        {\n            collen = 1;\n            replen = 0;\n        }\n        while (ptr8 < lend)\n        {\n            if (ptr8[0] == ptr8[1])\n            {\n                replen++;\n            }\n            else\n            {\n                if (replen > 0)\n                {\n                    if (replen < 3)\n                    {\n                        collen += replen + 1;\n                        replen = 0;\n                    }\n                    else\n                    {\n                        fout(collen, replen, colptr, s);\n                        colptr = ptr8 + 1;\n                        replen = 0;\n                        collen = 1;\n                    }\n                }\n                else\n                {\n                    collen++;\n                }\n            }\n            ptr8++;\n        }\n        /* end of line */\n        fout(collen, replen, colptr, s);\n    }\n    return (int) (s->p - holdp);\n}\n\n/*****************************************************************************/\nstatic int\nfoutraw3(struct stream *s, int bytes, int header,\n         char *r_data, char *g_data, char *b_data)\n{\n    out_uint8(s, header);\n    out_uint8a(s, r_data, bytes);\n    out_uint8a(s, g_data, bytes);\n    out_uint8a(s, b_data, bytes);\n    /* pad if no RLE */\n    out_uint8(s, 0x00);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nfoutraw4(struct stream *s, int bytes, int header,\n         char *a_data, char *r_data, char *g_data, char *b_data)\n{\n    out_uint8(s, header);\n    out_uint8a(s, a_data, bytes);\n    out_uint8a(s, r_data, bytes);\n    out_uint8a(s, g_data, bytes);\n    out_uint8a(s, b_data, bytes);\n    /* pad if no RLE */\n    out_uint8(s, 0x00);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns the number of lines compressed */\nint\nxrdp_bitmap32_compress(char *in_data, int width, int height,\n                       struct stream *s, int bpp, int byte_limit,\n                       int start_line, struct stream *temp_s,\n                       int e, int flags)\n{\n    char *a_data;\n    char *r_data;\n    char *g_data;\n    char *b_data;\n    char *sa_data;\n    char *sr_data;\n    char *sg_data;\n    char *sb_data;\n    char *hold_p;\n    int a_bytes;\n    int r_bytes;\n    int g_bytes;\n    int b_bytes;\n    int cx;\n    int cy;\n    int max_bytes;\n    int total_bytes;\n    int header;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_bitmap32_compress:\");\n    max_bytes = 4 * 1024;\n    /* need max 8, 4K planes for work */\n    if (max_bytes * 8 > temp_s->size)\n    {\n        return 0;\n    }\n    header = flags & 0xFF;\n    cx = width + e;\n    sa_data = temp_s->data;\n    sr_data = sa_data + max_bytes;\n    sg_data = sr_data + max_bytes;\n    sb_data = sg_data + max_bytes;\n    a_data = sb_data + max_bytes;\n    r_data = a_data + max_bytes;\n    g_data = r_data + max_bytes;\n    b_data = g_data + max_bytes;\n    hold_p = s->p;\n\n    if (header & FLAGS_NOALPHA)\n    {\n        cy = fsplit3(in_data, start_line, width, e,\n                     sr_data, sg_data, sb_data);\n        if (header & FLAGS_RLE)\n        {\n            fdelta(sr_data, r_data, cx, cy);\n            fdelta(sg_data, g_data, cx, cy);\n            fdelta(sb_data, b_data, cx, cy);\n            while (cy > 0)\n            {\n                s->p = hold_p;\n                out_uint8(s, header);\n                r_bytes = fpack(r_data, cx, cy, s);\n                g_bytes = fpack(g_data, cx, cy, s);\n                b_bytes = fpack(b_data, cx, cy, s);\n                max_bytes = cx * cy * 3;\n                total_bytes = r_bytes + g_bytes + b_bytes;\n                if (total_bytes > max_bytes)\n                {\n                    if (2 + max_bytes <= byte_limit)\n                    {\n                        s->p = hold_p;\n                        foutraw3(s, cx * cy, FLAGS_NOALPHA, sr_data, sg_data, sb_data);\n                        break;\n                    }\n                }\n                if (1 + total_bytes <= byte_limit)\n                {\n                    break;\n                }\n                cy--;\n            }\n        }\n        else\n        {\n            while (cy > 0)\n            {\n                max_bytes = cx * cy * 3;\n                if (2 + max_bytes <= byte_limit)\n                {\n                    s->p = hold_p;\n                    foutraw3(s, cx * cy, FLAGS_NOALPHA, sr_data, sg_data, sb_data);\n                    break;\n                }\n                cy--;\n            }\n        }\n    }\n    else\n    {\n        cy = fsplit4(in_data, start_line, width, e,\n                     sa_data, sr_data, sg_data, sb_data);\n        if (header & FLAGS_RLE)\n        {\n            fdelta(sa_data, a_data, cx, cy);\n            fdelta(sr_data, r_data, cx, cy);\n            fdelta(sg_data, g_data, cx, cy);\n            fdelta(sb_data, b_data, cx, cy);\n            while (cy > 0)\n            {\n                s->p = hold_p;\n                out_uint8(s, header);\n                a_bytes = fpack(a_data, cx, cy, s);\n                r_bytes = fpack(r_data, cx, cy, s);\n                g_bytes = fpack(g_data, cx, cy, s);\n                b_bytes = fpack(b_data, cx, cy, s);\n                max_bytes = cx * cy * 4;\n                total_bytes = a_bytes + r_bytes + g_bytes + b_bytes;\n                if (total_bytes > max_bytes)\n                {\n                    if (2 + max_bytes <= byte_limit)\n                    {\n                        s->p = hold_p;\n                        foutraw4(s, cx * cy, 0, sa_data, sr_data, sg_data, sb_data);\n                        break;\n                    }\n                }\n                if (1 + total_bytes <= byte_limit)\n                {\n                    break;\n                }\n                cy--;\n            }\n        }\n        else\n        {\n            while (cy > 0)\n            {\n                max_bytes = cx * cy * 4;\n                if (2 + max_bytes <= byte_limit)\n                {\n                    s->p = hold_p;\n                    foutraw4(s, cx * cy, 0, sa_data, sr_data, sg_data, sb_data);\n                    break;\n                }\n                cy--;\n            }\n        }\n    }\n    return cy;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_bitmap_compress.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * bitmap compressor\n * This is the original RDP bitmap compression algorithm.  Pixel based.\n * This does not do 32 bpp compression, nscodec, rfx, etc\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n\n#define BC_MAX_BYTES (16 * 1024)\n\n/*****************************************************************************/\n#define IN_PIXEL8(in_ptr, in_x, in_y, in_w, in_last_pixel, in_pixel); \\\n    do { \\\n        if (in_ptr == 0) \\\n        { \\\n            in_pixel = 0; \\\n        } \\\n        else if (in_x < in_w) \\\n        { \\\n            in_pixel = GETPIXEL8(in_ptr, in_x, in_y, in_w); \\\n        } \\\n        else \\\n        { \\\n            in_pixel = in_last_pixel; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************/\n#define IN_PIXEL16(in_ptr, in_x, in_y, in_w, in_last_pixel, in_pixel); \\\n    do { \\\n        if (in_ptr == 0) \\\n        { \\\n            in_pixel = 0; \\\n        } \\\n        else if (in_x < in_w) \\\n        { \\\n            in_pixel = GETPIXEL16(in_ptr, in_x, in_y, in_w); \\\n        } \\\n        else \\\n        { \\\n            in_pixel = in_last_pixel; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************/\n#define IN_PIXEL32(in_ptr, in_x, in_y, in_w, in_last_pixel, in_pixel); \\\n    do { \\\n        if (in_ptr == 0) \\\n        { \\\n            in_pixel = 0; \\\n        } \\\n        else if (in_x < in_w) \\\n        { \\\n            in_pixel = GETPIXEL32(in_ptr, in_x, in_y, in_w); \\\n        } \\\n        else \\\n        { \\\n            in_pixel = in_last_pixel; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************/\n/* color */\n#define OUT_COLOR_COUNT1(in_count, in_s, in_data) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                temp = (0x3 << 5) | in_count; \\\n                out_uint8(in_s, temp); \\\n                out_uint8(in_s, in_data); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x60); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n                out_uint8(in_s, in_data); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf3); \\\n                out_uint16_le(in_s, in_count); \\\n                out_uint8(in_s, in_data); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* color */\n#define OUT_COLOR_COUNT2(in_count, in_s, in_data) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                temp = (0x3 << 5) | in_count; \\\n                out_uint8(in_s, temp); \\\n                out_uint16_le(in_s, in_data); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x60); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n                out_uint16_le(in_s, in_data); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf3); \\\n                out_uint16_le(in_s, in_count); \\\n                out_uint16_le(in_s, in_data); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* color */\n#define OUT_COLOR_COUNT3(in_count, in_s, in_data) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                temp = (0x3 << 5) | in_count; \\\n                out_uint8(in_s, temp); \\\n                out_uint8(in_s, in_data & 0xff); \\\n                out_uint8(in_s, (in_data >> 8) & 0xff); \\\n                out_uint8(in_s, (in_data >> 16) & 0xff); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x60); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n                out_uint8(in_s, in_data & 0xff); \\\n                out_uint8(in_s, (in_data >> 8) & 0xff); \\\n                out_uint8(in_s, (in_data >> 16) & 0xff); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf3); \\\n                out_uint16_le(in_s, in_count); \\\n                out_uint8(in_s, in_data & 0xff); \\\n                out_uint8(in_s, (in_data >> 8) & 0xff); \\\n                out_uint8(in_s, (in_data >> 16) & 0xff); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* copy */\n#define OUT_COPY_COUNT1(in_count, in_s, in_data) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                temp = (0x4 << 5) | in_count; \\\n                out_uint8(in_s, temp); \\\n                out_uint8a(in_s, in_data->data, in_count); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x80); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n                out_uint8a(in_s, in_data->data, in_count); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf4); \\\n                out_uint16_le(in_s, in_count); \\\n                out_uint8a(in_s, in_data->data, in_count); \\\n            } \\\n        } \\\n        in_count = 0; \\\n        init_stream(in_data, 0); \\\n    } while (0)\n\n/*****************************************************************************/\n/* copy */\n#define OUT_COPY_COUNT2(in_count, in_s, in_data) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                temp = (0x4 << 5) | in_count; \\\n                out_uint8(in_s, temp); \\\n                temp = in_count * 2; \\\n                out_uint8a(in_s, in_data->data, temp); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x80); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n                temp = in_count * 2; \\\n                out_uint8a(in_s, in_data->data, temp); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf4); \\\n                out_uint16_le(in_s, in_count); \\\n                temp = in_count * 2; \\\n                out_uint8a(in_s, in_data->data, temp); \\\n            } \\\n        } \\\n        in_count = 0; \\\n        init_stream(in_data, 0); \\\n    } while (0)\n\n/*****************************************************************************/\n/* copy */\n#define OUT_COPY_COUNT3(in_count, in_s, in_data) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                temp = (0x4 << 5) | in_count; \\\n                out_uint8(in_s, temp); \\\n                temp = in_count * 3; \\\n                out_uint8a(in_s, in_data->end, temp); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x80); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n                temp = in_count * 3; \\\n                out_uint8a(in_s, in_data->end, temp); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf4); \\\n                out_uint16_le(in_s, in_count); \\\n                temp = in_count * 3; \\\n                out_uint8a(in_s, in_data->end, temp); \\\n            } \\\n        } \\\n        in_count = 0; \\\n        init_stream(in_data, 0); \\\n    } while (0)\n\n/*****************************************************************************/\n/* bicolor */\n#define OUT_BICOLOR_COUNT1(in_count, in_s, in_color1, in_color2) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count / 2 < 16) \\\n            { \\\n                temp = (0xe << 4) | (in_count / 2); \\\n                out_uint8(in_s, temp); \\\n                out_uint8(in_s, in_color1); \\\n                out_uint8(in_s, in_color2); \\\n            } \\\n            else if (in_count / 2 < 256 + 16) \\\n            { \\\n                out_uint8(in_s, 0xe0); \\\n                temp = in_count / 2 - 16; \\\n                out_uint8(in_s, temp); \\\n                out_uint8(in_s, in_color1); \\\n                out_uint8(in_s, in_color2); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf8); \\\n                temp = in_count / 2; \\\n                out_uint16_le(in_s, temp); \\\n                out_uint8(in_s, in_color1); \\\n                out_uint8(in_s, in_color2); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* bicolor */\n#define OUT_BICOLOR_COUNT2(in_count, in_s, in_color1, in_color2) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count / 2 < 16) \\\n            { \\\n                temp = (0xe << 4) | (in_count / 2); \\\n                out_uint8(in_s, temp); \\\n                out_uint16_le(in_s, in_color1); \\\n                out_uint16_le(in_s, in_color2); \\\n            } \\\n            else if (in_count / 2 < 256 + 16) \\\n            { \\\n                out_uint8(in_s, 0xe0); \\\n                temp = in_count / 2 - 16; \\\n                out_uint8(in_s, temp); \\\n                out_uint16_le(in_s, in_color1); \\\n                out_uint16_le(in_s, in_color2); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf8); \\\n                temp = in_count / 2; \\\n                out_uint16_le(in_s, temp); \\\n                out_uint16_le(in_s, in_color1); \\\n                out_uint16_le(in_s, in_color2); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* bicolor */\n#define OUT_BICOLOR_COUNT3(in_count, in_s, in_color1, in_color2) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count / 2 < 16) \\\n            { \\\n                temp = (0xe << 4) | (in_count / 2); \\\n                out_uint8(in_s, temp); \\\n                out_uint8(in_s, in_color1 & 0xff); \\\n                out_uint8(in_s, (in_color1 >> 8) & 0xff); \\\n                out_uint8(in_s, (in_color1 >> 16) & 0xff); \\\n                out_uint8(in_s, in_color2 & 0xff); \\\n                out_uint8(in_s, (in_color2 >> 8) & 0xff); \\\n                out_uint8(in_s, (in_color2 >> 16) & 0xff); \\\n            } \\\n            else if (in_count / 2 < 256 + 16) \\\n            { \\\n                out_uint8(in_s, 0xe0); \\\n                temp = in_count / 2 - 16; \\\n                out_uint8(in_s, temp); \\\n                out_uint8(in_s, in_color1 & 0xff); \\\n                out_uint8(in_s, (in_color1 >> 8) & 0xff); \\\n                out_uint8(in_s, (in_color1 >> 16) & 0xff); \\\n                out_uint8(in_s, in_color2 & 0xff); \\\n                out_uint8(in_s, (in_color2 >> 8) & 0xff); \\\n                out_uint8(in_s, (in_color2 >> 16) & 0xff); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf8); \\\n                temp = in_count / 2; \\\n                out_uint16_le(in_s, temp); \\\n                out_uint8(in_s, in_color1 & 0xff); \\\n                out_uint8(in_s, (in_color1 >> 8) & 0xff); \\\n                out_uint8(in_s, (in_color1 >> 16) & 0xff); \\\n                out_uint8(in_s, in_color2 & 0xff); \\\n                out_uint8(in_s, (in_color2 >> 8) & 0xff); \\\n                out_uint8(in_s, (in_color2 >> 16) & 0xff); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* fill */\n#define OUT_FILL_COUNT1(in_count, in_s) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                out_uint8(in_s, in_count); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x0); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf0); \\\n                out_uint16_le(in_s, in_count); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* fill */\n#define OUT_FILL_COUNT2(in_count, in_s) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                out_uint8(in_s, in_count); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x0); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf0); \\\n                out_uint16_le(in_s, in_count); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* fill */\n#define OUT_FILL_COUNT3(in_count, in_s) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                out_uint8(in_s, in_count); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x0); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf0); \\\n                out_uint16_le(in_s, in_count); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* mix */\n#define OUT_MIX_COUNT1(in_count, in_s) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                temp = (0x1 << 5) | in_count; \\\n                out_uint8(in_s, temp); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x20); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf1); \\\n                out_uint16_le(in_s, in_count); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* mix */\n#define OUT_MIX_COUNT2(in_count, in_s) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                temp = (0x1 << 5) | in_count; \\\n                out_uint8(in_s, temp); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x20); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf1); \\\n                out_uint16_le(in_s, in_count); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* mix */\n#define OUT_MIX_COUNT3(in_count, in_s) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if (in_count < 32) \\\n            { \\\n                temp = (0x1 << 5) | in_count; \\\n                out_uint8(in_s, temp); \\\n            } \\\n            else if (in_count < 256 + 32) \\\n            { \\\n                out_uint8(in_s, 0x20); \\\n                temp = in_count - 32; \\\n                out_uint8(in_s, temp); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf1); \\\n                out_uint16_le(in_s, in_count); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* fom */\n#define OUT_FOM_COUNT1(in_count, in_s, in_mask, in_mask_len) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if ((in_count % 8) == 0 && in_count < 249) \\\n            { \\\n                temp = (0x2 << 5) | (in_count / 8); \\\n                out_uint8(in_s, temp); \\\n                out_uint8a(in_s, in_mask, in_mask_len); \\\n            } \\\n            else if (in_count < 256) \\\n            { \\\n                out_uint8(in_s, 0x40); \\\n                temp = in_count - 1; \\\n                out_uint8(in_s, temp); \\\n                out_uint8a(in_s, in_mask, in_mask_len); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf2); \\\n                out_uint16_le(in_s, in_count); \\\n                out_uint8a(in_s, in_mask, in_mask_len); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* fom */\n#define OUT_FOM_COUNT2(in_count, in_s, in_mask, in_mask_len) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if ((in_count % 8) == 0 && in_count < 249) \\\n            { \\\n                temp = (0x2 << 5) | (in_count / 8); \\\n                out_uint8(in_s, temp); \\\n                out_uint8a(in_s, in_mask, in_mask_len); \\\n            } \\\n            else if (in_count < 256) \\\n            { \\\n                out_uint8(in_s, 0x40); \\\n                temp = in_count - 1; \\\n                out_uint8(in_s, temp); \\\n                out_uint8a(in_s, in_mask, in_mask_len); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf2); \\\n                out_uint16_le(in_s, in_count); \\\n                out_uint8a(in_s, in_mask, in_mask_len); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n/* fill or mix (fom) */\n#define OUT_FOM_COUNT3(in_count, in_s, in_mask, in_mask_len) \\\n    do { \\\n        if (in_count > 0) \\\n        { \\\n            if ((in_count % 8) == 0 && in_count < 249) \\\n            { \\\n                temp = (0x2 << 5) | (in_count / 8); \\\n                out_uint8(in_s, temp); \\\n                out_uint8a(in_s, in_mask, in_mask_len); \\\n            } \\\n            else if (in_count < 256) \\\n            { \\\n                out_uint8(in_s, 0x40); \\\n                temp = in_count - 1; \\\n                out_uint8(in_s, temp); \\\n                out_uint8a(in_s, in_mask, in_mask_len); \\\n            } \\\n            else \\\n            { \\\n                out_uint8(in_s, 0xf2); \\\n                out_uint16_le(in_s, in_count); \\\n                out_uint8a(in_s, in_mask, in_mask_len); \\\n            } \\\n        } \\\n        in_count = 0; \\\n    } while (0)\n\n/*****************************************************************************/\n#define TEST_FILL \\\n    ((last_line == 0 && pixel == 0) || \\\n     (last_line != 0 && pixel == ypixel))\n#define TEST_MIX \\\n    ((last_line == 0 && pixel == mix) || \\\n     (last_line != 0 && pixel == (ypixel ^ mix)))\n#define TEST_FOM (TEST_FILL || TEST_MIX)\n#define TEST_COLOR (pixel == last_pixel)\n#define TEST_BICOLOR \\\n    ( \\\n      (pixel != last_pixel) && \\\n      ( \\\n        (!bicolor_spin && pixel == bicolor1 && last_pixel == bicolor2) || \\\n        (bicolor_spin && pixel == bicolor2 && last_pixel == bicolor1) \\\n      ) \\\n    )\n#define RESET_COUNTS \\\n    do { \\\n        bicolor_count = 0; \\\n        fill_count = 0; \\\n        color_count = 0; \\\n        mix_count = 0; \\\n        fom_count = 0; \\\n        fom_mask_len = 0; \\\n        bicolor_spin = 0; \\\n    } while (0)\n\n/*****************************************************************************/\nint\nxrdp_bitmap_compress(char *in_data, int width, int height,\n                     struct stream *s, int bpp, int byte_limit,\n                     int start_line, struct stream *temp_s,\n                     int e)\n{\n    char *line;\n    char *last_line;\n    char fom_mask[8192]; /* good for up to 64K bitmap */\n    int lines_sent;\n    int pixel;\n    int count;\n    int color_count;\n    int last_pixel;\n    int bicolor_count;\n    int bicolor1;\n    int bicolor2;\n    int bicolor_spin;\n    int end;\n    int i;\n    int out_count;\n    int ypixel;\n    int last_ypixel;\n    int fill_count;\n    int mix_count;\n    int mix;\n    int fom_count;\n    int fom_mask_len;\n    int temp; /* used in macros */\n\n    init_stream(temp_s, 0);\n    fom_mask_len = 0;\n    last_line = 0;\n    lines_sent = 0;\n    end = width + e;\n    count = 0;\n    color_count = 0;\n    last_pixel = 0;\n    last_ypixel = 0;\n    bicolor_count = 0;\n    bicolor1 = 0;\n    bicolor2 = 0;\n    bicolor_spin = 0;\n    fill_count = 0;\n    mix_count = 0;\n    fom_count = 0;\n\n    if (bpp == 8)\n    {\n        mix = 0xff;\n        out_count = end;\n        line = in_data + width * start_line;\n\n        while (start_line >= 0 && out_count <= BC_MAX_BYTES)\n        {\n            i = (s->p - s->data) + count;\n\n            if (i - color_count >= byte_limit &&\n                    i - bicolor_count >= byte_limit &&\n                    i - fill_count >= byte_limit &&\n                    i - mix_count >= byte_limit &&\n                    i - fom_count >= byte_limit)\n            {\n                break;\n            }\n\n            out_count += end;\n\n            for (i = 0; i < end; i++)\n            {\n                /* read next pixel */\n                IN_PIXEL8(line, i, 0, width, last_pixel, pixel);\n                IN_PIXEL8(last_line, i, 0, width, last_ypixel, ypixel);\n\n                if (!TEST_FILL)\n                {\n                    if (fill_count > 3 &&\n                            fill_count >= color_count &&\n                            fill_count >= bicolor_count &&\n                            fill_count >= mix_count &&\n                            fill_count >= fom_count)\n                    {\n                        count -= fill_count;\n                        OUT_COPY_COUNT1(count, s, temp_s);\n                        OUT_FILL_COUNT1(fill_count, s);\n                        RESET_COUNTS;\n                    }\n\n                    fill_count = 0;\n                }\n\n                if (!TEST_MIX)\n                {\n                    if (mix_count > 3 &&\n                            mix_count >= fill_count &&\n                            mix_count >= bicolor_count &&\n                            mix_count >= color_count &&\n                            mix_count >= fom_count)\n                    {\n                        count -= mix_count;\n                        OUT_COPY_COUNT1(count, s, temp_s);\n                        OUT_MIX_COUNT1(mix_count, s);\n                        RESET_COUNTS;\n                    }\n\n                    mix_count = 0;\n                }\n\n                if (!TEST_COLOR)\n                {\n                    if (color_count > 3 &&\n                            color_count >= fill_count &&\n                            color_count >= bicolor_count &&\n                            color_count >= mix_count &&\n                            color_count >= fom_count)\n                    {\n                        count -= color_count;\n                        OUT_COPY_COUNT1(count, s, temp_s);\n                        OUT_COLOR_COUNT1(color_count, s, last_pixel);\n                        RESET_COUNTS;\n                    }\n\n                    color_count = 0;\n                }\n\n                if (!TEST_BICOLOR)\n                {\n                    if (bicolor_count > 3 &&\n                            bicolor_count >= fill_count &&\n                            bicolor_count >= color_count &&\n                            bicolor_count >= mix_count &&\n                            bicolor_count >= fom_count)\n                    {\n                        if ((bicolor_count % 2) == 0)\n                        {\n                            count -= bicolor_count;\n                            OUT_COPY_COUNT1(count, s, temp_s);\n                            OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor1, bicolor2);\n                        }\n                        else\n                        {\n                            bicolor_count--;\n                            count -= bicolor_count;\n                            OUT_COPY_COUNT1(count, s, temp_s);\n                            OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor2, bicolor1);\n                        }\n\n                        RESET_COUNTS;\n                    }\n\n                    bicolor_count = 0;\n                    bicolor1 = last_pixel;\n                    bicolor2 = pixel;\n                    bicolor_spin = 0;\n                }\n\n                if (!TEST_FOM)\n                {\n                    if (fom_count > 3 &&\n                            fom_count >= fill_count &&\n                            fom_count >= color_count &&\n                            fom_count >= mix_count &&\n                            fom_count >= bicolor_count)\n                    {\n                        count -= fom_count;\n                        OUT_COPY_COUNT1(count, s, temp_s);\n                        OUT_FOM_COUNT1(fom_count, s, fom_mask, fom_mask_len);\n                        RESET_COUNTS;\n                    }\n\n                    fom_count = 0;\n                    fom_mask_len = 0;\n                }\n\n                if (TEST_FILL)\n                {\n                    fill_count++;\n                }\n\n                if (TEST_MIX)\n                {\n                    mix_count++;\n                }\n\n                if (TEST_COLOR)\n                {\n                    color_count++;\n                }\n\n                if (TEST_BICOLOR)\n                {\n                    bicolor_spin = !bicolor_spin;\n                    bicolor_count++;\n                }\n\n                if (TEST_FOM)\n                {\n                    if ((fom_count % 8) == 0)\n                    {\n                        fom_mask[fom_mask_len] = 0;\n                        fom_mask_len++;\n                    }\n\n                    if (pixel == (ypixel ^ mix))\n                    {\n                        fom_mask[fom_mask_len - 1] |= (1 << (fom_count % 8));\n                    }\n\n                    fom_count++;\n                }\n\n                out_uint8(temp_s, pixel);\n                count++;\n                last_pixel = pixel;\n                last_ypixel = ypixel;\n            }\n\n            /* can't take fix, mix, or fom past first line */\n            if (last_line == 0)\n            {\n                if (fill_count > 3 &&\n                        fill_count >= color_count &&\n                        fill_count >= bicolor_count &&\n                        fill_count >= mix_count &&\n                        fill_count >= fom_count)\n                {\n                    count -= fill_count;\n                    OUT_COPY_COUNT1(count, s, temp_s);\n                    OUT_FILL_COUNT1(fill_count, s);\n                    RESET_COUNTS;\n                }\n\n                fill_count = 0;\n\n                if (mix_count > 3 &&\n                        mix_count >= fill_count &&\n                        mix_count >= bicolor_count &&\n                        mix_count >= color_count &&\n                        mix_count >= fom_count)\n                {\n                    count -= mix_count;\n                    OUT_COPY_COUNT1(count, s, temp_s);\n                    OUT_MIX_COUNT1(mix_count, s);\n                    RESET_COUNTS;\n                }\n\n                mix_count = 0;\n\n                if (fom_count > 3 &&\n                        fom_count >= fill_count &&\n                        fom_count >= color_count &&\n                        fom_count >= mix_count &&\n                        fom_count >= bicolor_count)\n                {\n                    count -= fom_count;\n                    OUT_COPY_COUNT1(count, s, temp_s);\n                    OUT_FOM_COUNT1(fom_count, s, fom_mask, fom_mask_len);\n                    RESET_COUNTS;\n                }\n\n                fom_count = 0;\n                fom_mask_len = 0;\n            }\n\n            last_line = line;\n            line = line - width;\n            start_line--;\n            lines_sent++;\n        }\n\n        if (fill_count > 3 &&\n                fill_count >= color_count &&\n                fill_count >= bicolor_count &&\n                fill_count >= mix_count &&\n                fill_count >= fom_count)\n        {\n            count -= fill_count;\n            OUT_COPY_COUNT1(count, s, temp_s);\n            OUT_FILL_COUNT1(fill_count, s);\n        }\n        else if (mix_count > 3 &&\n                 mix_count >= color_count &&\n                 mix_count >= bicolor_count &&\n                 mix_count >= fill_count &&\n                 mix_count >= fom_count)\n        {\n            count -= mix_count;\n            OUT_COPY_COUNT1(count, s, temp_s);\n            OUT_MIX_COUNT1(mix_count, s);\n        }\n        else if (color_count > 3 &&\n                 color_count >= mix_count &&\n                 color_count >= bicolor_count &&\n                 color_count >= fill_count &&\n                 color_count >= fom_count)\n        {\n            count -= color_count;\n            OUT_COPY_COUNT1(count, s, temp_s);\n            OUT_COLOR_COUNT1(color_count, s, last_pixel);\n        }\n        else if (bicolor_count > 3 &&\n                 bicolor_count >= mix_count &&\n                 bicolor_count >= color_count &&\n                 bicolor_count >= fill_count &&\n                 bicolor_count >= fom_count)\n        {\n            if ((bicolor_count % 2) == 0)\n            {\n                count -= bicolor_count;\n                OUT_COPY_COUNT1(count, s, temp_s);\n                OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor1, bicolor2);\n            }\n            else\n            {\n                bicolor_count--;\n                count -= bicolor_count;\n                OUT_COPY_COUNT1(count, s, temp_s);\n                OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor2, bicolor1);\n            }\n\n            count -= bicolor_count;\n            OUT_COPY_COUNT1(count, s, temp_s);\n            OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor1, bicolor2);\n        }\n        else if (fom_count > 3 &&\n                 fom_count >= mix_count &&\n                 fom_count >= color_count &&\n                 fom_count >= fill_count &&\n                 fom_count >= bicolor_count)\n        {\n            count -= fom_count;\n            OUT_COPY_COUNT1(count, s, temp_s);\n            OUT_FOM_COUNT1(fom_count, s, fom_mask, fom_mask_len);\n        }\n        else\n        {\n            OUT_COPY_COUNT1(count, s, temp_s);\n        }\n    }\n    else if ((bpp == 15) || (bpp == 16))\n    {\n        mix = (bpp == 15) ? 0xba1f : 0xffff;\n        out_count = end * 2;\n        line = in_data + width * start_line * 2;\n\n        while (start_line >= 0 && out_count <= BC_MAX_BYTES)\n        {\n            i = (s->p - s->data) + count * 2;\n\n            if (i - (color_count * 2) >= byte_limit &&\n                    i - (bicolor_count * 2) >= byte_limit &&\n                    i - (fill_count * 2) >= byte_limit &&\n                    i - (mix_count * 2) >= byte_limit &&\n                    i - (fom_count * 2) >= byte_limit)\n            {\n                break;\n            }\n\n            out_count += end * 2;\n\n            for (i = 0; i < end; i++)\n            {\n                /* read next pixel */\n                IN_PIXEL16(line, i, 0, width, last_pixel, pixel);\n                IN_PIXEL16(last_line, i, 0, width, last_ypixel, ypixel);\n\n                if (!TEST_FILL)\n                {\n                    if (fill_count > 3 &&\n                            fill_count >= color_count &&\n                            fill_count >= bicolor_count &&\n                            fill_count >= mix_count &&\n                            fill_count >= fom_count)\n                    {\n                        count -= fill_count;\n                        OUT_COPY_COUNT2(count, s, temp_s);\n                        OUT_FILL_COUNT2(fill_count, s);\n                        RESET_COUNTS;\n                    }\n\n                    fill_count = 0;\n                }\n\n                if (!TEST_MIX)\n                {\n                    if (mix_count > 3 &&\n                            mix_count >= fill_count &&\n                            mix_count >= bicolor_count &&\n                            mix_count >= color_count &&\n                            mix_count >= fom_count)\n                    {\n                        count -= mix_count;\n                        OUT_COPY_COUNT2(count, s, temp_s);\n                        OUT_MIX_COUNT2(mix_count, s);\n                        RESET_COUNTS;\n                    }\n\n                    mix_count = 0;\n                }\n\n                if (!TEST_COLOR)\n                {\n                    if (color_count > 3 &&\n                            color_count >= fill_count &&\n                            color_count >= bicolor_count &&\n                            color_count >= mix_count &&\n                            color_count >= fom_count)\n                    {\n                        count -= color_count;\n                        OUT_COPY_COUNT2(count, s, temp_s);\n                        OUT_COLOR_COUNT2(color_count, s, last_pixel);\n                        RESET_COUNTS;\n                    }\n\n                    color_count = 0;\n                }\n\n                if (!TEST_BICOLOR)\n                {\n                    if (bicolor_count > 3 &&\n                            bicolor_count >= fill_count &&\n                            bicolor_count >= color_count &&\n                            bicolor_count >= mix_count &&\n                            bicolor_count >= fom_count)\n                    {\n                        if ((bicolor_count % 2) == 0)\n                        {\n                            count -= bicolor_count;\n                            OUT_COPY_COUNT2(count, s, temp_s);\n                            OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor1, bicolor2);\n                        }\n                        else\n                        {\n                            bicolor_count--;\n                            count -= bicolor_count;\n                            OUT_COPY_COUNT2(count, s, temp_s);\n                            OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor2, bicolor1);\n                        }\n\n                        RESET_COUNTS;\n                    }\n\n                    bicolor_count = 0;\n                    bicolor1 = last_pixel;\n                    bicolor2 = pixel;\n                    bicolor_spin = 0;\n                }\n\n                if (!TEST_FOM)\n                {\n                    if (fom_count > 3 &&\n                            fom_count >= fill_count &&\n                            fom_count >= color_count &&\n                            fom_count >= mix_count &&\n                            fom_count >= bicolor_count)\n                    {\n                        count -= fom_count;\n                        OUT_COPY_COUNT2(count, s, temp_s);\n                        OUT_FOM_COUNT2(fom_count, s, fom_mask, fom_mask_len);\n                        RESET_COUNTS;\n                    }\n\n                    fom_count = 0;\n                    fom_mask_len = 0;\n                }\n\n                if (TEST_FILL)\n                {\n                    fill_count++;\n                }\n\n                if (TEST_MIX)\n                {\n                    mix_count++;\n                }\n\n                if (TEST_COLOR)\n                {\n                    color_count++;\n                }\n\n                if (TEST_BICOLOR)\n                {\n                    bicolor_spin = !bicolor_spin;\n                    bicolor_count++;\n                }\n\n                if (TEST_FOM)\n                {\n                    if ((fom_count % 8) == 0)\n                    {\n                        fom_mask[fom_mask_len] = 0;\n                        fom_mask_len++;\n                    }\n\n                    if (pixel == (ypixel ^ mix))\n                    {\n                        fom_mask[fom_mask_len - 1] |= (1 << (fom_count % 8));\n                    }\n\n                    fom_count++;\n                }\n\n                out_uint16_le(temp_s, pixel);\n                count++;\n                last_pixel = pixel;\n                last_ypixel = ypixel;\n            }\n\n            /* can't take fix, mix, or fom past first line */\n            if (last_line == 0)\n            {\n                if (fill_count > 3 &&\n                        fill_count >= color_count &&\n                        fill_count >= bicolor_count &&\n                        fill_count >= mix_count &&\n                        fill_count >= fom_count)\n                {\n                    count -= fill_count;\n                    OUT_COPY_COUNT2(count, s, temp_s);\n                    OUT_FILL_COUNT2(fill_count, s);\n                    RESET_COUNTS;\n                }\n\n                fill_count = 0;\n\n                if (mix_count > 3 &&\n                        mix_count >= fill_count &&\n                        mix_count >= bicolor_count &&\n                        mix_count >= color_count &&\n                        mix_count >= fom_count)\n                {\n                    count -= mix_count;\n                    OUT_COPY_COUNT2(count, s, temp_s);\n                    OUT_MIX_COUNT2(mix_count, s);\n                    RESET_COUNTS;\n                }\n\n                mix_count = 0;\n\n                if (fom_count > 3 &&\n                        fom_count >= fill_count &&\n                        fom_count >= color_count &&\n                        fom_count >= mix_count &&\n                        fom_count >= bicolor_count)\n                {\n                    count -= fom_count;\n                    OUT_COPY_COUNT2(count, s, temp_s);\n                    OUT_FOM_COUNT2(fom_count, s, fom_mask, fom_mask_len);\n                    RESET_COUNTS;\n                }\n\n                fom_count = 0;\n                fom_mask_len = 0;\n            }\n\n            last_line = line;\n            line = line - width * 2;\n            start_line--;\n            lines_sent++;\n        }\n\n        if (fill_count > 3 &&\n                fill_count >= color_count &&\n                fill_count >= bicolor_count &&\n                fill_count >= mix_count &&\n                fill_count >= fom_count)\n        {\n            count -= fill_count;\n            OUT_COPY_COUNT2(count, s, temp_s);\n            OUT_FILL_COUNT2(fill_count, s);\n        }\n        else if (mix_count > 3 &&\n                 mix_count >= color_count &&\n                 mix_count >= bicolor_count &&\n                 mix_count >= fill_count &&\n                 mix_count >= fom_count)\n        {\n            count -= mix_count;\n            OUT_COPY_COUNT2(count, s, temp_s);\n            OUT_MIX_COUNT2(mix_count, s);\n        }\n        else if (color_count > 3 &&\n                 color_count >= mix_count &&\n                 color_count >= bicolor_count &&\n                 color_count >= fill_count &&\n                 color_count >= fom_count)\n        {\n            count -= color_count;\n            OUT_COPY_COUNT2(count, s, temp_s);\n            OUT_COLOR_COUNT2(color_count, s, last_pixel);\n        }\n        else if (bicolor_count > 3 &&\n                 bicolor_count >= mix_count &&\n                 bicolor_count >= color_count &&\n                 bicolor_count >= fill_count &&\n                 bicolor_count >= fom_count)\n        {\n            if ((bicolor_count % 2) == 0)\n            {\n                count -= bicolor_count;\n                OUT_COPY_COUNT2(count, s, temp_s);\n                OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor1, bicolor2);\n            }\n            else\n            {\n                bicolor_count--;\n                count -= bicolor_count;\n                OUT_COPY_COUNT2(count, s, temp_s);\n                OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor2, bicolor1);\n            }\n\n            count -= bicolor_count;\n            OUT_COPY_COUNT2(count, s, temp_s);\n            OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor1, bicolor2);\n        }\n        else if (fom_count > 3 &&\n                 fom_count >= mix_count &&\n                 fom_count >= color_count &&\n                 fom_count >= fill_count &&\n                 fom_count >= bicolor_count)\n        {\n            count -= fom_count;\n            OUT_COPY_COUNT2(count, s, temp_s);\n            OUT_FOM_COUNT2(fom_count, s, fom_mask, fom_mask_len);\n        }\n        else\n        {\n            OUT_COPY_COUNT2(count, s, temp_s);\n        }\n    }\n    else if (bpp == 24)\n    {\n        mix = 0xffffff;\n        out_count = end * 3;\n        line = in_data + width * start_line * 4;\n\n        while (start_line >= 0 && out_count <= BC_MAX_BYTES)\n        {\n            i = (s->p - s->data) + count * 3;\n\n            if (i - (color_count * 3) >= byte_limit &&\n                    i - (bicolor_count * 3) >= byte_limit &&\n                    i - (fill_count * 3) >= byte_limit &&\n                    i - (mix_count * 3) >= byte_limit &&\n                    i - (fom_count * 3) >= byte_limit)\n            {\n                break;\n            }\n\n            out_count += end * 3;\n\n            for (i = 0; i < end; i++)\n            {\n                /* read next pixel */\n                IN_PIXEL32(line, i, 0, width, last_pixel, pixel);\n                IN_PIXEL32(last_line, i, 0, width, last_ypixel, ypixel);\n\n                if (!TEST_FILL)\n                {\n                    if (fill_count > 3 &&\n                            fill_count >= color_count &&\n                            fill_count >= bicolor_count &&\n                            fill_count >= mix_count &&\n                            fill_count >= fom_count)\n                    {\n                        count -= fill_count;\n                        OUT_COPY_COUNT3(count, s, temp_s);\n                        OUT_FILL_COUNT3(fill_count, s);\n                        RESET_COUNTS;\n                    }\n\n                    fill_count = 0;\n                }\n\n                if (!TEST_MIX)\n                {\n                    if (mix_count > 3 &&\n                            mix_count >= fill_count &&\n                            mix_count >= bicolor_count &&\n                            mix_count >= color_count &&\n                            mix_count >= fom_count)\n                    {\n                        count -= mix_count;\n                        OUT_COPY_COUNT3(count, s, temp_s);\n                        OUT_MIX_COUNT3(mix_count, s);\n                        RESET_COUNTS;\n                    }\n\n                    mix_count = 0;\n                }\n\n                if (!TEST_COLOR)\n                {\n                    if (color_count > 3 &&\n                            color_count >= fill_count &&\n                            color_count >= bicolor_count &&\n                            color_count >= mix_count &&\n                            color_count >= fom_count)\n                    {\n                        count -= color_count;\n                        OUT_COPY_COUNT3(count, s, temp_s);\n                        OUT_COLOR_COUNT3(color_count, s, last_pixel);\n                        RESET_COUNTS;\n                    }\n\n                    color_count = 0;\n                }\n\n                if (!TEST_BICOLOR)\n                {\n                    if (bicolor_count > 3 &&\n                            bicolor_count >= fill_count &&\n                            bicolor_count >= color_count &&\n                            bicolor_count >= mix_count &&\n                            bicolor_count >= fom_count)\n                    {\n                        if ((bicolor_count % 2) == 0)\n                        {\n                            count -= bicolor_count;\n                            OUT_COPY_COUNT3(count, s, temp_s);\n                            OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor1, bicolor2);\n                        }\n                        else\n                        {\n                            bicolor_count--;\n                            count -= bicolor_count;\n                            OUT_COPY_COUNT3(count, s, temp_s);\n                            OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor2, bicolor1);\n                        }\n\n                        RESET_COUNTS;\n                    }\n\n                    bicolor_count = 0;\n                    bicolor1 = last_pixel;\n                    bicolor2 = pixel;\n                    bicolor_spin = 0;\n                }\n\n                if (!TEST_FOM)\n                {\n                    if (fom_count > 3 &&\n                            fom_count >= fill_count &&\n                            fom_count >= color_count &&\n                            fom_count >= mix_count &&\n                            fom_count >= bicolor_count)\n                    {\n                        count -= fom_count;\n                        OUT_COPY_COUNT3(count, s, temp_s);\n                        OUT_FOM_COUNT3(fom_count, s, fom_mask, fom_mask_len);\n                        RESET_COUNTS;\n                    }\n\n                    fom_count = 0;\n                    fom_mask_len = 0;\n                }\n\n                if (TEST_FILL)\n                {\n                    fill_count++;\n                }\n\n                if (TEST_MIX)\n                {\n                    mix_count++;\n                }\n\n                if (TEST_COLOR)\n                {\n                    color_count++;\n                }\n\n                if (TEST_BICOLOR)\n                {\n                    bicolor_spin = !bicolor_spin;\n                    bicolor_count++;\n                }\n\n                if (TEST_FOM)\n                {\n                    if ((fom_count % 8) == 0)\n                    {\n                        fom_mask[fom_mask_len] = 0;\n                        fom_mask_len++;\n                    }\n\n                    if (pixel == (ypixel ^ mix))\n                    {\n                        fom_mask[fom_mask_len - 1] |= (1 << (fom_count % 8));\n                    }\n\n                    fom_count++;\n                }\n\n                out_uint8(temp_s, pixel & 0xff);\n                out_uint8(temp_s, (pixel >> 8) & 0xff);\n                out_uint8(temp_s, (pixel >> 16) & 0xff);\n                count++;\n                last_pixel = pixel;\n                last_ypixel = ypixel;\n            }\n\n            /* can't take fix, mix, or fom past first line */\n            if (last_line == 0)\n            {\n                if (fill_count > 3 &&\n                        fill_count >= color_count &&\n                        fill_count >= bicolor_count &&\n                        fill_count >= mix_count &&\n                        fill_count >= fom_count)\n                {\n                    count -= fill_count;\n                    OUT_COPY_COUNT3(count, s, temp_s);\n                    OUT_FILL_COUNT3(fill_count, s);\n                    RESET_COUNTS;\n                }\n\n                fill_count = 0;\n\n                if (mix_count > 3 &&\n                        mix_count >= fill_count &&\n                        mix_count >= bicolor_count &&\n                        mix_count >= color_count &&\n                        mix_count >= fom_count)\n                {\n                    count -= mix_count;\n                    OUT_COPY_COUNT3(count, s, temp_s);\n                    OUT_MIX_COUNT3(mix_count, s);\n                    RESET_COUNTS;\n                }\n\n                mix_count = 0;\n\n                if (fom_count > 3 &&\n                        fom_count >= fill_count &&\n                        fom_count >= color_count &&\n                        fom_count >= mix_count &&\n                        fom_count >= bicolor_count)\n                {\n                    count -= fom_count;\n                    OUT_COPY_COUNT3(count, s, temp_s);\n                    OUT_FOM_COUNT3(fom_count, s, fom_mask, fom_mask_len);\n                    RESET_COUNTS;\n                }\n\n                fom_count = 0;\n                fom_mask_len = 0;\n            }\n\n            last_line = line;\n            line = line - width * 4;\n            start_line--;\n            lines_sent++;\n        }\n\n        if (fill_count > 3 &&\n                fill_count >= color_count &&\n                fill_count >= bicolor_count &&\n                fill_count >= mix_count &&\n                fill_count >= fom_count)\n        {\n            count -= fill_count;\n            OUT_COPY_COUNT3(count, s, temp_s);\n            OUT_FILL_COUNT3(fill_count, s);\n        }\n        else if (mix_count > 3 &&\n                 mix_count >= color_count &&\n                 mix_count >= bicolor_count &&\n                 mix_count >= fill_count &&\n                 mix_count >= fom_count)\n        {\n            count -= mix_count;\n            OUT_COPY_COUNT3(count, s, temp_s);\n            OUT_MIX_COUNT3(mix_count, s);\n        }\n        else if (color_count > 3 &&\n                 color_count >= mix_count &&\n                 color_count >= bicolor_count &&\n                 color_count >= fill_count &&\n                 color_count >= fom_count)\n        {\n            count -= color_count;\n            OUT_COPY_COUNT3(count, s, temp_s);\n            OUT_COLOR_COUNT3(color_count, s, last_pixel);\n        }\n        else if (bicolor_count > 3 &&\n                 bicolor_count >= mix_count &&\n                 bicolor_count >= color_count &&\n                 bicolor_count >= fill_count &&\n                 bicolor_count >= fom_count)\n        {\n            if ((bicolor_count % 2) == 0)\n            {\n                count -= bicolor_count;\n                OUT_COPY_COUNT3(count, s, temp_s);\n                OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor1, bicolor2);\n            }\n            else\n            {\n                bicolor_count--;\n                count -= bicolor_count;\n                OUT_COPY_COUNT3(count, s, temp_s);\n                OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor2, bicolor1);\n            }\n\n            count -= bicolor_count;\n            OUT_COPY_COUNT3(count, s, temp_s);\n            OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor1, bicolor2);\n        }\n        else if (fom_count > 3 &&\n                 fom_count >= mix_count &&\n                 fom_count >= color_count &&\n                 fom_count >= fill_count &&\n                 fom_count >= bicolor_count)\n        {\n            count -= fom_count;\n            OUT_COPY_COUNT3(count, s, temp_s);\n            OUT_FOM_COUNT3(fom_count, s, fom_mask, fom_mask_len);\n        }\n        else\n        {\n            OUT_COPY_COUNT3(count, s, temp_s);\n        }\n    }\n\n    return lines_sent;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_caps.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n * Copyright (C) Idan Freiberg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * RDP Capability Sets\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <limits.h>\n\n#include \"guid.h\"\n#include \"libxrdp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"ms-rdperp.h\"\n\n/**\n * The largest supported size for a fastpath update\n * (TS_MULTIFRAGMENTUPDATE_CAPABILITYSET) we advertise to the client. This\n * size is big enough for the tiles required for two 3840x2160 monitors\n * without using multiple update PDUS.\n *\n * Consult calculate_multifragmentupdate_len() below before changing this\n * value.\n */\n#define MAX_MULTIFRAGMENTUPDATE_SIZE (2U * (3840 * 2160) * 16384 + 16384)\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_send_monitorlayout(struct xrdp_rdp *self)\n{\n    struct stream *s;\n    uint32_t i;\n    struct display_size_description *description;\n    int rv = 0;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_rdp_init_data(self, s) != 0)\n    {\n        free_stream(s);\n        return 1;\n    }\n\n    description = &self->client_info.display_sizes;\n\n    out_uint32_le(s, description->monitorCount); /* monitorCount (4 bytes) */\n\n    /* TODO: validate for allowed monitors in terminal server (maybe by config?) */\n    for (i = 0; i < description->monitorCount; i++)\n    {\n        out_uint32_le(s, description->minfo[i].left);\n        out_uint32_le(s, description->minfo[i].top);\n        out_uint32_le(s, description->minfo[i].right);\n        out_uint32_le(s, description->minfo[i].bottom);\n        out_uint32_le(s, description->minfo[i].is_primary);\n    }\n\n    s_mark_end(s);\n\n    // [MS-RDPBCGR]\n    // - 2.2.12.1 - ...the pduSource field MUST be set to zero.\n    // - 3.3.5.12.1 - The contents of this PDU SHOULD NOT be compressed\n    rv = xrdp_rdp_send_data_from_channel(self, s,\n                                         PDUTYPE2_MONITOR_LAYOUT_PDU, 0, 0);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_general(struct xrdp_rdp *self, struct stream *s,\n                          int len)\n{\n    int extraFlags;\n    int client_does_fastpath_output;\n\n    if (len < 10 + 2)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Not enough bytes in the stream: \"\n            \"len 12, remaining %d\", len);\n        return 1;\n    }\n\n    in_uint16_le(s, self->client_info.client_os_major); /* osMajorType (2 bytes) */\n    in_uint16_le(s, self->client_info.client_os_minor); /* osMinorType (2 bytes) */\n    in_uint8s(s, 6);\n    in_uint16_le(s, extraFlags); /* extraFlags (2 bytes) */\n\n    self->client_info.op1 = extraFlags & NO_BITMAP_COMPRESSION_HDR;\n    /* use_compact_packets is pretty much 'use rdp5' */\n    self->client_info.use_compact_packets = (extraFlags != 0);\n    /* op2 is a boolean to use compact bitmap headers in bitmap cache */\n    /* set it to same as 'use rdp5' boolean */\n    self->client_info.op2 = self->client_info.use_compact_packets;\n    /* FASTPATH_OUTPUT_SUPPORTED 0x0001 */\n    client_does_fastpath_output = extraFlags & FASTPATH_OUTPUT_SUPPORTED;\n    if ((self->client_info.use_fast_path & 1) && !client_does_fastpath_output)\n    {\n        /* server supports fast path output and client does not, turn it off */\n        self->client_info.use_fast_path &= ~1;\n    }\n    return 0;\n}\n\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_bitmap(struct xrdp_rdp *self, struct stream *s,\n                         int len)\n{\n    /* [MS-RDPBCGR] 2.2.7.1.2 */\n    int desktopResizeFlag;\n    if (len < 14 + 2)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Not enough bytes in the stream: \"\n            \"len 16, remaining %d\", len);\n        return 1;\n    }\n\n    in_uint8s(s, 14);\n    in_uint16_le(s, desktopResizeFlag);\n\n    /* Work out what kind of client resizing we can do from the server */\n    int early_cap_flags = self->client_info.mcs_early_capability_flags;\n    if (desktopResizeFlag == 0)\n    {\n        self->client_info.client_resize_mode = CRMODE_NONE;\n        LOG(LOG_LEVEL_INFO, \"Client cannot be resized by xrdp\");\n    }\n    else if ((early_cap_flags & RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU) == 0)\n    {\n        self->client_info.client_resize_mode = CRMODE_SINGLE_SCREEN;\n        LOG(LOG_LEVEL_INFO, \"Client supports single-screen resizes by xrdp\");\n    }\n    else\n    {\n        self->client_info.client_resize_mode = CRMODE_MULTI_SCREEN;\n        LOG(LOG_LEVEL_INFO, \"Client supports multi-screen resizes by xrdp\");\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Process [MS-RDPBCGR] TS_ORDER_CAPABILITYSET (2.2.7.1.3) message.\n */\nstatic int\nxrdp_caps_process_order(struct xrdp_rdp *self, struct stream *s,\n                        int len)\n{\n    int i;\n    char order_caps[XR_PRIMARY_ORDER_COUNT];\n    int ex_flags;\n    int cap_flags;\n\n    if (len < 20 + 2 + 2 + 2 + 2 + 2 + 2 + 32 + 2 + 2 + 4 + 4 + 4 + 4)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Not enough bytes in the stream: \"\n            \"len 84, remaining %d\", len);\n        return 1;\n    }\n    in_uint8s(s, 20); /* Terminal desc, pad */\n    in_uint8s(s, 2); /* Cache X granularity */\n    in_uint8s(s, 2); /* Cache Y granularity */\n    in_uint8s(s, 2); /* Pad */\n    in_uint8s(s, 2); /* Max order level */\n    in_uint8s(s, 2); /* Number of fonts */\n    in_uint16_le(s, cap_flags); /* Capability flags */\n    in_uint8a(s, order_caps, XR_PRIMARY_ORDER_COUNT); /* Orders supported */\n    g_memcpy(self->client_info.orders, order_caps, XR_PRIMARY_ORDER_COUNT);\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: terminalDescriptor (ignored as per protocol spec)\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: desktopSaveXGranularity (ignored as per protocol spec)\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: desktopSaveYGranularity (ignored as per protocol spec)\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: maximumOrderLevel (ignored as per protocol spec)\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: numberFonts (ignored as per protocol spec)\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderFlags 0x%4.4x\", cap_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 0: DstBlt %d\", order_caps[0]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 1: PatBlt %d\", order_caps[1]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 2: ScrBlt %d\", order_caps[2]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 3,13: MemBlt %d %d\", order_caps[3], order_caps[13]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 4,14: Mem3Blt %d %d\", order_caps[4], order_caps[14]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 5-6: unused index\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 7: DrawNineGrid %d\", order_caps[7]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 8: LineTo %d\", order_caps[8]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 9: MultiDrawNineGrid %d\", order_caps[9]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 10: unused index\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 11: SaveBitmap %d\", order_caps[11]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 12-14: unused index\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 15: MultiDstBlt %d\", order_caps[15]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 16: MultiPatBlt %d\", order_caps[16]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 17: MultiScrBlt %d\", order_caps[17]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 18: MultiOpaqueRect %d\", order_caps[18]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 19: FastIndex %d\", order_caps[19]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 20: PolygonSC %d\", order_caps[20]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 21: PolygonCB %d\", order_caps[21]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 22: Polyline %d\", order_caps[22]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 23: unused index\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 24: FastGlyph %d\", order_caps[24]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 25: EllipseSC %d\", order_caps[25]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 26: EllipseCB %d\", order_caps[26]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 27: GlyphIndex %d\", order_caps[27]);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupport index 28-31: unused index\");\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: order_caps\", order_caps, XR_PRIMARY_ORDER_COUNT);\n\n    in_uint8s(s, 2); /* Text capability flags */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: textFlags (ignored as per protocol spec)\");\n    /* read extended order support flags */\n    in_uint16_le(s, ex_flags); /* Ex flags */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: orderSupportExFlags 0x%4.4x\", ex_flags);\n\n    if (cap_flags & ORDERFLAGS_EXTRA_FLAGS)\n    {\n        self->client_info.order_flags_ex = ex_flags;\n        if (ex_flags & XR_ORDERFLAGS_EX_CACHE_BITMAP_REV3_SUPPORT)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"Client Capability: bitmap cache v3 supported\");\n            self->client_info.bitmap_cache_version |= 4;\n        }\n    }\n    in_uint8s(s, 4); /* Pad */\n\n    in_uint32_le(s, i); /* desktop cache size, usually 0x38400 */\n    self->client_info.desktop_cache = i;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"TS_ORDER_CAPABILITYSET: desktopSaveSize %d\", i);\n    in_uint8s(s, 4); /* Pad */\n    in_uint8s(s, 4); /* Pad */\n\n    /* check if libpainter should be used for drawing, instead of orders */\n    if (!(order_caps[TS_NEG_DSTBLT_INDEX] && order_caps[TS_NEG_PATBLT_INDEX] &&\n            order_caps[TS_NEG_SCRBLT_INDEX] && order_caps[TS_NEG_MEMBLT_INDEX]))\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO, \"Client Capability: not enough orders supported by client, using painter.\");\n        self->client_info.no_orders_supported = 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* get the bitmap cache size */\nstatic int\nxrdp_caps_process_bmpcache(struct xrdp_rdp *self, struct stream *s,\n                           int len)\n{\n    int i;\n\n    if (len < 24 + 2 + 2 + 2 + 2 + 2 + 2)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Not enough bytes in the stream: \"\n            \"len 36, remaining %d\", len);\n        return 1;\n    }\n    self->client_info.bitmap_cache_version |= 1;\n    in_uint8s(s, 24);\n    /* cache 1 */\n    in_uint16_le(s, i);\n    i = MIN(i, XRDP_MAX_BITMAP_CACHE_IDX);\n    i = MAX(i, 0);\n    self->client_info.cache1_entries = i;\n    in_uint16_le(s, self->client_info.cache1_size);\n    /* cache 2 */\n    in_uint16_le(s, i);\n    i = MIN(i, XRDP_MAX_BITMAP_CACHE_IDX);\n    i = MAX(i, 0);\n    self->client_info.cache2_entries = i;\n    in_uint16_le(s, self->client_info.cache2_size);\n    /* cache 3 */\n    in_uint16_le(s, i);\n    i = MIN(i, XRDP_MAX_BITMAP_CACHE_IDX);\n    i = MAX(i, 0);\n    self->client_info.cache3_entries = i;\n    in_uint16_le(s, self->client_info.cache3_size);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"cache1 entries %d size %d\", self->client_info.cache1_entries,\n              self->client_info.cache1_size);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"cache2 entries %d size %d\", self->client_info.cache2_entries,\n              self->client_info.cache2_size);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"cache3 entries %d size %d\", self->client_info.cache3_entries,\n              self->client_info.cache3_size);\n    return 0;\n}\n\n/*****************************************************************************/\n/* get the bitmap cache size */\nstatic int\nxrdp_caps_process_bmpcache2(struct xrdp_rdp *self, struct stream *s,\n                            int len)\n{\n    int Bpp = 0;\n    int i = 0;\n\n    if (len < 2 + 2 + 4 + 4 + 4)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Not enough bytes in the stream: \"\n            \"len 16, remaining %d\", len);\n        return 1;\n    }\n    self->client_info.bitmap_cache_version |= 2;\n    Bpp = (self->client_info.bpp + 7) / 8;\n    in_uint16_le(s, i); /* cache flags */\n    self->client_info.bitmap_cache_persist_enable = i;\n    in_uint8s(s, 2); /* number of caches in set, 3 */\n    in_uint32_le(s, i);\n    i = MIN(i, XRDP_MAX_BITMAP_CACHE_IDX);\n    i = MAX(i, 0);\n    self->client_info.cache1_entries = i;\n    self->client_info.cache1_size = 256 * Bpp;\n    in_uint32_le(s, i);\n    i = MIN(i, XRDP_MAX_BITMAP_CACHE_IDX);\n    i = MAX(i, 0);\n    self->client_info.cache2_entries = i;\n    self->client_info.cache2_size = 1024 * Bpp;\n    in_uint32_le(s, i);\n    i = i & 0x7fffffff;\n    i = MIN(i, XRDP_MAX_BITMAP_CACHE_IDX);\n    i = MAX(i, 0);\n    self->client_info.cache3_entries = i;\n    self->client_info.cache3_size = 4096 * Bpp;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"cache1 entries %d size %d\", self->client_info.cache1_entries,\n              self->client_info.cache1_size);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"cache2 entries %d size %d\", self->client_info.cache2_entries,\n              self->client_info.cache2_size);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"cache3 entries %d size %d\", self->client_info.cache3_entries,\n              self->client_info.cache3_size);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_cache_v3_codec_id(struct xrdp_rdp *self, struct stream *s,\n                                    int len)\n{\n    int codec_id;\n\n    if (len < 1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Not enough bytes in the stream: \"\n            \"len 1, remaining %d\", len);\n        return 1;\n    }\n    in_uint8(s, codec_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_process_cache_v3_codec_id: cache_v3_codec_id %d\",\n              codec_id);\n    self->client_info.v3_codec_id = codec_id;\n    return 0;\n}\n\n/*****************************************************************************/\n/* get the number of client cursor cache */\nstatic int\nxrdp_caps_process_pointer(struct xrdp_rdp *self, struct stream *s,\n                          int len)\n{\n    int i;\n    int colorPointerFlag;\n    int no_new_cursor;\n\n    if (len < 2 + 2 + 2)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_caps_process_pointer: error\");\n        return 1;\n    }\n    no_new_cursor = self->client_info.pointer_flags & 2;\n    in_uint16_le(s, colorPointerFlag);\n    self->client_info.pointer_flags = colorPointerFlag;\n    in_uint16_le(s, i);\n    i = MIN(i, 32);\n    self->client_info.pointer_cache_entries = i;\n    if (colorPointerFlag & 1)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_caps_process_pointer: client supports \"\n            \"new(color) cursor\");\n        in_uint16_le(s, i);\n        i = MIN(i, 32);\n        self->client_info.pointer_cache_entries = i;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_caps_process_pointer: client does not support \"\n            \"new(color) cursor\");\n    }\n    if (no_new_cursor)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_caps_process_pointer: new(color) cursor is \"\n            \"disabled by config\");\n        self->client_info.pointer_flags = 0;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_input(struct xrdp_rdp *self, struct stream *s,\n                        int len)\n{\n    int inputFlags;\n    int client_does_fastpath_input;\n\n    in_uint16_le(s, inputFlags);\n    client_does_fastpath_input = (inputFlags & INPUT_FLAG_FASTPATH_INPUT) ||\n                                 (inputFlags & INPUT_FLAG_FASTPATH_INPUT2);\n    if ((self->client_info.use_fast_path & 2) && !client_does_fastpath_input)\n    {\n        self->client_info.use_fast_path &= ~2;\n    }\n\n    // We always advertise Unicode support, so if the client supports it too,\n    // we can use it.\n    //\n    // If Unicode support is already active, the CAPSTYPE_INPUT\n    // PDU has been received as part of a Deactivation-Reactivation sequence.\n    // In this case, ignore the flag.\n    if (self->client_info.unicode_input_support != UIS_ACTIVE)\n    {\n        if ((inputFlags & INPUT_FLAG_UNICODE) != 0)\n        {\n            self->client_info.unicode_input_support = UIS_SUPPORTED;\n            LOG(LOG_LEVEL_INFO, \"Client supports Unicode input\");\n        }\n        else\n        {\n            self->client_info.unicode_input_support = UIS_UNSUPPORTED;\n            LOG(LOG_LEVEL_INFO, \"Client does not support Unicode input\");\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* get the type of client brush cache */\nstatic int\nxrdp_caps_process_brushcache(struct xrdp_rdp *self, struct stream *s,\n                             int len)\n{\n    int code;\n\n    if (len < 4)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_caps_process_brushcache: error\");\n        return 1;\n    }\n    in_uint32_le(s, code);\n    self->client_info.brush_cache_code = code;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_glyphcache(struct xrdp_rdp *self, struct stream *s,\n                             int len)\n{\n    int glyph_support_level;\n\n    if (len < 40 + 4 + 2 + 2) /* MS-RDPBCGR 2.2.7.1.8 */\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_caps_process_glyphcache: error\");\n        return 1;\n    }\n\n    in_uint8s(s, 40);  /* glyph cache */\n    in_uint8s(s, 4);   /* frag cache */\n    in_uint16_le(s, glyph_support_level);\n    in_uint8s(s, 2);   /* pad */\n\n    if (glyph_support_level == GLYPH_SUPPORT_ENCODE)\n    {\n        self->client_info.use_cache_glyph_v2 = 1;\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_process_glyphcache: support level %d \",\n              glyph_support_level);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_offscreen_bmpcache(struct xrdp_rdp *self, struct stream *s,\n                                     int len)\n{\n    int i32;\n\n    if (len < 4 + 2 + 2)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_caps_process_offscreen_bmpcache: error\");\n        return 1;\n    }\n    in_uint32_le(s, i32);\n    self->client_info.offscreen_support_level = i32;\n    in_uint16_le(s, i32);\n    self->client_info.offscreen_cache_size = i32 * 1024;\n    in_uint16_le(s, i32);\n    self->client_info.offscreen_cache_entries = i32;\n    LOG(LOG_LEVEL_INFO, \"xrdp_process_offscreen_bmpcache: support level %d \"\n        \"cache size %d bytes cache entries %d\",\n        self->client_info.offscreen_support_level,\n        self->client_info.offscreen_cache_size,\n        self->client_info.offscreen_cache_entries);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_rail(struct xrdp_rdp *self, struct stream *s, int len)\n{\n    int i32;\n\n    if (len < 4)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Not enough bytes in the stream: \"\n            \"len 4, remaining %d\", len);\n        return 1;\n    }\n    in_uint32_le(s, i32);\n    self->client_info.rail_support_level = i32;\n    LOG(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - CAPSTYPE_RAIL \"\n        \"RailSupportLevel 0x%8.8x (%s%s%s%s%s%s%s%s)\",\n        self->client_info.rail_support_level,\n        (self->client_info.rail_support_level & 0x01) ? \"TS_RAIL_LEVEL_SUPPORTED \" : \"\",\n        (self->client_info.rail_support_level & 0x02) ? \"TS_RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED \" : \"\",\n        (self->client_info.rail_support_level & 0x04) ? \"TS_RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED \" : \"\",\n        (self->client_info.rail_support_level & 0x08) ? \"TS_RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED \" : \"\",\n        (self->client_info.rail_support_level & 0x10) ? \"TS_RAIL_LEVEL_SERVER_TO_CLIENT_IME_SYNC_SUPPORTED \" : \"\",\n        (self->client_info.rail_support_level & 0x20) ? \"TS_RAIL_LEVEL_HIDE_MINIMIZED_APPS_SUPPORTED \" : \"\",\n        (self->client_info.rail_support_level & 0x40) ? \"TS_RAIL_LEVEL_WINDOW_CLOAKING_SUPPORTED \" : \"\",\n        (self->client_info.rail_support_level & 0x80) ? \"TS_RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED \" : \"\"\n       );\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_window(struct xrdp_rdp *self, struct stream *s, int len)\n{\n    int i32;\n\n    if (len < 4 + 1 + 2)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_caps_process_window: error\");\n        return 1;\n    }\n    in_uint32_le(s, i32);\n    self->client_info.wnd_support_level = i32;\n    in_uint8(s, i32);\n    self->client_info.wnd_num_icon_caches = i32;\n    in_uint16_le(s, i32);\n    self->client_info.wnd_num_icon_cache_entries = i32;\n    LOG(LOG_LEVEL_INFO, \"xrdp_process_capset_window wnd_support_level %d, \"\n        \"wnd_num_icon_caches %d, wnd_num_icon_cache_entries %d\",\n        self->client_info.wnd_support_level,\n        self->client_info.wnd_num_icon_caches,\n        self->client_info.wnd_num_icon_cache_entries);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_codecs(struct xrdp_rdp *self, struct stream *s, int len)\n{\n    int codec_id;\n    int codec_count;\n    int index;\n    int codec_properties_length;\n    int i1;\n    char *codec_guid;\n    char *next_guid;\n    struct guid guid;\n    char codec_guid_str[GUID_STR_SIZE];\n\n    guid_clear(&guid);\n\n    if (len < 1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_caps_process_codecs: error\");\n        return 1;\n    }\n    in_uint8(s, codec_count);\n    len--;\n\n    for (index = 0; index < codec_count; index++)\n    {\n        codec_guid = s->p;\n\n        g_memcpy(guid.g, s->p, GUID_SIZE);\n        guid_to_str(&guid, codec_guid_str);\n\n        if (len < 16 + 1 + 2)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_caps_process_codecs: error\");\n            return 1;\n        }\n        in_uint8s(s, 16);\n        in_uint8(s, codec_id);\n        in_uint16_le(s, codec_properties_length);\n        len -= 16 + 1 + 2;\n        if (len < codec_properties_length)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_caps_process_codecs: error\");\n            return 1;\n        }\n        len -= codec_properties_length;\n        next_guid = s->p + codec_properties_length;\n\n        if (g_memcmp(codec_guid, XR_CODEC_GUID_NSCODEC, 16) == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_caps_process_codecs: NSCodec(%s), codec id [%d], properties len [%d]\",\n                codec_guid_str, codec_id, codec_properties_length);\n            self->client_info.ns_codec_id = codec_id;\n            i1 = MIN(64, codec_properties_length);\n            g_memcpy(self->client_info.ns_prop, s->p, i1);\n            self->client_info.ns_prop_len = i1;\n        }\n        else if (g_memcmp(codec_guid, XR_CODEC_GUID_REMOTEFX, 16) == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_caps_process_codecs: RemoteFX(%s), codec id [%d], properties len [%d]\",\n                codec_guid_str, codec_id, codec_properties_length);\n            self->client_info.rfx_codec_id = codec_id;\n            i1 = MIN(64, codec_properties_length);\n            g_memcpy(self->client_info.rfx_prop, s->p, i1);\n            self->client_info.rfx_prop_len = i1;\n        }\n        else if (g_memcmp(codec_guid, XR_CODEC_GUID_JPEG, 16) == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_caps_process_codecs: JPEG(%s), codec id [%d], properties len [%d]\",\n                codec_guid_str, codec_id, codec_properties_length);\n            self->client_info.jpeg_codec_id = codec_id;\n            i1 = MIN(64, codec_properties_length);\n            g_memcpy(self->client_info.jpeg_prop, s->p, i1);\n            self->client_info.jpeg_prop_len = i1;\n            /* make sure that requested quality is  between 0 to 100 */\n            if (self->client_info.jpeg_prop[0] < 0 || self->client_info.jpeg_prop[0] > 100)\n            {\n                LOG(LOG_LEVEL_WARNING, \"  Warning: the requested jpeg quality (%d) is invalid, \"\n                    \"falling back to default\", self->client_info.jpeg_prop[0]);\n                self->client_info.jpeg_prop[0] = 75; /* use default */\n            }\n            LOG(LOG_LEVEL_INFO, \"  jpeg quality set to %d\", self->client_info.jpeg_prop[0]);\n        }\n        else if (g_memcmp(codec_guid, XR_CODEC_GUID_H264, 16) == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_caps_process_codecs: H264(%s), codec id [%d], properties len [%d]\",\n                codec_guid_str, codec_id, codec_properties_length);\n            self->client_info.h264_codec_id = codec_id;\n            i1 = MIN(64, codec_properties_length);\n            g_memcpy(self->client_info.h264_prop, s->p, i1);\n            self->client_info.h264_prop_len = i1;\n        }\n        /* other known codec but not supported yet */\n        else if (g_memcmp(codec_guid, XR_CODEC_GUID_IMAGE_REMOTEFX, 16) == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_caps_process_codecs: Image RemoteFX(%s), codec id [%d], properties len [%d]\",\n                codec_guid_str, codec_id, codec_properties_length);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING, \"xrdp_caps_process_codecs: unknown(%s), codec id [%d], properties len [%d]\",\n                codec_guid_str, codec_id, codec_properties_length);\n        }\n\n        s->p = next_guid;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_multifragmentupdate(struct xrdp_rdp *self, struct stream *s,\n                                      int len)\n{\n    int MaxRequestSize;\n\n    in_uint32_le(s, MaxRequestSize);\n    if (self->client_info.use_fast_path & 1)\n    {\n        self->client_info.max_fastpath_frag_bytes = MaxRequestSize;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_largepointer(struct xrdp_rdp *self, struct stream *s,\n                               int len)\n{\n    int largePointerSupportFlags;\n\n    in_uint16_le(s, largePointerSupportFlags);\n    self->client_info.large_pointer_support_flags = largePointerSupportFlags;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_frame_ack(struct xrdp_rdp *self, struct stream *s, int len)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_process_frame_ack:\");\n    self->client_info.use_frame_acks = 1;\n    in_uint32_le(s, self->client_info.max_unacknowledged_frame_count);\n    if (self->client_info.max_unacknowledged_frame_count < 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"  invalid max_unacknowledged_frame_count value (%d), setting to 0\",\n            self->client_info.max_unacknowledged_frame_count);\n        self->client_info.max_unacknowledged_frame_count = 0;\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"  max_unacknowledged_frame_count %d\", self->client_info.max_unacknowledged_frame_count);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_caps_process_surface_cmds(struct xrdp_rdp *self, struct stream *s, int len)\n{\n#ifdef USE_DEVEL_LOGGING\n    int cmdFlags;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_process_surface_cmds:\");\n    in_uint32_le(s, cmdFlags);\n    in_uint8s(s, 4); /* reserved */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"  cmdFlags 0x%08x\", cmdFlags);\n#endif\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Process a [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU (2.2.1.13.2.1) message.\n */\nint\nxrdp_caps_process_confirm_active(struct xrdp_rdp *self, struct stream *s)\n{\n    int cap_len;\n    int source_len;\n    int num_caps;\n    int index;\n    int type;\n    int len;\n    char *p;\n\n    if (!s_check_rem_and_log(s, 10,\n                             \"Parsing [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU\"\n                             \" - header\"))\n    {\n        return 1;\n    }\n    in_uint8s(s, 4); /* rdp_shareid */\n    in_uint8s(s, 2); /* userid */\n    in_uint16_le(s, source_len); /* sizeof RDP_SOURCE */\n    in_uint16_le(s, cap_len);\n\n    if (!s_check_rem_and_log(s, source_len + 2 + 2,\n                             \"Parsing [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU\"\n                             \" - header2\"))\n    {\n        return 1;\n    }\n    in_uint8s(s, source_len);\n    in_uint16_le(s, num_caps);\n    in_uint8s(s, 2); /* pad */\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU \"\n              \"shareID (ignored), originatorID (ignored), lengthSourceDescriptor %d, \"\n              \"lengthCombinedCapabilities  %d, sourceDescriptor (ignored), \"\n              \"numberCapabilities %d\", source_len, cap_len, num_caps);\n\n    if ((cap_len < 0) || (cap_len > 1024 * 1024))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU \"\n            \"lengthCombinedCapabilities %d is too long (> %d)\",\n            cap_len, 1024 * 1024);\n        return 1;\n    }\n\n    for (index = 0; index < num_caps; index++)\n    {\n        p = s->p;\n        if (!s_check_rem_and_log(s, 4,\n                                 \"Parsing [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET\"))\n        {\n            return 1;\n        }\n        in_uint16_le(s, type);\n        in_uint16_le(s, len);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                  \"capabilitySetType %d, lengthCapability %d\", type, len);\n        if (len < 4)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Protocol error [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                \"lengthCapability must be greater than 3, received %d\", len);\n            return 1;\n        }\n        if (!s_check_rem_and_log(s, len - 4,\n                                 \"Parsing [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"))\n        {\n            return 1;\n        }\n        len -= 4;\n        switch (type)\n        {\n            case CAPSTYPE_GENERAL:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_GENERAL\");\n                xrdp_caps_process_general(self, s, len);\n                break;\n            case CAPSTYPE_BITMAP:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_BITMAP\");\n                xrdp_caps_process_bitmap(self, s, len);\n                break;\n            case CAPSTYPE_ORDER:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_ORDER\");\n                xrdp_caps_process_order(self, s, len);\n                break;\n            case CAPSTYPE_BITMAPCACHE:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_BITMAPCACHE\");\n                xrdp_caps_process_bmpcache(self, s, len);\n                break;\n            case CAPSTYPE_CONTROL:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_CONTROL - Ignored\");\n                break;\n            case 6:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = 6\");\n                xrdp_caps_process_cache_v3_codec_id(self, s, len);\n                break;\n            case CAPSTYPE_ACTIVATION:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_ACTIVATION - Ignored\");\n                break;\n            case CAPSTYPE_POINTER:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_POINTER\");\n                xrdp_caps_process_pointer(self, s, len);\n                break;\n            case CAPSTYPE_SHARE:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_SHARE - Ignored\");\n                break;\n            case CAPSTYPE_COLORCACHE:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_COLORCACHE - Ignored\");\n                break;\n            case CAPSTYPE_SOUND:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_SOUND - Ignored\");\n                break;\n            case CAPSTYPE_INPUT:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_INPUT\");\n                xrdp_caps_process_input(self, s, len);\n                break;\n            case CAPSTYPE_FONT:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_FONT - Ignored\");\n                break;\n            case CAPSTYPE_BRUSH:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_BRUSH\");\n                xrdp_caps_process_brushcache(self, s, len);\n                break;\n            case CAPSTYPE_GLYPHCACHE:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_GLYPHCACHE\");\n                xrdp_caps_process_glyphcache(self, s, len);\n                break;\n            case CAPSTYPE_OFFSCREENCACHE:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_OFFSCREENCACHE\");\n                xrdp_caps_process_offscreen_bmpcache(self, s, len);\n                break;\n            case CAPSTYPE_BITMAPCACHE_REV2:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_BITMAPCACHE_REV2\");\n                xrdp_caps_process_bmpcache2(self, s, len);\n                break;\n            case CAPSTYPE_VIRTUALCHANNEL:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_VIRTUALCHANNEL - Ignored\");\n                break;\n            case CAPSTYPE_DRAWNINGRIDCACHE:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_DRAWNINGRIDCACHE - Ignored\");\n                break;\n            case CAPSTYPE_DRAWGDIPLUS:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_DRAWGDIPLUS - Ignored\");\n                break;\n            case CAPSTYPE_RAIL:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_RAIL\");\n                xrdp_caps_process_rail(self, s, len);\n                break;\n            case CAPSTYPE_WINDOW:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_WINDOW\");\n                xrdp_caps_process_window(self, s, len);\n                break;\n            case CAPSSETTYPE_MULTIFRAGMENTUPDATE:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSSETTYPE_MULTIFRAGMENTUPDATE\");\n                xrdp_caps_process_multifragmentupdate(self, s, len);\n                break;\n            case CAPSETTYPE_LARGE_POINTER:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSETTYPE_LARGE_POINTER\");\n                xrdp_caps_process_largepointer(self, s, len);\n                break;\n            case CAPSETTYPE_SURFACE_COMMANDS:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSETTYPE_SURFACE_COMMANDS\");\n                xrdp_caps_process_surface_cmds(self, s, len);\n                break;\n            case CAPSSETTYPE_BITMAP_CODECS:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSSETTYPE_BITMAP_CODECS\");\n                xrdp_caps_process_codecs(self, s, len);\n                break;\n            case CAPSTYPE_FRAME_ACKNOWLEDGE:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                          \"capabilitySetType = CAPSTYPE_FRAME_ACKNOWLEDGE\");\n                xrdp_caps_process_frame_ack(self, s, len);\n                break;\n            default:\n                LOG(LOG_LEVEL_WARNING, \"Received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU - TS_CAPS_SET \"\n                    \"capabilitySetType = %d is unknown - Ignored\", type);\n                break;\n        }\n\n        s->p = p + len + 4;\n    }\n\n    if (self->client_info.no_orders_supported &&\n            (self->client_info.offscreen_support_level != 0))\n    {\n        LOG(LOG_LEVEL_WARNING, \"Client Capability: not enough orders \"\n            \"supported by client, client wants off screen bitmap but \"\n            \"offscreen bitmaps disabled\");\n        self->client_info.offscreen_support_level = 0;\n        self->client_info.offscreen_cache_size = 0;\n        self->client_info.offscreen_cache_entries = 0;\n    }\n\n    if (self->client_info.use_fast_path)\n    {\n        if ((self->client_info.large_pointer_support_flags & LARGE_POINTER_FLAG_96x96) &&\n                (self->client_info.max_fastpath_frag_bytes < 38055))\n        {\n            LOG(LOG_LEVEL_WARNING, \"Client Capability: client requested \"\n                \"LARGE_POINTER_FLAG_96x96 but max_fastpath_frag_bytes(%d) is less then \"\n                \"the required size of 38055, 96x96 large cursor support disabled\",\n                self->client_info.max_fastpath_frag_bytes);\n            self->client_info.large_pointer_support_flags &= ~LARGE_POINTER_FLAG_96x96;\n        }\n        if ((self->client_info.large_pointer_support_flags & LARGE_POINTER_FLAG_384x384) &&\n                (self->client_info.max_fastpath_frag_bytes < 608299))\n        {\n            LOG(LOG_LEVEL_WARNING, \"Client Capability: client requested \"\n                \"LARGE_POINTER_FLAG_384x384 but max_fastpath_frag_bytes(%d) is less then \"\n                \"the required size of 608299, 384x384 large cursor support disabled\",\n                self->client_info.max_fastpath_frag_bytes);\n            self->client_info.large_pointer_support_flags &= ~LARGE_POINTER_FLAG_384x384;\n        }\n    }\n    else\n    {\n        if (self->client_info.large_pointer_support_flags != 0)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Client Capability: client requested \"\n                \"large pointers but use_fast_path is false, \"\n                \"all large cursor support disabled\");\n            self->client_info.large_pointer_support_flags = 0;\n        }\n    }\n    if (self->client_info.large_pointer_support_flags & LARGE_POINTER_FLAG_96x96)\n    {\n        LOG(LOG_LEVEL_INFO, \"Client Capability: LARGE_POINTER_FLAG_96x96 supported\");\n    }\n    if (self->client_info.large_pointer_support_flags & LARGE_POINTER_FLAG_384x384)\n    {\n        LOG(LOG_LEVEL_INFO, \"Client Capability: LARGE_POINTER_FLAG_384x384 supported\");\n    }\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Completed processing received [MS-RDPBCGR] TS_CONFIRM_ACTIVE_PDU\");\n    return 0;\n}\n\n/**************************************************************************//**\n * Calculate the multifragmentupdate len we advertised to the client\n * for fastpath updates\n *\n * See [MS-RDPBCGR] 2.2.7.2.6\n *\n * The basic logic is taken from freerdp 2.4. We try to use the highest\n * useful request size that will allow us to pack a complete screen\n * update into a single fast path PDU using any of the supported codecs.\n * For RemoteFX, the client MUST use at least this value\n *\n * A backstop on the maximum advertised size is implemented to prevent\n * extreme memory usage for large screen configurations. RDP supports a\n * maximum desktop size of 32768x32768, which would cause overflow for\n * 32-bit integers using a simple calculation.\n *\n * The codecs have to deal with the value returned by the client after\n * we advertise our own value, and must not assume a complete update\n * will fit in a single PDU\n */\nstatic\nunsigned int calculate_multifragmentupdate_len(const struct xrdp_rdp *self)\n{\n    unsigned int result = MAX_MULTIFRAGMENTUPDATE_SIZE;\n\n    unsigned int x_tiles = (self->client_info.display_sizes.session_width + 63) / 64;\n    unsigned int y_tiles = (self->client_info.display_sizes.session_height + 63) / 64;\n\n    /* Check for overflow on calculation if bad parameters are supplied */\n    if ((x_tiles * y_tiles  + 1) < (UINT_MAX / 16384))\n    {\n        result = x_tiles * y_tiles * 16384;\n        /* and add room for headers, regions, frame markers, etc. */\n        result += 16384;\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nint\nxrdp_caps_send_demand_active(struct xrdp_rdp *self)\n{\n    struct stream *s;\n    int caps_count;\n    int caps_size;\n    int codec_caps_count;\n    int codec_caps_size;\n    int flags;\n    char *caps_count_ptr;\n    char *caps_size_ptr;\n    char *caps_ptr;\n    char *codec_caps_count_ptr;\n    char *codec_caps_size_ptr;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n\n    if (xrdp_rdp_init(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_caps_send_demand_active: xrdp_rdp_init failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    caps_count = 0;\n    out_uint32_le(s, self->share_id);\n    out_uint16_le(s, 4); /* 4 chars for RDP\\0 */\n    /* 2 bytes size after num caps, set later */\n    caps_size_ptr = s->p;\n    out_uint8s(s, 2);\n    out_uint8a(s, \"RDP\", 4);\n    /* 4 byte num caps, set later */\n    caps_count_ptr = s->p;\n    out_uint8s(s, 4);\n    caps_ptr = s->p;\n\n    /* Output share capability set */\n    caps_count++;\n    out_uint16_le(s, CAPSTYPE_SHARE);\n    out_uint16_le(s, CAPSTYPE_SHARE_LEN);\n    out_uint16_le(s, self->mcs_channel);\n    out_uint16_be(s, 0xb5e2); /* 0x73e1 */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"CAPSTYPE_SHARE \"\n              \"channel ID = 0x%x\", self->mcs_channel);\n\n    /* Output general capability set */\n    caps_count++;\n    out_uint16_le(s, CAPSTYPE_GENERAL);\n    out_uint16_le(s, CAPSTYPE_GENERAL_LEN);\n    out_uint16_le(s, OSMAJORTYPE_WINDOWS);\n    out_uint16_le(s, OSMINORTYPE_WINDOWS_NT);\n    out_uint16_le(s, 0x200); /* Protocol version */\n    out_uint16_le(s, 0); /* pad */\n    out_uint16_le(s, 0); /* Compression types */\n    if (self->client_info.use_fast_path & 1)\n    {\n        out_uint16_le(s, NO_BITMAP_COMPRESSION_HDR | FASTPATH_OUTPUT_SUPPORTED);\n    }\n    else\n    {\n        out_uint16_le(s, NO_BITMAP_COMPRESSION_HDR);\n    }\n    out_uint16_le(s, 0); /* Update capability */\n    out_uint16_le(s, 0); /* Remote unshare capability */\n    out_uint16_le(s, 0); /* Compression level */\n    out_uint8(s, 1); /* refreshRectSupport */\n    out_uint8(s, 1); /* suppressOutputSupport */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"CAPSTYPE_GENERAL TODO\");\n\n    /* Output bitmap capability set */\n    caps_count++;\n    out_uint16_le(s, CAPSTYPE_BITMAP);\n    out_uint16_le(s, CAPSTYPE_BITMAP_LEN);\n    out_uint16_le(s, self->client_info.bpp); /* Preferred BPP */\n    out_uint16_le(s, 1); /* Receive 1 BPP */\n    out_uint16_le(s, 1); /* Receive 4 BPP */\n    out_uint16_le(s, 1); /* Receive 8 BPP */\n    out_uint16_le(s, self->client_info.display_sizes.session_width); /* width */\n    out_uint16_le(s, self->client_info.display_sizes.session_height); /* height */\n    out_uint16_le(s, 0); /* Pad */\n    out_uint16_le(s, 1); /* Allow resize */\n    out_uint16_le(s, 1); /* bitmap compression */\n    out_uint16_le(s, 0); /* unknown */\n    out_uint16_le(s, 0); /* unknown */\n    out_uint16_le(s, 0); /* pad */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"CAPSTYPE_BITMAP TODO\");\n\n    /* Output font capability set */\n    caps_count++;\n    out_uint16_le(s, CAPSTYPE_FONT);\n    out_uint16_le(s, CAPSTYPE_FONT_LEN);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"CAPSTYPE_FONT\");\n\n    /* Output order capability set */\n    caps_count++;\n    out_uint16_le(s, CAPSTYPE_ORDER);\n    out_uint16_le(s, CAPSTYPE_ORDER_LEN);\n    out_uint8s(s, 16);\n    out_uint32_be(s, 0x40420f00);\n    out_uint16_le(s, 1); /* Cache X granularity */\n    out_uint16_le(s, 20); /* Cache Y granularity */\n    out_uint16_le(s, 0); /* Pad */\n    out_uint16_le(s, 1); /* Max order level */\n    out_uint16_le(s, 0x2f); /* Number of fonts */\n    out_uint16_le(s, 0x22); /* Capability flags */\n    /* caps */\n    out_uint8(s, 1); /* NEG_DSTBLT_INDEX                0x00 0 */\n    out_uint8(s, 1); /* NEG_PATBLT_INDEX                0x01 1 */\n    out_uint8(s, 1); /* NEG_SCRBLT_INDEX                0x02 2 */\n    out_uint8(s, 1); /* NEG_MEMBLT_INDEX                0x03 3 */\n    out_uint8(s, 0); /* NEG_MEM3BLT_INDEX               0x04 4 */\n    out_uint8(s, 0); /* NEG_ATEXTOUT_INDEX              0x05 5 */\n    out_uint8(s, 0); /* NEG_AEXTTEXTOUT_INDEX           0x06 6 */\n    out_uint8(s, 0); /* NEG_DRAWNINEGRID_INDEX          0x07 7 */\n    out_uint8(s, 1); /* NEG_LINETO_INDEX                0x08 8 */\n    out_uint8(s, 0); /* NEG_MULTI_DRAWNINEGRID_INDEX    0x09 9 */\n    out_uint8(s, 1); /* NEG_OPAQUE_RECT_INDEX           0x0A 10 */\n    out_uint8(s, 0); /* NEG_SAVEBITMAP_INDEX            0x0B 11 */\n    out_uint8(s, 0); /* NEG_WTEXTOUT_INDEX              0x0C 12 */\n    out_uint8(s, 0); /* NEG_MEMBLT_V2_INDEX             0x0D 13 */\n    out_uint8(s, 0); /* NEG_MEM3BLT_V2_INDEX            0x0E 14 */\n    out_uint8(s, 0); /* NEG_MULTIDSTBLT_INDEX           0x0F 15 */\n    out_uint8(s, 0); /* NEG_MULTIPATBLT_INDEX           0x10 16 */\n    out_uint8(s, 0); /* NEG_MULTISCRBLT_INDEX           0x11 17 */\n    out_uint8(s, 1); /* NEG_MULTIOPAQUERECT_INDEX       0x12 18 */\n    out_uint8(s, 0); /* NEG_FAST_INDEX_INDEX            0x13 19 */\n    out_uint8(s, 0); /* NEG_POLYGON_SC_INDEX            0x14 20 */\n    out_uint8(s, 0); /* NEG_POLYGON_CB_INDEX            0x15 21 */\n    out_uint8(s, 0); /* NEG_POLYLINE_INDEX              0x16 22 */\n    out_uint8(s, 0); /* unused                          0x17 23 */\n    out_uint8(s, 0); /* NEG_FAST_GLYPH_INDEX            0x18 24 */\n    out_uint8(s, 0); /* NEG_ELLIPSE_SC_INDEX            0x19 25 */\n    out_uint8(s, 0); /* NEG_ELLIPSE_CB_INDEX            0x1A 26 */\n    out_uint8(s, 1); /* NEG_GLYPH_INDEX_INDEX           0x1B 27 */\n    out_uint8(s, 0); /* NEG_GLYPH_WEXTTEXTOUT_INDEX     0x1C 28 */\n    out_uint8(s, 0); /* NEG_GLYPH_WLONGTEXTOUT_INDEX    0x1D 29 */\n    out_uint8(s, 0); /* NEG_GLYPH_WLONGEXTTEXTOUT_INDEX 0x1E 30 */\n    out_uint8(s, 0); /* unused                          0x1F 31 */\n    out_uint16_le(s, 0x6a1);\n    /* declare support of bitmap cache rev3 */\n    out_uint16_le(s, XR_ORDERFLAGS_EX_CACHE_BITMAP_REV3_SUPPORT);\n    out_uint32_le(s, 0x0f4240); /* desk save */\n    out_uint32_le(s, 0x0f4240); /* desk save */\n    out_uint32_le(s, 1); /* ? */\n    out_uint32_le(s, 0); /* ? */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"CAPSTYPE_ORDER \"\n              \"TODO\");\n\n    /* Output bmpcodecs capability set */\n    caps_count++;\n    out_uint16_le(s, CAPSSETTYPE_BITMAP_CODECS);\n    codec_caps_size_ptr = s->p;\n    out_uint8s(s, 2); /* cap len set later */\n    codec_caps_count = 0;\n    codec_caps_count_ptr = s->p;\n    out_uint8s(s, 1); /* bitmapCodecCount set later */\n    /* nscodec */\n    codec_caps_count++;\n    out_uint8a(s, XR_CODEC_GUID_NSCODEC, 16);\n    out_uint8(s, 1); /* codec id, must be 1 */\n    out_uint16_le(s, 3); /* codecPropertiesLength */\n    out_uint8(s, 0x01); /* fAllowDynamicFidelity */\n    out_uint8(s, 0x01); /* fAllowSubsampling */\n    out_uint8(s, 0x03); /* colorLossLevel */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"NSCODEC \"\n              \"fAllowDynamicFidelity = 0x01,\"\n              \"fAllowSubsampling = 0x01,\"\n              \"colorLossLevel = 0x03\");\n#if defined(XRDP_RFXCODEC) || defined(XRDP_NEUTRINORDP)\n    /* remotefx */\n    codec_caps_count++;\n    out_uint8a(s, XR_CODEC_GUID_REMOTEFX, 16);\n    out_uint8(s, 0); /* codec id, client sets */\n    out_uint16_le(s, 4); /* codecPropertiesLength */\n    out_uint32_le(s, 0); /* reserved */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"REMOTEFX\");\n    /* image remotefx */\n    codec_caps_count++;\n    out_uint8a(s, XR_CODEC_GUID_IMAGE_REMOTEFX, 16);\n    out_uint8(s, 0); /* codec id, client sets */\n    out_uint16_le(s, 4); /* codecPropertiesLength */\n    out_uint32_le(s, 0); /* reserved */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"IMAGE_REMOTEFX\");\n#endif\n    /* jpeg */\n    codec_caps_count++;\n    out_uint8a(s, XR_CODEC_GUID_JPEG, 16);\n    out_uint8(s, 0); /* codec id, client sets */\n    out_uint16_le(s, 1); /* codecPropertiesLength */\n    out_uint8(s, 75); /* jpeg compression ratio */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"JPEG: \"\n              \"jpeg compression ratio = 75\");\n    /* calculate and set size and count */\n    codec_caps_size = (int)(s->p - codec_caps_size_ptr);\n    codec_caps_size += 2; /* 2 bytes for CAPSTYPE_BMPCODECS above */\n    codec_caps_size_ptr[0] = codec_caps_size;\n    codec_caps_size_ptr[1] = codec_caps_size >> 8;\n    codec_caps_count_ptr[0] = codec_caps_count;\n\n    /* Output color cache capability set */\n    caps_count++;\n    out_uint16_le(s, CAPSTYPE_COLORCACHE);\n    out_uint16_le(s, CAPSTYPE_COLORCACHE_LEN);\n    out_uint16_le(s, 6); /* cache size */\n    out_uint16_le(s, 0); /* pad */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"CAPSTYPE_COLORCACHE: \"\n              \"colorTableCacheSize = 6\");\n\n    /* Output pointer capability set */\n    caps_count++;\n    out_uint16_le(s, CAPSTYPE_POINTER);\n    out_uint16_le(s, CAPSTYPE_POINTER_LEN);\n    out_uint16_le(s, 1); /* Colour pointer */\n    out_uint16_le(s, 0x19); /* Cache size */\n    out_uint16_le(s, 0x19); /* Cache size */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"CAPSTYPE_POINTER: \"\n              \"colorPointerFlag = true\"\n              \"colorPointerCacheSize = 0x19\"\n              \"pointerCacheSize = 0x19\");\n\n    /* Output input capability set */\n    /* https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/b3bc76ae-9ee5-454f-b197-ede845ca69cc */\n    caps_count++;\n    out_uint16_le(s, CAPSTYPE_INPUT);\n    out_uint16_le(s, CAPSTYPE_INPUT_LEN);\n\n    flags = INPUT_FLAG_SCANCODES |\n            INPUT_FLAG_MOUSEX    |\n            INPUT_FLAG_UNICODE   |\n            TS_INPUT_FLAG_MOUSE_HWHEEL;\n\n    if (self->client_info.use_fast_path & 2)\n    {\n        flags |= INPUT_FLAG_FASTPATH_INPUT | INPUT_FLAG_FASTPATH_INPUT2;\n    }\n    out_uint16_le(s, flags);\n    out_uint8s(s, 82);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"CAPSTYPE_INPUT: \"\n              \"inputFlags = 0x%x\", flags);\n\n    if (self->client_info.rail_enable) /* MS-RDPERP 3.3.5.1.4 */\n    {\n        /* Remote Programs Capability Set */\n        caps_count++;\n        out_uint16_le(s, CAPSTYPE_RAIL);\n        out_uint16_le(s, 8); /* LengthCapability: MS-RDPERP 2.2.1.1.1 */\n        out_uint32_le(s, 3); /* See: https://msdn.microsoft.com/en-us/library/cc242518.aspx\n                                TS_RAIL_LEVEL_SUPPORTED\n                                TS_RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n                  \"CAPSTYPE_RAIL: \"\n                  \"RailSupportLevel = \"\n                  \"TS_RAIL_LEVEL_SUPPORTED | TS_RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED\");\n\n        /* Window List Capability Set */\n        caps_count++;\n        out_uint16_le(s, CAPSTYPE_WINDOW);\n        out_uint16_le(s, 11); /* LengthCapability: MS-RDPERP 2.2.1.1.2 */\n        out_uint32_le(s, TS_WINDOW_LEVEL_SUPPORTED_EX);\n        out_uint8(s, 3); /* NumIconCaches */\n        out_uint16_le(s, 12); /* NumIconCacheEntries */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n                  \"CAPSTYPE_WINDOW: \"\n                  \"WndSupportLevel = TS_WINDOW_LEVEL_SUPPORTED_EX, \"\n                  \"NumIconCaches = 3,\"\n                  \"NumIconCacheEntries = 12\");\n    }\n\n    /* 6 - bitmap cache v3 codecid */\n    caps_count++;\n    out_uint16_le(s, 0x0006);\n    out_uint16_le(s, 5);\n    out_uint8(s, 0); /* client sets */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n              \"0x0006 = 0\");\n\n    if (self->client_info.use_fast_path & FASTPATH_OUTPUT_SUPPORTED) /* fastpath output on */\n    {\n        unsigned int max_request_size = calculate_multifragmentupdate_len(self);\n        caps_count++;\n        out_uint16_le(s, CAPSSETTYPE_MULTIFRAGMENTUPDATE);\n        out_uint16_le(s, CAPSSETTYPE_MULTIFRAGMENTUPDATE_LEN);\n        out_uint32_le(s, max_request_size);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n                  \"CAPSSETTYPE_MULTIFRAGMENTUPDATE = %d\", max_request_size);\n\n        /* large pointer 96x96 */\n        caps_count++;\n        out_uint16_le(s, CAPSETTYPE_LARGE_POINTER);\n        out_uint16_le(s, CAPSETTYPE_LARGE_POINTER_LEN);\n        out_uint16_le(s, LARGE_POINTER_FLAG_96x96);\n\n        /* frame acks */\n        caps_count++;\n        out_uint16_le(s, CAPSTYPE_FRAME_ACKNOWLEDGE);\n        out_uint16_le(s, CAPSTYPE_FRAME_ACKNOWLEDGE_LEN);\n        out_uint32_le(s, 2); /* 2 frames in flight */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n                  \"CAPSTYPE_FRAME_ACKNOWLEDGE = 2 frames\");\n\n        /* surface commands */\n        caps_count++;\n        out_uint16_le(s, CAPSETTYPE_SURFACE_COMMANDS);\n        out_uint16_le(s, CAPSETTYPE_SURFACE_COMMANDS_LEN);\n        out_uint32_le(s, (SURFCMDS_SETSURFACEBITS |\n                          SURFCMDS_FRAMEMARKER |\n                          SURFCMDS_STREAMSUFRACEBITS)); /* cmdFlags */\n        out_uint32_le(s, 0); /* reserved */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: Server Capability \"\n                  \"CAPSETTYPE_SURFACE_COMMANDS = \"\n                  \"SURFCMDS_SETSURFACEBITS | SURFCMDS_FRAMEMARKER | SURFCMDS_STREAMSUFRACEBITS\");\n    }\n\n    out_uint8s(s, 4); /* pad */\n\n    s_mark_end(s);\n\n    caps_size = (int)(s->end - caps_ptr);\n    caps_size_ptr[0] = caps_size;\n    caps_size_ptr[1] = caps_size >> 8;\n\n    caps_count_ptr[0] = caps_count;\n    caps_count_ptr[1] = caps_count >> 8;\n    caps_count_ptr[2] = caps_count >> 16;\n    caps_count_ptr[3] = caps_count >> 24;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: sending PDUTYPE_DEMANDACTIVEPDU \"\n              \"message with the server's capabilities\");\n    if (xrdp_rdp_send(self, s, PDUTYPE_DEMANDACTIVEPDU) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_caps_send_demand_active: xrdp_rdp_send failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    /* send Monitor Layout PDU for multi-monitor */\n    int early_cap_flags = self->client_info.mcs_early_capability_flags;\n\n    if ((early_cap_flags & RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU) != 0 &&\n            self->client_info.display_sizes.monitorCount > 0 &&\n            self->client_info.multimon == 1)\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_caps_send_demand_active: sending monitor layout pdu\");\n        if (xrdp_caps_send_monitorlayout(self) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_caps_send_demand_active: error sending monitor layout pdu\");\n        }\n    }\n\n    free_stream(s);\n    return 0;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_channel.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2006-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * channel layer\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n#include \"string_calls.h\"\n#include \"xrdp_channel.h\"\n\n#define CMD_DVC_OPEN_CHANNEL    0x10\n#define CMD_DVC_DATA_FIRST      0x20\n#define CMD_DVC_DATA            0x30\n#define CMD_DVC_CLOSE_CHANNEL   0x40\n#define CMD_DVC_CAPABILITY      0x50\n\n#define XRDP_DRDYNVC_CHANNEL_ID_TO_NAME(self, chan_id) \\\n    (xrdp_channel_get_item((self), (chan_id)) != NULL \\\n     ? xrdp_channel_get_item((self), (chan_id))->name \\\n     : \"unknown\")\n\n/*****************************************************************************/\n/* returns pointer or nil on error */\nstatic struct mcs_channel_item *\nxrdp_channel_get_item(struct xrdp_channel *self, int channel_id)\n{\n    struct mcs_channel_item *channel;\n\n    if (self->mcs_layer->channel_list == NULL)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Channel list is NULL, returning NULL\");\n        return NULL ;\n    }\n\n    channel = (struct mcs_channel_item *)\n              list_get_item(self->mcs_layer->channel_list, channel_id);\n    return channel;\n}\n\n/*****************************************************************************/\nstruct xrdp_channel *\nxrdp_channel_create(struct xrdp_sec *owner, struct xrdp_mcs *mcs_layer)\n{\n    struct xrdp_channel *self;\n\n    self = (struct xrdp_channel *)g_malloc(sizeof(struct xrdp_channel), 1);\n    self->sec_layer = owner;\n    self->mcs_layer = mcs_layer;\n    self->drdynvc_channel_id = -1;\n    return self;\n}\n\n/*****************************************************************************/\n/* returns error */\nvoid\nxrdp_channel_delete(struct xrdp_channel *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n    free_stream(self->s);\n    g_memset(self, 0, sizeof(struct xrdp_channel));\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_channel_init(struct xrdp_channel *self, struct stream *s)\n{\n    if (xrdp_sec_init(self->sec_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_channel_init: xrdp_sec_init failed\");\n        return 1;\n    }\n\n    s_push_layer(s, channel_hdr, 8);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* This sends data out to the secure layer. */\nint\nxrdp_channel_send(struct xrdp_channel *self, struct stream *s, int channel_id,\n                  int total_data_len, int flags)\n{\n    struct mcs_channel_item *channel;\n\n    channel = xrdp_channel_get_item(self, channel_id);\n\n    if (channel == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Request to send a message to non-existent channel_id %d\",\n            channel_id);\n        return 1;\n    }\n\n    if (channel->disabled)\n    {\n        LOG(LOG_LEVEL_DEBUG,\n            \"Request to send a message to the disabled channel %s (%d)\",\n            channel->name, channel_id);\n        return 0; /* not an error */\n    }\n\n    s_pop_layer(s, channel_hdr);\n    out_uint32_le(s, total_data_len);\n\n    /*\n     * According to 2.2.1.3.4.1 Channel Definition Structure (CHANNEL_DEF):\n     * CHANNEL_OPTION_SHOW_PROTOCOL 0x00200000\n     *  The value of this flag MUST be ignored by the server. The\n     *  visibility of the Channel PDU Header (section 2.2.6.1.1) is\n     *  determined by the CHANNEL_FLAG_SHOW_PROTOCOL\n     *  (0x00000010) flag as defined in the flags field (section\n     *  2.2.6.1.1).\n     *\n     *   That's flag makes MSTSC crash when using RAIL channel.\n     */\n    //    if (channel->flags & XR_CHANNEL_OPTION_SHOW_PROTOCOL)\n    //    {\n    //        flags |= CHANNEL_FLAG_SHOW_PROTOCOL;\n    //    }\n\n    out_uint32_le(s, flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] CHANNEL_PDU_HEADER \"\n              \"length %d, flags 0x%8.8x\", total_data_len, flags);\n\n    if (xrdp_sec_send(self->sec_layer, s, channel->chanid) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_channel_send: xrdp_sec_send failed\");\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* this will inform the callback, whatever it is that some channel data is\n   ready.  the default for this is a call to xrdp_wm.c. */\nstatic int\nxrdp_channel_call_callback(struct xrdp_channel *self, struct stream *s,\n                           int channel_id,\n                           int total_data_len, int flags)\n{\n    struct xrdp_session *session;\n    int rv;\n    int size;\n\n    rv = 0;\n    session = self->sec_layer->rdp_layer->session;\n\n    if (session != 0)\n    {\n        if (session->callback != 0)\n        {\n            size = (int)(s->end - s->p);\n            /* in xrdp_wm.c */\n            rv = session->callback(session->id, 0x5555,\n                                   MAKELONG(channel_id, flags),\n                                   size, (tbus)(s->p), total_data_len);\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING, \"session->callback is NULL\");\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_WARNING, \"session is NULL\");\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/**\n * Write a variable length unsigned int (1, 2, or 4 bytes) to the stream.\n *\n * The number of bytes written is the minimum number of bytes needed to\n * represent the value.\n *\n * @param s the stream to write to\n * @param val the value to write\n * @return the DYNVC cbId length code for the number of bytes written (see [MS-RDPEDYC] 2.2.2.1)\n */\nstatic int\ndrdynvc_insert_uint_124(struct stream *s, uint32_t val)\n{\n    int ret_val;\n\n    if (val <= 0xff)\n    {\n        out_uint8(s, val);\n        ret_val = 0;\n    }\n    else if (val <= 0xffff)\n    {\n        out_uint16_le(s, val);\n        ret_val = 1;\n    }\n    else\n    {\n        out_uint32_le(s, val);\n        ret_val = 2;\n    }\n\n    return ret_val;\n}\n\n/*****************************************************************************/\n/**\n * Read a variable length unsigned int (1, 2, or 4 bytes) from the stream.\n *\n * The number of bytes read is determined by the cbId bit field flag in the\n * cmd argument (see [MS-RDPEDYC] 2.2.2.1).\n *\n * @param s [in] the stream to read from\n * @param cmd [in] the cmd byte which contains the cbId bit field flag\n * @param chan_id_p [out] a pointer to the value read from the stream\n * @return error code\n */\nstatic int\ndrdynvc_get_chan_id(struct stream *s, char cmd, uint32_t *chan_id_p)\n{\n    int cbChId;\n    int chan_id;\n\n    cbChId = cmd & 0x03;\n    if (cbChId == 0)\n    {\n        if (!s_check_rem_and_log(s, 1, \"Parsing [MS-RDPEDYC] channel id\"))\n        {\n            return 1;\n        }\n        in_uint8(s, chan_id);\n    }\n    else if (cbChId == 1)\n    {\n        if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPEDYC] channel id\"))\n        {\n            return 1;\n        }\n        in_uint16_le(s, chan_id);\n    }\n    else\n    {\n        if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEDYC] channel id\"))\n        {\n            return 1;\n        }\n        in_uint32_le(s, chan_id);\n    }\n    *chan_id_p = chan_id;\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Process a [MS-RDPEDYC] DYNVC_CAPS_RSP message.\n */\nstatic int\ndrdynvc_process_capability_response(struct xrdp_channel *self,\n                                    int cmd, struct stream *s)\n{\n    struct xrdp_session *session;\n    int cap_version;\n    int rv;\n\n    if (!s_check_rem_and_log(s, 3, \"Parsing [MS-RDPEDYC] DYNVC_CAPS_RSP\"))\n    {\n        return 1;\n    }\n    in_uint8s(s, 1);              /* skip padding */\n    in_uint16_le(s, cap_version); /* Version */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPEDYC] DYNVC_CAPS_RSP \"\n              \"version %d\", cap_version);\n\n    if ((cap_version != 2) && (cap_version != 3))\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Dynamic Virtual Channel version %d is not supported\",\n            cap_version);\n        return 1;\n    }\n    self->drdynvc_state = 1;\n    session = self->sec_layer->rdp_layer->session;\n    rv = session->callback(session->id, 0x5558, 0, 0, 0, 0);\n    return rv;\n}\n\n/*****************************************************************************/\n/*\n * Process a [MS-RDPEDYC] DYNVC_CREATE_RSP message.\n */\nstatic int\ndrdynvc_process_open_channel_response(struct xrdp_channel *self,\n                                      int cmd, struct stream *s)\n{\n    struct xrdp_session *session;\n    int creation_status;\n    uint32_t chan_id;\n    struct xrdp_drdynvc *drdynvc;\n\n    if (drdynvc_get_chan_id(s, cmd, &chan_id) != 0) /* ChannelId */\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [MS-RDPEDYC] DYNVC_CREATE_RSP failed\");\n        return 1;\n    }\n    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEDYC] DYNVC_CREATE_RSP\"))\n    {\n        return 1;\n    }\n    in_uint32_le(s, creation_status); /* CreationStatus */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPEDYC] DYNVC_CREATE_RSP \"\n              \"ChannelId %d, CreationStatus %d\", chan_id, creation_status);\n    if (chan_id > 255)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Received [MS-RDPEDYC] DYNVC_CREATE_RSP for an \"\n            \"invalid channel id. Max allowed 255, received %d\", chan_id);\n        return 1;\n    }\n\n    session = self->sec_layer->rdp_layer->session;\n    drdynvc = self->drdynvcs + chan_id;\n    if (creation_status == 0)\n    {\n        drdynvc->status = XRDP_DRDYNVC_STATUS_OPEN;\n    }\n    else\n    {\n        drdynvc->status = XRDP_DRDYNVC_STATUS_CLOSED;\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG,\n              \"Dynamic Virtual Channel %s (%d) updated: status = %s\",\n              XRDP_DRDYNVC_CHANNEL_ID_TO_NAME(self, chan_id),\n              chan_id,\n              XRDP_DRDYNVC_STATUS_TO_STR(drdynvc->status));\n    if (drdynvc->open_response != NULL)\n    {\n        return drdynvc->open_response(session->id, chan_id, creation_status);\n    }\n    LOG_DEVEL(LOG_LEVEL_WARNING, \"Dynamic Virtual Channel %s (%d): \"\n              \"callback 'open_response' is NULL\",\n              XRDP_DRDYNVC_CHANNEL_ID_TO_NAME(self, chan_id),\n              chan_id);\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Process a [MS-RDPEDYC] DYNVC_CLOSE message.\n */\nstatic int\ndrdynvc_process_close_channel_response(struct xrdp_channel *self,\n                                       int cmd, struct stream *s)\n{\n    struct xrdp_session *session;\n    uint32_t chan_id;\n    struct xrdp_drdynvc *drdynvc;\n\n    if (drdynvc_get_chan_id(s, cmd, &chan_id) != 0) /* ChannelId */\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"drdynvc_process_close_channel_response: drdynvc_get_chan_id failed\");\n        return 1;\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPEDYC] DYNVC_CLOSE \"\n              \"ChannelId %d\", chan_id);\n    session = self->sec_layer->rdp_layer->session;\n    if (chan_id > 255)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Received message for an invalid \"\n            \"channel id. channel id %d\", chan_id);\n        return 1;\n    }\n\n    drdynvc = self->drdynvcs + chan_id;\n    drdynvc->status = XRDP_DRDYNVC_STATUS_CLOSED;\n    LOG_DEVEL(LOG_LEVEL_DEBUG,\n              \"Dynamic Virtual Channel %s (%d) updated: status = %s\",\n              XRDP_DRDYNVC_CHANNEL_ID_TO_NAME(self, chan_id),\n              chan_id,\n              XRDP_DRDYNVC_STATUS_TO_STR(drdynvc->status));\n\n    if (drdynvc->close_response != NULL)\n    {\n        return drdynvc->close_response(session->id, chan_id);\n    }\n    LOG_DEVEL(LOG_LEVEL_WARNING, \"Dynamic Virtual Channel %s (%d): \"\n              \"callback 'close_response' is NULL\",\n              XRDP_DRDYNVC_CHANNEL_ID_TO_NAME(self, chan_id),\n              chan_id);\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Process a [MS-RDPEDYC] DYNVC_DATA_FIRST message.\n */\nstatic int\ndrdynvc_process_data_first(struct xrdp_channel *self,\n                           int cmd, struct stream *s)\n{\n    struct xrdp_session *session;\n    uint32_t chan_id;\n    int len;\n    int bytes;\n    int total_bytes;\n    struct xrdp_drdynvc *drdynvc;\n\n    if (drdynvc_get_chan_id(s, cmd, &chan_id) != 0) /* ChannelId */\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [MS-RDPEDYC] DYNVC_DATA_FIRST failed\");\n        return 1;\n    }\n    len = (cmd >> 2) & 0x03;\n    if (len == 0)\n    {\n        if (!s_check_rem_and_log(s, 1, \"Parsing [MS-RDPEDYC] DYNVC_DATA_FIRST\"))\n        {\n            return 1;\n        }\n        in_uint8(s, total_bytes); /* Length */\n    }\n    else if (len == 1)\n    {\n        if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPEDYC] DYNVC_DATA_FIRST\"))\n        {\n            return 1;\n        }\n        in_uint16_le(s, total_bytes); /* Length */\n    }\n    else\n    {\n        if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEDYC] DYNVC_DATA_FIRST\"))\n        {\n            return 1;\n        }\n        in_uint32_le(s, total_bytes); /* Length */\n    }\n    bytes = (int) (s->end - s->p);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPEDYC] DYNVC_DATA_FIRST \"\n              \"ChannelId %d, Length %d, Data (omitted from the log)\",\n              chan_id, total_bytes);\n\n    session = self->sec_layer->rdp_layer->session;\n    if (chan_id > 255)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Received [MS-RDPEDYC] DYNVC_DATA_FIRST for an \"\n            \"invalid channel id. Max allowed 255, received %d\", chan_id);\n        return 1;\n    }\n    drdynvc = self->drdynvcs + chan_id;\n    if (drdynvc->data_first != NULL)\n    {\n        return drdynvc->data_first(session->id, chan_id, s->p,\n                                   bytes, total_bytes);\n    }\n    LOG_DEVEL(LOG_LEVEL_WARNING, \"Dynamic Virtual Channel %s (%d): \"\n              \"callback 'data_first' is NULL\",\n              XRDP_DRDYNVC_CHANNEL_ID_TO_NAME(self, chan_id),\n              chan_id);\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Process a [MS-RDPEDYC] DYNVC_DATA message.\n */\nstatic int\ndrdynvc_process_data(struct xrdp_channel *self,\n                     int cmd, struct stream *s)\n{\n    struct xrdp_session *session;\n    uint32_t chan_id;\n    int bytes;\n    struct xrdp_drdynvc *drdynvc;\n\n    if (drdynvc_get_chan_id(s, cmd, &chan_id) != 0) /* ChannelId */\n    {\n        LOG(LOG_LEVEL_ERROR, \"drdynvc_process_data: drdynvc_get_chan_id failed\");\n        return 1;\n    }\n    bytes = (int) (s->end - s->p);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPEDYC] DYNVC_DATA \"\n              \"ChannelId %d, (re-assembled) Length %d, Data (omitted from the log)\",\n              chan_id, bytes);\n    session = self->sec_layer->rdp_layer->session;\n    if (chan_id > 255)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Received message for an invalid \"\n            \"channel id. channel id %d\", chan_id);\n        return 1;\n    }\n    drdynvc = self->drdynvcs + chan_id;\n    if (drdynvc->data != NULL)\n    {\n        return drdynvc->data(session->id, chan_id, s->p, bytes);\n    }\n    LOG_DEVEL(LOG_LEVEL_WARNING, \"Dynamic Virtual Channel %s (%d): \"\n              \"callback 'data' is NULL\",\n              XRDP_DRDYNVC_CHANNEL_ID_TO_NAME(self, chan_id),\n              chan_id);\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Process a [MS-RDPBCGR] 2.2.6.1 Virtual Channel PDU and re-assemble the\n * data chunks as needed.\n */\nstatic int\nxrdp_channel_process_drdynvc(struct xrdp_channel *self,\n                             struct mcs_channel_item *channel,\n                             struct stream *s)\n{\n    int total_length;\n    int length;\n    int flags;\n    int cmd;\n    int rv;\n    struct stream *ls;\n\n    if (!s_check_rem_and_log(s, 8, \"Parsing [MS-RDPBCGR] CHANNEL_PDU_HEADER\"))\n    {\n        return 1;\n    }\n    in_uint32_le(s, total_length); /* length */\n    in_uint32_le(s, flags);        /* flags */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPBCGR] CHANNEL_PDU_HEADER \"\n              \"length %d, flags 0x%8.8x\", total_length, flags);\n    ls = NULL;\n    switch (flags & 3)\n    {\n        case 0: /* not first chunk and not last chunk */\n            length = (int) (s->end - s->p);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] data chunk (middle) \"\n                      \"length %d\", length);\n            if (length > s_rem_out(self->s))\n            {\n                LOG(LOG_LEVEL_ERROR, \"[MS-RDPBCGR] Data chunk length is bigger than \"\n                    \"the remaining chunk buffer size. length %d, remaining %d\",\n                    length, s_rem_out(self->s));\n                return 1;\n            }\n            out_uint8a(self->s, s->p, length); /* append data to chunk buffer */\n            in_uint8s(s, length);              /* virtualChannelData */\n            return 0;\n        case 1: /* CHANNEL_FLAG_FIRST */\n            free_stream(self->s);\n            make_stream(self->s);\n            init_stream(self->s, total_length);\n            length = (int) (s->end - s->p);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] data chunk (first) \"\n                      \"length %d\", length);\n            if (length > s_rem_out(self->s))\n            {\n                LOG(LOG_LEVEL_ERROR, \"[MS-RDPBCGR] Data chunk length is bigger than \"\n                    \"the remaining chunk buffer size. length %d, remaining %d\",\n                    length, s_rem_out(self->s));\n                return 1;\n            }\n            out_uint8a(self->s, s->p, length); /* append data to chunk buffer */\n            in_uint8s(s, length);              /* virtualChannelData */\n            return 0;\n        case 2: /* CHANNEL_FLAG_LAST */\n            length = (int) (s->end - s->p);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] data chunk (last) \"\n                      \"length %d\", length);\n            if (length > s_rem_out(self->s))\n            {\n                LOG(LOG_LEVEL_ERROR, \"[MS-RDPBCGR] Data chunk length is bigger than \"\n                    \"the remaining chunk buffer size. length %d, remaining %d\",\n                    length, s_rem_out(self->s));\n                return 1;\n            }\n            out_uint8a(self->s, s->p, length); /* append data to chunk buffer */\n            in_uint8s(s, length);              /* virtualChannelData */\n            ls = self->s;\n            break;\n        case 3: /* CHANNEL_FLAG_FIRST and CHANNEL_FLAG_LAST */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] data chunk (first and last) \"\n                      \"length %d\", total_length);\n            ls = s;\n            break;\n        default:\n            LOG(LOG_LEVEL_ERROR, \"Received [MS-RDPBCGR] data chunk with \"\n                \"unknown flag 0x%8.8x\", (int) (flags & 3));\n            return 1;\n    }\n    if (ls == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"BUG: ls must not be NULL\");\n        return 1;\n    }\n    in_uint8(ls, cmd); /* cbId (low 2 bits), Sp (2 bits), Cmd (hi 4 bits) */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPEDYC] \"\n              \"cbId %d, Sp %d, Cmd 0x%2.2x\",\n              (cmd & 0x03), (cmd & 0x0c) >> 2, (cmd & 0xf0) >> 4);\n    rv = 1;\n    switch (cmd & 0xf0)\n    {\n        case CMD_DVC_CAPABILITY:\n            rv = drdynvc_process_capability_response(self, cmd, s);\n            break;\n        case CMD_DVC_OPEN_CHANNEL:\n            rv = drdynvc_process_open_channel_response(self, cmd, s);\n            break;\n        case CMD_DVC_CLOSE_CHANNEL:\n            rv = drdynvc_process_close_channel_response(self, cmd, s);\n            break;\n        case CMD_DVC_DATA_FIRST:\n            rv = drdynvc_process_data_first(self, cmd, s);\n            break;\n        case CMD_DVC_DATA:\n            rv = drdynvc_process_data(self, cmd, s);\n            break;\n        default:\n            LOG(LOG_LEVEL_ERROR, \"Received header [MS-RDPEDYC] with \"\n                \"unknown command 0x%2.2x\", cmd);\n            break;\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* Process a static ([MS-RDPBCGR] 2.2.6) or dynamic (MS-RDPEDYC 2.2.3)\n * virtual channel message.\n * returns error */\n/* This is called from the secure layer to process an incoming non global\n   channel packet.\n   'chanid' passed in here is the mcs channel id so it MCS_GLOBAL_CHANNEL\n   plus something. */\nint\nxrdp_channel_process(struct xrdp_channel *self, struct stream *s,\n                     int chanid)\n{\n    int length;\n    int flags;\n    int rv;\n    int channel_id;\n    struct mcs_channel_item *channel;\n\n    /* this assumes that the channels are in order of chanid(mcs channel id)\n       but they should be, see xrdp_sec_process_mcs_data_channels\n       the first channel should be MCS_GLOBAL_CHANNEL + 1, second\n       one should be MCS_GLOBAL_CHANNEL + 2, and so on */\n    channel_id = (chanid - MCS_GLOBAL_CHANNEL) - 1;\n    channel = xrdp_channel_get_item(self, channel_id);\n    if (channel == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Received a message for an unknown channel id. channel id %d\",\n            chanid);\n        return 1;\n    }\n    if (channel->disabled)\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"Received a message for the disabled channel %s (%d)\",\n            channel->name, chanid);\n        return 0; /* not an error */\n    }\n    if (channel_id == self->drdynvc_channel_id)\n    {\n        return xrdp_channel_process_drdynvc(self, channel, s);\n    }\n    rv = 0;\n    in_uint32_le(s, length); /* length */\n    in_uint32_le(s, flags);  /* flags */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPBCGR] CHANNEL_PDU_HEADER \"\n              \"length %d, flags 0x%8.8x\", length, flags);\n    rv = xrdp_channel_call_callback(self, s, channel_id, length, flags);\n    return rv;\n}\n\n/*****************************************************************************/\n/* Send a [MS-RDPEDYC] DYNVC_CAPS_VERSION2 message */\nstatic int\nxrdp_channel_drdynvc_send_capability_request(struct xrdp_channel *self)\n{\n    struct stream *s;\n    int flags;\n    int total_data_len;\n    int channel_id;\n    char *phold;\n\n    /* setup stream */\n    make_stream(s);\n    init_stream(s, 8192);\n    if (xrdp_channel_init(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_channel_drdynvc_send_capability_request: xrdp_channel_init failed\");\n        free_stream(s);\n        return 1;\n    }\n    phold = s->p;\n    out_uint8(s, 0x50);         /* insert cbId (2 bits), Sp (2 bits), cmd (4 bits) */\n    out_uint8(s, 0x00);         /* insert padding   */\n    out_uint16_le(s, 2);        /* insert version   */\n    /* channel priority unused for now              */\n    out_uint16_le(s, 0x0000);  /* priority charge 0 */\n    out_uint16_le(s, 0x0000);  /* priority charge 1 */\n    out_uint16_le(s, 0x0000);  /* priority charge 2 */\n    out_uint16_le(s, 0x0000);  /* priority charge 3 */\n    s_mark_end(s);\n    /* send command to client */\n    total_data_len = (int) (s->end - phold);\n    flags = XR_CHANNEL_FLAG_FIRST | XR_CHANNEL_FLAG_LAST;\n    channel_id = self->drdynvc_channel_id;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPEDYC] DYNVC_CAPS_VERSION2 \"\n              \"cbId 0, Sp 0, Cmd 0x05, Version 2, PriorityCharge0 0, \"\n              \"PriorityCharge1 0, PriorityCharge2 0, PriorityCharge3 0\");\n    if (xrdp_channel_send(self, s, channel_id, total_data_len, flags) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_channel_drdynvc_send_capability_request: xrdp_channel_send failed\");\n        free_stream(s);\n        return 1;\n    }\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_channel_drdynvc_start(struct xrdp_channel *self)\n{\n    int rv = 0;\n    LOG_DEVEL(LOG_LEVEL_INFO,\n              \"xrdp_channel_drdynvc_start: drdynvc_channel_id %d\",\n              self->drdynvc_channel_id);\n    if (self->drdynvc_channel_id != -1)\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO,\n                  \"xrdp_channel_drdynvc_start: already started\");\n    }\n    else\n    {\n        int index;\n        int count;\n        struct mcs_channel_item *ci;\n        struct mcs_channel_item *dci;\n        dci = NULL;\n        count = self->mcs_layer->channel_list->count;\n        for (index = 0; index < count; index++)\n        {\n            ci = (struct mcs_channel_item *)\n                 list_get_item(self->mcs_layer->channel_list, index);\n            if (ci != NULL)\n            {\n                if (g_strcasecmp(ci->name, DRDYNVC_SVC_CHANNEL_NAME) == 0)\n                {\n                    dci = ci;\n                    break;\n                }\n            }\n        }\n        if (dci == NULL)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Static channel '%s' not found.\",\n                DRDYNVC_SVC_CHANNEL_NAME);\n            rv = -1;\n        }\n        else if (dci->disabled)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Static channel '%s' is disabled.\",\n                DRDYNVC_SVC_CHANNEL_NAME);\n            rv = -1;\n        }\n        else\n        {\n            self->drdynvc_channel_id = (dci->chanid - MCS_GLOBAL_CHANNEL) - 1;\n            LOG_DEVEL(LOG_LEVEL_DEBUG, DRDYNVC_SVC_CHANNEL_NAME\n                      \"Initializing Dynamic Virtual Channel with channel id %d\",\n                      self->drdynvc_channel_id);\n            xrdp_channel_drdynvc_send_capability_request(self);\n        }\n    }\n\n    if (rv != 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Dynamic channels will not be available\");\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/*\n * Send a [MS-RDPEDYC] DYNVC_CREATE_REQ message to request the creation of a channel.\n */\nint\nxrdp_channel_drdynvc_open(struct xrdp_channel *self, const char *name,\n                          int flags, struct xrdp_drdynvc_procs *procs,\n                          int *chan_id)\n{\n    struct stream *s;\n    int ChId;\n    int cbChId;\n    int chan_pri;\n    int static_channel_id;\n    int name_length;\n    int total_data_len;\n    int static_flags;\n    char *cmd_ptr;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    if (xrdp_channel_init(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_channel_drdynvc_open: xrdp_channel_init failed\");\n        free_stream(s);\n        return 1;\n    }\n    cmd_ptr = s->p;\n    out_uint8(s, 0); /* set later */\n    ChId = 1;\n    while (self->drdynvcs[ChId].status != XRDP_DRDYNVC_STATUS_CLOSED)\n    {\n        ChId++;\n        if (ChId > 255)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Attempting to create a new channel when the maximum \"\n                \"number of channels have already been created. \"\n                \"XRDP only supports 255 open channels.\");\n            free_stream(s);\n            return 1;\n        }\n    }\n    cbChId = drdynvc_insert_uint_124(s, ChId); /* ChannelId */\n    name_length = g_strlen(name);\n    out_uint8a(s, name, name_length + 1); /* ChannelName */\n    chan_pri = 0;\n    /* cbId (low 2 bits), Pri (2 bits), Cmd (hi 4 bits) */\n    cmd_ptr[0] = CMD_DVC_OPEN_CHANNEL | ((chan_pri << 2) & 0x0c) | cbChId;\n    static_channel_id = self->drdynvc_channel_id;\n    static_flags = XR_CHANNEL_FLAG_FIRST | XR_CHANNEL_FLAG_LAST;\n    s_mark_end(s);\n    total_data_len = (int) (s->end - cmd_ptr);\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPEDYC] DYNVC_CREATE_REQ \"\n              \"cbId %d, Pri %d, Cmd 0x%2.2x, ChannelId %d, ChannelName [%s]\",\n              cbChId, chan_pri, CMD_DVC_OPEN_CHANNEL, ChId, name);\n    if (xrdp_channel_send(self, s, static_channel_id, total_data_len,\n                          static_flags) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Sending [MS-RDPEDYC] DYNVC_CREATE_REQ failed\");\n        free_stream(s);\n        return 1;\n    }\n    free_stream(s);\n    *chan_id = ChId;\n    self->drdynvcs[ChId].open_response = procs->open_response;\n    self->drdynvcs[ChId].close_response = procs->close_response;\n    self->drdynvcs[ChId].data_first = procs->data_first;\n    self->drdynvcs[ChId].data = procs->data;\n    self->drdynvcs[ChId].status = XRDP_DRDYNVC_STATUS_OPEN_SENT;\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Send a [MS-RDPEDYC] DYNVC_CLOSE message to request the closing of a channel.\n */\nint\nxrdp_channel_drdynvc_close(struct xrdp_channel *self, int chan_id)\n{\n    struct stream *s;\n    int ChId;\n    int cbChId;\n    int static_channel_id;\n    int total_data_len;\n    int static_flags;\n    char *cmd_ptr;\n\n    if ((chan_id < 0) || (chan_id > 255))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Attempting to close an invalid channel id. \"\n            \"channel id %d\", chan_id);\n        return 1;\n    }\n    if ((self->drdynvcs[chan_id].status != XRDP_DRDYNVC_STATUS_OPEN) &&\n            (self->drdynvcs[chan_id].status != XRDP_DRDYNVC_STATUS_OPEN_SENT))\n    {\n        /* not open */\n        LOG(LOG_LEVEL_ERROR, \"Attempting to close a channel that is not open. \"\n            \"channel id %d, channel status %s\",\n            chan_id,\n            XRDP_DRDYNVC_STATUS_TO_STR(self->drdynvcs[chan_id].status));\n        return 1;\n    }\n    make_stream(s);\n    init_stream(s, 8192);\n    if (xrdp_channel_init(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_channel_drdynvc_close: xrdp_channel_init failed\");\n        free_stream(s);\n        return 1;\n    }\n    cmd_ptr = s->p;\n    out_uint8(s, 0); /* set later */\n    ChId = chan_id;\n    cbChId = drdynvc_insert_uint_124(s, ChId); /* ChannelId */\n    /* cbId (low 2 bits), Sp (2 bits), Cmd (hi 4 bits) */\n    cmd_ptr[0] = CMD_DVC_CLOSE_CHANNEL | cbChId;\n    static_channel_id = self->drdynvc_channel_id;\n    static_flags = XR_CHANNEL_FLAG_FIRST | XR_CHANNEL_FLAG_LAST;\n    s_mark_end(s);\n    total_data_len = (int) (s->end - cmd_ptr);\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPEDYC] DYNVC_CLOSE \"\n              \"cbId %d, Sp 0, Cmd 0x%2.2x, ChannelId %d\",\n              cbChId, CMD_DVC_CLOSE_CHANNEL, ChId);\n    if (xrdp_channel_send(self, s, static_channel_id, total_data_len,\n                          static_flags) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_channel_drdynvc_open: xrdp_channel_send failed\");\n        free_stream(s);\n        return 1;\n    }\n    free_stream(s);\n    self->drdynvcs[ChId].status = XRDP_DRDYNVC_STATUS_CLOSE_SENT;\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Send a [MS-RDPEDYC] DYNVC_DATA_FIRST message.\n */\nint\nxrdp_channel_drdynvc_data_first(struct xrdp_channel *self, int chan_id,\n                                const char *data, int data_bytes,\n                                int total_data_bytes)\n{\n    struct stream *s;\n    int ChId;\n    int cbChId;\n    int cbTotalDataSize;\n    int static_channel_id;\n    int total_data_len;\n    int static_flags;\n    char *cmd_ptr;\n\n    if ((chan_id < 0) || (chan_id > 255))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Attempting to send data to an invalid \"\n            \"channel id. channel id %d\", chan_id);\n        return 1;\n    }\n    if (self->drdynvcs[chan_id].status != XRDP_DRDYNVC_STATUS_OPEN)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Attempting to send data to a channel that \"\n            \"is not open. channel id %d, channel status %s\",\n            chan_id,\n            XRDP_DRDYNVC_STATUS_TO_STR(self->drdynvcs[chan_id].status));\n        return 1;\n    }\n    if (data_bytes > 1590)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Payload for channel id %d is is too big. \"\n            \"data_bytes %d\", chan_id, data_bytes);\n        return 1;\n    }\n    make_stream(s);\n    init_stream(s, 8192);\n    if (xrdp_channel_init(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_channel_drdynvc_data_first: xrdp_channel_init failed\");\n        free_stream(s);\n        return 1;\n    }\n    cmd_ptr = s->p;\n    out_uint8(s, 0); /* set later */\n    ChId = chan_id;\n    cbChId = drdynvc_insert_uint_124(s, ChId); /* ChannelId */\n    cbTotalDataSize = drdynvc_insert_uint_124(s, total_data_bytes); /* Length */\n    out_uint8p(s, data, data_bytes);           /* Data */\n    /* cbId (low 2 bits), Len (2 bits), Cmd (hi 4 bits) */\n    cmd_ptr[0] = CMD_DVC_DATA_FIRST | (cbTotalDataSize << 2) | cbChId;\n    static_channel_id = self->drdynvc_channel_id;\n    static_flags = XR_CHANNEL_FLAG_FIRST | XR_CHANNEL_FLAG_LAST;\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPEDYC] DYNVC_DATA_FIRST \"\n              \"cbId %d, Len %d, Cmd 0x%2.2x, ChannelId %d, Length %d\",\n              cbChId, cbTotalDataSize, CMD_DVC_DATA_FIRST, ChId, total_data_bytes);\n    total_data_len = (int) (s->end - cmd_ptr);\n    if (xrdp_channel_send(self, s, static_channel_id, total_data_len,\n                          static_flags) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_channel_drdynvc_data_first: xrdp_channel_send failed\");\n        free_stream(s);\n        return 1;\n    }\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Send a [MS-RDPEDYC] DYNVC_DATA message.\n */\nint\nxrdp_channel_drdynvc_data(struct xrdp_channel *self, int chan_id,\n                          const char *data, int data_bytes)\n{\n    struct stream *s;\n    int ChId;\n    int cbChId;\n    int static_channel_id;\n    int total_data_len;\n    int static_flags;\n    char *cmd_ptr;\n\n    if ((chan_id < 0) || (chan_id > 255))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Attempting to send data to an invalid \"\n            \"channel id. channel id %d\", chan_id);\n        return 1;\n    }\n    if (self->drdynvcs[chan_id].status != XRDP_DRDYNVC_STATUS_OPEN)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Attempting to send data to a channel that \"\n            \"is not open. channel id %d, channel status %s\",\n            chan_id,\n            XRDP_DRDYNVC_STATUS_TO_STR(self->drdynvcs[chan_id].status));\n        return 1;\n    }\n    if (data_bytes > 1590)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Payload for channel id %d is is too big. \"\n            \"data_bytes %d\", chan_id, data_bytes);\n        return 1;\n    }\n    make_stream(s);\n    init_stream(s, 8192);\n    if (xrdp_channel_init(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_channel_drdynvc_data: xrdp_channel_init failed\");\n        free_stream(s);\n        return 1;\n    }\n    cmd_ptr = s->p;\n    out_uint8(s, 0); /* set later */\n    ChId = chan_id;\n    cbChId = drdynvc_insert_uint_124(s, ChId); /* ChannelId */\n    out_uint8p(s, data, data_bytes);           /* Data */\n    /* cbId (low 2 bits), Sp (2 bits), Cmd (hi 4 bits) */\n    cmd_ptr[0] = CMD_DVC_DATA | cbChId;\n    static_channel_id = self->drdynvc_channel_id;\n    static_flags = XR_CHANNEL_FLAG_FIRST | XR_CHANNEL_FLAG_LAST;\n    s_mark_end(s);\n    total_data_len = (int) (s->end - cmd_ptr);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPEDYC] DYNVC_DATA \"\n              \"cbId %d, Sp 0, Cmd 0x%2.2x, ChannelId %d\",\n              cbChId, CMD_DVC_DATA_FIRST, ChId);\n    if (xrdp_channel_send(self, s, static_channel_id, total_data_len,\n                          static_flags) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_channel_drdynvc_data: xrdp_channel_send failed\");\n        free_stream(s);\n        return 1;\n    }\n    free_stream(s);\n    return 0;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_channel.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * MS-RDPEDYC : Definitions related to documentation in [MS-RDPEDYC]\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * References to MS-RDPEDYC are currently correct for v20210406 of that\n * document\n */\n\n#if !defined(XRDP_CHANNEL_H)\n#define XRDP_CHANNEL_H\n\n/*\n   These are not directly defined in MS-RDPEDYC, but\n   they are derived statuses needed to implement it.\n*/\n#define XRDP_DRDYNVC_STATUS_CLOSED          0\n#define XRDP_DRDYNVC_STATUS_OPEN_SENT       1\n#define XRDP_DRDYNVC_STATUS_OPEN            2\n#define XRDP_DRDYNVC_STATUS_CLOSE_SENT      3\n\n#define XRDP_DRDYNVC_STATUS_TO_STR(status) \\\n    ((status) == XRDP_DRDYNVC_STATUS_CLOSED ? \"CLOSED\" : \\\n     (status) == XRDP_DRDYNVC_STATUS_OPEN_SENT ? \"OPEN_SENT\" : \\\n     (status) == XRDP_DRDYNVC_STATUS_OPEN ? \"OPEN\" : \\\n     (status) == XRDP_DRDYNVC_STATUS_CLOSE_SENT ? \"CLOSE_SENT\" : \\\n     \"unknown\" \\\n    )\n\n#endif /* XRDP_CHANNEL_H */\n"
  },
  {
    "path": "libxrdp/xrdp_fastpath.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2014\n * Copyright (C) Idan Freiberg 2013-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n#include \"ms-rdpbcgr.h\"\n\n/*****************************************************************************/\nstruct xrdp_fastpath *\nxrdp_fastpath_create(struct xrdp_sec *owner, struct trans *trans)\n{\n    struct xrdp_fastpath *self;\n\n    self = (struct xrdp_fastpath *)g_malloc(sizeof(struct xrdp_fastpath), 1);\n    self->sec_layer = owner;\n    self->trans = trans;\n    self->session = owner->rdp_layer->session;\n\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_fastpath_delete(struct xrdp_fastpath *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n    g_free(self);\n}\n\n/*****************************************************************************/\nint\nxrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s)\n{\n    int fp_hdr;\n    int len = 0;\n    int byte;\n    char *holdp;\n\n\n    holdp = s->p;\n    if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPBCGR] TS_FP_INPUT_PDU\"))\n    {\n        return 1;\n    }\n    in_uint8(s, fp_hdr); /* fpInputHeader (1 byte) */\n    in_uint8(s, byte); /* length 1 (1 byte) */\n\n    self->numEvents = (fp_hdr & 0x3C) >> 2;\n    self->secFlags = (fp_hdr & 0xC0) >> 6;\n\n    if (byte & 0x80)\n    {\n        byte &= ~(0x80);\n        len = (byte << 8);\n\n        if (!s_check_rem_and_log(s, 1, \"Parsing [MS-RDPBCGR] TS_FP_INPUT_PDU length2\"))\n        {\n            return 1;\n        }\n        in_uint8(s, byte); /* length 2 (1 byte) */\n\n        len += byte;\n    }\n    else\n    {\n        len = byte;\n    }\n    s->next_packet = holdp + len;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPBCGR] TS_FP_INPUT_PDU \"\n              \"fpInputHeader.action (ignored), fpInputHeader.numEvents %d, \"\n              \"fpInputHeader.flags 0x%1.1x, length %d\",\n              self->numEvents, self->secFlags, len);\n    return 0;\n}\n\n/*****************************************************************************/\n/* no fragmentation */\nint\nxrdp_fastpath_init(struct xrdp_fastpath *self, struct stream *s)\n{\n    int bytes;\n\n    bytes = self->session->client_info->max_fastpath_frag_bytes;\n    if (bytes < 32 * 1024)\n    {\n        bytes = 32 * 1024;\n    }\n    init_stream(s, bytes);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_fastpath_session_callback(struct xrdp_fastpath *self, int msg,\n                               long param1, long param2,\n                               long param3, long param4)\n{\n    if (self->session->callback != 0)\n    {\n        /* msg_type can be\n          RDP_INPUT_SYNCHRONIZE - 0\n          RDP_INPUT_SCANCODE - 4\n          RDP_INPUT_MOUSE - 0x8001\n          RDP_INPUT_MOUSEX - 0x8002 */\n        /* call to xrdp_wm.c : callback */\n        self->session->callback(self->session->id, msg,\n                                param1, param2, param3, param4);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_WARNING, \"Bug: session is NULL\");\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* no fragmentation */\nint\nxrdp_fastpath_send(struct xrdp_fastpath *self, struct stream *s)\n{\n    if (trans_write_copy_s(self->trans, s) != 0)\n    {\n        return 1;\n    }\n    if (self->session->check_for_app_input)\n    {\n        xrdp_fastpath_session_callback(self, 0x5556, 0, 0, 0, 0);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Converts the fastpath keyboard event flags to slowpath event flags\n * @param fp_flags fastpath flags\n * @return slowpath flags\n *\n * See [MMS-RDPBCGR] 2.2.8.1.1.3.1.1.1 and 2.2.8.1.2.2.1\n */\nstatic int\nget_slowpath_keyboard_event_flags(int fp_flags)\n{\n    int flags = 0;\n\n    if (fp_flags & FASTPATH_INPUT_KBDFLAGS_RELEASE)\n    {\n        // Assume the key was down prior to this event - the fastpath\n        // message doesn't have a separate flag which maps to\n        // KBDFLAGS_DOWN\n        flags |= KBDFLAGS_DOWN | KBDFLAGS_RELEASE;\n    }\n    if (fp_flags & FASTPATH_INPUT_KBDFLAGS_EXTENDED)\n    {\n        flags |= KBDFLAGS_EXTENDED;\n    }\n    if (fp_flags & FASTPATH_INPUT_KBDFLAGS_EXTENDED1)\n    {\n        flags |= KBDFLAGS_EXTENDED1;\n    }\n\n    return flags;\n}\n\n/*****************************************************************************/\n/* FASTPATH_INPUT_EVENT_SCANCODE */\nstatic int\nxrdp_fastpath_process_EVENT_SCANCODE(struct xrdp_fastpath *self,\n                                     int eventFlags, struct stream *s)\n{\n    int flags;\n    int code;\n\n    if (!s_check_rem_and_log(s, 1, \"Parsing [MS-RDPBCGR] TS_FP_KEYBOARD_EVENT\"))\n    {\n        return 1;\n    }\n    in_uint8(s, code); /* keyCode (1 byte) */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_FP_KEYBOARD_EVENT \"\n              \"eventHeader.eventFlags 0x%2.2x, eventHeader.eventCode (ignored), \"\n              \"keyCode %d\", eventFlags, code);\n\n    flags = get_slowpath_keyboard_event_flags(eventFlags);\n\n    xrdp_fastpath_session_callback(self, RDP_INPUT_SCANCODE,\n                                   code, 0, flags, 0);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* FASTPATH_INPUT_EVENT_MOUSE */\nstatic int\nxrdp_fastpath_process_EVENT_MOUSE(struct xrdp_fastpath *self,\n                                  int eventFlags, struct stream *s)\n{\n    int pointerFlags;\n    int xPos;\n    int yPos;\n\n    /* eventFlags MUST be zeroed out */\n    if (eventFlags != 0)\n    {\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 2 + 2 + 2, \"Parsing [MS-RDPBCGR] TS_FP_POINTER_EVENT\"))\n    {\n        return 1;\n    }\n    in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */\n    in_uint16_le(s, xPos); /* xPos (2 bytes) */\n    in_uint16_le(s, yPos); /* yPos (2 bytes) */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_FP_POINTER_EVENT \"\n              \"eventHeader.eventFlags 0x00, eventHeader.eventCode (ignored), \"\n              \"pointerFlags 0x%4.4x, xPos %d, yPos %d\", pointerFlags, xPos, yPos);\n\n    xrdp_fastpath_session_callback(self, RDP_INPUT_MOUSE,\n                                   xPos, yPos, pointerFlags, 0);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* FASTPATH_INPUT_EVENT_MOUSEX */\nstatic int\nxrdp_fastpath_process_EVENT_MOUSEX(struct xrdp_fastpath *self,\n                                   int eventFlags, struct stream *s)\n{\n    int pointerFlags;\n    int xPos;\n    int yPos;\n\n    /* eventFlags MUST be zeroed out */\n    if (eventFlags != 0)\n    {\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 2 + 2 + 2,\n                             \"Parsing [MS-RDPBCGR] TS_FP_POINTERX_EVENT\"))\n    {\n        return 1;\n    }\n    in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */\n    in_uint16_le(s, xPos); /* xPos (2 bytes) */\n    in_uint16_le(s, yPos); /* yPos (2 bytes) */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_FP_POINTERX_EVENT \"\n              \"eventHeader.eventFlags 0x%2.2x, eventHeader.eventCode (ignored), \"\n              \"pointerFlags 0x%4.4x, xPos %d, yPos %d\",\n              eventFlags, pointerFlags, xPos, yPos);\n\n    xrdp_fastpath_session_callback(self, RDP_INPUT_MOUSEX,\n                                   xPos, yPos, pointerFlags, 0);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* FASTPATH_INPUT_EVENT_SYNC */\nstatic int\nxrdp_fastpath_process_EVENT_SYNC(struct xrdp_fastpath *self,\n                                 int eventFlags, struct stream *s)\n{\n    /*\n     * The eventCode bitfield (3 bits in size) MUST be set to\n     * FASTPATH_INPUT_EVENT_SYNC (3).\n     * The eventFlags bitfield (5 bits in size) contains flags\n     * indicating the \"on\"\n     * status of the keyboard toggle keys.\n     */\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_FP_SYNC_EVENT\"\n              \"eventHeader.eventFlags 0x%2.2x, eventHeader.eventCode (ignored), \",\n              eventFlags);\n\n    xrdp_fastpath_session_callback(self, RDP_INPUT_SYNCHRONIZE,\n                                   eventFlags, 0, 0, 0);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* FASTPATH_INPUT_EVENT_UNICODE */\nstatic int\nxrdp_fastpath_process_EVENT_UNICODE(struct xrdp_fastpath *self,\n                                    int eventFlags, struct stream *s)\n{\n    int flags;\n    int code;\n\n    if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPBCGR] TS_FP_UNICODE_KEYBOARD_EVENT\"))\n    {\n        return 1;\n    }\n    in_uint16_le(s, code); /* unicode (2 byte) */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_FP_UNICODE_KEYBOARD_EVENT\"\n              \"eventHeader.eventFlags 0x%2.2x, eventHeader.eventCode (ignored), \"\n              \"unicodeCode %d\",\n              eventFlags, code);\n\n    flags = get_slowpath_keyboard_event_flags(eventFlags);\n\n    xrdp_fastpath_session_callback(self, RDP_INPUT_UNICODE,\n                                   code, 0, flags, 0);\n    return 0;\n}\n\n/*****************************************************************************/\n/* FASTPATH_INPUT_EVENT */\nint\nxrdp_fastpath_process_input_event(struct xrdp_fastpath *self,\n                                  struct stream *s)\n{\n    int i;\n    int eventHeader;\n    int eventCode;\n    int eventFlags;\n\n    /* process fastpath input events */\n    for (i = 0; i < self->numEvents; i++)\n    {\n        if (!s_check_rem_and_log(s, 1, \"Parsing [MS-RDPBCGR] TS_FP_INPUT_EVENT eventHeader\"))\n        {\n            return 1;\n        }\n        in_uint8(s, eventHeader);\n\n        eventFlags = (eventHeader & 0x1F);\n        eventCode = (eventHeader >> 5);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_FP_INPUT_EVENT\"\n                  \"eventHeader.eventFlags 0x%2.2x, eventHeader.eventCode 0x%1.1x\",\n                  eventFlags, eventCode);\n\n        switch (eventCode)\n        {\n            case FASTPATH_INPUT_EVENT_SCANCODE:\n                if (xrdp_fastpath_process_EVENT_SCANCODE(self,\n                        eventFlags,\n                        s) != 0)\n                {\n                    return 1;\n                }\n                break;\n            case FASTPATH_INPUT_EVENT_MOUSE:\n                if (xrdp_fastpath_process_EVENT_MOUSE(self,\n                                                      eventFlags,\n                                                      s) != 0)\n                {\n                    return 1;\n                }\n                break;\n            case FASTPATH_INPUT_EVENT_MOUSEX:\n                if (xrdp_fastpath_process_EVENT_MOUSEX(self,\n                                                       eventFlags,\n                                                       s) != 0)\n                {\n                    return 1;\n                }\n                break;\n            case FASTPATH_INPUT_EVENT_SYNC:\n                if (xrdp_fastpath_process_EVENT_SYNC(self,\n                                                     eventFlags,\n                                                     s) != 0)\n                {\n                    return 1;\n                }\n                break;\n            case FASTPATH_INPUT_EVENT_UNICODE:\n                if (xrdp_fastpath_process_EVENT_UNICODE(self,\n                                                        eventFlags,\n                                                        s) != 0)\n                {\n                    return 1;\n                }\n                break;\n            default:\n                LOG(LOG_LEVEL_ERROR, \"xrdp_fastpath_process_input_event: \"\n                    \"unknown eventCode %d\", eventCode);\n                break;\n        }\n    }\n    return 0;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_iso.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n * Copyright (C) Idan Freiberg 2013-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * iso layer\n *\n * Note: [ITU-T X.224] and [ISO/IEC 8073] are essentially two specifications\n * of the same protocol (see [ITU-T X.224] Appendix I – Differences between\n * ITU-T Rec. X.224 (1993) and ISO/IEC 8073:1992). The RDP protocol\n * specification [MS-RDPBCGR] makes reference to the [ITU-T X.224] specificaiton.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"string_calls.h\"\n#include \"log.h\"\n\n\n/*****************************************************************************/\n/**\n * Converts a protocol mask ([MS-RDPBCGR] 2.2.1.1.1 to a string)\n *\n * @param protocol Protocol mask\n * @param buff Output buffer\n * @param bufflen total length of buff\n * @return As for snprintf()\n *\n * The string \"RDP\" is always added to the output, even if other bits\n * are set\n */\nstatic int\nprotocol_mask_to_str(int protocol, char *buff, int bufflen)\n{\n    char delim = '|';\n\n    static const struct bitmask_string bits[] =\n    {\n        { PROTOCOL_SSL, \"SSL\" },\n        { PROTOCOL_HYBRID, \"HYBRID\" },\n        { PROTOCOL_RDSTLS, \"RDSTLS\" },\n        { PROTOCOL_HYBRID_EX, \"HYBRID_EX\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    return g_bitmask_to_str(protocol, bits, delim, buff, bufflen);\n}\n\n/*****************************************************************************/\nstruct xrdp_iso *\nxrdp_iso_create(struct xrdp_mcs *owner, struct trans *trans)\n{\n    struct xrdp_iso *self;\n\n    self = (struct xrdp_iso *) g_malloc(sizeof(struct xrdp_iso), 1);\n    self->mcs_layer = owner;\n    self->trans = trans;\n\n    // See if we're running in vmconnect mode on this connection\n    struct xrdp_client_info *client_info = &(self->mcs_layer->sec_layer->rdp_layer->client_info);\n    if (client_info->vmconnect && trans->mode != TRANS_MODE_VSOCK)\n    {\n        char desc[MAX_PEER_DESCSTRLEN];\n        g_sck_get_peer_description(trans->sck, desc, sizeof(desc));\n        LOG(LOG_LEVEL_INFO, \"Disabling vmconnect mode for connection from %s\",\n            desc);\n        client_info->vmconnect = 0;\n    }\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_iso_delete(struct xrdp_iso *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_iso_negotiate_security(struct xrdp_iso *self)\n{\n    int rv = 0;\n    struct xrdp_client_info *client_info = &(self->mcs_layer->sec_layer->rdp_layer->client_info);\n    char protostr[64];\n    int got_protocol = 0;\n    int security_type_mask;\n\n    /* Map the configuration from xrdp.ini to a mask of allowed\n     * security types ([MS-RDPBCGR] 2.2.1.2.1)\n     *\n     * There's some oddness around PROTOCOL_RDP. This value is 0,\n     * for compatibility reasons, and it's OK for the server to\n     * suggest RDP as the fallback protocol if nothing else is\n     * agreed on. Nowadays, classic RDP security should\n     * not be used, if at all avoidable */\n\n    /* At present we only support SSL and RDP security */\n    if (client_info->security_layer == SECURITY_LAYER_RDP)\n    {\n        security_type_mask = PROTOCOL_RDP;\n    }\n    else\n    {\n        security_type_mask = PROTOCOL_SSL;\n    }\n    /* But VMConnect mode supports everything. */\n    if (client_info->vmconnect)\n    {\n        security_type_mask |= PROTOCOL_HYBRID | PROTOCOL_HYBRID_EX;\n    }\n\n    /* Logically 'and' this value with the mask requested by the client, and\n     * see what's left */\n    protocol_mask_to_str(self->requestedProtocol, protostr, sizeof(protostr));\n    LOG(LOG_LEVEL_INFO, \"Client requested security types (RDP assumed) : %s\",\n        protostr);\n    security_type_mask &= self->requestedProtocol;\n\n    if (security_type_mask & PROTOCOL_HYBRID_EX)\n    {\n        /* Currently supported by VMConnect mode only */\n        LOG(LOG_LEVEL_INFO, \"Selected HYBRID_EX security\");\n        self->selectedProtocol = PROTOCOL_HYBRID_EX;\n        got_protocol = 1;\n    }\n    else if (security_type_mask & PROTOCOL_HYBRID)\n    {\n        /* Currently supported by VMConnect mode only */\n        LOG(LOG_LEVEL_INFO, \"Selected HYBRID security\");\n        self->selectedProtocol = PROTOCOL_HYBRID;\n        got_protocol = 1;\n    }\n    else if ((security_type_mask & PROTOCOL_SSL) != 0)\n    {\n        /* Can we do TLS? (basic check). VMConnect is exempt. */\n        if ((g_file_readable(client_info->certificate) &&\n                g_file_readable(client_info->key_file)) || client_info->vmconnect)\n        {\n            LOG(LOG_LEVEL_INFO, \"Selected TLS security\");\n            self->selectedProtocol = PROTOCOL_SSL;\n            got_protocol = 1;\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING, \"Cannot accept TLS connections because \"\n                \"certificate or private key file is not readable. \"\n                \"certificate file: [%s], private key file: [%s]\",\n                client_info->certificate, client_info->key_file);\n\n            /* If we're configured to ONLY use TLS, this is a problem.\n             * If not, we can fall back to RDP */\n            if (client_info->security_layer == SECURITY_LAYER_TLS)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"Server requires TLS (security_layer=tls)\");\n                self->failureCode = SSL_CERT_NOT_ON_SERVER;\n                rv = 1;\n            }\n        }\n    }\n    else if (client_info->security_layer == SECURITY_LAYER_TLS)\n    {\n        /* We don't have a match on TLS, but we'll accept nothing less */\n        LOG(LOG_LEVEL_ERROR, \"Server requires TLS (security_layer=tls)\");\n        self->failureCode = SSL_REQUIRED_BY_SERVER;\n        rv = 1;\n    }\n\n    /* If we haven't got a match so far, and we haven't got a fail,\n     * try RDP */\n    if (!got_protocol && !rv)\n    {\n        if (g_fips_mode_enabled())\n        {\n            /* This is a FIPS-mode machine, and we don't support classic RDP\n             * encryption */\n            LOG(LOG_LEVEL_ERROR,\n                \"Server in FIPS mode requires TLS for security\");\n            self->failureCode = SSL_REQUIRED_BY_SERVER;\n            rv = 1; /* error */\n        }\n        else\n        {\n            self->selectedProtocol = PROTOCOL_RDP;\n            LOG(LOG_LEVEL_INFO, \"Selected classic RDP security\");\n            LOG(LOG_LEVEL_WARNING, \"Classic RDP security is not secure -\"\n                \" please configure TLS on the client and server\");\n            got_protocol = 1;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] RDP_NEG_REQ message.\n * returns error\n */\nstatic int\nxrdp_iso_process_rdp_neg_req(struct xrdp_iso *self, struct stream *s)\n{\n    int flags;\n    int len;\n\n    if (!s_check_rem_and_log(s, 7, \"Parsing [MS-RDPBCGR] RDP_NEG_REQ\"))\n    {\n        return 1;\n    }\n\n    /* The type field has already been read to determine that this function\n       should be called */\n    in_uint8(s, flags); /* flags */\n    if ((flags & 0x0000000b) != flags)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Unsupported [MS-RDPBCGR] RDP_NEG_REQ flags: 0x%2.2x\", flags);\n        return 1;\n    }\n\n    /* If both flags are set, it means 'OR', so fail only if only the one is set. */\n    if ((flags & REDIRECTED_AUTHENTICATION_MODE_REQUIRED) && !(flags & RESTRICTED_ADMIN_MODE_REQUIRED))\n    {\n        LOG(LOG_LEVEL_ERROR, \"[MS-RDPBCGR] RDP_NEG_REQ: RemoteGuard isn't supported !\");\n        return 1;\n    }\n\n    in_uint16_le(s, len); /* length */\n    if (len != 8)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Protocol error: [MS-RDPBCGR] RDP_NEG_REQ length must be 8, \"\n            \"received %d\", len);\n        return 1;\n    }\n\n    in_uint32_le(s, self->requestedProtocol); /* requestedProtocols */\n\n    /* TODO: why is requestedProtocols flag value bigger than 0xb invalid? */\n    if (self->requestedProtocol > 0xb)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Unknown requested protocol flag [MS-RDPBCGR] RDP_NEG_REQ, \"\n            \"requestedProtocol 0x%8.8x\", self->requestedProtocol);\n        return 1;\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received struct [MS-RDPBCGR] RDP_NEG_REQ \"\n              \"flags 0x%2.2x, length 8, requestedProtocol 0x%8.8x\",\n              flags, self->requestedProtocol);\n\n    return 0;\n}\n/*****************************************************************************\n * Reads an X.224 PDU (X.224 section 13) preceded by a T.123 TPKT\n * header (T.123 section 8)\n *\n * On entry, the TPKT header length field will have been inspected and used to\n * set up the input stream.\n *\n * On exit, the TPKT header and the fixed part of the PDU header will have been\n * removed from the stream.\n *\n * @param s [in]\n * @param code [out]\n * @param len [out]\n * Returns error\n *****************************************************************************/\nstatic int\nxrdp_iso_recv_msg(struct xrdp_iso *self, struct stream *s, int *code, int *len)\n{\n    int ver;\n\n    *code = 0;\n    *len = 0;\n\n    if (s != self->trans->in_s)\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"Bug: the input stream is not the same stream as the \"\n            \"transport input stream\");\n    }\n\n    /* [ITU-T T.123] TPKT header is 4 bytes, then first 2 bytes of the X.224 CR-TPDU */\n    if (!s_check_rem_and_log(s, 6,\n                             \"Parsing [ITU-T T.123] TPKT header and [ITU-T X.224] TPDU header\"))\n    {\n        return 1;\n    }\n\n    /* [ITU-T T.123] TPKT header */\n    in_uint8(s, ver); /* version */\n    in_uint8s(s, 3); /* Skip reserved field (1 byte), plus length (2 bytes) */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [ITU-T T.123] TPKT \"\n              \"version %d, length (ignored)\", ver);\n\n    /* [ITU-T X.224] TPDU header */\n    in_uint8(s, *len);  /* LI (length indicator) */\n    in_uint8(s, *code); /* TPDU code */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [ITU-T X.224] TPDU \"\n              \"length indicator %d, TDPU code 0x%2.2x\", *len, *code);\n\n    if (ver != 3)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Unsupported [ITU-T T.123] TPKT header version: %d\", ver);\n        LOG_DEVEL_HEXDUMP(LOG_LEVEL_ERROR, \"[ITU-T T.123] TPKT header\", s->data, 4);\n        return 1;\n    }\n\n    if (*len == 255)\n    {\n        /* X.224 13.2.1 - reserved value */\n        LOG(LOG_LEVEL_ERROR,\n            \"[ITU-T X.224] TPDU header: unsupported use of reserved length value\");\n        LOG_DEVEL_HEXDUMP(LOG_LEVEL_ERROR, \"[ITU-T X.224] TPDU header\", s->data + 4, 4);\n        return 1;\n    }\n\n    if (*code == ISO_PDU_DT)\n    {\n        /* Data PDU : X.224 13.7 class 0 */\n        if (!s_check_rem_and_log(s, 1, \"Parsing [ITU-T X.224] DT-TPDU (Data) header\"))\n        {\n            return 1;\n        }\n        in_uint8s(s, 1); /* EOT (End of TSDU Mark) (upper 1 bit) and\n                            TPDU-NR (Data TPDU Number) (lower 7 bits) */\n    }\n    else\n    {\n        /* Other supported X.224 class 0 PDUs all have 5 bytes remaining\n           in the fixed header :\n            CR Connection request (13.3)\n            CC Connection confirm (13.4)\n            DR Disconnect request (13.5) */\n        if (!s_check_rem_and_log(s, 5, \"Parsing [ITU-T X.224] Other PDU header\"))\n        {\n            return 1;\n        }\n        in_uint8s(s, 5); /* DST-REF (2 bytes)\n                            SRC-REF (2 bytes)\n                            [CR, CC] CLASS OPTION (1 byte) or [DR] REASON (1 byte) */\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Process the header of a [ITU-T X.224] DT-TPDU (Data) message.\n *\n * returns error\n */\nint\nxrdp_iso_recv(struct xrdp_iso *self, struct stream *s)\n{\n    int code;\n    int len;\n\n    if (xrdp_iso_recv_msg(self, s, &code, &len) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_iso_recv: xrdp_iso_recv_msg failed\");\n        return 1;\n    }\n\n    if (code != ISO_PDU_DT || len != 2)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_iso_recv only supports processing \"\n            \"[ITU-T X.224] DT-TPDU (Data) headers. Received TPDU header: \"\n            \"length indicator %d, TDPU code 0x%2.2x\", len, code);\n        return 1;\n    }\n\n    return 0;\n}\n/*****************************************************************************/\n/*\n * Send a [ITU-T X.224] CC-TPDU (Connection Confirm) message with\n * [ITU-T T.123] TPKT header.\n *\n * returns error\n */\nstatic int\nxrdp_iso_send_cc(struct xrdp_iso *self)\n{\n    struct stream *s;\n    char *holdp;\n    char *len_ptr;\n    char *len_indicator_ptr;\n    char flags;\n    int len;\n    int len_indicator;\n\n    struct xrdp_client_info *client_info = &(self->mcs_layer->sec_layer->rdp_layer->client_info);\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    holdp = s->p;\n    /* [ITU-T T.123] TPKT header */\n    out_uint8(s, 3); /* version */\n    out_uint8(s, 0); /* reserved (padding) */\n    len_ptr = s->p;\n    out_uint16_be(s, 0); /* length, set later */\n\n    /* [ITU-T X.224] CC-TPDU */\n    len_indicator_ptr = s->p;\n    out_uint8(s, 0);          /* length indicator, set later */\n    out_uint8(s, ISO_PDU_CC); /* Connection Confirm PDU */\n    out_uint16_be(s, 0);      /* DST-REF */\n    out_uint16_be(s, 0x1234); /* SRC-REF */\n    out_uint8(s, 0);          /* CLASS OPTION */\n\n    /* [MS-RDPBCGR] 2.2.1.2 rdpNegData */\n    if (self->rdpNegData)\n    {\n        if (self->failureCode)\n        {\n            /* [MS-RDPBCGR] RDP_NEG_FAILURE */\n            out_uint8(s, RDP_NEG_FAILURE);       /* type*/\n            out_uint8(s, 0);                     /* flags (none) */\n            out_uint16_le(s, 8);                 /* length (must be 8) */\n            out_uint32_le(s, self->failureCode); /* failureCode */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding structure [MS-RDPBCGR] RDP_NEG_FAILURE \"\n                      \"flags 0, length 8, failureCode 0x%8.8x\", self->failureCode);\n        }\n        else\n        {\n            flags = EXTENDED_CLIENT_DATA_SUPPORTED;\n\n            if (client_info->vmconnect)\n            {\n                /* NLA is handled by the host and not us. */\n                flags |= RESTRICTED_ADMIN_MODE_SUPPORTED;\n            }\n\n            /* [MS-RDPBCGR] RDP_NEG_RSP */\n            out_uint8(s, RDP_NEG_RSP);                    /* type*/\n            out_uint8(s, flags);                          /* flags */\n            out_uint16_le(s, 8);                          /* length (must be 8) */\n            out_uint32_le(s, self->selectedProtocol);     /* selectedProtocol */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding structure [MS-RDPBCGR] RDP_NEG_RSP \"\n                      \"flags 0x%02x, length 8, selectedProtocol 0x%8.8x\",\n                      EXTENDED_CLIENT_DATA_SUPPORTED,\n                      self->selectedProtocol);\n        }\n    }\n    s_mark_end(s);\n\n    len = (int) (s->end - holdp);\n    len_indicator = (int) (s->end - len_indicator_ptr) - 1;\n    len_ptr[0] = len >> 8;\n    len_ptr[1] = len;\n    len_indicator_ptr[0] = len_indicator;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [ITU-T T.123] TPKT \"\n              \"version 3, length %d\", len);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [ITU-T X.224] CC-TPDU (Connection Confirm) \"\n              \"length indicator %d, DST-REF 0, SRC-REF 0, CLASS OPTION 0\",\n              len_indicator);\n\n    if (trans_write_copy_s(self->trans, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Sending [ITU-T X.224] CC-TPDU (Connection Confirm) failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n/*****************************************************************************\n * Process an X.224 connection request PDU\n *\n * See MS-RDPBCGR v20190923 sections 2.2.1.1 and 3.3.5.3.1.\n *\n * From the latter, in particular:-\n * - The length embedded in the TPKT header MUST be examined for\n *   consistency with the received data. If there is a discrepancy, the\n *   connection SHOULD be dropped\n * - If the optional routingToken field exists it MUST be ignored.\n * - If the optional cookie field is present it MUST be ignored.\n * - If both the routingToken and cookie fields are present, the server\n *   SHOULD continue with the connection.\n *****************************************************************************/\n/* returns error */\nint\nxrdp_iso_incoming(struct xrdp_iso *self)\n{\n    int rv = 0;\n    int code;\n    int len;\n    int cc_type;\n    struct stream *s;\n    int expected_pdu_len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"[ITU-T X.224] Connection Sequence: receive connection request\");\n    s = libxrdp_force_read(self->trans);\n    if (s == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[ITU-T X.224] Connection Sequence: CR-TPDU (Connection Request) failed\");\n        return 1;\n    }\n\n    if (xrdp_iso_recv_msg(self, s, &code, &len) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[ITU-T X.224] Connection Sequence: CR-TPDU (Connection Request) failed\");\n        return 1;\n    }\n\n    if (code != ISO_PDU_CR)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_iso_incoming only supports processing \"\n            \"[ITU-T X.224] CR-TPDU (Connection Request) headers. \"\n            \"Received TPDU header: length indicator %d, TDPU code 0x%2.2x\",\n            len, code);\n        return 1;\n    }\n\n    /*\n     * Make sure the length indicator field extracted from the X.224\n     * connection request TPDU corresponds to the length in the TPKT header.\n     *\n     * We do this by seeing how the indicator field minus the counted\n     * octets in the TPDU header (6) compares with the space left in\n     * the stream.\n     */\n    expected_pdu_len = (s->end - s->p) + 6;\n    if (len != expected_pdu_len)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Invalid length indicator in [ITU-T X.224] CR-TPDU (Connection Request). \"\n            \"expected %d, received %d\",\n            expected_pdu_len, len);\n        return 1;\n    }\n\n    /* process connection request [MS-RDPBCGR] 2.2.1.1 */\n    while (s_check_rem(s, 1))\n    {\n        in_uint8(s, cc_type); /* type or 'C' */\n        switch (cc_type)\n        {\n            default:\n                LOG_DEVEL(LOG_LEVEL_WARNING,\n                          \"Ignoring unknown structure type in [ITU-T X.224] CR-TPDU (Connection Request). \"\n                          \"type 0x%2.2x\", cc_type);\n                break;\n            case RDP_NEG_REQ: /* rdpNegReq 1 */\n                self->rdpNegData = 1;\n                if (xrdp_iso_process_rdp_neg_req(self, s) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"[ITU-T X.224] Connection Sequence: failed\");\n                    return 1;\n                }\n                break;\n            case RDP_CORRELATION_INFO: /* rdpCorrelationInfo 6 */\n                // TODO\n                if (!s_check_rem_and_log(s, 1 + 2 + 16 + 16,\n                                         \"Parsing [MS-RDPBCGR] RDP_NEG_CORRELATION_INFO\"))\n                {\n                    return 1;\n                }\n\n                in_uint8s(s, 1 + 2 + 16 + 16);\n                LOG_DEVEL(LOG_LEVEL_TRACE,\n                          \"Received struct [MS-RDPBCGR] RDP_NEG_CORRELATION_INFO \"\n                          \"(all fields ignored)\");\n                break;\n            case 'C': /* Cookie or routingToken */\n                /* The routingToken and cookie fields are both ASCII\n                 * strings starting with the word 'Cookie: ' and\n                 * ending with CR+LF. We ignore both, so we do\n                 * not need to distinguish them  */\n                while (s_check_rem(s, 1))\n                {\n                    in_uint8(s, cc_type);\n                    if (cc_type == 0x0D && s_check_rem(s, 1))\n                    {\n                        in_uint8(s, cc_type);\n                        if (cc_type == 0x0A)\n                        {\n                            break;\n                        }\n                    }\n                }\n                LOG_DEVEL(LOG_LEVEL_TRACE,\n                          \"Received struct [MS-RDPBCGR] routingToken or cookie \"\n                          \"(ignored)\");\n                break;\n        }\n    }\n\n    /* negotiate client-server security layer */\n    rv = xrdp_iso_negotiate_security(self);\n\n    /* send connection confirm back to client */\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"[ITU-T X.224] Connection Sequence: send connection confirmation\");\n    if (xrdp_iso_send_cc(self) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[ITU-T X.224] Connection Sequence: send connection confirmation failed\");\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"[ITU-T X.224] Connection Sequence: completed\");\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_iso_init(struct xrdp_iso *self, struct stream *s)\n{\n    init_stream(s, 8192 * 4); /* 32 KB */\n    s_push_layer(s, iso_hdr, 7);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Sends a message with the [ITU-T T.123] TPKT header (T.123 section 8) and\n * [ITU-T X.224] DT-TPDU (Data) header (X.224 section 13)\n * returns error\n */\nint\nxrdp_iso_send(struct xrdp_iso *self, struct stream *s)\n{\n    int len;\n\n    s_pop_layer(s, iso_hdr);\n    len = (int) (s->end - s->p);\n    /* [ITU-T T.123] TPKT header */\n    out_uint8(s, 3);       /* version */\n    out_uint8(s, 0);       /* reserved (padding) */\n    out_uint16_be(s, len); /* length */\n\n    /* [ITU-T X.224] DT-TPDU (Data) header */\n    out_uint8(s, 2);          /* LI (length indicator) */\n    out_uint8(s, ISO_PDU_DT); /* TPDU code */\n    out_uint8(s, 0x80);       /* EOT (End of TSDU Mark) (upper 1 bit) and\n                                 TPDU-NR (Data TPDU Number) (lower 7 bits) */\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [ITU-T T.123] TPKT \"\n              \"version 3, length %d\", len);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [ITU-T X.224] DT-TPDU (Data) \"\n              \"length indicator 2, TPDU code 0x%2.2x, EOT 1, TPDU-NR 0x00\",\n              ISO_PDU_DT);\n\n    if (trans_write_copy_s(self->trans, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_iso_send: trans_write_copy_s failed\");\n        return 1;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_jpeg_compress.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * jpeg compressor\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n\n#if defined(XRDP_TJPEG)\n\n/* turbo jpeg */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <turbojpeg.h>\n#include \"log.h\"\n\n/*****************************************************************************/\nint\nxrdp_jpeg_compress(void *handle, char *in_data, int width, int height,\n                   struct stream *s, int bpp, int byte_limit,\n                   int start_line, struct stream *temp_s,\n                   int e, int quality)\n{\n    int error;\n    int i;\n    int j;\n    unsigned int pixel;\n    unsigned int *src32;\n    unsigned int *dst32;\n    unsigned long cdata_bytes;\n    unsigned char *src_buf;\n    unsigned char *dst_buf;\n    char *temp_buf;\n    tjhandle tj_han;\n\n    if (bpp != 24)\n    {\n        LOG(LOG_LEVEL_WARNING, \"xrdp_jpeg_compress: bpp wrong %d\", bpp);\n        return height;\n    }\n    if (handle == 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"xrdp_jpeg_compress: handle is nil\");\n        return height;\n    }\n    tj_han = (tjhandle) handle;\n    cdata_bytes = byte_limit;\n    src_buf = (unsigned char *) in_data;\n    dst_buf = (unsigned char *) (s->p);\n    temp_buf = 0;\n    if (e == 0)\n    {\n        src_buf = (unsigned char *)in_data;\n    }\n    else\n    {\n        temp_buf = (char *) g_malloc((width + e) * height * 4, 0);\n        dst32 = (unsigned int *) temp_buf;\n        src32 = (unsigned int *) in_data;\n        for (j = 0; j < height; j++)\n        {\n            for (i = 0; i < width; i++)\n            {\n                pixel = *src32;\n                src32++;\n                *dst32 = pixel;\n                dst32++;\n            }\n            if (width > 0)\n            {\n                for (i = 0; i < e; i++)\n                {\n                    *dst32 = pixel;\n                    dst32++;\n                }\n            }\n        }\n        src_buf = (unsigned char *) temp_buf;\n    }\n    dst_buf = (unsigned char *)(s->p);\n    error = tjCompress(tj_han, src_buf, width + e, (width + e) * 4, height,\n                       TJPF_XBGR, dst_buf, &cdata_bytes,\n                       TJSAMP_420, quality, 0);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_jpeg_compress: tjCompress error: %s\",\n            tjGetErrorStr());\n    }\n\n    s->p += cdata_bytes;\n    g_free(temp_buf);\n    return height;\n}\n\n/**\n * Compress a rectangular area (aka inner rectangle) inside our\n * frame buffer (inp_data)\n *****************************************************************************/\n\nint\nxrdp_codec_jpeg_compress(void *handle,\n                         int   format,   /* input data format */\n                         char *inp_data, /* input data */\n                         int   width,    /* width of inp_data */\n                         int   height,   /* height of inp_data */\n                         int   stride,   /* inp_data stride, in bytes*/\n                         int   x,        /* x loc in inp_data */\n                         int   y,        /* y loc in inp_data */\n                         int   cx,       /* width of area to compress */\n                         int   cy,       /* height of area to compress */\n                         int   quality,  /* higher numbers compress less */\n                         char *out_data, /* dest for jpg image */\n                         int  *io_len    /* length of out_data and on return */\n                         /* len of compressed data */\n                        )\n{\n    tjhandle       tj_han;\n    int            error;\n    int            bpp;\n    char          *src_ptr;\n    unsigned long  lio_len;\n\n    /*\n     * note: for now we assume that format is always XBGR and ignore format\n     */\n\n    if (handle == 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"xrdp_codec_jpeg_compress: handle is nil\");\n        return height;\n    }\n\n    tj_han = (tjhandle) handle;\n\n    /* get bytes per pixel */\n    bpp = stride / width;\n\n    /* start of inner rect in inp_data */\n    src_ptr = inp_data + (y * stride + x * bpp);\n\n    lio_len = *io_len;\n    /* compress inner rect */\n\n    /* notes\n     * TJPF_RGB no works, zero bytes\n     * TJPF_BGR no works, not zero but no open\n     * TJPF_RGBX no works, zero bytes\n     * TJPF_BGRX no works, off scaled image\n     * TJPF_XBGR works\n     * TJPF_XRGB no works, zero bytes\n     * TJPF_RGBA no works, zero bytes\n     * TJPF_BGRA no works, zero bytes\n     * TJPF_ABGR no works, zero bytes\n     * TJPF_ARGB no works, zero bytes */\n\n    error = tjCompress(tj_han,     /* opaque handle */\n                       (unsigned char *) src_ptr,    /* source buf */\n                       cx,         /* width of area to compress */\n                       stride,     /* pitch */\n                       cy,         /* height of area to compress */\n                       TJPF_XBGR,  /* pixel size */\n                       (unsigned char *) out_data,   /* dest buf */\n                       &lio_len,   /* inner_buf length & compressed_size */\n                       TJSAMP_420, /* jpeg sub sample */\n                       quality,    /* jpeg quality */\n                       0           /* flags */\n                      );\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_codec_jpeg_compress: tjCompress error: %s\",\n            tjGetErrorStr());\n    }\n\n    *io_len = lio_len;\n    return height;\n}\n\n/*****************************************************************************/\nvoid *\nxrdp_jpeg_init(void)\n{\n    tjhandle tj_han;\n\n    tj_han = tjInitCompress();\n    return tj_han;\n}\n\n/*****************************************************************************/\nint\nxrdp_jpeg_deinit(void *handle)\n{\n    tjhandle tj_han;\n\n    if (handle == 0)\n    {\n        return 0;\n    }\n    tj_han = (tjhandle) handle;\n    tjDestroy(tj_han);\n    return 0;\n}\n\n#elif defined(XRDP_JPEG)\n\n/* libjpeg */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <jpeglib.h>\n\n#define JP_QUALITY 75\n\nstruct mydata_comp\n{\n    JOCTET *cb;\n    int cb_bytes;\n    int total_done;\n    int overwrite;\n};\n\n/*****************************************************************************/\n/* called at beginning */\nstatic void\nmy_init_destination(j_compress_ptr cinfo)\n{\n    struct mydata_comp *md;\n\n    md = (struct mydata_comp *)(cinfo->client_data);\n    md->total_done = 0;\n    md->overwrite = 0;\n    cinfo->dest->next_output_byte = md->cb;\n    cinfo->dest->free_in_buffer = md->cb_bytes;\n}\n\n/*****************************************************************************/\n/* called when buffer is full and we need more space */\nstatic int\nmy_empty_output_buffer(j_compress_ptr cinfo)\n{\n    struct mydata_comp *md;\n    int chunk_bytes;\n\n    md = (struct mydata_comp *)(cinfo->client_data);\n    chunk_bytes = md->cb_bytes;\n    md->total_done += chunk_bytes;\n    cinfo->dest->next_output_byte = md->cb;\n    cinfo->dest->free_in_buffer = md->cb_bytes;\n    md->overwrite = 1;\n    return 1;\n}\n\n/*****************************************************************************/\n/* called at end */\nstatic void\nmy_term_destination(j_compress_ptr cinfo)\n{\n    struct mydata_comp *md;\n    int chunk_bytes;\n\n    md = (struct mydata_comp *)(cinfo->client_data);\n    chunk_bytes = md->cb_bytes - cinfo->dest->free_in_buffer;\n    md->total_done += chunk_bytes;\n}\n\n/*****************************************************************************/\nstatic int\njp_do_compress(JOCTET *data, int width, int height, int bpp, int quality,\n               JOCTET *comp_data, int *comp_data_bytes)\n{\n    struct jpeg_compress_struct cinfo;\n    struct jpeg_error_mgr jerr;\n    struct jpeg_destination_mgr dst_mgr;\n    struct mydata_comp md;\n    JSAMPROW row_pointer[4];\n    int Bpp;\n\n    Bpp = (bpp + 7) / 8;\n    memset(&cinfo, 0, sizeof(cinfo));\n    cinfo.err = jpeg_std_error(&jerr);\n    jpeg_create_compress(&cinfo);\n    memset(&md, 0, sizeof(md));\n    md.cb = comp_data,\n    md.cb_bytes = *comp_data_bytes;\n    cinfo.client_data = &md;\n    memset(&dst_mgr, 0, sizeof(dst_mgr));\n    dst_mgr.init_destination = my_init_destination;\n    dst_mgr.empty_output_buffer = my_empty_output_buffer;\n    dst_mgr.term_destination = my_term_destination;\n    cinfo.dest = &dst_mgr;\n    cinfo.image_width = width;\n    cinfo.image_height = height;\n    cinfo.input_components = Bpp;\n    cinfo.in_color_space = JCS_RGB;\n    jpeg_set_defaults(&cinfo);\n    cinfo.num_components = 3;\n    cinfo.dct_method = JDCT_FLOAT;\n    jpeg_set_quality(&cinfo, quality, 1);\n    jpeg_start_compress(&cinfo, 1);\n\n    while (cinfo.next_scanline + 3 < cinfo.image_height)\n    {\n        row_pointer[0] = data;\n        data += width * Bpp;\n        row_pointer[1] = data;\n        data += width * Bpp;\n        row_pointer[2] = data;\n        data += width * Bpp;\n        row_pointer[3] = data;\n        data += width * Bpp;\n        jpeg_write_scanlines(&cinfo, row_pointer, 4);\n    }\n\n    while (cinfo.next_scanline < cinfo.image_height)\n    {\n        row_pointer[0] = data;\n        data += width * Bpp;\n        jpeg_write_scanlines(&cinfo, row_pointer, 1);\n    }\n\n    jpeg_finish_compress(&cinfo);\n    *comp_data_bytes = md.total_done;\n    jpeg_destroy_compress(&cinfo);\n\n    if (md.overwrite)\n    {\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\njpeg_compress(char *in_data, int width, int height,\n              struct stream *s, struct stream *temp_s, int bpp,\n              int byte_limit, int e, int quality)\n{\n    JOCTET *data;\n    tui32 *src32;\n    tui8 *dst8;\n    tui32 pixel;\n    int red;\n    int blue;\n    int green;\n    int j;\n    int i;\n    int cdata_bytes;\n\n    data = (JOCTET *) temp_s->data;\n    dst8 = data;\n\n    if (bpp == 24)\n    {\n        src32 = (tui32 *)in_data;\n\n        for (j = 0; j < height; j++)\n        {\n            for (i = 0; i < width; i++)\n            {\n                pixel = src32[i + j * width];\n                SPLITCOLOR32(red, green, blue, pixel);\n                *(dst8++) = blue;\n                *(dst8++) = green;\n                *(dst8++) = red;\n            }\n\n            if (width > 0)\n            {\n                for (i = 0; i < e; i++)\n                {\n                    *(dst8++) = blue;\n                    *(dst8++) = green;\n                    *(dst8++) = red;\n                }\n            }\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"bpp wrong %d\", bpp);\n    }\n\n    cdata_bytes = byte_limit;\n    jp_do_compress(data, width + e, height, 24, quality, (JOCTET *) s->p,\n                   &cdata_bytes);\n    s->p += cdata_bytes;\n    return cdata_bytes;\n}\n\n/*****************************************************************************/\nint\nxrdp_jpeg_compress(void *handle, char *in_data, int width, int height,\n                   struct stream *s, int bpp, int byte_limit,\n                   int start_line, struct stream *temp_s,\n                   int e, int quality)\n{\n    jpeg_compress(in_data, width, height, s, temp_s, bpp, byte_limit,\n                  e, quality);\n    return height;\n}\n\n/*****************************************************************************/\nint\nxrdp_codec_jpeg_compress(void *handle, int format, char *inp_data, int width,\n                         int height, int stride, int x, int y, int cx, int cy,\n                         int quality, char *out_data, int *io_len)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nvoid *\nxrdp_jpeg_init(void)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_jpeg_deinit(void *handle)\n{\n    return 0;\n}\n\n#else\n\n/*****************************************************************************/\nint\nxrdp_jpeg_compress(void *handle, char *in_data, int width, int height,\n                   struct stream *s, int bpp, int byte_limit,\n                   int start_line, struct stream *temp_s,\n                   int e, int quality)\n{\n    return height;\n}\n\n/*****************************************************************************/\nint\nxrdp_codec_jpeg_compress(void *handle, int format, char *inp_data, int width,\n                         int height, int stride, int x, int y, int cx, int cy,\n                         int quality, char *out_data, int *io_len)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nvoid *\nxrdp_jpeg_init(void)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_jpeg_deinit(void *handle)\n{\n    return 0;\n}\n\n#endif\n"
  },
  {
    "path": "libxrdp/xrdp_mcs.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * mcs layer which implements the Multipoint Communication Service protocol as\n * specified in [ITU-T T.125]\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"log.h\"\n\n/* Forward references */\nstatic int\nhandle_channel_join_requests(struct xrdp_mcs *self,\n                             struct stream *s, int *appid);\n\n/*****************************************************************************/\nstruct xrdp_mcs *\nxrdp_mcs_create(struct xrdp_sec *owner, struct trans *trans,\n                struct stream *client_mcs_data,\n                struct stream *server_mcs_data)\n{\n    struct xrdp_mcs *self;\n\n    self = (struct xrdp_mcs *)g_malloc(sizeof(struct xrdp_mcs), 1);\n    self->sec_layer = owner;\n    self->userid = 1;\n    self->chanid = 1001;\n    self->client_mcs_data = client_mcs_data;\n    self->server_mcs_data = server_mcs_data;\n    self->iso_layer = xrdp_iso_create(self, trans);\n    self->channel_list = list_create();\n\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_mcs_delete(struct xrdp_mcs *self)\n{\n    struct mcs_channel_item *channel_item;\n    int index;\n    int count;\n\n    if (self == 0)\n    {\n        return;\n    }\n\n    /* here we have to free the channel items and anything in them */\n    count = self->channel_list->count;\n\n    for (index = count - 1; index >= 0; index--)\n    {\n        channel_item = (struct mcs_channel_item *)\n                       list_get_item(self->channel_list, index);\n        g_free(channel_item);\n    }\n\n    list_delete(self->channel_list);\n\n    xrdp_iso_delete(self->iso_layer);\n    /* make sure we get null pointer exception if struct is used again. */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mcs_delete processed\");\n    g_memset(self, 0, sizeof(struct xrdp_mcs)) ;\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* Send an [ITU-T T.125] DomainMCSPDU message with type ChannelJoinConfirm */\n/* returns error = 1 ok = 0 */\nstatic int\nxrdp_mcs_send_cjcf(struct xrdp_mcs *self, int userid, int chanid)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_iso_init(self->iso_layer, s) != 0)\n    {\n        free_stream(s);\n        LOG(LOG_LEVEL_ERROR, \"xrdp_mcs_send_cjcf: xrdp_iso_init failed\");\n        return 1;\n    }\n\n    /* The DomainMCSPDU choice index is a 6-bit int with the next bit as the\n       bit field of the two optional fields in the struct (channelId, nonStandard)\n    */\n    out_uint8(s, (MCS_CJCF << 2) | 0x02); /* DomainMCSPDU choice index,\n                                             channelId field is present,\n                                             nonStandard field is not present */\n    out_uint8(s, 0); /* result choice index 0 = rt-successful */\n    out_uint16_be(s, userid); /* initiator */\n    out_uint16_be(s, chanid); /* requested */\n    out_uint16_be(s, chanid); /* channelId (OPTIONAL) */\n    s_mark_end(s);\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [ITU-T T.125] ChannelJoinConfirm \"\n              \"result SUCCESS, initiator %d, requested %d, \"\n              \"channelId %d\",  userid, chanid, chanid);\n    if (xrdp_iso_send(self->iso_layer, s) != 0)\n    {\n        free_stream(s);\n        LOG(LOG_LEVEL_ERROR, \"Sening [ITU-T T.125] ChannelJoinConfirm failed\");\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Reads the header of a DomainMCSPDU and gets the appid\n *\n * @return 0 for success */\nstatic int\nget_domain_mcs_pdu_header(struct xrdp_mcs *self, struct stream *s, int *appid)\n{\n    int opcode;\n    if (xrdp_iso_recv(self->iso_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_mcs_recv: xrdp_iso_recv failed\");\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 1, \"Parsing [ITU-T T.125] DomainMCSPDU\"))\n    {\n        return 1;\n    }\n\n    /* The DomainMCSPDU choice index is a 6-bit int with the 2 least\n       significant bits of the byte as padding */\n    in_uint8(s, opcode);\n    *appid = opcode >> 2; /* 2-bit padding */\n    LOG_DEVEL(LOG_LEVEL_TRACE,\n              \"Received [ITU-T T.125] DomainMCSPDU choice index %d\", *appid);\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Processes an [ITU-T T.125] DomainMCSPDU message.\n *\n * Note: DomainMCSPDU messages use the ALIGNED BASIC-PER (Packed Encoding Rules)\n * from [ITU-T X.691].\n *\n * returns error\n */\nint\nxrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan)\n{\n    int appid;\n    int len;\n\n    if (get_domain_mcs_pdu_header(self, s, &appid) != 0)\n    {\n        return 1;\n    }\n\n    if (self->expecting_channel_join_requests)\n    {\n        if (handle_channel_join_requests(self, s, &appid) != 0)\n        {\n            return 1;\n        }\n        LOG(LOG_LEVEL_DEBUG, \"[MCS Connection Sequence] completed\");\n        self->expecting_channel_join_requests = 0;\n    }\n\n    if (appid == MCS_DPUM) /* Disconnect Provider Ultimatum */\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE,\n                  \"Received [ITU-T T.125] DisconnectProviderUltimatum\");\n        LOG(LOG_LEVEL_DEBUG, \"Received disconnection request\");\n        return 1;\n    }\n\n\n    if (appid != MCS_SDRQ)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Received [ITU-T T.125] DomainMCSPDU \"\n            \"choice index %d is unknown. Expected the DomainMCSPDU to \"\n            \"contain the type SendDataRequest with index %d\",\n            appid, MCS_SDRQ);\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 6, \"Parsing [ITU-T T.125] SendDataRequest\"))\n    {\n        return 1;\n    }\n\n    in_uint8s(s, 2); /* initiator */\n    in_uint16_be(s, *chan); /* channelId */\n    in_uint8s(s, 1); /* dataPriority (4-bits), segmentation (2-bits), padding (2-bits) */\n    in_uint8(s, len); /* userData Length (byte 1) */\n\n    if ((len & 0xC0) == 0x80)\n    {\n        /* From [ITU-T X.691] 11.9.3.7\n           encoding a length determinant if \"n\" is greater than 127 and\n           less than 16K, then n is encoded using 2 bytes.\n           The first byte will have the two highest order bits set to 1 and 0\n           (ie. len & 0xC0 == 0x80) and the length is encoded as remaining 14 bits of\n           the two bytes (ie. len & 0x3fff). */\n        if (!s_check_rem_and_log(s, 1, \"Parsing [ITU-T T.125] SendDataRequest userData Length\"))\n        {\n            return 1;\n        }\n        in_uint8s(s, 1); /* userData Length (byte 2) */\n    }\n    else if ((len & 0xC0) == 0xC0)\n    {\n        /* From [ITU-T X.691] 11.9.3.8\n           encoding a length determinant if \"n\" is greater than 16K,\n           then the list of items is fragmented with the length of the first\n           fragment encoded using 1 byte. The two highest order bits are set\n           to 1 and 1 (ie. len & 0xC0 == 0xC0) and the remaining 6 bits contain\n           a multiplyer for 16K (ie. n = (len & 0x3f) * 0x3f)\n        */\n        LOG(LOG_LEVEL_ERROR, \"[ITU-T T.125] SendDataRequest with length greater \"\n            \"than 16K is not supported. len 0x%2.2x\", len);\n        return 1;\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [ITU-T T.125] SendDataRequest \"\n              \"initiator (ignored), channelId %d, dataPriority (ignored), \"\n              \"segmentation (ignored), userData Length (ignored)\", *chan);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Parse the identifier and length of a [ITU-T X.690] BER (Basic Encoding Rules)\n * structure header.\n *\n * @param s [in] - the stream to read from\n * @param tag_val [in] - the expected tag value\n * @param len [out] - the length of the structure\n * @returns error\n */\nstatic int\nxrdp_mcs_ber_parse_header(struct xrdp_mcs *self, struct stream *s,\n                          int tag_val, int *len)\n{\n    int tag;\n    int l;\n    int i;\n\n    if (tag_val > 0xff)\n    {\n        if (!s_check_rem_and_log(s, 2, \"Parsing [ITU-T X.690] Identifier\"))\n        {\n            return 1;\n        }\n        in_uint16_be(s, tag);\n    }\n    else\n    {\n        if (!s_check_rem_and_log(s, 1, \"Parsing [ITU-T X.690] Identifier\"))\n        {\n            return 1;\n        }\n        in_uint8(s, tag);\n    }\n\n    if (tag != tag_val)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Parsed [ITU-T X.690] Identifier: \"\n            \"expected 0x%4.4x, actual 0x%4.4x\", tag_val, tag);\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 1, \"Parsing [ITU-T X.690] Length\"))\n    {\n        return 1;\n    }\n\n    in_uint8(s, l);\n\n    if (l & 0x80)\n    {\n        l = l & ~0x80;\n        *len = 0;\n\n        while (l > 0)\n        {\n            if (!s_check_rem_and_log(s, 1, \"Parsing [ITU-T X.690] Length\"))\n            {\n                return 1;\n            }\n            in_uint8(s, i);\n            *len = (*len << 8) | i;\n            l--;\n        }\n    }\n    else\n    {\n        *len = l;\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Parsed BER header [ITU-T X.690] \"\n              \"Identifier 0x%4.4x, Length %d\", tag, *len);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Parses a [ITU-T T.125] DomainParameters structure encoded using BER */\n/* returns error */\nstatic int\nxrdp_mcs_parse_domain_params(struct xrdp_mcs *self, struct stream *s)\n{\n    int len;\n\n    if (xrdp_mcs_ber_parse_header(self, s, MCS_TAG_DOMAIN_PARAMS, &len) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] DomainParameters failed\");\n        return 1;\n    }\n\n    if (len < 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] DomainParameters length field is \"\n            \"invalid. Expected >= 0, actual %d\", len);\n        return 1;\n    }\n    if (!s_check_rem_and_log(s, len, \"Parsing [ITU-T T.125] DomainParameters\"))\n    {\n        return 1;\n    }\n\n    in_uint8s(s, len); /* skip all fields */\n\n    return !s_check_rem_and_log(s, 0, \"Parsing [ITU-T T.125] DomainParameters\");\n}\n\n/*****************************************************************************/\n/* Process a [ITU-T T.125] Connect-Initial message encoded using BER */\n/* returns error */\nstatic int\nxrdp_mcs_recv_connect_initial(struct xrdp_mcs *self)\n{\n    int len;\n    struct stream *s;\n\n    s = libxrdp_force_read(self->iso_layer->trans);\n    if (s == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Processing [ITU-T T.125] Connect-Initial failed\");\n        return 1;\n    }\n\n    if (xrdp_iso_recv(self->iso_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Processing [ITU-T T.125] Connect-Initial failed\");\n        return 1;\n    }\n\n    if (xrdp_mcs_ber_parse_header(self, s, MCS_CONNECT_INITIAL, &len) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial failed\");\n        return 1;\n    }\n\n    if (xrdp_mcs_ber_parse_header(self, s, BER_TAG_OCTET_STRING, &len) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial callingDomainSelector failed\");\n        return 1;\n    }\n\n    if (len < 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial callingDomainSelector length field is \"\n            \"invalid. Expected >= 0, actual %d\", len);\n        return 1;\n    }\n    if (!s_check_rem_and_log(s, len, \"Parsing [ITU-T T.125] Connect-Initial callingDomainSelector\"))\n    {\n        return 1;\n    }\n\n    in_uint8s(s, len); /* [ITU-T T.125] Connect-Initial callingDomainSelector */\n\n    if (xrdp_mcs_ber_parse_header(self, s, BER_TAG_OCTET_STRING, &len) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial calledDomainSelector failed\");\n        return 1;\n    }\n    if (len < 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial calledDomainSelector length field is \"\n            \"invalid. Expected >= 0, actual %d\", len);\n        return 1;\n    }\n    if (!s_check_rem_and_log(s, len, \"Parsing [ITU-T T.125] Connect-Initial calledDomainSelector\"))\n    {\n        return 1;\n    }\n\n    in_uint8s(s, len); /* [ITU-T T.125] Connect-Initial calledDomainSelector */\n\n    if (xrdp_mcs_ber_parse_header(self, s, BER_TAG_BOOLEAN, &len) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial upwardFlag failed\");\n        return 1;\n    }\n    if (len < 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial upwardFlag length field is \"\n            \"invalid. Expected >= 0, actual %d\", len);\n        return 1;\n    }\n    if (!s_check_rem_and_log(s, len, \"Parsing [ITU-T T.125] Connect-Initial upwardFlag\"))\n    {\n        return 1;\n    }\n\n    in_uint8s(s, len);  /* [ITU-T T.125] Connect-Initial upwardFlag */\n\n    /* [ITU-T T.125] Connect-Initial targetParameters */\n    if (xrdp_mcs_parse_domain_params(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial targetParameters failed\");\n        return 1;\n    }\n\n    /* [ITU-T T.125] Connect-Initial minimumParameters */\n    if (xrdp_mcs_parse_domain_params(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial minimumParameters failed\");\n        return 1;\n    }\n\n    /* [ITU-T T.125] Connect-Initial maximumParameters */\n    if (xrdp_mcs_parse_domain_params(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial maximumParameters failed\");\n        return 1;\n    }\n\n    if (xrdp_mcs_ber_parse_header(self, s, BER_TAG_OCTET_STRING, &len) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial userData failed\");\n        return 1;\n    }\n    /* mcs userData can not be zero length */\n    if ((len <= 0) || (len > 16 * 1024))\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Parsing [ITU-T T.125] Connect-Initial userData: invalid length. \"\n            \"Expected min 1, max %d; Actual %d\", 16 * 1024, len);\n        return 1;\n    }\n    if (!s_check_rem_and_log(s, len, \"Parsing [ITU-T T.125] Connect-Initial userData\"))\n    {\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [ITU-T T.125] Connect-Initial \"\n              \"callingDomainSelector (ignored), calledDomainSelector (ignored), \"\n              \"upwardFlag (ignored), targetParameters (ignored), \"\n              \"minimumParameters (ignored), maximumParameters (ignored), \"\n              \"userData (copied to client_mcs_data)\");\n    /* make a copy of client mcs data */\n    init_stream(self->client_mcs_data, len);\n    out_uint8a(self->client_mcs_data, s->p, len); /* [ITU-T T.125] Connect-Initial userData */\n    in_uint8s(s, len);\n    s_mark_end(self->client_mcs_data);\n\n    if (!s_check_end_and_log(s, \"MCS protocol error [ITU-T T.125] Connect-Initial\"))\n    {\n        return 1;\n    }\n\n    return 0;\n\n}\n\n/*****************************************************************************/\n/* Processes a [ITU-T T.25] DomainMCSPDU with type ErectDomainRequest\n *\n * Note: a parsing example can be found in [MS-RDPBCGR] 4.1.5\n *\n * returns error */\nstatic int\nxrdp_mcs_recv_edrq(struct xrdp_mcs *self)\n{\n    int opcode;\n    struct stream *s;\n\n    s = libxrdp_force_read(self->iso_layer->trans);\n    if (s == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Processing [ITU-T T.125] ErectDomainRequest failed\");\n        return 1;\n    }\n\n    if (xrdp_iso_recv(self->iso_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Processing [ITU-T T.125] ErectDomainRequest failed\");\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 1, \"Parsing [ITU-T T.125] DomainMCSPDU\"))\n    {\n        return 1;\n    }\n\n    /* The DomainMCSPDU choice index is a 6-bit int with the next bit as the\n       bit field of the optional field in the struct\n    */\n    in_uint8(s, opcode);\n\n    if ((opcode >> 2) != MCS_EDRQ)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Parsed [ITU-T T.125] DomainMCSPDU choice index \"\n            \"expected %d, received %d\", MCS_EDRQ, (opcode >> 2));\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 4, \"Parsing [ITU-T T.125] ErectDomainRequest\"))\n    {\n        return 1;\n    }\n\n    in_uint8s(s, 2); /* subHeight */\n    in_uint8s(s, 2); /* subInterval */\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [ITU-T T.125] DomainMCSPDU \"\n              \"choice index %d (ErectDomainRequest)\", (opcode >> 2));\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [ITU-T T.125] ErectDomainRequest \"\n              \"subHeight (ignored), subInterval (ignored), \"\n              \"nonStandard (%s)\",\n              (opcode & 2) ? \"present\" : \"not present\");\n\n    /*\n     * [MS-RDPBCGR] 2.2.1.5 says that the mcsEDrq field is 5 bytes (which have\n     * already been read into the opcode and previous fields), so the\n     * nonStandard field should never be present.\n     */\n    if (opcode & 2) /* ErectDomainRequest v3 nonStandard optional field is present? */\n    {\n        if (!s_check_rem_and_log(s, 2, \"Parsing [ITU-T T.125] ErectDomainRequest nonStandard\"))\n        {\n            return 1;\n        }\n        in_uint16_be(s, self->userid); /* NonStandardParameter.key\n                                          NonStandardParameter.data */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [ITU-T T.125] DomainMCSPDU \"\n                  \"choice index %d (ErectDomainRequest)\", (opcode >> 2));\n    }\n\n    if (!s_check_end_and_log(s, \"MCS protocol error [ITU-T T.125] ErectDomainRequest\"))\n    {\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Processes a [ITU-T T.25] DomainMCSPDU with type AttachUserRequest\n *\n * Note: a parsing example can be found in [MS-RDPBCGR] 4.1.6\n *\n * returns error */\nstatic int\nxrdp_mcs_recv_aurq(struct xrdp_mcs *self)\n{\n    int opcode;\n    struct stream *s;\n\n    s = libxrdp_force_read(self->iso_layer->trans);\n    if (s == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Processing [ITU-T T.125] AttachUserRequest failed\");\n        return 1;\n    }\n\n    if (xrdp_iso_recv(self->iso_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Processing [ITU-T T.125] AttachUserRequest failed\");\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 1, \"Parsing [ITU-T T.125] DomainMCSPDU\"))\n    {\n        return 1;\n    }\n\n    /* The DomainMCSPDU choice index is a 6-bit int with the next bit as the\n       bit field of the optional field in the struct\n    */\n    in_uint8(s, opcode);\n\n    if ((opcode >> 2) != MCS_AURQ)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Parsed [ITU-T T.125] DomainMCSPDU choice index \"\n            \"expected %d, received %d\", MCS_AURQ, (opcode >> 2));\n        return 1;\n    }\n\n    /*\n     * [MS-RDPBCGR] 2.2.1.6 says that the mcsAUrq field is 1 bytes (which have\n     * already been read into the opcode), so the nonStandard field should\n     * never be present.\n     */\n    if (opcode & 2)\n    {\n        if (!s_check_rem_and_log(s, 2, \"Parsing [ITU-T T.125] AttachUserRequest nonStandard\"))\n        {\n            return 1;\n        }\n        in_uint16_be(s, self->userid); /* NonStandardParameter.key\n                                          NonStandardParameter.data */\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [ITU-T T.125] DomainMCSPDU \"\n              \"choice index %d (AttachUserRequest)\", (opcode >> 2));\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [ITU-T T.125] AttachUserRequest \"\n              \"nonStandard (%s)\",\n              (opcode & 2) ? \"present\" : \"not present\");\n\n    if (!s_check_end_and_log(s, \"MCS protocol error [ITU-T T.125] AttachUserRequest\"))\n    {\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Send a [ITU-T T.125] DomainMCSPDU with type AttachUserConfirm.\n *\n * Note: a parsing example can be found in [MS-RDPBCGR] 4.1.7\n *\n * returns error */\nstatic int\nxrdp_mcs_send_aucf(struct xrdp_mcs *self)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_iso_init(self->iso_layer, s) != 0)\n    {\n        free_stream(s);\n        LOG(LOG_LEVEL_ERROR, \"xrdp_mcs_send_aucf: xrdp_iso_init failed\");\n        return 1;\n    }\n\n    out_uint8(s, ((MCS_AUCF << 2) | 2)); /* AttachUserConfirm\n                                            optional field initiator is present */\n    out_uint8s(s, 1); /* result = 0 rt-successful */\n    out_uint16_be(s, self->userid); /* initiator */\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [ITU-T T.125] DomainMCSPDU \"\n              \"of type AttachUserConfirm: result SUCCESS, initiator %d\",\n              self->userid);\n\n    if (xrdp_iso_send(self->iso_layer, s) != 0)\n    {\n        free_stream(s);\n        LOG(LOG_LEVEL_ERROR, \"Sending [ITU-T T.125] AttachUserConfirm failed\");\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Write the identifier and length of a [ITU-T X.690] BER (Basic Encoding Rules)\n * structure header.\n * returns error */\nstatic int\nxrdp_mcs_ber_out_header(struct xrdp_mcs *self, struct stream *s,\n                        int tag_val, int len)\n{\n    if (tag_val > 0xff)\n    {\n        out_uint16_be(s, tag_val);\n    }\n    else\n    {\n        out_uint8(s, tag_val);\n    }\n\n    if (len >= 0x80)\n    {\n        out_uint8(s, 0x82);\n        out_uint16_be(s, len);\n    }\n    else\n    {\n        out_uint8(s, len);\n    }\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [ITU-T X.690] Identifier %d, Length %d\",\n              tag_val, len);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_mcs_ber_out_int8(struct xrdp_mcs *self, struct stream *s, int value)\n{\n    xrdp_mcs_ber_out_header(self, s, BER_TAG_INTEGER, 1);\n    out_uint8(s, value);\n    return 0;\n}\n\n#if 0 /* not used */\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_mcs_ber_out_int16(struct xrdp_mcs *self, struct stream *s, int value)\n{\n    xrdp_mcs_ber_out_header(self, s, BER_TAG_INTEGER, 2);\n    out_uint8(s, (value >> 8));\n    out_uint8(s, value);\n    return 0;\n}\n#endif\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_mcs_ber_out_int24(struct xrdp_mcs *self, struct stream *s, int value)\n{\n    xrdp_mcs_ber_out_header(self, s, BER_TAG_INTEGER, 3);\n    out_uint8(s, (value >> 16));\n    out_uint8(s, (value >> 8));\n    out_uint8(s, value);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_mcs_out_domain_params(struct xrdp_mcs *self, struct stream *s,\n                           int max_channels,\n                           int max_users, int max_tokens,\n                           int max_pdu_size)\n{\n    xrdp_mcs_ber_out_header(self, s, MCS_TAG_DOMAIN_PARAMS, 26);\n    xrdp_mcs_ber_out_int8(self, s, max_channels);\n    xrdp_mcs_ber_out_int8(self, s, max_users);\n    xrdp_mcs_ber_out_int8(self, s, max_tokens);\n    xrdp_mcs_ber_out_int8(self, s, 1); /* numPriorities */\n    xrdp_mcs_ber_out_int8(self, s, 0); /* minThroughput */\n    xrdp_mcs_ber_out_int8(self, s, 1); /* maxHeight */\n    xrdp_mcs_ber_out_int24(self, s, max_pdu_size);\n    xrdp_mcs_ber_out_int8(self, s, 2); /* protocolVersion */\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [ITU-T T.125] DomainParameters \"\n              \"maxChannelIds %d, maxUserIds %d, maxTokenIds %d, numPriorities 1, \"\n              \"minThroughput 0 B/s, maxHeight 1, maxMCSPDUsize %d, \"\n              \"protocolVersion 2\",\n              max_channels, max_users, max_tokens, max_pdu_size);\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Output a TS_UD_SC_CORE struct ([MS-RDPBCGR] 2.2.1.4.2)\n */\nstatic void\nout_server_core_data(struct xrdp_sec *self, struct stream *s)\n{\n    unsigned int version = 0x00080004;\n    unsigned int client_requested_protocols = 0;\n    unsigned int early_capability_flags = RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED;\n\n    if (self->mcs_layer->iso_layer->rdpNegData)\n    {\n        client_requested_protocols =\n            self->mcs_layer->iso_layer->requestedProtocol;\n    }\n\n    /* [MS-RDPBCGR] TS_UD_HEADER */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct header [MS-RDPBCGR] TS_UD_HEADER \"\n              \"type 0x%4.4x, length %d\", SEC_TAG_SRV_INFO, 16);\n    out_uint16_le(s, SEC_TAG_SRV_INFO); /* type */\n    out_uint16_le(s, 16); /* length */\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [MS-RDPBCGR] TS_UD_SC_CORE \"\n              \"version 0x%8.8x clientRequestedProtocols 0x%8.8x \"\n              \"earlyCapabilityFlags 0x%8.8x\",\n              version, client_requested_protocols,\n              early_capability_flags);\n    out_uint32_le(s, version);\n    out_uint32_le(s, client_requested_protocols);\n    out_uint32_le(s, early_capability_flags);\n}\n\n/*****************************************************************************/\n/* Write an [ITU-T T.124] ConnectData (ALIGNED variant of BASIC-PER) message\n * with ConnectGCCPDU, ConferenceCreateResponse,\n * and [MS-RDPBCGR] Server Data Blocks as user data.\n */\nstatic int\nxrdp_mcs_out_gcc_data(struct xrdp_sec *self)\n{\n    struct stream *s;\n    int num_channels_even;\n    int num_channels;\n    int index;\n    int channel;\n    int gcc_size;\n    char *gcc_size_ptr;\n    char *ud_ptr;\n    int header_length;\n    int server_cert_len;\n    int public_key_blob_len;\n    int key_len;\n    int bit_len;\n    int data_len;\n    int modulus_len;\n\n    num_channels = self->mcs_layer->channel_list->count;\n    num_channels_even = num_channels + (num_channels & 1);\n    s = &(self->server_mcs_data);\n    init_stream(s, 8192);\n\n    /* [ITU-T T.124] ConnectData (ALIGNED variant of BASIC-PER) */\n    out_uint16_be(s, 5); /* = 0x00 0x05 */\n    /* t124Identifier choice index = 0 (object) */\n    /* object length = 5 */\n    out_uint16_be(s, 0x14);  /* t124Identifier.object = ??? (0x00 0x14 0x7c 0x00 0x01) */\n    out_uint8(s, 0x7c);\n    out_uint16_be(s, 1); /* -- */\n    out_uint8(s, 0x2a);  /* connectPDU length = 42 */\n    /* connectPDU octet string of type ConnectGCCPDU\n       (unknown where this octet string is defined to be\n       of type ConnectGCCPDU) */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [ITU-T T.124] ConnectData \"\n              \"t124Identifier.object 0x00 0x14 0x7c 0x00 0x01, connectPDU length %d\",\n              0x2a);\n\n    /* [ITU-T T.124] ConnectGCCPDU (ALIGNED variant of BASIC-PER) */\n    out_uint8(s, 0x14);  /* ConnectGCCPDU choice index 1 = ConferenceCreateResponse with userData present */\n\n    /* [ITU-T T.124] ConferenceCreateResponse (ALIGNED variant of BASIC-PER) */\n    out_uint8(s, 0x76); /* nodeID = 31219 - 1001 (PER offset for min value)\n                                  = 30218 (big-endian 0x760a) */\n    out_uint8(s, 0x0a);\n    out_uint8(s, 1);    /* tag length */\n    out_uint8(s, 1);    /* tag */\n    out_uint8(s, 0);    /* result = 0 (success) */\n    out_uint16_le(s, 0xc001); /* userData set count = 1 (0x01),\n                                 userData.isPresent = 0x80 (yes) | userData.key choice index = 0x40 (1 = h221NonStandard) */\n    out_uint8(s, 0);    /* userData.key.h221NonStandard length\n                           = 4 - 4 (PER offset for min value) (H221NonStandardIdentifier is an octet string SIZE (4..255))\n                           = 0\n                           */\n\n    /* [ITU-T H.221] H221NonStandardIdentifier uses country codes and\n       manufactuer codes from [ITU-T T.35]. Unknown why these values are used,\n       maybe this is just copied from the [MS-RDPBCGR] 4.1.4 example which uses\n       the value \"McDn\" */\n    out_uint8(s, 0x4d); /* M */\n    out_uint8(s, 0x63); /* c */\n    out_uint8(s, 0x44); /* D */\n    out_uint8(s, 0x6e); /* n */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [ITU-T T.124] ConferenceCreateResponse \"\n              \"nodeID %d, result SUCCESS\", 0x760a + 1001);\n\n    /* ConferenceCreateResponse.userData.key.value (octet string) */\n    /* GCC Response Total Length - 2 bytes , set later */\n    gcc_size_ptr = s->p; /* RDPGCCUserDataResponseLength */\n    out_uint8s(s, 2);\n    ud_ptr = s->p; /* User Data */\n\n    out_server_core_data(self, s);\n\n    /* [MS-RDPBCGR] TS_UD_HEADER */\n    out_uint16_le(s, SEC_TAG_SRV_CHANNELS); /* type */\n    out_uint16_le(s, 8 + (num_channels_even * 2)); /* length */\n    /* [MS-RDPBCGR] TS_UD_SC_NET */\n    out_uint16_le(s, MCS_GLOBAL_CHANNEL); /* 1003, 0x03eb main channel (MCSChannelId) */\n    out_uint16_le(s, num_channels); /* number of other channels (channelCount) */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct header [MS-RDPBCGR] TS_UD_HEADER \"\n              \"type 0x%4.4x, length %d\",\n              SEC_TAG_SRV_CHANNELS, 8 + (num_channels_even * 2));\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [MS-RDPBCGR] TS_UD_SC_NET \"\n              \"MCSChannelId %d, channelCount %d\",\n              MCS_GLOBAL_CHANNEL, num_channels);\n    for (index = 0; index < num_channels_even; index++)\n    {\n        if (index < num_channels)\n        {\n            channel = MCS_GLOBAL_CHANNEL + (index + 1);\n            out_uint16_le(s, channel); /* channelIdArray[index] (channel allocated) */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [MS-RDPBCGR] TS_UD_SC_NET channelIdArray[%d] \"\n                      \"channelId %d\", index, channel);\n        }\n        else\n        {\n            out_uint16_le(s, 0); /* padding or channelIdArray[index] (channel not allocated) */\n        }\n\n    }\n\n    if (self->rsa_key_bytes == 64 || self->rsa_key_bytes == 256)\n    {\n        if (self->rsa_key_bytes == 64)\n        {\n            header_length = 0x00ec;       /* length = 236 */\n            server_cert_len = 0xb8;       /* serverCertLen (184 bytes) */\n            public_key_blob_len = 0x005c; /* wPublicKeyBlobLen (92 bytes) */\n            key_len = 0x0048;             /* keylen (72 bytes = (bitlen / 8) modulus + 8 padding) */\n            bit_len = 512;                /* bitlen = 512 */\n            data_len = 63;                /* datalen (63 = (bitlen / 8) - 1) */\n            modulus_len = 64;\n        }\n        else /* if (self->rsa_key_bytes == 256) */\n        {\n            header_length = 0x01ac;       /* length = 428 */\n            server_cert_len = 0x178;      /* serverCertLen (376 bytes) */\n            public_key_blob_len = 0x011c; /* wPublicKeyBlobLen (284 bytes) */\n            key_len = 0x0108;             /* keylen (264 bytes = (bitlen / 8) modulus + 8 padding) */\n            bit_len = 2048;               /* bitlen = 2048 */\n            data_len = 255;               /* datalen (255 = (bitlen / 8) - 1) */\n            modulus_len = 256;\n        }\n        LOG(LOG_LEVEL_DEBUG, \"using %d bit RSA key\", bit_len);\n\n        /* [MS-RDPBCGR] TS_UD_HEADER */\n        out_uint16_le(s, SEC_TAG_SRV_CRYPT);  /* type */\n        out_uint16_le(s, header_length);      /* length */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct header [MS-RDPBCGR] TS_UD_HEADER \"\n                  \"type 0x%4.4x, length %d\", SEC_TAG_SRV_CRYPT, header_length);\n\n        /* [MS-RDPBCGR] TS_UD_SC_SEC1 */\n        out_uint32_le(s, self->crypt_method);   /* encryptionMethod  */\n        out_uint32_le(s, self->crypt_level);    /* encryptionLevel */\n        out_uint32_le(s, 32);                   /* serverRandomLen */\n        out_uint32_le(s, server_cert_len);      /* serverCertLen */\n        out_uint8a(s, self->server_random, 32); /* serverRandom */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [MS-RDPBCGR] TS_UD_SC_SEC1 \"\n                  \"encryptionMethod 0x%8.8x, encryptionLevel 0x%8.8x, \"\n                  \"serverRandomLen 32, serverCertLen %d, serverRandom (omitted), \",\n                  self->crypt_method, self->crypt_level, server_cert_len);\n\n        /* (field serverCertificate) [MS-RDPBCGR] SERVER_CERTIFICATE */\n        /* HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\ */\n        /* TermService\\Parameters\\Certificate */\n        out_uint32_le(s, 1); /* dwVersion (1 = PROPRIETARYSERVERCERTIFICATE) */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [MS-RDPBCGR] SERVER_CERTIFICATE \"\n                  \"dwVersion.certChainVersion 1 (CERT_CHAIN_VERSION_1), \"\n                  \"dwVersion.t 0 (permanent)\");\n\n        /* [MS-RDPBCGR] PROPRIETARYSERVERCERTIFICATE */\n        out_uint32_le(s, 1);              /* dwSigAlgId (1 = RSA) */\n        out_uint32_le(s, 1);              /* dwKeyAlgId (1 = RSA) */\n        out_uint16_le(s, SEC_TAG_PUBKEY); /* wPublicKeyBlobType (BB_RSA_KEY_BLOB) */\n        out_uint16_le(s, public_key_blob_len); /* wPublicKeyBlobLen */\n\n        /* (field PublicKeyBlob) [MS-RDPBCGR] RSA_PUBLIC_KEY */\n        out_uint32_le(s, SEC_RSA_MAGIC);  /* magic (0x31415352 'RSA1') */\n        out_uint32_le(s, key_len);        /* keylen */\n        out_uint32_le(s, bit_len);        /* bitlen */\n        out_uint32_le(s, data_len);       /* datalen */\n        out_uint8a(s, self->pub_exp, 4);  /* pubExp */\n        out_uint8a(s, self->pub_mod, modulus_len); /* modulus */\n        out_uint8s(s, 8);                 /* modulus zero padding */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [MS-RDPBCGR] RSA_PUBLIC_KEY \"\n                  \"magic 0x%8.8x, keylen %d, bitlen %d, datalen %d, \"\n                  \"pubExp <omitted>, modulus <omitted>, \",\n                  SEC_RSA_MAGIC, key_len, bit_len, data_len);\n\n        out_uint16_le(s, SEC_TAG_KEYSIG); /* wSignatureBlobType (0x0008 RSA) */\n        out_uint16_le(s, 72);             /* wSignatureBlobLen */\n        out_uint8a(s, self->pub_sig, 64); /* SignatureBlob */\n        out_uint8s(s, 8);                 /* modulus zero padding */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [MS-RDPBCGR] PROPRIETARYSERVERCERTIFICATE \"\n                  \"dwKeyAlgId 1, \"\n                  \"wPublicKeyBlobType 0x%4.4x, \"\n                  \"wPublicKeyBlobLen %d, PublicKeyBlob <see RSA_PUBLIC_KEY above>\"\n                  \"wSignatureBlobType 0x%4.4x, \"\n                  \"wSignatureBlobLen %d, \"\n                  \"SignatureBlob <omitted>\",\n                  SEC_TAG_PUBKEY, public_key_blob_len,\n                  SEC_TAG_KEYSIG, 72);\n    }\n    else if (self->rsa_key_bytes == 0) /* no security */\n    {\n        LOG(LOG_LEVEL_DEBUG, \"using no security\");\n        /* [MS-RDPBCGR] TS_UD_HEADER */\n        out_uint16_le(s, SEC_TAG_SRV_CRYPT);  /* type*/\n        out_uint16_le(s, 12);                 /* length */\n        /* [MS-RDPBCGR] TS_UD_SC_SEC1 */\n        out_uint32_le(s, self->crypt_method); /* encryptionMethod  */\n        out_uint32_le(s, self->crypt_level);  /* encryptionLevel */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct header [MS-RDPBCGR] TS_UD_HEADER \"\n                  \"type 0x%4.4x, length %d\", SEC_TAG_SRV_CRYPT, 12);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding struct [MS-RDPBCGR] TS_UD_SC_SEC1 \"\n                  \"encryptionMethod 0x%8.8x, encryptionMethod 0x%8.8x\",\n                  self->crypt_method, self->crypt_level);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"Unsupported xrdp_sec.rsa_key_bytes value: %d, the client \"\n            \"will not be sent a [MS-RDPBCGR] TS_UD_SC_SEC1 message.\",\n            self->rsa_key_bytes);\n    }\n    s_mark_end(s);\n\n    gcc_size = (int)(s->end - ud_ptr) | 0x8000;\n    gcc_size_ptr[0] = gcc_size >> 8;\n    gcc_size_ptr[1] = gcc_size;\n\n    return 0;\n}\n/*****************************************************************************/\n/* Send an [ITU-T T.125] Connect-Response message.\n *\n * Note: the xrdp_mcs_out_gcc_data() function must be called (to populate the\n * xrdp_mcs.server_mcs_data stream) before this method is called.\n *\n * returns error\n */\nstatic int\nxrdp_mcs_send_connect_response(struct xrdp_mcs *self)\n{\n    int data_len;\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    data_len = (int) (self->server_mcs_data->end - self->server_mcs_data->data);\n    xrdp_iso_init(self->iso_layer, s);\n    //TODO: we should calculate the whole length include MCS_CONNECT_RESPONSE\n    xrdp_mcs_ber_out_header(self, s, MCS_CONNECT_RESPONSE,\n                            data_len > 0x80 ? data_len + 38 : data_len + 36);\n    xrdp_mcs_ber_out_header(self, s, BER_TAG_RESULT, 1);\n    out_uint8(s, 0); /* result choice index 0 = rt-successful */\n    xrdp_mcs_ber_out_header(self, s, BER_TAG_INTEGER, 1);\n    out_uint8(s, 0); /* calledConnectId */\n    xrdp_mcs_out_domain_params(self, s, 22, 3, 0, 0xfff8);\n    xrdp_mcs_ber_out_header(self, s, BER_TAG_OCTET_STRING, data_len);\n    /* mcs data */\n    out_uint8a(s, self->server_mcs_data->data, data_len);\n    s_mark_end(s);\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [ITU-T T.125] Connect-Response \"\n              \"result SUCCESS, calledConnectId 0, \"\n              \"domainParameters (see xrdp_mcs_out_domain_params() trace logs), \"\n              \"userData (see xrdp_mcs_out_gcc_data() trace logs and \"\n              \"hex dump below)\");\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"[ITU-T T.125] Connect-Response userData\",\n                      self->server_mcs_data->data, data_len);\n    if (xrdp_iso_send(self->iso_layer, s) != 0)\n    {\n        free_stream(s);\n        LOG(LOG_LEVEL_ERROR, \"Sending [ITU-T T.125] Connect-Response failed\");\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Handle all client channel join requests\n *\n * @param self MCS structure\n * @param s Input stream\n * @param[in,out] appid Type of the MCS PDU whose header has just been read.\n * @return 0 for success\n *\n * Called when an MCS PDU header has been read, but the PDU has not\n * been processed.\n *\n * If the PDU is a channel join request, it is processed, and the next\n * PDU header is read. When we've exhausted all the channel join requests,\n * the type of the next PDU is passed back to the caller for the caller\n * to process.\n *\n * We simply take all the join requests which come in,\n * and respond to them. We do this for a number of reasons:-\n *\n * 1) Older clients may not issue exactly the documented number of\n *    channel join requests. See\n *    https://github.com/neutrinolabs/xrdp/issues/2166\n * 2) If we set RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED in our early capabilities\n *    flags, and the client sets RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN, the\n *    client can still send channel join requests and be compliant with the\n *    spec. See [MS-RDPCCGR] 3.2.5.3.8.\n */\nstatic int\nhandle_channel_join_requests(struct xrdp_mcs *self,\n                             struct stream *s, int *appid)\n{\n    int rv = 0;\n    unsigned int expected_join_count = 0;\n    if ((self->sec_layer->rdp_layer->client_info.mcs_early_capability_flags &\n            RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN) == 0)\n    {\n        /*\n         * The client has indicated it does not support skipping channel\n         * join request/confirm PDUs.\n         *\n         * Expect a channel join request PDU for each of the static\n         * virtual channels, plus the user channel (self->chanid) and\n         * the I/O channel (MCS_GLOBAL_CHANNEL) */\n        expected_join_count = self->channel_list->count + 2;\n    }\n\n    unsigned int actual_join_count = 0;\n\n    while (*appid == MCS_CJRQ)\n    {\n        int userid;\n        int chanid;\n\n        if (!s_check_rem_and_log(s, 4, \"Parsing [ITU-T T.125] \"\n                                 \"ChannelJoinRequest\"))\n        {\n            rv = 1;\n            break;\n        }\n\n        in_uint16_be(s, userid);\n        in_uint16_be(s, chanid);\n        LOG_DEVEL(LOG_LEVEL_TRACE,\n                  \"Received [ITU-T T.125] ChannelJoinRequest \"\n                  \"initiator 0x%4.4x, channelId 0x%4.4x\", userid, chanid);\n        ++actual_join_count;\n\n        if (xrdp_mcs_send_cjcf(self, userid, chanid) != 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"[ITU-T T.125] Channel join sequence: failed\");\n        }\n\n        /* Get the next PDU header */\n        s = libxrdp_force_read(self->iso_layer->trans);\n        if (s == 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_mcs_recv: libxrdp_force_read failed\");\n            rv = 1;\n            break;\n        }\n        if (get_domain_mcs_pdu_header(self, s, appid) != 0)\n        {\n            rv = 1;\n            break;\n        }\n    }\n\n    if (rv == 0 && expected_join_count != actual_join_count)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Expected %u channel join PDUs but got %u\",\n            expected_join_count, actual_join_count);\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* Process and send the MCS messages for the RDP Connection Sequence\n * [MS-RDPBCGR] 1.3.1.1\n *\n * returns error\n */\nint\nxrdp_mcs_incoming(struct xrdp_mcs *self)\n{\n    LOG(LOG_LEVEL_DEBUG, \"[MCS Connection Sequence] receive connection request\");\n    if (xrdp_mcs_recv_connect_initial(self) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[MCS Connection Sequence] receive connection request failed\");\n        return 1;\n    }\n\n    /* in xrdp_sec.c */\n    if (xrdp_sec_process_mcs_data(self->sec_layer) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[MCS Connection Sequence] Connect Initial PDU with GCC Conference Create Request failed\");\n        return 1;\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"[MCS Connection Sequence] construct connection response\");\n    if (xrdp_mcs_out_gcc_data(self->sec_layer) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[MCS Connection Sequence] construct connection response failed\");\n        return 1;\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"[MCS Connection Sequence] send connection response\");\n    if (xrdp_mcs_send_connect_response(self) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[MCS Connection Sequence] send connection response failed\");\n        return 1;\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"[MCS Connection Sequence] receive erect domain request\");\n    if (xrdp_mcs_recv_edrq(self) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[MCS Connection Sequence] receive erect domain request failed\");\n        return 1;\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"[MCS Connection Sequence] receive attach user request\");\n    if (xrdp_mcs_recv_aurq(self) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[MCS Connection Sequence] receive attach user request failed\");\n        return 1;\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"[MCS Connection Sequence] send attach user confirm\");\n    if (xrdp_mcs_send_aucf(self) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[MCS Connection Sequence] send attach user confirm failed\");\n        return 1;\n    }\n\n    /* Tell the MCS PDU processing loop that (zere or more ) channel\n       join requests are expected at this point */\n    self->expecting_channel_join_requests = 1;\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_mcs_init(struct xrdp_mcs *self, struct stream *s)\n{\n    xrdp_iso_init(self->iso_layer, s);\n    s_push_layer(s, mcs_hdr, 8);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* Inform the callback that an mcs packet has been sent.  This is needed so\n   the module can send any high priority mcs packets like audio. */\nstatic int\nxrdp_mcs_call_callback(struct xrdp_mcs *self)\n{\n    int rv;\n    struct xrdp_session *session;\n\n    rv = 0;\n    /* if there is a callback, call it here */\n    session = self->sec_layer->rdp_layer->session;\n\n    if (session != 0)\n    {\n        if (session->callback != 0)\n        {\n            if (session->check_for_app_input)\n            {\n                /* in xrdp_wm.c */\n                rv = session->callback(session->id, 0x5556, 0, 0, 0, 0);\n            }\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING, \"session->callback is NULL\");\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_WARNING, \"session is NULL\");\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* Send a [ITU-T T.125] SendDataIndication message\n * returns error */\nint\nxrdp_mcs_send(struct xrdp_mcs *self, struct stream *s, int chan)\n{\n    int len;\n    char *lp;\n    //static int max_len = 0;\n\n    s_pop_layer(s, mcs_hdr);\n    len = (s->end - s->p) - 8;\n\n    if (len > 8192 * 2)\n    {\n        LOG(LOG_LEVEL_WARNING, \"xrdp_mcs_send: stream size too big: %d bytes\", len);\n    }\n\n    /* The DomainMCSPDU choice index is a 6-bit int with the 2 least\n           significant bits of the byte as padding */\n    out_uint8(s, MCS_SDIN << 2);    /* DomainMCSPDU choice index */\n    out_uint16_be(s, self->userid); /* initiator */\n    out_uint16_be(s, chan);         /* channelId */\n    out_uint8(s, 0x70);             /* dataPriority (upper 2 bits),\n                                       segmentation (next 2 bits),\n                                       padding (4 bits) */\n\n    if (len >= 128)\n    {\n        len = len | 0x8000;\n        out_uint16_be(s, len);      /* userData length */\n    }\n    else\n    {\n        out_uint8(s, len);          /* userData length */\n        /* move everything up one byte */\n        lp = s->p;\n\n        while (lp < s->end)\n        {\n            lp[0] = lp[1];\n            lp++;\n        }\n\n        s->end--;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [ITU-T T.125] SendDataIndication \"\n              \"initiator %d, channelId %d, dataPriority %d, segmentation 0x0, \"\n              \"userData length %d\",\n              self->userid, chan, 0x70 >> 6, (0x70 >> 4) & 0x03);\n    if (xrdp_iso_send(self->iso_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_mcs_send: xrdp_iso_send failed\");\n        return 1;\n    }\n\n    /* todo, do we need to call this for every mcs packet,\n       maybe every 5 or so */\n    if (chan == MCS_GLOBAL_CHANNEL)\n    {\n        xrdp_mcs_call_callback(self);\n    }\n\n    return 0;\n}\n\n/**\n * Internal help function to close the socket\n */\nstatic void\nclose_rdp_socket(struct xrdp_mcs *self)\n{\n    if (self->iso_layer != 0)\n    {\n        if (self->iso_layer->trans != 0)\n        {\n            trans_shutdown_tls_mode(self->iso_layer->trans);\n            g_tcp_close(self->iso_layer->trans->sck);\n            self->iso_layer->trans->sck = -1;\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mcs_disconnect - socket closed\");\n            return;\n        }\n    }\n    LOG_DEVEL(LOG_LEVEL_WARNING, \"Failed to close socket\");\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_mcs_disconnect(struct xrdp_mcs *self)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_iso_init(self->iso_layer, s) != 0)\n    {\n        free_stream(s);\n        close_rdp_socket(self);\n        LOG(LOG_LEVEL_ERROR, \"xrdp_mcs_disconnect: xrdp_iso_init failed\");\n        return 1;\n    }\n\n    out_uint8(s, (MCS_DPUM << 2) | 1);\n    out_uint8(s, 0x80); /* reason (upper 3 bits) (4 = rn-channel-purged)*/\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [ITU T.125] DisconnectProviderUltimatum \"\n              \"reason %d\", 0x80 >> 5);\n\n    if (xrdp_iso_send(self->iso_layer, s) != 0)\n    {\n        free_stream(s);\n        close_rdp_socket(self);\n        LOG(LOG_LEVEL_ERROR, \"Sending [ITU T.125] DisconnectProviderUltimatum failed\");\n        return 1;\n    }\n\n    free_stream(s);\n    close_rdp_socket(self);\n    return 0;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_mppc_enc.c",
    "content": "/**\n * FreeRDP: A Remote Desktop Protocol Implementation\n * Implements Microsoft Point to Point Compression (MPPC) protocol\n *\n * Copyright 2012-2013 Laxmikant Rashinkar <LK.Rashinkar@gmail.com>\n * Copyright 2012-2013 Jay Sorg <jay.sorg@gmail.com>\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n\n/* local defines */\n\n#define RDP_40_HIST_BUF_LEN (1024 * 8) /* RDP 4.0 uses 8K history buf */\n#define RDP_50_HIST_BUF_LEN (1024 * 64) /* RDP 5.0 uses 64K history buf */\n\n/* Compression Types */\n#define PACKET_COMPRESSED       0x20\n#define PACKET_AT_FRONT         0x40\n#define PACKET_FLUSHED          0x80\n#define PACKET_COMPR_TYPE_8K    0x00\n#define PACKET_COMPR_TYPE_64K   0x01\n#define PACKET_COMPR_TYPE_RDP6  0x02\n#define PACKET_COMPR_TYPE_RDP61 0x03\n#define CompressionTypeMask     0x0F\n\n#define CRC_INIT 0xFFFF\n#define CRC(_crcval, _newchar) _crcval = \\\n    ((_crcval) >> 8) ^ g_crc_table[((_crcval) ^ (_newchar)) & 0x00ff]\n\n/* CRC16 defs */\nstatic const tui16 g_crc_table[256] =\n{\n    0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,\n    0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,\n    0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,\n    0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,\n    0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,\n    0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,\n    0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,\n    0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,\n    0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,\n    0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,\n    0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,\n    0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,\n    0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,\n    0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,\n    0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,\n    0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,\n    0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,\n    0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,\n    0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,\n    0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,\n    0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,\n    0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,\n    0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,\n    0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,\n    0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,\n    0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,\n    0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,\n    0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,\n    0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,\n    0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,\n    0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,\n    0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78\n};\n\n/*****************************************************************************\n                     insert 2 bits into outputBuffer\n******************************************************************************/\n#define insert_2_bits(_data) \\\n    do \\\n    { \\\n        if ((bits_left >= 3) && (bits_left <= 8)) \\\n        { \\\n            i = bits_left - 2; \\\n            outputBuffer[opb_index] |= _data << i; \\\n            bits_left = i; \\\n        } \\\n        else \\\n        { \\\n            i = 2 - bits_left; \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= _data >> i; \\\n            outputBuffer[opb_index] |= _data << j; \\\n            bits_left = j; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 3 bits into outputBuffer\n******************************************************************************/\n#define insert_3_bits(_data) \\\n    do \\\n    { \\\n        if ((bits_left >= 4) && (bits_left <= 8)) \\\n        { \\\n            i = bits_left - 3; \\\n            outputBuffer[opb_index] |= _data << i; \\\n            bits_left = i; \\\n        } \\\n        else \\\n        { \\\n            i = 3 - bits_left; \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= _data >> i; \\\n            outputBuffer[opb_index] |= _data << j; \\\n            bits_left = j; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 4 bits into outputBuffer\n******************************************************************************/\n#define insert_4_bits(_data) \\\n    do \\\n    { \\\n        if ((bits_left >= 5) && (bits_left <= 8)) \\\n        { \\\n            i = bits_left - 4; \\\n            outputBuffer[opb_index] |= _data << i; \\\n            bits_left = i; \\\n        } \\\n        else \\\n        { \\\n            i = 4 - bits_left; \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= _data >> i; \\\n            outputBuffer[opb_index] |= _data << j; \\\n            bits_left = j; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 5 bits into outputBuffer\n******************************************************************************/\n#define insert_5_bits(_data) \\\n    do \\\n    { \\\n        if ((bits_left >= 6) && (bits_left <= 8)) \\\n        { \\\n            i = bits_left - 5; \\\n            outputBuffer[opb_index] |= _data << i; \\\n            bits_left = i; \\\n        } \\\n        else \\\n        { \\\n            i = 5 - bits_left; \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= _data >> i; \\\n            outputBuffer[opb_index] |= _data << j; \\\n            bits_left = j; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 6 bits into outputBuffer\n******************************************************************************/\n#define insert_6_bits(_data) \\\n    do \\\n    { \\\n        if ((bits_left >= 7) && (bits_left <= 8)) \\\n        { \\\n            i = bits_left - 6; \\\n            outputBuffer[opb_index] |= (_data << i); \\\n            bits_left = i; \\\n        } \\\n        else \\\n        { \\\n            i = 6 - bits_left; \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= (_data >> i); \\\n            outputBuffer[opb_index] |= (_data << j); \\\n            bits_left = j; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 7 bits into outputBuffer\n******************************************************************************/\n#define insert_7_bits(_data) \\\n    do \\\n    { \\\n        if (bits_left == 8) \\\n        { \\\n            outputBuffer[opb_index] |= _data << 1; \\\n            bits_left = 1; \\\n        } \\\n        else \\\n        { \\\n            i = 7 - bits_left; \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= _data >> i; \\\n            outputBuffer[opb_index] |= _data << j; \\\n            bits_left = j; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 8 bits into outputBuffer\n******************************************************************************/\n#define insert_8_bits(_data) \\\n    do \\\n    { \\\n        if (bits_left == 8) \\\n        { \\\n            outputBuffer[opb_index++] |= _data; \\\n            bits_left = 8; \\\n        } \\\n        else \\\n        { \\\n            i = 8 - bits_left; \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= _data >> i; \\\n            outputBuffer[opb_index] |= _data << j; \\\n            bits_left = j; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 9 bits into outputBuffer\n******************************************************************************/\n#define insert_9_bits(_data16) \\\n    do \\\n    { \\\n        i = 9 - bits_left; \\\n        j = 8 - i; \\\n        outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n        outputBuffer[opb_index] |= (char) (_data16 << j); \\\n        bits_left = j; \\\n        if (bits_left == 0) \\\n        { \\\n            opb_index++; \\\n            bits_left = 8; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 10 bits into outputBuffer\n******************************************************************************/\n#define insert_10_bits(_data16) \\\n    do \\\n    { \\\n        i = 10 - bits_left; \\\n        if ((bits_left >= 3) && (bits_left <= 8)) \\\n        { \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index] |= (char) (_data16 << j); \\\n            bits_left = j; \\\n        } \\\n        else \\\n        { \\\n            j = i - 8; \\\n            k = 8 - j; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> j); \\\n            outputBuffer[opb_index] |= (char) (_data16 << k); \\\n            bits_left = k; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 11 bits into outputBuffer\n******************************************************************************/\n#define insert_11_bits(_data16) \\\n    do \\\n    { \\\n        i = 11 - bits_left; \\\n        if ((bits_left >= 4) && (bits_left <= 8)) \\\n        { \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index] |= (char) (_data16 << j); \\\n            bits_left = j; \\\n        } \\\n        else \\\n        { \\\n            j = i - 8;                                \\\n            k = 8 - j; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> j); \\\n            outputBuffer[opb_index] |= (char) (_data16 << k); \\\n            bits_left = k; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 12 bits into outputBuffer\n******************************************************************************/\n#define insert_12_bits(_data16) \\\n    do \\\n    { \\\n        i = 12 - bits_left; \\\n        if ((bits_left >= 5) && (bits_left <= 8)) \\\n        { \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index] |= (char) (_data16 << j); \\\n            bits_left = j; \\\n        } \\\n        else \\\n        { \\\n            j = i - 8; \\\n            k = 8 - j; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> j); \\\n            outputBuffer[opb_index] |= (char) (_data16 << k); \\\n            bits_left = k; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 13 bits into outputBuffer\n******************************************************************************/\n#define insert_13_bits(_data16) \\\n    do \\\n    { \\\n        i = 13 - bits_left; \\\n        if ((bits_left >= 6) && (bits_left <= 8)) \\\n        { \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index] |= (char) (_data16 << j); \\\n            bits_left = j; \\\n        } \\\n        else \\\n        { \\\n            j = i - 8; \\\n            k = 8 - j; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> j); \\\n            outputBuffer[opb_index] |= (char) (_data16 << k); \\\n            bits_left = k; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 14 bits into outputBuffer\n******************************************************************************/\n#define insert_14_bits(_data16) \\\n    do \\\n    { \\\n        i = 14 - bits_left; \\\n        if ((bits_left >= 7) && (bits_left <= 8)) \\\n        { \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index] |= (char) (_data16 << j); \\\n            bits_left = j; \\\n        } \\\n        else \\\n        { \\\n            j = i - 8; \\\n            k = 8 - j; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> j); \\\n            outputBuffer[opb_index] |= (char) (_data16 << k); \\\n            bits_left = k; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 15 bits into outputBuffer\n******************************************************************************/\n#define insert_15_bits(_data16) \\\n    do \\\n    { \\\n        i = 15 - bits_left; \\\n        if (bits_left == 8) \\\n        { \\\n            j = 8 - i; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index] |= (char) (_data16 << j); \\\n            bits_left = j; \\\n        } \\\n        else \\\n        { \\\n            j = i - 8; \\\n            k = 8 - j; \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n            outputBuffer[opb_index++] |= (char) (_data16 >> j); \\\n            outputBuffer[opb_index] |= (char) (_data16 << k); \\\n            bits_left = k; \\\n        } \\\n    } while (0)\n\n/*****************************************************************************\n                     insert 16 bits into outputBuffer\n******************************************************************************/\n#define insert_16_bits(_data16) \\\n    do \\\n    { \\\n        i = 16 - bits_left; \\\n        j = i - 8; \\\n        k = 8 - j; \\\n        outputBuffer[opb_index++] |= (char) (_data16 >> i); \\\n        outputBuffer[opb_index++] |= (char) (_data16 >> j); \\\n        outputBuffer[opb_index] |= (char) (_data16 << k); \\\n        bits_left = k; \\\n    } while (0)\n\n/**\n * Initialize mppc_enc structure\n *\n * @param   protocol_type   PROTO_RDP_40 or PROTO_RDP_50\n *\n * @return  struct xrdp_mppc_enc* or nil on failure\n */\n\nstruct xrdp_mppc_enc *\nmppc_enc_new(int protocol_type)\n{\n    struct xrdp_mppc_enc *enc;\n\n    enc = (struct xrdp_mppc_enc *) g_malloc(sizeof(struct xrdp_mppc_enc), 1);\n\n    if (enc == 0)\n    {\n        return 0;\n    }\n\n    switch (protocol_type)\n    {\n        case PROTO_RDP_40:\n            enc->protocol_type = PROTO_RDP_40;\n            enc->buf_len = RDP_40_HIST_BUF_LEN;\n            break;\n\n        case PROTO_RDP_50:\n            enc->protocol_type = PROTO_RDP_50;\n            enc->buf_len = RDP_50_HIST_BUF_LEN;\n            break;\n\n        default:\n            g_free(enc);\n            return 0;\n    }\n\n    enc->flagsHold = PACKET_AT_FRONT;\n    enc->historyBuffer = (char *) g_malloc(enc->buf_len, 1);\n\n    if (enc->historyBuffer == 0)\n    {\n        g_free(enc);\n        return 0;\n    }\n\n    enc->outputBufferPlus = (char *) g_malloc(enc->buf_len + 64, 1);\n\n    if (enc->outputBufferPlus == 0)\n    {\n        g_free(enc->historyBuffer);\n        g_free(enc);\n        return 0;\n    }\n\n    enc->outputBuffer = enc->outputBufferPlus + 64;\n    enc->hash_table = (tui16 *) g_malloc(enc->buf_len * 2, 1);\n\n    if (enc->hash_table == 0)\n    {\n        g_free(enc->historyBuffer);\n        g_free(enc->outputBufferPlus);\n        g_free(enc);\n        return 0;\n    }\n\n    return enc;\n}\n\n/**\n * deinit mppc_enc structure\n *\n * @param   enc  struct to be deinited\n */\n\nvoid\nmppc_enc_free(struct xrdp_mppc_enc *enc)\n{\n    if (enc == 0)\n    {\n        return;\n    }\n    g_free(enc->historyBuffer);\n    g_free(enc->outputBufferPlus);\n    g_free(enc->hash_table);\n    g_free(enc);\n}\n\n/**\n * encode (compress) data using RDP 4.0 protocol\n *\n * @param   enc           encoder state info\n * @param   srcData       uncompressed data\n * @param   len           length of srcData\n *\n * @return  TRUE on success, FALSE on failure\n */\n\nstatic int\ncompress_rdp_4(struct xrdp_mppc_enc *enc, tui8 *srcData, int len)\n{\n    /* RDP 4.0 encoding not yet implemented */\n    return 0;\n}\n\n/**\n * encode (compress) data using RDP 5.0 protocol using hash table\n *\n * @param   enc           encoder state info\n * @param   srcData       uncompressed data\n * @param   len           length of srcData\n *\n * @return  TRUE on success, FALSE on failure\n */\n\nstatic int\ncompress_rdp_5(struct xrdp_mppc_enc *enc, tui8 *srcData, int len)\n{\n    char *outputBuffer;     /* points to enc->outputBuffer */\n    char *hptr_end;         /* points to end of history data */\n    char *historyPointer;   /* points to first byte of srcData in\n                             * historyBuffer */\n    char *hbuf_start;       /* points to start of history buffer */\n    char *cptr1;\n    char *cptr2;\n    int opb_index;          /* index into outputBuffer */\n    int bits_left;          /* unused bits in current byte in outputBuffer */\n    tui32 copy_offset;      /* pattern match starts here... */\n    tui32 lom;              /* ...and matches this many bytes */\n    int last_crc_index;     /* don't compute CRC beyond this index */\n    tui16 *hash_table;      /* hash table for pattern matching */\n\n    tui32 i;\n    tui32 j;\n    tui32 k;\n    tui32 x;\n    tui8 data;\n    tui16 data16;\n    tui32 historyOffset;\n    tui16 crc;\n    tui32 ctr;\n    tui32 saved_ctr;\n    tui32 data_end;\n    tui8 byte_val;\n\n    lom = 0;\n    ctr = 0;\n    opb_index = 0;\n    bits_left = 8;\n    hash_table = enc->hash_table;\n    hbuf_start = enc->historyBuffer;\n    outputBuffer = enc->outputBuffer;\n    g_memset(outputBuffer, 0, len);\n    enc->flags = PACKET_COMPR_TYPE_64K;\n\n    if ((enc->historyOffset + len) >= enc->buf_len - 3)\n    {\n        /* historyBuffer cannot hold srcData - rewind it */\n        enc->historyOffset = 0;\n        g_memset(hash_table, 0, enc->buf_len * 2);\n        g_memset(enc->historyBuffer, 0, enc->buf_len); // added\n        enc->flagsHold |= PACKET_AT_FRONT | PACKET_FLUSHED;\n    }\n\n    /* point to next free byte in historyBuffer */\n    historyOffset = enc->historyOffset;\n\n    /* add / append new data to historyBuffer */\n    g_memcpy(&(enc->historyBuffer[historyOffset]), srcData, len);\n\n    /* point to start of data to be compressed */\n    historyPointer = &(enc->historyBuffer[historyOffset]);\n\n    /* if we are at start of history buffer, do not attempt to compress */\n    /* first 2 bytes, because minimum LoM is 3                          */\n    if (historyOffset == 0)\n    {\n        /* encode first two bytes as literals */\n        for (x = 0; x < 2; x++)\n        {\n            data = *(historyPointer + x);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"%.2x \", (tui8) data);\n            if (data & 0x80)\n            {\n                /* insert encoded literal */\n                insert_2_bits(0x02);\n                data &= 0x7f;\n                insert_7_bits(data);\n            }\n            else\n            {\n                /* insert literal */\n                insert_8_bits(data);\n            }\n        }\n\n        /* store hash for first two entries in historyBuffer */\n        crc = CRC_INIT;\n        byte_val = enc->historyBuffer[0];\n        CRC(crc, byte_val);\n        byte_val = enc->historyBuffer[1];\n        CRC(crc, byte_val);\n        byte_val = enc->historyBuffer[2];\n        CRC(crc, byte_val);\n        hash_table[crc] = 0;\n\n        crc = CRC_INIT;\n        byte_val = enc->historyBuffer[1];\n        CRC(crc, byte_val);\n        byte_val = enc->historyBuffer[2];\n        CRC(crc, byte_val);\n        byte_val = enc->historyBuffer[3];\n        CRC(crc, byte_val);\n        hash_table[crc] = 1;\n\n        /* first two bytes have already been processed */\n        ctr = 2;\n    }\n\n    enc->historyOffset += len;\n\n    /* point to last byte in new data */\n    hptr_end = &(enc->historyBuffer[enc->historyOffset - 1]);\n\n    /* do not compute CRC beyond this */\n    last_crc_index = enc->historyOffset - 3;\n\n    /* do not search for pattern match beyond this */\n    data_end = len - 2;\n\n    /* start compressing data */\n\n    while (ctr < data_end)\n    {\n        cptr1 = historyPointer + ctr;\n\n        crc = CRC_INIT;\n        byte_val = *cptr1;\n        CRC(crc, byte_val);\n        byte_val = *(cptr1 + 1);\n        CRC(crc, byte_val);\n        byte_val = *(cptr1 + 2);\n        CRC(crc, byte_val);\n\n        /* cptr2 points to start of pattern match */\n        cptr2 = hbuf_start + hash_table[crc];\n        copy_offset = cptr1 - cptr2;\n\n        /* save current entry */\n        hash_table[crc] = cptr1 - hbuf_start;\n\n        /* double check that we have a pattern match */\n        if ((*cptr1 != *cptr2) ||\n                (*(cptr1 + 1) != *(cptr2 + 1)) ||\n                (*(cptr1 + 2) != *(cptr2 + 2)))\n        {\n            /* no match found; encode literal byte */\n            data = *cptr1;\n\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"%.2x \", data);\n            if (data < 0x80)\n            {\n                /* literal byte < 0x80 */\n                insert_8_bits(data);\n            }\n            else\n            {\n                /* literal byte >= 0x80 */\n                insert_2_bits(0x02);\n                data &= 0x7f;\n                insert_7_bits(data);\n            }\n            ctr++;\n            continue;\n        }\n\n        /* we have a match - compute Length of Match */\n        cptr1 += 3;\n        cptr2 += 3;\n        lom = 3;\n        while ((cptr1 <= hptr_end) && (*(cptr1++) == *(cptr2++)))\n        {\n            lom++;\n        }\n        saved_ctr = ctr + lom;\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"<%ld: %u,%d> \",  (historyPointer + ctr) - hbuf_start,\n                  copy_offset, lom);\n\n        /* compute CRC for matching segment and store in hash table */\n\n        cptr1 = historyPointer + ctr;\n        if (cptr1 + lom > hbuf_start + last_crc_index)\n        {\n            /* we have gone beyond last_crc_index - go back */\n            j = last_crc_index - (cptr1 - hbuf_start);\n        }\n        else\n        {\n            j = lom - 1;\n        }\n        ctr++;\n        for (i = 0; i < j; i++)\n        {\n            cptr1 = historyPointer + ctr;\n\n            /* compute CRC on triplet */\n            crc = CRC_INIT;\n            byte_val = *(cptr1++);\n            CRC(crc, byte_val);\n            byte_val = *(cptr1++);\n            CRC(crc, byte_val);\n            byte_val = *(cptr1++);\n            CRC(crc, byte_val);\n\n            /* save current entry */\n            hash_table[crc] = (cptr1 - 3) - hbuf_start;\n\n            /* point to next triplet */\n            ctr++;\n        }\n        ctr = saved_ctr;\n\n        /* encode copy_offset and insert into output buffer */\n\n        if (copy_offset <= 63) /* (copy_offset >= 0) is always true */\n        {\n            /* insert binary header */\n            data = 0x1f;\n            insert_5_bits(data);\n\n            /* insert 6 bits of copy_offset */\n            data = (char) (copy_offset & 0x3f);\n            insert_6_bits(data);\n        }\n        else if ((copy_offset >= 64) && (copy_offset <= 319))\n        {\n            /* insert binary header */\n            data = 0x1e;\n            insert_5_bits(data);\n\n            /* insert 8 bits of copy offset */\n            data = (char) (copy_offset - 64);\n            insert_8_bits(data);\n        }\n        else if ((copy_offset >= 320) && (copy_offset <= 2367))\n        {\n            /* insert binary header */\n            data = 0x0e;\n            insert_4_bits(data);\n\n            /* insert 11 bits of copy offset */\n            data16 = copy_offset - 320;;\n            insert_11_bits(data16);\n        }\n        else\n        {\n            /* copy_offset is 2368+ */\n\n            /* insert binary header */\n            data = 0x06;\n            insert_3_bits(data);\n\n            /* insert 16 bits of copy offset */\n            data16 = copy_offset - 2368;;\n            insert_16_bits(data16);\n        }\n\n        /* encode length of match and insert into output buffer */\n\n        if (lom == 3)\n        {\n            /* binary header is 'zero'; since outputBuffer is zero */\n            /* filled, all we have to do is update bits_left */\n            bits_left--;\n            if (bits_left == 0)\n            {\n                opb_index++;\n                bits_left = 8;\n            }\n        }\n        else if ((lom >= 4) && (lom <= 7))\n        {\n            /* insert binary header */\n            data = 0x02;\n            insert_2_bits(data);\n\n            /* insert lower 2 bits of LoM */\n            data = (char) (lom - 4);\n            insert_2_bits(data);\n        }\n        else if ((lom >= 8) && (lom <= 15))\n        {\n            /* insert binary header */\n            data = 0x06;\n            insert_3_bits(data);\n\n            /* insert lower 3 bits of LoM */\n            data = (char) (lom - 8);\n            insert_3_bits(data);\n        }\n        else if ((lom >= 16) && (lom <= 31))\n        {\n            /* insert binary header */\n            data = 0x0e;\n            insert_4_bits(data);\n\n            /* insert lower 4 bits of LoM */\n            data = (char) (lom - 16);\n            insert_4_bits(data);\n        }\n        else if ((lom >= 32) && (lom <= 63))\n        {\n            /* insert binary header */\n            data = 0x1e;\n            insert_5_bits(data);\n\n            /* insert lower 5 bits of LoM */\n            data = (char) (lom - 32);\n            insert_5_bits(data);\n        }\n        else if ((lom >= 64) && (lom <= 127))\n        {\n            /* insert binary header */\n            data = 0x3e;\n            insert_6_bits(data);\n\n            /* insert lower 6 bits of LoM */\n            data = (char) (lom - 64);\n            insert_6_bits(data);\n        }\n        else if ((lom >= 128) && (lom <= 255))\n        {\n            /* insert binary header */\n            data = 0x7e;\n            insert_7_bits(data);\n\n            /* insert lower 7 bits of LoM */\n            data = (char) (lom - 128);\n            insert_7_bits(data);\n        }\n        else if ((lom >= 256) && (lom <= 511))\n        {\n            /* insert binary header */\n            data = 0xfe;\n            insert_8_bits(data);\n\n            /* insert lower 8 bits of LoM */\n            data = (char) (lom - 256);\n            insert_8_bits(data);\n        }\n        else if ((lom >= 512) && (lom <= 1023))\n        {\n            /* insert binary header */\n            data16 = 0x1fe;\n            insert_9_bits(data16);\n\n            /* insert lower 9 bits of LoM */\n            data16 = lom - 512;\n            insert_9_bits(data16);\n        }\n        else if ((lom >= 1024) && (lom <= 2047))\n        {\n            /* insert binary header */\n            data16 = 0x3fe;\n            insert_10_bits(data16);\n\n            /* insert 10 lower bits of LoM */\n            data16 = lom - 1024;\n            insert_10_bits(data16);\n        }\n        else if ((lom >= 2048) && (lom <= 4095))\n        {\n            /* insert binary header */\n            data16 = 0x7fe;\n            insert_11_bits(data16);\n\n            /* insert 11 lower bits of LoM */\n            data16 = lom - 2048;\n            insert_11_bits(data16);\n        }\n        else if ((lom >= 4096) && (lom <= 8191))\n        {\n            /* insert binary header */\n            data16 = 0xffe;\n            insert_12_bits(data16);\n\n            /* insert 12 lower bits of LoM */\n            data16 = lom - 4096;\n            insert_12_bits(data16);\n        }\n        else if ((lom >= 8192) && (lom <= 16383))\n        {\n            /* insert binary header */\n            data16 = 0x1ffe;\n            insert_13_bits(data16);\n\n            /* insert 13 lower bits of LoM */\n            data16 = lom - 8192;\n            insert_13_bits(data16);\n        }\n        else if ((lom >= 16384) && (lom <= 32767))\n        {\n            /* insert binary header */\n            data16 = 0x3ffe;\n            insert_14_bits(data16);\n\n            /* insert 14 lower bits of LoM */\n            data16 = lom - 16384;\n            insert_14_bits(data16);\n        }\n        else if ((lom >= 32768) && (lom <= 65535))\n        {\n            /* insert binary header */\n            data16 = 0x7ffe;\n            insert_15_bits(data16);\n\n            /* insert 15 lower bits of LoM */\n            data16 = lom - 32768;\n            insert_15_bits(data16);\n        }\n    } /* end while (ctr < data_end) */\n\n    /* add remaining data to the output */\n    while (len - ctr > 0)\n    {\n        data = srcData[ctr];\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"%.2x \", data);\n        if (data < 0x80)\n        {\n            /* literal byte < 0x80 */\n            insert_8_bits(data);\n        }\n        else\n        {\n            /* literal byte >= 0x80 */\n            insert_2_bits(0x02);\n            data &= 0x7f;\n            insert_7_bits(data);\n        }\n        ctr++;\n    }\n\n    /* if bits_left != 8, increment opb_index, which is zero indexed */\n    if (bits_left != 8)\n    {\n        opb_index++;\n    }\n\n    if (opb_index > len)\n    {\n        /* compressed data longer than uncompressed data */\n        /* give up */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"Compression algorithim produced a compressed \"\n                  \"buffer which is larger than the uncompressed buffer. \"\n                  \"compression ratio %f, flags 0x%x\",\n                  (float) len / (float) opb_index, enc->flags);\n        enc->historyOffset = 0;\n        g_memset(hash_table, 0, enc->buf_len * 2);\n        g_memset(enc->historyBuffer, 0, enc->buf_len);\n        enc->flagsHold |= PACKET_AT_FRONT | PACKET_FLUSHED;\n        return 0;\n    }\n\n    enc->flags |= PACKET_COMPRESSED;\n    enc->bytes_in_opb = opb_index;\n\n    enc->flags |= enc->flagsHold;\n    enc->flagsHold = 0;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Compression successful. compression ratio %f, \"\n              \"flags 0x%x, bytes_in_opb %d, historyOffset %d, uncompressed len %d\",\n              (float) len / (float) enc->bytes_in_opb, enc->flags,\n              enc->bytes_in_opb, enc->historyOffset, len);\n    return 1;\n}\n\n/**\n * encode (compress) data\n *\n * @param   enc           encoder state info\n * @param   srcData       uncompressed data\n * @param   len           length of srcData\n *\n * @return  TRUE on success, FALSE on failure\n */\n\nint\ncompress_rdp(struct xrdp_mppc_enc *enc, tui8 *srcData, int len)\n{\n    if ((enc == 0) || (srcData == 0) || (len <= 0) || (len > enc->buf_len))\n    {\n        return 0;\n    }\n\n    switch (enc->protocol_type)\n    {\n        case PROTO_RDP_40:\n            return compress_rdp_4(enc, srcData, len);\n            break;\n\n        case PROTO_RDP_50:\n            return compress_rdp_5(enc, srcData, len);\n            break;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_orders.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * orders\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"ms-rdpegdi.h\"\n\n#if defined(XRDP_NEUTRINORDP)\n#include <freerdp/codec/rfx.h>\n#endif\n\n\n\n#define MAX_ORDERS_SIZE(_client_info) \\\n    (MAX((_client_info)->max_fastpath_frag_bytes, 16 * 1024) - 256);\n\n/*****************************************************************************/\nstruct xrdp_orders *\nxrdp_orders_create(struct xrdp_session *session, struct xrdp_rdp *rdp_layer)\n{\n    struct xrdp_orders *self;\n\n    self = (struct xrdp_orders *)g_malloc(sizeof(struct xrdp_orders), 1);\n    self->session = session;\n    self->rdp_layer = rdp_layer;\n    make_stream(self->out_s);\n    init_stream(self->out_s, 32 * 1024);\n    self->orders_state.clip_right = 1; /* silly rdp right clip */\n    self->orders_state.clip_bottom = 1; /* silly rdp bottom clip */\n    self->jpeg_han = xrdp_jpeg_init();\n    self->rfx_min_pixel = rdp_layer->client_info.rfx_min_pixel;\n    if (self->rfx_min_pixel == 0)\n    {\n        self->rfx_min_pixel = 64 * 32;\n    }\n    make_stream(self->s);\n    make_stream(self->temp_s);\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_orders_delete(struct xrdp_orders *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n    xrdp_jpeg_deinit(self->jpeg_han);\n    free_stream(self->out_s);\n    free_stream(self->s);\n    free_stream(self->temp_s);\n    g_free(self->orders_state.text_data);\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* set all values to zero */\n/* returns error */\nint\nxrdp_orders_reset(struct xrdp_orders *self)\n{\n    if (xrdp_orders_force_send(self) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_orders_reset: xrdp_orders_force_send failed\");\n        return 1;\n    }\n    g_free(self->orders_state.text_data);\n    g_memset(&(self->orders_state), 0, sizeof(self->orders_state));\n    self->order_count_ptr = 0;\n    self->order_count = 0;\n    self->order_level = 0;\n    self->orders_state.clip_right = 1; /* silly rdp right clip */\n    self->orders_state.clip_bottom = 1; /* silly rdp bottom clip */\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_orders_init(struct xrdp_orders *self)\n{\n    self->order_level++;\n    if (self->order_level == 1)\n    {\n        self->order_count = 0;\n        if (self->rdp_layer->client_info.use_fast_path & 1)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_orders_init: fastpath\");\n            if (xrdp_rdp_init_fastpath(self->rdp_layer, self->out_s) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"xrdp_orders_init: xrdp_rdp_init_fastpath failed\");\n                return 1;\n            }\n            self->order_count_ptr = self->out_s->p;\n            out_uint8s(self->out_s, 2); /* number of orders, set later */\n            // LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] TODO\");\n        }\n        else\n        {\n            if (xrdp_rdp_init_data(self->rdp_layer, self->out_s) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"xrdp_orders_init: xrdp_rdp_init_data failed\");\n                return 1;\n            }\n            out_uint16_le(self->out_s, UPDATETYPE_ORDERS); /* updateType */\n            out_uint8s(self->out_s, 2); /* pad */\n            self->order_count_ptr = self->out_s->p;\n            out_uint8s(self->out_s, 2); /* number of orders, set later */\n            out_uint8s(self->out_s, 2); /* pad */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] TS_UPDATE_ORDERS_PDU_DATA \"\n                      \"updateType %d (UPDATETYPE_ORDERS), pad2OctetsA <ignored>, \"\n                      \"numberOrders <to be set later>, pad2OctetsB <ignored>\",\n                      UPDATETYPE_ORDERS);\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_orders_send(struct xrdp_orders *self)\n{\n    int rv;\n\n    rv = 0;\n    if (self->order_level > 0)\n    {\n        self->order_level--;\n        if ((self->order_level == 0) && (self->order_count > 0))\n        {\n            s_mark_end(self->out_s);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_orders_send sending %d orders\", self->order_count);\n            self->order_count_ptr[0] = self->order_count;\n            self->order_count_ptr[1] = self->order_count >> 8;\n            self->order_count = 0;\n            if (self->rdp_layer->client_info.use_fast_path & 1)\n            {\n                if (xrdp_rdp_send_fastpath(self->rdp_layer,\n                                           self->out_s, 0) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"xrdp_orders_send: xrdp_rdp_send_fastpath failed\");\n                    rv = 1;\n                }\n            }\n            else\n            {\n                if (xrdp_rdp_send_data(self->rdp_layer, self->out_s,\n                                       PDUTYPE2_UPDATE) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"xrdp_orders_send: xrdp_rdp_send_data failed\");\n                    rv = 1;\n                }\n            }\n        }\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_orders_force_send(struct xrdp_orders *self)\n{\n    if (self == 0)\n    {\n        return 1;\n    }\n    if ((self->order_level > 0) && (self->order_count > 0))\n    {\n        s_mark_end(self->out_s);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_orders_force_send sending %d orders\", self->order_count);\n        self->order_count_ptr[0] = self->order_count;\n        self->order_count_ptr[1] = self->order_count >> 8;\n        if (self->rdp_layer->client_info.use_fast_path & 1)\n        {\n            if (xrdp_rdp_send_fastpath(self->rdp_layer,\n                                       self->out_s, FASTPATH_UPDATETYPE_ORDERS) != 0)\n            {\n                return 1;\n            }\n        }\n        else\n        {\n            if (xrdp_rdp_send_data(self->rdp_layer, self->out_s,\n                                   PDUTYPE2_UPDATE) != 0)\n            {\n                return 1;\n            }\n        }\n    }\n    self->order_count = 0;\n    self->order_level = 0;\n    return 0;\n}\n\n/*****************************************************************************/\n/* check if the current order will fit in packet size of 16384, if not */\n/* send what we got and init a new one */\n/* returns error */\nint\nxrdp_orders_check(struct xrdp_orders *self, int max_size)\n{\n    int size;\n    int max_order_size;\n    struct xrdp_client_info *ci;\n\n    ci = &(self->rdp_layer->client_info);\n    max_order_size = MAX_ORDERS_SIZE(ci);\n\n    if (self->order_level < 1)\n    {\n        if (max_size > max_order_size)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Requested orders max_size (%d) \"\n                \"is greater than the client connection max_size (%d)\",\n                max_size, max_order_size);\n            return 1;\n        }\n        else\n        {\n            xrdp_orders_init(self);\n            return 0;\n        }\n    }\n\n    size = (int)(self->out_s->p - self->order_count_ptr);\n    if (size < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Bug: order data length cannot be negative. \"\n            \"Found length %d bytes\", size);\n        return 1;\n    }\n    if (size > max_order_size)\n    {\n        /* this suggests someone calls this function without passing the\n           correct max_size so we end up putting more into the buffer\n           than we indicate we can */\n        LOG(LOG_LEVEL_WARNING, \"Ignoring Bug: order data length \"\n            \"is larger than maximum length. Expected %d, actual %d\",\n            max_order_size, size);\n        /* We where getting called with size already greater than\n           max_order_size\n           Which I suspect was because the sending of text did not include\n           the text len to check the buffer size. So attempt to send the data\n           anyway.\n           Lets write the data anyway, somewhere else may barf. */\n        /*    return 1; */\n    }\n\n    if ((size + max_size + 100) > max_order_size)\n    {\n        xrdp_orders_force_send(self);\n        xrdp_orders_init(self);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* check if rect is the same as the last one sent */\n/* returns boolean */\nstatic int\nxrdp_orders_last_bounds(struct xrdp_orders *self, struct xrdp_rect *rect)\n{\n    if (rect == 0)\n    {\n        return 0;\n    }\n\n    if ((rect->left == self->orders_state.clip_left) &&\n            (rect->top == self->orders_state.clip_top) &&\n            (rect->right == self->orders_state.clip_right) &&\n            (rect->bottom == self->orders_state.clip_bottom))\n    {\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* check if all coords are within 256 bytes */\n/* returns boolean */\nstatic int\nxrdp_orders_send_delta(struct xrdp_orders *self, int *vals, int count)\n{\n    int i;\n\n    for (i = 0; i < count; i += 2)\n    {\n        if (g_abs(vals[i] - vals[i + 1]) >= 128)\n        {\n            return 0;\n        }\n    }\n\n    return 1;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_orders_out_bounds(struct xrdp_orders *self, struct xrdp_rect *rect)\n{\n    char *bounds_flags_ptr;\n    int bounds_flags;\n\n    bounds_flags = 0;\n    bounds_flags_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    /* left */\n    if (rect->left == self->orders_state.clip_left)\n    {\n    }\n    else if (g_abs(rect->left - self->orders_state.clip_left) < 128)\n    {\n        bounds_flags |= 0x10;\n    }\n    else\n    {\n        bounds_flags |= 0x01;\n    }\n\n    /* top */\n    if (rect->top == self->orders_state.clip_top)\n    {\n    }\n    else if (g_abs(rect->top - self->orders_state.clip_top) < 128)\n    {\n        bounds_flags |= 0x20;\n    }\n    else\n    {\n        bounds_flags |= 0x02;\n    }\n\n    /* right */\n    if (rect->right == self->orders_state.clip_right)\n    {\n    }\n    else if (g_abs(rect->right - self->orders_state.clip_right) < 128)\n    {\n        bounds_flags |= 0x40;\n    }\n    else\n    {\n        bounds_flags |= 0x04;\n    }\n\n    /* bottom */\n    if (rect->bottom == self->orders_state.clip_bottom)\n    {\n    }\n    else if (g_abs(rect->bottom - self->orders_state.clip_bottom) < 128)\n    {\n        bounds_flags |= 0x80;\n    }\n    else\n    {\n        bounds_flags |= 0x08;\n    }\n\n    /* left */\n    if (bounds_flags & 0x01)\n    {\n        out_uint16_le(self->out_s, rect->left);\n    }\n    else if (bounds_flags & 0x10)\n    {\n        out_uint8(self->out_s, rect->left - self->orders_state.clip_left);\n    }\n\n    self->orders_state.clip_left = rect->left;\n\n    /* top */\n    if (bounds_flags & 0x02)\n    {\n        out_uint16_le(self->out_s, rect->top);\n    }\n    else if (bounds_flags & 0x20)\n    {\n        out_uint8(self->out_s, rect->top - self->orders_state.clip_top);\n    }\n\n    self->orders_state.clip_top = rect->top;\n\n    /* right */\n    if (bounds_flags & 0x04)\n    {\n        /* silly rdp right clip */\n        out_uint16_le(self->out_s, rect->right - 1);\n    }\n    else if (bounds_flags & 0x40)\n    {\n        out_uint8(self->out_s, rect->right - self->orders_state.clip_right);\n    }\n\n    self->orders_state.clip_right = rect->right;\n\n    /* bottom */\n    if (bounds_flags & 0x08)\n    {\n        /* silly rdp bottom clip */\n        out_uint16_le(self->out_s, rect->bottom - 1);\n    }\n    else if (bounds_flags & 0x80)\n    {\n        out_uint8(self->out_s, rect->bottom - self->orders_state.clip_bottom);\n    }\n\n    self->orders_state.clip_bottom = rect->bottom;\n    /* set flags */\n    *bounds_flags_ptr = bounds_flags;\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_order_pack_small_or_tiny(struct xrdp_orders *self,\n                              char *order_flags_ptr, int orders_flags,\n                              char *present_ptr, int present,\n                              int present_size)\n{\n    int move_up_count = 0;\n    int index = 0;\n    int size;\n    int keep_looking = 1;\n\n    move_up_count = 0;\n    keep_looking = 1;\n\n    for (index = present_size - 1; index >= 0; index--)\n    {\n        if (keep_looking)\n        {\n            if (((present >> (index * 8)) & 0xff) == 0)\n            {\n                move_up_count++;\n            }\n            else\n            {\n                keep_looking = 0;\n            }\n        }\n\n        present_ptr[index] = present >> (index * 8);\n    }\n\n    if (move_up_count > 0)\n    {\n        /* move_up_count should be 0, 1, 2, or 3\n           shifting it 6 will make it RDP_ORDER_TINY(0x80) or\n           RDP_ORDER_SMALL(0x40) or both */\n        orders_flags |= move_up_count << 6;\n        size = (int)(self->out_s->p - present_ptr);\n        size -= present_size;\n\n        for (index = 0; index < size; index++)\n        {\n            present_ptr[index + (present_size - move_up_count)] =\n                present_ptr[index + present_size];\n        }\n\n        self->out_s->p -= move_up_count;\n    }\n\n    order_flags_ptr[0] = orders_flags;\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* send a solid rect to client */\n/* max size 23 */\nint\nxrdp_orders_rect(struct xrdp_orders *self, int x, int y, int cx, int cy,\n                 int color, struct xrdp_rect *rect)\n{\n    int order_flags;\n    int vals[8];\n    int present;\n    char *present_ptr;\n    char *order_flags_ptr;\n\n    if (xrdp_orders_check(self, 23) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD;\n\n    if (self->orders_state.last_order != RDP_ORDER_RECT)\n    {\n        order_flags |= TS_TYPE_CHANGE;\n    }\n\n    self->orders_state.last_order = RDP_ORDER_RECT;\n\n    if (rect != 0)\n    {\n        /* if clip is present, still check if it's needed */\n        if (x < rect->left || y < rect->top ||\n                x + cx > rect->right || y + cy > rect->bottom)\n        {\n            order_flags |= TS_BOUNDS;\n\n            if (xrdp_orders_last_bounds(self, rect))\n            {\n                order_flags |= TS_ZERO_BOUNDS_DELTAS;\n            }\n        }\n    }\n\n    vals[0] = x;\n    vals[1] = self->orders_state.rect_x;\n    vals[2] = y;\n    vals[3] = self->orders_state.rect_y;\n    vals[4] = cx;\n    vals[5] = self->orders_state.rect_cx;\n    vals[6] = cy;\n    vals[7] = self->orders_state.rect_cy;\n\n    if (xrdp_orders_send_delta(self, vals, 8))\n    {\n        order_flags |= TS_DELTA_COORDINATES;\n    }\n\n    /* order_flags, set later, 1 byte */\n    order_flags_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if (order_flags & TS_TYPE_CHANGE)\n    {\n        out_uint8(self->out_s, self->orders_state.last_order);\n    }\n\n    present = 0;\n    /* present, set later, 1 byte */\n    present_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if ((order_flags & TS_BOUNDS) &&\n            !(order_flags & TS_ZERO_BOUNDS_DELTAS))\n    {\n        xrdp_orders_out_bounds(self, rect);\n    }\n\n    if (x != self->orders_state.rect_x)\n    {\n        present |= 0x01;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, x - self->orders_state.rect_x);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, x);\n        }\n\n        self->orders_state.rect_x = x;\n    }\n\n    if (y != self->orders_state.rect_y)\n    {\n        present |= 0x02;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, y - self->orders_state.rect_y);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, y);\n        }\n\n        self->orders_state.rect_y = y;\n    }\n\n    if (cx != self->orders_state.rect_cx)\n    {\n        present |= 0x04;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cx - self->orders_state.rect_cx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cx);\n        }\n\n        self->orders_state.rect_cx = cx;\n    }\n\n    if (cy != self->orders_state.rect_cy)\n    {\n        present |= 0x08;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cy - self->orders_state.rect_cy);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cy);\n        }\n\n        self->orders_state.rect_cy = cy;\n    }\n\n    if ((color & 0xff) != (self->orders_state.rect_color & 0xff))\n    {\n        present |= 0x10;\n        self->orders_state.rect_color =\n            (self->orders_state.rect_color & 0xffff00) | (color & 0xff);\n        out_uint8(self->out_s, color);\n    }\n\n    if ((color & 0xff00) != (self->orders_state.rect_color & 0xff00))\n    {\n        present |= 0x20;\n        self->orders_state.rect_color =\n            (self->orders_state.rect_color & 0xff00ff) | (color & 0xff00);\n        out_uint8(self->out_s, color >> 8);\n    }\n\n    if ((color & 0xff0000) != (self->orders_state.rect_color & 0xff0000))\n    {\n        present |= 0x40;\n        self->orders_state.rect_color =\n            (self->orders_state.rect_color & 0x00ffff) | (color & 0xff0000);\n        out_uint8(self->out_s, color >> 16);\n    }\n\n    xrdp_order_pack_small_or_tiny(self, order_flags_ptr, order_flags,\n                                  present_ptr, present, 1);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* send a screen blt order */\n/* max size 25 */\nint\nxrdp_orders_screen_blt(struct xrdp_orders *self, int x, int y,\n                       int cx, int cy, int srcx, int srcy,\n                       int rop, struct xrdp_rect *rect)\n{\n    int order_flags = 0;\n    int vals[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\n    int present = 0;\n    char *present_ptr = (char *)NULL;\n    char *order_flags_ptr = (char *)NULL;\n\n    if (xrdp_orders_check(self, 25) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD;\n\n    if (self->orders_state.last_order != RDP_ORDER_SCREENBLT)\n    {\n        order_flags |= TS_TYPE_CHANGE;\n    }\n\n    self->orders_state.last_order = RDP_ORDER_SCREENBLT;\n\n    if (rect != 0)\n    {\n        /* if clip is present, still check if it's needed */\n        if (x < rect->left || y < rect->top ||\n                x + cx > rect->right || y + cy > rect->bottom)\n        {\n            order_flags |= TS_BOUNDS;\n\n            if (xrdp_orders_last_bounds(self, rect))\n            {\n                order_flags |= TS_ZERO_BOUNDS_DELTAS;\n            }\n        }\n    }\n\n    vals[0] = x;\n    vals[1] = self->orders_state.scr_blt_x;\n    vals[2] = y;\n    vals[3] = self->orders_state.scr_blt_y;\n    vals[4] = cx;\n    vals[5] = self->orders_state.scr_blt_cx;\n    vals[6] = cy;\n    vals[7] = self->orders_state.scr_blt_cy;\n    vals[8] = srcx;\n    vals[9] = self->orders_state.scr_blt_srcx;\n    vals[10] = srcy;\n    vals[11] = self->orders_state.scr_blt_srcy;\n\n    if (xrdp_orders_send_delta(self, vals, 12))\n    {\n        order_flags |= TS_DELTA_COORDINATES;\n    }\n\n    /* order_flags, set later, 1 byte */\n    order_flags_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if (order_flags & TS_TYPE_CHANGE)\n    {\n        out_uint8(self->out_s, self->orders_state.last_order);\n    }\n\n    present = 0;\n    /* present, set later, 1 byte */\n    present_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if ((order_flags & TS_BOUNDS) &&\n            !(order_flags & TS_ZERO_BOUNDS_DELTAS))\n    {\n        xrdp_orders_out_bounds(self, rect);\n    }\n\n    if (x != self->orders_state.scr_blt_x)\n    {\n        present |= 0x01;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, x - self->orders_state.scr_blt_x);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, x);\n        }\n\n        self->orders_state.scr_blt_x = x;\n    }\n\n    if (y != self->orders_state.scr_blt_y)\n    {\n        present |= 0x02;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, y - self->orders_state.scr_blt_y);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, y);\n        }\n\n        self->orders_state.scr_blt_y = y;\n    }\n\n    if (cx != self->orders_state.scr_blt_cx)\n    {\n        present |= 0x04;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cx - self->orders_state.scr_blt_cx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cx);\n        }\n\n        self->orders_state.scr_blt_cx = cx;\n    }\n\n    if (cy != self->orders_state.scr_blt_cy)\n    {\n        present |= 0x08;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cy - self->orders_state.scr_blt_cy);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cy);\n        }\n\n        self->orders_state.scr_blt_cy = cy;\n    }\n\n    if (rop != self->orders_state.scr_blt_rop)\n    {\n        present |= 0x10;\n        out_uint8(self->out_s, rop);\n        self->orders_state.scr_blt_rop = rop;\n    }\n\n    if (srcx != self->orders_state.scr_blt_srcx)\n    {\n        present |= 0x20;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, srcx - self->orders_state.scr_blt_srcx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, srcx);\n        }\n\n        self->orders_state.scr_blt_srcx = srcx;\n    }\n\n    if (srcy != self->orders_state.scr_blt_srcy)\n    {\n        present |= 0x40;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, srcy - self->orders_state.scr_blt_srcy);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, srcy);\n        }\n\n        self->orders_state.scr_blt_srcy = srcy;\n    }\n\n    xrdp_order_pack_small_or_tiny(self, order_flags_ptr, order_flags,\n                                  present_ptr, present, 1);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* send a pat blt order */\n/* max size 39 */\nint\nxrdp_orders_pat_blt(struct xrdp_orders *self, int x, int y,\n                    int cx, int cy, int rop, int bg_color,\n                    int fg_color, struct xrdp_brush *brush,\n                    struct xrdp_rect *rect)\n{\n    int order_flags;\n    int present;\n    int vals[8];\n    char *present_ptr;\n    char *order_flags_ptr;\n    struct xrdp_brush blank_brush;\n\n    if (xrdp_orders_check(self, 39) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD;\n\n    if (self->orders_state.last_order != RDP_ORDER_PATBLT)\n    {\n        order_flags |= TS_TYPE_CHANGE;\n    }\n\n    self->orders_state.last_order = RDP_ORDER_PATBLT;\n\n    if (rect != 0)\n    {\n        /* if clip is present, still check if it's needed */\n        if (x < rect->left || y < rect->top ||\n                x + cx > rect->right || y + cy > rect->bottom)\n        {\n            order_flags |= TS_BOUNDS;\n\n            if (xrdp_orders_last_bounds(self, rect))\n            {\n                order_flags |= TS_ZERO_BOUNDS_DELTAS;\n            }\n        }\n    }\n\n    vals[0] = x;\n    vals[1] = self->orders_state.pat_blt_x;\n    vals[2] = y;\n    vals[3] = self->orders_state.pat_blt_y;\n    vals[4] = cx;\n    vals[5] = self->orders_state.pat_blt_cx;\n    vals[6] = cy;\n    vals[7] = self->orders_state.pat_blt_cy;\n\n    if (xrdp_orders_send_delta(self, vals, 8))\n    {\n        order_flags |= TS_DELTA_COORDINATES;\n    }\n\n    /* order_flags, set later, 1 byte */\n    order_flags_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if (order_flags & TS_TYPE_CHANGE)\n    {\n        out_uint8(self->out_s, self->orders_state.last_order);\n    }\n\n    present = 0;\n    /* present, set later, 2 bytes */\n    present_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 2);\n\n    if ((order_flags & TS_BOUNDS) &&\n            !(order_flags & TS_ZERO_BOUNDS_DELTAS))\n    {\n        xrdp_orders_out_bounds(self, rect);\n    }\n\n    if (x != self->orders_state.pat_blt_x)\n    {\n        present |= 0x0001;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, x - self->orders_state.pat_blt_x);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, x);\n        }\n\n        self->orders_state.pat_blt_x = x;\n    }\n\n    if (y != self->orders_state.pat_blt_y)\n    {\n        present |= 0x0002;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, y - self->orders_state.pat_blt_y);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, y);\n        }\n\n        self->orders_state.pat_blt_y = y;\n    }\n\n    if (cx != self->orders_state.pat_blt_cx)\n    {\n        present |= 0x0004;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cx - self->orders_state.pat_blt_cx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cx);\n        }\n\n        self->orders_state.pat_blt_cx = cx;\n    }\n\n    if (cy != self->orders_state.pat_blt_cy)\n    {\n        present |= 0x0008;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cy - self->orders_state.pat_blt_cy);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cy);\n        }\n\n        self->orders_state.pat_blt_cy = cy;\n    }\n\n    if (rop != self->orders_state.pat_blt_rop)\n    {\n        present |= 0x0010;\n        /* PATCOPY PATPAINT PATINVERT DSTINVERT BLACKNESS WHITENESS */\n        out_uint8(self->out_s, rop);\n        self->orders_state.pat_blt_rop = rop;\n    }\n\n    if (bg_color != self->orders_state.pat_blt_bg_color)\n    {\n        present |= 0x0020;\n        out_uint8(self->out_s, bg_color);\n        out_uint8(self->out_s, bg_color >> 8);\n        out_uint8(self->out_s, bg_color >> 16);\n        self->orders_state.pat_blt_bg_color = bg_color;\n    }\n\n    if (fg_color != self->orders_state.pat_blt_fg_color)\n    {\n        present |= 0x0040;\n        out_uint8(self->out_s, fg_color);\n        out_uint8(self->out_s, fg_color >> 8);\n        out_uint8(self->out_s, fg_color >> 16);\n        self->orders_state.pat_blt_fg_color = fg_color;\n    }\n\n    if (brush == 0) /* if nil use blank one */\n    {\n        /* todo can we just set style to zero */\n        g_memset(&blank_brush, 0, sizeof(struct xrdp_brush));\n        brush = &blank_brush;\n    }\n\n    if (brush->x_origin != self->orders_state.pat_blt_brush.x_origin)\n    {\n        present |= 0x0080;\n        out_uint8(self->out_s, brush->x_origin);\n        self->orders_state.pat_blt_brush.x_origin = brush->x_origin;\n    }\n\n    if (brush->y_origin != self->orders_state.pat_blt_brush.y_origin)\n    {\n        present |= 0x0100;\n        out_uint8(self->out_s, brush->y_origin);\n        self->orders_state.pat_blt_brush.y_origin = brush->y_origin;\n    }\n\n    if (brush->style != self->orders_state.pat_blt_brush.style)\n    {\n        present |= 0x0200;\n        out_uint8(self->out_s, brush->style);\n        self->orders_state.pat_blt_brush.style = brush->style;\n    }\n\n    if (brush->pattern[0] != self->orders_state.pat_blt_brush.pattern[0])\n    {\n        present |= 0x0400;\n        out_uint8(self->out_s, brush->pattern[0]);\n        self->orders_state.pat_blt_brush.pattern[0] = brush->pattern[0];\n    }\n\n    if (g_memcmp(brush->pattern + 1,\n                 self->orders_state.pat_blt_brush.pattern + 1, 7) != 0)\n    {\n        present |= 0x0800;\n        out_uint8a(self->out_s, brush->pattern + 1, 7);\n        g_memcpy(self->orders_state.pat_blt_brush.pattern + 1,\n                 brush->pattern + 1, 7);\n    }\n\n    xrdp_order_pack_small_or_tiny(self, order_flags_ptr, order_flags,\n                                  present_ptr, present, 2);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* send a dest blt order */\n/* max size 21 */\nint\nxrdp_orders_dest_blt(struct xrdp_orders *self, int x, int y,\n                     int cx, int cy, int rop,\n                     struct xrdp_rect *rect)\n{\n    int order_flags;\n    int vals[8];\n    int present;\n    char *present_ptr;\n    char *order_flags_ptr;\n\n    if (xrdp_orders_check(self, 21) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD;\n\n    if (self->orders_state.last_order != RDP_ORDER_DESTBLT)\n    {\n        order_flags |= TS_TYPE_CHANGE;\n    }\n\n    self->orders_state.last_order = RDP_ORDER_DESTBLT;\n\n    if (rect != 0)\n    {\n        /* if clip is present, still check if it's needed */\n        if (x < rect->left || y < rect->top ||\n                x + cx > rect->right || y + cy > rect->bottom)\n        {\n            order_flags |= TS_BOUNDS;\n\n            if (xrdp_orders_last_bounds(self, rect))\n            {\n                order_flags |= TS_ZERO_BOUNDS_DELTAS;\n            }\n        }\n    }\n\n    vals[0] = x;\n    vals[1] = self->orders_state.dest_blt_x;\n    vals[2] = y;\n    vals[3] = self->orders_state.dest_blt_y;\n    vals[4] = cx;\n    vals[5] = self->orders_state.dest_blt_cx;\n    vals[6] = cy;\n    vals[7] = self->orders_state.dest_blt_cy;\n\n    if (xrdp_orders_send_delta(self, vals, 8))\n    {\n        order_flags |= TS_DELTA_COORDINATES;\n    }\n\n    /* order_flags, set later, 1 byte */\n    order_flags_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if (order_flags & TS_TYPE_CHANGE)\n    {\n        out_uint8(self->out_s, self->orders_state.last_order);\n    }\n\n    present = 0;\n    /* present, set later, 1 byte */\n    present_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if ((order_flags & TS_BOUNDS) &&\n            !(order_flags & TS_ZERO_BOUNDS_DELTAS))\n    {\n        xrdp_orders_out_bounds(self, rect);\n    }\n\n    if (x != self->orders_state.dest_blt_x)\n    {\n        present |= 0x01;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, x - self->orders_state.dest_blt_x);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, x);\n        }\n\n        self->orders_state.dest_blt_x = x;\n    }\n\n    if (y != self->orders_state.dest_blt_y)\n    {\n        present |= 0x02;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, y - self->orders_state.dest_blt_y);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, y);\n        }\n\n        self->orders_state.dest_blt_y = y;\n    }\n\n    if (cx != self->orders_state.dest_blt_cx)\n    {\n        present |= 0x04;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cx - self->orders_state.dest_blt_cx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cx);\n        }\n\n        self->orders_state.dest_blt_cx = cx;\n    }\n\n    if (cy != self->orders_state.dest_blt_cy)\n    {\n        present |= 0x08;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cy - self->orders_state.dest_blt_cy);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cy);\n        }\n\n        self->orders_state.dest_blt_cy = cy;\n    }\n\n    if (rop != self->orders_state.dest_blt_rop)\n    {\n        present |= 0x10;\n        out_uint8(self->out_s, rop);\n        self->orders_state.dest_blt_rop = rop;\n    }\n\n    xrdp_order_pack_small_or_tiny(self, order_flags_ptr, order_flags,\n                                  present_ptr, present, 1);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* send a line order */\n/* max size 32 */\nint\nxrdp_orders_line(struct xrdp_orders *self, int mix_mode,\n                 int startx, int starty,\n                 int endx, int endy, int rop, int bg_color,\n                 struct xrdp_pen *pen,\n                 struct xrdp_rect *rect)\n{\n    int order_flags = 0;\n    int vals[8] = {0, 0, 0, 0, 0, 0, 0, 0};\n    int present = 0;\n    char *present_ptr = (char *)NULL;\n    char *order_flags_ptr = (char *)NULL;\n    struct xrdp_pen blank_pen;\n\n    g_memset(&blank_pen, 0, sizeof(struct xrdp_pen));\n\n    /* if mix mode or rop are out of range, mstsc build 6000+ will parse the\n       orders wrong */\n    if ((mix_mode < 1) || (mix_mode > 2)) /* TRANSPARENT(1) or OPAQUE(2) */\n    {\n        mix_mode = 1;\n    }\n\n    if ((rop < 1) || (rop > 0x10))\n    {\n        rop = 0x0d; /* R2_COPYPEN */\n    }\n\n    if (xrdp_orders_check(self, 32) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD;\n\n    if (self->orders_state.last_order != RDP_ORDER_LINE)\n    {\n        order_flags |= TS_TYPE_CHANGE;\n    }\n\n    self->orders_state.last_order = RDP_ORDER_LINE;\n\n    if (rect != 0)\n    {\n        /* if clip is present, still check if it's needed */\n        if (MIN(endx, startx) < rect->left ||\n                MIN(endy, starty) < rect->top ||\n                MAX(endx, startx) >= rect->right ||\n                MAX(endy, starty) >= rect->bottom)\n        {\n            order_flags |= TS_BOUNDS;\n\n            if (xrdp_orders_last_bounds(self, rect))\n            {\n                order_flags |= TS_ZERO_BOUNDS_DELTAS;\n            }\n        }\n    }\n\n    vals[0] = startx;\n    vals[1] = self->orders_state.line_startx;\n    vals[2] = starty;\n    vals[3] = self->orders_state.line_starty;\n    vals[4] = endx;\n    vals[5] = self->orders_state.line_endx;\n    vals[6] = endy;\n    vals[7] = self->orders_state.line_endy;\n\n    if (xrdp_orders_send_delta(self, vals, 8))\n    {\n        order_flags |= TS_DELTA_COORDINATES;\n    }\n\n    /* order_flags, set later, 1 byte */\n    order_flags_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if (order_flags & TS_TYPE_CHANGE)\n    {\n        out_uint8(self->out_s, self->orders_state.last_order);\n    }\n\n    present = 0;\n    /* present, set later, 2 bytes */\n    present_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 2);\n\n    if ((order_flags & TS_BOUNDS) &&\n            !(order_flags & TS_ZERO_BOUNDS_DELTAS))\n    {\n        xrdp_orders_out_bounds(self, rect);\n    }\n\n    if (mix_mode != self->orders_state.line_mix_mode)\n    {\n        present |= 0x0001;\n        out_uint16_le(self->out_s, mix_mode);\n        self->orders_state.line_mix_mode = mix_mode;\n    }\n\n    if (startx != self->orders_state.line_startx)\n    {\n        present |= 0x0002;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, startx - self->orders_state.line_startx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, startx);\n        }\n\n        self->orders_state.line_startx = startx;\n    }\n\n    if (starty != self->orders_state.line_starty)\n    {\n        present |= 0x0004;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, starty - self->orders_state.line_starty);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, starty);\n        }\n\n        self->orders_state.line_starty = starty;\n    }\n\n    if (endx != self->orders_state.line_endx)\n    {\n        present |= 0x0008;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, endx - self->orders_state.line_endx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, endx);\n        }\n\n        self->orders_state.line_endx = endx;\n    }\n\n    if (endy != self->orders_state.line_endy)\n    {\n        present |= 0x0010;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, endy - self->orders_state.line_endy);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, endy);\n        }\n\n        self->orders_state.line_endy = endy;\n    }\n\n    if (bg_color != self->orders_state.line_bg_color)\n    {\n        present |= 0x0020;\n        out_uint8(self->out_s, bg_color);\n        out_uint8(self->out_s, bg_color >> 8);\n        out_uint8(self->out_s, bg_color >> 16);\n        self->orders_state.line_bg_color = bg_color;\n    }\n\n    if (rop != self->orders_state.line_rop)\n    {\n        present |= 0x0040;\n        out_uint8(self->out_s, rop);\n        self->orders_state.line_rop = rop;\n    }\n\n    if (pen == 0)\n    {\n        g_memset(&blank_pen, 0, sizeof(struct xrdp_pen));\n        pen = &blank_pen;\n    }\n\n    if (pen->style != self->orders_state.line_pen.style)\n    {\n        present |= 0x0080;\n        out_uint8(self->out_s, pen->style);\n        self->orders_state.line_pen.style = pen->style;\n    }\n\n    if (pen->width != self->orders_state.line_pen.width)\n    {\n        present |= 0x0100;\n        out_uint8(self->out_s, pen->width);\n        self->orders_state.line_pen.width = pen->width;\n    }\n\n    if (pen->color != self->orders_state.line_pen.color)\n    {\n        present |= 0x0200;\n        out_uint8(self->out_s, pen->color);\n        out_uint8(self->out_s, pen->color >> 8);\n        out_uint8(self->out_s, pen->color >> 16);\n        self->orders_state.line_pen.color = pen->color;\n    }\n\n    xrdp_order_pack_small_or_tiny(self, order_flags_ptr, order_flags,\n                                  present_ptr, present, 2);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* send a mem blt order */\n/* max size  30 */\nint\nxrdp_orders_mem_blt(struct xrdp_orders *self, int cache_id,\n                    int color_table, int x, int y, int cx, int cy,\n                    int rop, int srcx, int srcy,\n                    int cache_idx, struct xrdp_rect *rect)\n{\n    int order_flags = 0;\n    int vals[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\n    int present = 0;\n    char *present_ptr = (char *)NULL;\n    char *order_flags_ptr = (char *)NULL;\n\n    if (xrdp_orders_check(self, 30) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD;\n\n    if (self->orders_state.last_order != RDP_ORDER_MEMBLT)\n    {\n        order_flags |= TS_TYPE_CHANGE;\n    }\n\n    self->orders_state.last_order = RDP_ORDER_MEMBLT;\n\n    if (rect != 0)\n    {\n        /* if clip is present, still check if it's needed */\n        if (x < rect->left || y < rect->top ||\n                x + cx > rect->right || y + cy > rect->bottom)\n        {\n            order_flags |= TS_BOUNDS;\n\n            if (xrdp_orders_last_bounds(self, rect))\n            {\n                order_flags |= TS_ZERO_BOUNDS_DELTAS;\n            }\n        }\n    }\n\n    vals[0] = x;\n    vals[1] = self->orders_state.mem_blt_x;\n    vals[2] = y;\n    vals[3] = self->orders_state.mem_blt_y;\n    vals[4] = cx;\n    vals[5] = self->orders_state.mem_blt_cx;\n    vals[6] = cy;\n    vals[7] = self->orders_state.mem_blt_cy;\n    vals[8] = srcx;\n    vals[9] = self->orders_state.mem_blt_srcx;\n    vals[10] = srcy;\n    vals[11] = self->orders_state.mem_blt_srcy;\n\n    if (xrdp_orders_send_delta(self, vals, 12))\n    {\n        order_flags |= TS_DELTA_COORDINATES;\n    }\n\n    /* order_flags, set later, 1 byte */\n    order_flags_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if (order_flags & TS_TYPE_CHANGE)\n    {\n        out_uint8(self->out_s, self->orders_state.last_order);\n    }\n\n    present = 0;\n    /* present, set later, 2 bytes */\n    present_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 2);\n\n    if ((order_flags & TS_BOUNDS) &&\n            !(order_flags & TS_ZERO_BOUNDS_DELTAS))\n    {\n        xrdp_orders_out_bounds(self, rect);\n    }\n\n    if (cache_id != self->orders_state.mem_blt_cache_id ||\n            color_table != self->orders_state.mem_blt_color_table)\n    {\n        present |= 0x0001;\n        out_uint8(self->out_s, cache_id);\n        out_uint8(self->out_s, color_table);\n        self->orders_state.mem_blt_cache_id = cache_id;\n        self->orders_state.mem_blt_color_table = color_table;\n    }\n\n    if (x != self->orders_state.mem_blt_x)\n    {\n        present |= 0x0002;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, x - self->orders_state.mem_blt_x);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, x);\n        }\n\n        self->orders_state.mem_blt_x = x;\n    }\n\n    if (y != self->orders_state.mem_blt_y)\n    {\n        present |= 0x0004;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, y - self->orders_state.mem_blt_y);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, y);\n        }\n\n        self->orders_state.mem_blt_y = y;\n    }\n\n    if (cx != self->orders_state.mem_blt_cx)\n    {\n        present |= 0x0008;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cx - self->orders_state.mem_blt_cx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cx);\n        }\n\n        self->orders_state.mem_blt_cx = cx;\n    }\n\n    if (cy != self->orders_state.mem_blt_cy)\n    {\n        present |= 0x0010;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, cy - self->orders_state.mem_blt_cy);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, cy);\n        }\n\n        self->orders_state.mem_blt_cy = cy;\n    }\n\n    if (rop != self->orders_state.mem_blt_rop)\n    {\n        present |= 0x0020;\n        out_uint8(self->out_s, rop);\n        self->orders_state.mem_blt_rop = rop;\n    }\n\n    if (srcx != self->orders_state.mem_blt_srcx)\n    {\n        present |= 0x0040;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, srcx - self->orders_state.mem_blt_srcx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, srcx);\n        }\n\n        self->orders_state.mem_blt_srcx = srcx;\n    }\n\n    if (srcy != self->orders_state.mem_blt_srcy)\n    {\n        present |= 0x0080;\n\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, srcy - self->orders_state.mem_blt_srcy);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, srcy);\n        }\n\n        self->orders_state.mem_blt_srcy = srcy;\n    }\n\n    if (cache_idx != self->orders_state.mem_blt_cache_idx)\n    {\n        present |= 0x0100;\n        out_uint16_le(self->out_s, cache_idx);\n        self->orders_state.mem_blt_cache_idx = cache_idx;\n    }\n\n    xrdp_order_pack_small_or_tiny(self, order_flags_ptr, order_flags,\n                                  present_ptr, present, 2);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_orders_composite_blt(struct xrdp_orders *self, int srcidx, int srcformat,\n                          int srcwidth, int srcrepeat, int *srctransform,\n                          int mskflags, int mskidx, int mskformat,\n                          int mskwidth, int mskrepeat, int op,\n                          int srcx, int srcy, int mskx, int msky,\n                          int dstx, int dsty, int width, int height,\n                          int dstformat,\n                          struct xrdp_rect *rect)\n{\n    int order_flags;\n    int vals[20];\n    int present;\n    char *present_ptr;\n    char *order_flags_ptr;\n\n    if (xrdp_orders_check(self, 80) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD;\n    if (self->orders_state.last_order != RDP_ORDER_COMPOSITE)\n    {\n        order_flags |= TS_TYPE_CHANGE;\n    }\n    self->orders_state.last_order = RDP_ORDER_COMPOSITE;\n    if (rect != 0)\n    {\n        /* if clip is present, still check if it's needed */\n        if (dstx < rect->left || dsty < rect->top ||\n                dstx + width > rect->right || dsty + height > rect->bottom)\n        {\n            order_flags |= TS_BOUNDS;\n            if (xrdp_orders_last_bounds(self, rect))\n            {\n\n                order_flags |= TS_ZERO_BOUNDS_DELTAS;\n\n            }\n        }\n    }\n    vals[0] = srcx;\n    vals[1] = self->orders_state.com_blt_srcx;\n    vals[2] = srcy;\n    vals[3] = self->orders_state.com_blt_srcy;\n    vals[4] = mskx;\n    vals[5] = self->orders_state.com_blt_mskx;\n    vals[6] = msky;\n    vals[7] = self->orders_state.com_blt_msky;\n    vals[8] = dstx;\n    vals[9] = self->orders_state.com_blt_dstx;\n    vals[10] = dsty;\n    vals[11] = self->orders_state.com_blt_dsty;\n    vals[12] = width;\n    vals[13] = self->orders_state.com_blt_width;\n    vals[14] = height;\n    vals[15] = self->orders_state.com_blt_height;\n    vals[16] = srcwidth;\n    vals[17] = self->orders_state.com_blt_srcwidth;\n    vals[18] = mskwidth;\n    vals[19] = self->orders_state.com_blt_mskwidth;\n    if (xrdp_orders_send_delta(self, vals, 20))\n    {\n        order_flags |= TS_DELTA_COORDINATES;\n    }\n    /* order_flags, set later, 1 byte */\n    order_flags_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n    if (order_flags & TS_TYPE_CHANGE)\n    {\n        out_uint8(self->out_s, self->orders_state.last_order);\n    }\n    present = 0;\n    /* present, set later, 3 bytes */\n    present_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 3);\n    if ((order_flags & TS_BOUNDS) &&\n            !(order_flags & TS_ZERO_BOUNDS_DELTAS))\n    {\n        xrdp_orders_out_bounds(self, rect);\n    }\n\n    if (srcidx != self->orders_state.com_blt_srcidx)\n    {\n        present |= 0x000001;\n        out_uint16_le(self->out_s, srcidx);\n        self->orders_state.com_blt_srcidx = srcidx;\n    }\n\n    if (srcformat != self->orders_state.com_blt_srcformat)\n    {\n        present |= 0x000002;\n        out_uint32_le(self->out_s, srcformat);\n        self->orders_state.com_blt_srcformat = srcformat;\n    }\n\n    if (srcwidth != self->orders_state.com_blt_srcwidth)\n    {\n        present |= 0x000004;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, srcwidth - self->orders_state.com_blt_srcwidth);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, srcwidth);\n        }\n        self->orders_state.com_blt_srcwidth = srcwidth;\n    }\n\n    if (srcrepeat != self->orders_state.com_blt_srcrepeat)\n    {\n        present |= 0x000008;\n        out_uint8(self->out_s, srcrepeat);\n        self->orders_state.com_blt_srcrepeat = srcrepeat;\n    }\n\n    if (srctransform != 0)\n    {\n        if (srctransform[0] != self->orders_state.com_blt_srctransform[0])\n        {\n            present |= 0x000010;\n            out_uint32_le(self->out_s, srctransform[0]);\n            self->orders_state.com_blt_srctransform[0] = srctransform[0];\n        }\n        if (g_memcmp(&(srctransform[1]),\n                     &(self->orders_state.com_blt_srctransform[1]),\n                     36) != 0)\n        {\n            present |= 0x000020;\n            out_uint32_le(self->out_s, srctransform[1]);\n            out_uint32_le(self->out_s, srctransform[2]);\n            out_uint32_le(self->out_s, srctransform[3]);\n            out_uint32_le(self->out_s, srctransform[4]);\n            out_uint32_le(self->out_s, srctransform[5]);\n            out_uint32_le(self->out_s, srctransform[6]);\n            out_uint32_le(self->out_s, srctransform[7]);\n            out_uint32_le(self->out_s, srctransform[8]);\n            out_uint32_le(self->out_s, srctransform[9]);\n        }\n    }\n    else\n    {\n        if (self->orders_state.com_blt_srctransform[0] != 0)\n        {\n            present |= 0x000010;\n            out_uint32_le(self->out_s, 0);\n            self->orders_state.com_blt_srctransform[0] = 0;\n        }\n    }\n\n    if (mskflags != self->orders_state.com_blt_mskflags)\n    {\n        present |= 0x000040;\n        out_uint8(self->out_s, mskflags);\n        self->orders_state.com_blt_mskflags = mskflags;\n    }\n\n    if (mskidx != self->orders_state.com_blt_mskidx)\n    {\n        present |= 0x000080;\n        out_uint16_le(self->out_s, mskidx);\n        self->orders_state.com_blt_mskidx = mskidx;\n    }\n\n    if (mskformat != self->orders_state.com_blt_mskformat)\n    {\n        present |= 0x000100;\n        out_uint32_le(self->out_s, mskformat);\n        self->orders_state.com_blt_mskformat = mskformat;\n    }\n\n    if (mskwidth != self->orders_state.com_blt_mskwidth)\n    {\n        present |= 0x000200;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, mskwidth - self->orders_state.com_blt_mskwidth);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, mskwidth);\n        }\n        self->orders_state.com_blt_mskwidth = mskwidth;\n    }\n\n    if (mskrepeat != self->orders_state.com_blt_mskrepeat)\n    {\n        present |= 0x000400;\n        out_uint8(self->out_s, mskrepeat);\n        self->orders_state.com_blt_mskrepeat = mskrepeat;\n    }\n\n    if (op != self->orders_state.com_blt_op)\n    {\n        present |= 0x000800;\n        out_uint8(self->out_s, op);\n        self->orders_state.com_blt_op = op;\n    }\n\n    if (srcx != self->orders_state.com_blt_srcx)\n    {\n        present |= 0x001000;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, srcx - self->orders_state.com_blt_srcx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, srcx);\n        }\n        self->orders_state.com_blt_srcx = srcx;\n    }\n\n    if (srcy != self->orders_state.com_blt_srcy)\n    {\n        present |= 0x002000;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, srcy - self->orders_state.com_blt_srcy);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, srcy);\n        }\n        self->orders_state.com_blt_srcy = srcy;\n    }\n\n    if (mskx != self->orders_state.com_blt_mskx)\n    {\n        present |= 0x004000;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, mskx - self->orders_state.com_blt_mskx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, mskx);\n        }\n        self->orders_state.com_blt_mskx = mskx;\n    }\n\n    if (msky != self->orders_state.com_blt_msky)\n    {\n        present |= 0x008000;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, msky - self->orders_state.com_blt_msky);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, msky);\n        }\n        self->orders_state.com_blt_msky = msky;\n    }\n\n    if (dstx != self->orders_state.com_blt_dstx)\n    {\n        present |= 0x010000;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, dstx - self->orders_state.com_blt_dstx);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, dstx);\n        }\n        self->orders_state.com_blt_dstx = dstx;\n    }\n\n    if (dsty != self->orders_state.com_blt_dsty)\n    {\n        present |= 0x020000;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, dsty - self->orders_state.com_blt_dsty);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, dsty);\n        }\n        self->orders_state.com_blt_dsty = dsty;\n    }\n\n    if (width != self->orders_state.com_blt_width)\n    {\n        present |= 0x040000;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, width - self->orders_state.com_blt_width);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, width);\n        }\n        self->orders_state.com_blt_width = width;\n    }\n\n    if (height != self->orders_state.com_blt_height)\n    {\n        present |= 0x080000;\n        if (order_flags & TS_DELTA_COORDINATES)\n        {\n            out_uint8(self->out_s, height - self->orders_state.com_blt_height);\n        }\n        else\n        {\n            out_uint16_le(self->out_s, height);\n        }\n        self->orders_state.com_blt_height = height;\n    }\n\n    if (dstformat != self->orders_state.com_blt_dstformat)\n    {\n        present |= 0x100000;\n        out_uint32_le(self->out_s, dstformat);\n        self->orders_state.com_blt_dstformat = dstformat;\n    }\n\n    xrdp_order_pack_small_or_tiny(self, order_flags_ptr, order_flags,\n\n                                  present_ptr, present, 3);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_orders_text(struct xrdp_orders *self,\n                 int font, int flags, int mixmode,\n                 int fg_color, int bg_color,\n                 int clip_left, int clip_top,\n                 int clip_right, int clip_bottom,\n                 int box_left, int box_top,\n                 int box_right, int box_bottom,\n                 int x, int y, char *data, int data_len,\n                 struct xrdp_rect *rect)\n{\n    int order_flags = 0;\n    int present = 0;\n    char *present_ptr = (char *)NULL;\n    char *order_flags_ptr = (char *)NULL;\n\n    if (xrdp_orders_check(self, 44 + data_len) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD;\n\n    if (self->orders_state.last_order != RDP_ORDER_TEXT2)\n    {\n        order_flags |= TS_TYPE_CHANGE;\n    }\n\n    self->orders_state.last_order = RDP_ORDER_TEXT2;\n\n    if (rect != 0)\n    {\n        /* if clip is present, still check if it's needed */\n        if ((box_right - box_left > 1 &&\n                (box_left < rect->left ||\n                 box_top < rect->top ||\n                 box_right > rect->right ||\n                 box_bottom > rect->bottom)) ||\n                (clip_left < rect->left ||\n                 clip_top < rect->top ||\n                 clip_right > rect->right ||\n                 clip_bottom > rect->bottom))\n        {\n            order_flags |= TS_BOUNDS;\n\n            if (xrdp_orders_last_bounds(self, rect))\n            {\n                order_flags |= TS_ZERO_BOUNDS_DELTAS;\n            }\n        }\n    }\n\n    /* order_flags, set later, 1 byte */\n    order_flags_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 1);\n\n    if (order_flags & TS_TYPE_CHANGE)\n    {\n        out_uint8(self->out_s, self->orders_state.last_order);\n    }\n\n    present = 0;\n    /* present, set later, 3 bytes */\n    present_ptr = self->out_s->p;\n    out_uint8s(self->out_s, 3);\n\n    if ((order_flags & TS_BOUNDS) &&\n            !(order_flags & TS_ZERO_BOUNDS_DELTAS))\n    {\n        xrdp_orders_out_bounds(self, rect);\n    }\n\n    if (font != self->orders_state.text_font)\n    {\n        present |= 0x000001;\n        out_uint8(self->out_s, font);\n        self->orders_state.text_font = font;\n    }\n\n    if (flags != self->orders_state.text_flags)\n    {\n        present |= 0x000002;\n        out_uint8(self->out_s, flags);\n        self->orders_state.text_flags = flags;\n    }\n\n    /* unknown */\n    if (mixmode != self->orders_state.text_mixmode)\n    {\n        present |= 0x000008;\n        out_uint8(self->out_s, mixmode);\n        self->orders_state.text_mixmode = mixmode;\n    }\n\n    if (fg_color != self->orders_state.text_fg_color)\n    {\n        present |= 0x000010;\n        out_uint8(self->out_s, fg_color);\n        out_uint8(self->out_s, fg_color >> 8);\n        out_uint8(self->out_s, fg_color >> 16);\n        self->orders_state.text_fg_color = fg_color;\n    }\n\n    if (bg_color != self->orders_state.text_bg_color)\n    {\n        present |= 0x000020;\n        out_uint8(self->out_s, bg_color);\n        out_uint8(self->out_s, bg_color >> 8);\n        out_uint8(self->out_s, bg_color >> 16);\n        self->orders_state.text_bg_color = bg_color;\n    }\n\n    if (clip_left != self->orders_state.text_clip_left)\n    {\n        present |= 0x000040;\n        out_uint16_le(self->out_s, clip_left);\n        self->orders_state.text_clip_left = clip_left;\n    }\n\n    if (clip_top != self->orders_state.text_clip_top)\n    {\n        present |= 0x000080;\n        out_uint16_le(self->out_s, clip_top);\n        self->orders_state.text_clip_top = clip_top;\n    }\n\n    if (clip_right != self->orders_state.text_clip_right)\n    {\n        present |= 0x000100;\n        out_uint16_le(self->out_s, clip_right);\n        self->orders_state.text_clip_right = clip_right;\n    }\n\n    if (clip_bottom != self->orders_state.text_clip_bottom)\n    {\n        present |= 0x000200;\n        out_uint16_le(self->out_s, clip_bottom);\n        self->orders_state.text_clip_bottom = clip_bottom;\n    }\n\n    if (box_left != self->orders_state.text_box_left)\n    {\n        present |= 0x000400;\n        out_uint16_le(self->out_s, box_left);\n        self->orders_state.text_box_left = box_left;\n    }\n\n    if (box_top != self->orders_state.text_box_top)\n    {\n        present |= 0x000800;\n        out_uint16_le(self->out_s, box_top);\n        self->orders_state.text_box_top = box_top;\n    }\n\n    if (box_right != self->orders_state.text_box_right)\n    {\n        present |= 0x001000;\n        out_uint16_le(self->out_s, box_right);\n        self->orders_state.text_box_right = box_right;\n    }\n\n    if (box_bottom != self->orders_state.text_box_bottom)\n    {\n        present |= 0x002000;\n        out_uint16_le(self->out_s, box_bottom);\n        self->orders_state.text_box_bottom = box_bottom;\n    }\n\n    if (x != self->orders_state.text_x)\n    {\n        present |= 0x080000;\n        out_uint16_le(self->out_s, x);\n        self->orders_state.text_x = x;\n    }\n\n    if (y != self->orders_state.text_y)\n    {\n        present |= 0x100000;\n        out_uint16_le(self->out_s, y);\n        self->orders_state.text_y = y;\n    }\n\n    {\n        /* always send text */\n        present |= 0x200000;\n        out_uint8(self->out_s, data_len);\n        out_uint8a(self->out_s, data, data_len);\n    }\n\n    xrdp_order_pack_small_or_tiny(self, order_flags_ptr, order_flags,\n                                  present_ptr, present, 3);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* when a palette gets sent, send the main palette too */\nint\nxrdp_orders_send_palette(struct xrdp_orders *self, int *palette,\n                         int cache_id)\n{\n    int order_flags;\n    int len;\n    int i;\n\n    if (xrdp_orders_check(self, 2000) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_orders_send_palette: xrdp_orders_check failed\");\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD | TS_SECONDARY;\n    out_uint8(self->out_s, order_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] DRAWING_ORDER \"\n              \"controlFlags 0x%2.2x (TS_STANDARD | TS_SECONDARY)\", order_flags);\n\n    len = 1027 - 7; /* length after type minus 7 */\n    out_uint16_le(self->out_s, len);              /* orderLength */\n    out_uint16_le(self->out_s, 0);                /* extraFlags */\n    out_uint8(self->out_s, TS_CACHE_COLOR_TABLE); /* orderType */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] SECONDARY_DRAWING_ORDER_HEADER \"\n              \"orderLength %d, extraFlags 0x0000, orderType 0x%2.2x (TS_CACHE_COLOR_TABLE)\",\n              len, TS_CACHE_COLOR_TABLE);\n\n    out_uint8(self->out_s, cache_id);\n    out_uint16_le(self->out_s, 256); /* num colors */\n\n    for (i = 0; i < 256; i++)\n    {\n        out_uint8(self->out_s, palette[i]);\n        out_uint8(self->out_s, palette[i] >> 8);\n        out_uint8(self->out_s, palette[i] >> 16);\n        out_uint8(self->out_s, 0);\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order [MS-RDPEGDI] CACHE_COLOR_TABLE_ORDER \"\n              \"cacheIndex %d, numberColors 256, colorTable <omitted from log>\",\n              cache_id);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* max size width * height * Bpp + 16 */\nint\nxrdp_orders_send_raw_bitmap(struct xrdp_orders *self,\n                            int width, int height, int bpp, char *data,\n                            int cache_id, int cache_idx)\n{\n    int order_flags = 0;\n    int len = 0;\n    int bufsize = 0;\n    int Bpp = 0;\n    int i;\n    int j;\n    int pixel;\n    int e = 0;\n    int max_order_size;\n    struct xrdp_client_info *ci;\n\n    if (width > 64)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error, width > 64\");\n        return 1;\n    }\n\n    if (height > 64)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error, height > 64\");\n        return 1;\n    }\n\n    e = width % 4;\n\n    if (e != 0)\n    {\n        e = 4 - e;\n    }\n\n    Bpp = (bpp + 7) / 8;\n    bufsize = (width + e) * height * Bpp;\n    ci = &(self->rdp_layer->client_info);\n    max_order_size = MAX_ORDERS_SIZE(ci);\n    while (bufsize + 16 > max_order_size)\n    {\n        height--;\n        bufsize = (width + e) * height * Bpp;\n    }\n    if (xrdp_orders_check(self, bufsize + 16) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD | TS_SECONDARY;\n    out_uint8(self->out_s, order_flags);\n    len = (bufsize + 9) - 7; /* length after type minus 7 */\n    out_uint16_le(self->out_s, len);\n    out_uint16_le(self->out_s, 8); /* flags */\n    out_uint8(self->out_s, TS_CACHE_BITMAP_UNCOMPRESSED); /* type */\n    out_uint8(self->out_s, cache_id);\n    out_uint8s(self->out_s, 1); /* pad */\n    out_uint8(self->out_s, width + e);\n    out_uint8(self->out_s, height);\n    out_uint8(self->out_s, bpp);\n    out_uint16_le(self->out_s, bufsize);\n    out_uint16_le(self->out_s, cache_idx);\n\n    if (Bpp == 4)\n    {\n        for (i = height - 1; i >= 0; i--)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = GETPIXEL32(data, j, i, width);\n                out_uint8(self->out_s, pixel);\n                out_uint8(self->out_s, pixel >> 8);\n                out_uint8(self->out_s, pixel >> 16);\n                out_uint8(self->out_s, pixel >> 24);\n            }\n            out_uint8s(self->out_s, Bpp * e);\n        }\n    }\n    else if (Bpp == 3)\n    {\n        for (i = height - 1; i >= 0; i--)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = GETPIXEL32(data, j, i, width);\n                out_uint8(self->out_s, pixel);\n                out_uint8(self->out_s, pixel >> 8);\n                out_uint8(self->out_s, pixel >> 16);\n            }\n            out_uint8s(self->out_s, Bpp * e);\n        }\n    }\n    else if (Bpp == 2)\n    {\n        for (i = height - 1; i >= 0; i--)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = GETPIXEL16(data, j, i, width);\n                out_uint8(self->out_s, pixel);\n                out_uint8(self->out_s, pixel >> 8);\n            }\n            out_uint8s(self->out_s, Bpp * e);\n        }\n    }\n    else if (Bpp == 1)\n    {\n        for (i = height - 1; i >= 0; i--)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = GETPIXEL8(data, j, i, width);\n                out_uint8(self->out_s, pixel);\n            }\n            out_uint8s(self->out_s, Bpp * e);\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* max size width * height * Bpp + 16 */\nint\nxrdp_orders_send_bitmap(struct xrdp_orders *self,\n                        int width, int height, int bpp, char *data,\n                        int cache_id, int cache_idx)\n{\n    int order_flags = 0;\n    int len = 0;\n    int bufsize = 0;\n    int Bpp = 0;\n    int i = 0;\n    int lines_sending = 0;\n    int e = 0;\n    struct stream *s = NULL;\n    struct stream *temp_s = NULL;\n    char *p = NULL;\n    int max_order_size;\n    struct xrdp_client_info *ci;\n\n    if (width > 64)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error, width > 64\");\n        return 1;\n    }\n\n    if (height > 64)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error, height > 64\");\n        return 1;\n    }\n\n    ci = &(self->rdp_layer->client_info);\n    max_order_size = MAX_ORDERS_SIZE(ci);\n\n    e = width % 4;\n\n    if (e != 0)\n    {\n        e = 4 - e;\n    }\n\n    s = self->s;\n    init_stream(s, 16384 * 2);\n    temp_s = self->temp_s;\n    init_stream(temp_s, 16384 * 2);\n    p = s->p;\n    i = height;\n    if (bpp > 24)\n    {\n        lines_sending = xrdp_bitmap32_compress(data, width, height, s,\n                                               bpp, max_order_size,\n                                               i - 1, temp_s, e, 0x10);\n    }\n    else\n    {\n        lines_sending = xrdp_bitmap_compress(data, width, height, s,\n                                             bpp, max_order_size,\n                                             i - 1, temp_s, e);\n    }\n\n    if (lines_sending != height)\n    {\n        height = lines_sending;\n    }\n\n    bufsize = (int)(s->p - p);\n    Bpp = (bpp + 7) / 8;\n    if (xrdp_orders_check(self, bufsize + 16) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD | TS_SECONDARY;\n    out_uint8(self->out_s, order_flags);\n\n    if (self->rdp_layer->client_info.op2)\n    {\n        len = (bufsize + 9) - 7; /* length after type minus 7 */\n        out_uint16_le(self->out_s, len);\n        out_uint16_le(self->out_s, 1024); /* flags */\n    }\n    else\n    {\n        len = (bufsize + 9 + 8) - 7; /* length after type minus 7 */\n        out_uint16_le(self->out_s, len);\n        out_uint16_le(self->out_s, 8); /* flags */\n    }\n\n    out_uint8(self->out_s, TS_CACHE_BITMAP_COMPRESSED); /* type */\n    out_uint8(self->out_s, cache_id);\n    out_uint8s(self->out_s, 1); /* pad */\n    out_uint8(self->out_s, width + e);\n    out_uint8(self->out_s, height);\n    out_uint8(self->out_s, bpp);\n    out_uint16_le(self->out_s, bufsize/* + 8*/);\n    out_uint16_le(self->out_s, cache_idx);\n\n    if (!self->rdp_layer->client_info.op2)\n    {\n        out_uint8s(self->out_s, 2); /* pad */\n        out_uint16_le(self->out_s, bufsize);\n        out_uint16_le(self->out_s, (width + e) * Bpp); /* line size */\n        out_uint16_le(self->out_s, (width + e) *\n                      Bpp * height); /* final size */\n    }\n\n    out_uint8a(self->out_s, s->data, bufsize);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* max size datasize + 18*/\n/* todo, only sends one for now */\nstatic int\nxrdp_orders_cache_glyph(struct xrdp_orders *self,\n                        struct xrdp_font_char *font_char,\n                        int font_index, int char_index)\n{\n    int order_flags = 0;\n    int datasize = 0;\n    int len = 0;\n    int flags;\n\n    if (font_char->bpp == 8) /* alpha font */\n    {\n        datasize = ((font_char->width + 3) & ~3) * font_char->height;\n        flags = 8 | 0x4000;\n    }\n    else\n    {\n        datasize = FONT_DATASIZE(font_char);\n        flags = 8;\n    }\n    if (xrdp_orders_check(self, datasize + 18) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD | TS_SECONDARY;\n    out_uint8(self->out_s, order_flags);\n    len = (datasize + 12) - 7; /* length after type minus 7 */\n    out_uint16_le(self->out_s, len);\n    out_uint16_le(self->out_s, flags);\n    out_uint8(self->out_s, TS_CACHE_GLYPH); /* type */\n    out_uint8(self->out_s, font_index);\n    out_uint8(self->out_s, 1); /* num of chars */\n    out_uint16_le(self->out_s, char_index);\n    out_uint16_le(self->out_s, font_char->offset);\n    out_uint16_le(self->out_s, font_char->baseline);\n    out_uint16_le(self->out_s, font_char->width);\n    out_uint16_le(self->out_s, font_char->height);\n    out_uint8a(self->out_s, font_char->data, datasize);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int write_2byte_signed(struct stream *s, int value)\n{\n    unsigned char byte;\n    int negative = 0;\n\n    if (value < 0)\n    {\n        negative = 1;\n        value *= -1;\n    }\n\n    if (value > 0x3FFF)\n    {\n        return 1;\n    }\n\n    if (value >= 0x3F)\n    {\n        byte = ((value & 0x3F00) >> 8);\n\n        if (negative)\n        {\n            byte |= 0x40;\n        }\n\n        out_uint8(s, byte | 0x80);\n        byte = (value & 0xFF);\n        out_uint8(s, byte);\n    }\n    else\n    {\n        byte = (value & 0x3F);\n\n        if (negative)\n        {\n            byte |= 0x40;\n        }\n\n        out_uint8(s, byte);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int write_2byte_unsigned(struct stream *s, unsigned int value)\n{\n    unsigned char byte;\n\n    if (value > 0x7FFF)\n    {\n        return 1;\n    }\n\n    if (value >= 0x7F)\n    {\n        byte = ((value & 0x7F00) >> 8);\n        out_uint8(s, byte | 0x80);\n        byte = (value & 0xFF);\n        out_uint8(s, byte);\n    }\n    else\n    {\n        byte = (value & 0x7F);\n        out_uint8(s, byte);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* max size datasize + 15*/\n/* todo, only sends one for now */\nstatic int\nxrdp_orders_cache_glyph_v2(struct xrdp_orders *self,\n                           struct xrdp_font_char *font_char,\n                           int font_index, int char_index)\n{\n    int order_flags = 0;\n    int datasize = 0;\n    int len = 0;\n    int extra_flags;\n    char *len_ptr;\n\n    if (font_char->bpp == 8) /* alpha font */\n    {\n        datasize = ((font_char->width + 3) & ~3) * font_char->height;\n    }\n    else\n    {\n        datasize = FONT_DATASIZE(font_char);\n    }\n\n    /* cacheId, flags(GLYPH_ORDER_REV2), cGlyphs */\n    extra_flags = (font_index & 0x000F) | (0x2 << 4) | (1 << 8);\n\n    if (xrdp_orders_check(self, datasize + 15) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD | TS_SECONDARY;\n    out_uint8(self->out_s, order_flags);\n    len_ptr = self->out_s->p;\n    out_uint16_le(self->out_s, 0);  /* set later */\n    out_uint16_le(self->out_s, extra_flags);\n    out_uint8(self->out_s, TS_CACHE_GLYPH); /* type */\n\n    out_uint8(self->out_s, char_index);\n    if (write_2byte_signed(self->out_s, font_char->offset) ||\n            write_2byte_signed(self->out_s, font_char->baseline) ||\n            write_2byte_unsigned(self->out_s, font_char->width) ||\n            write_2byte_unsigned(self->out_s, font_char->height))\n    {\n        return 1;\n    }\n\n    out_uint8a(self->out_s, font_char->data, datasize);\n    len = (self->out_s->p - len_ptr) + 1 - 13;\n    len_ptr[0] = len & 0xFF;\n    len_ptr[1] = (len >> 8) & 0xFF;\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_orders_send_font(struct xrdp_orders *self,\n                      struct xrdp_font_char *font_char,\n                      int font_index, int char_index)\n{\n    if (self->rdp_layer->client_info.use_cache_glyph_v2)\n    {\n        return xrdp_orders_cache_glyph_v2(self, font_char, font_index, char_index);\n    }\n\n    return xrdp_orders_cache_glyph(self, font_char, font_index, char_index);\n}\n\n/*****************************************************************************/\n/* returns error */\n/* max size width * height * Bpp + 14 */\nint\nxrdp_orders_send_raw_bitmap2(struct xrdp_orders *self,\n                             int width, int height, int bpp, char *data,\n                             int cache_id, int cache_idx)\n{\n    int order_flags = 0;\n    int len = 0;\n    int bufsize = 0;\n    int Bpp = 0;\n    int i = 0;\n    int j;\n    int pixel;\n    int e = 0;\n    int max_order_size;\n    struct xrdp_client_info *ci;\n\n    if (width > 64)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error, width > 64\");\n        return 1;\n    }\n\n    if (height > 64)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error, height > 64\");\n        return 1;\n    }\n\n    ci = &(self->rdp_layer->client_info);\n    max_order_size = MAX_ORDERS_SIZE(ci);\n\n    e = width % 4;\n\n    if (e != 0)\n    {\n        e = 4 - e;\n    }\n\n    Bpp = (bpp + 7) / 8;\n    bufsize = (width + e) * height * Bpp;\n    while (bufsize + 14 > max_order_size)\n    {\n        height--;\n        bufsize = (width + e) * height * Bpp;\n    }\n    if (xrdp_orders_check(self, bufsize + 14) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD | TS_SECONDARY;\n    out_uint8(self->out_s, order_flags);\n    len = (bufsize + 6) - 7; /* length after type minus 7 */\n    out_uint16_le(self->out_s, len);\n    i = (((Bpp + 2) << 3) & 0x38) | (cache_id & 7);\n    out_uint16_le(self->out_s, i); /* flags */\n    out_uint8(self->out_s, TS_CACHE_BITMAP_UNCOMPRESSED_REV2); /* type */\n    out_uint8(self->out_s, width + e);\n    out_uint8(self->out_s, height);\n    out_uint16_be(self->out_s, bufsize | 0x4000);\n    i = ((cache_idx >> 8) & 0xff) | 0x80;\n    out_uint8(self->out_s, i);\n    i = cache_idx & 0xff;\n    out_uint8(self->out_s, i);\n\n    if (Bpp == 4)\n    {\n        for (i = height - 1; i >= 0; i--)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = GETPIXEL32(data, j, i, width);\n                out_uint8(self->out_s, pixel);\n                out_uint8(self->out_s, pixel >> 8);\n                out_uint8(self->out_s, pixel >> 16);\n                out_uint8(self->out_s, pixel >> 24);\n            }\n            out_uint8s(self->out_s, Bpp * e);\n        }\n    }\n    else if (Bpp == 3)\n    {\n        for (i = height - 1; i >= 0; i--)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = GETPIXEL32(data, j, i, width);\n                out_uint8(self->out_s, pixel);\n                out_uint8(self->out_s, pixel >> 8);\n                out_uint8(self->out_s, pixel >> 16);\n            }\n            out_uint8s(self->out_s, Bpp * e);\n        }\n    }\n    else if (Bpp == 2)\n    {\n        for (i = height - 1; i >= 0; i--)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = GETPIXEL16(data, j, i, width);\n                out_uint8(self->out_s, pixel);\n                out_uint8(self->out_s, pixel >> 8);\n            }\n            out_uint8s(self->out_s, Bpp * e);\n        }\n    }\n    else if (Bpp == 1)\n    {\n        for (i = height - 1; i >= 0; i--)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = GETPIXEL8(data, j, i, width);\n                out_uint8(self->out_s, pixel);\n            }\n            out_uint8s(self->out_s, Bpp * e);\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* max size width * height * Bpp + 14 */\nint\nxrdp_orders_send_bitmap2(struct xrdp_orders *self,\n                         int width, int height, int bpp, char *data,\n                         int cache_id, int cache_idx, int hints)\n{\n    int order_flags = 0;\n    int len = 0;\n    int bufsize = 0;\n    int Bpp = 0;\n    int i = 0;\n    int lines_sending = 0;\n    int e = 0;\n    struct stream *s = NULL;\n    struct stream *temp_s = NULL;\n    char *p = NULL;\n    int max_order_size;\n    struct xrdp_client_info *ci;\n\n    if (width > 64)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error, width > 64\");\n        return 1;\n    }\n\n    if (height > 64)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error, height > 64\");\n        return 1;\n    }\n\n    ci = &(self->rdp_layer->client_info);\n    max_order_size = MAX_ORDERS_SIZE(ci);\n\n    e = width % 4;\n\n    if (e != 0)\n    {\n        e = 4 - e;\n    }\n\n    s = self->s;\n    init_stream(s, 16384 * 2);\n    temp_s = self->temp_s;\n    init_stream(temp_s, 16384 * 2);\n    p = s->p;\n    i = height;\n    if (bpp > 24)\n    {\n        lines_sending = xrdp_bitmap32_compress(data, width, height, s,\n                                               bpp, max_order_size,\n                                               i - 1, temp_s, e, 0x10);\n    }\n    else\n    {\n        lines_sending = xrdp_bitmap_compress(data, width, height, s,\n                                             bpp, max_order_size,\n                                             i - 1, temp_s, e);\n    }\n\n    if (lines_sending != height)\n    {\n        height = lines_sending;\n    }\n\n    bufsize = (int)(s->p - p);\n    Bpp = (bpp + 7) / 8;\n    if (xrdp_orders_check(self, bufsize + 14) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD | TS_SECONDARY;\n    out_uint8(self->out_s, order_flags);\n    len = (bufsize + 6) - 7; /* length after type minus 7 */\n    out_uint16_le(self->out_s, len);\n    i = (((Bpp + 2) << 3) & 0x38) | (cache_id & 7);\n    i = i | (0x08 << 7); /* CBR2_NO_BITMAP_COMPRESSION_HDR */\n    out_uint16_le(self->out_s, i); /* flags */\n    out_uint8(self->out_s, TS_CACHE_BITMAP_COMPRESSED_REV2); /* type */\n    out_uint8(self->out_s, width + e);\n    out_uint8(self->out_s, height);\n    out_uint16_be(self->out_s, bufsize | 0x4000);\n    i = ((cache_idx >> 8) & 0xff) | 0x80;\n    out_uint8(self->out_s, i);\n    i = cache_idx & 0xff;\n    out_uint8(self->out_s, i);\n    out_uint8a(self->out_s, s->data, bufsize);\n    return 0;\n}\n\n#if defined(XRDP_JPEG)\n/*****************************************************************************/\nstatic int\nxrdp_orders_send_as_jpeg(struct xrdp_orders *self,\n                         int width, int height, int bpp, int hints)\n{\n    if (hints & 1)\n    {\n        return 0;\n    }\n\n    if (bpp != 24)\n    {\n        return 0;\n    }\n\n    if (width * height < 64)\n    {\n        return 0;\n    }\n\n    return 1;\n}\n#endif\n\n#if defined(XRDP_NEUTRINORDP)\n/*****************************************************************************/\n/*  secondary drawing order (bitmap v3) using remotefx compression */\nstatic int\nxrdp_orders_send_as_rfx(struct xrdp_orders *self,\n                        int width, int height, int bpp,\n                        int hints)\n{\n    if (hints & 1)\n    {\n        return 0;\n    }\n\n    if (bpp != 24)\n    {\n        return 0;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"width %d height %d rfx_min_pixel %d\", width, height,\n              self->rfx_min_pixel);\n    if (width * height < self->rfx_min_pixel)\n    {\n        return 0;\n    }\n\n    return 1;\n}\n#endif\n\n#if defined(XRDP_JPEG) || defined(XRDP_NEUTRINORDP)\n/*****************************************************************************/\nstatic int\nxrdp_orders_out_v3(struct xrdp_orders *self, int cache_id, int cache_idx,\n                   char *buf, int bufsize, int width, int height, int bpp,\n                   int codec_id)\n{\n    int Bpp;\n    int order_flags;\n    int len;\n    int i;\n\n    Bpp = (bpp + 7) / 8;\n    if (xrdp_orders_check(self, bufsize + 30) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD | TS_SECONDARY;\n    out_uint8(self->out_s, order_flags);\n    len = (bufsize + 22) - 7; /* length after type minus 7 */\n    out_uint16_le(self->out_s, len);\n    i = (((Bpp + 2) << 3) & 0x38) | (cache_id & 7);\n    out_uint16_le(self->out_s, i); /* flags */\n    out_uint8(self->out_s, TS_CACHE_BITMAP_COMPRESSED_REV3); /* type */\n    /* cache index */\n    out_uint16_le(self->out_s, cache_idx);\n    /* persistent cache key 1/2 */\n    out_uint32_le(self->out_s, 0);\n    out_uint32_le(self->out_s, 0);\n    /* bitmap data */\n    out_uint8(self->out_s, bpp);\n    out_uint8(self->out_s, 0); /* reserved */\n    out_uint8(self->out_s, 0); /* reserved */\n    out_uint8(self->out_s, codec_id);\n    out_uint16_le(self->out_s, width);\n    out_uint16_le(self->out_s, height);\n    out_uint32_le(self->out_s, bufsize);\n    out_uint8a(self->out_s, buf, bufsize);\n    return 0;\n}\n#endif\n\n/*****************************************************************************/\n/*  secondary drawing order (bitmap v3) using remotefx compression */\nint\nxrdp_orders_send_bitmap3(struct xrdp_orders *self,\n                         int width, int height, int bpp, char *data,\n                         int cache_id, int cache_idx, int hints)\n{\n    struct xrdp_client_info *ci;\n#if defined(XRDP_JPEG) || defined(XRDP_NEUTRINORDP)\n    int bufsize;\n    struct stream *xr_s; /* xrdp stream */\n#endif\n#if defined(XRDP_JPEG)\n    int e;\n    int quality;\n    struct stream *temp_s; /* xrdp stream */\n#endif\n#if defined(XRDP_NEUTRINORDP)\n    STREAM *fr_s; /* FreeRDP stream */\n    RFX_CONTEXT *context;\n    RFX_RECT rect;\n#endif\n\n    ci = &(self->rdp_layer->client_info);\n\n    if (ci->v3_codec_id == 0)\n    {\n        return 2;\n    }\n\n    if (ci->v3_codec_id == ci->rfx_codec_id)\n    {\n#if defined(XRDP_NEUTRINORDP)\n\n        if (!xrdp_orders_send_as_rfx(self, width, height, bpp, hints))\n        {\n            return 2;\n        }\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_orders_send_bitmap3: rfx\");\n        context = (RFX_CONTEXT *)(self->rdp_layer->rfx_enc);\n        make_stream(xr_s);\n        init_stream(xr_s, 16384);\n        fr_s = stream_new(0);\n        stream_attach(fr_s, (tui8 *)(xr_s->data), 16384);\n        rect.x = 0;\n        rect.y = 0;\n        rect.width = width;\n        rect.height = height;\n        rfx_compose_message(context, fr_s, &rect, 1, (tui8 *)data, width,\n                            height, width * 4);\n        bufsize = stream_get_length(fr_s);\n        xrdp_orders_out_v3(self, cache_id, cache_idx, (char *)(fr_s->data),\n                           bufsize, width, height, bpp, ci->v3_codec_id);\n        stream_detach(fr_s);\n        stream_free(fr_s);\n        free_stream(xr_s);\n        return 0;\n#else\n        return 2;\n#endif\n    }\n    else if (ci->v3_codec_id == ci->jpeg_codec_id)\n    {\n#if defined(XRDP_JPEG)\n\n        if (!xrdp_orders_send_as_jpeg(self, width, height, bpp, hints))\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_orders_send_bitmap3: jpeg skipped\");\n            return 2;\n        }\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_orders_send_bitmap3: jpeg\");\n        e = width % 4;\n\n        if (e != 0)\n        {\n            e = 4 - e;\n        }\n\n        make_stream(xr_s);\n        init_stream(xr_s, 16384);\n        make_stream(temp_s);\n        init_stream(temp_s, 16384);\n        quality = ci->jpeg_prop[0];\n        xrdp_jpeg_compress(self->jpeg_han, data, width, height, xr_s, bpp, 16384,\n                           height - 1, temp_s, e, quality);\n        s_mark_end(xr_s);\n        bufsize = (int)(xr_s->end - xr_s->data);\n        xrdp_orders_out_v3(self, cache_id, cache_idx, (char *)(xr_s->data), bufsize,\n                           width + e, height, bpp, ci->v3_codec_id);\n        free_stream(xr_s);\n        free_stream(temp_s);\n        return 0;\n#else\n        return 2;\n#endif\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_orders_send_bitmap3: todo unknown codec\");\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* send a brush cache entry */\nint\nxrdp_orders_send_brush(struct xrdp_orders *self, int width, int height,\n                       int bpp, int type, int size, char *data, int cache_id)\n{\n    int order_flags = 0;\n    int len = 0;\n\n    if (xrdp_orders_check(self, size + 12) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_STANDARD | TS_SECONDARY;\n    out_uint8(self->out_s, order_flags);\n    len = (size + 6) - 7; /* length after type minus 7 */\n    out_uint16_le(self->out_s, len);\n    out_uint16_le(self->out_s, 0); /* flags */\n    out_uint8(self->out_s, TS_CACHE_BRUSH); /* type */\n    out_uint8(self->out_s, cache_id);\n    out_uint8(self->out_s, bpp);\n    out_uint8(self->out_s, width);\n    out_uint8(self->out_s, height);\n    out_uint8(self->out_s, type);\n    out_uint8(self->out_s, size);\n    out_uint8a(self->out_s, data, size);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* send an off screen bitmap entry */\nint\nxrdp_orders_send_create_os_surface(struct xrdp_orders *self, int id,\n                                   int width, int height,\n                                   struct list *del_list)\n{\n    int order_flags;\n    int cache_id;\n    int flags;\n    int index;\n    int bytes;\n    int num_del_list;\n\n    bytes = 7;\n    num_del_list = del_list->count;\n\n    if (num_del_list > 0)\n    {\n        bytes += 2;\n        bytes += num_del_list * 2;\n    }\n\n    if (xrdp_orders_check(self, bytes) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_SECONDARY;\n    order_flags |= 1 << 2; /* type RDP_ORDER_ALTSEC_CREATE_OFFSCR_BITMAP */\n    out_uint8(self->out_s, order_flags);\n    cache_id = id & 0x7fff;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_orders_send_create_os_surface: cache_id %d\", cache_id);\n    flags = cache_id;\n\n    if (num_del_list > 0)\n    {\n        flags |= 0x8000;\n    }\n\n    out_uint16_le(self->out_s, flags);\n    out_uint16_le(self->out_s, width);\n    out_uint16_le(self->out_s, height);\n\n    if (num_del_list > 0)\n    {\n        /* delete list */\n        out_uint16_le(self->out_s, num_del_list);\n\n        for (index = 0; index < num_del_list; index++)\n        {\n            cache_id = list_get_item(del_list, index) & 0x7fff;\n            out_uint16_le(self->out_s, cache_id);\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_orders_send_switch_os_surface(struct xrdp_orders *self, int id)\n{\n    int order_flags;\n    int cache_id;\n\n    if (xrdp_orders_check(self, 3) != 0)\n    {\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_SECONDARY;\n    order_flags |= 0 << 2; /* type RDP_ORDER_ALTSEC_SWITCH_SURFACE */\n    out_uint8(self->out_s, order_flags);\n    cache_id = id & 0xffff;\n    out_uint16_le(self->out_s, cache_id);\n    return 0;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_orders_rail.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp_orders_rail.h\"\n#include \"libxrdp.h\"\n#include \"ms-rdpegdi.h\"\n#include \"xrdp_rail.h\"\n#include \"string_calls.h\"\n\n/* [MS-RDPERP]: Remote Desktop Protocol:\n   Remote Programs Virtual Channel Extension\n   http://msdn.microsoft.com/en-us/library/cc242568(v=prot.10) */\n\n/*****************************************************************************/\n/* RAIL */\n/* returns error */\nint\nxrdp_orders_send_window_delete(struct xrdp_orders *self, int window_id)\n{\n    int order_size;\n    int order_flags;\n    int field_present_flags;\n\n    order_size = 11;\n    if (xrdp_orders_check(self, order_size) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_orders_send_window_delete: xrdp_orders_check failed\");\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_SECONDARY;\n    order_flags |= 0xb << 2; /* type TS_ALTSEC_WINDOW */\n    out_uint8(self->out_s, order_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] ALTSEC_DRAWING_ORDER_HEADER \"\n              \"controlFlags.class 0x%1.1x (TS_SECONDARY), \"\n              \"controlFlags.orderType 0x%2.2x (TS_ALTSEC_WINDOW)\",\n              (order_flags & 0x3), (order_flags >> 2));\n\n    /* orderSize (2 bytes) */\n    out_uint16_le(self->out_s, order_size);\n    /* FieldsPresentFlags (4 bytes) */\n    field_present_flags = WINDOW_ORDER_TYPE_WINDOW | WINDOW_ORDER_STATE_DELETED;\n    out_uint32_le(self->out_s, field_present_flags);\n    /* windowId (4 bytes) */\n    out_uint32_le(self->out_s, window_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPERP] TS_WINDOW_ORDER_HEADER \"\n              \"OrderSize %d, \"\n              \"FieldsPresentFlags 0x%8.8x (WINDOW_ORDER_TYPE_WINDOW | WINDOW_ORDER_STATE_DELETED), \"\n              \"WindowId 0x%8.8x\",\n              order_size, field_present_flags, window_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order [MS-RDPERP] Deleted Window\");\n    return 0;\n}\n\n/*****************************************************************************/\n/* RAIL */\n/* returns error */\n/* flags can contain WINDOW_ORDER_STATE_NEW and/or\n   WINDOW_ORDER_FIELD_ICON_BIG */\nint\nxrdp_orders_send_window_cached_icon(struct xrdp_orders *self,\n                                    int window_id, int cache_entry,\n                                    int cache_id, int flags)\n{\n    int order_size;\n    int order_flags;\n    int field_present_flags;\n\n    order_size = 14;\n    if (xrdp_orders_check(self, order_size) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_orders_send_window_cached_icon: xrdp_orders_check failed\");\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_SECONDARY;\n    order_flags |= 0xb << 2; /* type TS_ALTSEC_WINDOW */\n    out_uint8(self->out_s, order_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] ALTSEC_DRAWING_ORDER_HEADER \"\n              \"controlFlags.class 0x%1.1x (TS_SECONDARY), \"\n              \"controlFlags.orderType 0x%2.2x (TS_ALTSEC_WINDOW)\",\n              (order_flags & 0x3), (order_flags >> 2));\n\n    /* orderSize (2 bytes) */\n    out_uint16_le(self->out_s, order_size);\n    /* FieldsPresentFlags (4 bytes) */\n    field_present_flags = flags | WINDOW_ORDER_TYPE_WINDOW |\n                          WINDOW_ORDER_CACHED_ICON;\n    out_uint32_le(self->out_s, field_present_flags);\n    /* windowId (4 bytes) */\n    out_uint32_le(self->out_s, window_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPERP] TS_WINDOW_ORDER_HEADER \"\n              \"OrderSize %d, FieldsPresentFlags 0x%8.8x, WindowId 0x%8.8x\",\n              order_size, field_present_flags, window_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order [MS-RDPERP] Cached Icon\");\n\n    /* CacheEntry (2 bytes) */\n    out_uint16_le(self->out_s, cache_entry);\n    /* CacheId (1 byte) */\n    out_uint8(self->out_s, cache_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order field [MS-RDPERP] TS_CACHED_ICON_INFO \"\n              \"CacheEntry %d, CacheId %d\", cache_entry, cache_id);\n    return 0;\n}\n\n/*****************************************************************************/\n/* RAIL */\n/* returns error */\nstatic int\nxrdp_orders_send_ts_icon(struct stream *s, int cache_entry, int cache_id,\n                         struct rail_icon_info *icon_info)\n{\n    int use_cmap;\n\n    use_cmap = 0;\n\n    if ((icon_info->bpp == 1) || (icon_info->bpp == 2) || (icon_info->bpp == 4))\n    {\n        use_cmap = 1;\n    }\n\n    /* TS_ICON_INFO */\n    out_uint16_le(s, cache_entry);\n    out_uint8(s, cache_id);\n    out_uint8(s, icon_info->bpp);\n    out_uint16_le(s, icon_info->width);\n    out_uint16_le(s, icon_info->height);\n\n    if (use_cmap)\n    {\n        out_uint16_le(s, icon_info->cmap_bytes);\n    }\n\n    out_uint16_le(s, icon_info->mask_bytes);\n    out_uint16_le(s, icon_info->data_bytes);\n    out_uint8p(s, icon_info->mask, icon_info->mask_bytes);\n\n    if (use_cmap)\n    {\n        out_uint8p(s, icon_info->cmap, icon_info->cmap_bytes);\n    }\n\n    out_uint8p(s, icon_info->data, icon_info->data_bytes);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order fields [MS-RDPERP] TS_ICON_INFO \"\n              \"CacheEntry %d, CacheId %d, Bpp %d, Width %d, Height %d, \"\n              \"CbColorTable <%s>, \"\n              \"CbBitsMask %d, CbBitsColor %d, BitsMask <omitted from log>, \"\n              \"ColorTable <%s>, \"\n              \"BitsColor <omitted from log>\",\n              cache_entry, cache_id, icon_info->bpp, icon_info->width,\n              icon_info->height,\n              (use_cmap ? \"present, omitted from log\" : \"not present\"),\n              icon_info->mask_bytes, icon_info->data_bytes,\n              (use_cmap ? \"present, omitted from log\" : \"not present\")\n             );\n    return 0;\n}\n\n/*****************************************************************************/\n/* RAIL */\n/* returns error */\n/* flags can contain WINDOW_ORDER_STATE_NEW and/or\n   WINDOW_ORDER_FIELD_ICON_BIG */\nint\nxrdp_orders_send_window_icon(struct xrdp_orders *self,\n                             int window_id, int cache_entry, int cache_id,\n                             struct rail_icon_info *icon_info,\n                             int flags)\n{\n    int order_size;\n    int order_flags;\n    int field_present_flags;\n    int use_cmap;\n\n    use_cmap = 0;\n\n    if ((icon_info->bpp == 1) || (icon_info->bpp == 2) || (icon_info->bpp == 4))\n    {\n        use_cmap = 1;\n    }\n\n    order_size = 23 + icon_info->mask_bytes + icon_info->data_bytes;\n\n    if (use_cmap)\n    {\n        order_size += icon_info->cmap_bytes + 2;\n    }\n\n    if (xrdp_orders_check(self, order_size) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_orders_send_window_icon: xrdp_orders_check failed\");\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_SECONDARY;\n    order_flags |= 0xb << 2; /* type TS_ALTSEC_WINDOW */\n    out_uint8(self->out_s, order_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] ALTSEC_DRAWING_ORDER_HEADER \"\n              \"controlFlags.class 0x%1.1x (TS_SECONDARY), \"\n              \"controlFlags.orderType 0x%2.2x (TS_ALTSEC_WINDOW)\",\n              (order_flags & 0x3), (order_flags >> 2));\n\n    /* orderSize (2 bytes) */\n    out_uint16_le(self->out_s, order_size);\n    /* FieldsPresentFlags (4 bytes) */\n    field_present_flags = flags | WINDOW_ORDER_TYPE_WINDOW |\n                          WINDOW_ORDER_ICON;\n    out_uint32_le(self->out_s, field_present_flags);\n    /* windowId (4 bytes) */\n    out_uint32_le(self->out_s, window_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPERP] TS_WINDOW_ORDER_HEADER \"\n              \"OrderSize %d, FieldsPresentFlags 0x%8.8x, WindowId 0x%8.8x\",\n              order_size, field_present_flags, window_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order [MS-RDPERP] Window Icon\");\n\n    xrdp_orders_send_ts_icon(self->out_s, cache_entry, cache_id, icon_info);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_orders_send_as_unicode(struct stream *s, const char *text)\n{\n    unsigned int text_len = strlen(text);\n    int i32 = utf8_as_utf16_word_count(text, text_len) * 2;\n\n    out_uint16_le(s, i32);\n    out_utf8_as_utf16_le(s, text, text_len);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_orders_get_unicode_bytes(const char *text)\n{\n    unsigned int text_len = strlen(text);\n    /* Add 1 to word size to include length ([MS-RDPERP] 2.2.1.2.1) */\n    return (utf8_as_utf16_word_count(text, text_len) + 1) * 2;\n}\n\n/*****************************************************************************/\n/* RAIL */\n/* returns error */\n/* flags can contain WINDOW_ORDER_STATE_NEW */\nint\nxrdp_orders_send_window_new_update(struct xrdp_orders *self, int window_id,\n                                   struct rail_window_state_order *window_state,\n                                   int flags)\n{\n    int order_size;\n    int order_flags;\n    int field_present_flags;\n    int index;\n\n    order_size = 11;\n    field_present_flags = flags | WINDOW_ORDER_TYPE_WINDOW;\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_OWNER)\n    {\n        /* ownerWindowId (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_STYLE)\n    {\n        /* style (4 bytes) */\n        order_size += 4;\n        /* extendedStyle (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_SHOW)\n    {\n        /* showState (1 byte) */\n        order_size += 1;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_TITLE)\n    {\n        /* titleInfo */\n        order_size += xrdp_orders_get_unicode_bytes(window_state->title_info);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET)\n    {\n        /* clientOffsetX (4 bytes) */\n        order_size += 4;\n        /* clientOffsetY (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE)\n    {\n        /* clientAreaWidth (4 bytes) */\n        order_size += 4;\n        /* clientAreaHeight (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_RP_CONTENT)\n    {\n        /* RPContent (1 byte) */\n        order_size += 1;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_ROOT_PARENT)\n    {\n        /* rootParentHandle (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_WND_OFFSET)\n    {\n        /* windowOffsetX (4 bytes) */\n        order_size += 4;\n        /* windowOffsetY (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA)\n    {\n        /* windowClientDeltaX (4 bytes) */\n        order_size += 4;\n        /* windowClientDeltaY (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_WND_SIZE)\n    {\n        /* windowWidth (4 bytes) */\n        order_size += 4;\n        /* windowHeight (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_WND_RECTS)\n    {\n        /* numWindowRects (2 bytes) */\n        order_size += 2;\n        order_size += 8 * window_state->num_window_rects;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_VIS_OFFSET)\n    {\n        /* visibleOffsetX (4 bytes) */\n        order_size += 4;\n        /* visibleOffsetY (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_VISIBILITY)\n    {\n        /* numVisibilityRects (2 bytes) */\n        order_size += 2;\n        order_size += 8 * window_state->num_visibility_rects;\n    }\n\n    if (order_size < 12)\n    {\n        /* no flags set */\n        return 0;\n    }\n\n    if (xrdp_orders_check(self, order_size) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_orders_send_window_new_update: xrdp_orders_check failed\");\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_SECONDARY;\n    order_flags |= 0xb << 2; /* type TS_ALTSEC_WINDOW */\n    out_uint8(self->out_s, order_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] ALTSEC_DRAWING_ORDER_HEADER \"\n              \"controlFlags.class 0x%1.1x (TS_SECONDARY), \"\n              \"controlFlags.orderType 0x%2.2x (TS_ALTSEC_WINDOW)\",\n              (order_flags & 0x3), (order_flags >> 2));\n\n    /* orderSize (2 bytes) */\n    out_uint16_le(self->out_s, order_size);\n    /* FieldsPresentFlags (4 bytes) */\n    out_uint32_le(self->out_s, field_present_flags);\n    /* windowId (4 bytes) */\n    out_uint32_le(self->out_s, window_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPERP] TS_WINDOW_ORDER_HEADER \"\n              \"OrderSize %d, FieldsPresentFlags 0x%8.8x, WindowId 0x%8.8x\",\n              order_size, field_present_flags, window_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order [MS-RDPERP] New or Existing Window (TS_WINDOW_INFO)\");\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_OWNER)\n    {\n        /* ownerWindowId (4 bytes) */\n        out_uint32_le(self->out_s, window_state->owner_window_id);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"OwnerWindowId 0x%8.8x\", window_state->owner_window_id);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_STYLE)\n    {\n        /* style (4 bytes) */\n        out_uint32_le(self->out_s, window_state->style);\n        /* extendedStyle (4 bytes) */\n        out_uint32_le(self->out_s, window_state->extended_style);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"Style 0x%8.8x, ExtendedStyle 0x%8.8x\",\n                  window_state->style, window_state->extended_style);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_SHOW)\n    {\n        /* showState (1 byte) */\n        out_uint8(self->out_s, window_state->show_state);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"ShowState 0x%2.2x\", window_state->show_state);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_TITLE)\n    {\n        /* titleInfo */\n        xrdp_orders_send_as_unicode(self->out_s, window_state->title_info);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"TitleInfo %s\", window_state->title_info);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET)\n    {\n        /* clientOffsetX (4 bytes) */\n        out_uint32_le(self->out_s, window_state->client_offset_x);\n        /* clientOffsetY (4 bytes) */\n        out_uint32_le(self->out_s, window_state->client_offset_y);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"ClientOffsetX  %d, ClientOffsetY %d\",\n                  window_state->client_offset_x, window_state->client_offset_y);\n    }\n\n    /* TODO: The [MS-RDPERP] spec says that:\n     * The ClientAreaWidth and ClientAreaHeight field only appears if the WndSupportLevel field of the\n     * Window List Capability Set message is set to TS_WINDOW_LEVEL_SUPPORTED_EX\n     * (as specified in [MS-RDPERP] section 2.2.1.1.2)\n     */\n    if (field_present_flags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE)\n    {\n        /* clientAreaWidth (4 bytes) */\n        out_uint32_le(self->out_s, window_state->client_area_width);\n        /* clientAreaHeight (4 bytes) */\n        out_uint32_le(self->out_s, window_state->client_area_height);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"ClientAreaWidth %d, ClientAreaHeight %d\",\n                  window_state->client_area_width, window_state->client_area_height);\n    }\n    /* TODO: The [MS-RDPERP] spec section 2.2.1.3.1.2.1 has the following additional fields:\n     * WindowLeftResizeMargin (optional)\n     * WindowRightResizeMargin (optional)\n     * WindowTopResizeMargin (optional)\n     * WindowBottomResizeMargin (optional)\n     */\n\n    /* TODO: The [MS-RDPERP] spec says that:\n     * The RPContent field only appears if the WndSupportLevel field of the\n     * Window List Capability Set message is set to TS_WINDOW_LEVEL_SUPPORTED_EX\n     * (as specified in [MS-RDPERP] section 2.2.1.1.2)\n     */\n    if (field_present_flags & WINDOW_ORDER_FIELD_RP_CONTENT)\n    {\n        /* RPContent (1 byte) */\n        out_uint8(self->out_s, window_state->rp_content);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"RPContent 0x%2.2x\", window_state->rp_content);\n    }\n\n    /* TODO: The [MS-RDPERP] spec says that:\n     * The RootParentHandle field only appears if the WndSupportLevel field of the\n     * Window List Capability Set message is set to TS_WINDOW_LEVEL_SUPPORTED_EX\n     * (as specified in [MS-RDPERP] section 2.2.1.1.2)\n     */\n    if (field_present_flags & WINDOW_ORDER_FIELD_ROOT_PARENT)\n    {\n        /* rootParentHandle (4 bytes) */\n        out_uint32_le(self->out_s, window_state->root_parent_handle);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"RootParentHandle 0x%8.8x\", window_state->root_parent_handle);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_WND_OFFSET)\n    {\n        /* windowOffsetX (4 bytes) */\n        out_uint32_le(self->out_s, window_state->window_offset_x);\n        /* windowOffsetY (4 bytes) */\n        out_uint32_le(self->out_s, window_state->window_offset_y);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"WindowOffsetX %d, WindowOffsetY %d\",\n                  window_state->window_offset_x, window_state->window_offset_y);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA)\n    {\n        /* windowClientDeltaX (4 bytes) */\n        out_uint32_le(self->out_s, window_state->window_client_delta_x);\n        /* windowClientDeltaY (4 bytes) */\n        out_uint32_le(self->out_s, window_state->window_client_delta_y);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"WindowClientDeltaX %d, WindowClientDeltaY %d\",\n                  window_state->window_client_delta_x, window_state->window_client_delta_y);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_WND_SIZE)\n    {\n        /* windowWidth (4 bytes) */\n        out_uint32_le(self->out_s, window_state->window_width);\n        /* windowHeight (4 bytes) */\n        out_uint32_le(self->out_s, window_state->window_height);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"WindowWidth %d, WindowHeight %d\",\n                  window_state->window_width, window_state->window_height);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_WND_RECTS)\n    {\n        /* numWindowRects (2 bytes) */\n        out_uint16_le(self->out_s, window_state->num_window_rects);\n\n        for (index = 0; index < window_state->num_window_rects; index++)\n        {\n            out_uint16_le(self->out_s, window_state->window_rects[index].left);\n            out_uint16_le(self->out_s, window_state->window_rects[index].top);\n            out_uint16_le(self->out_s, window_state->window_rects[index].right);\n            out_uint16_le(self->out_s, window_state->window_rects[index].bottom);\n        }\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"NumWindowRects %d, WindowRects <omitted from log>\",\n                  window_state->num_window_rects);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_VIS_OFFSET)\n    {\n        /* visibleOffsetX (4 bytes) */\n        out_uint32_le(self->out_s, window_state->visible_offset_x);\n        /* visibleOffsetY (4 bytes) */\n        out_uint32_le(self->out_s, window_state->visible_offset_y);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"VisibleOffsetX %d, VisibleOffsetY %d\",\n                  window_state->visible_offset_x, window_state->visible_offset_y);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_VISIBILITY)\n    {\n        /* numVisibilityRects (2 bytes) */\n        out_uint16_le(self->out_s, window_state->num_visibility_rects);\n\n        for (index = 0; index < window_state->num_visibility_rects; index++)\n        {\n            out_uint16_le(self->out_s, window_state->visibility_rects[index].left);\n            out_uint16_le(self->out_s, window_state->visibility_rects[index].top);\n            out_uint16_le(self->out_s, window_state->visibility_rects[index].right);\n            out_uint16_le(self->out_s, window_state->visibility_rects[index].bottom);\n        }\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding optional field [MS-RDPERP] TS_WINDOW_INFO \"\n                  \"NumVisibilityRects %d, VisibilityRects <omitted from log>\",\n                  window_state->num_visibility_rects);\n    }\n    /* TODO: The [MS-RDPERP] spec section 2.2.1.3.1.2.1 has the following additional fields:\n     * OverlayDescription (optional, variable)\n     * TaskbarButton (optional)\n     * EnforceServerZOrder (optional)\n     * AppBarState (optional)\n     * AppBarEdge (optional)\n     */\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* RAIL */\n/* returns error */\nint\nxrdp_orders_send_notify_delete(struct xrdp_orders *self, int window_id,\n                               int notify_id)\n{\n    int order_size;\n    int order_flags;\n    int field_present_flags;\n\n    order_size = 15;\n    if (xrdp_orders_check(self, order_size) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_orders_send_notify_delete: xrdp_orders_check failed\");\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_SECONDARY;\n    order_flags |= 0xb << 2; /* type TS_ALTSEC_WINDOW */\n    out_uint8(self->out_s, order_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] ALTSEC_DRAWING_ORDER_HEADER \"\n              \"controlFlags.class 0x%1.1x (TS_SECONDARY), \"\n              \"controlFlags.orderType 0x%2.2x (TS_ALTSEC_WINDOW)\",\n              (order_flags & 0x3), (order_flags >> 2));\n\n    /* orderSize (2 bytes) */\n    out_uint16_le(self->out_s, order_size);\n    /* FieldsPresentFlags (4 bytes) */\n    field_present_flags = WINDOW_ORDER_TYPE_NOTIFY | WINDOW_ORDER_STATE_DELETED;\n    out_uint32_le(self->out_s, field_present_flags);\n    /* windowId (4 bytes) */\n    out_uint32_le(self->out_s, window_id);\n    /* notifyIconId (4 bytes) */\n    out_uint32_le(self->out_s, notify_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPERP] TS_NOTIFYICON_ORDER_HEADER \"\n              \"OrderSize %d, FieldsPresentFlags 0x%8.8x, WindowId 0x%8.8x, NotifyIconId 0x%8.8x\",\n              order_size, field_present_flags, window_id, notify_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order [MS-RDPERP] Deleted Notification Icons\");\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* RAIL */\n/* returns error */\n/* flags can contain WINDOW_ORDER_STATE_NEW */\nint\nxrdp_orders_send_notify_new_update(struct xrdp_orders *self,\n                                   int window_id, int notify_id,\n                                   struct rail_notify_state_order *notify_state,\n                                   int flags)\n{\n    int order_size;\n    int order_flags;\n    int field_present_flags;\n    int use_cmap;\n\n    order_size = 15;\n    field_present_flags = flags | WINDOW_ORDER_TYPE_NOTIFY;\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_NOTIFY_VERSION)\n    {\n        /* Version (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_NOTIFY_TIP)\n    {\n        /* ToolTip (variable) UNICODE_STRING */\n        order_size += xrdp_orders_get_unicode_bytes(notify_state->tool_tip);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP)\n    {\n        /* InfoTip (variable) TS_NOTIFY_ICON_INFOTIP */\n        /* UNICODE_STRING */\n        order_size += xrdp_orders_get_unicode_bytes(notify_state->infotip.title);\n        /* UNICODE_STRING */\n        order_size += xrdp_orders_get_unicode_bytes(notify_state->infotip.text);\n        /* Timeout (4 bytes) */\n        /* InfoFlags (4 bytes) */\n        order_size += 8;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_NOTIFY_STATE)\n    {\n        /* State (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_ICON)\n    {\n        /* Icon (variable) */\n        use_cmap = 0;\n\n        if ((notify_state->icon_info.bpp == 1) || (notify_state->icon_info.bpp == 2) ||\n                (notify_state->icon_info.bpp == 4))\n        {\n            use_cmap = 1;\n        }\n\n        order_size += 12 + notify_state->icon_info.mask_bytes +\n                      notify_state->icon_info.data_bytes;\n\n        if (use_cmap)\n        {\n            order_size += notify_state->icon_info.cmap_bytes + 2;\n        }\n    }\n\n    if (field_present_flags & WINDOW_ORDER_CACHED_ICON)\n    {\n        /* CachedIcon (3 bytes) */\n        order_size += 3;\n    }\n\n    if (xrdp_orders_check(self, order_size) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_orders_send_notify_new_update: xrdp_orders_check failed\");\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_SECONDARY;\n    order_flags |= 0xb << 2; /* type TS_ALTSEC_WINDOW */\n    out_uint8(self->out_s, order_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] ALTSEC_DRAWING_ORDER_HEADER \"\n              \"controlFlags.class 0x%1.1x (TS_SECONDARY), \"\n              \"controlFlags.orderType 0x%2.2x (TS_ALTSEC_WINDOW)\",\n              (order_flags & 0x3), (order_flags >> 2));\n\n    /* orderSize (2 bytes) */\n    out_uint16_le(self->out_s, order_size);\n    /* FieldsPresentFlags (4 bytes) */\n    out_uint32_le(self->out_s, field_present_flags);\n    /* windowId (4 bytes) */\n    out_uint32_le(self->out_s, window_id);\n    /* notifyIconId (4 bytes) */\n    out_uint32_le(self->out_s, notify_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPERP] TS_NOTIFYICON_ORDER_HEADER \"\n              \"OrderSize %d, FieldsPresentFlags 0x%8.8x, WindowId 0x%8.8x, NotifyIconId 0x%8.8x\",\n              order_size, field_present_flags, window_id, notify_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order [MS-RDPERP] New or Existing Notification Icons\");\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_NOTIFY_VERSION)\n    {\n        /* Version (4 bytes) */\n        out_uint32_le(self->out_s, notify_state->version);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order optional field [MS-RDPERP] \"\n                  \"Version %d\", notify_state->version);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_NOTIFY_TIP)\n    {\n        /* ToolTip (variable) UNICODE_STRING */\n        xrdp_orders_send_as_unicode(self->out_s, notify_state->tool_tip);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order optional field [MS-RDPERP] \"\n                  \"ToolTip %s\", notify_state->tool_tip);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP)\n    {\n        /* InfoTip (variable) TS_NOTIFY_ICON_INFOTIP */\n        out_uint32_le(self->out_s, notify_state->infotip.timeout);\n        out_uint32_le(self->out_s, notify_state->infotip.flags);\n        xrdp_orders_send_as_unicode(self->out_s, notify_state->infotip.text);\n        xrdp_orders_send_as_unicode(self->out_s, notify_state->infotip.title);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order optional field [MS-RDPERP] TS_NOTIFY_ICON_INFOTIP \"\n                  \"Timeout %d, InfoFlags 0x%8.8x, InfoTipText %s, Title %s\",\n                  notify_state->infotip.timeout, notify_state->infotip.flags,\n                  notify_state->infotip.text, notify_state->infotip.title);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_NOTIFY_STATE)\n    {\n        /* State (4 bytes) */\n        out_uint32_le(self->out_s, notify_state->state);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order optional field [MS-RDPERP] \"\n                  \"State %d\", notify_state->state);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_ICON)\n    {\n        /* Icon (variable) */\n        xrdp_orders_send_ts_icon(self->out_s, notify_state->icon_cache_entry,\n                                 notify_state->icon_cache_id,\n                                 &notify_state->icon_info);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_CACHED_ICON)\n    {\n        /* CacheEntry (2 bytes) */\n        out_uint16_le(self->out_s, notify_state->icon_cache_entry);\n        /* CacheId (1 byte) */\n        out_uint8(self->out_s, notify_state->icon_cache_id);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order field [MS-RDPERP] TS_CACHED_ICON_INFO \"\n                  \"CacheEntry %d, CacheId %d\",\n                  notify_state->icon_cache_entry, notify_state->icon_cache_id);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* RAIL */\n/* returns error */\n/* used for both Non-Monitored Desktop and Actively Monitored Desktop */\nint\nxrdp_orders_send_monitored_desktop(struct xrdp_orders *self,\n                                   struct rail_monitored_desktop_order *mdo,\n                                   int flags)\n{\n    int order_size;\n    int order_flags;\n    int field_present_flags;\n    int index;\n\n    order_size = 7;\n    field_present_flags = flags | WINDOW_ORDER_TYPE_DESKTOP;\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND)\n    {\n        /* ActiveWindowId (4 bytes) */\n        order_size += 4;\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_DESKTOP_ZORDER)\n    {\n        /* NumWindowIds (1 byte) */\n        order_size += 1;\n        /* WindowIds (variable) */\n        order_size += mdo->num_window_ids *  4;\n    }\n\n    if (xrdp_orders_check(self, order_size) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_orders_send_monitored_desktop: xrdp_orders_check failed\");\n        return 1;\n    }\n    self->order_count++;\n    order_flags = TS_SECONDARY;\n    order_flags |= 0xb << 2; /* type TS_ALTSEC_WINDOW */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPEGDI] ALTSEC_DRAWING_ORDER_HEADER \"\n              \"controlFlags.class 0x%1.1x (TS_SECONDARY), \"\n              \"controlFlags.orderType 0x%2.2x (TS_ALTSEC_WINDOW)\",\n              (order_flags & 0x3), (order_flags >> 2));\n\n    out_uint8(self->out_s, order_flags);\n    /* orderSize (2 bytes) */\n    out_uint16_le(self->out_s, order_size);\n    /* FieldsPresentFlags (4 bytes) */\n    out_uint32_le(self->out_s, field_present_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPERP] TS_DESKTOP_ORDER_HEADER \"\n              \"OrderSize %d, FieldsPresentFlags 0x%8.8x\",\n              order_size, field_present_flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order [MS-RDPERP] %s\",\n              ((field_present_flags & WINDOW_ORDER_FIELD_DESKTOP_NONE) ?\n               \"Non-Monitored Desktop\" : \"Actively Monitored Desktop\"));\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND)\n    {\n        /* ActiveWindowId (4 bytes) */\n        out_uint32_le(self->out_s, mdo->active_window_id);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order optional field [MS-RDPERP] \"\n                  \"ActiveWindowId 0x%8.8x\", mdo->active_window_id);\n    }\n\n    if (field_present_flags & WINDOW_ORDER_FIELD_DESKTOP_ZORDER)\n    {\n        /* NumWindowIds (1 byte) */\n        out_uint8(self->out_s, mdo->num_window_ids);\n\n        /* WindowIds (variable) */\n        for (index = 0; index < mdo->num_window_ids; index++)\n        {\n            out_uint32_le(self->out_s, mdo->window_ids[index]);\n        }\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding order optional field [MS-RDPERP] \"\n                  \"NumWindowIds %d, WindowIds <omitted from log>\",\n                  mdo->num_window_ids);\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_orders_rail.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(_XRDP_ORDERS_RAIL_H)\n#define _XRDP_ORDERS_RAIL_H\n\n#include \"libxrdp.h\"\n\nint\nxrdp_orders_send_window_delete(struct xrdp_orders *self, int window_id);\nint\nxrdp_orders_send_window_cached_icon(struct xrdp_orders *self,\n                                    int window_id, int cache_entry,\n                                    int cache_id, int flags);\nint\nxrdp_orders_send_window_icon(struct xrdp_orders *self,\n                             int window_id, int cache_entry, int cache_id,\n                             struct rail_icon_info *icon_info,\n                             int flags);\nint\nxrdp_orders_send_window_new_update(struct xrdp_orders *self, int window_id,\n                                   struct rail_window_state_order *window_state,\n                                   int flags);\nint\nxrdp_orders_send_notify_delete(struct xrdp_orders *self, int window_id,\n                               int notify_id);\nint\nxrdp_orders_send_notify_new_update(struct xrdp_orders *self,\n                                   int window_id, int notify_id,\n                                   struct rail_notify_state_order *notify_state,\n                                   int flags);\nint\nxrdp_orders_send_monitored_desktop(struct xrdp_orders *self,\n                                   struct rail_monitored_desktop_order *mdo,\n                                   int flags);\n\n#endif\n"
  },
  {
    "path": "libxrdp/xrdp_rdp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * rdp layer\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"log.h\"\n#include \"ssl_calls.h\"\n#include \"string_calls.h\"\n\n#if defined(XRDP_NEUTRINORDP)\n#include <freerdp/codec/rfx.h>\n#include <freerdp/constants.h>\n#endif\n\n\n\n#define FASTPATH_FRAG_SIZE (16 * 1024 - 128)\n\n/*****************************************************************************/\nstatic int\nxrdp_rdp_read_config(const char *xrdp_ini, struct xrdp_client_info *client_info)\n{\n    int index = 0;\n    struct list *items = (struct list *)NULL;\n    struct list *values = (struct list *)NULL;\n    char *item = NULL;\n    char *value = NULL;\n    int pos;\n    char *tmp = NULL;\n    int tmp_length;\n\n    client_info->xrdp_keyboard_overrides.type = -1;\n    client_info->xrdp_keyboard_overrides.subtype = -1;\n    client_info->xrdp_keyboard_overrides.layout = -1;\n\n    /* initialize (zero out) local variables: */\n    items = list_create();\n    items->auto_free = 1;\n    values = list_create();\n    values->auto_free = 1;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Reading config file %s\", xrdp_ini);\n    file_by_name_read_section(xrdp_ini, \"globals\", items, values);\n\n    for (index = 0; index < items->count; index++)\n    {\n        item = (char *)list_get_item(items, index);\n        value = (char *)list_get_item(values, index);\n        LOG(LOG_LEVEL_DEBUG, \"item %s, value %s\", item, value);\n\n        if (g_strcasecmp(item, \"bitmap_cache\") == 0)\n        {\n            client_info->use_bitmap_cache = g_text2bool(value);\n        }\n        else if (g_strcasecmp(item, \"bitmap_compression\") == 0)\n        {\n            client_info->use_bitmap_comp = g_text2bool(value);\n        }\n        else if (g_strcasecmp(item, \"bulk_compression\") == 0)\n        {\n            client_info->use_bulk_comp = g_text2bool(value);\n        }\n        else if (g_strcasecmp(item, \"crypt_level\") == 0)\n        {\n            if (g_strcasecmp(value, \"none\") == 0)\n            {\n                client_info->crypt_level = 0;\n            }\n            else if (g_strcasecmp(value, \"low\") == 0)\n            {\n                client_info->crypt_level = 1;\n            }\n            else if (g_strcasecmp(value, \"medium\") == 0)\n            {\n                client_info->crypt_level = 2;\n            }\n            else if (g_strcasecmp(value, \"high\") == 0)\n            {\n                client_info->crypt_level = 3;\n            }\n            else if (g_strcasecmp(value, \"fips\") == 0)\n            {\n                client_info->crypt_level = 4;\n            }\n            else\n            {\n                LOG(LOG_LEVEL_WARNING, \"Your configured crypt level is \"\n                    \"undefined, 'high' will be used\");\n                client_info->crypt_level = 3;\n            }\n        }\n        else if (g_strcasecmp(item, \"allow_channels\") == 0)\n        {\n            client_info->channels_allowed = g_text2bool(value);\n            if (client_info->channels_allowed == 0)\n            {\n                LOG(LOG_LEVEL_INFO, \"All channels are disabled\");\n            }\n        }\n        else if (g_strcasecmp(item, \"allow_multimon\") == 0)\n        {\n            client_info->multimon = g_text2bool(value);\n            if (client_info->multimon == 0)\n            {\n                LOG(LOG_LEVEL_INFO, \"Multi monitor server support disabled\");\n            }\n        }\n        else if (g_strcasecmp(item, \"max_bpp\") == 0)\n        {\n            client_info->max_bpp = g_atoi(value);\n        }\n        else if (g_strcasecmp(item, \"rfx_min_pixel\") == 0)\n        {\n            client_info->rfx_min_pixel = g_atoi(value);\n        }\n        else if (g_strcasecmp(item, \"new_cursors\") == 0)\n        {\n            client_info->pointer_flags = g_text2bool(value) == 0 ? 2 : 0;\n        }\n        else if (g_strcasecmp(item, \"require_credentials\") == 0)\n        {\n            client_info->require_credentials = g_text2bool(value);\n        }\n        else if (g_strcasecmp(item, \"enable_token_login\") == 0)\n        {\n            client_info->enable_token_login = g_text2bool(value);\n        }\n        else if (g_strcasecmp(item, \"use_fastpath\") == 0)\n        {\n            if (g_strcasecmp(value, \"output\") == 0)\n            {\n                client_info->use_fast_path = 1;\n            }\n            else if (g_strcasecmp(value, \"input\") == 0)\n            {\n                client_info->use_fast_path = 2;\n            }\n            else if (g_strcasecmp(value, \"both\") == 0)\n            {\n                client_info->use_fast_path = 3;\n            }\n            else if (g_strcasecmp(value, \"none\") == 0)\n            {\n                client_info->use_fast_path = 0;\n            }\n            else\n            {\n                LOG(LOG_LEVEL_WARNING, \"Your configured fastpath level is \"\n                    \"undefined, fastpath will not be used\");\n                client_info->use_fast_path = 0;\n            }\n        }\n        else if (g_strcasecmp(item, \"ssl_protocols\") == 0)\n        {\n            /* put leading/trailing comma to properly detect \"TLSv1\" without regex */\n            tmp_length = g_strlen(value) + 3;\n            tmp = g_new(char, tmp_length);\n            g_snprintf(tmp, tmp_length, \"%s%s%s\", \",\", value, \",\");\n            /* replace all spaces with comma */\n            /* to accept space after comma */\n            while ((pos = g_pos(tmp, \" \")) != -1)\n            {\n                tmp[pos] = ',';\n            }\n            ssl_get_protocols_from_string(tmp, &(client_info->ssl_protocols));\n            g_free(tmp);\n        }\n        else if (g_strcasecmp(item, \"tls_ciphers\") == 0)\n        {\n            client_info->tls_ciphers = g_strdup(value);\n        }\n        else if (g_strcasecmp(item, \"security_layer\") == 0)\n        {\n            if (g_strcasecmp(value, \"rdp\") == 0)\n            {\n                client_info->security_layer = SECURITY_LAYER_RDP;\n            }\n            else if (g_strcasecmp(value, \"tls\") == 0)\n            {\n                client_info->security_layer = SECURITY_LAYER_TLS;\n            }\n            else if (g_strcasecmp(value, \"negotiate\") == 0)\n            {\n                client_info->security_layer = SECURITY_LAYER_NEGOTIATE;\n            }\n            else\n            {\n                LOG(LOG_LEVEL_WARNING, \"security_layer=%s is not \"\n                    \"recognized, will use security_layer=negotiate\",\n                    value);\n                client_info->security_layer = SECURITY_LAYER_NEGOTIATE;\n            }\n        }\n        else if (g_strcasecmp(item, \"vmconnect\") == 0)\n        {\n            client_info->vmconnect = g_text2bool(value);\n        }\n        else if (g_strcasecmp(item, \"certificate\") == 0)\n        {\n            g_memset(client_info->certificate, 0, sizeof(char) * 1024);\n            if (g_strlen(value) == 0)\n            {\n                /* default certificate path */\n                g_snprintf(client_info->certificate, 1023, \"%s/cert.pem\", XRDP_CFG_PATH);\n                LOG(LOG_LEVEL_INFO,\n                    \"Using default X.509 certificate: %s\",\n                    client_info->certificate);\n\n            }\n            else if (value[0] != '/')\n            {\n                /* default certificate path */\n                g_snprintf(client_info->certificate, 1023, \"%s/cert.pem\", XRDP_CFG_PATH);\n                LOG(LOG_LEVEL_WARNING,\n                    \"X.509 certificate should use absolute path, using \"\n                    \"default instead: %s\", client_info->certificate);\n            }\n            else\n            {\n                /* use user defined certificate */\n                g_strncpy(client_info->certificate, value, 1023);\n            }\n\n            if (!g_file_readable(client_info->certificate))\n            {\n                LOG(LOG_LEVEL_ERROR, \"Cannot read certificate file %s: %s\",\n                    client_info->certificate, g_get_strerror());\n            }\n        }\n        else if (g_strcasecmp(item, \"key_file\") == 0)\n        {\n            g_memset(client_info->key_file, 0, sizeof(char) * 1024);\n            if (g_strlen(value) == 0)\n            {\n                /* default key_file path */\n                g_snprintf(client_info->key_file, 1023, \"%s/key.pem\", XRDP_CFG_PATH);\n                LOG(LOG_LEVEL_INFO, \"Using default X.509 key file: %s\",\n                    client_info->key_file);\n            }\n            else if (value[0] != '/')\n            {\n                /* default key_file path */\n                g_snprintf(client_info->key_file, 1023, \"%s/key.pem\", XRDP_CFG_PATH);\n                LOG(LOG_LEVEL_WARNING,\n                    \"X.509 key file should use absolute path, using \"\n                    \"default instead: %s\", client_info->key_file);\n            }\n            else\n            {\n                /* use user defined key_file */\n                g_strncpy(client_info->key_file, value, 1023);\n            }\n\n            if (!g_file_readable(client_info->key_file))\n            {\n                LOG(LOG_LEVEL_ERROR, \"Cannot read private key file %s: %s\",\n                    client_info->key_file, g_get_strerror());\n            }\n        }\n        else if (g_strcasecmp(item, \"tls_pms_log_file\") == 0)\n        {\n            if (ssl_set_pre_master_secret_logfile(value))\n            {\n                LOG(LOG_LEVEL_WARNING, \"TLS pre-master secrets will be logged. \"\n                    \"This is a security risk.\");\n            }\n        }\n        else if (g_strcasecmp(item, \"domain_user_separator\") == 0\n                 && g_strlen(value) > 0)\n        {\n            g_strncpy(client_info->domain_user_separator, value, sizeof(client_info->domain_user_separator) - 1);\n        }\n        else if (g_strcasecmp(item, \"xrdp.override_keyboard_type\") == 0)\n        {\n            client_info->xrdp_keyboard_overrides.type = g_atoix(value);\n        }\n        else if (g_strcasecmp(item, \"xrdp.override_keyboard_subtype\") == 0)\n        {\n            client_info->xrdp_keyboard_overrides.subtype = g_atoix(value);\n        }\n        else if (g_strcasecmp(item, \"xrdp.override_keylayout\") == 0)\n        {\n            client_info->xrdp_keyboard_overrides.layout = g_atoix(value);\n        }\n    }\n\n    list_delete(items);\n    list_delete(values);\n    return 0;\n}\n\n#if defined(XRDP_NEUTRINORDP)\n/*****************************************************************************/\nstatic void\ncpuid(tui32 info, tui32 *eax, tui32 *ebx, tui32 *ecx, tui32 *edx)\n{\n#ifdef __GNUC__\n#if defined(__i386__) || defined(__x86_64__)\n    __asm volatile\n    (\n        /* The EBX (or RBX register on x86_64) is used for the PIC base address\n           and must not be corrupted by our inline assembly. */\n#if defined(__i386__)\n        \"mov %%ebx, %%esi;\"\n        \"cpuid;\"\n        \"xchg %%ebx, %%esi;\"\n#else\n        \"mov %%rbx, %%rsi;\"\n        \"cpuid;\"\n        \"xchg %%rbx, %%rsi;\"\n#endif\n        : \"=a\" (*eax), \"=S\" (*ebx), \"=c\" (*ecx), \"=d\" (*edx)\n        : \"0\" (info)\n    );\n#endif\n#endif\n}\n\n/*****************************************************************************/\nstatic tui32\nxrdp_rdp_detect_cpu(void)\n{\n    tui32 eax;\n    tui32 ebx;\n    tui32 ecx;\n    tui32 edx;\n    tui32 cpu_opt;\n\n    eax = 0;\n    ebx = 0;\n    ecx = 0;\n    edx = 0;\n    cpu_opt = 0;\n    cpuid(1, &eax, &ebx, &ecx, &edx);\n\n    if (edx & (1 << 26))\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"SSE2 detected\");\n        cpu_opt |= CPU_SSE2;\n    }\n\n    return cpu_opt;\n}\n#endif\n\n/*****************************************************************************/\nstruct xrdp_rdp *\nxrdp_rdp_create(struct xrdp_session *session, struct trans *trans)\n{\n    struct xrdp_rdp *self = (struct xrdp_rdp *)NULL;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"in xrdp_rdp_create\");\n    self = (struct xrdp_rdp *)g_malloc(sizeof(struct xrdp_rdp), 1);\n    self->session = session;\n    self->share_id = 66538;\n    /* read ini settings */\n    xrdp_rdp_read_config(session->xrdp_ini, &self->client_info);\n    /* create sec layer */\n    self->sec_layer = xrdp_sec_create(self, trans);\n    /* default 8 bit v1 color bitmap cache entries and size */\n    self->client_info.cache1_entries = 600;\n    self->client_info.cache1_size = 256;\n    self->client_info.cache2_entries = 300;\n    self->client_info.cache2_size = 1024;\n    self->client_info.cache3_entries = 262;\n    self->client_info.cache3_size = 4096;\n    /* load client ip info */\n    g_sck_get_peer_ip_address(trans->sck,\n                              self->client_info.client_ip,\n                              sizeof(self->client_info.client_ip),\n                              NULL);\n    g_sck_get_peer_description(trans->sck,\n                               self->client_info.client_description,\n                               sizeof(self->client_info.client_description));\n    self->mppc_enc = mppc_enc_new(PROTO_RDP_50);\n#if defined(XRDP_NEUTRINORDP)\n    self->rfx_enc = rfx_context_new();\n    rfx_context_set_cpu_opt(self->rfx_enc, xrdp_rdp_detect_cpu());\n#endif\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"out xrdp_rdp_create\");\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_rdp_delete(struct xrdp_rdp *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n\n    xrdp_sec_delete(self->sec_layer);\n    mppc_enc_free(self->mppc_enc);\n#if defined(XRDP_NEUTRINORDP)\n    rfx_context_free((RFX_CONTEXT *)(self->rfx_enc));\n#endif\n    g_free(self->client_info.tls_ciphers);\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* Initialize the stream for sending a [MS-RDPBCGR] Control PDU */\nint\nxrdp_rdp_init(struct xrdp_rdp *self, struct stream *s)\n{\n    if (xrdp_sec_init(self->sec_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_init: xrdp_sec_init failed\");\n        return 1;\n    }\n\n    s_push_layer(s, rdp_hdr, 6); /* 6 = sizeof(TS_SHARECONTROLHEADER) */\n    return 0;\n}\n\n/*****************************************************************************/\n/* Initialize the stream for sending a [MS-RDPBCGR] Data PDU */\nint\nxrdp_rdp_init_data(struct xrdp_rdp *self, struct stream *s)\n{\n    if (xrdp_sec_init(self->sec_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_init_data: xrdp_sec_init failed\");\n        return 1;\n    }\n\n    s_push_layer(s, rdp_hdr, 18);  /* 18 = sizeof(TS_SHAREDATAHEADER) */\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n  Receives and parses pdu code from next data unit.\n\n  @param self\n  @param (in/out) s: the stream to read from. Upon return the stream is ?\n  @param (out) code: the pdu code from the packet\n  returns error\n  */\nint\nxrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code)\n{\n    int error;\n    int len = 0;\n    int pdu_code = 0;\n    int chan;\n    const tui8 *header;\n\n\n    if (s->next_packet == 0 || s->next_packet >= s->end)\n    {\n        /* check for fastpath first */\n        header = (const tui8 *) (s->p);\n        if (header[0] != 0x3)\n        {\n            if (xrdp_sec_recv_fastpath(self->sec_layer, s) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_recv: xrdp_sec_recv_fastpath failed\");\n                return 1;\n            }\n            /* next_packet gets set in xrdp_sec_recv_fastpath */\n            *code = 2; // special code for fastpath input\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_rdp_recv: out code 2 (fastpath)\");\n            return 0;\n        }\n\n        /* not fastpath, do tpkt */\n        chan = 0;\n        error = xrdp_sec_recv(self->sec_layer, s, &chan);\n\n        if (error == -1) /* special code for send demand active */\n        {\n            s->next_packet = 0;\n            *code = -1;\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_rdp_recv: out code -1 (send demand active)\");\n            return 0;\n        }\n\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_recv: xrdp_sec_recv failed\");\n            return 1;\n        }\n\n        if ((chan != MCS_GLOBAL_CHANNEL) && (chan > 0))\n        {\n            if (chan > MCS_GLOBAL_CHANNEL)\n            {\n                if (xrdp_channel_process(self->sec_layer->chan_layer, s, chan) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_recv: xrdp_channel_process failed\");\n                }\n            }\n            else\n            {\n                if (chan != 1)\n                {\n                    LOG_DEVEL(LOG_LEVEL_WARNING,\n                              \"xrdp_rdp_recv: Wrong channel Id to be handled \"\n                              \"by xrdp_channel_process, channel id %d\", chan);\n                }\n            }\n\n            s->next_packet = 0;\n            *code = 0;\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_rdp_recv: out code 0 (skip data) \"\n                      \"data processed by channel id %d\", chan);\n            return 0;\n        }\n\n        s->next_packet = s->p;\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_rdp_recv: stream not touched\");\n        s->p = s->next_packet;\n    }\n\n    if (!s_check_rem_and_log(s, 6, \"Parsing [MS-RDPBCGR] TS_SHARECONTROLHEADER\"))\n    {\n        s->next_packet = 0;\n        *code = 0;\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_recv: out code 0 (skip data) \"\n            \"bad RDP packet\");\n        return 0;\n    }\n    else\n    {\n        in_uint16_le(s, len);      /* totalLength */\n        in_uint16_le(s, pdu_code); /* pduType */\n        *code = pdu_code & 0xf;\n        in_uint8s(s, 2);           /* pduSource */\n        s->next_packet += len;\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPBCGR] TS_SHARECONTROLHEADER \"\n                  \"totalLength %d, pduType.type %s (%d), pduType.PDUVersion %d, \"\n                  \"pduSource (ignored)\", len, PDUTYPE_TO_STR(*code), *code,\n                  ((pdu_code & 0xfff0) >> 4));\n        return 0;\n    }\n}\n\n/*****************************************************************************/\n/* Send a [MS-RDPBCGR] Control PDU with for the given pduType with the headers\n   added */\nint\nxrdp_rdp_send(struct xrdp_rdp *self, struct stream *s, int pdu_type)\n{\n    int len = 0;\n\n    s_pop_layer(s, rdp_hdr);\n    len = s->end - s->p;\n\n    /* TS_SHARECONTROLHEADER */\n    out_uint16_le(s, len);               /* totalLength */\n    out_uint16_le(s, 0x10 | pdu_type);   /* pduType */\n    out_uint16_le(s, self->mcs_channel); /* pduSource */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_SHARECONTROLHEADER \"\n              \"totalLength %d, pduType.type %s (%d), pduType.PDUVersion %d, \"\n              \"pduSource %d\", len, PDUTYPE_TO_STR(pdu_type & 0xf),\n              pdu_type & 0xf, (((0x10 | pdu_type) & 0xfff0) >> 4),\n              self->mcs_channel);\n\n    if (xrdp_sec_send(self->sec_layer, s, MCS_GLOBAL_CHANNEL) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_send: xrdp_sec_send failed\");\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Send a [MS-RDPBCGR] Data PDU for the given pduType2 from\n * the specified source with the headers\n    added and data compressed */\nint\nxrdp_rdp_send_data_from_channel(struct xrdp_rdp *self, struct stream *s,\n                                int data_pdu_type, int channel_id,\n                                int compress)\n{\n    int len;\n    int ctype;\n    int clen;\n    int dlen;\n    int pdulen;\n    int pdutype;\n    int tocomplen;\n    int iso_offset;\n    int mcs_offset;\n    int sec_offset;\n    int rdp_offset;\n    struct stream ls;\n    struct xrdp_mppc_enc *mppc_enc;\n\n    s_pop_layer(s, rdp_hdr);\n    len = (int)(s->end - s->p);\n    pdutype = 0x10 | PDUTYPE_DATAPDU;\n    pdulen = len;\n    dlen = len;\n    ctype = 0;\n    clen = len;\n    tocomplen = pdulen - 18;\n\n    if (compress && self->client_info.rdp_compression &&\n            self->session->up_and_running)\n    {\n        mppc_enc = self->mppc_enc;\n        if (compress_rdp(mppc_enc, (tui8 *)(s->p + 18), tocomplen))\n        {\n            clen = mppc_enc->bytes_in_opb + 18;\n            pdulen = clen;\n            ctype = mppc_enc->flags;\n            iso_offset = (int)(s->iso_hdr - s->data);\n            mcs_offset = (int)(s->mcs_hdr - s->data);\n            sec_offset = (int)(s->sec_hdr - s->data);\n            rdp_offset = (int)(s->rdp_hdr - s->data);\n\n            /* outputBuffer has 64 bytes preceding it */\n            ls.data = mppc_enc->outputBuffer - (rdp_offset + 18);\n            ls.p = ls.data + rdp_offset;\n            ls.end = ls.p + clen;\n            ls.size = s->end - s->data;\n            ls.iso_hdr = ls.data + iso_offset;\n            ls.mcs_hdr = ls.data + mcs_offset;\n            ls.sec_hdr = ls.data + sec_offset;\n            ls.rdp_hdr = ls.data + rdp_offset;\n            ls.channel_hdr = 0;\n            ls.next_packet = 0;\n            s = &ls;\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_TRACE,\n                      \"xrdp_rdp_send_data_from_channel: \"\n                      \"compress_rdp failed, sending \"\n                      \"uncompressed data. type %d, flags %d\",\n                      mppc_enc->protocol_type, mppc_enc->flags);\n        }\n    }\n\n    /* TS_SHARECONTROLHEADER */\n    out_uint16_le(s, pdulen);            /* totalLength */\n    out_uint16_le(s, pdutype);           /* pduType */\n    out_uint16_le(s, channel_id);        /* pduSource */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_SHARECONTROLHEADER \"\n              \"totalLength %d, pduType.type %s (%d), pduType.PDUVersion %d, \"\n              \"pduSource %d\", pdulen, PDUTYPE_TO_STR(pdutype & 0xf),\n              pdutype & 0xf, ((pdutype & 0xfff0) >> 4), channel_id);\n\n    /* TS_SHAREDATAHEADER */\n    out_uint32_le(s, self->share_id);\n    out_uint8(s, 0); /* pad */\n    out_uint8(s, 1); /* streamID */\n    out_uint16_le(s, dlen); /* uncompressedLength */\n    out_uint8(s, data_pdu_type); /* pduType2 */\n    out_uint8(s, ctype); /* compressedType */\n    out_uint16_le(s, clen); /* compressedLength */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_SHAREDATAHEADER \"\n              \"shareID %d, streamID 1, uncompressedLength %d, \"\n              \"pduType2 0x%2.2x, compressedType 0x%2.2x, compressedLength %d\",\n              self->share_id, dlen, data_pdu_type, ctype, clen);\n\n    if (xrdp_sec_send(self->sec_layer, s, MCS_GLOBAL_CHANNEL) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_send_data_from_channel: \"\n            \"xrdp_sec_send failed\");\n        return 1;\n    }\n\n    return 0;\n}\n\n\n/*****************************************************************************/\n/* Send a [MS-RDPBCGR] Data PDU on the MCS channel for the given pduType2\n * with the headers added and data compressed */\nint\nxrdp_rdp_send_data(struct xrdp_rdp *self, struct stream *s,\n                   int data_pdu_type)\n{\n    return xrdp_rdp_send_data_from_channel(self, s, data_pdu_type,\n                                           self->mcs_channel, 1);\n}\n\n/*****************************************************************************/\n/* returns the fastpath rdp byte count */\nint\nxrdp_rdp_get_fastpath_bytes(struct xrdp_rdp *self)\n{\n    if (self->client_info.rdp_compression)\n    {\n        return 4;\n    }\n    return 3;\n}\n\n/*****************************************************************************/\nint\nxrdp_rdp_init_fastpath(struct xrdp_rdp *self, struct stream *s)\n{\n    if (xrdp_sec_init_fastpath(self->sec_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_init_fastpath: xrdp_sec_init_fastpath failed\");\n        return 1;\n    }\n    if (self->client_info.rdp_compression)\n    {\n        s_push_layer(s, rdp_hdr, 4);\n    }\n    else\n    {\n        s_push_layer(s, rdp_hdr, 3);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* 2.2.9.1.2.1 Fast-Path Update (TS_FP_UPDATE)\n * http://msdn.microsoft.com/en-us/library/cc240622.aspx */\nint\nxrdp_rdp_send_fastpath(struct xrdp_rdp *self, struct stream *s,\n                       int data_pdu_type)\n{\n    int updateHeader;\n    int updateCode;\n    int fragmentation;\n    int compression;\n    int comp_type;\n    int comp_len;\n    int no_comp_len;\n    int send_len;\n    int cont;\n    int header_bytes;\n    int sec_bytes;\n    int to_comp_len;\n    int sec_offset;\n    int rdp_offset;\n    struct stream frag_s;\n    struct stream comp_s;\n    struct stream send_s;\n    struct xrdp_mppc_enc *mppc_enc;\n    char comp_type_str[7];\n    comp_type_str[0] = '\\0';\n\n    s_pop_layer(s, rdp_hdr);\n    updateCode = data_pdu_type;\n    if (self->client_info.rdp_compression)\n    {\n        compression = 2;\n        header_bytes = 4;\n    }\n    else\n    {\n        compression = 0;\n        header_bytes = 3;\n    }\n    sec_bytes = xrdp_sec_get_fastpath_bytes(self->sec_layer);\n    fragmentation = 0;\n    frag_s = *s;\n    sec_offset = (int)(frag_s.sec_hdr - frag_s.data);\n    rdp_offset = (int)(frag_s.rdp_hdr - frag_s.data);\n    cont = 1;\n    while (cont)\n    {\n        comp_type = 0;\n        send_s = frag_s;\n        no_comp_len = (int)(frag_s.end - frag_s.p);\n        if (no_comp_len > FASTPATH_FRAG_SIZE)\n        {\n            no_comp_len = FASTPATH_FRAG_SIZE;\n            if (fragmentation == 0)\n            {\n                fragmentation = 2; /* FASTPATH_FRAGMENT_FIRST */\n            }\n            else if (fragmentation == 2)\n            {\n                fragmentation = 3; /* FASTPATH_FRAGMENT_NEXT */\n            }\n        }\n        else\n        {\n            if (fragmentation != 0)\n            {\n                fragmentation = 1; /* FASTPATH_FRAGMENT_LAST */\n            }\n        }\n        send_len = no_comp_len;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_rdp_send_fastpath: no_comp_len %d, fragmentation %d\",\n                  no_comp_len, fragmentation);\n        if ((compression != 0) && (no_comp_len > header_bytes + 16))\n        {\n            to_comp_len = no_comp_len - header_bytes;\n            mppc_enc = self->mppc_enc;\n            if (compress_rdp(mppc_enc, (tui8 *)(frag_s.p + header_bytes),\n                             to_comp_len))\n            {\n                comp_len = mppc_enc->bytes_in_opb + header_bytes;\n                send_len = comp_len;\n                comp_type = mppc_enc->flags;\n                /* outputBuffer has 64 bytes preceding it */\n                g_memset(&comp_s, 0, sizeof(comp_s));\n                comp_s.data = mppc_enc->outputBuffer -\n                              (rdp_offset + header_bytes);\n                comp_s.p = comp_s.data + rdp_offset;\n                comp_s.end = comp_s.p + send_len;\n                comp_s.size = send_len;\n                comp_s.sec_hdr = comp_s.data + sec_offset;\n                comp_s.rdp_hdr = comp_s.data + rdp_offset;\n                send_s = comp_s;\n            }\n            else\n            {\n                LOG(LOG_LEVEL_DEBUG,\n                    \"compress_rdp failed, sending uncompressed data. \"\n                    \"type %d, flags %d\", mppc_enc->protocol_type,\n                    mppc_enc->flags);\n            }\n        }\n        updateHeader = (updateCode & 15) |\n                       ((fragmentation & 3) << 4) |\n                       ((compression & 3) << 6);\n\n        send_s.end = send_s.p + send_len;\n        send_s.size = send_s.end - send_s.data;\n        out_uint8(&send_s, updateHeader);\n        if (compression != 0)\n        {\n            out_uint8(&send_s, comp_type);\n            g_snprintf(comp_type_str, 7, \"0x%4.4x\", comp_type);\n        }\n        send_len -= header_bytes;\n        out_uint16_le(&send_s, send_len);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_FP_UPDATE \"\n                  \"updateCode %d, fragmentation %d, compression %d, compressionFlags %s, size %d\",\n                  updateCode, fragmentation, compression,\n                  (compression ? comp_type_str : \"(not present)\"), send_len);\n        if (xrdp_sec_send_fastpath(self->sec_layer, &send_s) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_send_fastpath: xrdp_sec_send_fastpath failed\");\n            return 1;\n        }\n        frag_s.p += no_comp_len;\n        cont = frag_s.p < frag_s.end;\n        frag_s.p -= header_bytes;\n        frag_s.sec_hdr = frag_s.p - sec_bytes;\n        frag_s.data = frag_s.sec_hdr;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* Send a [MS-RDPBCGR] TS_UPDATE_SYNC or TS_FP_UPDATE_SYNCHRONIZE message\n   depending on if the client supports the fast path capability or not */\nint\nxrdp_rdp_send_data_update_sync(struct xrdp_rdp *self)\n{\n    struct stream *s = (struct stream *)NULL;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (self->client_info.use_fast_path & 1) /* fastpath output supported */\n    {\n        if (xrdp_rdp_init_fastpath(self, s) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_send_data_update_sync: xrdp_rdp_init_fastpath failed\");\n            free_stream(s);\n            return 1;\n        }\n    }\n    else /* slowpath */\n    {\n        if (xrdp_rdp_init_data(self, s) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_send_data_update_sync: xrdp_rdp_init_data failed\");\n            free_stream(s);\n            return 1;\n        }\n        out_uint16_le(s, UPDATETYPE_SYNCHRONIZE); /* updateType */\n        out_uint16_le(s, 0); /* pad */\n\n    }\n\n    s_mark_end(s);\n\n    if (self->client_info.use_fast_path & 1) /* fastpath output supported */\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FP_UPDATE_SYNCHRONIZE\");\n        if (xrdp_rdp_send_fastpath(self, s,\n                                   FASTPATH_UPDATETYPE_SYNCHRONIZE) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Sending [MS-RDPBCGR] TS_FP_UPDATE_SYNCHRONIZE failed\");\n            free_stream(s);\n            return 1;\n        }\n    }\n    else /* slowpath */\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_UPDATE_SYNC \"\n                  \"updateType %s (%d)\",\n                  GRAPHICS_UPDATE_TYPE_TO_STR(UPDATETYPE_SYNCHRONIZE),\n                  UPDATETYPE_SYNCHRONIZE);\n        if (xrdp_rdp_send_data(self, s, PDUTYPE2_UPDATE) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Sending [MS-RDPBCGR] TS_UPDATE_SYNC failed\");\n            free_stream(s);\n            return 1;\n        }\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_rdp_incoming(struct xrdp_rdp *self)\n{\n    struct xrdp_iso *iso;\n\n    iso = self->sec_layer->mcs_layer->iso_layer;\n\n    if (xrdp_sec_incoming(self->sec_layer) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_incoming: xrdp_sec_incoming failed\");\n        return 1;\n    }\n    self->mcs_channel = self->sec_layer->mcs_layer->userid +\n                        MCS_USERCHANNEL_BASE;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_rdp->mcs_channel %d\", self->mcs_channel);\n\n    /* log TLS version and cipher of TLS connections */\n    if (iso->selectedProtocol > PROTOCOL_RDP)\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"TLS connection established from %s %s with cipher %s\",\n            self->client_info.client_description,\n            iso->trans->ssl_protocol,\n            iso->trans->cipher_name);\n    }\n    /* log non-TLS connections */\n    else\n    {\n        int crypt_level = self->sec_layer->crypt_level;\n        const char *security_level =\n            (crypt_level == CRYPT_LEVEL_NONE) ? \"none\" :\n            (crypt_level == CRYPT_LEVEL_LOW) ? \"low\" :\n            (crypt_level == CRYPT_LEVEL_CLIENT_COMPATIBLE) ? \"medium\" :\n            (crypt_level == CRYPT_LEVEL_HIGH) ? \"high\" :\n            (crypt_level == CRYPT_LEVEL_FIPS) ? \"fips\" :\n            /* default */ \"unknown\";\n\n        LOG(LOG_LEVEL_INFO,\n            \"Non-TLS connection established from %s with security level : %s\",\n            self->client_info.client_description, security_level);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_POINTER_PDU message */\nstatic int\nxrdp_rdp_process_data_pointer(struct xrdp_rdp *self, struct stream *s)\n{\n    LOG_DEVEL(LOG_LEVEL_WARNING, \"Protocol error ignored: a [MS-RDPBCGR] \"\n              \"TS_SHAREDATAHEADER PDUTYPE2_POINTER was received by the server \"\n              \"but this type of PDU is only suppose to be sent by the server \"\n              \"to the client.\");\n    return 0;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_INPUT_PDU_DATA message */\nstatic int\nxrdp_rdp_process_data_input(struct xrdp_rdp *self, struct stream *s)\n{\n    int num_events;\n    int index;\n    int msg_type;\n    int device_flags;\n    int param1;\n    int param2;\n    int time;\n\n    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPBCGR] TS_INPUT_PDU_DATA\"))\n    {\n        return 1;\n    }\n    in_uint16_le(s, num_events);\n    in_uint8s(s, 2); /* pad */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_INPUT_PDU_DATA \"\n              \"numEvents %d\", num_events);\n\n    for (index = 0; index < num_events; index++)\n    {\n        if (!s_check_rem_and_log(s, 12, \"Parsing [MS-RDPBCGR] TS_INPUT_EVENT\"))\n        {\n            return 1;\n        }\n        in_uint32_le(s, time);\n        in_uint16_le(s, msg_type);\n        in_uint16_le(s, device_flags);\n        in_sint16_le(s, param1);\n        in_sint16_le(s, param2);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"With field [MS-RDPBCGR] TS_INPUT_EVENT \"\n                  \"eventTime %d, messageType 0x%4.4x\", time, msg_type);\n\n        switch (msg_type)\n        {\n            case RDP_INPUT_SYNCHRONIZE:\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_SYNC_EVENT \"\n                          \"toggleFlags 0x%8.8x\", ((param2 << 16) | param1));\n                break;\n            case RDP_INPUT_SCANCODE:\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_KEYBOARD_EVENT \"\n                          \"keyboardFlags 0x%4.4x, keyCode %d\", device_flags, param1);\n                break;\n            case RDP_INPUT_UNICODE:\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_UNICODE_KEYBOARD_EVENT \"\n                          \"keyboardFlags 0x%4.4x, unicodeCode %d\", device_flags, param1);\n                break;\n            case RDP_INPUT_MOUSE:\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_POINTER_EVENT \"\n                          \"pointerFlags 0x%4.4x, xPos %d, yPos %d\",\n                          device_flags, param1, param2);\n                break;\n            case RDP_INPUT_MOUSEX:\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_POINTERX_EVENT \"\n                          \"pointerFlags 0x%4.4x, xPos %d, yPos %d\",\n                          device_flags, param1, param2);\n                break;\n            default:\n                LOG_DEVEL(LOG_LEVEL_WARNING, \"Received unknown [MS-RDPBCGR] TS_INPUT_EVENT \"\n                          \"messageType 0x%4.4x\", msg_type);\n                break;\n        }\n\n        if (self->session->callback != 0)\n        {\n            /* msg_type can be\n               RDP_INPUT_SYNCHRONIZE - 0\n               RDP_INPUT_SCANCODE - 4\n               RDP_INPUT_MOUSE - 0x8001\n               RDP_INPUT_MOUSEX - 0x8002 */\n            /* call to xrdp_wm.c : callback */\n            self->session->callback(self->session->id, msg_type, param1, param2,\n                                    device_flags, time);\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING,\n                      \"Bug: no callback registered for xrdp_rdp_process_data_input\");\n        }\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"Processing [MS-RDPBCGR] TS_INPUT_PDU_DATA complete\");\n    return 0;\n}\n\n/*****************************************************************************/\n/* Send a [MS-RDPBCGR] TS_SYNCHRONIZE_PDU message */\nstatic int\nxrdp_rdp_send_synchronise(struct xrdp_rdp *self)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_rdp_init_data(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_send_synchronise: xrdp_rdp_init_data failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    out_uint16_le(s, 1); /* messageType (2 bytes) */\n    out_uint16_le(s, 1002); /* targetUser (2 bytes) */\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_SYNCHRONIZE_PDU \"\n              \"messageType 1, targetUser 1002\");\n\n    if (xrdp_rdp_send_data(self, s, PDUTYPE2_SYNCHRONISE) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Sending [MS-RDPBCGR] TS_SYNCHRONIZE_PDU failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Send a [MS-RDPBCGR] TS_CONTROL_PDU message */\nstatic int\nxrdp_rdp_send_control(struct xrdp_rdp *self, int action,\n                      int grant_id, int control_id)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_rdp_init_data(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_send_control: xrdp_rdp_init_data failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    out_uint16_le(s, action);\n    out_uint16_le(s, grant_id);\n    out_uint32_le(s, control_id);\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_CONTROL_PDU \"\n              \"action %d, grantId 0, controlId 1002\", action);\n\n    if (xrdp_rdp_send_data(self, s, PDUTYPE2_CONTROL) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Sending [MS-RDPBCGR] TS_CONTROL_PDU failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_CONTROL_PDU message */\nstatic int\nxrdp_rdp_process_data_control(struct xrdp_rdp *self, struct stream *s)\n{\n    int action;\n\n    in_uint16_le(s, action);\n    in_uint8s(s, 2); /* user id */\n    in_uint8s(s, 4); /* control id */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_CONTROL_PDU \"\n              \"action 0x%4.4x, grantId (ignored), controlId (ignored)\",\n              action);\n\n    if (action == RDP_CTL_REQUEST_CONTROL)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"Responding to [MS-RDPBCGR] TS_CONTROL_PDU \"\n                  \"action CTRLACTION_REQUEST_CONTROL with 3 messages: \"\n                  \"TS_SYNCHRONIZE_PDU, TS_CONTROL_PDU with CTRLACTION_COOPERATE, \"\n                  \" and TS_CONTROL_PDU with CTRLACTION_GRANTED_CONTROL\");\n        xrdp_rdp_send_synchronise(self);\n        xrdp_rdp_send_control(self, RDP_CTL_COOPERATE, 0, 0);\n        xrdp_rdp_send_control(self, RDP_CTL_GRANT_CONTROL,\n                              self->mcs_channel, 0x03ea);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_WARNING, \"Received [MS-RDPBCGR] TS_CONTROL_PDU \"\n                  \"action %d is unknown (skipped)\", action);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_SYNCHRONIZE_PDU message */\nstatic int\nxrdp_rdp_process_data_sync(struct xrdp_rdp *self)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_SYNCHRONIZE_PDU - no-op\");\n    return 0;\n}\n\n/*****************************************************************************/\n/* 2.2.11.2.1 Refresh Rect PDU Data (TS_REFRESH_RECT_PDU) */\nstatic int\nxrdp_rdp_process_screen_update(struct xrdp_rdp *self, struct stream *s)\n{\n    int index;\n    int num_rects;\n    int left;\n    int top;\n    int right;\n    int bottom;\n    int cx;\n    int cy;\n\n    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPBCGR] TS_REFRESH_RECT_PDU\"))\n    {\n        return 1;\n    }\n    in_uint8(s, num_rects);\n    in_uint8s(s, 3); /* pad */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_REFRESH_RECT_PDU \"\n              \"numberOfAreas %d\", num_rects);\n    for (index = 0; index < num_rects; index++)\n    {\n        if (!s_check_rem_and_log(s, 8, \"Parsing [MS-RDPBCGR] TS_RECTANGLE16\"))\n        {\n            return 1;\n        }\n        /* Inclusive Rectangle (TS_RECTANGLE16) */\n        in_uint16_le(s, left);\n        in_uint16_le(s, top);\n        in_uint16_le(s, right);\n        in_uint16_le(s, bottom);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"With field [MS-RDPBCGR] TS_RECTANGLE16 \"\n                  \"left %d, top %d, right %d, bottom %d\",\n                  left, top, right, bottom);\n        cx = (right - left) + 1;\n        cy = (bottom - top) + 1;\n        if (self->session->callback != 0)\n        {\n            self->session->callback(self->session->id, 0x4444,\n                                    left, top, cx, cy);\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING,\n                      \"Bug: no callback registered for xrdp_rdp_process_screen_update\");\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* Send a [MS-RDPBCGR] TS_FONT_MAP_PDU message */\nstatic int\nxrdp_rdp_send_fontmap(struct xrdp_rdp *self)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_rdp_init_data(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_rdp_send_fontmap: xrdp_rdp_init_data failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    out_uint16_le(s, 0); /* numberEntries */\n    out_uint16_le(s, 0); /* totalNumEntries */\n    out_uint16_le(s, 0x3); /* mapFlags (sequence flags) */\n    out_uint16_le(s, 0x4); /* entrySize */\n\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FONT_MAP_PDU \"\n              \"numberEntries 0, totalNumEntries 0, mapFlags 0x0003, entrySize 4\");\n\n    if (xrdp_rdp_send_data(self, s, 0x28) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Sending [MS-RDPBCGR] TS_FONT_MAP_PDU failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_FONT_LIST_PDU message */\nstatic int\nxrdp_rdp_process_data_font(struct xrdp_rdp *self, struct stream *s)\n{\n    int seq;\n\n    if (!s_check_rem_and_log(s, 6, \"Parsing [MS-RDPBCGR] TS_FONT_LIST_PDU\"))\n    {\n        return 1;\n    }\n\n    in_uint8s(s, 2); /* NumberFonts: 0x0, SHOULD be set to 0 */\n    in_uint8s(s, 2); /* TotalNumberFonts: 0x0, SHOULD be set to 0 */\n    in_uint16_le(s, seq); /* ListFlags */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_FONT_LIST_PDU \"\n              \"numberFonts (ignored), totalNumFonts (ignored), listFlags 0x%4.4x\",\n              seq);\n\n    /* 419 client sends Seq 1, then 2 */\n    /* 2600 clients sends only Seq 3 */\n    /* listFlags SHOULD be set to 0x0003, which is the logical OR'd value of\n       FONTLIST_FIRST (0x0001) and FONTLIST_LAST (0x0002) */\n    if (seq == 2 || seq == 3) /* after second font message, we are up and */\n    {\n        /* running */\n        LOG_DEVEL(LOG_LEVEL_DEBUG,\n                  \"Client sent FONTLIST_LAST, replying with server fontmap\");\n        xrdp_rdp_send_fontmap(self);\n\n        self->session->up_and_running = 1;\n        LOG_DEVEL(LOG_LEVEL_INFO, \"yeah, up_and_running\");\n        xrdp_rdp_send_data_update_sync(self);\n\n        /* This is also the end of an Deactivation-reactivation\n         * sequence [MS-RDPBCGR] 1.3.1.3 */\n        xrdp_rdp_suppress_output(self, 0, XSO_REASON_DEACTIVATE_REACTIVATE,\n                                 0, 0,\n                                 self->client_info.display_sizes.session_width,\n                                 self->client_info.display_sizes.session_height);\n\n        if (self->session->callback != 0)\n        {\n            /* call to xrdp_wm.c : callback */\n            self->session->callback(self->session->id, 0x555a, 0, 0,\n                                    0, 0);\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"Received [MS-RDPBCGR] TS_FONT_LIST_PDU \"\n                  \"without FONTLIST_LAST in the listFlags field. Ignoring message.\");\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Send a Sending [MS-RDPBCGR] TS_SHUTDOWN_DENIED_PDU message */\nstatic int\nxrdp_rdp_send_disconnect_query_response(struct xrdp_rdp *self)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_rdp_init_data(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_rdp_send_disconnect_query_response: xrdp_rdp_init_data failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_SHUTDOWN_DENIED_PDU\");\n\n    if (xrdp_rdp_send_data(self, s, PDUTYPE2_SHUTDOWN_DENIED) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Sending [MS-RDPBCGR] TS_SHUTDOWN_DENIED_PDU failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_rdp_send_set_error(struct xrdp_rdp *self, int reason)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_rdp_init_data(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_rdp_send_set_error_pdu: xrdp_rdp_init_data failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    out_uint32_le(s, reason);\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_SET_ERROR_INFO_PDU \"\n              \"errorInfo 0x%8.8x\", reason);\n\n    if (xrdp_rdp_send_data(self, s, PDUTYPE2_SET_ERROR_INFO_PDU) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Sending [MS-RDPBCGR] TS_SET_ERROR_INFO_PDU failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPRFX] TS_FRAME_ACKNOWLEDGE_PDU message */\nstatic int\nxrdp_rdp_process_frame_ack(struct xrdp_rdp *self, struct stream *s)\n{\n    int frame_id;\n\n    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPRFX] TS_FRAME_ACKNOWLEDGE_PDU\"))\n    {\n        return 1;\n    }\n    in_uint32_le(s, frame_id);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPRFX] TS_FRAME_ACKNOWLEDGE_PDU \"\n              \"frameID %d\", frame_id);\n    if (self->session->callback != 0)\n    {\n        /* call to xrdp_wm.c : callback */\n        self->session->callback(self->session->id, 0x5557, frame_id, 0,\n                                0, 0);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_WARNING,\n                  \"Bug: no callback registered for xrdp_rdp_process_frame_ack\");\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_rdp_suppress_output(struct xrdp_rdp *self, int suppress,\n                         enum suppress_output_reason reason,\n                         int left, int top, int right, int bottom)\n{\n    int old_suppress = self->client_info.suppress_output_mask != 0;\n    if (suppress)\n    {\n        self->client_info.suppress_output_mask |= (unsigned int)reason;\n    }\n    else\n    {\n        self->client_info.suppress_output_mask &= ~(unsigned int)reason;\n    }\n\n    int current_suppress =  self->client_info.suppress_output_mask != 0;\n    if (current_suppress != old_suppress && self->session->callback != 0)\n    {\n        self->session->callback(self->session->id, 0x5559, suppress,\n                                MAKELONG(left, top),\n                                MAKELONG(right, bottom), 0);\n    }\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_SUPPRESS_OUTPUT_PDU message */\nstatic int\nxrdp_rdp_process_suppress(struct xrdp_rdp *self, struct stream *s)\n{\n    int rv = 1;\n    int allowDisplayUpdates;\n    int left;\n    int top;\n    int right;\n    int bottom;\n\n    if (s_check_rem_and_log(s, 1, \"Parsing [MS-RDPBCGR] TS_SUPPRESS_OUTPUT_PDU\"))\n    {\n        in_uint8(s, allowDisplayUpdates);\n        LOG_DEVEL(LOG_LEVEL_TRACE,\n                  \"Received [MS-RDPBCGR] TS_SUPPRESS_OUTPUT_PDU \"\n                  \"allowDisplayUpdates %d\", allowDisplayUpdates);\n        switch (allowDisplayUpdates)\n        {\n            case 0: /* SUPPRESS_DISPLAY_UPDATES */\n                LOG_DEVEL(LOG_LEVEL_DEBUG,\n                          \"Client requested display output to be suppressed\");\n                xrdp_rdp_suppress_output(self, 1,\n                                         XSO_REASON_CLIENT_REQUEST,\n                                         0, 0, 0, 0);\n                rv = 0;\n                break;\n            case 1: /* ALLOW_DISPLAY_UPDATES */\n                LOG_DEVEL(LOG_LEVEL_DEBUG,\n                          \"Client requested display output to be enabled\");\n                if (s_check_rem_and_log(s, 11,\n                                        \"Parsing [MS-RDPBCGR] Padding and TS_RECTANGLE16\"))\n                {\n                    in_uint8s(s, 3); /* pad */\n                    in_uint16_le(s, left);\n                    in_uint16_le(s, top);\n                    in_uint16_le(s, right);\n                    in_uint16_le(s, bottom);\n                    LOG_DEVEL(LOG_LEVEL_TRACE,\n                              \"Received [MS-RDPBCGR] TS_RECTANGLE16 \"\n                              \"left %d, top %d, right %d, bottom %d\",\n                              left, top, right, bottom);\n                    xrdp_rdp_suppress_output(self, 0,\n                                             XSO_REASON_CLIENT_REQUEST,\n                                             left, top, right, bottom);\n                    rv = 0;\n                }\n                break;\n        }\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_SHAREDATAHEADER message based on it's pduType2 */\nint\nxrdp_rdp_process_data(struct xrdp_rdp *self, struct stream *s)\n{\n    int uncompressedLength;\n    int pduType2;\n    int compressedType;\n    int compressedLength;\n\n    if (!s_check_rem_and_log(s, 12, \"Parsing [MS-RDPBCGR] TS_SHAREDATAHEADER\"))\n    {\n        return 1;\n    }\n    in_uint8s(s, 6); /* shareID (4 bytes), padding (1 byte), streamID (1 byte) */\n    in_uint16_le(s, uncompressedLength); /* shareID */\n    in_uint8(s, pduType2);\n    in_uint8(s, compressedType);\n    in_uint16_le(s, compressedLength);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_SHAREDATAHEADER \"\n              \"shareID (ignored), streamID (ignored), uncompressedLength %d, \"\n              \"pduType2 0x%2.2x, compressedType 0x%2.2x, compressedLength %d\",\n              uncompressedLength, pduType2, compressedType, compressedLength);\n\n    if (compressedType != 0)\n    {\n        /* don't support compression */\n        /* PACKET_COMPR_TYPE_8K = 0x00 */\n        LOG(LOG_LEVEL_ERROR, \"Only RDP 4.0 bulk compression \"\n            \"(PACKET_COMPR_TYPE_8K) is supported by XRDP\");\n        return 1;\n    }\n    if (compressedLength > uncompressedLength)\n    {\n        LOG(LOG_LEVEL_ERROR, \"The compressed length %d is larger than \"\n            \"the uncompressed length %d, failing the processing of this \"\n            \"PDU\", compressedLength, uncompressedLength);\n        return 1;\n    }\n\n    switch (pduType2)\n    {\n        case PDUTYPE2_POINTER:\n            xrdp_rdp_process_data_pointer(self, s);\n            break;\n        case PDUTYPE2_INPUT:\n            xrdp_rdp_process_data_input(self, s);\n            break;\n        case PDUTYPE2_CONTROL:\n            xrdp_rdp_process_data_control(self, s);\n            break;\n        case PDUTYPE2_SYNCHRONISE:\n            xrdp_rdp_process_data_sync(self);\n            break;\n        case PDUTYPE2_REFRESH_RECT:\n            xrdp_rdp_process_screen_update(self, s);\n            break;\n        case PDUTYPE2_SUPPRESS_OUTPUT:\n            xrdp_rdp_process_suppress(self, s);\n            break;\n        case PDUTYPE2_SHUTDOWN_REQUEST:\n            /* when this message comes, send a 37 back so the client */\n            /* is sure the connection is alive and it can ask if user */\n            /* really wants to disconnect */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_SHUTDOWN_REQ_PDU\");\n            xrdp_rdp_send_disconnect_query_response(self); /* send a 37 back */\n            break;\n        case PDUTYPE2_FONTLIST:\n            xrdp_rdp_process_data_font(self, s);\n            break;\n        case PDUTYPE2_FRAME_ACKNOWLEDGE:\n            xrdp_rdp_process_frame_ack(self, s);\n            break;\n        default:\n            LOG(LOG_LEVEL_WARNING,\n                \"Received unknown [MS-RDPBCGR] TS_SHAREDATAHEADER pduType2 %d (ignoring)\",\n                pduType2);\n            break;\n    }\n    return 0;\n}\n/*****************************************************************************/\nint\nxrdp_rdp_disconnect(struct xrdp_rdp *self)\n{\n    return xrdp_sec_disconnect(self->sec_layer);\n}\n\n/*****************************************************************************/\nint\nxrdp_rdp_send_deactivate(struct xrdp_rdp *self)\n{\n    // See [MS-RDPBCGR] 2.2.3.1.1\n    const char source_descriptor[] = { '\\0' };\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_rdp_init(self, s) != 0)\n    {\n        free_stream(s);\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_send_deactivate: xrdp_rdp_init failed\");\n        return 1;\n    }\n    out_uint32_le(s, self->share_id);\n    out_uint16_le(s, sizeof(source_descriptor));\n    out_uint8p(s, source_descriptor, sizeof(source_descriptor));\n\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_DEACTIVATE_ALL_PDU \"\n              \"shareID %d, sourceDescriptor 0x0\", self->share_id);\n\n    if (xrdp_rdp_send(self, s, PDUTYPE_DEACTIVATEALLPDU) != 0)\n    {\n        free_stream(s);\n        LOG(LOG_LEVEL_ERROR, \"Sending [MS-RDPBCGR] TS_DEACTIVATE_ALL_PDU failed\");\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/** Send a [MS-RDPBCGR] TS_SAVE_SESSION_INFO_PDU_DATA message.\n *\n * @param data the data to send to the client in the\n *      TS_SAVE_SESSION_INFO_PDU_DATA message. The first 4 bytes of the data\n *      buffer MUST by the infoType value as specified in MS-RDPBCGR 2.2.10.1.1\n * @param data_bytes the length of the data buffer\n * @returns error code\n */\nint\nxrdp_rdp_send_session_info(struct xrdp_rdp *self, const char *data,\n                           int data_bytes)\n{\n    struct stream *s;\n\n    if (data == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"data must not be null\");\n        return 1;\n    }\n    if (data_bytes < 4)\n    {\n        LOG(LOG_LEVEL_ERROR, \"data_bytes must greater than or equal to 4\");\n        return 1;\n    }\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_rdp_init_data(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_rdp_send_session_info: xrdp_rdp_init_data failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    if (!s_check_rem_out_and_log(s, data_bytes, \"Sending [MS-RDPBCGR] TS_SAVE_SESSION_INFO_PDU_DATA\"))\n    {\n        free_stream(s);\n        return 1;\n    }\n\n    out_uint8a(s, data, data_bytes);\n    s_mark_end(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_SAVE_SESSION_INFO_PDU_DATA \"\n              \"infoType 0x%8.8x, infoData <omitted from log>\",\n              *((unsigned int *) data));\n\n    if (xrdp_rdp_send_data(self, s, PDUTYPE2_SAVE_SESSION_INFO) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Sending [MS-RDPBCGR] TS_SAVE_SESSION_INFO_PDU_DATA failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n"
  },
  {
    "path": "libxrdp/xrdp_sec.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * secure layer\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n\n/* some compilers need unsigned char to avoid warnings */\nstatic tui8 g_pad_54[40] =\n{\n    54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,\n    54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,\n    54, 54, 54, 54, 54, 54, 54, 54\n};\n\n/* some compilers need unsigned char to avoid warnings */\nstatic tui8 g_pad_92[48] =\n{\n    92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,\n    92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,\n    92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92\n};\n\nstatic const tui8 g_fips_reverse_table[256] =\n{\n    0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,\n    0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,\n    0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,\n    0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,\n    0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,\n    0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,\n    0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,\n    0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,\n    0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,\n    0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,\n    0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,\n    0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,\n    0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,\n    0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,\n    0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,\n    0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,\n    0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,\n    0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,\n    0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,\n    0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,\n    0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,\n    0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,\n    0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,\n    0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,\n    0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,\n    0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,\n    0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,\n    0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,\n    0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,\n    0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,\n    0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,\n    0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff\n};\n\nstatic const tui8 g_fips_oddparity_table[256] =\n{\n    0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x07, 0x07,\n    0x08, 0x08, 0x0b, 0x0b, 0x0d, 0x0d, 0x0e, 0x0e,\n    0x10, 0x10, 0x13, 0x13, 0x15, 0x15, 0x16, 0x16,\n    0x19, 0x19, 0x1a, 0x1a, 0x1c, 0x1c, 0x1f, 0x1f,\n    0x20, 0x20, 0x23, 0x23, 0x25, 0x25, 0x26, 0x26,\n    0x29, 0x29, 0x2a, 0x2a, 0x2c, 0x2c, 0x2f, 0x2f,\n    0x31, 0x31, 0x32, 0x32, 0x34, 0x34, 0x37, 0x37,\n    0x38, 0x38, 0x3b, 0x3b, 0x3d, 0x3d, 0x3e, 0x3e,\n    0x40, 0x40, 0x43, 0x43, 0x45, 0x45, 0x46, 0x46,\n    0x49, 0x49, 0x4a, 0x4a, 0x4c, 0x4c, 0x4f, 0x4f,\n    0x51, 0x51, 0x52, 0x52, 0x54, 0x54, 0x57, 0x57,\n    0x58, 0x58, 0x5b, 0x5b, 0x5d, 0x5d, 0x5e, 0x5e,\n    0x61, 0x61, 0x62, 0x62, 0x64, 0x64, 0x67, 0x67,\n    0x68, 0x68, 0x6b, 0x6b, 0x6d, 0x6d, 0x6e, 0x6e,\n    0x70, 0x70, 0x73, 0x73, 0x75, 0x75, 0x76, 0x76,\n    0x79, 0x79, 0x7a, 0x7a, 0x7c, 0x7c, 0x7f, 0x7f,\n    0x80, 0x80, 0x83, 0x83, 0x85, 0x85, 0x86, 0x86,\n    0x89, 0x89, 0x8a, 0x8a, 0x8c, 0x8c, 0x8f, 0x8f,\n    0x91, 0x91, 0x92, 0x92, 0x94, 0x94, 0x97, 0x97,\n    0x98, 0x98, 0x9b, 0x9b, 0x9d, 0x9d, 0x9e, 0x9e,\n    0xa1, 0xa1, 0xa2, 0xa2, 0xa4, 0xa4, 0xa7, 0xa7,\n    0xa8, 0xa8, 0xab, 0xab, 0xad, 0xad, 0xae, 0xae,\n    0xb0, 0xb0, 0xb3, 0xb3, 0xb5, 0xb5, 0xb6, 0xb6,\n    0xb9, 0xb9, 0xba, 0xba, 0xbc, 0xbc, 0xbf, 0xbf,\n    0xc1, 0xc1, 0xc2, 0xc2, 0xc4, 0xc4, 0xc7, 0xc7,\n    0xc8, 0xc8, 0xcb, 0xcb, 0xcd, 0xcd, 0xce, 0xce,\n    0xd0, 0xd0, 0xd3, 0xd3, 0xd5, 0xd5, 0xd6, 0xd6,\n    0xd9, 0xd9, 0xda, 0xda, 0xdc, 0xdc, 0xdf, 0xdf,\n    0xe0, 0xe0, 0xe3, 0xe3, 0xe5, 0xe5, 0xe6, 0xe6,\n    0xe9, 0xe9, 0xea, 0xea, 0xec, 0xec, 0xef, 0xef,\n    0xf1, 0xf1, 0xf2, 0xf2, 0xf4, 0xf4, 0xf7, 0xf7,\n    0xf8, 0xf8, 0xfb, 0xfb, 0xfd, 0xfd, 0xfe, 0xfe\n};\n\nstatic const tui8 g_fips_ivec[8] =\n{\n    0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF\n};\n\n/*****************************************************************************/\nstatic void\nhex_str_to_bin(char *in, char *out, int out_len)\n{\n    int in_index;\n    int in_len;\n    int out_index;\n    int val;\n    char hex[16];\n\n    in_len = g_strlen(in);\n    out_index = 0;\n    in_index = 0;\n\n    while (in_index <= (in_len - 4))\n    {\n        if ((in[in_index] == '0') && (in[in_index + 1] == 'x'))\n        {\n            hex[0] = in[in_index + 2];\n            hex[1] = in[in_index + 3];\n            hex[2] = 0;\n\n            if (out_index < out_len)\n            {\n                val = g_htoi(hex);\n                out[out_index] = val;\n            }\n\n            out_index++;\n        }\n\n        in_index++;\n    }\n}\n\n/*****************************************************************************/\nstruct xrdp_sec *\nxrdp_sec_create(struct xrdp_rdp *owner, struct trans *trans)\n{\n    struct xrdp_sec *self;\n\n    self = (struct xrdp_sec *) g_malloc(sizeof(struct xrdp_sec), 1);\n    self->rdp_layer = owner;\n    self->crypt_method = CRYPT_METHOD_NONE; /* set later */\n    self->crypt_level = CRYPT_LEVEL_NONE;\n    self->mcs_layer = xrdp_mcs_create(self, trans, &(self->client_mcs_data),\n                                      &(self->server_mcs_data));\n    self->fastpath_layer = xrdp_fastpath_create(self, trans);\n    self->chan_layer = xrdp_channel_create(self, self->mcs_layer);\n    self->is_security_header_present = 1;\n\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_sec_delete(struct xrdp_sec *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n\n    xrdp_channel_delete(self->chan_layer);\n    xrdp_mcs_delete(self->mcs_layer);\n    xrdp_fastpath_delete(self->fastpath_layer);\n    ssl_rc4_info_delete(self->decrypt_rc4_info); /* TODO clear all data */\n    ssl_rc4_info_delete(self->encrypt_rc4_info); /* TODO clear all data */\n    ssl_des3_info_delete(self->decrypt_fips_info);\n    ssl_des3_info_delete(self->encrypt_fips_info);\n    ssl_hmac_info_delete(self->sign_fips_info);\n    g_free(self->client_mcs_data.data);\n    g_free(self->server_mcs_data.data);\n    /* Crypto information must always be cleared */\n    g_memset(self, 0, sizeof(struct xrdp_sec));\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_sec_init(struct xrdp_sec *self, struct stream *s)\n{\n    if (xrdp_mcs_init(self->mcs_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_sec_init: xrdp_mcs_init failed\");\n        return 1;\n    }\n\n    if (self->crypt_level > CRYPT_LEVEL_NONE) /* RDP encryption */\n    {\n        if (self->crypt_level == CRYPT_LEVEL_FIPS)\n        {\n            s_push_layer(s, sec_hdr, 4 + 4 + 8);\n        }\n        else if (self->crypt_level > CRYPT_LEVEL_LOW)\n        {\n            s_push_layer(s, sec_hdr, 4 + 8);\n        }\n        else if (self->crypt_level)\n        {\n            s_push_layer(s, sec_hdr, 4);\n        }\n    }\n    else\n    {\n        s_push_layer(s, sec_hdr, 0);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Reduce key entropy from 64 to 40 bits */\nstatic void\nxrdp_sec_make_40bit(char *key)\n{\n    key[0] = 0xd1;\n    key[1] = 0x26;\n    key[2] = 0x9e;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* update an encryption key */\nstatic int\nxrdp_sec_update(char *key, char *update_key, int key_len)\n{\n    char shasig[20];\n    void *sha1_info;\n    void *md5_info;\n    void *rc4_info;\n\n    sha1_info = ssl_sha1_info_create();\n    md5_info = ssl_md5_info_create();\n    rc4_info = ssl_rc4_info_create();\n    ssl_sha1_clear(sha1_info);\n    ssl_sha1_transform(sha1_info, update_key, key_len);\n    ssl_sha1_transform(sha1_info, (char *)g_pad_54, 40);\n    ssl_sha1_transform(sha1_info, key, key_len);\n    ssl_sha1_complete(sha1_info, shasig);\n    ssl_md5_clear(md5_info);\n    ssl_md5_transform(md5_info, update_key, key_len);\n    ssl_md5_transform(md5_info, (char *)g_pad_92, 48);\n    ssl_md5_transform(md5_info, shasig, 20);\n    ssl_md5_complete(md5_info, key);\n    ssl_rc4_set_key(rc4_info, key, key_len);\n    ssl_rc4_crypt(rc4_info, key, key_len);\n\n    if (key_len == 8)\n    {\n        xrdp_sec_make_40bit(key);\n    }\n\n    ssl_sha1_info_delete(sha1_info);\n    ssl_md5_info_delete(md5_info);\n    ssl_rc4_info_delete(rc4_info);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic void\nxrdp_sec_fips_decrypt(struct xrdp_sec *self, char *data, int len)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_sec_fips_decrypt:\");\n    ssl_des3_decrypt(self->decrypt_fips_info, len, data, data);\n    self->decrypt_use_count++;\n}\n\n/*****************************************************************************/\nstatic void\nxrdp_sec_decrypt(struct xrdp_sec *self, char *data, int len)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_sec_decrypt:\");\n    if (self->decrypt_use_count == 4096)\n    {\n        xrdp_sec_update(self->decrypt_key, self->decrypt_update_key,\n                        self->rc4_key_len);\n        ssl_rc4_set_key(self->decrypt_rc4_info, self->decrypt_key,\n                        self->rc4_key_len);\n        self->decrypt_use_count = 0;\n    }\n    ssl_rc4_crypt(self->decrypt_rc4_info, data, len);\n    self->decrypt_use_count++;\n}\n\n/*****************************************************************************/\nstatic void\nxrdp_sec_fips_encrypt(struct xrdp_sec *self, char *data, int len)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_sec_fips_encrypt:\");\n    ssl_des3_encrypt(self->encrypt_fips_info, len, data, data);\n    self->encrypt_use_count++;\n}\n\n/*****************************************************************************/\nstatic void\nxrdp_sec_encrypt(struct xrdp_sec *self, char *data, int len)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_sec_encrypt:\");\n    if (self->encrypt_use_count == 4096)\n    {\n        xrdp_sec_update(self->encrypt_key, self->encrypt_update_key,\n                        self->rc4_key_len);\n        ssl_rc4_set_key(self->encrypt_rc4_info, self->encrypt_key,\n                        self->rc4_key_len);\n        self->encrypt_use_count = 0;\n    }\n\n    ssl_rc4_crypt(self->encrypt_rc4_info, data, len);\n    self->encrypt_use_count++;\n}\n\n/*****************************************************************************/\n/**\n * Reads a null-terminated unicode string from a stream where the length\n * of the string is known.\n *\n * Strings are part of one of the following from [MS-RDPBCGR] :-\n * - TS_INFO_PACKET (2.2.1.11.1.1)\n * - TS_EXTENDED_INFO_PACKET (2.2.1.11.1.1.1)\n *\n * @param s Stream\n * @param src_bytes Size in bytes of the string, EXCLUDING the two-byte\n *                  terminator\n * @param dst Destination buffer\n * @param dst_len Length of buffer, including terminator space\n *\n * @return 0 for success, != 0 for a buffer overflow or a missing terminator\n */\nstatic int\nts_info_utf16_in(struct stream *s, int src_bytes, char *dst, int dst_len)\n{\n    int rv = 0;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"ts_info_utf16_in: uni_len %d, dst_len %d\", src_bytes, dst_len);\n\n    if (!s_check_rem_and_log(s, src_bytes + 2, \"ts_info_utf16_in\"))\n    {\n        rv = 1;\n    }\n    else\n    {\n        int term;\n        int num_chars = in_utf16_le_fixed_as_utf8(s, src_bytes / 2,\n                        dst, dst_len);\n        if (num_chars > dst_len)\n        {\n            LOG(LOG_LEVEL_ERROR, \"ts_info_utf16_in: output buffer overflow\");\n            rv = 1;\n        }\n\n        // String should be null-terminated. We haven't read the terminator yet\n        in_uint16_le(s, term);\n        if (term != 0)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"ts_info_utf16_in: bad terminator. Expected 0, got %d\", term);\n            rv = 1;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* Process TS_INFO_PACKET */\n/* returns error */\nstatic int\nxrdp_sec_process_logon_info(struct xrdp_sec *self, struct stream *s)\n{\n    int flags = 0;\n    unsigned int len_domain = 0;\n    unsigned int len_user = 0;\n    unsigned int len_password = 0;\n    unsigned int len_program = 0;\n    unsigned int len_directory = 0;\n    unsigned int len_clnt_addr = 0;\n    unsigned int len_clnt_dir = 0;\n    const char *sep;\n\n    if (!s_check_rem_and_log(s, 8, \"Parsing [MS-RDPBCGR] TS_INFO_PACKET\"))\n    {\n        return 1;\n    }\n    in_uint8s(s, 4);\n    in_uint32_le(s, flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Parsing [MS-RDPBCGR] TS_INFO_PACKET\");\n\n    /* this is the first test that the decrypt is working */\n    if ((flags & RDP_LOGON_NORMAL) != RDP_LOGON_NORMAL) /* 0x33 */\n    {\n        /* must be or error */\n        LOG(LOG_LEVEL_ERROR, \"received wrong flags, likely decrypt not working\");\n        return 1;\n    }\n\n    if (flags & RDP_LOGON_LEAVE_AUDIO)\n    {\n        self->rdp_layer->client_info.sound_code = 1;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"[MS-RDPBCGR] TS_INFO_PACKET flag INFO_REMOTECONSOLEAUDIO found\");\n        LOG(LOG_LEVEL_DEBUG,\n            \"Client requested that audio on the server be played on the server.\");\n    }\n\n    if (flags & RDP_LOGON_RAIL)\n    {\n        self->rdp_layer->client_info.rail_enable = 1;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"[MS-RDPBCGR] TS_INFO_PACKET flag INFO_RAIL found\");\n        LOG(LOG_LEVEL_DEBUG,\n            \"Client requested Remote Application Integrated Locally (RAIL).\");\n    }\n\n    if (flags & RDP_LOGON_AUTO)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"[MS-RDPBCGR] TS_INFO_PACKET flag INFO_AUTOLOGON found\");\n        /* todo, for now not allowing autologon and mce both */\n        if (!self->rdp_layer->client_info.is_mce)\n        {\n            self->rdp_layer->client_info.rdp_autologin = 1;\n            LOG(LOG_LEVEL_DEBUG, \"Client requested auto logon.\");\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING, \"Auto logon is not supported with MCE\");\n        }\n    }\n\n    if (flags & RDP_COMPRESSION)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"[MS-RDPBCGR] TS_INFO_PACKET flag INFO_COMPRESSION found, \"\n                  \"CompressionType 0x%1.1x\", (flags & 0x00001E00) >> 9);\n        /* TODO: check the client's supported compression type vs the server\n           compression used */\n        if (self->rdp_layer->client_info.use_bulk_comp)\n        {\n\n            self->rdp_layer->client_info.rdp_compression = 1;\n            LOG(LOG_LEVEL_DEBUG, \"Client requested compression enabled.\");\n        }\n        else\n        {\n            LOG(LOG_LEVEL_DEBUG, \"Client requested compression, but server \"\n                \"compression is disabled.\");\n        }\n    }\n\n    if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPBCGR] TS_INFO_PACKET cbDomain\"))\n    {\n        return 1;\n    }\n    in_uint16_le(s, len_domain);\n\n    if (len_domain >= INFO_CLIENT_MAX_CB_LEN)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Client supplied domain is too long. Max length %d, domain length %d\",\n            INFO_CLIENT_MAX_CB_LEN, len_domain);\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPBCGR] TS_INFO_PACKET cbUserName\"))\n    {\n        return 1;\n    }\n    in_uint16_le(s, len_user);\n\n    /*\n     * Microsoft's itap client running on Mac OS/Android\n     * always sends autologon credentials, even when user has not\n     * configured any\n     */\n    if (len_user == 0 && self->rdp_layer->client_info.rdp_autologin)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Client supplied user name is empty, disabling autologin\");\n        self->rdp_layer->client_info.rdp_autologin = 0;\n    }\n\n    if (len_user >= INFO_CLIENT_MAX_CB_LEN)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Client supplied user name is too long. Max length %d, user name length %d\",\n            INFO_CLIENT_MAX_CB_LEN, len_user);\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPBCGR] TS_INFO_PACKET cbPassword\"))\n    {\n        return 1;\n    }\n    in_uint16_le(s, len_password);\n\n    /*\n     * Ignore autologin requests if the password is empty. System managers\n     * who really want to allow empty passwords can do this with a\n     * special session type */\n    if (len_password == 0 && self->rdp_layer->client_info.rdp_autologin)\n    {\n        LOG(LOG_LEVEL_DEBUG,\n            \"Client supplied password is empty, disabling autologin\");\n        self->rdp_layer->client_info.rdp_autologin = 0;\n    }\n\n    if (len_password >= INFO_CLIENT_MAX_CB_LEN)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Client supplied password is too long. Max length %d, password length %d\",\n            INFO_CLIENT_MAX_CB_LEN, len_password);\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPBCGR] TS_INFO_PACKET cbAlternateShell\"))\n    {\n        return 1;\n    }\n    in_uint16_le(s, len_program);\n\n    if (len_program >= INFO_CLIENT_MAX_CB_LEN)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Client supplied program name is too long. Max length %d, program name length %d\",\n            INFO_CLIENT_MAX_CB_LEN, len_program);\n        return 1;\n    }\n\n    if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPBCGR] TS_INFO_PACKET cbWorkingDir\"))\n    {\n        return 1;\n    }\n    in_uint16_le(s, len_directory);\n\n    if (len_directory >= INFO_CLIENT_MAX_CB_LEN)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Client supplied directory name is too long. Max length %d, directory name length %d\",\n            INFO_CLIENT_MAX_CB_LEN, len_directory);\n        return 1;\n    }\n\n    if (ts_info_utf16_in(s, len_domain, self->rdp_layer->client_info.domain, sizeof(self->rdp_layer->client_info.domain)) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"ERROR reading domain\");\n        return 1;\n    }\n\n    if (ts_info_utf16_in(s, len_user, self->rdp_layer->client_info.username, sizeof(self->rdp_layer->client_info.username)) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"ERROR reading user name\");\n        return 1;\n    }\n\n    // If we require credentials, don't continue if they're not provided\n    if (self->rdp_layer->client_info.require_credentials)\n    {\n        if ((flags & RDP_LOGON_AUTO) == 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Server is configured to require that the \"\n                \"client enable auto logon with credentials, but the client did \"\n                \"not request auto logon.\");\n            return 1;\n        }\n        if (len_user == 0 || len_password == 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Server is configured to require that the \"\n                \"client enable auto logon with credentials, but the client did \"\n                \"not supply both a username and password.\");\n            return 1;\n        }\n    }\n\n    if (flags & RDP_LOGON_AUTO)\n    {\n        if (ts_info_utf16_in(s, len_password, self->rdp_layer->client_info.password, sizeof(self->rdp_layer->client_info.password)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"ERROR reading password\");\n            return 1;\n        }\n    }\n    else if (self->rdp_layer->client_info.enable_token_login\n             && len_user > 0\n             && len_password == 0\n             && (sep = g_strchr(self->rdp_layer->client_info.username, '\\x1f')) != NULL)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Client supplied a Logon token. Overwriting password with logon token.\");\n        g_strncpy(self->rdp_layer->client_info.password, sep + 1,\n                  sizeof(self->rdp_layer->client_info.password) - 1);\n        self->rdp_layer->client_info.username[sep - self->rdp_layer->client_info.username] = '\\0';\n        self->rdp_layer->client_info.rdp_autologin = 1;\n    }\n    else\n    {\n        // Skip the password\n        if (!s_check_rem_and_log(s, len_password + 2, \"Parsing [MS-RDPBCGR] TS_INFO_PACKET Password\"))\n        {\n            return 1;\n        }\n        in_uint8s(s, len_password + 2);\n    }\n    if (self->rdp_layer->client_info.domain_user_separator[0] != '\\0'\n            && self->rdp_layer->client_info.domain[0] != '\\0')\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Client supplied domain with user name. Overwriting user name with user name parsed from domain.\");\n        int size = sizeof(self->rdp_layer->client_info.username);\n        g_strncat(self->rdp_layer->client_info.username, self->rdp_layer->client_info.domain_user_separator, size - 1 - g_strlen(self->rdp_layer->client_info.domain_user_separator));\n        g_strncat(self->rdp_layer->client_info.username, self->rdp_layer->client_info.domain, size - 1 - g_strlen(self->rdp_layer->client_info.domain));\n    }\n\n    if (ts_info_utf16_in(s, len_program, self->rdp_layer->client_info.program, sizeof(self->rdp_layer->client_info.program)) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"ERROR reading program\");\n        return 1;\n    }\n\n    if (ts_info_utf16_in(s, len_directory, self->rdp_layer->client_info.directory, sizeof(self->rdp_layer->client_info.directory)) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"ERROR reading directory\");\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_INFO_PACKET \"\n              \"CodePage (ignored), flags 0x%8.8x, cbDomain %d, cbUserName %d, \"\n              \"cbPassword %d, cbAlternateShell %d, cbWorkingDir %d, Domain %s, \"\n              \"UserName %s, Password (omitted from log), AlternateShell %s, \"\n              \"WorkingDir %s\", flags, len_domain,\n              len_user, len_password, len_program, len_directory,\n              self->rdp_layer->client_info.domain,\n              self->rdp_layer->client_info.username,\n              self->rdp_layer->client_info.program,\n              self->rdp_layer->client_info.directory);\n    LOG(LOG_LEVEL_DEBUG, \"Client supplied domain: %s\", self->rdp_layer->client_info.domain);\n    LOG(LOG_LEVEL_DEBUG, \"Client supplied username: %s\", self->rdp_layer->client_info.username);\n    LOG(LOG_LEVEL_DEBUG, \"Client supplied password: <omitted from log>\");\n    LOG(LOG_LEVEL_DEBUG, \"Client supplied program: %s\", self->rdp_layer->client_info.program);\n    LOG(LOG_LEVEL_DEBUG, \"Client supplied directory: %s\", self->rdp_layer->client_info.directory);\n\n    /* TODO: explain why the windows key flag is used to determine if the\n       TS_EXTENDED_INFO_PACKET should be parsed */\n    if (flags & RDP_LOGON_BLOB) /* INFO_ENABLEWINDOWSKEY */\n    {\n        if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET \"\n                                 \"clientAddressFamily and cbClientAddress\"))\n        {\n            return 1;\n        }\n        /* TS_EXTENDED_INFO_PACKET required fields */\n        in_uint8s(s, 2);         /* clientAddressFamily */\n        in_uint16_le(s, len_clnt_addr);\n        if (len_clnt_addr > EXTENDED_INFO_MAX_CLIENT_ADDR_LENGTH ||\n                !s_check_rem(s, len_clnt_addr))\n        {\n            LOG(LOG_LEVEL_ERROR, \"clientAddress is too long (%u bytes)\",\n                len_clnt_addr);\n            return 1;\n        }\n        // The clientAddress is currently unused. [MS-RDPBCGR] requires\n        // a mandatory null terminator, but some clients set\n        // len_clnt_addr == 0 if this field is missing. Allow for this\n        // in any future implementation.\n        in_uint8s(s, len_clnt_addr); // Skip Unicode clientAddress\n\n        if (!s_check_rem_and_log(s, 2, \"Parsing [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET clientDir\"))\n        {\n            return 1;\n        }\n        in_uint16_le(s, len_clnt_dir);\n        if (len_clnt_dir > INFO_CLIENT_MAX_CB_LEN ||\n                !s_check_rem(s, len_clnt_dir))\n        {\n            LOG(LOG_LEVEL_ERROR, \"clientDir is too long (%u bytes)\", len_clnt_dir);\n            return 1;\n        }\n        in_uint8s(s, len_clnt_dir); // Skip Unicode clientDir\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET \"\n                  \"<Required Fields> clientAddressFamily (ignored), \"\n                  \"cbClientAddress (ignored), clientAddress (ignored), \"\n                  \"cbClientDir (ignored), clientDir (ignored)\");\n\n        /* TODO: MS-BCGR 2.2.1.11.1.1.1 says that all fields after the\n           client directory are optional. */\n        if (!s_check_rem_and_log(s, 4 + 64 + 20 + 64 + 20 + 4 + 4,\n                                 \"Parsing [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET \"\n                                 \"clientTimeZone, clientSessionId, and performanceFlags\"))\n        {\n            return 1;\n        }\n        /* TS_TIME_ZONE_INFORMATION */\n        in_uint8s(s, 4);   /* Bias (4) */\n        in_uint8s(s, 64);  /* StandardName (64) */\n        in_uint8s(s, 20);  /* StandardDate (16), StandardBias (4) */\n        in_uint8s(s, 64);  /* DaylightName (64) */\n        in_uint8s(s, 20);  /* DaylightDate (16), DaylightBias (4) */\n        in_uint8s(s, 4);   /* TS_EXTENDED_INFO_PACKET clientSessionId (4) */\n\n        /* TS_EXTENDED_INFO_PACKET optional fields */\n        in_uint32_le(s, self->rdp_layer->client_info.rdp5_performanceflags);\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET \"\n                  \"<Optional Fields> clientTimeZone (ignored), \"\n                  \"clientSessionId (ignored), performanceFlags 0x%8.8x, \"\n                  \"cbAutoReconnectCookie (ignored), autoReconnectCookie (ignored), \"\n                  \"reserved1 (ignored), reserved2 (ignored), \"\n                  \"cbDynamicDSTTimeZoneKeyName (ignored), \"\n                  \"dynamicDSTTimeZoneKeyName (ignored), \"\n                  \"dynamicDaylightTimeDisabled (ignored)\",\n                  self->rdp_layer->client_info.rdp5_performanceflags);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n * Send a [MS-RDPBCGR] Server License Error PDU (2.2.1.12) with\n * STATUS_VALID_CLIENT\n */\n/* returns error */\nstatic int\nxrdp_sec_send_lic_response(struct xrdp_sec *self)\n{\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    if (xrdp_mcs_init(self->mcs_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_sec_send_lic_response: xrdp_mcs_init failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    /* [MS-RDPBCGR] TS_SECURITY_HEADER */\n    /* A careful reading of [MS-RDPBCGR] 2.2.1.12 shows that a securityHeader\n     * MUST be included, and provided the flag fields of the header does\n     * not contain SEC_ENCRYPT, it is always possible to send a basic\n     * security header */\n    out_uint16_le(s, SEC_LICENSE_PKT | SEC_LICENSE_ENCRYPT_CS); /* flags */\n    out_uint16_le(s, 0); /* flagsHi */\n\n    /* [MS-RDPBCGR] LICENSE_VALID_CLIENT_DATA */\n    /* preamble (LICENSE_PREAMBLE) */\n    out_uint8(s, ERROR_ALERT);\n    out_uint8(s, PREAMBLE_VERSION_3_0);\n    out_uint16_le(s, 16); /* Message size, including pre-amble */\n\n    /* validClientMessage */\n    /* From [MS-RDPBCGR] 2.2.12.1, dwStateTransition must be ST_NO_TRANSITION,\n     * and the bbErrorInfo field must contain an empty blob of type\n     * BB_ERROR_BLOB */\n    out_uint32_le(s, STATUS_VALID_CLIENT); /* dwErrorCode */\n    out_uint32_le(s, ST_NO_TRANSITION); /* dwStateTransition */\n    out_uint16_le(s, BB_ERROR_BLOB);    /* wBlobType */\n    out_uint16_le(s, 0);                /* wBlobLen */\n    s_mark_end(s);\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] Server License Error PDU with STATUS_VALID_CLIENT\");\n    if (xrdp_mcs_send(self->mcs_layer, s, MCS_GLOBAL_CHANNEL) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Sending [MS-RDPBCGR] Server License Error PDU with STATUS_VALID_CLIENT failed\");\n        free_stream(s);\n        return 1;\n    }\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic void\nxrdp_sec_rsa_op(struct xrdp_sec *self, char *out, char *in, int in_bytes,\n                char *mod, char *exp)\n{\n    ssl_mod_exp(out, self->rsa_key_bytes, in, in_bytes,\n                mod, self->rsa_key_bytes,\n                exp, self->rsa_key_bytes);\n}\n\n/*****************************************************************************/\nstatic void\nxrdp_sec_hash_48(char *out, char *in, char *salt1, char *salt2, int salt)\n{\n    int i;\n    void *sha1_info;\n    void *md5_info;\n    char pad[4];\n    char sha1_sig[20];\n    char md5_sig[16];\n\n    sha1_info = ssl_sha1_info_create();\n    md5_info = ssl_md5_info_create();\n\n    for (i = 0; i < 3; i++)\n    {\n        g_memset(pad, salt + i, 4);\n        ssl_sha1_clear(sha1_info);\n        ssl_sha1_transform(sha1_info, pad, i + 1);\n        ssl_sha1_transform(sha1_info, in, 48);\n        ssl_sha1_transform(sha1_info, salt1, 32);\n        ssl_sha1_transform(sha1_info, salt2, 32);\n        ssl_sha1_complete(sha1_info, sha1_sig);\n        ssl_md5_clear(md5_info);\n        ssl_md5_transform(md5_info, in, 48);\n        ssl_md5_transform(md5_info, sha1_sig, 20);\n        ssl_md5_complete(md5_info, md5_sig);\n        g_memcpy(out + i * 16, md5_sig, 16);\n    }\n\n    ssl_sha1_info_delete(sha1_info);\n    ssl_md5_info_delete(md5_info);\n}\n\n/*****************************************************************************/\nstatic void\nxrdp_sec_hash_16(char *out, char *in, char *salt1, char *salt2)\n{\n    void *md5_info;\n\n    md5_info = ssl_md5_info_create();\n    ssl_md5_clear(md5_info);\n    ssl_md5_transform(md5_info, in, 16);\n    ssl_md5_transform(md5_info, salt1, 32);\n    ssl_md5_transform(md5_info, salt2, 32);\n    ssl_md5_complete(md5_info, out);\n    ssl_md5_info_delete(md5_info);\n}\n\n/*****************************************************************************/\nstatic void\nfips_expand_key_bits(const char *in, char *out)\n{\n    tui8 buf[32];\n    tui8 c;\n    int i;\n    int b;\n    int p;\n    int r;\n\n    /* reverse every byte in the key */\n    for (i = 0; i < 21; i++)\n    {\n        c = in[i];\n        buf[i] = g_fips_reverse_table[c];\n    }\n    /* insert a zero-bit after every 7th bit */\n    for (i = 0, b = 0; i < 24; i++, b += 7)\n    {\n        p = b / 8;\n        r = b % 8;\n        if (r == 0)\n        {\n            out[i] = buf[p] & 0xfe;\n        }\n        else\n        {\n            /* c is accumulator */\n            c = buf[p] << r;\n            c |= buf[p + 1] >> (8 - r);\n            out[i] = c & 0xfe;\n        }\n    }\n    /* reverse every byte */\n    /* alter lsb so the byte has odd parity */\n    for (i = 0; i < 24; i++)\n    {\n        c = out[i];\n        c = g_fips_reverse_table[c];\n        out[i] = g_fips_oddparity_table[c];\n    }\n}\n\n/****************************************************************************/\nstatic void\nxrdp_sec_fips_establish_keys(struct xrdp_sec *self)\n{\n    char server_encrypt_key[32];\n    char server_decrypt_key[32];\n    const char *fips_ivec;\n    void *sha1;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_sec_fips_establish_keys:\");\n\n    sha1 = ssl_sha1_info_create();\n    ssl_sha1_clear(sha1);\n    ssl_sha1_transform(sha1, self->client_random + 16, 16);\n    ssl_sha1_transform(sha1, self->server_random + 16, 16);\n    ssl_sha1_complete(sha1, server_decrypt_key);\n\n    server_decrypt_key[20] = server_decrypt_key[0];\n    fips_expand_key_bits(server_decrypt_key, self->fips_decrypt_key);\n    ssl_sha1_info_delete(sha1);\n\n    sha1 = ssl_sha1_info_create();\n    ssl_sha1_clear(sha1);\n    ssl_sha1_transform(sha1, self->client_random, 16);\n    ssl_sha1_transform(sha1, self->server_random, 16);\n    ssl_sha1_complete(sha1, server_encrypt_key);\n    server_encrypt_key[20] = server_encrypt_key[0];\n    fips_expand_key_bits(server_encrypt_key, self->fips_encrypt_key);\n    ssl_sha1_info_delete(sha1);\n\n    sha1 = ssl_sha1_info_create();\n    ssl_sha1_clear(sha1);\n    ssl_sha1_transform(sha1, server_encrypt_key, 20);\n    ssl_sha1_transform(sha1, server_decrypt_key, 20);\n    ssl_sha1_complete(sha1, self->fips_sign_key);\n    ssl_sha1_info_delete(sha1);\n\n    fips_ivec = (const char *) g_fips_ivec;\n    self->encrypt_fips_info =\n        ssl_des3_encrypt_info_create(self->fips_encrypt_key, fips_ivec);\n    self->decrypt_fips_info =\n        ssl_des3_decrypt_info_create(self->fips_decrypt_key, fips_ivec);\n    self->sign_fips_info = ssl_hmac_info_create();\n}\n\n/****************************************************************************/\nstatic void\nxrdp_sec_establish_keys(struct xrdp_sec *self)\n{\n    char session_key[48];\n    char temp_hash[48];\n    char input[48];\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_sec_establish_keys:\");\n\n    g_memcpy(input, self->client_random, 24);\n    g_memcpy(input + 24, self->server_random, 24);\n    xrdp_sec_hash_48(temp_hash, input, self->client_random,\n                     self->server_random, 65);\n    xrdp_sec_hash_48(session_key, temp_hash, self->client_random,\n                     self->server_random, 88);\n    g_memcpy(self->sign_key, session_key, 16);\n    xrdp_sec_hash_16(self->encrypt_key, session_key + 16, self->client_random,\n                     self->server_random);\n    xrdp_sec_hash_16(self->decrypt_key, session_key + 32, self->client_random,\n                     self->server_random);\n\n    if (self->crypt_method == CRYPT_METHOD_40BIT)\n    {\n        xrdp_sec_make_40bit(self->sign_key);\n        xrdp_sec_make_40bit(self->encrypt_key);\n        xrdp_sec_make_40bit(self->decrypt_key);\n        self->rc4_key_len = 8;\n    }\n    else\n    {\n        self->rc4_key_len = 16;\n    }\n\n    g_memcpy(self->decrypt_update_key, self->decrypt_key, 16);\n    g_memcpy(self->encrypt_update_key, self->encrypt_key, 16);\n    ssl_rc4_set_key(self->decrypt_rc4_info, self->decrypt_key, self->rc4_key_len);\n    ssl_rc4_set_key(self->encrypt_rc4_info, self->encrypt_key, self->rc4_key_len);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_sec_recv_fastpath(struct xrdp_sec *self, struct stream *s)\n{\n    int ver;\n    int len;\n    int pad;\n\n#ifndef USE_DEVEL_LOGGING\n    /* TODO: remove UNUSED_VAR once the `ver` variable is used for more than\n    logging in debug mode */\n    UNUSED_VAR(ver);\n#endif\n\n    if (xrdp_fastpath_recv(self->fastpath_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_sec_recv_fastpath: xrdp_fastpath_recv failed\");\n        return 1;\n    }\n\n    if (self->fastpath_layer->secFlags & FASTPATH_INPUT_ENCRYPTED)\n    {\n        if (self->crypt_level == CRYPT_LEVEL_FIPS)\n        {\n            if (!s_check_rem_and_log(s, 12, \"Parsing [MS-RDPBCGR] TS_FP_FIPS_INFO\"))\n            {\n                return 1;\n            }\n            /* TS_FP_FIPS_INFO */\n            in_uint16_le(s, len);\n            in_uint8(s, ver); /* length (2 bytes) */\n            in_uint8(s, pad);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPBCGR] TS_FP_FIPS_INFO \"\n                      \"length %d, version %d, padlen %d\", len, ver, pad);\n            if (len != 0x10)  /* length MUST set to 0x10 */\n            {\n                LOG(LOG_LEVEL_ERROR, \"Received header [MS-RDPBCGR] TS_FP_FIPS_INFO \"\n                    \"invalid fastpath length. Expected 16, received %d\", len);\n                return 1;\n            }\n\n            /* remainder of TS_FP_INPUT_PDU */\n            in_uint8s(s, 8);  /* dataSignature (8 bytes), skip for now */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"CRYPT_LEVEL_FIPS - data len %d\",\n                      (int)(s->end - s->p));\n            xrdp_sec_fips_decrypt(self, s->p, (int)(s->end - s->p));\n            s->end -= pad;\n        }\n        else\n        {\n            if (!s_check_rem_and_log(s, 8,\n                                     \"Parsing [MS-RDPBCGR] TS_FP_INPUT_PDU dataSignature\"))\n            {\n                return 1;\n            }\n            /* remainder of TS_FP_INPUT_PDU */\n            in_uint8s(s, 8);  /* dataSignature (8 bytes), skip for now */\n            xrdp_sec_decrypt(self, s->p, (int)(s->end - s->p));\n        }\n    }\n\n    if (self->fastpath_layer->numEvents == 0) /* set by xrdp_fastpath_recv() */\n    {\n        /**\n         * If numberEvents is not provided in fpInputHeader, it will be provided\n         * as one additional byte here.\n         */\n        if (!s_check_rem_and_log(s, 8, \"Parsing [MS-RDPBCGR] TS_FP_INPUT_PDU numEvents\"))\n        {\n            return 1;\n        }\n        in_uint8(s, self->fastpath_layer->numEvents); /* numEvents (1 byte) (optional) */\n    }\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_FP_INPUT_PDU \"\n              \"fpInputHeader.action (ignored), \"\n              \"fpInputHeader.numEvents (see final numEvents), \"\n              \"fpInputHeader.flags %d, length1 (ToDo), length2 (ToDo), \"\n              \"fipsInformation %s, dataSignature (ignored), numEvents %d\",\n              self->fastpath_layer->secFlags,\n              (self->fastpath_layer->secFlags & FASTPATH_INPUT_ENCRYPTED) ? \"(see above)\" : \"(not present)\",\n              self->fastpath_layer->numEvents);\n\n    return 0;\n}\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_sec_recv(struct xrdp_sec *self, struct stream *s, int *chan)\n{\n    int flags;\n    int len;\n    int ver;\n    int pad;\n\n\n    if (xrdp_mcs_recv(self->mcs_layer, s, chan) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_sec_recv: xrdp_mcs_recv failed\");\n        return 1;\n    }\n\n    /* TODO: check if moving this check until after the is_security_header_present\n    causes any issues.\n    the security header is optional (eg. TLS connections), so this\n    check should really be after the check if the security header is present,\n    this currently seems to be working by coincidence at the moment. */\n    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPBCGR] TS_SECURITY_HEADER\"))\n    {\n        return 1;\n    }\n\n    if (!(self->is_security_header_present))\n    {\n        /* noisy log statement with no real info since this is an\n           expected state for TLS connections\n        */\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_sec_recv: security header NOT present\");\n        return 0;\n    }\n\n    /* TS_SECURITY_HEADER */\n    in_uint32_le(s, flags);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPBCGR] TS_SECURITY_HEADER \"\n              \"flags 0x%8.8x, flagsHi (merged with flags)\", flags);\n\n    if (flags & SEC_ENCRYPT) /* 0x08 */\n    {\n        if (self->crypt_level == CRYPT_LEVEL_FIPS)\n        {\n            if (!s_check_rem_and_log(s, 12, \"Parsing [MS-RDPBCGR] TS_SECURITY_HEADER2\"))\n            {\n                return 1;\n            }\n            /* TS_SECURITY_HEADER2 */\n            in_uint16_le(s, len); /* length */\n            in_uint8(s, ver); /* version */\n            in_uint8(s, pad); /* padlen */\n            in_uint8s(s, 8); /* signature(8) */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPBCGR] TS_SECURITY_HEADER2 \"\n                      \"length %d, version %d, padlen %d, dataSignature (ignored)\",\n                      len, ver, pad);\n            if (len != 16)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Received header [MS-RDPBCGR] TS_SECURITY_HEADER2 \"\n                    \"has unexpected length. Expected 16, actual %d\", len);\n                return 1;\n            }\n            if (ver != 1)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Received header [MS-RDPBCGR] TS_SECURITY_HEADER2 \"\n                    \"has unexpected version. Expected 1, actual %d\", ver);\n                return 1;\n            }\n            xrdp_sec_fips_decrypt(self, s->p, (int)(s->end - s->p));\n            s->end -= pad;\n        }\n        else if (self->crypt_level > CRYPT_LEVEL_NONE)\n        {\n            if (!s_check_rem_and_log(s, 8, \"Parsing [MS-RDPBCGR] TS_SECURITY_HEADER1\"))\n            {\n                return 1;\n            }\n            /* TS_SECURITY_HEADER1 */\n            in_uint8s(s, 8); /* signature(8) */\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPBCGR] TS_SECURITY_HEADER1 \"\n                      \"dataSignature (ignored)\");\n            xrdp_sec_decrypt(self, s->p, (int)(s->end - s->p));\n        }\n    }\n\n    if (flags & SEC_EXCHANGE_PKT) /* 0x01 TS_SECURITY_PACKET */\n    {\n        if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPBCGR] TS_SECURITY_PACKET\"))\n        {\n            return 1;\n        }\n        in_uint32_le(s, len);\n        /* 512, 2048 bit */\n        if ((len != 64 + 8) && (len != 256 + 8))\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_sec_recv : error - unexpected length %d\", len);\n            return 1;\n        }\n        if (!s_check_rem_and_log(s, len - 8,\n                                 \"Parsing [MS-RDPBCGR] TS_SECURITY_PACKET encryptedClientRandom\"))\n        {\n            return 1;\n        }\n        in_uint8a(s, self->client_crypt_random, len - 8);\n\n        xrdp_sec_rsa_op(self, self->client_random, self->client_crypt_random,\n                        len - 8, self->pub_mod, self->pri_exp);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_SECURITY_PACKET \"\n                  \"length %d, encryptedClientRandom (see below)\", len);\n        LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"encryptedClientRandom\", self->client_crypt_random, len - 8);\n        LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"decrypted encryptedClientRandom\", self->client_random, 256);\n        if (self->crypt_level == CRYPT_LEVEL_FIPS)\n        {\n            xrdp_sec_fips_establish_keys(self);\n        }\n        else if (self->crypt_method != CRYPT_METHOD_NONE)\n        {\n            xrdp_sec_establish_keys(self);\n        }\n        *chan = 1; /* just set a non existing channel and exit */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_sec_recv: out channel 1 (non-existing channel)\");\n        return 0;\n    }\n\n    if (flags & SEC_INFO_PKT)\n    {\n        if (xrdp_sec_process_logon_info(self, s) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_sec_recv: xrdp_sec_process_logon_info failed\");\n            return 1;\n        }\n\n        if (xrdp_sec_send_lic_response(self) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_sec_recv: xrdp_sec_send_lic_response failed\");\n            return 1;\n        }\n\n        if (self->crypt_level == CRYPT_LEVEL_NONE\n                && self->crypt_method == CRYPT_METHOD_NONE)\n        {\n            /* in tls mode, no more security header from now on */\n            self->is_security_header_present = 0;\n        }\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_sec_recv: out 'send demand active'\");\n        return -1; /* special error that means send demand active */\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Output a uint32 into a buffer (little-endian) */\nstatic void\nbuf_out_uint32(char *buffer, int value)\n{\n    buffer[0] = (value) & 0xff;\n    buffer[1] = (value >> 8) & 0xff;\n    buffer[2] = (value >> 16) & 0xff;\n    buffer[3] = (value >> 24) & 0xff;\n}\n\n/*****************************************************************************/\n/* Generate a MAC hash (5.2.3.1), using a combination of SHA1 and MD5 */\nstatic void\nxrdp_sec_fips_sign(struct xrdp_sec *self, char *out, int out_len,\n                   char *data, int data_len)\n{\n    char buf[20];\n    char lenhdr[4];\n\n    buf_out_uint32(lenhdr, self->encrypt_use_count);\n    ssl_hmac_sha1_init(self->sign_fips_info, self->fips_sign_key, 20);\n    ssl_hmac_transform(self->sign_fips_info, data, data_len);\n    ssl_hmac_transform(self->sign_fips_info, lenhdr, 4);\n    ssl_hmac_complete(self->sign_fips_info, buf, 20);\n    g_memcpy(out, buf, out_len);\n}\n\n/*****************************************************************************/\n/* Generate a MAC hash (5.2.3.1), using a combination of SHA1 and MD5 */\nstatic void\nxrdp_sec_sign(struct xrdp_sec *self, char *out, int out_len,\n              char *data, int data_len)\n{\n    char shasig[20];\n    char md5sig[16];\n    char lenhdr[4];\n    void *sha1_info;\n    void *md5_info;\n\n    buf_out_uint32(lenhdr, data_len);\n    sha1_info = ssl_sha1_info_create();\n    md5_info = ssl_md5_info_create();\n    ssl_sha1_clear(sha1_info);\n    ssl_sha1_transform(sha1_info, self->sign_key, self->rc4_key_len);\n    ssl_sha1_transform(sha1_info, (char *)g_pad_54, 40);\n    ssl_sha1_transform(sha1_info, lenhdr, 4);\n    ssl_sha1_transform(sha1_info, data, data_len);\n    ssl_sha1_complete(sha1_info, shasig);\n    ssl_md5_clear(md5_info);\n    ssl_md5_transform(md5_info, self->sign_key, self->rc4_key_len);\n    ssl_md5_transform(md5_info, (char *)g_pad_92, 48);\n    ssl_md5_transform(md5_info, shasig, 20);\n    ssl_md5_complete(md5_info, md5sig);\n    g_memcpy(out, md5sig, out_len);\n    ssl_sha1_info_delete(sha1_info);\n    ssl_md5_info_delete(md5_info);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_sec_send(struct xrdp_sec *self, struct stream *s, int chan)\n{\n    int datalen;\n    int pad;\n\n    s_pop_layer(s, sec_hdr);\n\n    if (self->crypt_level > CRYPT_LEVEL_NONE)\n    {\n        if (self->crypt_level == CRYPT_LEVEL_FIPS)\n        {\n            out_uint32_le(s, SEC_ENCRYPT);\n            datalen = (int)((s->end - s->p) - 12);\n            out_uint16_le(s, 16); /* crypto header size */\n            out_uint8(s, 1); /* fips version */\n            pad = (8 - (datalen % 8)) & 7;\n            g_memset(s->end, 0, pad);\n            s->end += pad;\n            out_uint8(s, pad); /* fips pad */\n            xrdp_sec_fips_sign(self, s->p, 8, s->p + 8, datalen);\n            xrdp_sec_fips_encrypt(self, s->p + 8, datalen + pad);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_SECURITY_HEADER2 \"\n                      \"flags 0x%4.4x, flagsHi 0x%4.4x, length 16, version 1, \"\n                      \"padlen %d, dataSignature 0x%8.8x 0x%8.8x\",\n                      SEC_ENCRYPT & 0xffff, (SEC_ENCRYPT & 0xffff0000) >> 16,\n                      pad, *((uint32_t *) s->p), *((uint32_t *) (s->p + 4)));\n        }\n        else if (self->crypt_level > CRYPT_LEVEL_LOW)\n        {\n            out_uint32_le(s, SEC_ENCRYPT);\n            datalen = (int)((s->end - s->p) - 8);\n            xrdp_sec_sign(self, s->p, 8, s->p + 8, datalen);\n            xrdp_sec_encrypt(self, s->p + 8, datalen);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_SECURITY_HEADER1 \"\n                      \"flags 0x%4.4x, flagsHi 0x%4.4x, dataSignature 0x%8.8x 0x%8.8x\",\n                      SEC_ENCRYPT & 0xffff, (SEC_ENCRYPT & 0xffff0000) >> 16,\n                      *((uint32_t *) s->p), *((uint32_t *) (s->p + 4)));\n        }\n        else\n        {\n            out_uint32_le(s, 0);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"Adding header [MS-RDPBCGR] TS_SECURITY_HEADER \"\n                      \"flags 0x0000, flagsHi 0x0000\");\n        }\n    }\n\n    if (xrdp_mcs_send(self->mcs_layer, s, chan) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_sec_send: xrdp_mcs_send failed\");\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns the fastpath sec byte count */\nint\nxrdp_sec_get_fastpath_bytes(struct xrdp_sec *self)\n{\n    if (self->crypt_level == CRYPT_LEVEL_FIPS)\n    {\n        return 3 + 4 + 8;\n    }\n    else if (self->crypt_level > CRYPT_LEVEL_LOW)\n    {\n        return 3 + 8;\n    }\n    return 3;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_sec_init_fastpath(struct xrdp_sec *self, struct stream *s)\n{\n    if (xrdp_fastpath_init(self->fastpath_layer, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_sec_init_fastpath: xrdp_fastpath_init failed\");\n        return 1;\n    }\n    if (self->crypt_level == CRYPT_LEVEL_FIPS)\n    {\n        s_push_layer(s, sec_hdr, 3 + 4 + 8);\n    }\n    else if (self->crypt_level > CRYPT_LEVEL_LOW)\n    {\n        s_push_layer(s, sec_hdr, 3 + 8);\n    }\n    else\n    {\n        s_push_layer(s, sec_hdr, 3);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* 2.2.9.1.2 Server Fast-Path Update PDU (TS_FP_UPDATE_PDU)\n * http://msdn.microsoft.com/en-us/library/cc240621.aspx */\nint\nxrdp_sec_send_fastpath(struct xrdp_sec *self, struct stream *s)\n{\n    int secFlags;\n    int fpOutputHeader;\n    int datalen;\n    int pdulen;\n    int pad;\n    int error;\n    char save[8];\n\n    error = 0;\n    s_pop_layer(s, sec_hdr);\n    if (self->crypt_level == CRYPT_LEVEL_FIPS)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_sec_send_fastpath: fips\");\n        pdulen = (int)(s->end - s->p);\n        datalen = pdulen - 15;\n        pad = (8 - (datalen % 8)) & 7;\n        secFlags = 0x2;\n        fpOutputHeader = secFlags << 6;\n        out_uint8(s, fpOutputHeader);\n        pdulen += pad;\n        pdulen |= 0x8000;\n        out_uint16_be(s, pdulen);\n        out_uint16_le(s, 16); /* crypto header size */\n        out_uint8(s, 1); /* fips version */\n        s->end += pad;\n        out_uint8(s, pad); /* fips pad */\n        xrdp_sec_fips_sign(self, s->p, 8, s->p + 8, datalen);\n        g_memcpy(save, s->p + 8 + datalen, pad);\n        g_memset(s->p + 8 + datalen, 0, pad);\n        xrdp_sec_fips_encrypt(self, s->p + 8, datalen + pad);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FP_UPDATE_PDU \"\n                  \"fpOutputHeader.action 0, fpOutputHeader.reserved 0, \"\n                  \"fpOutputHeader.flags 0x2, length1 0x%2.2x, length2 0x%2.2x, \"\n                  \"fipsInformation.length 16, fipsInformation.version 1, \"\n                  \"fipsInformation.padlen %d, dataSignature 0x%8.8x 0x%8.8x, \",\n                  pdulen >> 4, pdulen & 0xff, pad,\n                  *((uint32_t *) s->p), *((uint32_t *) (s->p + 4)));\n        error = xrdp_fastpath_send(self->fastpath_layer, s);\n        g_memcpy(s->p + 8 + datalen, save, pad);\n    }\n    else if (self->crypt_level > CRYPT_LEVEL_LOW)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_sec_send_fastpath: crypt\");\n        pdulen = (int)(s->end - s->p);\n        datalen = pdulen - 11;\n        secFlags = 0x2;\n        fpOutputHeader = secFlags << 6;\n        out_uint8(s, fpOutputHeader);\n        pdulen |= 0x8000;\n        out_uint16_be(s, pdulen);\n        xrdp_sec_sign(self, s->p, 8, s->p + 8, datalen);\n        xrdp_sec_encrypt(self, s->p + 8, datalen);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FP_UPDATE_PDU \"\n                  \"fpOutputHeader.action 0, fpOutputHeader.reserved 0, \"\n                  \"fpOutputHeader.flags 0x2, length1 0x%2.2x, length2 0x%2.2x, \"\n                  \"dataSignature 0x%8.8x 0x%8.8x, \",\n                  pdulen >> 4, pdulen & 0xff,\n                  *((uint32_t *) s->p), *((uint32_t *) (s->p + 4)));\n        error = xrdp_fastpath_send(self->fastpath_layer, s);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_sec_send_fastpath: no crypt\");\n        pdulen = (int)(s->end - s->p);\n        secFlags = 0x0;\n        fpOutputHeader = secFlags << 6;\n        out_uint8(s, fpOutputHeader);\n        pdulen |= 0x8000;\n        out_uint16_be(s, pdulen);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Sending [MS-RDPBCGR] TS_FP_UPDATE_PDU \"\n                  \"fpOutputHeader.action 0, fpOutputHeader.reserved 0, \"\n                  \"fpOutputHeader.flags 0, length1 0x%2.2x, length2 0x%2.2x\",\n                  pdulen >> 4, pdulen & 0xff);\n        error = xrdp_fastpath_send(self->fastpath_layer, s);\n    }\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_sec_send_fastpath: xrdp_fastpath_send failed\");\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* http://msdn.microsoft.com/en-us/library/cc240510.aspx\n   2.2.1.3.2 Client Core Data (TS_UD_CS_CORE) */\nstatic int\nxrdp_sec_process_mcs_data_CS_CORE(struct xrdp_sec *self, struct stream *s)\n{\n#define CS_CORE_MIN_LENGTH \\\n    (\\\n     4 +            /* Version */ \\\n     2 + 2 +        /* desktopWidth + desktopHeight */ \\\n     2 + 2 +        /* colorDepth + SASSequence */ \\\n     4 +            /* keyboardLayout */ \\\n     4 + INFO_CLIENT_NAME_BYTES_UTF16 + /* clientBuild + clientName */ \\\n     4 + 4 + 4 +    /* keyboardType + keyboardSubType + keyboardFunctionKey */ \\\n     64 +           /* imeFileName */ \\\n     0)\n\n    int version;\n    int colorDepth;\n    int postBeta2ColorDepth;\n    int highColorDepth;\n    int supportedColorDepths;\n    int earlyCapabilityFlags;\n\n    UNUSED_VAR(version);\n    struct xrdp_client_info *client_info = &self->rdp_layer->client_info;\n    /* Clear physical sizes. These are optional and may not be read later */\n    client_info->session_physical_width = 0;\n    client_info->session_physical_height = 0;\n\n    /* TS_UD_CS_CORE required fields */\n    if (!s_check_rem_and_log(s, CS_CORE_MIN_LENGTH,\n                             \"Parsing [MS-RDPBCGR] TS_UD_CS_CORE\"))\n    {\n        return 1;\n    }\n    in_uint32_le(s, version);\n    in_uint16_le(s, client_info->display_sizes.session_width);\n    in_uint16_le(s, client_info->display_sizes.session_height);\n    in_uint16_le(s, colorDepth);\n    switch (colorDepth)\n    {\n        case RNS_UD_COLOR_4BPP:\n            client_info->bpp = 4;\n            break;\n        case RNS_UD_COLOR_8BPP:\n            client_info->bpp = 8;\n            break;\n    }\n    in_uint8s(s, 2); /* SASSequence */\n    in_uint32_le(s, client_info->keylayout);\n    in_uint32_le(s, client_info->build);\n\n    /* clientName\n     *\n     * This should be null-terminated. Allow for the possibility it\n     * isn't by ignoring the last two bytes and treating them as a\n     * terminator anyway */\n    in_utf16_le_fixed_as_utf8(s, (INFO_CLIENT_NAME_BYTES_UTF16 - 2) / 2,\n                              client_info->client_name,\n                              sizeof(client_info->client_name));\n    in_uint8s(s, 2); /* See above */\n    LOG(LOG_LEVEL_INFO, \"Connected client computer name: %s\",\n        client_info->client_name);\n    in_uint32_le(s, client_info->keyboard_type); /* [MS-RDPBCGR] TS_UD_CS_CORE keyboardType */\n    in_uint32_le(s, client_info->keyboard_subtype); /* [MS-RDPBCGR] TS_UD_CS_CORE keyboardSubType */\n    in_uint8s(s, 4); /* keyboardFunctionKey */\n    in_uint8s(s, 64); /* imeFileName */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Required fields> version %08x, desktopWidth %d, \"\n              \"desktopHeight %d, colorDepth %s, SASSequence (ignored), \"\n              \"keyboardLayout 0x%8.8x, clientBuild %d, \"\n              \"clientName %s, keyboardType 0x%8.8x, \"\n              \"keyboardSubType 0x%8.8x, keyboardFunctionKey (ignored), \"\n              \"imeFileName (ignored)\",\n              version,\n              client_info->display_sizes.session_width,\n              client_info->display_sizes.session_height,\n              (colorDepth == RNS_UD_COLOR_4BPP ? \"RNS_UD_COLOR_4BPP\" :\n               colorDepth == RNS_UD_COLOR_8BPP ? \"RNS_UD_COLOR_8BPP\" :\n               \"unknown\"),\n              client_info->keylayout,\n              client_info->build,\n              client_info->client_name,\n              client_info->keyboard_type,\n              client_info->keyboard_subtype);\n\n    /* TS_UD_CS_CORE optional fields */\n    if (!s_check_rem(s, 2))\n    {\n        return 0;\n    }\n    in_uint16_le(s, postBeta2ColorDepth);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> postBeta2ColorDepth %s\",\n              postBeta2ColorDepth == 0xca00 ? \"RNS_UD_COLOR_4BPP\" :\n              postBeta2ColorDepth == 0xca01 ? \"RNS_UD_COLOR_8BPP\" :\n              postBeta2ColorDepth == 0xca02 ? \"RNS_UD_COLOR_16BPP_555\" :\n              postBeta2ColorDepth == 0xca03 ? \"RNS_UD_COLOR_16BPP_565\" :\n              postBeta2ColorDepth == 0xca04 ? \"RNS_UD_COLOR_24BPP\" :\n              \"unknown\");\n\n    switch (postBeta2ColorDepth)\n    {\n        case RNS_UD_COLOR_4BPP:\n            client_info->bpp = 4;\n            break;\n        case RNS_UD_COLOR_8BPP :\n            client_info->bpp = 8;\n            break;\n        case RNS_UD_COLOR_16BPP_555:\n            client_info->bpp = 15;\n            break;\n        case RNS_UD_COLOR_16BPP_565:\n            client_info->bpp = 16;\n            break;\n        case RNS_UD_COLOR_24BPP:\n            client_info->bpp = 24;\n            break;\n    }\n    if (!s_check_rem(s, 2))\n    {\n        return 0;\n    }\n    in_uint8s(s, 2); /* clientProductId */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> clientProductId (ignored)\");\n\n    if (!s_check_rem(s, 4))\n    {\n        return 0;\n    }\n    in_uint8s(s, 4); /* serialNumber */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> serialNumber (ignored)\");\n\n    if (!s_check_rem(s, 2))\n    {\n        return 0;\n    }\n    in_uint16_le(s, highColorDepth);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> highColorDepth %s\",\n              highColorDepth == 0x0004 ? \"HIGH_COLOR_4BPP\" :\n              highColorDepth == 0x0008 ? \"HIGH_COLOR_8BPP\" :\n              highColorDepth == 0x000F ? \"HIGH_COLOR_15BPP\" :\n              highColorDepth == 0x0010 ? \"HIGH_COLOR_16BPP\" :\n              highColorDepth == 0x0018 ? \"HIGH_COLOR_24BPP\" :\n              \"unknown\");\n    client_info->bpp = highColorDepth;\n\n    if (!s_check_rem(s, 2))\n    {\n        return 0;\n    }\n    in_uint16_le(s, supportedColorDepths);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> supportedColorDepths %s\",\n              supportedColorDepths == RNS_UD_24BPP_SUPPORT\n              ? \"RNS_UD_24BPP_SUPPORT\" :\n              supportedColorDepths == RNS_UD_16BPP_SUPPORT\n              ? \"RNS_UD_16BPP_SUPPORT\" :\n              supportedColorDepths == RNS_UD_15BPP_SUPPORT\n              ? \"RNS_UD_15BPP_SUPPORT\" :\n              supportedColorDepths == RNS_UD_32BPP_SUPPORT\n              ? \"RNS_UD_32BPP_SUPPORT\" :\n              \"unknown\");\n\n    if (!s_check_rem(s, 2))\n    {\n        return 0;\n    }\n    in_uint16_le(s, earlyCapabilityFlags);\n    client_info->mcs_early_capability_flags = earlyCapabilityFlags;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> earlyCapabilityFlags 0x%4.4x\",\n              earlyCapabilityFlags);\n    if ((earlyCapabilityFlags & RNS_UD_CS_WANT_32BPP_SESSION)\n            && (supportedColorDepths & RNS_UD_32BPP_SUPPORT))\n    {\n        client_info->bpp = 32;\n    }\n#ifdef XRDP_RFXCODEC\n    if (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL)\n    {\n        if (client_info->bpp < 32)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"client requested gfx protocol with insufficient color depth\");\n        }\n        else if (client_info->max_bpp > 0 && client_info->max_bpp < 32)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Client requested gfx protocol \"\n                \"but the server configuration is limited to %d bpp.\",\n                client_info->max_bpp);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_INFO, \"client supports gfx protocol\");\n            self->rdp_layer->client_info.gfx = 1;\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO, \"client DOES NOT support gfx\");\n    }\n#endif\n    if (!s_check_rem(s, 64))\n    {\n        return 0;\n    }\n    in_uint8s(s, 64); /* clientDigProductId */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> clientDigProductId (ignored)\");\n\n    if (!s_check_rem(s, 1))\n    {\n        return 0;\n    }\n    in_uint8(s, client_info->mcs_connection_type); /* connectionType */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> connectionType 0x%2.2x\",\n              client_info->mcs_connection_type);\n\n    if (!s_check_rem(s, 1))\n    {\n        return 0;\n    }\n    in_uint8s(s, 1); /* pad1octet */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> pad1octet (ignored)\");\n\n    if (!s_check_rem(s, 4))\n    {\n        return 0;\n    }\n    in_uint8s(s, 4); /* serverSelectedProtocol */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> serverSelectedProtocol (ignored)\");\n\n    /*\n     * Non-zero values for the desktop physical width and height values\n     * are only sent if the client has a single monitor. For multiple\n     * monitors, the physical size of each monitor is sent in the\n     * TS_UD_CS_MONITOR_EX PDU */\n    if (!s_check_rem(s, 4))\n    {\n        return 0;\n    }\n    in_uint32_le(s, client_info->session_physical_width);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> desktopPhysicalWidth %u\",\n              client_info->session_physical_width);\n\n    if (!s_check_rem(s, 4))\n    {\n        client_info->session_physical_width = 0;\n        return 0;\n    }\n    in_uint32_le(s, client_info->session_physical_height);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> desktopPhysicalHeight %u\",\n              client_info->session_physical_height);\n\n    /* MS-RDPBCGR 2.2.1.3.2 */\n    if (client_info->session_physical_width < 10 ||\n            client_info->session_physical_width > 10000 ||\n            client_info->session_physical_height < 10 ||\n            client_info->session_physical_height > 10000)\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"Physical desktop dimensions (%ux%u) are invalid\",\n            client_info->session_physical_width,\n            client_info->session_physical_height);\n        client_info->session_physical_width = 0;\n        client_info->session_physical_height = 0;\n    }\n    if (!s_check_rem(s, 2))\n    {\n        return 0;\n    }\n    in_uint8s(s, 2); /* reserved */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_CORE \"\n              \"<Optional Field> desktopOrientation (ignored)\");\n\n    return 0;\n#undef CS_CORE_MIN_LENGTH\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_UD_CS_SEC message */\nstatic int\nxrdp_sec_process_mcs_data_CS_SECURITY(struct xrdp_sec *self, struct stream *s)\n{\n    int crypt_method;\n    int found;\n\n    in_uint32_le(s, crypt_method);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_SEC \"\n              \"encryptionMethods 0x%8.8x, extEncryptionMethods (ignored)\",\n              crypt_method);\n    if (crypt_method & CRYPT_METHOD_40BIT)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Client supports 40 bit encryption\");\n    }\n    if (crypt_method & CRYPT_METHOD_128BIT)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Client supports 128 bit encryption\");\n    }\n    if (crypt_method & CRYPT_METHOD_56BIT)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Client supports 56 bit encryption\");\n    }\n    if (crypt_method & CRYPT_METHOD_FIPS)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Client supports fips encryption\");\n    }\n    found = 0;\n    if ((found == 0) &&\n            (self->mcs_layer->iso_layer->selectedProtocol == PROTOCOL_SSL))\n    {\n        LOG(LOG_LEVEL_DEBUG,\n            \"The connection is using TLS, skipping RDP crypto negotiation\");\n        found = 1;\n    }\n    if ((found == 0) &&\n            (self->crypt_method & CRYPT_METHOD_FIPS) &&\n            (self->crypt_level == CRYPT_LEVEL_FIPS))\n    {\n        if (crypt_method & CRYPT_METHOD_FIPS)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"Client and server both support fips encryption, \"\n                \"using RDP fips encryption.\");\n            self->crypt_method = CRYPT_METHOD_FIPS;\n            self->crypt_level = CRYPT_LEVEL_FIPS;\n            found = 1;\n        }\n    }\n    if ((found == 0) &&\n            (self->crypt_method & CRYPT_METHOD_128BIT) &&\n            (self->crypt_level == CRYPT_LEVEL_HIGH))\n    {\n        if (crypt_method & CRYPT_METHOD_128BIT)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"Client and server both support high encryption, \"\n                \"using RDP 128-bit encryption.\");\n            self->crypt_method = CRYPT_METHOD_128BIT;\n            self->crypt_level = CRYPT_LEVEL_HIGH;\n            found = 1;\n        }\n    }\n    /* TODO: figure out why both \"COMPATIBLE\" and \"LOW\" crypto level both use\n        40-bit encryption, and why there is no cypto method for 56-bit\n        encryption even though there is code for checking for 56-bit\n        encryption */\n    if ((found == 0) &&\n            (self->crypt_method & CRYPT_METHOD_40BIT) &&\n            (self->crypt_level == CRYPT_LEVEL_CLIENT_COMPATIBLE))\n    {\n        if (crypt_method & CRYPT_METHOD_40BIT)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"Client and server both support medium encryption, \"\n                \"using RDP 40-bit encryption.\");\n            self->crypt_method = CRYPT_METHOD_40BIT;\n            self->crypt_level = CRYPT_LEVEL_CLIENT_COMPATIBLE;\n            found = 1;\n        }\n    }\n    if ((found == 0) &&\n            (self->crypt_method & CRYPT_METHOD_40BIT) &&\n            (self->crypt_level == CRYPT_LEVEL_LOW))\n    {\n        if (crypt_method & CRYPT_METHOD_40BIT)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"Client and server both support low encryption, \"\n                \"using RDP 40-bit encryption.\");\n            self->crypt_method = CRYPT_METHOD_40BIT;\n            self->crypt_level = CRYPT_LEVEL_LOW;\n            found = 1;\n        }\n    }\n    if ((found == 0) &&\n            (self->crypt_level == CRYPT_LEVEL_NONE))\n    {\n        if (crypt_method == CRYPT_METHOD_NONE)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"Client and server both support no encryption, \"\n                \"RDP encryption is disabled.\");\n            self->crypt_method = CRYPT_METHOD_NONE;\n            self->crypt_level = CRYPT_LEVEL_NONE;\n            found = 1;\n        }\n    }\n    if (found == 0)\n    {\n        /* TODO: figure out why failing to find a shared encryption level\n            does not return an error? */\n        /* TODO: does the connection fail now or is the default server\n            encryption used? */\n        LOG(LOG_LEVEL_WARNING,\n            \"Client and server do not both support the same encryption.\");\n        //        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_UD_CS_NET message.\n   This adds the mcs channels in the list of channels to be used when\n   creating the server mcs data */\nstatic int\nxrdp_sec_process_mcs_data_channels(struct xrdp_sec *self, struct stream *s)\n{\n    int num_channels;\n    int index;\n    struct xrdp_client_info *client_info;\n    struct mcs_channel_item *channel_item;\n    int next_mcs_channel_id;\n\n    client_info = &(self->rdp_layer->client_info);\n    /* this is an option set in xrdp.ini */\n    if (client_info->channels_allowed == 0) /* are channels on? */\n    {\n        LOG(LOG_LEVEL_DEBUG, \"All channels are disabled by configuration\");\n        return 0;\n    }\n    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPBCGR] TS_UD_CS_NET\"))\n    {\n        return 1;\n    }\n    in_uint32_le(s, num_channels);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"Received [MS-RDPBCGR] TS_UD_CS_NET \"\n              \"channelCount %d\", num_channels);\n    if (num_channels > MAX_STATIC_CHANNELS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"[MS-RDPBCGR] Protocol error: too many channels requested. \"\n            \"max %d, received %d\", MAX_STATIC_CHANNELS, num_channels);\n        return 1;\n    }\n\n    /* GOTCHA: When adding a channel the MCS channel ID is set to\n     * MCS_GLOBAL_CHANNEL + (index + 1). This is assumed by\n     * xrdp_channel_process(), when mapping an incoming PDU into an\n     * entry in this array */\n    next_mcs_channel_id = MCS_GLOBAL_CHANNEL + 1;\n\n    for (index = 0; index < num_channels; index++)\n    {\n        channel_item = g_new0(struct mcs_channel_item, 1);\n        if (!s_check_rem_and_log(s, 12, \"Parsing [MS-RDPBCGR] TS_UD_CS_NET.CHANNEL_DEF\"))\n        {\n            g_free(channel_item);\n            return 1;\n        }\n\n        in_uint8a(s, channel_item->name, CHANNEL_NAME_LEN + 1);\n        // The channel name *should* be null-terminated. Add a back-stop\n        // terminator in case it isn't.\n        channel_item->name[CHANNEL_NAME_LEN] = '\\0';\n        in_uint32_le(s, channel_item->flags);\n\n        channel_item->chanid = next_mcs_channel_id++;\n        list_add_item(self->mcs_layer->channel_list,\n                      (intptr_t) channel_item);\n        LOG(LOG_LEVEL_DEBUG,\n            \"Adding channel: name %s, channel id %d, flags 0x%8.8x\",\n            channel_item->name, channel_item->chanid, channel_item->flags);\n    }\n\n    /* Set the user channel as well */\n    self->mcs_layer->chanid = next_mcs_channel_id++;\n    self->mcs_layer->userid = self->mcs_layer->chanid - MCS_USERCHANNEL_BASE;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"MCS user is %d, channel id is %d\",\n              self->mcs_layer->userid, self->mcs_layer->chanid);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_UD_CS_MONITOR message.\n   reads the client monitors data */\nint\nxrdp_sec_process_mcs_data_monitors(struct xrdp_sec *self, struct stream *s)\n{\n    int flags;\n    int error = 0;\n    struct xrdp_client_info *client_info = &(self->rdp_layer->client_info);\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_sec_process_mcs_data_monitors:\");\n\n    /* this is an option set in xrdp.ini */\n    if (client_info->multimon != 1) /* are multi-monitors allowed ? */\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"xrdp_sec_process_mcs_data_monitors:\"\n            \" Multi-monitor is disabled by server config\");\n        return 0;\n    }\n    if (!s_check_rem_and_log(s, 4,\n                             \"xrdp_sec_process_mcs_data_monitors:\"\n                             \" Parsing [MS-RDPBCGR] TS_UD_CS_MONITOR\"))\n    {\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n    in_uint32_le(s, flags); /* flags */\n\n    //verify flags - must be 0x0\n    if (flags != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_sec_process_mcs_data_monitors: [MS-RDPBCGR]\"\n            \" Protocol error: TS_UD_CS_MONITOR flags MUST be zero,\"\n            \" received: 0x%8.8x\", flags);\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n\n    struct display_size_description *description =\n        (struct display_size_description *)\n        g_malloc(sizeof(struct display_size_description), 1);\n\n    error = libxrdp_process_monitor_stream(s, description, 0);\n    if (error == 0)\n    {\n        client_info->display_sizes.monitorCount = description->monitorCount;\n\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_sec_process_mcs_data_monitors:\"\n                  \" Received [MS-RDPBCGR] TS_UD_CS_MONITOR\"\n                  \" flags 0x%8.8x, monitorCount %d\",\n                  flags, description->monitorCount);\n\n        client_info->display_sizes.session_width = description->session_width;\n        client_info->display_sizes.session_height = description->session_height;\n        g_memcpy(client_info->display_sizes.minfo, description->minfo, sizeof(struct monitor_info) * CLIENT_MONITOR_DATA_MAXIMUM_MONITORS);\n        g_memcpy(client_info->display_sizes.minfo_wm, description->minfo_wm, sizeof(struct monitor_info) * CLIENT_MONITOR_DATA_MAXIMUM_MONITORS);\n    }\n\n    g_free(description);\n\n    return error;\n}\n\n/*****************************************************************************/\n/* Process a [MS-RDPBCGR] TS_UD_CS_MONITOR_EX message.\n   reads the client monitor's extended data */\nstatic int\nxrdp_sec_process_mcs_data_monitors_ex(struct xrdp_sec *self, struct stream *s)\n{\n    int flags;\n    struct xrdp_client_info *client_info = &(self->rdp_layer->client_info);\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_sec_process_mcs_data_monitors_ex:\");\n\n    /* this is an option set in xrdp.ini */\n    if (client_info->multimon != 1) /* are multi-monitors allowed ? */\n    {\n        /* This should already be logged in\n           xrdp_sec_process_mcs_data_monitors() */\n        return 0;\n    }\n    if (!s_check_rem_and_log(s, 4,\n                             \"xrdp_sec_process_mcs_data_monitors_ex:\"\n                             \" Parsing [MS-RDPBCGR] TS_UD_CS_MONITOR_EX\"))\n    {\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n    in_uint32_le(s, flags); /* flags */\n\n    //verify flags - must be 0x0\n    if (flags != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_sec_process_mcs_data_monitors_ex: [MS-RDPBCGR]\"\n            \" Protocol error: TS_UD_CS_MONITOR_EX flags MUST be zero,\"\n            \" received: 0x%8.8x\", flags);\n        return SEC_PROCESS_MONITORS_ERR;\n    }\n\n    return libxrdp_process_monitor_ex_stream(s, &client_info->display_sizes);\n}\n\n/*****************************************************************************/\n/* Process a Client MCS Connect Initial PDU with GCC Conference Create Request.\n   process client mcs data, we need some things in here to create the server\n   mcs data */\nint\nxrdp_sec_process_mcs_data(struct xrdp_sec *self)\n{\n    struct stream *s = (struct stream *)NULL;\n    char *hold_p = (char *)NULL;\n    int tag = 0;\n    int size = 0;\n    struct xrdp_client_info *client_info = &self->rdp_layer->client_info;\n\n    s = &(self->client_mcs_data);\n    /* set p to beginning */\n    s->p = s->data;\n    /* skip header */\n    if (!s_check_rem_and_log(s, 23, \"Parsing [ITU T.124] ConferenceCreateRequest\"))\n    {\n        return 1;\n    }\n    in_uint8s(s, 23); /* skip [ITU T.124] ConferenceCreateRequest fields until userData */\n\n    while (s_check_rem(s, 4))\n    {\n        hold_p = s->p;\n        in_uint16_le(s, tag);\n        in_uint16_le(s, size);\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"Received header [MS-RDPBCGR] TS_UD_HEADER \"\n                  \"type 0x%4.4x, length %d\", tag, size);\n\n        if (size < 4)\n        {\n            LOG(LOG_LEVEL_WARNING, \"[MS-RDPBCGR] Protocol error: Invalid TS_UD_HEADER length value. \"\n                \"expected >= 4, actual %d\", size);\n            break;\n        }\n        if (!s_check_rem_and_log(s, size - 4,\n                                 \"Parsing [MS-RDPBCGR] GCC Conference Create Request client data field\"))\n        {\n            break;\n        }\n\n        switch (tag)\n        {\n            case SEC_TAG_CLI_INFO:     /* CS_CORE           0xC001 */\n                if (xrdp_sec_process_mcs_data_CS_CORE(self, s) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Processing [MS-RDPBCGR] TS_UD_CS_CORE failed\");\n                    return 1;\n                }\n                break;\n            case SEC_TAG_CLI_CRYPT:    /* CS_SECURITY       0xC002 */\n                if (xrdp_sec_process_mcs_data_CS_SECURITY(self, s) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Processing [MS-RDPBCGR] TS_UD_CS_SEC failed\");\n                    return 1;\n                }\n                break;\n            case SEC_TAG_CLI_CHANNELS: /* CS_NET            0xC003 */\n                if (xrdp_sec_process_mcs_data_channels(self, s) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Processing [MS-RDPBCGR] TS_UD_CS_NET failed\");\n                    return 1;\n                }\n                break;\n            case SEC_TAG_CLI_4:        /* CS_CLUSTER        0xC004 */\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"Received [MS-RDPBCGR] TS_UD_CS_CLUSTER - no-op\");\n                break;\n            case SEC_TAG_CLI_MONITOR:  /* CS_MONITOR        0xC005 */\n                if (xrdp_sec_process_mcs_data_monitors(self, s) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Processing [MS-RDPBCGR] TS_UD_CS_MONITOR failed\");\n                    return 1;\n                }\n                break;\n            case SEC_TAG_CLI_MONITOR_EX:  /* CS_MONITOR_EX     0xC008 */\n                if (xrdp_sec_process_mcs_data_monitors_ex(self, s) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Processing [MS-RDPBCGR] TS_UD_CS_MONITOR_EX failed\");\n                    return 1;\n                }\n                break;\n            /* CS_MCS_MSGCHANNEL 0xC006\n               CS_MULTITRANSPORT 0xC00A\n               SC_CORE           0x0C01\n               SC_SECURITY       0x0C02\n               SC_NET            0x0C03\n               SC_MCS_MSGCHANNEL 0x0C04\n               SC_MULTITRANSPORT 0x0C08 */\n            default:\n                LOG(LOG_LEVEL_WARNING,\n                    \"Received [MS-RDPBCGR] TS_UD_HEADER type 0x%4.4x \"\n                    \"is unknown (ignored)\", tag);\n                break;\n        }\n\n        s->p = hold_p + size;\n    }\n\n    if (client_info->max_bpp > 0)\n    {\n        if (client_info->bpp > client_info->max_bpp)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Client requested %d bpp color depth, \"\n                \"but the server configuration is limited to %d bpp. \"\n                \"Downgrading the color depth to %d bits-per-pixel.\",\n                client_info->bpp,\n                client_info->max_bpp,\n                client_info->max_bpp);\n            client_info->bpp = client_info->max_bpp;\n        }\n    }\n\n    /* set p to beginning */\n    s->p = s->data;\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_sec_init_rdp_security(struct xrdp_sec *self)\n{\n    switch (self->rdp_layer->client_info.crypt_level)\n    {\n        case 0: /* none */\n            self->crypt_method = CRYPT_METHOD_NONE;\n            self->crypt_level = CRYPT_LEVEL_NONE;\n            break;\n        case 1: /* low */\n            self->crypt_method = CRYPT_METHOD_40BIT;\n            self->crypt_level = CRYPT_LEVEL_LOW;\n            break;\n        case 2: /* medium */\n            self->crypt_method = CRYPT_METHOD_40BIT;\n            self->crypt_level = CRYPT_LEVEL_CLIENT_COMPATIBLE;\n            break;\n        case 3: /* high */\n            self->crypt_method = CRYPT_METHOD_128BIT;\n            self->crypt_level = CRYPT_LEVEL_HIGH;\n            break;\n        case 4: /* fips */\n            self->crypt_method = CRYPT_METHOD_FIPS;\n            self->crypt_level = CRYPT_LEVEL_FIPS;\n            break;\n        default:\n            LOG_DEVEL(LOG_LEVEL_WARNING, \"Fatal : Illegal crypt_level %d\",\n                      self->rdp_layer->client_info.crypt_level);\n            break ;\n    }\n\n    if (self->decrypt_rc4_info != NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_WARNING,\n                  \"xrdp_sec_init_rdp_security: decrypt_rc4_info already created !!!\");\n    }\n    else\n    {\n        self->decrypt_rc4_info = ssl_rc4_info_create();\n    }\n\n    if (self->encrypt_rc4_info != NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_WARNING,\n                  \"xrdp_sec_init_rdp_security: encrypt_rc4_info already created !!!\");\n    }\n    else\n    {\n        self->encrypt_rc4_info = ssl_rc4_info_create();\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_sec_incoming(struct xrdp_sec *self)\n{\n    struct list *items = NULL;\n    struct list *values = NULL;\n    struct xrdp_iso *iso;\n    int index;\n    char *item = NULL;\n    char *value = NULL;\n    char key_file[256];\n\n    iso = self->mcs_layer->iso_layer;\n\n    /* negotiate security layer */\n    if (xrdp_iso_incoming(iso) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_sec_incoming: xrdp_iso_incoming failed\");\n        return 1;\n    }\n\n    /* initialize selected security layer */\n    if (self->rdp_layer->client_info.vmconnect && iso->selectedProtocol > PROTOCOL_RDP)\n    {\n        /* Security handled by host: do nothing. */\n    }\n    else if (iso->selectedProtocol > PROTOCOL_RDP)\n    {\n        /* init tls security */\n\n        if (trans_set_tls_mode(self->mcs_layer->iso_layer->trans,\n                               self->rdp_layer->client_info.key_file,\n                               self->rdp_layer->client_info.certificate,\n                               self->rdp_layer->client_info.ssl_protocols,\n                               self->rdp_layer->client_info.tls_ciphers) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_sec_incoming: trans_set_tls_mode failed\");\n            return 1;\n        }\n\n        LOG(LOG_LEVEL_DEBUG, \"Using TLS security, and \"\n            \"setting RDP security crypto to LEVEL_NONE and METHOD_NONE\");\n        self->crypt_level = CRYPT_LEVEL_NONE;\n        self->crypt_method = CRYPT_METHOD_NONE;\n        self->rsa_key_bytes = 0;\n\n    }\n    else\n    {\n        /* init rdp security */\n        if (g_fips_mode_enabled())\n        {\n            /* We can't generate rsakeys.ini in FIPS mode. Nor should we\n             * try to use it */\n            LOG(LOG_LEVEL_ERROR, \"xrdp_sec_incoming: \"\n                \"Classic RDP security unavailable in FIPS mode\");\n            return 1;\n        }\n\n        if (xrdp_sec_init_rdp_security(self) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_sec_incoming: xrdp_sec_init_rdp_security failed\");\n            return 1;\n        }\n        if (self->crypt_method != CRYPT_METHOD_NONE)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"Using RDP security, and \"\n                \"reading the server configuration\");\n\n            g_memset(key_file, 0, sizeof(char) * 256);\n            g_random(self->server_random, 32);\n            items = list_create();\n            items->auto_free = 1;\n            values = list_create();\n            values->auto_free = 1;\n            g_snprintf(key_file, 255, \"%s/rsakeys.ini\", XRDP_CFG_PATH);\n\n            if (file_by_name_read_section(key_file, \"keys\", items, values) != 0)\n            {\n                /* this is a show stopper */\n                LOG(LOG_LEVEL_ERROR, \"XRDP cannot read file: %s \"\n                    \"(check permissions)\", key_file);\n                list_delete(items);\n                list_delete(values);\n                return 1;\n            }\n\n            for (index = 0; index < items->count; index++)\n            {\n                item = (char *)list_get_item(items, index);\n                value = (char *)list_get_item(values, index);\n\n                if (g_strcasecmp(item, \"pub_exp\") == 0)\n                {\n                    hex_str_to_bin(value, self->pub_exp, 4);\n                }\n                else if (g_strcasecmp(item, \"pub_mod\") == 0)\n                {\n                    self->rsa_key_bytes = (g_strlen(value) + 1) / 5;\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"Server config: pub_mod bytes %d\",\n                              self->rsa_key_bytes);\n                    hex_str_to_bin(value, self->pub_mod, self->rsa_key_bytes);\n                }\n                else if (g_strcasecmp(item, \"pub_sig\") == 0)\n                {\n                    hex_str_to_bin(value, self->pub_sig, 64);\n                }\n                else if (g_strcasecmp(item, \"pri_exp\") == 0)\n                {\n                    self->rsa_key_bytes = (g_strlen(value) + 1) / 5;\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"Server config: pri_exp %d\",\n                              self->rsa_key_bytes);\n                    hex_str_to_bin(value, self->pri_exp, self->rsa_key_bytes);\n                }\n            }\n\n            if (self->rsa_key_bytes <= 64)\n            {\n                LOG(LOG_LEVEL_WARNING, \"warning, RSA key len 512 \"\n                    \"bits or less, consider creating a 2048 bit key\");\n            }\n\n            list_delete(items);\n            list_delete(values);\n        }\n    }\n\n    /* negotiate mcs layer */\n    if (xrdp_mcs_incoming(self->mcs_layer) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_sec_incoming: xrdp_mcs_incoming failed\");\n        return 1;\n    }\n\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"client mcs data received\",\n                      self->client_mcs_data.data,\n                      (int)(self->client_mcs_data.end - self->client_mcs_data.data));\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"server mcs data sent\",\n                      self->server_mcs_data.data,\n                      (int)(self->server_mcs_data.end - self->server_mcs_data.data));\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_sec_disconnect(struct xrdp_sec *self)\n{\n    int rv;\n\n    rv = xrdp_mcs_disconnect(self->mcs_layer);\n    return rv;\n}\n"
  },
  {
    "path": "libxrdp/xrdp_surface.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2013\n * Copyright (C) Kevin Zhou 2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"libxrdp.h\"\n#include <freerdp/codec/rfx.h>\n\n/*****************************************************************************/\nstruct xrdp_surface *\nxrdp_surface_create(struct xrdp_session *session, struct xrdp_fastpath *fastpath)\n{\n    struct xrdp_surface *self;\n\n    self = (struct xrdp_surface *)g_malloc(sizeof(struct xrdp_surface), 1);\n    self->session = session;\n    self->fastpath = fastpath;\n    self->rfx_context = rfx_context_new();\n    self->s = stream_new(16384);\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_surface_delete(struct xrdp_surface *self)\n{\n    STREAM *s;\n    RFX_CONTEXT *rfx_context;\n\n    if (self == 0)\n    {\n        return;\n    }\n\n    s = (STREAM *)(self->s);\n    rfx_context = (RFX_CONTEXT *)(self->rfx_context);\n    free_stream(self->out_s);\n    stream_free(s);\n    rfx_context_free(rfx_context);\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_surface_reset(struct xrdp_surface *self)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_surface_init(struct xrdp_surface *self)\n{\n    int width;\n    int height;\n    RFX_CONTEXT *rfx_context;\n\n    rfx_context = (RFX_CONTEXT *)(self->rfx_context);\n    width = self->session->client_info->width;\n    height = self->session->client_info->height;\n\n    rfx_context->mode = self->session->client_info->rfx_entropy;\n    rfx_context->width = width;\n    rfx_context->height = height;\n\n    make_stream(self->out_s);\n    init_stream(self->out_s, 2 * 3 * width * height + 22);\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_surface_send_surface_bits(struct xrdp_surface *self, int bpp, char *data,\n                               int x, int y, int cx, int cy)\n{\n    RFX_RECT rect;\n    int Bpp;\n    int codecId;\n    uint32 bitmapDataLength;\n    STREAM *s;\n    RFX_CONTEXT *rfx_context;\n\n    s = (STREAM *)(self->s);\n    rfx_context = (RFX_CONTEXT *)(self->rfx_context);\n\n    if ((bpp == 24) || (bpp == 32))\n    {\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"bpp = %d is not supported\\n\", bpp);\n        return 1;\n    }\n\n    Bpp = 4;\n\n    rect.x = 0;\n    rect.y = 0;\n    rect.width  = cx;\n    rect.height = cy;\n\n    init_stream(self->out_s, 0);\n\n    stream_set_pos(s, 0);\n    rfx_compose_message(rfx_context, s, &rect, 1, data, cx, cy, Bpp * cx);\n\n    codecId = self->session->client_info->rfx_codecId;\n    /* surface_bits_command */\n    out_uint16_le(self->out_s, CMDTYPE_STREAM_SURFACE_BITS); /* cmdType */\n    out_uint16_le(self->out_s, x);                           /* destLeft */\n    out_uint16_le(self->out_s, y);                           /* destTop */\n    out_uint16_le(self->out_s, x + cx);                      /* destRight */\n    out_uint16_le(self->out_s, y + cy);                      /* destBottom */\n    out_uint8(self->out_s, 32);                              /* bpp */\n    out_uint8(self->out_s, 0);                               /* reserved1 */\n    out_uint8(self->out_s, 0);                               /* reserved2 */\n    out_uint8(self->out_s, codecId);                         /* codecId */\n    out_uint16_le(self->out_s, cx);                          /* width */\n    out_uint16_le(self->out_s, cy);                          /* height */\n    bitmapDataLength = stream_get_length(s);\n    out_uint32_le(self->out_s, bitmapDataLength); /* bitmapDataLength */\n\n    /* rfx bit stream */\n    out_uint8p(self->out_s, s->data, bitmapDataLength);\n\n    s_mark_end(self->out_s);\n    return xrdp_fastpath_send_update_pdu(self->fastpath,\n                                         FASTPATH_UPDATETYPE_SURFCMDS,\n                                         self->out_s);\n}\n\n/*****************************************************************************/\nint\nxrdp_surface_send_frame_marker(struct xrdp_surface *self,\n                               uint16 frameAction, uint32 frameId)\n{\n    init_stream(self->out_s, 0);\n    out_uint16_le(self->out_s, CMDTYPE_FRAME_MARKER);\n    out_uint16_le(self->out_s, frameAction);\n    out_uint32_le(self->out_s, frameId);\n    s_mark_end(self->out_s);\n    return xrdp_fastpath_send_update_pdu(self->fastpath,\n                                         FASTPATH_UPDATETYPE_SURFCMDS,\n                                         self->out_s);\n}\n"
  },
  {
    "path": "m4/.gitignore",
    "content": "libtool.m4\nlt*.m4\n"
  },
  {
    "path": "m4/ax_append_compile_flags.m4",
    "content": "# ===========================================================================\n#  http://www.gnu.org/software/autoconf-archive/ax_append_compile_flags.html\n# ===========================================================================\n#\n# SYNOPSIS\n#\n#   AX_APPEND_COMPILE_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS], [INPUT])\n#\n# DESCRIPTION\n#\n#   For every FLAG1, FLAG2 it is checked whether the compiler works with the\n#   flag.  If it does, the flag is added FLAGS-VARIABLE\n#\n#   If FLAGS-VARIABLE is not specified, the current language's flags (e.g.\n#   CFLAGS) is used.  During the check the flag is always added to the\n#   current language's flags.\n#\n#   If EXTRA-FLAGS is defined, it is added to the current language's default\n#   flags (e.g. CFLAGS) when the check is done.  The check is thus made with\n#   the flags: \"CFLAGS EXTRA-FLAGS FLAG\".  This can for example be used to\n#   force the compiler to issue an error when a bad flag is given.\n#\n#   INPUT gives an alternative input source to AC_COMPILE_IFELSE.\n#\n#   NOTE: This macro depends on the AX_APPEND_FLAG and\n#   AX_CHECK_COMPILE_FLAG. Please keep this macro in sync with\n#   AX_APPEND_LINK_FLAGS.\n#\n# LICENSE\n#\n#   Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>\n#\n#   This program is free software: you can redistribute it and/or modify it\n#   under the terms of the GNU General Public License as published by the\n#   Free Software Foundation, either version 3 of the License, or (at your\n#   option) any later version.\n#\n#   This program is distributed in the hope that it will be useful, but\n#   WITHOUT ANY WARRANTY; without even the implied warranty of\n#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\n#   Public License for more details.\n#\n#   You should have received a copy of the GNU General Public License along\n#   with this program. If not, see <http://www.gnu.org/licenses/>.\n#\n#   As a special exception, the respective Autoconf Macro's copyright owner\n#   gives unlimited permission to copy, distribute and modify the configure\n#   scripts that are the output of Autoconf when processing the Macro. You\n#   need not follow the terms of the GNU General Public License when using\n#   or distributing such scripts, even though portions of the text of the\n#   Macro appear in them. The GNU General Public License (GPL) does govern\n#   all other use of the material that constitutes the Autoconf Macro.\n#\n#   This special exception to the GPL applies to versions of the Autoconf\n#   Macro released by the Autoconf Archive. When you make and distribute a\n#   modified version of the Autoconf Macro, you may extend this special\n#   exception to the GPL to apply to your modified version as well.\n\n#serial 5\n\nAC_DEFUN([AX_APPEND_COMPILE_FLAGS],\n[AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])\nAX_REQUIRE_DEFINED([AX_APPEND_FLAG])\nfor flag in $1; do\n  AX_CHECK_COMPILE_FLAG([$flag], [AX_APPEND_FLAG([$flag], [$2])], [], [$3], [$4])\ndone\n])dnl AX_APPEND_COMPILE_FLAGS\n"
  },
  {
    "path": "m4/ax_append_flag.m4",
    "content": "# ===========================================================================\n#      http://www.gnu.org/software/autoconf-archive/ax_append_flag.html\n# ===========================================================================\n#\n# SYNOPSIS\n#\n#   AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE])\n#\n# DESCRIPTION\n#\n#   FLAG is appended to the FLAGS-VARIABLE shell variable, with a space\n#   added in between.\n#\n#   If FLAGS-VARIABLE is not specified, the current language's flags (e.g.\n#   CFLAGS) is used.  FLAGS-VARIABLE is not changed if it already contains\n#   FLAG.  If FLAGS-VARIABLE is unset in the shell, it is set to exactly\n#   FLAG.\n#\n#   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION.\n#\n# LICENSE\n#\n#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>\n#   Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>\n#\n#   This program is free software: you can redistribute it and/or modify it\n#   under the terms of the GNU General Public License as published by the\n#   Free Software Foundation, either version 3 of the License, or (at your\n#   option) any later version.\n#\n#   This program is distributed in the hope that it will be useful, but\n#   WITHOUT ANY WARRANTY; without even the implied warranty of\n#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\n#   Public License for more details.\n#\n#   You should have received a copy of the GNU General Public License along\n#   with this program. If not, see <http://www.gnu.org/licenses/>.\n#\n#   As a special exception, the respective Autoconf Macro's copyright owner\n#   gives unlimited permission to copy, distribute and modify the configure\n#   scripts that are the output of Autoconf when processing the Macro. You\n#   need not follow the terms of the GNU General Public License when using\n#   or distributing such scripts, even though portions of the text of the\n#   Macro appear in them. The GNU General Public License (GPL) does govern\n#   all other use of the material that constitutes the Autoconf Macro.\n#\n#   This special exception to the GPL applies to versions of the Autoconf\n#   Macro released by the Autoconf Archive. When you make and distribute a\n#   modified version of the Autoconf Macro, you may extend this special\n#   exception to the GPL to apply to your modified version as well.\n\n#serial 6\n\nAC_DEFUN([AX_APPEND_FLAG],\n[dnl\nAC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF\nAS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])])\nAS_VAR_SET_IF(FLAGS,[\n  AS_CASE([\" AS_VAR_GET(FLAGS) \"],\n    [*\" $1 \"*], [AC_RUN_LOG([: FLAGS already contains $1])],\n    [\n     AS_VAR_APPEND(FLAGS,[\" $1\"])\n     AC_RUN_LOG([: FLAGS=\"$FLAGS\"])\n    ])\n  ],\n  [\n  AS_VAR_SET(FLAGS,[$1])\n  AC_RUN_LOG([: FLAGS=\"$FLAGS\"])\n  ])\nAS_VAR_POPDEF([FLAGS])dnl\n])dnl AX_APPEND_FLAG\n"
  },
  {
    "path": "m4/ax_cflags_warn_all.m4",
    "content": "# ===========================================================================\n#    http://www.gnu.org/software/autoconf-archive/ax_cflags_warn_all.html\n# ===========================================================================\n#\n# SYNOPSIS\n#\n#   AX_CFLAGS_WARN_ALL   [(shellvar [,default, [A/NA]])]\n#   AX_CXXFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]\n#   AX_FCFLAGS_WARN_ALL  [(shellvar [,default, [A/NA]])]\n#\n# DESCRIPTION\n#\n#   Try to find a compiler option that enables most reasonable warnings.\n#\n#   For the GNU compiler it will be -Wall (and -ansi -pedantic) The result\n#   is added to the shellvar being CFLAGS, CXXFLAGS, or FCFLAGS by default.\n#\n#   Currently this macro knows about the GCC, Solaris, Digital Unix, AIX,\n#   HP-UX, IRIX, NEC SX-5 (Super-UX 10), Cray J90 (Unicos 10.0.0.8), and\n#   Intel compilers.  For a given compiler, the Fortran flags are much more\n#   experimental than their C equivalents.\n#\n#    - $1 shell-variable-to-add-to : CFLAGS, CXXFLAGS, or FCFLAGS\n#    - $2 add-value-if-not-found : nothing\n#    - $3 action-if-found : add value to shellvariable\n#    - $4 action-if-not-found : nothing\n#\n#   NOTE: These macros depend on AX_APPEND_FLAG.\n#\n# LICENSE\n#\n#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>\n#   Copyright (c) 2010 Rhys Ulerich <rhys.ulerich@gmail.com>\n#\n#   This program is free software; you can redistribute it and/or modify it\n#   under the terms of the GNU General Public License as published by the\n#   Free Software Foundation; either version 3 of the License, or (at your\n#   option) any later version.\n#\n#   This program is distributed in the hope that it will be useful, but\n#   WITHOUT ANY WARRANTY; without even the implied warranty of\n#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\n#   Public License for more details.\n#\n#   You should have received a copy of the GNU General Public License along\n#   with this program. If not, see <http://www.gnu.org/licenses/>.\n#\n#   As a special exception, the respective Autoconf Macro's copyright owner\n#   gives unlimited permission to copy, distribute and modify the configure\n#   scripts that are the output of Autoconf when processing the Macro. You\n#   need not follow the terms of the GNU General Public License when using\n#   or distributing such scripts, even though portions of the text of the\n#   Macro appear in them. The GNU General Public License (GPL) does govern\n#   all other use of the material that constitutes the Autoconf Macro.\n#\n#   This special exception to the GPL applies to versions of the Autoconf\n#   Macro released by the Autoconf Archive. When you make and distribute a\n#   modified version of the Autoconf Macro, you may extend this special\n#   exception to the GPL to apply to your modified version as well.\n\n#serial 15\n\nAC_DEFUN([AX_FLAGS_WARN_ALL],[dnl\nAS_VAR_PUSHDEF([FLAGS],[_AC_LANG_PREFIX[]FLAGS])dnl\nAS_VAR_PUSHDEF([VAR],[ac_cv_[]_AC_LANG_ABBREV[]flags_warn_all])dnl\nAC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],\nVAR,[VAR=\"no, unknown\"\nac_save_[]FLAGS=\"$[]FLAGS\"\nfor ac_arg dnl\nin \"-warn all  % -warn all\"   dnl Intel\n   \"-pedantic  % -Wall\"       dnl GCC\n   \"-xstrconst % -v\"          dnl Solaris C\n   \"-std1      % -verbose -w0 -warnprotos\" dnl Digital Unix\n   \"-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd\" dnl AIX\n   \"-ansi -ansiE % -fullwarn\" dnl IRIX\n   \"+ESlit     % +w1\"         dnl HP-UX C\n   \"-Xc        % -pvctl[,]fullmsg\" dnl NEC SX-5 (Super-UX 10)\n   \"-h conform % -h msglevel 2\" dnl Cray C (Unicos)\n   #\ndo FLAGS=\"$ac_save_[]FLAGS \"`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`\n   AC_COMPILE_IFELSE([AC_LANG_PROGRAM],\n                     [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])\ndone\nFLAGS=\"$ac_save_[]FLAGS\"\n])\nAS_VAR_POPDEF([FLAGS])dnl\nAX_REQUIRE_DEFINED([AX_APPEND_FLAG])\ncase \".$VAR\" in\n     .ok|.ok,*) m4_ifvaln($3,$3) ;;\n   .|.no|.no,*) m4_default($4,[m4_ifval($2,[AX_APPEND_FLAG([$2], [$1])])]) ;;\n   *) m4_default($3,[AX_APPEND_FLAG([$VAR], [$1])]) ;;\nesac\nAS_VAR_POPDEF([VAR])dnl\n])dnl AX_FLAGS_WARN_ALL\ndnl  implementation tactics:\ndnl   the for-argument contains a list of options. The first part of\ndnl   these does only exist to detect the compiler - usually it is\ndnl   a global option to enable -ansi or -extrawarnings. All other\ndnl   compilers will fail about it. That was needed since a lot of\ndnl   compilers will give false positives for some option-syntax\ndnl   like -Woption or -Xoption as they think of it is a pass-through\ndnl   to later compile stages or something. The \"%\" is used as a\ndnl   delimiter. A non-option comment can be given after \"%%\" marks\ndnl   which will be shown but not added to the respective C/CXXFLAGS.\n\nAC_DEFUN([AX_CFLAGS_WARN_ALL],[dnl\nAC_LANG_PUSH([C])\nAX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])\nAC_LANG_POP([C])\n])\n\nAC_DEFUN([AX_CXXFLAGS_WARN_ALL],[dnl\nAC_LANG_PUSH([C++])\nAX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])\nAC_LANG_POP([C++])\n])\n\nAC_DEFUN([AX_FCFLAGS_WARN_ALL],[dnl\nAC_LANG_PUSH([Fortran])\nAX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])\nAC_LANG_POP([Fortran])\n])\n"
  },
  {
    "path": "m4/ax_check_compile_flag.m4",
    "content": "# ===========================================================================\n#   http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html\n# ===========================================================================\n#\n# SYNOPSIS\n#\n#   AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])\n#\n# DESCRIPTION\n#\n#   Check whether the given FLAG works with the current language's compiler\n#   or gives an error.  (Warnings, however, are ignored)\n#\n#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on\n#   success/failure.\n#\n#   If EXTRA-FLAGS is defined, it is added to the current language's default\n#   flags (e.g. CFLAGS) when the check is done.  The check is thus made with\n#   the flags: \"CFLAGS EXTRA-FLAGS FLAG\".  This can for example be used to\n#   force the compiler to issue an error when a bad flag is given.\n#\n#   INPUT gives an alternative input source to AC_COMPILE_IFELSE.\n#\n#   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this\n#   macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.\n#\n# LICENSE\n#\n#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>\n#   Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>\n#\n#   This program is free software: you can redistribute it and/or modify it\n#   under the terms of the GNU General Public License as published by the\n#   Free Software Foundation, either version 3 of the License, or (at your\n#   option) any later version.\n#\n#   This program is distributed in the hope that it will be useful, but\n#   WITHOUT ANY WARRANTY; without even the implied warranty of\n#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\n#   Public License for more details.\n#\n#   You should have received a copy of the GNU General Public License along\n#   with this program. If not, see <http://www.gnu.org/licenses/>.\n#\n#   As a special exception, the respective Autoconf Macro's copyright owner\n#   gives unlimited permission to copy, distribute and modify the configure\n#   scripts that are the output of Autoconf when processing the Macro. You\n#   need not follow the terms of the GNU General Public License when using\n#   or distributing such scripts, even though portions of the text of the\n#   Macro appear in them. The GNU General Public License (GPL) does govern\n#   all other use of the material that constitutes the Autoconf Macro.\n#\n#   This special exception to the GPL applies to versions of the Autoconf\n#   Macro released by the Autoconf Archive. When you make and distribute a\n#   modified version of the Autoconf Macro, you may extend this special\n#   exception to the GPL to apply to your modified version as well.\n\n#serial 4\n\nAC_DEFUN([AX_CHECK_COMPILE_FLAG],\n[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF\nAS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl\nAC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [\n  ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS\n  _AC_LANG_PREFIX[]FLAGS=\"$[]_AC_LANG_PREFIX[]FLAGS $4 $1\"\n  AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],\n    [AS_VAR_SET(CACHEVAR,[yes])],\n    [AS_VAR_SET(CACHEVAR,[no])])\n  _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])\nAS_VAR_IF(CACHEVAR,yes,\n  [m4_default([$2], :)],\n  [m4_default([$3], :)])\nAS_VAR_POPDEF([CACHEVAR])dnl\n])dnl AX_CHECK_COMPILE_FLAGS\n"
  },
  {
    "path": "m4/ax_gcc_func_attribute.m4",
    "content": "# ===========================================================================\n#   http://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html\n# ===========================================================================\n#\n# SYNOPSIS\n#\n#   AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE)\n#\n# DESCRIPTION\n#\n#   This macro checks if the compiler supports one of GCC's function\n#   attributes; many other compilers also provide function attributes with\n#   the same syntax. Compiler warnings are used to detect supported\n#   attributes as unsupported ones are ignored by default so quieting\n#   warnings when using this macro will yield false positives.\n#\n#   The ATTRIBUTE parameter holds the name of the attribute to be checked.\n#\n#   If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_<ATTRIBUTE>.\n#\n#   The macro caches its result in the ax_cv_have_func_attribute_<attribute>\n#   variable.\n#\n#   The macro currently supports the following function attributes:\n#\n#    alias\n#    aligned\n#    alloc_size\n#    always_inline\n#    artificial\n#    cold\n#    const\n#    constructor\n#    constructor_priority for constructor attribute with priority\n#    deprecated\n#    destructor\n#    dllexport\n#    dllimport\n#    error\n#    externally_visible\n#    flatten\n#    format\n#    format_arg\n#    gnu_inline\n#    hot\n#    ifunc\n#    leaf\n#    malloc\n#    noclone\n#    noinline\n#    nonnull\n#    noreturn\n#    nothrow\n#    optimize\n#    pure\n#    unused\n#    used\n#    visibility\n#    warning\n#    warn_unused_result\n#    weak\n#    weakref\n#\n#   Unsuppored function attributes will be tested with a prototype returning\n#   an int and not accepting any arguments and the result of the check might\n#   be wrong or meaningless so use with care.\n#\n# LICENSE\n#\n#   Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>\n#\n#   Copying and distribution of this file, with or without modification, are\n#   permitted in any medium without royalty provided the copyright notice\n#   and this notice are preserved.  This file is offered as-is, without any\n#   warranty.\n\n#serial 3\n\nAC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [\n    AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1])\n\n    AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [\n        AC_LINK_IFELSE([AC_LANG_PROGRAM([\n            m4_case([$1],\n                [alias], [\n                    int foo( void ) { return 0; }\n                    int bar( void ) __attribute__(($1(\"foo\")));\n                ],\n                [aligned], [\n                    int foo( void ) __attribute__(($1(32)));\n                ],\n                [alloc_size], [\n                    void *foo(int a) __attribute__(($1(1)));\n                ],\n                [always_inline], [\n                    inline __attribute__(($1)) int foo( void ) { return 0; }\n                ],\n                [artificial], [\n                    inline __attribute__(($1)) int foo( void ) { return 0; }\n                ],\n                [cold], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [const], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [constructor_priority], [\n                    int foo( void ) __attribute__((__constructor__(65535/2)));\n                ],\n                [constructor], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [deprecated], [\n                    int foo( void ) __attribute__(($1(\"\")));\n                ],\n                [destructor], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [dllexport], [\n                    __attribute__(($1)) int foo( void ) { return 0; }\n                ],\n                [dllimport], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [error], [\n                    int foo( void ) __attribute__(($1(\"\")));\n                ],\n                [externally_visible], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [flatten], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [format], [\n                    int foo(const char *p, ...) __attribute__(($1(printf, 1, 2)));\n                ],\n                [format_arg], [\n                    char *foo(const char *p) __attribute__(($1(1)));\n                ],\n                [gnu_inline], [\n                    inline __attribute__(($1)) int foo( void ) { return 0; }\n                ],\n                [hot], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [ifunc], [\n                    int my_foo( void ) { return 0; }\n                    static int (*resolve_foo(void))(void) { return my_foo; }\n                    int foo( void ) __attribute__(($1(\"resolve_foo\")));\n                ],\n                [leaf], [\n                    __attribute__(($1)) int foo( void ) { return 0; }\n                ],\n                [malloc], [\n                    void *foo( void ) __attribute__(($1));\n                ],\n                [noclone], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [noinline], [\n                    __attribute__(($1)) int foo( void ) { return 0; }\n                ],\n                [nonnull], [\n                    int foo(char *p) __attribute__(($1(1)));\n                ],\n                [noreturn], [\n                    void foo( void ) __attribute__(($1));\n                ],\n                [nothrow], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [optimize], [\n                    __attribute__(($1(3))) int foo( void ) { return 0; }\n                ],\n                [pure], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [unused], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [used], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [visibility], [\n                    int foo_def( void ) __attribute__(($1(\"default\")));\n                    int foo_hid( void ) __attribute__(($1(\"hidden\")));\n                    int foo_int( void ) __attribute__(($1(\"internal\")));\n                    int foo_pro( void ) __attribute__(($1(\"protected\")));\n                ],\n                [warning], [\n                    int foo( void ) __attribute__(($1(\"\")));\n                ],\n                [warn_unused_result], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [weak], [\n                    int foo( void ) __attribute__(($1));\n                ],\n                [weakref], [\n                    static int foo( void ) { return 0; }\n                    static int bar( void ) __attribute__(($1(\"foo\")));\n                ],\n                [\n                 m4_warn([syntax], [Unsupported attribute $1, the test may fail])\n                 int foo( void ) __attribute__(($1));\n                ]\n            )], [])\n            ],\n            dnl GCC doesn't exit with an error if an unknown attribute is\n            dnl provided but only outputs a warning, so accept the attribute\n            dnl only if no warning were issued.\n            [AS_IF([test -s conftest.err],\n                [AS_VAR_SET([ac_var], [no])],\n                [AS_VAR_SET([ac_var], [yes])])],\n            [AS_VAR_SET([ac_var], [no])])\n    ])\n\n    AS_IF([test yes = AS_VAR_GET([ac_var])],\n        [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1,\n            [Define to 1 if the system has the `$1' function attribute])], [])\n\n    AS_VAR_POPDEF([ac_var])\n])\n"
  },
  {
    "path": "m4/ax_require_defined.m4",
    "content": "# ===========================================================================\n#    http://www.gnu.org/software/autoconf-archive/ax_require_defined.html\n# ===========================================================================\n#\n# SYNOPSIS\n#\n#   AX_REQUIRE_DEFINED(MACRO)\n#\n# DESCRIPTION\n#\n#   AX_REQUIRE_DEFINED is a simple helper for making sure other macros have\n#   been defined and thus are available for use.  This avoids random issues\n#   where a macro isn't expanded.  Instead the configure script emits a\n#   non-fatal:\n#\n#     ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found\n#\n#   It's like AC_REQUIRE except it doesn't expand the required macro.\n#\n#   Here's an example:\n#\n#     AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG])\n#\n# LICENSE\n#\n#   Copyright (c) 2014 Mike Frysinger <vapier@gentoo.org>\n#\n#   Copying and distribution of this file, with or without modification, are\n#   permitted in any medium without royalty provided the copyright notice\n#   and this notice are preserved. This file is offered as-is, without any\n#   warranty.\n\n#serial 1\n\nAC_DEFUN([AX_REQUIRE_DEFINED], [dnl\n  m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])])\n])dnl AX_REQUIRE_DEFINED\n"
  },
  {
    "path": "m4/ax_type_socklen_t.m4",
    "content": "# ===========================================================================\n#    https://www.gnu.org/software/autoconf-archive/ax_type_socklen_t.html\n# ===========================================================================\n#\n# SYNOPSIS\n#\n#   AX_TYPE_SOCKLEN_T\n#\n# DESCRIPTION\n#\n#   Check whether sys/socket.h defines type socklen_t. Please note that some\n#   systems require sys/types.h to be included before sys/socket.h can be\n#   compiled.\n#\n# LICENSE\n#\n#   Copyright (c) 2008 Lars Brinkhoff <lars@nocrew.org>\n#\n#   This program is free software; you can redistribute it and/or modify it\n#   under the terms of the GNU General Public License as published by the\n#   Free Software Foundation; either version 2 of the License, or (at your\n#   option) any later version.\n#\n#   This program is distributed in the hope that it will be useful, but\n#   WITHOUT ANY WARRANTY; without even the implied warranty of\n#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\n#   Public License for more details.\n#\n#   You should have received a copy of the GNU General Public License along\n#   with this program. If not, see <https://www.gnu.org/licenses/>.\n#\n#   As a special exception, the respective Autoconf Macro's copyright owner\n#   gives unlimited permission to copy, distribute and modify the configure\n#   scripts that are the output of Autoconf when processing the Macro. You\n#   need not follow the terms of the GNU General Public License when using\n#   or distributing such scripts, even though portions of the text of the\n#   Macro appear in them. The GNU General Public License (GPL) does govern\n#   all other use of the material that constitutes the Autoconf Macro.\n#\n#   This special exception to the GPL applies to versions of the Autoconf\n#   Macro released by the Autoconf Archive. When you make and distribute a\n#   modified version of the Autoconf Macro, you may extend this special\n#   exception to the GPL to apply to your modified version as well.\n\n#serial 8\n\nAU_ALIAS([TYPE_SOCKLEN_T], [AX_TYPE_SOCKLEN_T])\nAC_DEFUN([AX_TYPE_SOCKLEN_T],\n[AC_CACHE_CHECK([for socklen_t], [ac_cv_ax_type_socklen_t],\n[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>\n  #include <sys/socket.h>]],\n  [[socklen_t len = (socklen_t) 42; return (!len);]])],\n  [ac_cv_ax_type_socklen_t=yes],\n  [ac_cv_ax_type_socklen_t=no])\n])\n  if test $ac_cv_ax_type_socklen_t != yes; then\n    AC_DEFINE(socklen_t, int, [Substitute for socklen_t])\n  fi\n])\n"
  },
  {
    "path": "m4/axrdp.m4",
    "content": "# SYNOPSIS\n#\n#   AXRDP_CHECK_UTMPX_MEMBER_EXISTS(MEMBER, COMPILE-DEFINE)\n#\n# EXAMPLE\n#\n# AXRDP_CHECK_UTMPX_MEMBER_EXISTS([ut_exit], [HAVE_UTMPX_UT_EXIT])\n#\n# DESCRIPTION\n#\n#   If the member MEMBER exists in the utmpx struct, the COMPILE-DEFINE\n#   is set for the C compiler.\n#\n#   The shell variable 'ac_cv_utmpx_has_$MEMBER' is set to 'yes' or 'no'\n#   and cached\n#\nAC_DEFUN([AXRDP_CHECK_UTMPX_MEMBER_EXISTS],\n[\n  AS_VAR_PUSHDEF([x_var], [ac_cv_utmpx_has_$1])\n  AS_VAR_PUSHDEF([x_define], [$2])\n  AC_CACHE_CHECK(\n      [for $1 in struct utmpx],\n      [x_var],\n      [AC_COMPILE_IFELSE(\n         [AC_LANG_SOURCE([[\n#           include <utmpx.h>\n#           include <stddef.h>\n            int main()\n            {\n                return offsetof(struct utmpx,$1);\n            }]])],\n         [AS_VAR_SET([x_var], [yes])],\n         [AS_VAR_SET([x_var], [no])])]\n  )\n  AS_VAR_IF(\n    [x_var],\n    [yes],\n    [AC_DEFINE([x_define], [1], [Define if '$1' is in struct utmpx.])])\n  AS_VAR_POPDEF([x_var])\n  AS_VAR_POPDEF([x_define])\n])\n\n\n"
  },
  {
    "path": "m4/pkg.m4",
    "content": "dnl pkg.m4 - Macros to locate and utilise pkg-config.   -*- Autoconf -*-\ndnl serial 11 (pkg-config-0.29.1)\ndnl\ndnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.\ndnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>\ndnl\ndnl This program is free software; you can redistribute it and/or modify\ndnl it under the terms of the GNU General Public License as published by\ndnl the Free Software Foundation; either version 2 of the License, or\ndnl (at your option) any later version.\ndnl\ndnl This program is distributed in the hope that it will be useful, but\ndnl WITHOUT ANY WARRANTY; without even the implied warranty of\ndnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\ndnl General Public License for more details.\ndnl\ndnl You should have received a copy of the GNU General Public License\ndnl along with this program; if not, write to the Free Software\ndnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\ndnl 02111-1307, USA.\ndnl\ndnl As a special exception to the GNU General Public License, if you\ndnl distribute this file as part of a program that contains a\ndnl configuration script generated by Autoconf, you may include it under\ndnl the same distribution terms that you use for the rest of that\ndnl program.\n\ndnl PKG_PREREQ(MIN-VERSION)\ndnl -----------------------\ndnl Since: 0.29\ndnl\ndnl Verify that the version of the pkg-config macros are at least\ndnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's\ndnl installed version of pkg-config, this checks the developer's version\ndnl of pkg.m4 when generating configure.\ndnl\ndnl To ensure that this macro is defined, also add:\ndnl m4_ifndef([PKG_PREREQ],\ndnl     [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])\ndnl\ndnl See the \"Since\" comment for each macro you use to see what version\ndnl of the macros you require.\nm4_defun([PKG_PREREQ],\n[m4_define([PKG_MACROS_VERSION], [0.29.1])\nm4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,\n    [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])\n])dnl PKG_PREREQ\n\ndnl PKG_PROG_PKG_CONFIG([MIN-VERSION])\ndnl ----------------------------------\ndnl Since: 0.16\ndnl\ndnl Search for the pkg-config tool and set the PKG_CONFIG variable to\ndnl first found in the path. Checks that the version of pkg-config found\ndnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is\ndnl used since that's the first version where most current features of\ndnl pkg-config existed.\nAC_DEFUN([PKG_PROG_PKG_CONFIG],\n[m4_pattern_forbid([^_?PKG_[A-Z_]+$])\nm4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])\nm4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])\nAC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])\nAC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])\nAC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])\n\nif test \"x$ac_cv_env_PKG_CONFIG_set\" != \"xset\"; then\n\tAC_PATH_TOOL([PKG_CONFIG], [pkg-config])\nfi\nif test -n \"$PKG_CONFIG\"; then\n\t_pkg_min_version=m4_default([$1], [0.9.0])\n\tAC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])\n\tif $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then\n\t\tAC_MSG_RESULT([yes])\n\telse\n\t\tAC_MSG_RESULT([no])\n\t\tPKG_CONFIG=\"\"\n\tfi\nfi[]dnl\n])dnl PKG_PROG_PKG_CONFIG\n\ndnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])\ndnl -------------------------------------------------------------------\ndnl Since: 0.18\ndnl\ndnl Check to see whether a particular set of modules exists. Similar to\ndnl PKG_CHECK_MODULES(), but does not set variables or print errors.\ndnl\ndnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])\ndnl only at the first occurence in configure.ac, so if the first place\ndnl it's called might be skipped (such as if it is within an \"if\", you\ndnl have to call PKG_CHECK_EXISTS manually\nAC_DEFUN([PKG_CHECK_EXISTS],\n[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl\nif test -n \"$PKG_CONFIG\" && \\\n    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors \"$1\"]); then\n  m4_default([$2], [:])\nm4_ifvaln([$3], [else\n  $3])dnl\nfi])\n\ndnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])\ndnl ---------------------------------------------\ndnl Internal wrapper calling pkg-config via PKG_CONFIG and setting\ndnl pkg_failed based on the result.\nm4_define([_PKG_CONFIG],\n[if test -n \"$$1\"; then\n    pkg_cv_[]$1=\"$$1\"\n elif test -n \"$PKG_CONFIG\"; then\n    PKG_CHECK_EXISTS([$3],\n                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 \"$3\" 2>/dev/null`\n\t\t      test \"x$?\" != \"x0\" && pkg_failed=yes ],\n\t\t     [pkg_failed=yes])\n else\n    pkg_failed=untried\nfi[]dnl\n])dnl _PKG_CONFIG\n\ndnl _PKG_SHORT_ERRORS_SUPPORTED\ndnl ---------------------------\ndnl Internal check to see if pkg-config supports short errors.\nAC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],\n[AC_REQUIRE([PKG_PROG_PKG_CONFIG])\nif $PKG_CONFIG --atleast-pkgconfig-version 0.20; then\n        _pkg_short_errors_supported=yes\nelse\n        _pkg_short_errors_supported=no\nfi[]dnl\n])dnl _PKG_SHORT_ERRORS_SUPPORTED\n\n\ndnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],\ndnl   [ACTION-IF-NOT-FOUND])\ndnl --------------------------------------------------------------\ndnl Since: 0.4.0\ndnl\ndnl Note that if there is a possibility the first call to\ndnl PKG_CHECK_MODULES might not happen, you should be sure to include an\ndnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac\nAC_DEFUN([PKG_CHECK_MODULES],\n[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl\nAC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl\nAC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl\n\npkg_failed=no\nAC_MSG_CHECKING([for $1])\n\n_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])\n_PKG_CONFIG([$1][_LIBS], [libs], [$2])\n\nm4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS\nand $1[]_LIBS to avoid the need to call pkg-config.\nSee the pkg-config man page for more details.])\n\nif test $pkg_failed = yes; then\n   \tAC_MSG_RESULT([no])\n        _PKG_SHORT_ERRORS_SUPPORTED\n        if test $_pkg_short_errors_supported = yes; then\n\t        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs \"$2\" 2>&1`\n        else \n\t        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs \"$2\" 2>&1`\n        fi\n\t# Put the nasty error message in config.log where it belongs\n\techo \"$$1[]_PKG_ERRORS\" >&AS_MESSAGE_LOG_FD\n\n\tm4_default([$4], [AC_MSG_ERROR(\n[Package requirements ($2) were not met:\n\n$$1_PKG_ERRORS\n\nConsider adjusting the PKG_CONFIG_PATH environment variable if you\ninstalled software in a non-standard prefix.\n\n_PKG_TEXT])[]dnl\n        ])\nelif test $pkg_failed = untried; then\n     \tAC_MSG_RESULT([no])\n\tm4_default([$4], [AC_MSG_FAILURE(\n[The pkg-config script could not be found or is too old.  Make sure it\nis in your PATH or set the PKG_CONFIG environment variable to the full\npath to pkg-config.\n\n_PKG_TEXT\n\nTo get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl\n        ])\nelse\n\t$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS\n\t$1[]_LIBS=$pkg_cv_[]$1[]_LIBS\n        AC_MSG_RESULT([yes])\n\t$3\nfi[]dnl\n])dnl PKG_CHECK_MODULES\n\n\ndnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],\ndnl   [ACTION-IF-NOT-FOUND])\ndnl ---------------------------------------------------------------------\ndnl Since: 0.29\ndnl\ndnl Checks for existence of MODULES and gathers its build flags with\ndnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags\ndnl and VARIABLE-PREFIX_LIBS from --libs.\ndnl\ndnl Note that if there is a possibility the first call to\ndnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to\ndnl include an explicit call to PKG_PROG_PKG_CONFIG in your\ndnl configure.ac.\nAC_DEFUN([PKG_CHECK_MODULES_STATIC],\n[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl\n_save_PKG_CONFIG=$PKG_CONFIG\nPKG_CONFIG=\"$PKG_CONFIG --static\"\nPKG_CHECK_MODULES($@)\nPKG_CONFIG=$_save_PKG_CONFIG[]dnl\n])dnl PKG_CHECK_MODULES_STATIC\n\n\ndnl PKG_INSTALLDIR([DIRECTORY])\ndnl -------------------------\ndnl Since: 0.27\ndnl\ndnl Substitutes the variable pkgconfigdir as the location where a module\ndnl should install pkg-config .pc files. By default the directory is\ndnl $libdir/pkgconfig, but the default can be changed by passing\ndnl DIRECTORY. The user can override through the --with-pkgconfigdir\ndnl parameter.\nAC_DEFUN([PKG_INSTALLDIR],\n[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])\nm4_pushdef([pkg_description],\n    [pkg-config installation directory @<:@]pkg_default[@:>@])\nAC_ARG_WITH([pkgconfigdir],\n    [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,\n    [with_pkgconfigdir=]pkg_default)\nAC_SUBST([pkgconfigdir], [$with_pkgconfigdir])\nm4_popdef([pkg_default])\nm4_popdef([pkg_description])\n])dnl PKG_INSTALLDIR\n\n\ndnl PKG_NOARCH_INSTALLDIR([DIRECTORY])\ndnl --------------------------------\ndnl Since: 0.27\ndnl\ndnl Substitutes the variable noarch_pkgconfigdir as the location where a\ndnl module should install arch-independent pkg-config .pc files. By\ndnl default the directory is $datadir/pkgconfig, but the default can be\ndnl changed by passing DIRECTORY. The user can override through the\ndnl --with-noarch-pkgconfigdir parameter.\nAC_DEFUN([PKG_NOARCH_INSTALLDIR],\n[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])\nm4_pushdef([pkg_description],\n    [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])\nAC_ARG_WITH([noarch-pkgconfigdir],\n    [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,\n    [with_noarch_pkgconfigdir=]pkg_default)\nAC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])\nm4_popdef([pkg_default])\nm4_popdef([pkg_description])\n])dnl PKG_NOARCH_INSTALLDIR\n\n\ndnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,\ndnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])\ndnl -------------------------------------------\ndnl Since: 0.28\ndnl\ndnl Retrieves the value of the pkg-config variable for the given module.\nAC_DEFUN([PKG_CHECK_VAR],\n[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl\nAC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl\n\n_PKG_CONFIG([$1], [variable=\"][$3][\"], [$2])\nAS_VAR_COPY([$1], [pkg_cv_][$1])\n\nAS_VAR_IF([$1], [\"\"], [$5], [$4])dnl\n])dnl PKG_CHECK_VAR\n"
  },
  {
    "path": "mc/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -I$(top_srcdir)/common\n\nmodule_LTLIBRARIES = \\\n  libmc.la\n\nlibmc_la_SOURCES = \\\n  mc.c \\\n  mc.h\n\nlibmc_la_LIBADD = \\\n  $(top_builddir)/common/libcommon.la\n\nif !MACOS\nlibmc_la_LDFLAGS = -avoid-version -module\nendif\n"
  },
  {
    "path": "mc/mc.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * media center\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"mc.h\"\n#include \"log.h\"\n\n/*****************************************************************************/\n/* return error */\nstatic int\nlib_mod_start(struct mod *mod, int w, int h, int bpp)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"in lib_mod_start\");\n    mod->width = w;\n    mod->height = h;\n    mod->bpp = bpp;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"out lib_mod_start\");\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_connect(struct mod *mod, int fd)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"in lib_mod_connect\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"out lib_mod_connect\");\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_event(struct mod *mod, int msg, long param1, long param2,\n              long param3, long param4)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"in lib_mod_event\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"out lib_mod_event\");\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_signal(struct mod *mod)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"in lib_mod_signal\");\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"out lib_mod_signal\");\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_end(struct mod *mod)\n{\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_set_param(struct mod *mod, const char *name, const char *value)\n{\n    return 0;\n}\n\n/******************************************************************************/\ntintptr EXPORT_CC\nmod_init(void)\n{\n    struct mod *mod;\n\n    mod = (struct mod *)g_malloc(sizeof(struct mod), 1);\n    mod->size = sizeof(struct mod);\n    mod->version = CURRENT_MOD_VER;\n    mod->handle = (tintptr) mod;\n    mod->mod_connect = lib_mod_connect;\n    mod->mod_start = lib_mod_start;\n    mod->mod_event = lib_mod_event;\n    mod->mod_signal = lib_mod_signal;\n    mod->mod_end = lib_mod_end;\n    mod->mod_set_param = lib_mod_set_param;\n    return (tintptr) mod;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nmod_exit(tintptr handle)\n{\n    struct mod *mod = (struct mod *) handle;\n\n    if (mod == 0)\n    {\n        return 0;\n    }\n\n    g_free(mod);\n    return 0;\n}\n"
  },
  {
    "path": "mc/mc.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * media center\n */\n\n#ifndef MC_H\n#define MC_H\n\n/* include other h files */\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"os_calls.h\"\n#include \"defines.h\"\n\n#define CURRENT_MOD_VER 3\n\nstruct source_info;\nstruct xrdp_client_info;\n\n/* Defined in xrdp_client_info.h */\nstruct monitor_info;\n\nstruct mod\n{\n    int size; /* size of this struct */\n    int version; /* internal version */\n    /* client functions */\n    int (*mod_start)(struct mod *v, int w, int h, int bpp);\n    int (*mod_connect)(struct mod *v, int fd);\n    int (*mod_event)(struct mod *v, int msg, long param1, long param2,\n                     long param3, long param4);\n    int (*mod_signal)(struct mod *v);\n    int (*mod_end)(struct mod *v);\n    int (*mod_set_param)(struct mod *v, const char *name, const char *value);\n    int (*mod_session_change)(struct mod *v, int, int);\n    int (*mod_get_wait_objs)(struct mod *v, tbus *read_objs, int *rcount,\n                             tbus *write_objs, int *wcount, int *timeout);\n    int (*mod_check_wait_objs)(struct mod *v);\n    tintptr mod_dumby[100 - 9]; /* align, 100 minus the number of mod\n                                 functions above */\n    /* server functions */\n    int (*server_begin_update)(struct mod *v);\n    int (*server_end_update)(struct mod *v);\n    int (*server_fill_rect)(struct mod *v, int x, int y, int cx, int cy);\n    int (*server_screen_blt)(struct mod *v, int x, int y, int cx, int cy,\n                             int srcx, int srcy);\n    int (*server_paint_rect)(struct mod *v, int x, int y, int cx, int cy,\n                             char *data, int width, int height, int srcx, int srcy);\n    int (*server_set_cursor)(struct mod *v, int x, int y, char *data, char *mask);\n    int (*server_palette)(struct mod *v, int *palette);\n    int (*server_msg)(struct mod *v, const char *msg, int code);\n    int (*server_is_term)(void);\n    int (*server_set_clip)(struct mod *v, int x, int y, int cx, int cy);\n    int (*server_reset_clip)(struct mod *v);\n    int (*server_set_fgcolor)(struct mod *v, int fgcolor);\n    int (*server_set_bgcolor)(struct mod *v, int bgcolor);\n    int (*server_set_opcode)(struct mod *v, int opcode);\n    int (*server_set_mixmode)(struct mod *v, int mixmode);\n    int (*server_set_brush)(struct mod *v, int x_origin, int y_origin,\n                            int style, char *pattern);\n    int (*server_set_pen)(struct mod *v, int style,\n                          int width);\n    int (*server_draw_line)(struct mod *v, int x1, int y1, int x2, int y2);\n    int (*server_add_char)(struct mod *v, int font, int character,\n                           int offset, int baseline,\n                           int width, int height, char *data);\n    int (*server_draw_text)(struct mod *v, int font,\n                            int flags, int mixmode, int clip_left, int clip_top,\n                            int clip_right, int clip_bottom,\n                            int box_left, int box_top,\n                            int box_right, int box_bottom,\n                            int x, int y, char *data, int data_len);\n    int (*client_monitor_resize)(struct mod *v, int width, int height,\n                                 int num_monitors,\n                                 const struct monitor_info *monitors);\n    int (*server_monitor_resize_done)(struct mod *v);\n    int (*server_get_channel_count)(struct mod *v);\n    int (*server_query_channel)(struct mod *v, int index,\n                                char *channel_name,\n                                int *channel_flags);\n    int (*server_get_channel_id)(struct mod *v, const char *name);\n    int (*server_send_to_channel)(struct mod *v, int channel_id,\n                                  char *data, int data_len,\n                                  int total_data_len, int flags);\n    int (*server_bell_trigger)(struct mod *v);\n    int (*server_chansrv_in_use)(struct mod *v);\n    void (*server_init_xkb_layout)(struct mod *v,\n                                   struct xrdp_client_info *client_info);\n    tintptr server_dumby[100 - 29]; /* align, 100 minus the number of server\n                                     functions above */\n    /* common */\n    tintptr handle; /* pointer to self as long */\n    tintptr wm;\n    tintptr painter;\n    struct source_info *si;\n    /* mod data */\n    int sck;\n    int width;\n    int height;\n    int bpp;\n};\n\n#endif // MC_H\n"
  },
  {
    "path": "neutrinordp/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -I$(top_srcdir)/common \\\n  $(FREERDP_CFLAGS)\n\nmodule_LTLIBRARIES = \\\n  libxrdpneutrinordp.la\n\nlibxrdpneutrinordp_la_SOURCES = \\\n  xrdp-color.c \\\n  xrdp-color.h \\\n  xrdp-neutrinordp.c \\\n  xrdp-neutrinordp.h\n\nlibxrdpneutrinordp_la_LIBADD = \\\n  $(top_builddir)/common/libcommon.la \\\n  $(FREERDP_LIBS)\n\nlibxrdpneutrinordp_la_LDFLAGS = -avoid-version -module\n"
  },
  {
    "path": "neutrinordp/xrdp-color.c",
    "content": "/**\n * FreeRDP: A Remote Desktop Protocol Server\n * freerdp wrapper\n *\n * Copyright 2011-2012 Jay Sorg\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp-neutrinordp.h\"\n#include \"defines.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n#include \"xrdp-color.h\"\n\nchar *\nconvert_bitmap(int in_bpp, int out_bpp, char *bmpdata,\n               int width, int height, int *palette)\n{\n    char *out;\n    char *src;\n    char *dst;\n    int i;\n    int j;\n    int red;\n    int green;\n    int blue;\n    int pixel;\n\n    if ((in_bpp == 8) && (out_bpp == 8))\n    {\n        out = (char *)g_malloc(width * height, 0);\n        src = bmpdata;\n        dst = out;\n\n        for (i = 0; i < height; i++)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = *((tui8 *)src);\n                pixel = palette[pixel];\n                SPLITCOLOR32(red, green, blue, pixel);\n                pixel = COLOR8(red, green, blue);\n                *dst = pixel;\n                src++;\n                dst++;\n            }\n        }\n\n        return out;\n    }\n\n    if ((in_bpp == 8) && (out_bpp == 16))\n    {\n        out = (char *)g_malloc(width * height * 2, 0);\n        src = bmpdata;\n        dst = out;\n\n        for (i = 0; i < height; i++)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = *((tui8 *)src);\n                pixel = palette[pixel];\n                SPLITCOLOR32(red, green, blue, pixel);\n                pixel = COLOR16(red, green, blue);\n                *((tui16 *)dst) = pixel;\n                src++;\n                dst += 2;\n            }\n        }\n\n        return out;\n    }\n\n    if ((in_bpp == 8) && (out_bpp == 24))\n    {\n        out = (char *)g_malloc(width * height * 4, 0);\n        src = bmpdata;\n        dst = out;\n\n        for (i = 0; i < height; i++)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = *((tui8 *)src);\n                pixel = palette[pixel];\n                SPLITCOLOR32(red, green, blue, pixel);\n                pixel = COLOR24RGB(red, green, blue);\n                *((tui32 *)dst) = pixel;\n                src++;\n                dst += 4;\n            }\n        }\n\n        return out;\n    }\n\n    if ((in_bpp == 15) && (out_bpp == 16))\n    {\n        out = (char *)g_malloc(width * height * 2, 0);\n        src = bmpdata;\n        dst = out;\n\n        for (i = 0; i < height; i++)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = *((tui16 *)src);\n                SPLITCOLOR15(red, green, blue, pixel);\n                pixel = COLOR16(red, green, blue);\n                *((tui16 *)dst) = pixel;\n                src += 2;\n                dst += 2;\n            }\n        }\n\n        return out;\n    }\n\n    if ((in_bpp == 15) && (out_bpp == 24))\n    {\n        out = (char *)g_malloc(width * height * 4, 0);\n        src = bmpdata;\n        dst = out;\n\n        for (i = 0; i < height; i++)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = *((tui16 *)src);\n                SPLITCOLOR15(red, green, blue, pixel);\n                pixel = COLOR24RGB(red, green, blue);\n                *((tui32 *)dst) = pixel;\n                src += 2;\n                dst += 4;\n            }\n        }\n\n        return out;\n    }\n\n    if ((in_bpp == 15) && (out_bpp == 15))\n    {\n        return bmpdata;\n    }\n\n    if ((in_bpp == 16) && (out_bpp == 16))\n    {\n        return bmpdata;\n    }\n\n    if ((in_bpp == 16) && (out_bpp == 24))\n    {\n        out = (char *)g_malloc(width * height * 4, 0);\n        src = bmpdata;\n        dst = out;\n\n        for (i = 0; i < height; i++)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = *((tui16 *)src);\n                SPLITCOLOR16(red, green, blue, pixel);\n                pixel = COLOR24RGB(red, green, blue);\n                *((tui32 *)dst) = pixel;\n                src += 2;\n                dst += 4;\n            }\n        }\n\n        return out;\n    }\n\n    if ((in_bpp == 24) && (out_bpp == 24))\n    {\n        out = (char *)g_malloc(width * height * 4, 0);\n        src = bmpdata;\n        dst = out;\n\n        for (i = 0; i < height; i++)\n        {\n            for (j = 0; j < width; j++)\n            {\n                blue = *((tui8 *)src);\n                src++;\n                green = *((tui8 *)src);\n                src++;\n                red = *((tui8 *)src);\n                src++;\n                pixel = COLOR24RGB(red, green, blue);\n                *((tui32 *)dst) = pixel;\n                dst += 4;\n            }\n        }\n\n        return out;\n    }\n\n    if ((in_bpp == 32) && (out_bpp == 24))\n    {\n        return bmpdata;\n    }\n\n    if ((in_bpp == 32) && (out_bpp == 32))\n    {\n        return bmpdata;\n    }\n\n    if ((in_bpp == 16) && (out_bpp == 32))\n    {\n        out = (char *)g_malloc(width * height * 4, 0);\n        src = bmpdata;\n        dst = out;\n\n        for (i = 0; i < height; i++)\n        {\n            for (j = 0; j < width; j++)\n            {\n                pixel = *((tui16 *)src);\n                SPLITCOLOR16(red, green, blue, pixel);\n                pixel = COLOR24RGB(red, green, blue);\n                *((tui32 *)dst) = pixel;\n                src += 2;\n                dst += 4;\n            }\n        }\n\n        return out;\n    }\n\n    LOG(LOG_LEVEL_WARNING, \"convert_bitmap: error unknown conversion from %d to %d\",\n        in_bpp, out_bpp);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns color or 0 */\nint\nconvert_color(int in_bpp, int out_bpp, int in_color, int *palette)\n{\n    int pixel;\n    int red;\n    int green;\n    int blue;\n\n    if ((in_bpp == 1) && (out_bpp == 24))\n    {\n        pixel = in_color == 0 ? 0 : 0xffffff;\n        return pixel;\n    }\n\n    if ((in_bpp == 8) && (out_bpp == 8))\n    {\n        pixel = palette[in_color];\n        SPLITCOLOR32(red, green, blue, pixel);\n        pixel = COLOR8(red, green, blue);\n        return pixel;\n    }\n\n    if ((in_bpp == 8) && (out_bpp == 16))\n    {\n        pixel = palette[in_color];\n        SPLITCOLOR32(red, green, blue, pixel);\n        pixel = COLOR16(red, green, blue);\n        return pixel;\n    }\n\n    if ((in_bpp == 8) && (out_bpp == 24))\n    {\n        pixel = palette[in_color];\n        SPLITCOLOR32(red, green, blue, pixel);\n        pixel = COLOR24BGR(red, green, blue);\n        return pixel;\n    }\n\n    if ((in_bpp == 15) && (out_bpp == 16))\n    {\n        pixel = in_color;\n        SPLITCOLOR15(red, green, blue, pixel);\n        pixel = COLOR16(red, green, blue);\n        return pixel;\n    }\n\n    if ((in_bpp == 15) && (out_bpp == 24))\n    {\n        pixel = in_color;\n        SPLITCOLOR15(red, green, blue, pixel);\n        pixel = COLOR24BGR(red, green, blue);\n        return pixel;\n    }\n\n    if ((in_bpp == 15) && (out_bpp == 15))\n    {\n        return in_color;\n    }\n\n    if ((in_bpp == 16) && (out_bpp == 16))\n    {\n        return in_color;\n    }\n\n    if ((in_bpp == 16) && (out_bpp == 24))\n    {\n        pixel = in_color;\n        SPLITCOLOR16(red, green, blue, pixel);\n        pixel = COLOR24BGR(red, green, blue);\n        return pixel;\n    }\n\n    if ((in_bpp == 16) && (out_bpp == 32))\n    {\n        pixel = in_color;\n        SPLITCOLOR16(red, green, blue, pixel);\n        pixel = COLOR24BGR(red, green, blue);\n        return pixel;\n    }\n\n    if ((in_bpp == 24) && (out_bpp == 24))\n    {\n        return in_color;\n    }\n\n    if ((in_bpp == 32) && (out_bpp == 24))\n    {\n        return in_color;\n    }\n\n    if ((in_bpp == 32) && (out_bpp == 32))\n    {\n        return in_color;\n    }\n\n    LOG(LOG_LEVEL_WARNING, \"convert_color: error unknown conversion from %d to %d\",\n        in_bpp, out_bpp);\n    return 0;\n}\n"
  },
  {
    "path": "neutrinordp/xrdp-color.h",
    "content": "/**\n * FreeRDP: A Remote Desktop Protocol Server\n * freerdp wrapper\n *\n * Copyright 2011-2012 Jay Sorg\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef __XRDP_COLOR_H\n#define __XRDP_COLOR_H\n\nchar *\nconvert_bitmap(int in_bpp, int out_bpp, char *bmpdata,\n               int width, int height, int *palette);\nint\nconvert_color(int in_bpp, int out_bpp, int in_color, int *palette);\n\n#endif\n"
  },
  {
    "path": "neutrinordp/xrdp-neutrinordp.c",
    "content": "/**\n * FreeRDP: A Remote Desktop Protocol Server\n * freerdp wrapper\n *\n * Copyright 2011-2013 Jay Sorg\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <freerdp/freerdp.h>\n#include <freerdp/codec/bitmap.h>\n\n// FreeRDP defines some macros that we have different values for.\n// To catch this we need to include the freerdp includes before our\n// local ones (see gcc bug #16358)\n#undef WM_LBUTTONUP\n#undef WM_LBUTTONDOWN\n#undef WM_RBUTTONUP\n#undef WM_RBUTTONDOWN\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp-neutrinordp.h\"\n#include \"xrdp-color.h\"\n#include \"xrdp_rail.h\"\n#include \"trans.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n#if defined(VERSION_STRUCT_RDP_FREERDP)\n#if VERSION_STRUCT_RDP_FREERDP > 1\n#define NEUTRINORDP_HAS_SUPPRESS_OUTPUT\n#endif\n#endif\n\n/* Max amount of buffered output data before we stop generating more */\n#define MAX_QUEUED_MODULE_OUTPUT_DATA 50000\n\n\nstruct mod_context\n{\n    rdpContext _p;\n    struct mod *modi;\n};\ntypedef struct mod_context modContext;\n\n/*****************************************************************************/\nstatic void\nverifyColorMap(struct mod *mod)\n{\n    int i;\n\n    for (i = 0; i < 255; i++)\n    {\n        if (mod->colormap[i] != 0)\n        {\n            return ;\n        }\n    }\n\n    LOG(LOG_LEVEL_WARNING, \"The colormap is all NULL\");\n}\n\n/*****************************************************************************/\nstatic int\nget_queued_module_output_data(struct mod *mod)\n{\n    return (mod->si != NULL) ? mod->si->source[XRDP_SOURCE_MOD] : 0;\n}\n\n/*****************************************************************************/\n/* return error */\nstatic int\nlxrdp_start(struct mod *mod, int w, int h, int bpp)\n{\n    rdpSettings *settings;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lxrdp_start: w %d h %d bpp %d\", w, h, bpp);\n    settings = mod->inst->settings;\n    settings->width = w;\n    settings->height = h;\n    settings->color_depth = bpp;\n    mod->bpp = bpp;\n\n    settings->encryption = 1;\n    settings->tls_security = 1;\n    settings->nla_security = 0;\n    settings->rdp_security = 1;\n\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic void\nset_keyboard_overrides(struct mod *mod)\n{\n    const struct kbd_overrides *ko = &mod->kbd_overrides;\n    rdpSettings *settings = mod->inst->settings;\n\n    if (mod->allow_client_kbd_settings)\n    {\n        settings->kbd_type = mod->client_info.keyboard_type;\n        settings->kbd_subtype = mod->client_info.keyboard_subtype;\n        /* Define the most common number of function keys, 12.\n           because we can't get it from client. */\n        settings->kbd_fn_keys = 12;\n        settings->kbd_layout = mod->client_info.keylayout;\n\n        /* Exception processing for each RDP Keyboard type */\n        if (mod->client_info.keyboard_type == 0x00)\n        {\n            /* 0x00000000 : Set on Server */\n            LOG(LOG_LEVEL_WARNING, \"keyboard_type:[0x%02x] ,Set on Server\",\n                mod->client_info.keyboard_type);\n        }\n        else if (mod->client_info.keyboard_type == 0x04)\n        {\n            /* 0x00000004 : IBM enhanced (101- or 102-key) keyboard */\n            /* Nothing to do. */\n        }\n        else if (mod->client_info.keyboard_type == 0x07)\n        {\n            /* 0x00000007 : Japanese keyboard */\n            /* Nothing to do. */\n        }\n    }\n\n    if (ko->type != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"overrode kbd_type 0x%02X with 0x%02X\",\n            settings->kbd_type, ko->type);\n        settings->kbd_type = ko->type;\n    }\n\n    if (ko->subtype != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"overrode kbd_subtype 0x%02X with 0x%02X\",\n            settings->kbd_subtype, ko->subtype);\n        settings->kbd_subtype = ko->subtype;\n    }\n\n    if (ko->fn_keys != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"overrode kbd_fn_keys %d with %d\",\n            settings->kbd_fn_keys, ko->fn_keys);\n        settings->kbd_fn_keys = ko->fn_keys;\n    }\n\n    if (ko->layout != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"overrode kbd_layout 0x%08X with 0x%08X\",\n            settings->kbd_layout, ko->layout);\n        settings->kbd_layout = ko->layout;\n    }\n\n    if (ko->layout_mask != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"Masked kbd_layout 0x%08X to 0x%08X\",\n            settings->kbd_layout, settings->kbd_layout & ko->layout_mask);\n        settings->kbd_layout &= ko->layout_mask;\n    }\n\n    LOG(LOG_LEVEL_INFO, \"NeutrinoRDP proxy remote keyboard settings, \"\n        \"kbd_type:[0x%02X], kbd_subtype:[0x%02X], \"\n        \"kbd_fn_keys:[%02d], kbd_layout:[0x%08X]\",\n        settings->kbd_type, settings->kbd_subtype,\n        settings->kbd_fn_keys, settings->kbd_layout);\n}\n\nstatic int\nlxrdp_connect(struct mod *mod, int fd)\n{\n    boolean ok;\n    set_keyboard_overrides(mod);\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lxrdp_connect:\");\n\n    if (fd >= 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"NeutrinoRDP : Can't connect to a file descriptor\");\n        ok = 0;\n    }\n    else\n    {\n        ok = freerdp_connect(mod->inst);\n        LOG_DEVEL(LOG_LEVEL_INFO,\n                  \"lxrdp_connect: freerdp_connect returned %d\", ok);\n    }\n\n    if (!ok)\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO, \"Failure to connect\");\n#ifdef ERRORSTART\n\n        if (connectErrorCode != 0)\n        {\n            char buf[128];\n\n            if (connectErrorCode < ERRORSTART)\n            {\n                if (strerror_r(connectErrorCode, buf, 128) != 0)\n                {\n                    g_snprintf(buf, 128, \"Errorcode from connect : %d\", connectErrorCode);\n                }\n            }\n            else\n            {\n                switch (connectErrorCode)\n                {\n                    case PREECONNECTERROR:\n                        g_snprintf(buf, 128, \"The error code from connect is \"\n                                   \"PREECONNECTERROR\");\n                        break;\n\n                    case UNDEFINEDCONNECTERROR:\n                        g_snprintf(buf, 128, \"The error code from connect is \"\n                                   \"UNDEFINEDCONNECTERROR\");\n                        break;\n\n                    case POSTCONNECTERROR:\n                        g_snprintf(buf, 128, \"The error code from connect is \"\n                                   \"POSTCONNECTERROR\");\n                        break;\n\n                    case DNSERROR:\n                        g_snprintf(buf, 128, \"The DNS system generated an error\");\n                        break;\n\n                    case DNSNAMENOTFOUND:\n                        g_snprintf(buf, 128, \"The DNS system could not find the \"\n                                   \"specified name\");\n                        break;\n\n                    case CONNECTERROR:\n                        g_snprintf(buf, 128, \"A general connect error was returned\");\n                        break;\n\n                    case MCSCONNECTINITIALERROR:\n                        g_snprintf(buf, 128, \"The error code from connect is \"\n                                   \"MCSCONNECTINITIALERROR\");\n                        break;\n\n                    case TLSCONNECTERROR:\n                        g_snprintf(buf, 128, \"Error in TLS handshake\");\n                        break;\n\n                    case AUTHENTICATIONERROR:\n                        g_snprintf(buf, 128, \"Authentication error check your password \"\n                                   \"and username\");\n                        break;\n\n                    case INSUFFICIENTPRIVILEGESERROR:\n                        g_snprintf(buf, 128, \"Insufficient privileges on target server\");\n                        break;\n\n                    default:\n                        g_snprintf(buf, 128, \"Unhandled Errorcode from connect : %d\",\n                                   connectErrorCode);\n                        break;\n                }\n            }\n\n            LOG(LOG_LEVEL_INFO, buf);\n            mod->server_msg(mod, buf, 0);\n        }\n#else\n        {\n            /* This version of freerdp returns no useful information at\n             * all */\n            mod->server_msg(mod, \"Neutrinordp connect failed.\", 0);\n            mod->server_msg(mod, \"No more information is available\", 0);\n            mod->server_msg(mod, \"Check host is up\"\n                            \" and credentials are correct\", 0);\n        }\n#endif\n        LOG(LOG_LEVEL_ERROR, \"NeutrinoRDP proxy connection: status [Failed],\"\n            \" RDP client [%s], RDP server [%s:%d], RDP server username [%s],\"\n            \" xrdp pamusername [%s], xrdp process id [%d]\",\n            mod->client_info.client_description,\n            mod->inst->settings->hostname,\n            mod->inst->settings->port,\n            mod->inst->settings->username,\n            mod->pamusername,\n            g_getpid());\n        return 1;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO, \"NeutrinoRDP proxy connection: status [Success],\"\n            \" RDP client [%s], RDP server [%s:%d], RDP server username [%s],\"\n            \" xrdp pamusername [%s], xrdp process id [%d]\",\n            mod->client_info.client_description,\n            mod->inst->settings->hostname,\n            mod->inst->settings->port,\n            mod->inst->settings->username,\n            mod->pamusername,\n            g_getpid());\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlxrdp_event(struct mod *mod, int msg, long param1, long param2,\n            long param3, long param4)\n{\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int flags;\n    int size;\n    int total_size;\n    int chanid;\n    int lchid;\n    char *data;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lxrdp_event: msg %d\", msg);\n\n    switch (msg)\n    {\n        case WM_KEYDOWN:\n\n            /* Before we handle the first character we synchronize\n               capslock and numlock. */\n            /* We collect the state during the first synchronize\n               ( see msg 17) */\n            if (!mod->bool_keyBoardSynced)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"Additional Sync event handled : %d\", mod->keyBoardLockInfo);\n                mod->inst->input->SynchronizeEvent(mod->inst->input, mod->keyBoardLockInfo);\n                mod->bool_keyBoardSynced = 1;\n            }\n\n            mod->inst->input->KeyboardEvent(mod->inst->input, param4, param3);\n            break;\n\n        case WM_KEYUP:\n            mod->inst->input->KeyboardEvent(mod->inst->input, param4, param3);\n            break;\n\n        case WM_KEYBRD_SYNC:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"Synchronized event handled : %ld\", param1);\n            /* In some situations the Synchronize event come to early.\n               Therefore we store this information and use it when we\n               receive the first keyboard event\n               Without this fix numlock and capslock can come\n               out of sync. */\n            mod->inst->input->SynchronizeEvent(mod->inst->input, param1);\n\n            if (!mod->bool_keyBoardSynced)\n            {\n                mod->keyBoardLockInfo = param1;\n            }\n\n            break;\n\n        case WM_MOUSEMOVE: /* mouse move */\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"mouse move %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_FLAGS_MOVE;\n            mod->inst->input->MouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_LBUTTONUP:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"left button up %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_FLAGS_BUTTON1;\n            mod->inst->input->MouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_LBUTTONDOWN:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"left button down %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_FLAGS_BUTTON1 | PTR_FLAGS_DOWN;\n            mod->inst->input->MouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_RBUTTONUP:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"right button up %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_FLAGS_BUTTON2;\n            mod->inst->input->MouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_RBUTTONDOWN:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"right button down %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_FLAGS_BUTTON2 | PTR_FLAGS_DOWN;\n            mod->inst->input->MouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_BUTTON3UP: /* middle button up */\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"middle button up %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_FLAGS_BUTTON3;\n            mod->inst->input->MouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_BUTTON3DOWN: /* middle button down */\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"middle button down %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_FLAGS_BUTTON3 | PTR_FLAGS_DOWN;\n            mod->inst->input->MouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_BUTTON4UP: /* wheel up */\n            flags = PTR_FLAGS_WHEEL | 0x0078;\n            mod->inst->input->MouseEvent(mod->inst->input, flags, 0, 0);\n            break;\n\n        case WM_BUTTON4DOWN:\n            break;\n\n        case WM_BUTTON5UP: /* wheel down */\n            flags = PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0088;\n            mod->inst->input->MouseEvent(mod->inst->input, flags, 0, 0);\n            break;\n\n        case WM_BUTTON5DOWN:\n            break;\n\n        case WM_BUTTON8UP:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"extended mouse button8 up %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_XFLAGS_BUTTON1;\n            mod->inst->input->ExtendedMouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_BUTTON8DOWN:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"extended mouse button8 down %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_XFLAGS_BUTTON1 | PTR_XFLAGS_DOWN;\n            mod->inst->input->ExtendedMouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_BUTTON9UP:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"extended mouse button9 up %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_XFLAGS_BUTTON2;\n            mod->inst->input->ExtendedMouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_BUTTON9DOWN:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"extended mouse button9 down %ld %ld\", param1, param2);\n            x = param1;\n            y = param2;\n            flags = PTR_XFLAGS_BUTTON2 | PTR_XFLAGS_DOWN;\n            mod->inst->input->ExtendedMouseEvent(mod->inst->input, flags, x, y);\n            break;\n\n        case WM_INVALIDATE:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"Invalidate request sent from client\");\n            x = (param1 >> 16) & 0xffff;\n            y = (param1 >> 0) & 0xffff;\n            cx = (param2 >> 16) & 0xffff;\n            cy = (param2 >> 0) & 0xffff;\n            mod->inst->SendInvalidate(mod->inst, -1, x, y, cx, cy);\n            break;\n\n        case WM_CHANNEL_DATA:\n            chanid = LOWORD(param1);\n            flags = HIWORD(param1);\n            size = (int)param2;\n            data = (char *)param3;\n            total_size = (int)param4;\n\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"lxrdp_event: client to server ,chanid= %d  flags= %d\", chanid, flags);\n\n            if ((chanid < 0) || (chanid >= mod->inst->settings->num_channels))\n            {\n                LOG(LOG_LEVEL_WARNING, \"lxrdp_event: error chanid %d\", chanid);\n                break;\n            }\n\n            lchid = mod->inst->settings->channels[chanid].channel_id;\n\n            switch (flags & 3)\n            {\n                case 3:\n                    mod->inst->SendChannelData(mod->inst, lchid, (tui8 *)data, total_size);\n                    break;\n\n                case 2:\n                    /* end */\n                    g_memcpy(mod->chan_buf + mod->chan_buf_valid, data, size);\n                    mod->chan_buf_valid += size;\n                    mod->inst->SendChannelData(mod->inst, lchid, (tui8 *)(mod->chan_buf),\n                                               total_size);\n                    g_free(mod->chan_buf);\n                    mod->chan_buf = 0;\n                    mod->chan_buf_bytes = 0;\n                    mod->chan_buf_valid = 0;\n                    break;\n\n                case 1:\n                    /* start */\n                    g_free(mod->chan_buf);\n                    mod->chan_buf = (char *)g_malloc(total_size, 0);\n                    mod->chan_buf_bytes = total_size;\n                    mod->chan_buf_valid = 0;\n                    g_memcpy(mod->chan_buf + mod->chan_buf_valid, data, size);\n                    mod->chan_buf_valid += size;\n                    break;\n\n                default:\n                    /* middle */\n                    g_memcpy(mod->chan_buf + mod->chan_buf_valid, data, size);\n                    mod->chan_buf_valid += size;\n                    break;\n            }\n\n            break;\n\n        default:\n            LOG(LOG_LEVEL_WARNING, \"Unhandled message type in eventhandler %d\", msg);\n            break;\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlxrdp_signal(struct mod *mod)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lxrdp_signal:\");\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlxrdp_end(struct mod *mod)\n{\n    int i;\n    int j;\n\n    for (j = 0; j < 4; j++)\n    {\n        for (i = 0; i < 4096; i++)\n        {\n            g_free(mod->bitmap_cache[j][i].data);\n        }\n    }\n\n    for (i = 0; i < 64; i++)\n    {\n        if (mod->brush_cache[i].data != mod->brush_cache[i].b8x8)\n        {\n            g_free(mod->brush_cache[i].data);\n        }\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lxrdp_end:\");\n    LOG(LOG_LEVEL_INFO, \"NeutrinoRDP proxy connection: status [Disconnect],\"\n        \" RDP client [%s], RDP server [%s:%d], RDP server username [%s],\"\n        \" xrdp pamusername [%s], xrdp process id [%d]\",\n        mod->client_info.client_description,\n        mod->inst->settings->hostname,\n        mod->inst->settings->port,\n        mod->inst->settings->username,\n        mod->pamusername,\n        g_getpid());\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlxrdp_set_param(struct mod *mod, const char *name, const char *value)\n{\n    rdpSettings *settings;\n\n    if (g_strcmp(name, \"password\") == 0 || g_strcmp(name, \"pampassword\") == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lxrdp_set_param: name [%s] value [******]\", name);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lxrdp_set_param: name [%s] value [%s]\", name, value);\n    }\n\n    settings = mod->inst->settings;\n\n    if (g_strcmp(name, \"client_name\") == 0)\n    {\n    }\n    else if (g_strcmp(name, \"ip\") == 0)\n    {\n        settings->hostname = g_strdup(value);\n    }\n    else if (g_strcmp(name, \"port\") == 0)\n    {\n        settings->port = g_atoi(value);\n    }\n    else if (g_strcmp(name, \"keylayout\") == 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"%s:[0x%08X]\", name, g_atoi(value));\n    }\n    else if (g_strcmp(name, \"name\") == 0)\n    {\n    }\n    else if (g_strcmp(name, \"lib\") == 0)\n    {\n    }\n    else if (g_strcmp(name, \"username\") == 0)\n    {\n        g_strncpy(mod->username, value, 255);\n    }\n    else if (g_strcmp(name, \"domain\") == 0)\n    {\n        g_strncpy(mod->domain, value, 255);\n    }\n    else if (g_strcmp(name, \"password\") == 0)\n    {\n        g_strncpy(mod->password, value, 255);\n    }\n    else if (g_strcmp(name, \"client_info\") == 0)\n    {\n        g_memcpy(&(mod->client_info), value, sizeof(mod->client_info));\n        /* This is a Struct and cannot be printed in next else*/\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"Client_info struct ignored\");\n    }\n    else if (g_strcmp(name, \"program\") == 0)\n    {\n        settings->shell = g_strdup(value);\n    }\n    else if (g_strcmp(name, \"nla\") == 0)\n    {\n        settings->nla_security = g_text2bool(value);\n    }\n    else if (g_strcmp(name, \"enable_dynamic_resizing\") == 0)\n    {\n        settings->desktop_resize = g_text2bool(value);\n    }\n    else if (g_strcmp(name, \"pamusername\") == 0)\n    {\n        g_strncpy(mod->pamusername, value, 255);\n    }\n    else if (g_strcmp(name, \"pampassword\") == 0 ||\n             g_strcmp(name, \"pamsessionmng\") == 0)\n    {\n        /* Valid (but unused) parameters not logged */\n    }\n    else if (g_strcmp(name, \"channel.rdpdr\") == 0 ||\n             g_strcmp(name, \"channel.rdpsnd\") == 0 ||\n             g_strcmp(name, \"channel.cliprdr\") == 0 ||\n             g_strcmp(name, \"channel.drdynvc\") == 0)\n    {\n        /* Valid (but unused) parameters not logged */\n    }\n    else if (g_strcmp(name, \"perf.allow_client_experiencesettings\") == 0)\n    {\n        mod->allow_client_experiencesettings = g_text2bool(value);\n    }\n    else if (g_strcmp(name, \"perf.wallpaper\") == 0)\n    {\n        mod->perf_settings_override_mask |= PERF_DISABLE_WALLPAPER;\n        if (!g_text2bool(value))\n        {\n            mod->perf_settings_values_mask |= PERF_DISABLE_WALLPAPER;\n        }\n    }\n    else if (g_strcmp(name, \"perf.font_smoothing\") == 0)\n    {\n        mod->perf_settings_override_mask |= PERF_ENABLE_FONT_SMOOTHING;\n        if (g_text2bool(value))\n        {\n            mod->perf_settings_values_mask |= PERF_ENABLE_FONT_SMOOTHING;\n        }\n    }\n    else if (g_strcmp(name, \"perf.desktop_composition\") == 0)\n    {\n        mod->perf_settings_override_mask |= PERF_ENABLE_DESKTOP_COMPOSITION;\n        if (g_text2bool(value))\n        {\n            mod->perf_settings_values_mask |= PERF_ENABLE_DESKTOP_COMPOSITION;\n        }\n    }\n    else if (g_strcmp(name, \"perf.full_window_drag\") == 0)\n    {\n        mod->perf_settings_override_mask |= PERF_DISABLE_FULLWINDOWDRAG;\n        if (!g_text2bool(value))\n        {\n            mod->perf_settings_values_mask |= PERF_DISABLE_FULLWINDOWDRAG;\n        }\n    }\n    else if (g_strcmp(name, \"perf.menu_anims\") == 0)\n    {\n        mod->perf_settings_override_mask |= PERF_DISABLE_MENUANIMATIONS;\n        if (!g_text2bool(value))\n        {\n            mod->perf_settings_values_mask |= PERF_DISABLE_MENUANIMATIONS;\n        }\n    }\n    else if (g_strcmp(name, \"perf.themes\") == 0)\n    {\n        mod->perf_settings_override_mask |= PERF_DISABLE_THEMING;\n        if (!g_text2bool(value))\n        {\n            mod->perf_settings_values_mask |= PERF_DISABLE_THEMING;\n        }\n    }\n    else if (g_strcmp(name, \"perf.cursor_blink\") == 0)\n    {\n        mod->perf_settings_override_mask |= PERF_DISABLE_CURSORSETTINGS;\n        if (!g_text2bool(value))\n        {\n            mod->perf_settings_values_mask |= PERF_DISABLE_CURSORSETTINGS;\n        }\n    }\n    else if (g_strcmp(name, \"perf.cursor_shadow\") == 0)\n    {\n        mod->perf_settings_override_mask |= PERF_DISABLE_CURSOR_SHADOW;\n        if (!g_text2bool(value))\n        {\n            mod->perf_settings_values_mask |= PERF_DISABLE_CURSOR_SHADOW;\n        }\n    }\n    else if (g_strcmp(name, \"neutrinordp.allow_client_keyboardLayout\") == 0)\n    {\n        mod->allow_client_kbd_settings = g_text2bool(value);\n    }\n    else if (g_strcmp(name, \"neutrinordp.override_keyboardLayout_mask\") == 0)\n    {\n        /* Keyboard values are stored for later processing */\n        mod->kbd_overrides.layout_mask = g_atoix(value);\n    }\n    else if (g_strcmp(name, \"neutrinordp.override_kbd_type\") == 0)\n    {\n        mod->kbd_overrides.type = g_atoix(value);\n    }\n    else if (g_strcmp(name, \"neutrinordp.override_kbd_subtype\") == 0)\n    {\n        mod->kbd_overrides.subtype = g_atoix(value);\n    }\n    else if (g_strcmp(name, \"neutrinordp.override_kbd_fn_keys\") == 0)\n    {\n        mod->kbd_overrides.fn_keys = g_atoix(value);\n    }\n    else if (g_strcmp(name, \"neutrinordp.override_kbd_layout\") == 0)\n    {\n        mod->kbd_overrides.layout = g_atoix(value);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"lxrdp_set_param: unknown name [%s] value [%s]\", name, value);\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlxrdp_session_change(struct mod *mod, int a, int b)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lxrdp_session_change: - no code here\");\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlxrdp_get_wait_objs(struct mod *mod, tbus *read_objs, int *rcount,\n                    tbus *write_objs, int *wcount, int *timeout)\n{\n    void **rfds;\n    void **wfds;\n    boolean ok;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lxrdp_get_wait_objs:\");\n    /*\n     * Don't check this module for activity if our queued output data\n     * has already reached the limit\n     */\n    if (get_queued_module_output_data(mod) > MAX_QUEUED_MODULE_OUTPUT_DATA)\n    {\n        *rcount = 0;\n        *wcount = 0;\n    }\n    else\n    {\n        rfds = (void **)read_objs;\n        wfds = (void **)write_objs;\n        ok = freerdp_get_fds(mod->inst, rfds, rcount, wfds, wcount);\n\n        if (!ok)\n        {\n            LOG(LOG_LEVEL_ERROR, \"lxrdp_get_wait_objs: freerdp_get_fds failed\");\n            return 1;\n        }\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlxrdp_check_wait_objs(struct mod *mod)\n{\n    boolean ok;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lxrdp_check_wait_objs:\");\n    /*\n     * Only process the freerdp file descriptors if our queued output data\n     * has not reached the limit\n     */\n    if (get_queued_module_output_data(mod) <= MAX_QUEUED_MODULE_OUTPUT_DATA)\n    {\n        /*\n         * Before checking the file descriptors, set the source info\n         * current source, so any data queued on output trans objects\n         * gets attributed to this module\n         */\n        if (mod->si)\n        {\n            mod->si->cur_source = XRDP_SOURCE_MOD;\n        }\n        ok = freerdp_check_fds(mod->inst);\n        if (mod->si)\n        {\n            mod->si->cur_source = XRDP_SOURCE_NONE;\n        }\n\n        if (!ok)\n        {\n            LOG(LOG_LEVEL_ERROR, \"lxrdp_check_wait_objs: freerdp_check_fds failed\");\n            return 1;\n        }\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlxrdp_frame_ack(struct mod *mod, int flags, int frame_id)\n{\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlxrdp_suppress_output(struct mod *mod, int suppress,\n                      int left, int top, int right, int bottom)\n{\n#if defined(NEUTRINORDP_HAS_SUPPRESS_OUTPUT)\n    mod->inst->SendSuppressOutput(mod->inst, !suppress, left, top, right, bottom);\n#endif\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlxrdp_server_version_message(struct mod *mod)\n{\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlxrdp_server_monitor_resize(struct mod *mod, int width, int height,\n                            int num_monitors,\n                            const struct monitor_info *monitors,\n                            int *in_progress)\n{\n    *in_progress = 0;\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlxrdp_server_monitor_full_invalidate(struct mod *mod, int width, int height)\n{\n    return 0;\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_begin_paint(rdpContext *context)\n{\n    struct mod *mod;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_begin_paint:\");\n    mod = ((struct mod_context *)context)->modi;\n    mod->server_begin_update(mod);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_end_paint(rdpContext *context)\n{\n    struct mod *mod;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_end_paint:\");\n    mod = ((struct mod_context *)context)->modi;\n    mod->server_end_update(mod);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_set_bounds(rdpContext *context, rdpBounds *bounds)\n{\n    struct mod *mod;\n    int x;\n    int y;\n    int cx;\n    int cy;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_set_bounds: %p\", bounds);\n    mod = ((struct mod_context *)context)->modi;\n\n    if (bounds != 0)\n    {\n        x = bounds->left;\n        y = bounds->top;\n        cx = (bounds->right - bounds->left) + 1;\n        cy = (bounds->bottom - bounds->top) + 1;\n        mod->server_set_clip(mod, x, y, cx, cy);\n    }\n    else\n    {\n        mod->server_reset_clip(mod);\n    }\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_bitmap_update(rdpContext *context, BITMAP_UPDATE *bitmap)\n{\n    struct mod *mod;\n    int index;\n    int cx;\n    int cy;\n    int server_bpp;\n    int server_Bpp;\n    int client_bpp;\n    int j;\n    int line_bytes;\n    BITMAP_DATA *bd;\n    char *dst_data;\n    char *dst_data1;\n    char *src;\n    char *dst;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_bitmap_update: %d %d\", bitmap->number, bitmap->count);\n\n    server_bpp = mod->inst->settings->color_depth;\n    server_Bpp = (server_bpp + 7) / 8;\n    client_bpp = mod->bpp;\n\n    for (index = 0; index < bitmap->number; index++)\n    {\n        bd = &bitmap->rectangles[index];\n        cx = (bd->destRight - bd->destLeft) + 1;\n        cy = (bd->destBottom - bd->destTop) + 1;\n        line_bytes = server_Bpp * bd->width;\n        dst_data = (char *)g_malloc(bd->height * line_bytes + 16, 0);\n\n        if (bd->compressed)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"decompress size : %d\", bd->bitmapLength);\n\n            if (!bitmap_decompress(bd->bitmapDataStream, (tui8 *)dst_data, bd->width,\n                                   bd->height, bd->bitmapLength, server_bpp, server_bpp))\n            {\n                LOG(LOG_LEVEL_WARNING, \"Failure to decompress the bitmap\");\n            }\n        }\n        else\n        {\n            /* bitmap is upside down */\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"bitmap upside down\");\n            src = (char *)(bd->bitmapDataStream);\n            dst = dst_data + bd->height * line_bytes;\n\n            for (j = 0; j < bd->height; j++)\n            {\n                dst -= line_bytes;\n                g_memcpy(dst, src, line_bytes);\n                src += line_bytes;\n            }\n        }\n\n        dst_data1 = convert_bitmap(server_bpp, client_bpp, dst_data,\n                                   bd->width, bd->height, mod->colormap);\n        mod->server_paint_rect(mod, bd->destLeft, bd->destTop, cx, cy,\n                               dst_data1, bd->width, bd->height, 0, 0);\n\n        if (dst_data1 != dst_data)\n        {\n            g_free(dst_data1);\n        }\n\n        g_free(dst_data);\n    }\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_dst_blt(rdpContext *context, DSTBLT_ORDER *dstblt)\n{\n    struct mod *mod;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_dst_blt:\");\n    mod->server_set_opcode(mod, dstblt->bRop);\n    mod->server_fill_rect(mod, dstblt->nLeftRect, dstblt->nTopRect,\n                          dstblt->nWidth, dstblt->nHeight);\n    mod->server_set_opcode(mod, 0xcc);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_pat_blt(rdpContext *context, PATBLT_ORDER *patblt)\n{\n    struct mod *mod;\n    int idx;\n    int fgcolor;\n    int bgcolor;\n    int server_bpp;\n    int client_bpp;\n    struct brush_item *bi;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_pat_blt:\");\n\n    server_bpp = mod->inst->settings->color_depth;\n    client_bpp = mod->bpp;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pat_blt: bpp %d %d\", server_bpp, client_bpp);\n\n    fgcolor = convert_color(server_bpp, client_bpp,\n                            patblt->foreColor, mod->colormap);\n    bgcolor = convert_color(server_bpp, client_bpp,\n                            patblt->backColor, mod->colormap);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pat_blt: nLeftRect %d nTopRect %d \"\n              \"nWidth %d nHeight %d fgcolor 0x%8.8x bgcolor 0x%8.8x\",\n              patblt->nLeftRect, patblt->nTopRect,\n              patblt->nWidth, patblt->nHeight, fgcolor, bgcolor);\n\n    if (fgcolor == bgcolor)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Warning same color on both bg and fg\");\n    }\n\n    mod->server_set_mixmode(mod, 1);\n    mod->server_set_opcode(mod, patblt->bRop);\n    mod->server_set_fgcolor(mod, fgcolor);\n    mod->server_set_bgcolor(mod, bgcolor);\n\n    if (patblt->brush.style & 0x80)\n    {\n        idx = patblt->brush.hatch;\n\n        if ((idx < 0) || (idx >= 64))\n        {\n            LOG(LOG_LEVEL_ERROR, \"lfreerdp_pat_blt: error patblt->brush.hatch, \"\n                \"Expected min 0, max 63. Actual %d\", idx);\n            return;\n        }\n\n        bi = mod->brush_cache + idx;\n        mod->server_set_brush(mod, patblt->brush.x, patblt->brush.y,\n                              3, bi->b8x8);\n    }\n    else\n    {\n        mod->server_set_brush(mod, patblt->brush.x, patblt->brush.y,\n                              patblt->brush.style,\n                              (char *)(patblt->brush.p8x8));\n    }\n\n    mod->server_fill_rect(mod, patblt->nLeftRect, patblt->nTopRect,\n                          patblt->nWidth, patblt->nHeight);\n    mod->server_set_opcode(mod, 0xcc);\n    mod->server_set_mixmode(mod, 0);\n\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_scr_blt(rdpContext *context, SCRBLT_ORDER *scrblt)\n{\n    struct mod *mod;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_scr_blt:\");\n    mod->server_set_opcode(mod, scrblt->bRop);\n    mod->server_screen_blt(mod, scrblt->nLeftRect, scrblt->nTopRect,\n                           scrblt->nWidth, scrblt->nHeight,\n                           scrblt->nXSrc, scrblt->nYSrc);\n    mod->server_set_opcode(mod, 0xcc);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_opaque_rect(rdpContext *context, OPAQUE_RECT_ORDER *opaque_rect)\n{\n    struct mod *mod;\n    int server_bpp;\n    int client_bpp;\n    int fgcolor;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_opaque_rect:\");\n    server_bpp = mod->inst->settings->color_depth;\n    client_bpp = mod->bpp;\n    fgcolor = convert_color(server_bpp, client_bpp,\n                            opaque_rect->color, mod->colormap);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_opaque_rect: nLeftRect %d nTopRect %d \"\n              \"nWidth %d nHeight %d fgcolor 0x%8.8x\",\n              opaque_rect->nLeftRect, opaque_rect->nTopRect,\n              opaque_rect->nWidth, opaque_rect->nHeight, fgcolor);\n    mod->server_set_fgcolor(mod, fgcolor);\n    mod->server_fill_rect(mod, opaque_rect->nLeftRect, opaque_rect->nTopRect,\n                          opaque_rect->nWidth, opaque_rect->nHeight);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_mem_blt(rdpContext *context, MEMBLT_ORDER *memblt)\n{\n    int id;\n    int idx;\n    struct mod *mod;\n    struct bitmap_item *bi;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_mem_blt: cacheId %d cacheIndex %d\",\n              memblt->cacheId, memblt->cacheIndex);\n\n    id = memblt->cacheId;\n    idx = memblt->cacheIndex;\n\n    if (idx == 32767) /* BITMAPCACHE_WAITING_LIST_INDEX */\n    {\n        idx = 4096 - 1;\n    }\n\n    if ((id < 0) || (id >= 4))\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_mem_blt: bad id [%d]\", id);\n        return;\n    }\n\n    if ((idx < 0) || (idx >= 4096))\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_mem_blt: bad idx [%d]\", idx);\n        return;\n    }\n\n    bi = &(mod->bitmap_cache[id][idx]);\n\n    mod->server_set_opcode(mod, memblt->bRop);\n    mod->server_paint_rect(mod, memblt->nLeftRect, memblt->nTopRect,\n                           memblt->nWidth, memblt->nHeight,\n                           bi->data, bi->width, bi->height,\n                           memblt->nXSrc, memblt->nYSrc);\n    mod->server_set_opcode(mod, 0xcc);\n\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_glyph_index(rdpContext *context, GLYPH_INDEX_ORDER *glyph_index)\n{\n    struct mod *mod;\n    int server_bpp;\n    int client_bpp;\n    int fgcolor;\n    int bgcolor;\n    int opLeft;\n    int opTop;\n    int opRight;\n    int opBottom;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_glyph_index:\");\n    server_bpp = mod->inst->settings->color_depth;\n    client_bpp = mod->bpp;\n    fgcolor = convert_color(server_bpp, client_bpp,\n                            glyph_index->foreColor, mod->colormap);\n    bgcolor = convert_color(server_bpp, client_bpp,\n                            glyph_index->backColor, mod->colormap);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_glyph_index: \"\n              \"bkLeft %d bkTop %d width %d height %d \"\n              \"opLeft %d opTop %d width %d height %d \"\n              \"cbData %d fgcolor 0x%8.8x bgcolor 0x%8.8x fOpRedundant %d\",\n              glyph_index->bkLeft, glyph_index->bkTop,\n              glyph_index->bkRight - glyph_index->bkLeft,\n              glyph_index->bkBottom - glyph_index->bkTop,\n              glyph_index->opLeft, glyph_index->opTop,\n              glyph_index->opRight - glyph_index->opLeft,\n              glyph_index->opBottom - glyph_index->opTop,\n              glyph_index->cbData, fgcolor, bgcolor, glyph_index->fOpRedundant);\n    mod->server_set_bgcolor(mod, fgcolor);\n    mod->server_set_fgcolor(mod, bgcolor);\n    opLeft = glyph_index->opLeft;\n    opTop = glyph_index->opTop;\n    opRight = glyph_index->opRight;\n    opBottom = glyph_index->opBottom;\n#if 1\n\n    /* workarounds for freerdp not using fOpRedundant in\n       glyph.c::update_gdi_glyph_index */\n    if (glyph_index->fOpRedundant)\n    {\n        opLeft = glyph_index->bkLeft;\n        opTop = glyph_index->bkTop;\n        opRight = glyph_index->bkRight;\n        opBottom = glyph_index->bkBottom;\n    }\n\n#endif\n    mod->server_draw_text(mod, glyph_index->cacheId, glyph_index->flAccel,\n                          glyph_index->fOpRedundant,\n                          glyph_index->bkLeft, glyph_index->bkTop,\n                          glyph_index->bkRight, glyph_index->bkBottom,\n                          opLeft, opTop, opRight, opBottom,\n                          glyph_index->x, glyph_index->y,\n                          (char *)(glyph_index->data), glyph_index->cbData);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_line_to(rdpContext *context, LINE_TO_ORDER *line_to)\n{\n    struct mod *mod;\n    int server_bpp;\n    int client_bpp;\n    int fgcolor;\n    int bgcolor;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_line_to:\");\n    mod->server_set_opcode(mod, line_to->bRop2);\n    server_bpp = mod->inst->settings->color_depth;\n    client_bpp = mod->bpp;\n    fgcolor = convert_color(server_bpp, client_bpp,\n                            line_to->penColor, mod->colormap);\n    bgcolor = convert_color(server_bpp, client_bpp,\n                            line_to->backColor, mod->colormap);\n    mod->server_set_fgcolor(mod, fgcolor);\n    mod->server_set_bgcolor(mod, bgcolor);\n    mod->server_set_pen(mod, line_to->penStyle, line_to->penWidth);\n    mod->server_draw_line(mod, line_to->nXStart, line_to->nYStart,\n                          line_to->nXEnd, line_to->nYEnd);\n    mod->server_set_opcode(mod, 0xcc);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_cache_bitmap(rdpContext *context, CACHE_BITMAP_ORDER *cache_bitmap_order)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"lfreerdp_cache_bitmap: - no code here\");\n}\n\n/******************************************************************************/\n/* Turn the bitmap upside down*/\nstatic void\nlfreerdp_upsidedown(uint8 *destination, CACHE_BITMAP_V2_ORDER *cache_bitmap_v2_order, int server_Bpp)\n{\n    tui8 *src;\n    tui8 *dst;\n    int line_bytes;\n    int j;\n\n    if (destination == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_upsidedown: destination pointer is NULL !!!\");\n        return;\n    }\n\n    line_bytes = server_Bpp * cache_bitmap_v2_order->bitmapWidth;\n    src = cache_bitmap_v2_order->bitmapDataStream;\n    dst = destination + ((cache_bitmap_v2_order->bitmapHeight) * line_bytes);\n\n    for (j = 0; j < cache_bitmap_v2_order->bitmapHeight; j++)\n    {\n        dst -= line_bytes;\n        g_memcpy(dst, src, line_bytes);\n        src += line_bytes;\n    }\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_cache_bitmapV2(rdpContext *context,\n                        CACHE_BITMAP_V2_ORDER *cache_bitmap_v2_order)\n{\n    char *dst_data;\n    char *dst_data1;\n    int bytes;\n    int width;\n    int height;\n    int id;\n    int idx;\n    int flags;\n    int server_bpp;\n    int server_Bpp;\n    int client_bpp;\n    struct mod *mod;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_cache_bitmapV2: %d %d 0x%8.8x compressed %d\",\n              cache_bitmap_v2_order->cacheId,\n              cache_bitmap_v2_order->cacheIndex,\n              cache_bitmap_v2_order->flags,\n              cache_bitmap_v2_order->compressed);\n\n    mod = ((struct mod_context *)context)->modi;\n    id = cache_bitmap_v2_order->cacheId;\n    idx = cache_bitmap_v2_order->cacheIndex;\n    flags = cache_bitmap_v2_order->flags;\n\n    if (flags & 0x10) /* CBR2_DO_NOT_CACHE */\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_cache_bitmapV2: CBR2_DO_NOT_CACHE\");\n        idx = 4096 - 1;\n    }\n\n    if ((id < 0) || (id >= 4))\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_cache_bitmapV2: bad id [%d]\", id);\n        return;\n    }\n\n    if ((idx < 0) || (idx >= 4096))\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_cache_bitmapV2: bad idx [%d]\", idx);\n        return;\n    }\n\n    server_bpp = mod->inst->settings->color_depth;\n    server_Bpp = (server_bpp + 7) / 8;\n    client_bpp = mod->bpp;\n\n    width = cache_bitmap_v2_order->bitmapWidth;\n    height = cache_bitmap_v2_order->bitmapHeight;\n    bytes = width * height * server_Bpp + 16;\n    dst_data = (char *)g_malloc(bytes, 0);\n\n    if (cache_bitmap_v2_order->compressed)\n    {\n        bitmap_decompress(cache_bitmap_v2_order->bitmapDataStream,\n                          (tui8 *)dst_data, width, height,\n                          cache_bitmap_v2_order->bitmapLength,\n                          server_bpp, server_bpp);\n    }\n    else\n    {\n        /* Uncompressed bitmaps are upside down */\n        lfreerdp_upsidedown((tui8 *)dst_data, cache_bitmap_v2_order, server_Bpp);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_cache_bitmapV2:  upside down progressed\");\n    }\n\n    dst_data1 = convert_bitmap(server_bpp, client_bpp, dst_data,\n                               width, height, mod->colormap);\n    g_free(mod->bitmap_cache[id][idx].data);\n    mod->bitmap_cache[id][idx].width = width;\n    mod->bitmap_cache[id][idx].height = height;\n    mod->bitmap_cache[id][idx].data = dst_data1;\n\n    if (dst_data != dst_data1)\n    {\n        g_free(dst_data);\n    }\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_cache_glyph(rdpContext *context, CACHE_GLYPH_ORDER *cache_glyph_order)\n{\n    int index;\n    GLYPH_DATA *gd;\n    struct mod *mod;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_cache_glyph: %d\", cache_glyph_order->cGlyphs);\n\n    for (index = 0; index < cache_glyph_order->cGlyphs; index++)\n    {\n        gd = cache_glyph_order->glyphData[index];\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  %d %d %d %d %d\", gd->cacheIndex, gd->x, gd->y,\n                  gd->cx, gd->cy);\n        mod->server_add_char(mod, cache_glyph_order->cacheId, gd->cacheIndex,\n                             gd->x, gd->y, gd->cx, gd->cy, (char *)(gd->aj));\n        free(gd->aj);\n        gd->aj = 0;\n        free(gd);\n        cache_glyph_order->glyphData[index] = 0;\n    }\n\n    free(cache_glyph_order->unicodeCharacters);\n    cache_glyph_order->unicodeCharacters = 0;\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_cache_brush(rdpContext *context, CACHE_BRUSH_ORDER *cache_brush_order)\n{\n    int idx;\n    int bytes;\n    int bpp;\n    int cx;\n    int cy;\n    struct mod *mod;\n\n    mod = ((struct mod_context *)context)->modi;\n    bpp = cache_brush_order->bpp;\n    cx = cache_brush_order->cx;\n    cy = cache_brush_order->cy;\n    idx = cache_brush_order->index;\n    bytes = cache_brush_order->length;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_cache_brush: bpp %d cx %d cy %d idx %d bytes %d\",\n              bpp, cx, cy, idx, bytes);\n\n    if ((idx < 0) || (idx >= 64))\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_cache_brush: error idx %d\", idx);\n        return;\n    }\n\n    if ((bpp != 1) || (cx != 8) || (cy != 8))\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_cache_brush: error unsupported brush \"\n            \"bpp %d cx %d cy %d\", bpp, cx, cy);\n        return;\n    }\n\n    mod->brush_cache[idx].bpp = bpp;\n    mod->brush_cache[idx].width = cx;\n    mod->brush_cache[idx].height = cy;\n    mod->brush_cache[idx].data = mod->brush_cache[idx].b8x8;\n\n    if (bytes > 8)\n    {\n        bytes = 8;\n    }\n\n    g_memset(mod->brush_cache[idx].data, 0, 8);\n\n    if (bytes > 0)\n    {\n        if (bytes > 8)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"lfreerdp_cache_brush: bytes too big %d\", bytes);\n            bytes = 8;\n        }\n\n        g_memcpy(mod->brush_cache[idx].data, cache_brush_order->data, bytes);\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_cache_brush: out bpp %d cx %d cy %d idx %d bytes %d\",\n              bpp, cx, cy, idx, bytes);\n\n    free(cache_brush_order->data);\n    cache_brush_order->data = 0;\n\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_pointer_position(rdpContext *context,\n                          POINTER_POSITION_UPDATE *pointer_position)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pointer_position: - no code here\");\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_pointer_system(rdpContext *context,\n                        POINTER_SYSTEM_UPDATE *pointer_system)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pointer_system: - no code here type value = %d\", pointer_system->type);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_pointer_color(rdpContext *context,\n                       POINTER_COLOR_UPDATE *pointer_color)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pointer_color: - no code here\");\n}\n\n/******************************************************************************/\nstatic int\nlfreerdp_get_pixel(void *bits, int width, int height, int bpp,\n                   int delta, int x, int y)\n{\n    int start;\n    int shift;\n    int pixel;\n    tui8 *src8;\n\n    if (bpp == 1)\n    {\n        src8 = (tui8 *)bits;\n        start = (y * delta) + x / 8;\n        shift = x % 8;\n        pixel = (src8[start] & (0x80 >> shift)) != 0;\n        return pixel ? 0xffffff : 0;\n    }\n    else if (bpp == 32)\n    {\n        src8 = (tui8 *)bits;\n        src8 += y * delta + x * 4;\n        pixel = ((int *)(src8))[0];\n        return pixel;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"lfreerdp_get_pixel: unknown bpp %d\", bpp);\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlfreerdp_set_pixel(int pixel, void *bits, int width, int height, int bpp,\n                   int delta, int x, int y)\n{\n    tui8 *dst8;\n    int start;\n    int shift;\n\n    if (bpp == 1)\n    {\n        dst8 = (tui8 *)bits;\n        start = (y * delta) + x / 8;\n        shift = x % 8;\n\n        if (pixel)\n        {\n            dst8[start] = dst8[start] | (0x80 >> shift);\n        }\n        else\n        {\n            dst8[start] = dst8[start] & ~(0x80 >> shift);\n        }\n    }\n    else if (bpp == 24)\n    {\n        dst8 = (tui8 *)bits;\n        dst8 += y * delta + x * 3;\n        dst8[0] = (pixel >> 0) & 0xff;\n        dst8[1] = (pixel >> 8) & 0xff;\n        dst8[2] = (pixel >> 16) & 0xff;\n    }\n    else if (bpp == 32)\n    {\n        dst8 = (tui8 *)bits;\n        dst8 += y * delta + x * 4;\n        ((int *)(dst8))[0] = pixel;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"lfreerdp_set_pixel: unknown bpp %d\", bpp);\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlfreerdp_convert_color_image(void *dst, int dst_width, int dst_height,\n                             int dst_bpp, int dst_delta,\n                             void *src, int src_width, int src_height,\n                             int src_bpp, int src_delta)\n{\n    int i;\n    int j;\n    int pixel;\n\n    for (j = 0; j < dst_height; j++)\n    {\n        for (i = 0; i < dst_width; i++)\n        {\n            pixel = lfreerdp_get_pixel(src, src_width, src_height, src_bpp,\n                                       src_delta, i, j);\n            lfreerdp_set_pixel(pixel, dst, dst_width, dst_height, dst_bpp,\n                               dst_delta, i, j);\n        }\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_pointer_new(rdpContext *context,\n                     POINTER_NEW_UPDATE *pointer_new)\n{\n    struct mod *mod;\n    int index;\n    int bytes_per_pixel;\n    int bits_per_pixel;\n    tui8 *dst;\n    tui8 *src;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pointer_new:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  bpp %d\", pointer_new->xorBpp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  width %d height %d\", pointer_new->colorPtrAttr.width,\n              pointer_new->colorPtrAttr.height);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  lengthXorMask %d lengthAndMask %d\",\n              pointer_new->colorPtrAttr.lengthXorMask,\n              pointer_new->colorPtrAttr.lengthAndMask);\n\n    index = pointer_new->colorPtrAttr.cacheIndex;\n\n    if (index >= 32)\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_pointer_new: pointer index too big\");\n        return ;\n    }\n\n    if (pointer_new->xorBpp == 1 &&\n            pointer_new->colorPtrAttr.width == 32 &&\n            pointer_new->colorPtrAttr.height == 32)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pointer_new:\");\n        mod->pointer_cache[index].hotx = pointer_new->colorPtrAttr.xPos;\n        mod->pointer_cache[index].hoty = pointer_new->colorPtrAttr.yPos;\n        mod->pointer_cache[index].bpp = 0;\n        dst = (tui8 *)(mod->pointer_cache[index].data);\n        dst += 32 * 32 * 3 - 32 * 3;\n        src = pointer_new->colorPtrAttr.xorMaskData;\n        lfreerdp_convert_color_image(dst, 32, 32, 24, 32 * -3,\n                                     src, 32, 32, 1, 32 / 8);\n        dst = (tui8 *)(mod->pointer_cache[index].mask);\n        dst += ( 32 * 32 / 8) - (32 / 8);\n        src = pointer_new->colorPtrAttr.andMaskData;\n        lfreerdp_convert_color_image(dst, 32, 32, 1, 32 / -8,\n                                     src, 32, 32, 1, 32 / 8);\n    }\n    else if (pointer_new->xorBpp >= 8 &&\n             pointer_new->colorPtrAttr.width == 32 &&\n             pointer_new->colorPtrAttr.height == 32)\n    {\n        bytes_per_pixel = (pointer_new->xorBpp + 7) / 8;\n        bits_per_pixel = pointer_new->xorBpp;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pointer_new: bpp %d Bpp %d\", bits_per_pixel,\n                  bytes_per_pixel);\n        mod->pointer_cache[index].hotx = pointer_new->colorPtrAttr.xPos;\n        mod->pointer_cache[index].hoty = pointer_new->colorPtrAttr.yPos;\n        mod->pointer_cache[index].bpp = bits_per_pixel;\n        memcpy(mod->pointer_cache[index].data,\n               pointer_new->colorPtrAttr.xorMaskData,\n               32 * 32 * bytes_per_pixel);\n        memcpy(mod->pointer_cache[index].mask,\n               pointer_new->colorPtrAttr.andMaskData,\n               32 * (32 / 8));\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"lfreerdp_pointer_new: error bpp %d width %d height %d index: %d\",\n            pointer_new->xorBpp, pointer_new->colorPtrAttr.width,\n            pointer_new->colorPtrAttr.height, index);\n    }\n\n    mod->server_set_pointer_ex(mod, mod->pointer_cache[index].hotx,\n                               mod->pointer_cache[index].hoty,\n                               mod->pointer_cache[index].data,\n                               mod->pointer_cache[index].mask,\n                               mod->pointer_cache[index].bpp);\n\n    free(pointer_new->colorPtrAttr.xorMaskData);\n    pointer_new->colorPtrAttr.xorMaskData = 0;\n    free(pointer_new->colorPtrAttr.andMaskData);\n    pointer_new->colorPtrAttr.andMaskData = 0;\n\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_pointer_cached(rdpContext *context,\n                        POINTER_CACHED_UPDATE *pointer_cached)\n{\n    struct mod *mod;\n    int index;\n\n    mod = ((struct mod_context *)context)->modi;\n    index = pointer_cached->cacheIndex;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pointer_cached:%d\", index);\n    mod->server_set_pointer_ex(mod, mod->pointer_cache[index].hotx,\n                               mod->pointer_cache[index].hoty,\n                               mod->pointer_cache[index].data,\n                               mod->pointer_cache[index].mask,\n                               mod->pointer_cache[index].bpp);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_polygon_cb(rdpContext *context, POLYGON_CB_ORDER *polygon_cb)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_polygon_cb called:- not supported!!!!!!!!!!!!!!!!!!!!\");\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_polygon_sc(rdpContext *context, POLYGON_SC_ORDER *polygon_sc)\n{\n    struct mod *mod;\n    int i;\n    struct\n    {\n        short x, y;\n    } points[4];\n    int fgcolor;\n    int server_bpp, client_bpp;\n\n    mod = ((struct mod_context *)context)->modi;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_polygon_sc :%d(points) %d(color) %d(fillmode) \"\n              \"%d(bRop) %d(cbData) %d(x) %d(y)\",\n              polygon_sc->nDeltaEntries, polygon_sc->brushColor,\n              polygon_sc->fillMode, polygon_sc->bRop2,\n              polygon_sc->cbData, polygon_sc->xStart,\n              polygon_sc->yStart);\n\n    if (polygon_sc->nDeltaEntries == 3)\n    {\n        server_bpp = mod->inst->settings->color_depth;\n        client_bpp = mod->bpp;\n\n        points[0].x = polygon_sc->xStart;\n        points[0].y = polygon_sc->yStart;\n\n        for (i = 0; i < polygon_sc->nDeltaEntries; i++)\n        {\n            points[i + 1].x = 0; // polygon_sc->points[i].x;\n            points[i + 1].y = 0; // polygon_sc->points[i].y;\n        }\n\n        fgcolor = convert_color(server_bpp, client_bpp,\n                                polygon_sc->brushColor, mod->colormap);\n\n        mod->server_set_opcode(mod, polygon_sc->bRop2);\n        mod->server_set_bgcolor(mod, 255);\n        mod->server_set_fgcolor(mod, fgcolor);\n        mod->server_set_pen(mod, 1, 1); // style, width\n        // TODO replace with correct brush; this is a workaround\n        // This workaround handles the text cursor in microsoft word.\n        mod->server_draw_line(mod, polygon_sc->xStart, polygon_sc->yStart, polygon_sc->xStart, polygon_sc->yStart + points[2].y);\n        //        mod->server_fill_rect(mod, points[0].x, points[0].y,\n        //                         points[0].x-points[3].x, points[0].y-points[2].y);\n        //      mod->server_set_brush(mod,); // howto use this on our indata??\n        mod->server_set_opcode(mod, 0xcc);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"Not handled number of points in lfreerdp_polygon_sc\");\n    }\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_synchronize(rdpContext *context)\n{\n    /* Uncomment these two lines when needed */\n#if 0\n    struct mod *mod;\n    mod = ((struct mod_context *)context)->modi;\n#endif\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_synchronize received - not handled\");\n}\n\n/******************************************************************************/\nstatic boolean\nlfreerdp_pre_connect(freerdp *instance)\n{\n#define MAX_FREERDP_CHANNELS \\\n    (sizeof(instance->settings->channels) / \\\n     sizeof(instance->settings->channels[0]))\n\n    struct mod *mod;\n    int index;\n    int error;\n    int num_chans;\n    int target_chan;\n    int ch_flags;\n    char ch_name[CHANNEL_NAME_LEN + 1];\n    const char *ch_names[MAX_FREERDP_CHANNELS];\n    char *dst_ch_name;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"lfreerdp_pre_connect:\");\n    mod = ((struct mod_context *)(instance->context))->modi;\n    verifyColorMap(mod);\n\n    num_chans = mod->server_get_channel_count(mod);\n    if (num_chans < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_pre_connect: Can't get channel count\");\n        num_chans = 0;\n    }\n\n    target_chan = 0;\n    for (index = 0 ; index < num_chans; ++index)\n    {\n        error = mod->server_query_channel(mod, index, ch_name, &ch_flags);\n        if (error == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_pre_connect: \"\n                      \"got channel [%s], id [%d], flags [0x%8.8x]\",\n                      ch_name, index, ch_flags);\n\n            if (g_strcmp(ch_name, DRDYNVC_SVC_CHANNEL_NAME) == 0)\n            {\n                /* xrdp currently reserves dynamic channels for its\n                 * exclusive use (e.g. for GFX support) */\n                LOG(LOG_LEVEL_INFO, \"Channel '%s' not passed to module\",\n                    ch_name);\n            }\n            else if (target_chan < MAX_FREERDP_CHANNELS)\n            {\n                dst_ch_name = instance->settings->channels[target_chan].name;\n                ch_names[target_chan] = dst_ch_name;\n                g_memset(dst_ch_name, 0, CHANNEL_NAME_LEN + 1);\n                g_snprintf(dst_ch_name, CHANNEL_NAME_LEN + 1, \"%s\", ch_name);\n                instance->settings->channels[target_chan].options = ch_flags;\n                ++target_chan;\n            }\n        }\n    }\n\n    g_strnjoin(ch_name, sizeof(ch_name), \",\", ch_names, target_chan);\n    LOG(LOG_LEVEL_INFO, \"Static channels (from %d) passed to module : %s\",\n        num_chans, ch_name);\n\n    instance->settings->num_channels = target_chan;\n\n    instance->settings->offscreen_bitmap_cache = 0;\n    instance->settings->draw_nine_grid = 0;\n\n    instance->settings->glyph_cache = true;\n    /* GLYPH_SUPPORT_FULL and GLYPH_SUPPORT_PARTIAL seem to be the same */\n    /* disabled as workaround for corrupted display like black bars left of cmd with W2K8 */\n    /* instance->settings->glyphSupportLevel = GLYPH_SUPPORT_FULL; */\n    instance->settings->glyphSupportLevel = GLYPH_SUPPORT_NONE;\n\n    instance->settings->order_support[NEG_DSTBLT_INDEX] = 1; /* 0x00 */\n    instance->settings->order_support[NEG_PATBLT_INDEX] = 1;\n    instance->settings->order_support[NEG_SCRBLT_INDEX] = 1;\n    instance->settings->order_support[NEG_MEMBLT_INDEX] = 1;\n    instance->settings->order_support[NEG_MEM3BLT_INDEX] = 0;\n    instance->settings->order_support[NEG_ATEXTOUT_INDEX] = 0;\n    instance->settings->order_support[NEG_AEXTTEXTOUT_INDEX] = 0;\n    instance->settings->order_support[NEG_DRAWNINEGRID_INDEX] = 0;\n    instance->settings->order_support[NEG_LINETO_INDEX] = 1; /* 0x08 */\n    instance->settings->order_support[NEG_MULTI_DRAWNINEGRID_INDEX] = 0;\n    instance->settings->order_support[NEG_OPAQUE_RECT_INDEX] = 1;\n    instance->settings->order_support[NEG_SAVEBITMAP_INDEX] = 0;\n    instance->settings->order_support[NEG_WTEXTOUT_INDEX] = 0;\n    instance->settings->order_support[NEG_MEMBLT_V2_INDEX] = 1;\n    instance->settings->order_support[NEG_MEM3BLT_V2_INDEX] = 0;\n    instance->settings->order_support[NEG_MULTIDSTBLT_INDEX] = 0;\n    instance->settings->order_support[NEG_MULTIPATBLT_INDEX] = 0; /* 0x10 */\n    instance->settings->order_support[NEG_MULTISCRBLT_INDEX] = 0;\n    instance->settings->order_support[NEG_MULTIOPAQUERECT_INDEX] = 0;\n    instance->settings->order_support[NEG_FAST_INDEX_INDEX] = 0;\n    instance->settings->order_support[NEG_POLYGON_SC_INDEX] = 0;\n    instance->settings->order_support[NEG_POLYGON_CB_INDEX] = 0;\n    instance->settings->order_support[NEG_POLYLINE_INDEX] = 0;\n    /* 0x17 missing */\n    instance->settings->order_support[NEG_FAST_GLYPH_INDEX] = 0; /* 0x18 */\n    instance->settings->order_support[NEG_ELLIPSE_SC_INDEX] = 0;\n    instance->settings->order_support[NEG_ELLIPSE_CB_INDEX] = 0;\n    /* disabled as workaround for corrupted display like black bars left of cmd with W2K8 */\n    /* instance->settings->order_support[NEG_GLYPH_INDEX_INDEX] = 1; */\n    instance->settings->order_support[NEG_GLYPH_INDEX_INDEX] = 0;\n\n    instance->settings->order_support[NEG_GLYPH_WEXTTEXTOUT_INDEX] = 0;\n    instance->settings->order_support[NEG_GLYPH_WLONGTEXTOUT_INDEX] = 0;\n    instance->settings->order_support[NEG_GLYPH_WLONGEXTTEXTOUT_INDEX] = 0;\n    /* 0x1F missing*/\n\n    instance->settings->bitmap_cache = 1;\n    instance->settings->bitmapCacheV2NumCells = 3; // 5;\n    instance->settings->bitmapCacheV2CellInfo[0].numEntries = 600; // 0x78;\n    instance->settings->bitmapCacheV2CellInfo[0].persistent = 0;\n    instance->settings->bitmapCacheV2CellInfo[1].numEntries = 600; //0x78; // 600;\n    instance->settings->bitmapCacheV2CellInfo[1].persistent = 0;\n    instance->settings->bitmapCacheV2CellInfo[2].numEntries = 2048; //0x150; // 2048;\n    instance->settings->bitmapCacheV2CellInfo[2].persistent = 0;\n    instance->settings->bitmapCacheV2CellInfo[3].numEntries = 4096; // 4096;\n    instance->settings->bitmapCacheV2CellInfo[3].persistent = 0;\n    instance->settings->bitmapCacheV2CellInfo[4].numEntries = 2048; // 2048;\n    instance->settings->bitmapCacheV2CellInfo[4].persistent = 0;\n\n    instance->settings->bitmap_cache_v3 = 1;\n\n    instance->settings->username = g_strdup(mod->username);\n    instance->settings->password = g_strdup(mod->password);\n    instance->settings->domain = g_strdup(mod->domain);\n\n    if (mod->client_info.rail_enable && (mod->client_info.rail_support_level > 0))\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO, \"Railsupport !!!!!!!!!!!!!!!!!!\");\n        instance->settings->remote_app = 1;\n        instance->settings->rail_langbar_supported = 1;\n        instance->settings->workarea = 1;\n        instance->settings->performance_flags = PERF_DISABLE_WALLPAPER | PERF_DISABLE_FULLWINDOWDRAG;\n        instance->settings->num_icon_caches = mod->client_info.wnd_num_icon_caches;\n        instance->settings->num_icon_cache_entries = mod->client_info.wnd_num_icon_cache_entries;\n\n\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"Special PerformanceFlags changed\");\n        instance->settings->performance_flags = PERF_DISABLE_WALLPAPER |\n                                                PERF_DISABLE_FULLWINDOWDRAG | PERF_DISABLE_MENUANIMATIONS |\n                                                PERF_DISABLE_THEMING;\n        // | PERF_DISABLE_CURSOR_SHADOW | PERF_DISABLE_CURSORSETTINGS;\n    }\n\n    /* Allow users or administrators to configure the mstsc experience settings. #1903 */\n\n    if ((mod->allow_client_experiencesettings == 1) &&\n            (mod->client_info.mcs_connection_type == CONNECTION_TYPE_AUTODETECT))\n    {\n        /* auto-detect not yet supported - use default performance settings */\n    }\n    else if (mod->allow_client_experiencesettings == 1)\n    {\n        instance->settings->performance_flags =\n            (mod->client_info.rdp5_performanceflags &\n             /* Mask to avoid accepting invalid flags. */\n             (PERF_DISABLE_WALLPAPER |\n              PERF_DISABLE_FULLWINDOWDRAG |\n              PERF_DISABLE_MENUANIMATIONS |\n              PERF_DISABLE_THEMING |\n              PERF_DISABLE_CURSOR_SHADOW |\n              PERF_DISABLE_CURSORSETTINGS |\n              PERF_ENABLE_FONT_SMOOTHING |\n              PERF_ENABLE_DESKTOP_COMPOSITION));\n\n        LOG(LOG_LEVEL_DEBUG, \"RDP client experience settings, \"\n            \"rdp5_performance_flags:[0x%08x], \"\n            \"masked performance_flags:[0x%08x]\",\n            mod->client_info.rdp5_performanceflags,\n            instance->settings->performance_flags);\n\n        if (mod->client_info.rail_enable &&\n                (mod->client_info.rail_support_level > 0))\n        {\n            instance->settings->performance_flags |= (PERF_DISABLE_WALLPAPER |\n                PERF_DISABLE_FULLWINDOWDRAG);\n            LOG(LOG_LEVEL_DEBUG, \"Add in performance setting for Railsupport:\"\n                \"[0x%08x]\", PERF_DISABLE_WALLPAPER |\n                PERF_DISABLE_FULLWINDOWDRAG);\n        }\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"before overriding performance_flags:[0x%08x]\",\n        instance->settings->performance_flags);\n    LOG(LOG_LEVEL_DEBUG, \"perf_settings_override_mask:[0x%08x], \"\n        \"perf_settings_values_mask:[0x%08x]\",\n        mod->perf_settings_override_mask,\n        mod->perf_settings_values_mask);\n\n    /* Clear bits for any overridden performance settings */\n    instance->settings->performance_flags &= ~mod->perf_settings_override_mask;\n\n    /* Add in overridden performance settings */\n    instance->settings->performance_flags |= mod->perf_settings_values_mask;\n\n    LOG(LOG_LEVEL_DEBUG, \"final performance_flags:[0x%08x]\",\n        instance->settings->performance_flags);\n\n    instance->settings->compression = 0;\n    instance->settings->ignore_certificate = 1;\n\n    // Multi Monitor Settings\n    const struct display_size_description *display_sizes =\n            &mod->client_info.display_sizes;\n    instance->settings->num_monitors = display_sizes->monitorCount;\n\n    for (index = 0; index < display_sizes->monitorCount; index++)\n    {\n        instance->settings->monitors[index].x = display_sizes->minfo[index].left;\n        instance->settings->monitors[index].y = display_sizes->minfo[index].top;\n        instance->settings->monitors[index].width = display_sizes->minfo[index].right;\n        instance->settings->monitors[index].height = display_sizes->minfo[index].bottom;\n        instance->settings->monitors[index].is_primary = display_sizes->minfo[index].is_primary;\n    }\n\n    instance->update->BeginPaint = lfreerdp_begin_paint;\n    instance->update->EndPaint = lfreerdp_end_paint;\n    instance->update->SetBounds = lfreerdp_set_bounds;\n    instance->update->BitmapUpdate = lfreerdp_bitmap_update;\n    instance->update->Synchronize = lfreerdp_synchronize;\n    instance->update->primary->DstBlt = lfreerdp_dst_blt;\n    instance->update->primary->PatBlt = lfreerdp_pat_blt;\n    instance->update->primary->ScrBlt = lfreerdp_scr_blt;\n    instance->update->primary->OpaqueRect = lfreerdp_opaque_rect;\n    instance->update->primary->MemBlt = lfreerdp_mem_blt;\n    instance->update->primary->GlyphIndex = lfreerdp_glyph_index;\n    instance->update->primary->LineTo = lfreerdp_line_to;\n    instance->update->primary->PolygonSC = lfreerdp_polygon_sc ;\n    instance->update->primary->PolygonCB = lfreerdp_polygon_cb;\n    instance->update->secondary->CacheBitmap = lfreerdp_cache_bitmap;\n    instance->update->secondary->CacheBitmapV2 = lfreerdp_cache_bitmapV2;\n    instance->update->secondary->CacheGlyph = lfreerdp_cache_glyph;\n    instance->update->secondary->CacheBrush = lfreerdp_cache_brush;\n\n    instance->update->pointer->PointerPosition = lfreerdp_pointer_position;\n    instance->update->pointer->PointerSystem = lfreerdp_pointer_system;\n    instance->update->pointer->PointerColor = lfreerdp_pointer_color;\n    instance->update->pointer->PointerNew = lfreerdp_pointer_new;\n    instance->update->pointer->PointerCached = lfreerdp_pointer_cached;\n\n    if ((mod->username[0] != 0) && (mod->password[0] != 0))\n    {\n        /* since we have username and password, we can try nla */\n        instance->settings->nla_security = 1;\n    }\n    else\n    {\n        instance->settings->nla_security = 0;\n    }\n\n    return 1;\n}\n\n/*****************************************************************************/\nstatic void\nlrail_WindowCreate(rdpContext *context, WINDOW_ORDER_INFO *orderInfo,\n                   WINDOW_STATE_ORDER *window_state)\n{\n    int index;\n    struct mod *mod;\n    struct rail_window_state_order wso;\n    UNICONV *uniconv;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_WindowCreate:\");\n    uniconv = freerdp_uniconv_new();\n    mod = ((struct mod_context *)context)->modi;\n    memset(&wso, 0, sizeof(wso));\n    /* copy the window state order */\n    wso.owner_window_id = window_state->ownerWindowId;\n    wso.style = window_state->style;\n    wso.extended_style = window_state->extendedStyle;\n    wso.show_state = window_state->showState;\n\n    if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE)\n    {\n        wso.title_info = freerdp_uniconv_in(uniconv,\n                                            window_state->titleInfo.string, window_state->titleInfo.length);\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lrail_WindowCreate: %s\", wso.title_info);\n    wso.client_offset_x = window_state->clientOffsetX;\n    wso.client_offset_y = window_state->clientOffsetY;\n    wso.client_area_width = window_state->clientAreaWidth;\n    wso.client_area_height = window_state->clientAreaHeight;\n    wso.rp_content = window_state->RPContent;\n    wso.root_parent_handle = window_state->rootParentHandle;\n    wso.window_offset_x = window_state->windowOffsetX;\n    wso.window_offset_y = window_state->windowOffsetY;\n    wso.window_client_delta_x = window_state->windowClientDeltaX;\n    wso.window_client_delta_y = window_state->windowClientDeltaY;\n    wso.window_width = window_state->windowWidth;\n    wso.window_height = window_state->windowHeight;\n    wso.num_window_rects = window_state->numWindowRects;\n\n    if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS)\n    {\n        wso.window_rects = (struct rail_window_rect *)\n                           g_malloc(sizeof(struct rail_window_rect) * wso.num_window_rects, 0);\n\n        for (index = 0; index < wso.num_window_rects; index++)\n        {\n            wso.window_rects[index].left = window_state->windowRects[index].left;\n            wso.window_rects[index].top = window_state->windowRects[index].top;\n            wso.window_rects[index].right = window_state->windowRects[index].right;\n            wso.window_rects[index].bottom = window_state->windowRects[index].bottom;\n        }\n    }\n\n    wso.visible_offset_x = window_state->visibleOffsetX;\n    wso.visible_offset_y = window_state->visibleOffsetY;\n    wso.num_visibility_rects = window_state->numVisibilityRects;\n\n    if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY)\n    {\n        wso.visibility_rects = (struct rail_window_rect *)\n                               g_malloc(sizeof(struct rail_window_rect) * wso.num_visibility_rects, 0);\n\n        for (index = 0; index < wso.num_visibility_rects; index++)\n        {\n            wso.visibility_rects[index].left = window_state->visibilityRects[index].left;\n            wso.visibility_rects[index].top = window_state->visibilityRects[index].top;\n            wso.visibility_rects[index].right = window_state->visibilityRects[index].right;\n            wso.visibility_rects[index].bottom = window_state->visibilityRects[index].bottom;\n        }\n    }\n\n    mod->server_window_new_update(mod, orderInfo->windowId, &wso,\n                                  orderInfo->fieldFlags);\n\n    free(wso.title_info);\n    g_free(wso.window_rects);\n    g_free(wso.visibility_rects);\n}\n\n/*****************************************************************************/\nstatic void\nlrail_WindowUpdate(rdpContext *context, WINDOW_ORDER_INFO *orderInfo,\n                   WINDOW_STATE_ORDER *window_state)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_WindowUpdate:\");\n    lrail_WindowCreate(context, orderInfo, window_state);\n}\n\n/*****************************************************************************/\nstatic void\nlrail_WindowDelete(rdpContext *context, WINDOW_ORDER_INFO *orderInfo)\n{\n    struct mod *mod;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_WindowDelete:\");\n    mod = ((struct mod_context *)context)->modi;\n    mod->server_window_delete(mod, orderInfo->windowId);\n}\n\n/*****************************************************************************/\nstatic void\nlrail_WindowIcon(rdpContext *context, WINDOW_ORDER_INFO *orderInfo,\n                 WINDOW_ICON_ORDER *window_icon)\n{\n    struct mod *mod;\n    struct rail_icon_info rii;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_WindowIcon:\");\n    mod = ((struct mod_context *)context)->modi;\n    memset(&rii, 0, sizeof(rii));\n    rii.bpp = window_icon->iconInfo->bpp;\n    rii.width = window_icon->iconInfo->width;\n    rii.height = window_icon->iconInfo->height;\n    rii.cmap_bytes = window_icon->iconInfo->cbColorTable;\n    rii.mask_bytes = window_icon->iconInfo->cbBitsMask;\n    rii.data_bytes = window_icon->iconInfo->cbBitsColor;\n    rii.mask = (char *)(window_icon->iconInfo->bitsMask);\n    rii.cmap = (char *)(window_icon->iconInfo->colorTable);\n    rii.data = (char *)(window_icon->iconInfo->bitsColor);\n    mod->server_window_icon(mod, orderInfo->windowId,\n                            window_icon->iconInfo->cacheEntry,\n                            window_icon->iconInfo->cacheId, &rii,\n                            orderInfo->fieldFlags);\n}\n\n/*****************************************************************************/\nstatic void\nlrail_WindowCachedIcon(rdpContext *context, WINDOW_ORDER_INFO *orderInfo,\n                       WINDOW_CACHED_ICON_ORDER *window_cached_icon)\n{\n    struct mod *mod;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_WindowCachedIcon:\");\n    mod = ((struct mod_context *)context)->modi;\n    mod->server_window_cached_icon(mod, orderInfo->windowId,\n                                   window_cached_icon->cachedIcon.cacheEntry,\n                                   window_cached_icon->cachedIcon.cacheId,\n                                   orderInfo->fieldFlags);\n}\n\n/*****************************************************************************/\nstatic void\nlrail_NotifyIconCreate(rdpContext *context, WINDOW_ORDER_INFO *orderInfo,\n                       NOTIFY_ICON_STATE_ORDER *notify_icon_state)\n{\n    struct mod *mod;\n    struct rail_notify_state_order rnso;\n    UNICONV *uniconv;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_NotifyIconCreate:\");\n    uniconv = freerdp_uniconv_new();\n    mod = ((struct mod_context *)context)->modi;\n\n    memset(&rnso, 0, sizeof(rnso));\n    rnso.version = notify_icon_state->version;\n\n    if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_TIP)\n    {\n        rnso.tool_tip = freerdp_uniconv_in(uniconv,\n                                           notify_icon_state->toolTip.string, notify_icon_state->toolTip.length);\n    }\n\n    if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP)\n    {\n        rnso.infotip.timeout = notify_icon_state->infoTip.timeout;\n        rnso.infotip.flags = notify_icon_state->infoTip.flags;\n        rnso.infotip.text = freerdp_uniconv_in(uniconv,\n                                               notify_icon_state->infoTip.text.string,\n                                               notify_icon_state->infoTip.text.length);\n        rnso.infotip.title = freerdp_uniconv_in(uniconv,\n                                                notify_icon_state->infoTip.title.string,\n                                                notify_icon_state->infoTip.title.length);\n    }\n\n    rnso.state = notify_icon_state->state;\n    rnso.icon_cache_entry = notify_icon_state->icon.cacheEntry;\n    rnso.icon_cache_id = notify_icon_state->icon.cacheId;\n\n    rnso.icon_info.bpp = notify_icon_state->icon.bpp;\n    rnso.icon_info.width = notify_icon_state->icon.width;\n    rnso.icon_info.height = notify_icon_state->icon.height;\n    rnso.icon_info.cmap_bytes = notify_icon_state->icon.cbColorTable;\n    rnso.icon_info.mask_bytes = notify_icon_state->icon.cbBitsMask;\n    rnso.icon_info.data_bytes = notify_icon_state->icon.cbBitsColor;\n    rnso.icon_info.mask = (char *)(notify_icon_state->icon.bitsMask);\n    rnso.icon_info.cmap = (char *)(notify_icon_state->icon.colorTable);\n    rnso.icon_info.data = (char *)(notify_icon_state->icon.bitsColor);\n\n    mod->server_notify_new_update(mod, orderInfo->windowId,\n                                  orderInfo->notifyIconId,\n                                  &rnso, orderInfo->fieldFlags);\n\n    free(rnso.tool_tip);\n    free(rnso.infotip.text);\n    free(rnso.infotip.title);\n}\n\n/*****************************************************************************/\nstatic void\nlrail_NotifyIconUpdate(rdpContext *context, WINDOW_ORDER_INFO *orderInfo,\n                       NOTIFY_ICON_STATE_ORDER *notify_icon_state)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_NotifyIconUpdate:\");\n    lrail_NotifyIconCreate(context, orderInfo, notify_icon_state);\n}\n\n/*****************************************************************************/\nstatic void\nlrail_NotifyIconDelete(rdpContext *context, WINDOW_ORDER_INFO *orderInfo)\n{\n    struct mod *mod;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_NotifyIconDelete:\");\n    mod = ((struct mod_context *)context)->modi;\n    mod->server_notify_delete(mod, orderInfo->windowId,\n                              orderInfo->notifyIconId);\n}\n\n/*****************************************************************************/\nstatic void\nlrail_MonitoredDesktop(rdpContext *context, WINDOW_ORDER_INFO *orderInfo,\n                       MONITORED_DESKTOP_ORDER *monitored_desktop)\n{\n    int index;\n    struct mod *mod;\n    struct rail_monitored_desktop_order rmdo;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_MonitoredDesktop:\");\n    mod = ((struct mod_context *)context)->modi;\n    memset(&rmdo, 0, sizeof(rmdo));\n    rmdo.active_window_id = monitored_desktop->activeWindowId;\n    rmdo.num_window_ids = monitored_desktop->numWindowIds;\n\n    if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ZORDER)\n    {\n        if (rmdo.num_window_ids > 0)\n        {\n            rmdo.window_ids = (int *)g_malloc(sizeof(int) * rmdo.num_window_ids, 0);\n\n            for (index = 0; index < rmdo.num_window_ids; index++)\n            {\n                rmdo.window_ids[index] = monitored_desktop->windowIds[index];\n            }\n        }\n    }\n\n    mod->server_monitored_desktop(mod, &rmdo, orderInfo->fieldFlags);\n    g_free(rmdo.window_ids);\n}\n\n/*****************************************************************************/\nstatic void\nlrail_NonMonitoredDesktop(rdpContext *context, WINDOW_ORDER_INFO *orderInfo)\n{\n    struct mod *mod;\n    struct rail_monitored_desktop_order rmdo;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lrail_NonMonitoredDesktop:\");\n    mod = ((struct mod_context *)context)->modi;\n    memset(&rmdo, 0, sizeof(rmdo));\n    mod->server_monitored_desktop(mod, &rmdo, orderInfo->fieldFlags);\n}\n\n/******************************************************************************/\nstatic boolean\nlfreerdp_post_connect(freerdp *instance)\n{\n    struct mod *mod;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_post_connect:\");\n    mod = ((struct mod_context *)(instance->context))->modi;\n    g_memset(mod->password, 0, sizeof(mod->password));\n\n    mod->inst->update->window->WindowCreate = lrail_WindowCreate;\n    mod->inst->update->window->WindowUpdate = lrail_WindowUpdate;\n    mod->inst->update->window->WindowDelete = lrail_WindowDelete;\n    mod->inst->update->window->WindowIcon = lrail_WindowIcon;\n    mod->inst->update->window->WindowCachedIcon = lrail_WindowCachedIcon;\n    mod->inst->update->window->NotifyIconCreate = lrail_NotifyIconCreate;\n    mod->inst->update->window->NotifyIconUpdate = lrail_NotifyIconUpdate;\n    mod->inst->update->window->NotifyIconDelete = lrail_NotifyIconDelete;\n    mod->inst->update->window->MonitoredDesktop = lrail_MonitoredDesktop;\n    mod->inst->update->window->NonMonitoredDesktop = lrail_NonMonitoredDesktop;\n\n    return 1;\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_context_new(freerdp *instance, rdpContext *context)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"lfreerdp_context_new: %p\", context);\n}\n\n/******************************************************************************/\nstatic void\nlfreerdp_context_free(freerdp *instance, rdpContext *context)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"lfreerdp_context_free: - no code here\");\n}\n\n/******************************************************************************/\nstatic int\nlfreerdp_receive_channel_data(freerdp *instance, int channelId, uint8 *data,\n                              int size, int flags, int total_size)\n{\n    struct mod *mod;\n    int lchid;\n    int index;\n    int error;\n\n    mod = ((struct mod_context *)(instance->context))->modi;\n    lchid = -1;\n\n    for (index = 0; index < instance->settings->num_channels; index++)\n    {\n        if (instance->settings->channels[index].channel_id == channelId)\n        {\n            lchid = index;\n            break;\n        }\n    }\n\n    if (lchid >= 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_receive_channel_data: server to client, chanid: %d\", lchid);\n        error = mod->server_send_to_channel(mod, lchid, (char *)data, size,\n                                            total_size, flags);\n\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"lfreerdp_receive_channel_data: error %d\", error);\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"lfreerdp_receive_channel_data: bad lchid\");\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic boolean\nlfreerdp_authenticate(freerdp *instance, char **username,\n                      char **password, char **domain)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_authenticate: - no code here\");\n    return 1;\n}\n\n/******************************************************************************/\nstatic boolean\nlfreerdp_verify_certificate(freerdp *instance, char *subject, char *issuer,\n                            char *fingerprint)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_verify_certificate: - no code here\");\n    return 1;\n}\n\n/******************************************************************************/\nstatic int\nlfreerdp_session_info(freerdp *instance, uint8 *data, int data_bytes)\n{\n    struct mod *mod;\n    int error;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lfreerdp_session_info:\");\n    error = 0;\n    mod = ((struct mod_context *)(instance->context))->modi;\n    if (mod != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lfreerdp_session_info: mod->server_session_info %p\",\n                  mod->server_session_info);\n        if (mod->server_session_info != 0)\n        {\n            error = mod->server_session_info(mod, (char *)data, data_bytes);\n        }\n    }\n    return error;\n}\n\n/******************************************************************************/\ntintptr EXPORT_CC\nmod_init(void)\n{\n    struct mod *mod;\n    modContext *lcon;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"mod_init:\");\n    mod = (struct mod *)g_malloc(sizeof(struct mod), 1);\n    freerdp_get_version(&(mod->vmaj), &(mod->vmin), &(mod->vrev));\n    LOG(LOG_LEVEL_INFO, \"  FreeRDP version major %d minor %d revision %d\",\n        mod->vmaj, mod->vmin, mod->vrev);\n    mod->size = sizeof(struct mod);\n    mod->version = CURRENT_MOD_VER;\n    mod->handle = (tintptr) mod;\n    mod->mod_connect = lxrdp_connect;\n    mod->mod_start = lxrdp_start;\n    mod->mod_event = lxrdp_event;\n    mod->mod_signal = lxrdp_signal;\n    mod->mod_end = lxrdp_end;\n    mod->mod_set_param = lxrdp_set_param;\n    mod->mod_session_change = lxrdp_session_change;\n    mod->mod_get_wait_objs = lxrdp_get_wait_objs;\n    mod->mod_check_wait_objs = lxrdp_check_wait_objs;\n    mod->mod_frame_ack = lxrdp_frame_ack;\n    mod->mod_suppress_output = lxrdp_suppress_output;\n    mod->mod_server_version_message = lxrdp_server_version_message;\n    mod->mod_server_monitor_resize = lxrdp_server_monitor_resize;\n    mod->mod_server_monitor_full_invalidate = lxrdp_server_monitor_full_invalidate;\n\n    mod->inst = freerdp_new();\n    mod->inst->PreConnect = lfreerdp_pre_connect;\n    mod->inst->PostConnect = lfreerdp_post_connect;\n    mod->inst->context_size = sizeof(modContext);\n    mod->inst->ContextNew = lfreerdp_context_new;\n    mod->inst->ContextFree = lfreerdp_context_free;\n    mod->inst->ReceiveChannelData = lfreerdp_receive_channel_data;\n    mod->inst->Authenticate = lfreerdp_authenticate;\n    mod->inst->VerifyCertificate = lfreerdp_verify_certificate;\n#if defined(VERSION_STRUCT_RDP_FREERDP)\n#if VERSION_STRUCT_RDP_FREERDP > 0\n    mod->inst->SessionInfo = lfreerdp_session_info;\n#endif\n#endif\n\n    freerdp_context_new(mod->inst);\n\n    lcon = (modContext *)(mod->inst->context);\n    lcon->modi = mod;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"mod_init: mod %p\", mod);\n\n    return (tintptr) mod;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nmod_exit(tintptr handle)\n{\n    struct mod *mod = (struct mod *) handle;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"mod_exit:\");\n\n    if (mod == 0)\n    {\n        return 0;\n    }\n\n    if (mod->inst == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"mod_exit - null pointer for inst:\");\n        g_free(mod);\n        return 0 ;\n    }\n\n    freerdp_disconnect(mod->inst);\n\n    if ((mod->vmaj == 1) && (mod->vmin == 0) && (mod->vrev == 1))\n    {\n        /* this version has a bug with double free in freerdp_free */\n    }\n    else\n    {\n        freerdp_context_free(mod->inst);\n    }\n\n    freerdp_free(mod->inst);\n    g_free(mod);\n    return 0;\n}\n"
  },
  {
    "path": "neutrinordp/xrdp-neutrinordp.h",
    "content": "/**\n * FreeRDP: A Remote Desktop Protocol Server\n * freerdp wrapper\n *\n * Copyright 2011-2013 Jay Sorg\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef XRDP_NEUTRINORDP_H\n#define XRDP_NEUTRINORDP_H\n\n#include \"arch.h\"\n#include \"xrdp_constants.h\"\n#include \"xrdp_client_info.h\"\n\n/* Incomplete type definitions, referenced below */\nstruct rail_window_state_order;\nstruct rail_notify_state_order;\nstruct rail_monitored_desktop_order;\nstruct rail_icon_info;\n\nstruct bitmap_item\n{\n    int width;\n    int height;\n    char *data;\n};\n\nstruct brush_item\n{\n    int bpp;\n    int width;\n    int height;\n    char *data;\n    char b8x8[8];\n};\n\nstruct pointer_item\n{\n    int hotx;\n    int hoty;\n    char data[32 * 32 * 4];\n    char mask[32 * 32 / 8];\n    int bpp;\n};\n\n#define CURRENT_MOD_VER 4\n\nstruct source_info;\n\nstruct kbd_overrides\n{\n    int type;\n    int subtype;\n    int fn_keys;\n    int layout;\n    int layout_mask;\n};\n\nstruct mod\n{\n    int size; /* size of this struct */\n    int version; /* internal version */\n    /* client functions */\n    int (*mod_start)(struct mod *v, int w, int h, int bpp);\n    int (*mod_connect)(struct mod *v, int fd);\n    int (*mod_event)(struct mod *v, int msg, long param1, long param2,\n                     long param3, long param4);\n    int (*mod_signal)(struct mod *v);\n    int (*mod_end)(struct mod *v);\n    int (*mod_set_param)(struct mod *v, const char *name, const char *value);\n    int (*mod_session_change)(struct mod *v, int, int);\n    int (*mod_get_wait_objs)(struct mod *v, tbus *read_objs, int *rcount,\n                             tbus *write_objs, int *wcount, int *timeout);\n    int (*mod_check_wait_objs)(struct mod *v);\n    int (*mod_frame_ack)(struct mod *mod, int flags, int frame_id);\n    int (*mod_suppress_output)(struct mod *mod, int suppress,\n                               int left, int top, int right, int bottom);\n    int (*mod_server_monitor_resize)(struct mod *mod,\n                                     int width, int height,\n                                     int num_monitors,\n                                     const struct monitor_info *monitors,\n                                     int *in_progress);\n    int (*mod_server_monitor_full_invalidate)(struct mod *mod,\n            int width, int height);\n    int (*mod_server_version_message)(struct mod *mod);\n    tintptr mod_dumby[100 - 14]; /* align, 100 minus the number of mod\n                                 functions above */\n    /* server functions */\n    int (*server_begin_update)(struct mod *v);\n    int (*server_end_update)(struct mod *v);\n    int (*server_fill_rect)(struct mod *v, int x, int y, int cx, int cy);\n    int (*server_screen_blt)(struct mod *v, int x, int y, int cx, int cy,\n                             int srcx, int srcy);\n    int (*server_paint_rect)(struct mod *v, int x, int y, int cx, int cy,\n                             char *data, int width, int height, int srcx, int srcy);\n    int (*server_set_pointer)(struct mod *v, int x, int y, char *data, char *mask);\n    int (*server_palette)(struct mod *v, int *palette);\n    int (*server_msg)(struct mod *v, const char *msg, int code);\n    int (*server_is_term)(void);\n    int (*server_set_clip)(struct mod *v, int x, int y, int cx, int cy);\n    int (*server_reset_clip)(struct mod *v);\n    int (*server_set_fgcolor)(struct mod *v, int fgcolor);\n    int (*server_set_bgcolor)(struct mod *v, int bgcolor);\n    int (*server_set_opcode)(struct mod *v, int opcode);\n    int (*server_set_mixmode)(struct mod *v, int mixmode);\n    int (*server_set_brush)(struct mod *v, int x_origin, int y_origin,\n                            int style, char *pattern);\n    int (*server_set_pen)(struct mod *v, int style,\n                          int width);\n    int (*server_draw_line)(struct mod *v, int x1, int y1, int x2, int y2);\n    int (*server_add_char)(struct mod *v, int font, int character,\n                           int offset, int baseline,\n                           int width, int height, char *data);\n    int (*server_draw_text)(struct mod *v, int font,\n                            int flags, int mixmode, int clip_left, int clip_top,\n                            int clip_right, int clip_bottom,\n                            int box_left, int box_top,\n                            int box_right, int box_bottom,\n                            int x, int y, char *data, int data_len);\n    int (*client_monitor_resize)(struct mod *v, int width, int height,\n                                 int num_monitors,\n                                 const struct monitor_info *monitors);\n    int (*server_monitor_resize_done)(struct mod *v);\n    int (*server_get_channel_count)(struct mod *v);\n    int (*server_query_channel)(struct mod *v, int index,\n                                char *channel_name,\n                                int *channel_flags);\n    int (*server_get_channel_id)(struct mod *v, const char *name);\n    int (*server_send_to_channel)(struct mod *v, int channel_id,\n                                  char *data, int data_len,\n                                  int total_data_len, int flags);\n    int (*server_bell_trigger)(struct mod *v);\n    int (*server_chansrv_in_use)(struct mod *v);\n    void (*server_init_xkb_layout)(struct mod *v,\n                                   struct xrdp_client_info *client_info);\n    /* off screen bitmaps */\n    int (*server_create_os_surface)(struct mod *v, int rdpindex,\n                                    int width, int height);\n    int (*server_switch_os_surface)(struct mod *v, int rdpindex);\n    int (*server_delete_os_surface)(struct mod *v, int rdpindex);\n    int (*server_paint_rect_os)(struct mod *mod, int x, int y,\n                                int cx, int cy,\n                                int rdpindex, int srcx, int srcy);\n    int (*server_set_hints)(struct mod *mod, int hints, int mask);\n    /* rail */\n    int (*server_window_new_update)(struct mod *mod, int window_id,\n                                    struct rail_window_state_order *window_state,\n                                    int flags);\n    int (*server_window_delete)(struct mod *mod, int window_id);\n    int (*server_window_icon)(struct mod *mod,\n                              int window_id, int cache_entry, int cache_id,\n                              struct rail_icon_info *icon_info,\n                              int flags);\n    int (*server_window_cached_icon)(struct mod *mod,\n                                     int window_id, int cache_entry,\n                                     int cache_id, int flags);\n    int (*server_notify_new_update)(struct mod *mod,\n                                    int window_id, int notify_id,\n                                    struct rail_notify_state_order *notify_state,\n                                    int flags);\n    int (*server_notify_delete)(struct mod *mod, int window_id,\n                                int notify_id);\n    int (*server_monitored_desktop)(struct mod *mod,\n                                    struct rail_monitored_desktop_order *mdo,\n                                    int flags);\n    int (*server_set_pointer_ex)(struct mod *mod, int x, int y, char *data,\n                                 char *mask, int bpp);\n    int (*server_add_char_alpha)(struct mod *mod, int font, int character,\n                                 int offset, int baseline,\n                                 int width, int height, char *data);\n    int (*server_create_os_surface_bpp)(struct mod *v, int rdpindex,\n                                        int width, int height, int bpp);\n    int (*server_paint_rect_bpp)(struct mod *v, int x, int y, int cx, int cy,\n                                 char *data, int width, int height,\n                                 int srcx, int srcy, int bpp);\n    int (*server_composite)(struct mod *v, int srcidx, int srcformat,\n                            int srcwidth, int srcrepeat, int *srctransform,\n                            int mskflags, int mskidx, int mskformat,\n                            int mskwidth, int mskrepeat, int op,\n                            int srcx, int srcy, int mskx, int msky,\n                            int dstx, int dsty, int width, int height,\n                            int dstformat);\n    int (*server_paint_rects)(struct mod *v,\n                              int num_drects, short *drects,\n                              int num_crects, short *crects,\n                              char *data, int width, int height,\n                              int flags, int frame_id);\n    int (*server_session_info)(struct mod *v, const char *data,\n                               int data_bytes);\n    tintptr server_dumby[100 - 48]; /* align, 100 minus the number of server\n                                       functions above */\n    /* common */\n    tintptr handle; /* pointer to self as long */\n    tintptr wm;\n    tintptr painter;\n    struct source_info *si;\n\n    /* mod data */\n    int sck;\n    int width;\n    int height;\n    int bpp;\n    int colormap[256];\n    char *chan_buf;\n    int chan_buf_valid;\n    int chan_buf_bytes;\n    int vmaj;\n    int vmin;\n    int vrev;\n    char username[INFO_CLIENT_MAX_CB_LEN];\n    char password[INFO_CLIENT_MAX_CB_LEN];\n    char domain[INFO_CLIENT_MAX_CB_LEN];\n    int bool_keyBoardSynced ; /* Numlock can be out of sync, we hold state here to resolve */\n    int keyBoardLockInfo ; /* Holds initial numlock capslock state */\n\n    struct xrdp_client_info client_info;\n\n    struct rdp_freerdp *inst;\n    struct bitmap_item bitmap_cache[4][4096];\n    struct brush_item brush_cache[64];\n    struct pointer_item pointer_cache[32];\n    char pamusername[256];\n\n    int allow_client_experiencesettings;\n    int perf_settings_override_mask; /* Performance bits overridden in ini file */\n    int perf_settings_values_mask; /* Values of overridden performance bits */\n    int allow_client_kbd_settings;\n    struct kbd_overrides kbd_overrides; /* neutrinordp.overide_kbd_* values */\n};\n\n#endif // XRDP_NEUTRINORDP_H\n"
  },
  {
    "path": "pkgconfig/.gitignore",
    "content": "xrdp.pc\nxrdp-uninstalled.pc\n"
  },
  {
    "path": "pkgconfig/Makefile.am",
    "content": "pkgconfigdir = @pkgconfigdir@\npkgconfig_DATA = xrdp.pc\n"
  },
  {
    "path": "pkgconfig/xrdp-uninstalled.pc.in",
    "content": "abs_top_srcdir=@abs_top_srcdir@\nincludedir=${abs_top_srcdir}/common\n\nName: xrdp\nDescription: An open source Remote Desktop Protocol (RDP) server\nVersion: @VERSION@\nCflags: -I${includedir}\n"
  },
  {
    "path": "pkgconfig/xrdp.pc.in",
    "content": "prefix=@prefix@\nexec_prefix=@exec_prefix@\nlibdir=@libdir@\nincludedir=@includedir@\n\nName: xrdp\nDescription: An open source Remote Desktop Protocol (RDP) server\nVersion: @VERSION@\nCflags: -I${includedir}\n"
  },
  {
    "path": "scripts/install_astyle.sh",
    "content": "#!/bin/sh\n\n# Script to install a version of astyle in ~/astyle.local/\n#\n# Used by CI builds\n#\n# Currently only supports git repos as sources\n#\n# Usage: /path/to/install_astyle.sh <astyle-git-repo> <version-tag>\n\nINSTALL_ROOT=~/astyle.local\n\n# ----------------------------------------------------------------------------\n# U S A G E\n# ----------------------------------------------------------------------------\nusage()\n{\n    echo \"** Usage: $0 <git-repo> <version-tag>\"\n    echo \"   e.g. $0 https://gitlab.com/saalen/astyle.git 3.4.12\"\n} >&2\n\n# ----------------------------------------------------------------------------\n# C A L L _ M A K E\n#\n# Calls make with the specified parameters, but only displays the error\n# log if it fails\n# ----------------------------------------------------------------------------\ncall_make()\n{\n    # Disable set -e, if active\n    set_entry_opts=`set +o`\n    set +e\n\n    status=1\n    log=`mktemp /tmp/astyle-log.XXXXXXXXXX`\n    if [ -n \"$log\" ]; then\n        make \"$@\" >\"$log\" 2>&1\n        status=$?\n        if [ $status -ne 0 ]; then\n            cat \"$log\" >&2\n        fi\n        rm \"$log\"\n    fi\n\n    # Re-enable `set -e` if active before\n    $set_entry_opts\n\n    return $status\n}\n\n\n# ----------------------------------------------------------------------------\n# M A I N\n# ----------------------------------------------------------------------------\nif [ $# -ne 2 ]; then\n    usage\n    exit 1\nfi\n\nREPO_URL=\"$1\"\nASTYLE_VER=\"$2\"\n\n# Already installed?\nexe=$INSTALL_ROOT/$ASTYLE_VER/usr/bin/astyle\nif [ -x \"$exe\" ]; then\n    echo \"astyle version $ASTYLE_VER is already installed at $exe\" >&2\n    exit 0\nfi\n\nworkdir=`mktemp -d /tmp/astyle.XXXXXXXXXX`\nif [ -z \"$workdir\" ]; then\n    echo \"** Unable to create temporary working directory\" 2>&1\n    exit 1\nfi\n\n# Use a sub-process for the next bit to restrict the scope of 'set -e'\n(\n    set -e ; # Exit sub-process on first error\n\n    # Put everything in this directory\n    FILESDIR=$INSTALL_ROOT/$ASTYLE_VER\n\n    git clone -b \"${ASTYLE_VER}\" --depth 1 ${REPO_URL} \"$workdir\"\n    cd \"$workdir\"/AStyle\n\n    make_args=\"DESTDIR=$FILESDIR\"\n\n    echo \"Creating Makefiles...\"\n    cmake .\n\n    echo \"Making astyle...\"\n    call_make $make_args\n\n    echo \"Installing astyle...\"\n    mkdir -p \"$FILESDIR\"\n    call_make install $make_args\n    # make install DESTDIR=~/astyle.local/3.1\n)\nstatus=$?\n\nif [ $status -eq 0 ]; then\n    rm -rf \"$workdir\"\nelse\n    \"** Script failed. Work dir is $workdir\" >&2\nfi\n\nexit $status\n"
  },
  {
    "path": "scripts/install_astyle_dependencies_with_apt.sh",
    "content": "#!/bin/sh\nset -eufx\n\nPACKAGES=\"subversion cmake\"\n\napt-get update\napt-get -yq --no-install-suggests --no-install-recommends install $PACKAGES\n"
  },
  {
    "path": "scripts/install_cppcheck.sh",
    "content": "#!/bin/sh\n\n# Script to install a version of cppcheck in ~/cppcheck.local/\n#\n# Used by Travis-CI builds, until Travis supports cppcheck natively\n#\n# Currently only supports git repos as sources\n#\n# Usage: /path/to/install_cppcheck.sh <cppcheck-git-repo> <version-tag>\n\nINSTALL_ROOT=~/cppcheck.local\n\n# ----------------------------------------------------------------------------\n# U S A G E\n# ----------------------------------------------------------------------------\nusage()\n{\n    echo \"** Usage: $0 <git-repo URL> <version-tag>\"\n    echo \"   e.g. $0 https://github.com/danmar/cppcheck.git 1.90\"\n} >&2\n\n# ----------------------------------------------------------------------------\n# C A L L _ M A K E\n#\n# Calls make with the specified parameters, but only displays the error\n# log if it fails\n# ----------------------------------------------------------------------------\ncall_make()\n{\n    # Disable set -e, if active\n    set_entry_opts=$(set +o)\n    set +e\n\n    status=1\n    log=$(mktemp /tmp/cppcheck-log.XXXXXXXXXX)\n    if [ -n \"$log\" ]; then\n        make \"$@\" >\"$log\" 2>&1\n        status=$?\n        if [ $status -ne 0 ]; then\n            cat \"$log\" >&2\n        fi\n        rm \"$log\"\n    fi\n\n    # Re-enable `set -e` if active before\n    $set_entry_opts\n\n    return $status\n}\n\n\n# ----------------------------------------------------------------------------\n# C R E A T E   Z 3   V E R S I O N   H\n#\n# Older versions of libz3-dev do not come packaged with z3_version.h. This\n# function uses the z3 command to create a copy of this file in the\n# cppcheck i#externalsi# directory.\n# ----------------------------------------------------------------------------\ncreate_z3_version_h()\n{\n    # shellcheck disable=SC2046\n    set -- $(z3 --version)\n    if [ $# != 3 ] || [ \"$1/$2\" != Z3/version ]; then\n        echo \"** Unexpected output from z3 command '$*'\" >&2\n        false\n    else\n        z3ver=\"$3\" ; # e.g. 4.4.3\n        # shellcheck disable=SC2046\n        set -- $(echo \"$z3ver\" | tr '.' ' ')\n        if [ $# != 3 ]; then\n            echo \"** Unable to determine Z3 version from '$z3ver'\" >&2\n            false\n        else\n            {\n                echo \"#ifndef Z3_MAJOR_VERSION\"\n                echo \"#define Z3_MAJOR_VERSION $1\"\n                echo \"#endif\"\n                echo\n                echo \"#ifndef Z3_MINOR_VERSION\"\n                echo \"#define Z3_MINOR_VERSION $2\"\n                echo \"#endif\"\n                echo\n                echo \"#ifndef Z3_BUILD_NUMBER\"\n                echo \"#define Z3_BUILD_NUMBER $3\"\n                echo \"#endif\"\n            } >externals/z3_version.h\n            echo \"  - Created z3_version.h for $1.$2.$3\"\n        fi\n    fi\n}\n\n# ----------------------------------------------------------------------------\n# M A I N\n# ----------------------------------------------------------------------------\nif [ $# -ne 2 ]; then\n    usage\n    exit 1\nfi\nREPO_URL=\"$1\"\nCPPCHECK_VER=\"$2\"\n\n# Already installed?\nexe=$INSTALL_ROOT/$CPPCHECK_VER/bin/cppcheck\nif [ -x \"$exe\" ]; then\n    echo \"cppcheck version $CPPCHECK_VER is already installed at $exe\" >&2\n    exit 0\nfi\n\nworkdir=$(mktemp -d /tmp/cppcheck.XXXXXXXXXX)\nif [ -z \"$workdir\" ]; then\n    echo \"** Unable to create temporary working directory\" 2>&1\n    exit 1\nfi\n\n# Use a sub-process for the next bit to restrict the scope of 'set -e'\n(\n    set -e ; # Exit sub-process on first error\n\n    # Put everything in this directory\n    FILESDIR=$INSTALL_ROOT/$CPPCHECK_VER\n\n    # See https://stackoverflow.com/questions/\n    #     791959/download-a-specific-tag-with-git\n    git clone -b \"$CPPCHECK_VER\" --depth 1 \"$REPO_URL\" \"$workdir\"\n\n    cd \"$workdir\"\n\n    make_args=\"MATCHCOMPILER=yes FILESDIR=$FILESDIR PREFIX=$FILESDIR\"\n\n    case \"$CPPCHECK_VER\" in\n        1.*)\n            # CFGDIR is needed for cppcheck before 1.86\n            make_args=\"$make_args CFGDIR=$FILESDIR\"\n            ;;\n        2.0 | 2.1 | 2.2 | 2.3 | 2.4 | 2.4.1 | 2.5 | 2.6 | 2.7)\n            make_args=\"$make_args USE_Z3=yes\"\n            # Check that the Z3 development files appear to be installed\n            # before trying to create z3_version.h. Otherwise we may\n            # mislead the user as to what needs to be done.\n            if [ ! -f /usr/include/z3.h ]; then\n                echo \"** libz3-dev (or equivalent) does not appear to be installed\" >&2\n            fi\n            if [ ! -f /usr/include/z3_version.h ]; then\n                create_z3_version_h\n            fi\n            ;;\n        2.8 | 2.9 | 2.10 | 2.11* | 2.12.* | 2.13.* | 2.14.* )\n            # Cppcheck 2.8 removed the dependency on z3\n            # Cppcheck 2.8 added optional support for utilizing Boost\n            make_args=\"$make_args CPPFLAGS=-DHAVE_BOOST\"\n            ;;\n        2.15.*)\n            # Cppcheck 2.15 doesn't seem to define FILESDIR if CPPFLAGS is set\n            ;;\n        2.*)\n            # Cppcheck 2.16 (and later) fixes the HAVE_BOOST issue\n            make_args=\"$make_args CPPFLAGS=-DHAVE_BOOST\"\n            ;;\n    esac\n\n    # Use all available CPUs\n    if [ -f /proc/cpuinfo ]; then\n        cpus=$(grep -c ^processor /proc/cpuinfo)\n        if [ -n \"$cpus\" ]; then\n            make_args=\"$make_args -j $cpus\"\n        fi\n    fi\n\n    echo \"Making cppcheck...\"\n    # shellcheck disable=SC2086\n    call_make $make_args\n\n    echo \"Installing cppcheck...\"\n    mkdir -p \"$FILESDIR\"\n    # shellcheck disable=SC2086\n    call_make install $make_args\n)\nstatus=$?\n\nif [ $status -eq 0 ]; then\n    rm -rf \"$workdir\"\nelse\n    \"** Script failed. Work dir is $workdir\" >&2\nfi\n\nexit $status\n"
  },
  {
    "path": "scripts/install_cppcheck_dependencies_with_apt.sh",
    "content": "#!/bin/sh\nset -eufx\n\n# these are the packages necessary to run ./configure so config_ac.h is generated\nPACKAGES=\"libpam0g-dev libxfixes-dev libxrandr-dev libxkbfile-dev nasm\"\n\nusage()\n{\n    echo \"** Usage: $0 <version-tag>\"\n    echo \"   e.g. $0 1.90\"\n} >&2\n\nif [ $# -ne 1 ]; then\n    usage\n    exit 1\nfi\nCPPCHECK_VER=\"$1\"\n\napt-get update\n\ncase \"$CPPCHECK_VER\" in\n        1.*)\n            # no dependencies\n            ;;\n        2.8 | 2.9 | 2.1* | 2.2*)\n            # Cppcheck 2.8 removed the dependency on z3\n            # Cppcheck 2.8 added optional support for utilizing Boost\n            PACKAGES=\"$PACKAGES libboost-container-dev\"\n            ;;\n        2.*)\n            PACKAGES=\"$PACKAGES libz3-dev z3\"\n            ;;\nesac\n\napt-get -yq --no-install-suggests --no-install-recommends install $PACKAGES\n"
  },
  {
    "path": "scripts/install_xrdp_build_dependencies_with_apt.sh",
    "content": "#!/bin/sh\nset -eufx\n\nFEATURE_SET=min\nARCH=amd64\n\n# See apt.conf(5)\nDEBUG_OPTS=\n#DEBUG_OPTS=\"$DEBUG_OPTS -oDebug::pkgProblemResolver=1\"\n\n# Given a list of i386 packages, this call makes sure the amd64 variants\n# of the development libraries are not installed\nremove_64bit_libdev_packages()\n{\n    flags=$-\n    set +x  ;# Disable tracing for this func\n    rlist=\"\"\n    for p in $PACKAGES; do\n        # Identify packages starting with 'lib' and ending with '-dev:i386'\n        if [ \"${p#lib}\" != \"$p\" -a \"${p%-dev:i386}\" != \"$p\" ]; then\n            p64=${p%i386}amd64\n            if dpkg -s $p64 >/dev/null 2>&1 ; then\n                rlist=\"$rlist ${p%i386}amd64\"\n            fi\n        fi\n    done\n    if [ -n \"$rlist\" ]; then\n        echo \"** Some 64-bit development packages appear to clash with i386 packages\"\n        echo \"**$rlist\"\n        apt-get remove $rlist || :\n    fi\n    # Restore tracing, if enabled on entry\n    set -$flags\n}\n\n# ----------------------------------------------------------------------------\n# M A I N\n# ----------------------------------------------------------------------------\n\nif [ $# -ge 1 ]; then\n    FEATURE_SET=\"$1\"\n    shift\nfi\nif [ $# -ge 1 ]; then\n    ARCH=\"$1\"\n    shift\nfi\nAPT_EXTRA_ARGS=\"$@\"\n\n# common build tools for all architectures and feature sets\nPACKAGES=\" \\\n    autoconf \\\n    automake \\\n    clang \\\n    gcc \\\n    g++ \\\n    libtool \\\n    make \\\n    nasm \\\n    pkg-config \\\n    check \\\n    libcmocka-dev\n    \"\n\n# libfreetype-dev package was renamed from libfreetype6-dev in older\n# versions\ncase `lsb_release -si`/`lsb_release -sr` in\n    Debian/10) LIBFREETYPE_DEV=libfreetype6-dev ;;\n    Ubuntu/18.*) LIBFREETYPE_DEV=libfreetype6-dev ;;\n    *) LIBFREETYPE_DEV=libfreetype-dev\nesac\n\n# We need systemd-dev for Debian-based systems using systemd\nif command -v systemctl >/dev/null; then\n    # Check for systemd version >= 255\n    set -- $(systemctl --version)\n    if [ \"$#\" -gt 2 ] && [ \"$1\" = systemd ] && [ \"$2\" -ge 255 ]; then\n        PACKAGES=\"$PACKAGES systemd-dev\"\n    fi\nfi\n\ncase \"$ARCH\"\nin\n    amd64)\n        PACKAGES_AMD64_MIN=\" \\\n            libpam0g-dev \\\n            libssl-dev \\\n            libx11-dev \\\n            libxrandr-dev \\\n            libxfixes-dev \\\n            libxkbfile-dev\"\n\n        case \"$FEATURE_SET\"\n        in\n            min)\n                PACKAGES=\"$PACKAGES $PACKAGES_AMD64_MIN\"\n                ;;\n            max)\n                PACKAGES=\"$PACKAGES \\\n                    $PACKAGES_AMD64_MIN \\\n                    $LIBFREETYPE_DEV \\\n                    libfuse3-dev \\\n                    libjpeg-dev \\\n                    libmp3lame-dev \\\n                    libfdk-aac-dev \\\n                    libibus-1.0-dev \\\n                    libimlib2-dev \\\n                    libopus-dev \\\n                    libpixman-1-dev \\\n                    libx264-dev \\\n                    libopenh264-dev\"\n                ;;\n            *)\n                echo \"unsupported feature set: $FEATURE_SET\"\n                exit 1;\n                ;;\n        esac\n        apt-get update\n        apt-get -y upgrade\n        ;;\n\n    i386)\n        # This list is not as complete as the amd64 list. It currently\n        # supports 32-bit CI building only, rather than being a generic\n        # build support tool.\n        # - Ubuntu 18.04 -> 20.04\n        #       Removed fdk-aac-dev:i386 and libfuse-dev:i386\n        # - Ubuntu 24.04.1\n        #       Removed libibus-1.0-dev:i386 and libimlib2-dev:i386\n        PACKAGES=\"$PACKAGES \\\n            g++-multilib \\\n            gcc-multilib \\\n            $LIBFREETYPE_DEV:i386 \\\n            libgl1-mesa-dev:i386 \\\n            libglu1-mesa-dev:i386 \\\n            libjpeg-dev:i386 \\\n            libmp3lame-dev:i386 \\\n            libopus-dev:i386 \\\n            libpam0g-dev:i386 \\\n            libssl-dev:i386 \\\n            libx11-dev:i386 \\\n            libxext-dev:i386 \\\n            libxfixes-dev:i386 \\\n            libxkbfile-dev:i386 \\\n            libxrandr-dev:i386 \\\n            libxrender-dev:i386 \\\n            libsubunit-dev:i386 \\\n            check:i386 \\\n            libcmocka-dev:i386\"\n\n        dpkg --add-architecture i386\n        dpkg --print-architecture\n        dpkg --print-foreign-architectures\n        apt-get update\n        remove_64bit_libdev_packages $PACKAGES\n        apt-get install libc6:i386 libgcc-s1:i386 libstdc++6:i386 libatomic1:i386\n        ;;\n    *)\n        echo \"unsupported architecture: $ARCH\"\n        exit 1;\n        ;;\nesac\n\napt-get -yq \\\n    --no-install-suggests \\\n    --no-install-recommends \\\n    $DEBUG_OPTS \\\n    $APT_EXTRA_ARGS \\\n    install $PACKAGES\n"
  },
  {
    "path": "scripts/run_astyle.sh",
    "content": "#!/bin/sh\n\n# Script to run astyle on the code\n#\n# Usage: /path/to/run_astyle.sh [ -v ASTYLE_VER]\n#\n# - If -v ASTYLE_VER is specified, that version of astyle is run from\n#   ~/astyle.local (whether or not it's there!). Use install_astyle.sh\n#   to install a new version.\n\n# Note: the script must be run from the root directory of the xrdp repository\n\nINSTALL_ROOT=~/astyle.local\nMIN_ASTYLE_VER=\"3.1\"\n\n# ----------------------------------------------------------------------------\n# U S A G E\n# ----------------------------------------------------------------------------\nusage()\n{\n    echo \"** Usage: $0 [ -v version]\"\n    echo \"   e.g. $0 -v 3.4.12\"\n} >&2\n\n# ----------------------------------------------------------------------------\n# M A I N\n# ----------------------------------------------------------------------------\n# Figure out ASTYLE setting, if any. Currently '-v' must be the first\n# argument on the command line.\ncase \"$1\" in\n    -v) # Version is separate parameter\n        if [ $# -ge 2 ]; then\n            ASTYLE=\"$INSTALL_ROOT/$2/usr/bin/astyle\"\n            shift 2\n        else\n            echo \"** ignoring '-v' with no arg\" >&2\n            shift 1\n        fi\n        ;;\n    -v*) # Version is in same parameter\n        # ${parameter#word} is not supported by classic Bourne shell,\n        # but it is on bash, dash, etc. If it doesn't work on your shell,\n        # don't use this form!\n        ASTYLE=\"$INSTALL_ROOT/${1#-v}/usr/bin/astyle\"\n        shift 1\nesac\n\nif [ -z \"$ASTYLE\" ]; then\n    ASTYLE=astyle\nfi\n\nif [ $# -ne 0 ]; then\n    usage\n    exit 1\nfi\n\n\n# check if the selected astyle meets the minimum requrements\nASTYLE_VER_OUTPUT=`$ASTYLE --version 2>/dev/null | grep \"Artistic Style Version\" | cut -d' ' -f4`\n\nif [ ! -z \"$ASTYLE_VER_OUTPUT\" ]; then\n    # Check the version meets the minimum requirements\n    LOWEST_VERSION=`{ echo \"$MIN_ASTYLE_VER\" ; echo \"$ASTYLE_VER_OUTPUT\"; } | sort -V | head -n1`\n    if [ \"$MIN_ASTYLE_VER\" != \"$LOWEST_VERSION\" ]; then\n        ERROR_MESSAGE=\"The version of astyle installed does not meet the minimum version requirement: >= $MIN_ASTYLE_VER \"\n    fi\nelif [ \"$ASTYLE\" = astyle ]; then\n    ERROR_MESSAGE=\"astyle is not installed on the system path\"\nelse\n    ERROR_MESSAGE=\"Can't find $ASTYLE\"\nfi\n\nif [ ! -z \"$ERROR_MESSAGE\" ]; then\n    echo \"$ERROR_MESSAGE\" >&2\n    exit 1\nfi\n\nif [ ! -f \"astyle_config.as\" ]; then\n    echo \"$0 must be run from the root xrdp repository directory which \" >&2\n    echo \"contains the 'astyle_config.as' file.\" >&2\n    exit 2\nfi\n\nASTYLE_FLAGS=\"--options=astyle_config.as --exclude=third_party ./\\*.c ./\\*.h\"\n\n# Display the astyle version and command for debugging\n\"$ASTYLE\" --version && {\n    echo \"Command: $ASTYLE $ASTYLE_FLAGS\"\n    \"$ASTYLE\" $ASTYLE_FLAGS\n}\n\nexit $?\n"
  },
  {
    "path": "scripts/run_cppcheck.sh",
    "content": "#!/bin/sh\n\n# Script to run cppcheck\n#\n# Usage: /path/to/run_cppcheck.sh [-f] [ -v CPPCHECK_VER] [<extra_opts_and_dirs>]\n#\n# - If <extra_opts_and_dirs> is missing, '.' is assumed\n# - If '-f' is specified, the exhaustive check level is used. This can take\n#   an hour or two.\n# - If -v CPPCHECK_VER is specified, that version of cppcheck is run from\n#   ~/cppcheck.local (whether or not it's there!). Use install_cppcheck.sh\n#   to install a new version.\n#\n# Environment (all optional):-\n#\n# CPPCHECK       : Override the default cppcheck command ('cppcheck').\n#                  Ignored if -v is specified\n# CPPCHECK_FLAGS : Override the default cppcheck flags\n# CPPCHECK_QUICK : If non-zero, disables the exhaustive check level.\n#                  Useful when developing\n\n# ----------------------------------------------------------------------------\n# C P P C H E C K   V E R S I O N   S T R\n#\n# Get the cppcheck version, and then convert to AABBCC for comparisons\n# where AA is the major version, BB is the minor version and CC is the\n# revision\n# For example, cppcheck version 2.13.0 produces 021300\n# ----------------------------------------------------------------------------\nCppcheckVerCompareStr()\n{\n    # shellcheck disable=SC2046\n    set -- $($CPPCHECK --version 2>/dev/null)\n    while [ $# -gt 0 ]; do\n        case \"$1\" in\n            [0123456789]*) break;;\n            *) shift\n        esac\n    done\n\n    if [ $# -eq 0 ]; then\n        echo 000000 ; # Something has gone wrong\n    else\n        case \"$1\" in\n            *.*.*) echo \"$1\" | awk -F.  '{printf \"%02d%02d%02d\",$1,$2,$3 }' ;;\n            *.*)   echo \"$1\" | awk -F.  '{printf \"%02d%02d00\",$1,$2 }' ;;\n            *)     printf '%02d0000\\n' \"$1\"\n        esac\n    fi\n}\n\nINSTALL_ROOT=~/cppcheck.local\n\n# Exhaustive test?\nif [ \"$1\" = \"-f\" ]; then\n    check_level=exhaustive\n    shift\nelse\n    check_level=normal\nfi\n\n# Figure out CPPCHECK setting, if any.\ncase \"$1\" in\n    -v) # Version is separate parameter\n        if [ $# -ge 2 ]; then\n            CPPCHECK=\"$INSTALL_ROOT/$2/bin/cppcheck\"\n            shift 2\n        else\n            echo \"** ignoring '-v' with no arg\" >&2\n            shift 1\n        fi\n        ;;\n    -v*) # Version is in same parameter\n        # ${parameter#word} is not supported by classic Bourne shell,\n        # but it is on bash, dash, etc. If it doesn't work on your shell,\n        # don't use this form!\n        CPPCHECK=\"$INSTALL_ROOT/${1#-v}/bin/cppcheck\"\n        shift 1\nesac\nif [ -z \"$CPPCHECK\" ]; then\n    CPPCHECK=cppcheck\nfi\n\n# Supply default flags passed to cppcheck if necessary\nif [ -z \"$CPPCHECK_FLAGS\" ]; then\n    CPPCHECK_FLAGS=\"--quiet --force --std=c11 --std=c++11 --inline-suppr \\\n                    --enable=warning,missingInclude,style,portability --disable=performance --error-exitcode=1 \\\n                    -i third_party \\\n                    -i vrplayer \\\n                    --suppress=constParameterCallback --suppress=variableScope --suppress=constParameterPointer --suppress=constVariablePointer --suppress=duplicateCondition --suppress=redundantAssignment --suppress=knownConditionTrueFalse --suppress=unreadVariable --suppress=constParameter --suppress=shadowFunction --suppress=unusedStructMember --suppress=duplicateExpression --suppress=unsignedLessThanZero --suppress=shadowVariable --suppress=unreachableCode --suppress=noExplicitConstructor --suppress=constParameterReference --suppress=functionStatic --suppress=shadowArgument --suppress=truncLongCastAssignment --suppress=cstyleCast --suppress=constVariableReference --suppress=badBitmaskCheck \\\n                    --suppress=missingIncludeSystem \\\n                    --suppress=uninitMemberVar:ulalaca/ulalaca.cpp \\\n                    --suppress=dangerousTypeCast:ulalaca/XrdpStream.template.cpp \\\n                    --suppress=shiftTooManyBits:libxrdp/xrdp_mppc_enc.c\"\n\n    # Check for flags added in later versions\n    CPPCHECK_COMPARE_VERSION=$(CppcheckVerCompareStr)\n    if [ \"$CPPCHECK_COMPARE_VERSION\" -ge 021100 ]; then\n        if [ \"$check_level\" = \"normal\" ]; then\n            # Disable warnings related to the check level\n            CPPCHECK_FLAGS=\"$CPPCHECK_FLAGS \\\n                --suppress=normalCheckLevelMaxBranches\"\n        fi\n        CPPCHECK_FLAGS=\"$CPPCHECK_FLAGS --check-level=$check_level\"\n    else\n        # This is echoed later\n        check_level=\"Default (option not supported)\"\n    fi\n\n    CPPCHECK_FLAGS=\"$CPPCHECK_FLAGS \\\n                    -I . \\\n                    -I common \\\n                    -I libipm \\\n                    -I libpainter/include \\\n                    -I librfxcodec/include \\\n                    -I librfxcodec/src \\\n                    -I librfxcodec/src/neon \\\n                    -I librfxcodec/src/sse2 \\\n                    -I libxrdp \\\n                    -I sesman/libsesman \\\n                    -I sesman/sesexec \\\n                    -I third_party \\\n                    -I third_party/tomlc99 \\\n                    -I xrdp \\\n                    -I xrdpapi \\\n                    -I xrdpvr\"\nfi\nCPPCHECK_FLAGS=\"$CPPCHECK_FLAGS -D__cppcheck__\"\n\n# Any options/directories specified?\nif [ $# -eq 0 ]; then\n    if [ -f /proc/cpuinfo ]; then\n        cpus=$(grep -c '^processor' /proc/cpuinfo)\n    else\n        cpus=2\n    fi\n    set -- -j $cpus .\nfi\n\n# Display the cppcheck version and command for debugging\n\"$CPPCHECK\" --version && {\n    echo \"Command: $CPPCHECK $CPPCHECK_FLAGS\" \"$@\"\n    echo \"Check level: $check_level\"\n\n    # shellcheck disable=SC2086\n    \"$CPPCHECK\" $CPPCHECK_FLAGS \"$@\"\n}\n"
  },
  {
    "path": "sesman/Doxyfile",
    "content": "# Doxyfile 1.4.4\n\n#---------------------------------------------------------------------------\n# Project related configuration options\n#---------------------------------------------------------------------------\nPROJECT_NAME           = xrdp/sesman\nPROJECT_NUMBER         = 0.2.0\nOUTPUT_DIRECTORY       = ../docs/sesman\nCREATE_SUBDIRS         = NO\nOUTPUT_LANGUAGE        = English\nUSE_WINDOWS_ENCODING   = NO\nBRIEF_MEMBER_DESC      = YES\nREPEAT_BRIEF           = NO\nABBREVIATE_BRIEF       = \nALWAYS_DETAILED_SEC    = NO\nINLINE_INHERITED_MEMB  = NO\nFULL_PATH_NAMES        = YES\nSTRIP_FROM_PATH        = \nSTRIP_FROM_INC_PATH    = \nSHORT_NAMES            = NO\nJAVADOC_AUTOBRIEF      = NO\nMULTILINE_CPP_IS_BRIEF = NO\nDETAILS_AT_TOP         = NO\nINHERIT_DOCS           = YES\nDISTRIBUTE_GROUP_DOC   = NO\nSEPARATE_MEMBER_PAGES  = NO\nTAB_SIZE               = 8\nALIASES                = \nOPTIMIZE_OUTPUT_FOR_C  = YES\nOPTIMIZE_OUTPUT_JAVA   = NO\nSUBGROUPING            = YES\n#---------------------------------------------------------------------------\n# Build related configuration options\n#---------------------------------------------------------------------------\nEXTRACT_ALL            = YES\nEXTRACT_PRIVATE        = NO\nEXTRACT_STATIC         = NO\nEXTRACT_LOCAL_CLASSES  = NO\nEXTRACT_LOCAL_METHODS  = NO\nHIDE_UNDOC_MEMBERS     = YES\nHIDE_UNDOC_CLASSES     = YES\nHIDE_FRIEND_COMPOUNDS  = NO\nHIDE_IN_BODY_DOCS      = NO\nINTERNAL_DOCS          = NO\nCASE_SENSE_NAMES       = YES\nHIDE_SCOPE_NAMES       = NO\nSHOW_INCLUDE_FILES     = YES\nINLINE_INFO            = YES\nSORT_MEMBER_DOCS       = YES\nSORT_BRIEF_DOCS        = NO\nSORT_BY_SCOPE_NAME     = NO\nGENERATE_TODOLIST      = YES\nGENERATE_TESTLIST      = YES\nGENERATE_BUGLIST       = YES\nGENERATE_DEPRECATEDLIST= YES\nENABLED_SECTIONS       = \nMAX_INITIALIZER_LINES  = 30\nSHOW_USED_FILES        = YES\nSHOW_DIRECTORIES       = YES\nFILE_VERSION_FILTER    = \n#---------------------------------------------------------------------------\n# configuration options related to warning and progress messages\n#---------------------------------------------------------------------------\nQUIET                  = NO\nWARNINGS               = YES\nWARN_IF_UNDOCUMENTED   = YES\nWARN_IF_DOC_ERROR      = YES\nWARN_NO_PARAMDOC       = NO\nWARN_FORMAT            = \"$file:$line: $text\"\nWARN_LOGFILE           = \n#---------------------------------------------------------------------------\n# configuration options related to the input files\n#---------------------------------------------------------------------------\nINPUT                  = \nFILE_PATTERNS          = \nRECURSIVE              = NO\nEXCLUDE                = \nEXCLUDE_SYMLINKS       = NO\nEXCLUDE_PATTERNS       = \nEXAMPLE_PATH           = \nEXAMPLE_PATTERNS       = \nEXAMPLE_RECURSIVE      = NO\nIMAGE_PATH             = \nINPUT_FILTER           = \nFILTER_PATTERNS        = \nFILTER_SOURCE_FILES    = NO\n#---------------------------------------------------------------------------\n# configuration options related to source browsing\n#---------------------------------------------------------------------------\nSOURCE_BROWSER         = YES\nINLINE_SOURCES         = NO\nSTRIP_CODE_COMMENTS    = YES\nREFERENCED_BY_RELATION = YES\nREFERENCES_RELATION    = YES\nUSE_HTAGS              = NO\nVERBATIM_HEADERS       = YES\n#---------------------------------------------------------------------------\n# configuration options related to the alphabetical class index\n#---------------------------------------------------------------------------\nALPHABETICAL_INDEX     = YES\nCOLS_IN_ALPHA_INDEX    = 5\nIGNORE_PREFIX          = \n#---------------------------------------------------------------------------\n# configuration options related to the HTML output\n#---------------------------------------------------------------------------\nGENERATE_HTML          = YES\nHTML_OUTPUT            = html\nHTML_FILE_EXTENSION    = .html\nHTML_HEADER            = \nHTML_FOOTER            = \nHTML_STYLESHEET        = \nHTML_ALIGN_MEMBERS     = YES\nGENERATE_HTMLHELP      = NO\nCHM_FILE               = \nHHC_LOCATION           = \nGENERATE_CHI           = NO\nBINARY_TOC             = NO\nTOC_EXPAND             = NO\nDISABLE_INDEX          = NO\nENUM_VALUES_PER_LINE   = 4\nGENERATE_TREEVIEW      = NO\nTREEVIEW_WIDTH         = 250\n#---------------------------------------------------------------------------\n# configuration options related to the LaTeX output\n#---------------------------------------------------------------------------\nGENERATE_LATEX         = NO\nLATEX_OUTPUT           = latex\nLATEX_CMD_NAME         = latex\nMAKEINDEX_CMD_NAME     = makeindex\nCOMPACT_LATEX          = NO\nPAPER_TYPE             = a4wide\nEXTRA_PACKAGES         = \nLATEX_HEADER           = \nPDF_HYPERLINKS         = NO\nUSE_PDFLATEX           = NO\nLATEX_BATCHMODE        = NO\nLATEX_HIDE_INDICES     = NO\n#---------------------------------------------------------------------------\n# configuration options related to the RTF output\n#---------------------------------------------------------------------------\nGENERATE_RTF           = NO\nRTF_OUTPUT             = rtf\nCOMPACT_RTF            = NO\nRTF_HYPERLINKS         = NO\nRTF_STYLESHEET_FILE    = \nRTF_EXTENSIONS_FILE    = \n#---------------------------------------------------------------------------\n# configuration options related to the man page output\n#---------------------------------------------------------------------------\nGENERATE_MAN           = NO\nMAN_OUTPUT             = man\nMAN_EXTENSION          = .3\nMAN_LINKS              = NO\n#---------------------------------------------------------------------------\n# configuration options related to the XML output\n#---------------------------------------------------------------------------\nGENERATE_XML           = NO\nXML_OUTPUT             = xml\nXML_SCHEMA             = \nXML_DTD                = \nXML_PROGRAMLISTING     = YES\n#---------------------------------------------------------------------------\n# configuration options for the AutoGen Definitions output\n#---------------------------------------------------------------------------\nGENERATE_AUTOGEN_DEF   = NO\n#---------------------------------------------------------------------------\n# configuration options related to the Perl module output\n#---------------------------------------------------------------------------\nGENERATE_PERLMOD       = NO\nPERLMOD_LATEX          = NO\nPERLMOD_PRETTY         = YES\nPERLMOD_MAKEVAR_PREFIX = \n#---------------------------------------------------------------------------\n# Configuration options related to the preprocessor   \n#---------------------------------------------------------------------------\nENABLE_PREPROCESSING   = YES\nMACRO_EXPANSION        = NO\nEXPAND_ONLY_PREDEF     = NO\nSEARCH_INCLUDES        = NO\nINCLUDE_PATH           = \nINCLUDE_FILE_PATTERNS  = \nPREDEFINED             = \nEXPAND_AS_DEFINED      = \nSKIP_FUNCTION_MACROS   = NO\n#---------------------------------------------------------------------------\n# Configuration::additions related to external references   \n#---------------------------------------------------------------------------\nTAGFILES               = \nGENERATE_TAGFILE       = \nALLEXTERNALS           = NO\nEXTERNAL_GROUPS        = YES\nPERL_PATH              = /usr/bin/perl\n#---------------------------------------------------------------------------\n# Configuration options related to the dot tool   \n#---------------------------------------------------------------------------\nCLASS_DIAGRAMS         = NO\nHIDE_UNDOC_RELATIONS   = YES\nHAVE_DOT               = NO\nCLASS_GRAPH            = YES\nCOLLABORATION_GRAPH    = YES\nGROUP_GRAPHS           = YES\nUML_LOOK               = NO\nTEMPLATE_RELATIONS     = NO\nINCLUDE_GRAPH          = YES\nINCLUDED_BY_GRAPH      = YES\nCALL_GRAPH             = NO\nGRAPHICAL_HIERARCHY    = YES\nDIRECTORY_GRAPH        = YES\nDOT_IMAGE_FORMAT       = png\nDOT_PATH               = \nDOTFILE_DIRS           = \nMAX_DOT_GRAPH_WIDTH    = 1024\nMAX_DOT_GRAPH_HEIGHT   = 1024\nMAX_DOT_GRAPH_DEPTH    = 0\nDOT_TRANSPARENT        = NO\nDOT_MULTI_TARGETS      = NO\nGENERATE_LEGEND        = YES\nDOT_CLEANUP            = YES\n#---------------------------------------------------------------------------\n# Configuration::additions related to the search engine   \n#---------------------------------------------------------------------------\nSEARCHENGINE           = NO\n"
  },
  {
    "path": "sesman/Makefile.am",
    "content": "EXTRA_DIST = \\\n  Doxyfile\n\nAM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_LIBEXEC_PATH=\\\"${libexecdir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -DXRDP_SOCKET_ROOT_PATH=\\\"${socketdir}\\\" \\\n  -I$(top_srcdir)/sesman/libsesman \\\n  -I$(top_srcdir)/common \\\n  -I$(top_srcdir)/libipm\n\nsbin_PROGRAMS = \\\n  xrdp-sesman\n\nxrdp_sesman_SOURCES = \\\n  display_utils.c \\\n  display_utils.h \\\n  eicp_process.c \\\n  eicp_process.h \\\n  ercp_process.c \\\n  ercp_process.h \\\n  lock_uds.c \\\n  lock_uds.h \\\n  scp_list.c \\\n  scp_list.h \\\n  scp_process.c \\\n  scp_process.h \\\n  sesman.c \\\n  sesman.h \\\n  sesman.ini.in \\\n  sesexec_control.c \\\n  sesexec_control.h \\\n  session_list.c \\\n  session_list.h \\\n  sesman_restart.c \\\n  sesman_restart.h \\\n  sig.c \\\n  sig.h\n\nxrdp_sesman_LDADD = \\\n  $(top_builddir)/sesman/libsesman/libsesman.la \\\n  $(top_builddir)/libipm/libipm.la \\\n  $(top_builddir)/common/libcommon.la\n\nsesmansysconfdir=$(sysconfdir)/$(sysconfsubdir)\n\nSUBST_VARS = sed \\\n   -e 's|@sesmansysconfdir[@]|$(sesmansysconfdir)|g'\n\nsubst_verbose = $(subst_verbose_@AM_V@)\nsubst_verbose_ = $(subst_verbose_@AM_DEFAULT_V@)\nsubst_verbose_0 = @echo \"  SUBST    $@\";\n\nSUFFIXES = .in\n.in:\n\t$(subst_verbose)$(SUBST_VARS) $< > $@\n\nnodist_sesmansysconf_DATA = \\\n  sesman.ini\n\ndist_sesmansysconf_SCRIPTS = \\\n  startwm.sh \\\n  reconnectwm.sh\n\nSUBDIRS = \\\n  libsesman \\\n  sesexec \\\n  tools \\\n  chansrv\n\nCLEANFILES = $(nodist_sesmansysconf_DATA)\n"
  },
  {
    "path": "sesman/chansrv/Makefile.am",
    "content": "EXTRA_DIST = \\\n  clipboard-notes.txt \\\n  pcsc \\\n  wave-format-server.txt\n\nAM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -DXRDP_SOCKET_ROOT_PATH=\\\"${socketdir}\\\" \\\n  -I$(top_srcdir)/sesman/libsesman \\\n  -I$(top_srcdir)/common \\\n  -I$(top_srcdir)/libipm\n\nCHANSRV_EXTRA_LIBS =\n\nif XRDP_FUSE\nAM_CPPFLAGS += -DXRDP_FUSE $(FUSE_CFLAGS) -DFUSE_USE_VERSION=30\nCHANSRV_EXTRA_LIBS += $(FUSE_LIBS)\nendif\n\nif XRDP_FDK_AAC\nAM_CPPFLAGS += -DXRDP_FDK_AAC $(FDKAAC_CFLAGS)\nCHANSRV_EXTRA_LIBS += $(FDKAAC_LIBS)\nendif\n\nif XRDP_OPUS\nAM_CPPFLAGS += -DXRDP_OPUS\nCHANSRV_EXTRA_LIBS += -lopus\nendif\n\nif XRDP_MP3LAME\nAM_CPPFLAGS += -DXRDP_MP3LAME\nCHANSRV_EXTRA_LIBS += -lmp3lame\nendif\n\nif XRDP_RDPSNDAUDIN\nAM_CPPFLAGS += -DXRDP_RDPSNDAUDIN\nendif\n\nAM_CFLAGS = $(X_CFLAGS)\n\nsbin_PROGRAMS = \\\n  xrdp-chansrv\n\nxrdp_chansrv_SOURCES = \\\n  chansrv.c \\\n  chansrv.h \\\n  chansrv_common.c \\\n  chansrv_common.h \\\n  chansrv_config.c \\\n  chansrv_config.h \\\n  chansrv_fuse.c \\\n  chansrv_fuse.h \\\n  chansrv_xfs.c \\\n  chansrv_xfs.h \\\n  clipboard.c \\\n  clipboard.h \\\n  clipboard_common.h \\\n  clipboard_file.c \\\n  clipboard_file.h \\\n  devredir.c \\\n  devredir.h \\\n  irp.c \\\n  irp.h \\\n  rail.c \\\n  rail.h \\\n  smartcard.h \\\n  sound.c \\\n  sound.h \\\n  xcommon.c \\\n  xcommon.h \\\n  input.h \\\n  audin.c \\\n  audin.h\n\nif XRDP_IBUS\nAM_CPPFLAGS += -DXRDP_IBUS $(IBUS_CFLAGS) $(GLIB2_CFLAGS)\nCHANSRV_EXTRA_LIBS += $(IBUS_LIBS) $(GLIB2_LIBS)\nxrdp_chansrv_SOURCES += \\\n  input_ibus.c\nendif\n\nif XRDP_SMARTCARD\nAM_CPPFLAGS += -DXRDP_SMARTCARD\nxrdp_chansrv_SOURCES += \\\n  smartcard.c \\\n  smartcard_internal.h \\\n  smartcard_pcsc.c \\\n  smartcard_pcsc.h\nelse\nxrdp_chansrv_SOURCES += \\\n  smartcard_dummy.c\nendif\n\nxrdp_chansrv_LDFLAGS = \\\n  $(X_LIBS)\n\nxrdp_chansrv_LDADD = \\\n  $(top_builddir)/common/libcommon.la \\\n  $(top_builddir)/sesman/libsesman/libsesman.la \\\n  $(top_builddir)/libipm/libipm.la \\\n  $(X_PRE_LIBS) -lXfixes -lXrandr -lX11 $(X_EXTRA_LIBS) \\\n  $(CHANSRV_EXTRA_LIBS)\n"
  },
  {
    "path": "sesman/chansrv/audin.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2019\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * MS-RDPEAI\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"os_calls.h\"\n#include \"chansrv.h\"\n#include \"log.h\"\n#include \"xrdp_constants.h\"\n#include \"fifo.h\"\n#include \"audin.h\"\n\n#define MSG_SNDIN_VERSION       1\n#define MSG_SNDIN_FORMATS       2\n#define MSG_SNDIN_OPEN          3\n#define MSG_SNDIN_OPEN_REPLY    4\n#define MSG_SNDIN_DATA_INCOMING 5\n#define MSG_SNDIN_DATA          6\n#define MSG_SNDIN_FORMATCHANGE  7\n\n#define AUDIN_VERSION 0x00000001\n\n#define AUDIN_NAME \"AUDIO_INPUT\"\n#define AUDIN_FLAGS  1 /* WTS_CHANNEL_OPTION_DYNAMIC */\n\nextern struct fifo *g_in_fifo; /* in sound.c */\nextern int g_bytes_in_fifo; /* in sound.c */\n\nstruct xr_wave_format_ex\n{\n    int wFormatTag;\n    int nChannels;\n    int nSamplesPerSec;\n    int nAvgBytesPerSec;\n    int nBlockAlign;\n    int wBitsPerSample;\n    int cbSize;\n    uint8_t *data;\n};\n\nstatic uint8_t g_pcm_44100_data[] = { 0 };\nstatic struct xr_wave_format_ex g_pcm_44100 =\n{\n    WAVE_FORMAT_PCM, /* wFormatTag */\n    2,               /* num of channels */\n    44100,           /* samples per sec */\n    176400,          /* avg bytes per sec */\n    4,               /* block align */\n    16,              /* bits per sample */\n    0,               /* data size */\n    g_pcm_44100_data /* data */\n};\n\nstatic struct chansrv_drdynvc_procs g_audin_info;\nstatic int g_audin_chanid;\nstatic struct stream *g_in_s;\n\nstatic struct xr_wave_format_ex *g_server_formats[] =\n{\n    &g_pcm_44100,\n    NULL\n};\n\nstatic struct xr_wave_format_ex **g_client_formats = NULL;\n\nstatic int g_current_format = 0; /* index in g_client_formats */\n\n/*****************************************************************************/\n\n/*\n * This can be called from sound.c because it includes audin.h.\n */\n\nconst char *\naudin_wave_format_tag_to_str(int tag)\n{\n    return\n        (tag == WAVE_FORMAT_PCM)        ? \"WAVE_FORMAT_PCM\" :\n        (tag == WAVE_FORMAT_ADPCM)      ? \"WAVE_FORMAT_ADPCM\" :\n        (tag == WAVE_FORMAT_ALAW)       ? \"WAVE_FORMAT_ALAW\" :\n        (tag == WAVE_FORMAT_MULAW)      ? \"WAVE_FORMAT_MULAW\" :\n        (tag == WAVE_FORMAT_MPEGLAYER3) ? \"WAVE_FORMAT_MPEGLAYER3\" :\n        (tag == WAVE_FORMAT_OPUS)       ? \"WAVE_FORMAT_OPUS\" :\n        (tag == WAVE_FORMAT_AAC)        ? \"WAVE_FORMAT_AAC\" :\n        \"UNKNOWN\";\n}\n\n/*****************************************************************************/\nstatic int\ncleanup_client_formats(void)\n{\n    int index;\n\n    if (g_client_formats == NULL)\n    {\n        return 0;\n    }\n    index = 0;\n    while (g_client_formats[index] != NULL)\n    {\n        g_free(g_client_formats[index]->data);\n        g_free(g_client_formats[index]);\n        index++;\n    }\n    g_free(g_client_formats);\n    g_client_formats = NULL;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_send_version(int chan_id)\n{\n    int error;\n    int bytes;\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_send_version:\");\n    make_stream(s);\n    init_stream(s, 32);\n    out_uint8(s, MSG_SNDIN_VERSION);\n    out_uint32_le(s, AUDIN_VERSION);\n    s_mark_end(s);\n    bytes = (int) (s->end - s->data);\n    error = chansrv_drdynvc_data(chan_id, s->data, bytes);\n    free_stream(s);\n    return error;\n}\n\n/*****************************************************************************/\nstatic int\naudin_send_formats(int chan_id)\n{\n    int error;\n    int bytes;\n    int num_formats;\n    int index;\n    struct stream *s;\n    struct xr_wave_format_ex *wf;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_send_formats:\");\n    num_formats = sizeof(g_server_formats) /\n                  sizeof(g_server_formats[0]) - 1;\n    make_stream(s);\n    init_stream(s, 8192 * num_formats);\n    out_uint8(s, MSG_SNDIN_FORMATS);\n    out_uint32_le(s, num_formats);\n    out_uint32_le(s, 0); /* cbSizeFormatsPacket */\n    for (index = 0; index < num_formats; index++)\n    {\n        wf = g_server_formats[index];\n        LOG_DEVEL(LOG_LEVEL_INFO, \"audin_send_formats: sending format wFormatTag 0x%4.4x \"\n                  \"nChannels %d nSamplesPerSec %d\",\n                  wf->wFormatTag, wf->nChannels, wf->nSamplesPerSec);\n        out_uint16_le(s, wf->wFormatTag);\n        out_uint16_le(s, wf->nChannels);\n        out_uint32_le(s, wf->nSamplesPerSec);\n        out_uint32_le(s, wf->nAvgBytesPerSec);\n        out_uint16_le(s, wf->nBlockAlign);\n        out_uint16_le(s, wf->wBitsPerSample);\n        out_uint16_le(s, wf->cbSize);\n        if (wf->cbSize > 0)\n        {\n            out_uint8p(s, wf->data, wf->cbSize);\n        }\n    }\n    s_mark_end(s);\n    bytes = (int) (s->end - s->data);\n    error = chansrv_drdynvc_data(chan_id, s->data, bytes);\n    free_stream(s);\n    return error;\n}\n\n/*****************************************************************************/\nstatic int\naudin_send_open(int chan_id)\n{\n    int error;\n    int bytes;\n    struct stream *s;\n    struct xr_wave_format_ex *wf = g_client_formats[g_current_format];\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_send_open:\");\n    make_stream(s);\n    /* wf->cbSize was checked when the format was received */\n    init_stream(s, wf->cbSize + 64);\n\n    out_uint8(s, MSG_SNDIN_OPEN);\n    out_uint32_le(s, 2048); /* FramesPerPacket */\n    out_uint32_le(s, g_current_format); /* initialFormat */\n    out_uint16_le(s, wf->wFormatTag);\n    out_uint16_le(s, wf->nChannels);\n    out_uint32_le(s, wf->nSamplesPerSec);\n    out_uint32_le(s, wf->nAvgBytesPerSec);\n    out_uint16_le(s, wf->nBlockAlign);\n    out_uint16_le(s, wf->wBitsPerSample);\n    bytes = wf->cbSize;\n    out_uint16_le(s, bytes);\n    if (bytes > 0)\n    {\n        out_uint8p(s, wf->data, bytes);\n    }\n    s_mark_end(s);\n    bytes = (int) (s->end - s->data);\n    error = chansrv_drdynvc_data(chan_id, s->data, bytes);\n    free_stream(s);\n    return error;\n}\n\n/*****************************************************************************/\nstatic int\naudin_process_version(int chan_id, struct stream *s)\n{\n    int version;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_process_version:\");\n    if (!s_check_rem(s, 4))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_process_version: parse error\");\n        return 1;\n    }\n    in_uint32_le(s, version);\n    LOG(LOG_LEVEL_INFO, \"audin_process_version: version %d\", version);\n    return audin_send_formats(chan_id);\n}\n\n/*****************************************************************************/\nstatic int\naudin_process_formats(int chan_id, struct stream *s)\n{\n    int index;\n    int num_formats;\n    struct xr_wave_format_ex *wf;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_process_formats:\");\n    cleanup_client_formats();\n    if (!s_check_rem(s, 8))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_process_formats: parse error\");\n        return 1;\n    }\n    in_uint32_le(s, num_formats);\n    in_uint8s(s, 4); /* cbSizeFormatsPacket */\n    g_client_formats = g_new0(struct xr_wave_format_ex *, num_formats + 1);\n    for (index = 0; index < num_formats; index++)\n    {\n        if (!s_check_rem(s, 18))\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_process_formats: parse error\");\n            return 1;\n        }\n        wf = g_new0(struct xr_wave_format_ex, 1);\n        g_client_formats[index] = wf;\n        in_uint16_le(s, wf->wFormatTag);\n        in_uint16_le(s, wf->nChannels);\n        in_uint32_le(s, wf->nSamplesPerSec);\n        in_uint32_le(s, wf->nAvgBytesPerSec);\n        in_uint16_le(s, wf->nBlockAlign);\n        in_uint16_le(s, wf->wBitsPerSample);\n        in_uint16_le(s, wf->cbSize);\n\n        LOG(LOG_LEVEL_INFO, \"audin_process_formats:\");\n        LOG(LOG_LEVEL_INFO, \"      wFormatNo       %d\", index);\n        LOG(LOG_LEVEL_INFO, \"      wFormatTag      %s\", audin_wave_format_tag_to_str(wf->wFormatTag));\n        LOG(LOG_LEVEL_INFO, \"      nChannels       %d\", wf->nChannels);\n        LOG(LOG_LEVEL_INFO, \"      nSamplesPerSec  %d\", wf->nSamplesPerSec);\n        LOG(LOG_LEVEL_INFO, \"      nAvgBytesPerSec %d\", wf->nAvgBytesPerSec);\n        LOG(LOG_LEVEL_INFO, \"      nBlockAlign     %d\", wf->nBlockAlign);\n        LOG(LOG_LEVEL_INFO, \"      wBitsPerSample  %d\", wf->wBitsPerSample);\n        LOG(LOG_LEVEL_INFO, \"      cbSize          %d\", wf->cbSize);\n\n        if (wf->cbSize > 0)\n        {\n            if (!s_check_rem(s, wf->cbSize))\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_process_formats: parse error\");\n                return 1;\n            }\n            wf->data = g_new0(uint8_t, wf->cbSize);\n            in_uint8a(s, wf->data, wf->cbSize);\n        }\n    }\n    audin_send_open(chan_id);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_process_open_reply(int chan_id, struct stream *s)\n{\n    int result;\n\n    if (!s_check_rem(s, 4))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_process_open_reply: parse error\");\n        return 1;\n    }\n    in_uint32_le(s, result);\n    LOG(LOG_LEVEL_INFO, \"audin_process_open_reply: result 0x%8.8x\", result);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_process_incoming_data(int chan_id, struct stream *s)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"audin_process_incoming_data:\");\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_process_data(int chan_id, struct stream *s)\n{\n    int data_bytes;\n    struct stream *ls;\n\n    data_bytes = (int) (s->end - s->p);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"audin_process_data: data_bytes %d\", data_bytes);\n\n    xstream_new(ls, data_bytes);\n    g_memcpy(ls->data, s->p, data_bytes);\n    ls->p += data_bytes;\n    s_mark_end(ls);\n    fifo_add_item(g_in_fifo, (void *) ls);\n    g_bytes_in_fifo += data_bytes;\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_process_format_change(int chan_id, struct stream *s)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_process_format_change:\");\n    if (!s_check_rem(s, 4))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_process_format_change: parse error\");\n        return 1;\n    }\n    in_uint32_le(s, g_current_format);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_process_format_change: g_current_format %d\",\n              g_current_format);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_process_msg(int chan_id, struct stream *s)\n{\n    int code;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"audin_process_msg:\");\n    if (!s_check_rem(s, 1))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_process_msg: parse error\");\n        return 1;\n    }\n    in_uint8(s, code);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"audin_process_msg: code %d\", code);\n    switch (code)\n    {\n        case MSG_SNDIN_VERSION:\n            return audin_process_version(chan_id, s);\n        case MSG_SNDIN_FORMATS:\n            return audin_process_formats(chan_id, s);\n        case MSG_SNDIN_OPEN_REPLY:\n            return audin_process_open_reply(chan_id, s);\n        case MSG_SNDIN_DATA_INCOMING:\n            return audin_process_incoming_data(chan_id, s);\n        case MSG_SNDIN_DATA:\n            return audin_process_data(chan_id, s);\n        case MSG_SNDIN_FORMATCHANGE:\n            return audin_process_format_change(chan_id, s);\n        default:\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_process_msg: unprocessed code %d\", code);\n            break;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_open_response(int chan_id, int creation_status)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_open_response: creation_status 0x%8.8x\", creation_status);\n    if (creation_status == 0)\n    {\n        return audin_send_version(chan_id);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_close_response(int chan_id)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_close_response:\");\n    g_audin_chanid = 0;\n    cleanup_client_formats();\n    free_stream(g_in_s);\n    g_in_s = NULL;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_data_fragment(int chan_id, char *data, int bytes)\n{\n    int rv;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"audin_data_fragment:\");\n    if (!s_check_rem(g_in_s, bytes))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_data_fragment: error bytes %d left %d\",\n                  bytes, (int) (g_in_s->end - g_in_s->p));\n        return 1;\n    }\n    out_uint8a(g_in_s, data, bytes);\n    if (g_in_s->p == g_in_s->end)\n    {\n        g_in_s->p = g_in_s->data;\n        rv = audin_process_msg(chan_id, g_in_s);\n        free_stream(g_in_s);\n        g_in_s = NULL;\n        return rv;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\naudin_data_first(int chan_id, char *data, int bytes, int total_bytes)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"audin_data_first:\");\n    if (g_in_s != NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_data_first: warning g_in_s is not nil\");\n        free_stream(g_in_s);\n    }\n    make_stream(g_in_s);\n    init_stream(g_in_s, total_bytes);\n    g_in_s->end = g_in_s->data + total_bytes;\n    return audin_data_fragment(chan_id, data, bytes);\n}\n\n/*****************************************************************************/\nstatic int\naudin_data(int chan_id, char *data, int bytes)\n{\n    struct stream ls;\n\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"audin_data:\", data, bytes);\n    if (g_in_s == NULL)\n    {\n        g_memset(&ls, 0, sizeof(ls));\n        ls.data = data;\n        ls.p = ls.data;\n        ls.end = ls.p + bytes;\n        return audin_process_msg(chan_id, &ls);\n    }\n    return audin_data_fragment(chan_id, data, bytes);\n}\n\n/*****************************************************************************/\nint\naudin_init(void)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_init:\");\n    g_memset(&g_audin_info, 0, sizeof(g_audin_info));\n    g_audin_info.open_response = audin_open_response;\n    g_audin_info.close_response = audin_close_response;\n    g_audin_info.data_first = audin_data_first;\n    g_audin_info.data = audin_data;\n    g_audin_chanid = 0;\n    g_in_s = NULL;\n    return 0;\n}\n\n/*****************************************************************************/\nint\naudin_deinit(void)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_deinit:\");\n    return 0;\n}\n\n/*****************************************************************************/\nint\naudin_start(void)\n{\n    int error;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_start:\");\n    if (g_audin_chanid != 0 || g_in_fifo == NULL)\n    {\n        return 1;\n    }\n\n    /* if there is any data in FIFO, discard it */\n    fifo_clear(g_in_fifo, NULL);\n    g_bytes_in_fifo = 0;\n\n    error = chansrv_drdynvc_open(AUDIN_NAME, AUDIN_FLAGS,\n                                 &g_audin_info, /* callback functions */\n                                 &g_audin_chanid); /* chansrv chan_id */\n    LOG_DEVEL(LOG_LEVEL_ERROR, \"audin_start: error %d g_audin_chanid %d\", error, g_audin_chanid);\n    return error;\n}\n\n/*****************************************************************************/\nint\naudin_stop(void)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"audin_stop:\");\n    chansrv_drdynvc_close(g_audin_chanid);\n    return 0;\n}\n"
  },
  {
    "path": "sesman/chansrv/audin.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2019\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * MS-RDPEAI\n *\n */\n\n#ifndef _AUDIN_H_\n#define _AUDIN_H_\n\nconst char *\naudin_wave_format_tag_to_str(int tag);\nint\naudin_init(void);\nint\naudin_deinit(void);\nint\naudin_start(void);\nint\naudin_stop(void);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/chansrv.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2009-2013\n * Copyright (C) Laxmikant Rashinkar 2009-2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#ifdef XRDP_IBUS\n#include \"input.h\"\n#endif\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"thread_calls.h\"\n#include \"trans.h\"\n#include \"chansrv.h\"\n#include \"defines.h\"\n#include \"sound.h\"\n#include \"clipboard.h\"\n#include \"devredir.h\"\n#include \"list.h\"\n#include \"file.h\"\n#include \"log.h\"\n#include \"rail.h\"\n#include \"xcommon.h\"\n#include \"chansrv_fuse.h\"\n#include \"chansrv_config.h\"\n#include \"xrdp_sockets.h\"\n#include \"xrdp_constants.h\"\n#include \"audin.h\"\n#include \"channel_defs.h\"\n\n#include \"scp.h\"\n#include \"scp_sync.h\"\n\n#include \"ms-rdpbcgr.h\"\n\nstatic struct trans *g_lis_trans = 0;\nstatic struct trans *g_con_trans = 0;\nstatic struct trans *g_api_lis_trans = 0;\nstatic struct list *g_api_con_trans_list = 0; /* list of apps using api functions */\nstatic struct chan_item g_chan_items[32];\nstatic int g_num_chan_items = 0;\nstatic int g_cliprdr_index = -1;\nstatic int g_rdpsnd_index = -1;\nstatic int g_rdpdr_index = -1;\nstatic int g_rail_index = -1;\n\nstatic tbus g_term_event = 0;\nstatic tintptr g_sigchld_event = 0;\nstatic tbus g_thread_done_event = 0;\n\nstruct config_chansrv *g_cfg = NULL;\n\nchar g_display_str[MAX_DISPLAY_NAME_SIZE];\n\nint g_cliprdr_chan_id = -1; /* cliprdr */\nint g_rdpsnd_chan_id = -1;  /* rdpsnd  */\nint g_rdpdr_chan_id = -1;   /* rdpdr   */\nint g_rail_chan_id = -1;    /* rail    */\n\nchar *g_exec_name;\ntbus g_exec_event = 0;\ntbus g_exec_mutex;\ntbus g_exec_sem;\nint g_exec_pid = 0;\n\n#define ARRAYSIZE(x) (sizeof(x)/sizeof(*(x)))\n/* max total channel bytes size */\n#define MAX_CHANNEL_BYTES (1 * 1024 * 1024 * 1024) /* 1 GB */\n#define MAX_CHANNEL_FRAG_BYTES 1600\n\n#define CHANSRV_DRDYNVC_STATUS_CLOSED       0\n#define CHANSRV_DRDYNVC_STATUS_OPEN_SENT    1\n#define CHANSRV_DRDYNVC_STATUS_OPEN         2\n#define CHANSRV_DRDYNVC_STATUS_CLOSE_SENT   3\n\nstruct chansrv_drdynvc\n{\n    int chan_id;\n    int status; /* see CHANSRV_DRDYNVC_STATUS_* */\n    int flags;\n    int pad0;\n    int (*open_response)(int chan_id, int creation_status);\n    int (*close_response)(int chan_id);\n    int (*data_first)(int chan_id, char *data, int bytes, int total_bytes);\n    int (*data)(int chan_id, char *data, int bytes);\n    struct trans *xrdp_api_trans;\n};\n\nstatic struct chansrv_drdynvc g_drdynvcs[256];\n\n/* data in struct trans::callback_data */\nstruct xrdp_api_data\n{\n    int chan_flags;\n    int chan_id;\n};\n\n// Session state passed to xrdpapi\n// Whenever a single member of this struct changes, the whole\n// block is sent to xrdpapi. This simplifies the interface, but\n// complicates xrdpapi somewhat\nstatic struct xrdp_chan_session_state g_session_state;\n\nstruct timeout_obj\n{\n    tui32 mstime;\n    void *data;\n    void (*callback)(void *data);\n    struct timeout_obj *next;\n};\n\nstatic struct timeout_obj *g_timeout_head = 0;\nstatic struct timeout_obj *g_timeout_tail = 0;\n\n/*****************************************************************************/\nint\nadd_timeout(int msoffset, void (*callback)(void *data), void *data)\n{\n    struct timeout_obj *tobj;\n    tui32 now;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"add_timeout:\");\n    now = g_get_elapsed_ms();\n    tobj = g_new0(struct timeout_obj, 1);\n    tobj->mstime = now + msoffset;\n    tobj->callback = callback;\n    tobj->data = data;\n    if (g_timeout_tail == 0)\n    {\n        g_timeout_head = tobj;\n        g_timeout_tail = tobj;\n    }\n    else\n    {\n        g_timeout_tail->next = tobj;\n        g_timeout_tail = tobj;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nget_timeout(int *timeout)\n{\n    struct timeout_obj *tobj;\n    tui32 now;\n    int ltimeout;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"get_timeout:\");\n    ltimeout = *timeout;\n    if (ltimeout < 1)\n    {\n        ltimeout = 0;\n    }\n    tobj = g_timeout_head;\n    if (tobj != 0)\n    {\n        now = g_get_elapsed_ms();\n        while (tobj != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  now %u tobj->mstime %u\", now, tobj->mstime);\n            if (now < tobj->mstime)\n            {\n                ltimeout = tobj->mstime - now;\n            }\n            tobj = tobj->next;\n        }\n    }\n    if (ltimeout > 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  ltimeout %d\", ltimeout);\n        if (*timeout < 1)\n        {\n            *timeout = ltimeout;\n        }\n        else\n        {\n            if (*timeout > ltimeout)\n            {\n                *timeout = ltimeout;\n            }\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\ncheck_timeout(void)\n{\n    struct timeout_obj *tobj;\n    struct timeout_obj *last_tobj;\n    struct timeout_obj *temp_tobj;\n    int count;\n    tui32 now;\n    UNUSED_VAR(count);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"check_timeout:\");\n    count = 0;\n    tobj = g_timeout_head;\n    if (tobj != 0)\n    {\n        last_tobj = 0;\n        while (tobj != 0)\n        {\n            count++;\n            now = g_get_elapsed_ms();\n            if (now >= tobj->mstime)\n            {\n                tobj->callback(tobj->data);\n                if (last_tobj == 0)\n                {\n                    g_timeout_head = tobj->next;\n                    if (g_timeout_head == 0)\n                    {\n                        g_timeout_tail = 0;\n                    }\n                }\n                else\n                {\n                    last_tobj->next = tobj->next;\n                    if (g_timeout_tail == tobj)\n                    {\n                        g_timeout_tail = last_tobj;\n                    }\n                }\n                temp_tobj = tobj;\n                tobj = tobj->next;\n                g_free(temp_tobj);\n            }\n            else\n            {\n                last_tobj = tobj;\n                tobj = tobj->next;\n            }\n        }\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  count %d\", count);\n    return 0;\n}\n\n/*****************************************************************************/\nint\ng_is_term(void)\n{\n    return g_is_wait_obj_set(g_term_event);\n}\n\n/*****************************************************************************/\n/* send data to a static virtual channel\n   size can be > MAX_CHANNEL_FRAG_BYTES, in which case, > 1 message\n   will be sent*/\n/* returns error */\nint\nsend_channel_data(int chan_id, const char *data, int size)\n{\n    int sending_bytes;\n    int chan_flags;\n    int error;\n    int total_size;\n    struct stream *s;\n\n    if ((chan_id < 0) || (chan_id > 31) ||\n            (data == NULL) ||\n            (size < 1) || (size > MAX_CHANNEL_BYTES))\n    {\n        /* bad param */\n        return 1;\n    }\n    total_size = size;\n    chan_flags = 1; /* first */\n    while (size > 0)\n    {\n        sending_bytes = MIN(MAX_CHANNEL_FRAG_BYTES, size);\n        if (sending_bytes >= size)\n        {\n            chan_flags |= 2; /* last */\n        }\n        s = trans_get_out_s(g_con_trans, 26 + sending_bytes);\n        if (s == NULL)\n        {\n            return 2;\n        }\n        out_uint32_le(s, 0); /* version */\n        out_uint32_le(s, 26 + sending_bytes);\n        out_uint32_le(s, 8); /* msg id */\n        out_uint32_le(s, 18 + sending_bytes);\n        out_uint16_le(s, chan_id);\n        out_uint16_le(s, chan_flags);\n        out_uint16_le(s, sending_bytes);\n        out_uint32_le(s, total_size);\n        out_uint8a(s, data, sending_bytes);\n        s_mark_end(s);\n        size -= sending_bytes;\n        data += sending_bytes;\n        error = trans_write_copy(g_con_trans);\n        if (error != 0)\n        {\n            return 3;\n        }\n        chan_flags = 0;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nsend_rail_drawing_orders(char *data, int size)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::send_rail_drawing_orders: size %d\", size);\n\n    struct stream *s;\n    int error;\n\n    s = trans_get_out_s(g_con_trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 8 + 8 + size); /* size */\n    out_uint32_le(s, 10); /* msg id */\n    out_uint32_le(s, 8 + size); /* size */\n    out_uint8a(s, data, size);\n    s_mark_end(s);\n    error = trans_force_write(g_con_trans);\n    if (error != 0)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Sends a session API state event to one listener\n */\nstatic int\nxrdpapi_send_session_state_event_single(struct trans *t)\n{\n    struct stream *s = t->out_s;\n    init_stream(s, (int)sizeof(g_session_state));\n    out_uint8a(s, &g_session_state, sizeof(g_session_state));\n    s_mark_end(s);\n    return trans_write_copy(t);\n}\n\n/*****************************************************************************/\n/**\n * Sends a session API state event to all listeners (if any)\n *\n * This should be called after updating g_session_state. The xrdpapi\n * module will generate any appropriate 'windows' events from the message\n */\nstatic void\nxrdpapi_send_session_state_event_all(void)\n{\n    int index;\n    struct trans *ltran;\n    struct xrdp_api_data *api_data;\n\n    for (index = 0; index < g_api_con_trans_list->count; index++)\n    {\n        ltran = (struct trans *) list_get_item(g_api_con_trans_list, index);\n        if (ltran != NULL)\n        {\n            api_data = (struct xrdp_api_data *) (ltran->callback_data);\n            if (api_data != NULL)\n            {\n                if (api_data->chan_id == CHAN_ID_XRDP_SESSION_INFO)\n                {\n                    (void)xrdpapi_send_session_state_event_single(ltran);\n                }\n            }\n        }\n    }\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nprocess_message_channel_setup(struct stream *s)\n{\n    int num_chans;\n    int index;\n    int rv;\n    struct chan_item *ci;\n\n    g_num_chan_items = 0;\n    g_cliprdr_index = -1;\n    g_rdpsnd_index = -1;\n    g_rdpdr_index = -1;\n    g_rail_index = -1;\n    g_cliprdr_chan_id = -1;\n    g_rdpsnd_chan_id = -1;\n    g_rdpdr_chan_id = -1;\n    g_rail_chan_id = -1;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_channel_setup:\");\n    in_uint16_le(s, num_chans);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_channel_setup: num_chans %d\",\n              num_chans);\n\n    for (index = 0; index < num_chans; index++)\n    {\n        ci = &(g_chan_items[g_num_chan_items]);\n        g_memset(ci->name, 0, sizeof(ci->name));\n        in_uint8a(s, ci->name, CHANNEL_NAME_LEN + 1);\n        in_uint16_le(s, ci->id);\n        in_uint16_le(s, ci->flags);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_channel_setup: chan name '%s' \"\n                  \"id %d flags %8.8x\", ci->name, ci->id, ci->flags);\n\n        if (g_strcasecmp(ci->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)\n        {\n            g_cliprdr_index = g_num_chan_items;\n            g_cliprdr_chan_id = ci->id;\n        }\n        else if (g_strcasecmp(ci->name, RDPSND_SVC_CHANNEL_NAME) == 0)\n        {\n            g_rdpsnd_index = g_num_chan_items;\n            g_rdpsnd_chan_id = ci->id;\n        }\n        else if (g_strcasecmp(ci->name, RDPDR_SVC_CHANNEL_NAME) == 0)\n        {\n            g_rdpdr_index = g_num_chan_items;\n            g_rdpdr_chan_id = ci->id;\n        }\n        /* disabled for now */\n        else if (g_strcasecmp(ci->name, RAIL_SVC_CHANNEL_NAME) == 0)\n        {\n            g_rail_index = g_num_chan_items;\n            g_rail_chan_id = ci->id;\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"other %s\", ci->name);\n        }\n\n        g_num_chan_items++;\n    }\n\n    rv = 0;\n\n    if (g_cliprdr_index >= 0)\n    {\n        clipboard_init();\n        xfuse_init();\n    }\n\n    if (g_rdpsnd_index >= 0)\n    {\n        sound_init();\n    }\n\n    if (g_rdpdr_index >= 0)\n    {\n        devredir_init();\n        xfuse_init();\n    }\n\n    if (g_rail_index >= 0)\n    {\n        rail_init();\n    }\n\n    audin_init();\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nprocess_message_channel_data(struct stream *s)\n{\n    int chan_id;\n    int chan_flags;\n    int rv;\n    int length;\n    int total_length;\n    int index;\n    int found;\n    struct stream *ls;\n    struct trans *ltran;\n    struct xrdp_api_data *api_data;\n\n    in_uint16_le(s, chan_id);\n    in_uint16_le(s, chan_flags);\n    in_uint16_le(s, length);\n    in_uint32_le(s, total_length);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_channel_data: chan_id %d \"\n              \"chan_flags %d\", chan_id, chan_flags);\n    rv = 0;\n\n    if (rv == 0)\n    {\n        if (chan_id == g_cliprdr_chan_id)\n        {\n            rv = clipboard_data_in(s, chan_id, chan_flags, length, total_length);\n        }\n        else if (chan_id == g_rdpsnd_chan_id)\n        {\n            rv = sound_data_in(s, chan_id, chan_flags, length, total_length);\n        }\n        else if (chan_id == g_rdpdr_chan_id)\n        {\n            rv = devredir_data_in(s, chan_id, chan_flags, length, total_length);\n        }\n        else if (chan_id == g_rail_chan_id)\n        {\n            rv = rail_data_in(s, chan_id, chan_flags, length, total_length);\n        }\n        else\n        {\n            found = 0;\n            for (index = 0; index < g_api_con_trans_list->count; index++)\n            {\n                ltran = (struct trans *) list_get_item(g_api_con_trans_list, index);\n                if (ltran != NULL)\n                {\n                    api_data = (struct xrdp_api_data *) (ltran->callback_data);\n                    if (api_data != NULL)\n                    {\n                        if (api_data->chan_id == chan_id)\n                        {\n                            found = 1;\n                            ls = ltran->out_s;\n                            if (chan_flags & 1) /* first */\n                            {\n                                init_stream(ls, total_length);\n                            }\n                            out_uint8a(ls, s->p, length);\n                            if (chan_flags & 2) /* last */\n                            {\n                                s_mark_end(ls);\n                                rv = trans_write_copy(ltran);\n                            }\n                            break;\n                        }\n                    }\n                }\n            }\n            if (found == 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_INFO, \"process_message_channel_data: not found channel %d\", chan_id);\n            }\n        }\n\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* open response from client */\nstatic int\nprocess_message_drdynvc_open_response(struct stream *s)\n{\n    struct chansrv_drdynvc *drdynvc;\n    int chan_id;\n    int creation_status;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_drdynvc_open_response:\");\n    if (!s_check_rem(s, 8))\n    {\n        return 1;\n    }\n    in_uint32_le(s, chan_id);\n    in_uint32_le(s, creation_status);\n    if ((chan_id < 0) || (chan_id > 255))\n    {\n        return 1;\n    }\n    drdynvc = g_drdynvcs + chan_id;\n    if (drdynvc->status != CHANSRV_DRDYNVC_STATUS_OPEN_SENT)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"process_message_drdynvc_open_response: status not right\");\n        return 1;\n    }\n    if (creation_status == 0)\n    {\n        drdynvc->status = CHANSRV_DRDYNVC_STATUS_OPEN;\n    }\n    else\n    {\n        drdynvc->status = CHANSRV_DRDYNVC_STATUS_CLOSED;\n    }\n    if (drdynvc->open_response != NULL)\n    {\n        if (drdynvc->open_response(chan_id, creation_status) != 0)\n        {\n            return 1;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* close response from client */\nstatic int\nprocess_message_drdynvc_close_response(struct stream *s)\n{\n    struct chansrv_drdynvc *drdynvc;\n    int chan_id;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_drdynvc_close_response:\");\n    if (!s_check_rem(s, 4))\n    {\n        return 1;\n    }\n    in_uint32_le(s, chan_id);\n    if ((chan_id < 0) || (chan_id > 255))\n    {\n        return 1;\n    }\n    drdynvc = g_drdynvcs + chan_id;\n    if (drdynvc->status != CHANSRV_DRDYNVC_STATUS_CLOSE_SENT)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"process_message_drdynvc_close_response: status not right\");\n        return 0;\n    }\n    drdynvc->status = CHANSRV_DRDYNVC_STATUS_CLOSED;\n    if (drdynvc->close_response != NULL)\n    {\n        if (drdynvc->close_response(chan_id) != 0)\n        {\n            return 1;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* data from client */\nstatic int\nprocess_message_drdynvc_data_first(struct stream *s)\n{\n    struct chansrv_drdynvc *drdynvc;\n    int chan_id;\n    int bytes;\n    int total_bytes;\n    char *data;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_drdynvc_data_first:\");\n    if (!s_check_rem(s, 12))\n    {\n        return 1;\n    }\n    in_uint32_le(s, chan_id);\n    in_uint32_le(s, bytes);\n    in_uint32_le(s, total_bytes);\n    if (!s_check_rem(s, bytes))\n    {\n        return 1;\n    }\n    in_uint8p(s, data, bytes);\n    if ((chan_id < 0) || (chan_id > 255))\n    {\n        return 1;\n    }\n    drdynvc = g_drdynvcs + chan_id;\n    if (drdynvc->data_first != NULL)\n    {\n        if (drdynvc->data_first(chan_id, data, bytes, total_bytes) != 0)\n        {\n            return 1;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\n/* data from client */\nstatic int\nprocess_message_drdynvc_data(struct stream *s)\n{\n    struct chansrv_drdynvc *drdynvc;\n    int chan_id;\n    int bytes;\n    char *data;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_drdynvc_data:\");\n    if (!s_check_rem(s, 8))\n    {\n        return 1;\n    }\n    in_uint32_le(s, chan_id);\n    in_uint32_le(s, bytes);\n    if (!s_check_rem(s, bytes))\n    {\n        return 1;\n    }\n    in_uint8p(s, data, bytes);\n    drdynvc = g_drdynvcs + chan_id;\n    if (drdynvc->data != NULL)\n    {\n        if (drdynvc->data(chan_id, data, bytes) != 0)\n        {\n            return 1;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* open call from chansrv */\nint\nchansrv_drdynvc_open(const char *name, int flags,\n                     struct chansrv_drdynvc_procs *procs, int *chan_id)\n{\n    struct stream *s;\n    int name_bytes;\n    int lchan_id;\n    int error;\n\n    lchan_id = 1;\n    while (g_drdynvcs[lchan_id].status != CHANSRV_DRDYNVC_STATUS_CLOSED)\n    {\n        lchan_id++;\n        if (lchan_id > 255)\n        {\n            return 1;\n        }\n    }\n    s = trans_get_out_s(g_con_trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    name_bytes = g_strlen(name);\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 8 + 8 + 4 + name_bytes + 4 + 4);\n    out_uint32_le(s, 12); /* msg id */\n    out_uint32_le(s, 8 + 4 + name_bytes + 4 + 4);\n    out_uint32_le(s, name_bytes);\n    out_uint8a(s, name, name_bytes);\n    out_uint32_le(s, flags);\n    out_uint32_le(s, lchan_id);\n    s_mark_end(s);\n    error = trans_write_copy(g_con_trans);\n    if (error == 0)\n    {\n        if (chan_id != NULL)\n        {\n            *chan_id = lchan_id;\n            g_drdynvcs[lchan_id].open_response = procs->open_response;\n            g_drdynvcs[lchan_id].close_response = procs->close_response;\n            g_drdynvcs[lchan_id].data_first = procs->data_first;\n            g_drdynvcs[lchan_id].data = procs->data;\n            g_drdynvcs[lchan_id].status = CHANSRV_DRDYNVC_STATUS_OPEN_SENT;\n\n        }\n    }\n    return error;\n}\n\n\n/*****************************************************************************/\n/* tell xrdp we can do Unicode input */\nstatic int\nchansrv_advertise_unicode_input(int status)\n{\n    struct stream *s = trans_get_out_s(g_con_trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 8 + 8 + 4);\n    out_uint32_le(s, 20); /* msg id */\n    out_uint32_le(s, 8 + 4);\n    out_uint32_le(s, status);\n    s_mark_end(s);\n    return trans_write_copy(g_con_trans);\n}\n\n/*****************************************************************************/\n/* close call from chansrv */\nint\nchansrv_drdynvc_close(int chan_id)\n{\n    struct stream *s;\n    int error;\n\n    s = trans_get_out_s(g_con_trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 20);\n    out_uint32_le(s, 14); /* msg id */\n    out_uint32_le(s, 12);\n    out_uint32_le(s, chan_id);\n    s_mark_end(s);\n    error = trans_write_copy(g_con_trans);\n    g_drdynvcs[chan_id].status = CHANSRV_DRDYNVC_STATUS_CLOSE_SENT;\n    return error;\n}\n\n/*****************************************************************************/\nint\nchansrv_drdynvc_data_first(int chan_id, const char *data, int data_bytes,\n                           int total_data_bytes)\n{\n    struct stream *s;\n    int error;\n\n    //LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv_drdynvc_data_first: data_bytes %d total_data_bytes %d\",\n    //          data_bytes, total_data_bytes);\n    s = trans_get_out_s(g_con_trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 28 + data_bytes);\n    out_uint32_le(s, 16); /* msg id */\n    out_uint32_le(s, 20 + data_bytes);\n    out_uint32_le(s, chan_id);\n    out_uint32_le(s, data_bytes);\n    out_uint32_le(s, total_data_bytes);\n    out_uint8a(s, data, data_bytes);\n    s_mark_end(s);\n    error = trans_write_copy(g_con_trans);\n    return error;\n}\n\n/*****************************************************************************/\nint\nchansrv_drdynvc_data(int chan_id, const char *data, int data_bytes)\n{\n    struct stream *s;\n    int error;\n\n    // LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv_drdynvc_data: data_bytes %d\", data_bytes);\n    s = trans_get_out_s(g_con_trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 24 + data_bytes);\n    out_uint32_le(s, 18); /* msg id */\n    out_uint32_le(s, 16 + data_bytes);\n    out_uint32_le(s, chan_id);\n    out_uint32_le(s, data_bytes);\n    out_uint8a(s, data, data_bytes);\n    s_mark_end(s);\n    error = trans_write_copy(g_con_trans);\n    return error;\n}\n\n/*****************************************************************************/\nint\nchansrv_drdynvc_send_data(int chan_id, const char *data, int data_bytes)\n{\n    int this_send_bytes;\n\n    // LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv_drdynvc_send_data: data_bytes %d\", data_bytes);\n    if (data_bytes > 1590)\n    {\n        if (chansrv_drdynvc_data_first(chan_id, data, 1590, data_bytes) != 0)\n        {\n            return 1;\n        }\n        data_bytes -= 1590;\n        data += 1590;\n    }\n    while (data_bytes > 0)\n    {\n        this_send_bytes = MIN(1590, data_bytes);\n        if (chansrv_drdynvc_data(chan_id, data, this_send_bytes) != 0)\n        {\n            return 1;\n        }\n        data_bytes -= this_send_bytes;\n        data += this_send_bytes;\n    }\n    return 0;\n}\n\n#ifdef XRDP_IBUS\n/*****************************************************************************/\nstatic int\nprocess_message_unicode_data(struct stream *s)\n{\n    int rv = 0;\n    int key_down;\n    char32_t unicode;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_unicode_keypress:\");\n    if (!s_check_rem(s, 8))\n    {\n        rv = 1;\n    }\n    else\n    {\n        in_uint32_le(s, key_down);\n        in_uint32_le(s, unicode);\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_message_unicode_keypress: received unicode %i\", unicode);\n\n        if (key_down)\n        {\n            xrdp_input_send_unicode(unicode);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nprocess_message_unicode_setup(struct stream *s)\n{\n    int rv = xrdp_input_unicode_init();\n    if (rv == 0)\n    {\n        // Tell xrdp we can support Unicode input\n        rv = chansrv_advertise_unicode_input(0);\n    }\n    else\n    {\n        // Tell xrdp there's a problem starting the framework\n        chansrv_advertise_unicode_input(2);\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nprocess_message_unicode_shutdown(struct stream *s)\n{\n    return xrdp_input_unicode_destroy();\n}\n#endif\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nprocess_message(void)\n{\n    struct stream *s = (struct stream *)NULL;\n    int size = 0;\n    int id = 0;\n    int rv = 0;\n    char *next_msg = (char *)NULL;\n\n    if (g_con_trans == 0)\n    {\n        return 1;\n    }\n\n    s = trans_get_in_s(g_con_trans);\n\n    if (s == 0)\n    {\n        return 1;\n    }\n\n    rv = 0;\n\n    while (s_check_rem(s, 8))\n    {\n        next_msg = s->p;\n        in_uint32_le(s, id);\n        in_uint32_le(s, size);\n        next_msg += size;\n\n        switch (id)\n        {\n            case 3: /* channel setup */\n                rv = process_message_channel_setup(s);\n                break;\n            case 5: /* channel data */\n                rv = process_message_channel_data(s);\n                break;\n            case 13: /* drdynvc open response */\n                rv = process_message_drdynvc_open_response(s);\n                break;\n            case 15: /* drdynvc close response */\n                rv = process_message_drdynvc_close_response(s);\n                break;\n            case 17: /* drdynvc data first */\n                rv = process_message_drdynvc_data_first(s);\n                break;\n            case 19: /* drdynvc data */\n                rv = process_message_drdynvc_data(s);\n                break;\n            case 21: /* unicode setup */\n#ifdef XRDP_IBUS\n                rv = process_message_unicode_setup(s);\n#else\n                // We don't support this.\n                rv = chansrv_advertise_unicode_input(1);\n#endif\n                break;\n            case 23: /* unicode key event */\n#ifdef XRDP_IBUS\n                rv = process_message_unicode_data(s);\n#endif\n                break;\n            case 25: /* unicode shut down */\n#ifdef XRDP_IBUS\n                rv = process_message_unicode_shutdown(s);\n#endif\n                break;\n\n            default:\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"process_message: unknown msg %d\", id);\n                break;\n        }\n\n        if (rv != 0)\n        {\n            g_writeln(\"process_message: error rv %d id %d\", rv, id);\n            rv = 0;\n        }\n\n        s->p = next_msg;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nmy_trans_data_in(struct trans *trans)\n{\n    struct stream *s = (struct stream *)NULL;\n    int size = 0;\n    int error = 0;\n\n    if (trans == 0)\n    {\n        return 0;\n    }\n\n    if (trans != g_con_trans)\n    {\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_trans_data_in:\");\n    s = trans_get_in_s(trans);\n    in_uint8s(s, 4); /* id */\n    in_uint32_le(s, size);\n    error = trans_force_read(trans, size - 8);\n\n    if (error == 0)\n    {\n        /* here, the entire message block is read in, process it */\n        error = process_message();\n        if (error == 0)\n        {\n        }\n        else\n        {\n            g_writeln(\"my_trans_data_in: process_message failed\");\n        }\n    }\n    else\n    {\n        g_writeln(\"my_trans_data_in: trans_force_read failed\");\n    }\n\n    return error;\n}\n\n/*****************************************************************************/\nstatic struct trans *\nget_api_trans_from_chan_id(int chan_id)\n{\n    return g_drdynvcs[chan_id].xrdp_api_trans;\n}\n\n/*****************************************************************************/\nstatic int\nmy_api_open_response(int chan_id, int creation_status)\n{\n    struct trans *trans;\n    struct stream *s;\n\n    //g_writeln(\"my_api_open_response: chan_id %d creation_status %d\",\n    //          chan_id, creation_status);\n    trans = get_api_trans_from_chan_id(chan_id);\n    if (trans == NULL)\n    {\n        return 1;\n    }\n    s = trans_get_out_s(trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_pe(s, creation_status);\n    s_mark_end(s);\n    if (trans_write_copy(trans) != 0)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nmy_api_close_response(int chan_id)\n{\n    //g_writeln(\"my_api_close_response:\");\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nmy_api_data_first(int chan_id, char *data, int bytes, int total_bytes)\n{\n    struct trans *trans;\n    struct stream *s;\n\n    //g_writeln(\"my_api_data_first: bytes %d total_bytes %d\", bytes, total_bytes);\n    trans = get_api_trans_from_chan_id(chan_id);\n    if (trans == NULL)\n    {\n        return 1;\n    }\n    s = trans_get_out_s(trans, bytes);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint8a(s, data, bytes);\n    s_mark_end(s);\n    if (trans_write_copy(trans) != 0)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nmy_api_data(int chan_id, char *data, int bytes)\n{\n    struct trans *trans;\n    struct stream *s;\n\n    //g_writeln(\"my_api_data: bytes %d\", bytes);\n    trans = get_api_trans_from_chan_id(chan_id);\n    if (trans == NULL)\n    {\n        return 1;\n    }\n    s = trans_get_out_s(trans, bytes);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint8a(s, data, bytes);\n    s_mark_end(s);\n    if (trans_write_copy(trans) != 0)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*\n * Handles an incoming channel connect request on an xrdpapi channel\n *\n ******************************************************************************/\nstatic int\nhandle_xrdpapi_connection_request(struct trans *trans)\n{\n    struct xrdp_api_data *ad = (struct xrdp_api_data *)(trans->callback_data);\n    struct stream *s = trans_get_in_s(trans);\n    int rv = 1; // Assume failure\n    struct xrdp_chan_connect connect_data;\n\n    in_uint8a(s, &connect_data, sizeof(connect_data));\n    connect_data.name[MAX_DVC_NAME_LEN] = '\\0';\n    //LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_api_trans_data_in: chan_name %s chan_flags 0x%8.8x\", connect_data.name, connect_data.flags);\n    if (connect_data.version != XRDPAPI_CONNECT_PDU_VERSION)\n    {\n        return 1;\n    }\n    ad->chan_flags = connect_data.flags;\n\n    if (connect_data.flags == 0 || connect_data.private_chan != 0)\n    {\n        /* SVC (or private) */\n        if (connect_data.private_chan >= CHAN_ID_XRDP_BASE &&\n                connect_data.private_chan < CHAN_ID_XRDP_MAX)\n        {\n            /* Valid private channel */\n            ad->chan_id = connect_data.private_chan;\n            ad->chan_flags = 0;\n            rv = 0;\n        }\n        else if (connect_data.private_chan == 0)\n        {\n            /* Check SVC names */\n            int index;\n            for (index = 0; index < g_num_chan_items; index++)\n            {\n                if (g_strcasecmp(g_chan_items[index].name,\n                                 connect_data.name) == 0)\n                {\n                    ad->chan_id = g_chan_items[index].id;\n                    rv = 0;\n                    break;\n                }\n            }\n        }\n\n        /* Send the status back to the caller */\n        struct stream *out_s = trans_get_out_s(trans, 8192);\n        if (out_s == NULL)\n        {\n            return 1;\n        }\n        out_uint32_pe(out_s, rv);\n        s_mark_end(out_s);\n        if (trans_write_copy(trans) != 0)\n        {\n            return 1;\n        }\n\n        /* Channel-specific processing */\n        if (rv == 0 && connect_data.private_chan != 0)\n        {\n            switch (connect_data.private_chan)\n            {\n                case CHAN_ID_XRDP_SESSION_INFO:\n                {\n                    rv = xrdpapi_send_session_state_event_single(trans);\n                    break;\n                }\n                default:\n                    break;\n            }\n        }\n    }\n    else\n    {\n        /* DVS */\n        struct chansrv_drdynvc_procs procs;\n        g_memset(&procs, 0, sizeof(procs));\n        procs.open_response = my_api_open_response;\n        procs.close_response = my_api_close_response;\n        procs.data_first = my_api_data_first;\n        procs.data = my_api_data;\n        rv = chansrv_drdynvc_open(connect_data.name, ad->chan_flags,\n                                  &procs, &(ad->chan_id));\n        //LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_api_trans_data_in: chansrv_drdynvc_open rv %d \"\n        //          \"chan_id %d\", rv, ad->chan_id);\n        g_drdynvcs[ad->chan_id].xrdp_api_trans = trans;\n    }\n\n    return rv;\n}\n\n/*\n * called when VirtualChannelOpen() is invoked in xrdpapi.c, and later,\n * when the channel is written to\n *\n ******************************************************************************/\nstatic int\nmy_api_trans_data_in(struct trans *trans)\n{\n    struct stream *s;\n    struct xrdp_api_data *ad;\n    int rv;\n    int bytes;\n\n    //LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_api_trans_data_in: extra_flags %d\", trans->extra_flags);\n    rv = 0;\n    ad = (struct xrdp_api_data *) (trans->callback_data);\n    s = trans_get_in_s(trans);\n    if (trans->extra_flags == 0)\n    {\n        trans->header_size = XRDPAPI_CONNECT_PDU_LEN; // Need more data\n        trans->extra_flags = 1;\n    }\n    else if (trans->extra_flags == 1)\n    {\n        // We've got a complete connection request on the channel */\n        handle_xrdpapi_connection_request(trans);\n        init_stream(s, 0);\n        trans->extra_flags = 2; // Mark the connection phase as complete\n        trans->header_size = 0;\n    }\n    else\n    {\n        bytes = g_sck_recv(trans->sck, s->data, s->size, 0);\n        if (bytes < 1)\n        {\n            //LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_api_trans_data_in: disconnect\");\n            return 1;\n        }\n        if (ad->chan_flags == 0)\n        {\n            if (ad->chan_id == CHAN_ID_XRDP_SESSION_INFO)\n            {\n                // Ignore data sent to this channel\n                rv = 0;\n            }\n            else\n            {\n                /* SVC */\n                rv = send_channel_data(ad->chan_id, s->data, bytes);\n            }\n        }\n        else\n        {\n            /* DVS */\n            //LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_api_trans_data_in: s->size %d bytes %d\", s->size, bytes);\n            rv = chansrv_drdynvc_send_data(ad->chan_id, s->data, bytes);\n        }\n        init_stream(s, 0);\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nmy_trans_conn_in(struct trans *trans, struct trans *new_trans)\n{\n    if (trans == 0)\n    {\n        return 1;\n    }\n\n    if (trans != g_lis_trans)\n    {\n        return 1;\n    }\n\n    if (g_con_trans != 0) /* if already set, error */\n    {\n        return 1;\n    }\n\n    if (new_trans == 0)\n    {\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_trans_conn_in:\");\n    g_con_trans = new_trans;\n    g_con_trans->trans_data_in = my_trans_data_in;\n    g_con_trans->header_size = 8;\n\n    /* Tell any xrdpapi listeners the session is connected. The\n     * previous state is guaranteed to be 'disconnected' at this point */\n    g_session_state.is_connected = 1;\n    xrdpapi_send_session_state_event_all();\n\n    /* stop listening */\n    trans_delete(g_lis_trans);\n    g_lis_trans = 0;\n    return 0;\n}\n\n/*\n * called when WTSVirtualChannelOpenEx is invoked in xrdpapi.c\n *\n ******************************************************************************/\nstatic int\nmy_api_trans_conn_in(struct trans *trans, struct trans *new_trans)\n{\n    struct xrdp_api_data *ad;\n\n    //LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_api_trans_conn_in:\");\n    if ((trans == NULL) || (trans != g_api_lis_trans) || (new_trans == NULL))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"my_api_trans_conn_in: error\");\n        return 1;\n    }\n    new_trans->trans_data_in = my_api_trans_data_in;\n    new_trans->header_size = 8;\n    new_trans->no_stream_init_on_data_in = 1;\n    ad = g_new0(struct xrdp_api_data, 1);\n    if (ad == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"my_api_trans_conn_in: error\");\n        return 1;\n    }\n    new_trans->callback_data = ad;\n    list_add_item(g_api_con_trans_list, (intptr_t) new_trans);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nsetup_listen(void)\n{\n    char port[XRDP_SOCKETS_MAXPATH];\n    int error = 0;\n\n    if (g_lis_trans != 0)\n    {\n        trans_delete(g_lis_trans);\n    }\n\n    g_lis_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);\n    g_lis_trans->is_term = g_is_term;\n    g_snprintf(port, sizeof(port), XRDP_CHANSRV_STR,\n               g_getuid(), g_display_str);\n\n    g_lis_trans->trans_conn_in = my_trans_conn_in;\n    error = trans_listen(g_lis_trans, port);\n\n    if (error != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"setup_listen: trans_listen failed for port %s\",\n                  port);\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nsetup_api_listen(void)\n{\n    char port[XRDP_SOCKETS_MAXPATH];\n    int error = 0;\n\n    g_api_lis_trans = trans_create(TRANS_MODE_UNIX, 8192 * 4, 8192 * 4);\n    g_api_lis_trans->is_term = g_is_term;\n    g_snprintf(port, sizeof(port), CHANSRV_API_STR,\n               g_getuid(), g_display_str);\n    g_api_lis_trans->trans_conn_in = my_api_trans_conn_in;\n    error = trans_listen(g_api_lis_trans, port);\n\n    if (error != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"setup_api_listen: trans_listen failed for port %s\",\n                  port);\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\napi_con_trans_list_get_wait_objs_rw(intptr_t *robjs, int *rcount,\n                                    intptr_t *wobjs, int *wcount,\n                                    int *timeout)\n{\n    int api_con_index;\n    struct trans *ltran;\n\n    for (api_con_index = g_api_con_trans_list->count - 1;\n            api_con_index >= 0;\n            api_con_index--)\n    {\n        ltran = (struct trans *)\n                list_get_item(g_api_con_trans_list, api_con_index);\n        if (ltran != NULL)\n        {\n            trans_get_wait_objs_rw(ltran, robjs, rcount, wobjs, wcount,\n                                   timeout);\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\napi_con_trans_list_check_wait_objs(void)\n{\n    int api_con_index;\n    int drdynvc_index;\n    struct trans *ltran;\n    struct xrdp_api_data *ad;\n\n    for (api_con_index = g_api_con_trans_list->count - 1;\n            api_con_index >= 0;\n            api_con_index--)\n    {\n        ltran = (struct trans *)\n                list_get_item(g_api_con_trans_list, api_con_index);\n        if (ltran != NULL)\n        {\n            if (trans_check_wait_objs(ltran) != 0)\n            {\n                /* disconnect */\n                list_remove_item(g_api_con_trans_list, api_con_index);\n                ad = (struct xrdp_api_data *) (ltran->callback_data);\n                if (ad->chan_flags != 0)\n                {\n                    chansrv_drdynvc_close(ad->chan_id);\n                }\n                for (drdynvc_index = 0;\n                        drdynvc_index < (int) ARRAYSIZE(g_drdynvcs);\n                        drdynvc_index++)\n                {\n                    if (g_drdynvcs[drdynvc_index].xrdp_api_trans == ltran)\n                    {\n                        g_drdynvcs[drdynvc_index].xrdp_api_trans = NULL;\n                    }\n                }\n                g_free(ad);\n                trans_delete(ltran);\n            }\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\napi_con_trans_list_remove_all(void)\n{\n    int api_con_index;\n    struct trans *ltran;\n\n    for (api_con_index = g_api_con_trans_list->count - 1;\n            api_con_index >= 0;\n            api_con_index--)\n    {\n        ltran = (struct trans *)\n                list_get_item(g_api_con_trans_list, api_con_index);\n        if (ltran != NULL)\n        {\n            list_remove_item(g_api_con_trans_list, api_con_index);\n            g_free(ltran->callback_data);\n            trans_delete(ltran);\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic THREAD_RV THREAD_CC\nchannel_thread_loop(void *in_val)\n{\n    tbus objs[32];\n    tbus wobjs[32];\n    int num_objs;\n    int num_wobjs;\n    int timeout;\n    int error;\n    THREAD_RV rv;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"channel_thread_loop: thread start\");\n    rv = 0;\n    g_api_con_trans_list = list_create();\n    setup_api_listen();\n    error = setup_listen();\n\n    if (error == 0)\n    {\n        timeout = -1;\n        num_objs = 0;\n        num_wobjs = 0;\n        objs[num_objs] = g_term_event;\n        num_objs++;\n        trans_get_wait_objs(g_lis_trans, objs, &num_objs);\n        trans_get_wait_objs(g_api_lis_trans, objs, &num_objs);\n\n        //g_writeln(\"timeout %d\", timeout);\n        while (g_obj_wait(objs, num_objs, wobjs, num_wobjs, timeout) == 0)\n        {\n            check_timeout();\n            if (g_is_wait_obj_set(g_term_event))\n            {\n                LOG_DEVEL(LOG_LEVEL_INFO, \"channel_thread_loop: g_term_event set\");\n                clipboard_deinit();\n                sound_deinit();\n                devredir_deinit();\n                rail_deinit();\n                break;\n            }\n\n            if (g_lis_trans != 0)\n            {\n                if (trans_check_wait_objs(g_lis_trans) != 0)\n                {\n                    LOG_DEVEL(LOG_LEVEL_INFO, \"channel_thread_loop: \"\n                              \"trans_check_wait_objs error\");\n                }\n            }\n\n            if (g_con_trans != 0)\n            {\n                if (trans_check_wait_objs(g_con_trans) != 0)\n                {\n                    LOG_DEVEL(LOG_LEVEL_INFO, \"channel_thread_loop: \"\n                              \"trans_check_wait_objs error resetting\");\n\n                    clipboard_deinit();\n                    sound_deinit();\n                    devredir_deinit();\n                    rail_deinit();\n                    /* delete g_con_trans */\n                    trans_delete(g_con_trans);\n                    g_con_trans = 0;\n                    /* Tell any xrdpapi listeners the session is\n                     * disconnected.  The previous state is guaranteed\n                     * to be 'connected' at this point */\n                    g_session_state.is_connected = 0;\n                    (void)xrdpapi_send_session_state_event_all();\n                    /* create new listener */\n                    error = setup_listen();\n\n                    if (error != 0)\n                    {\n                        break;\n                    }\n                }\n            }\n\n            if (g_api_lis_trans != 0)\n            {\n                if (trans_check_wait_objs(g_api_lis_trans) != 0)\n                {\n                    LOG_DEVEL(LOG_LEVEL_ERROR, \"channel_thread_loop: trans_check_wait_objs failed\");\n                }\n            }\n            /* check the wait_objs in g_api_con_trans_list */\n            api_con_trans_list_check_wait_objs();\n            xcommon_check_wait_objs();\n            sound_check_wait_objs();\n            devredir_check_wait_objs();\n            xfuse_check_wait_objs();\n            timeout = -1;\n            num_objs = 0;\n            num_wobjs = 0;\n            objs[num_objs] = g_term_event;\n            num_objs++;\n            trans_get_wait_objs_rw(g_lis_trans, objs, &num_objs,\n                                   wobjs, &num_wobjs, &timeout);\n            trans_get_wait_objs_rw(g_con_trans, objs, &num_objs,\n                                   wobjs, &num_wobjs, &timeout);\n            trans_get_wait_objs_rw(g_api_lis_trans, objs, &num_objs,\n                                   wobjs, &num_wobjs, &timeout);\n            /* get the wait_objs from in g_api_con_trans_list */\n            api_con_trans_list_get_wait_objs_rw(objs, &num_objs,\n                                                wobjs, &num_wobjs,\n                                                &timeout);\n            xcommon_get_wait_objs(objs, &num_objs, &timeout);\n            sound_get_wait_objs(objs, &num_objs, &timeout);\n            devredir_get_wait_objs(objs, &num_objs, &timeout);\n            xfuse_get_wait_objs(objs, &num_objs, &timeout);\n            get_timeout(&timeout);\n        } /* end while (g_obj_wait(objs, num_objs, 0, 0, timeout) == 0) */\n    }\n\n    trans_delete(g_lis_trans);\n    g_lis_trans = 0;\n    trans_delete(g_con_trans);\n    g_con_trans = 0;\n    /* Tell any xrdpapi listeners the session is disconnected */\n    if (g_session_state.is_connected)\n    {\n        g_session_state.is_connected = 0;\n        (void)xrdpapi_send_session_state_event_all();\n    }\n    trans_delete(g_api_lis_trans);\n    g_api_lis_trans = 0;\n    api_con_trans_list_remove_all();\n    list_delete(g_api_con_trans_list);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"channel_thread_loop: thread stop\");\n    g_set_wait_obj(g_thread_done_event);\n    return rv;\n}\n\n/*****************************************************************************/\nstatic void\nterm_signal_handler(int sig)\n{\n    g_set_wait_obj(g_term_event);\n}\n\n/*****************************************************************************/\nstatic void\nnil_signal_handler(int sig)\n{\n}\n\n/*****************************************************************************/\nstatic void\nset_sigchld_event(int sig)\n{\n    g_set_wait_obj(g_sigchld_event);\n}\n\n/*****************************************************************************/\nstatic void\nchild_signal_handler(void)\n{\n    int pid;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"child_signal_handler:\");\n    while ((pid = g_waitchild(NULL)) > 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO, \"child_signal_handler: child pid %d\", pid);\n        if (pid == g_exec_pid)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"child_signal_handler: found pid %d\", pid);\n            //shutdownx();\n        }\n    }\n}\n\n/*****************************************************************************/\nstatic void\nsegfault_signal_handler(int sig)\n{\n    LOG_DEVEL(LOG_LEVEL_ERROR, \"segfault_signal_handler: entered.......\");\n    xfuse_deinit();\n    exit(0);\n}\n\n/*****************************************************************************/\nstatic void\nx_server_fatal_handler(void)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xserver_fatal_handler: entered.......\");\n    /* At this point the X server has gone away. Dont make any X calls. */\n    xfuse_deinit();\n    exit(0);\n}\n\n/*****************************************************************************/\nint\nmain_cleanup(void)\n{\n    if (g_term_event != 0)\n    {\n        g_delete_wait_obj(g_term_event);\n    }\n    if (g_sigchld_event != 0)\n    {\n        g_delete_wait_obj(g_sigchld_event);\n    }\n    if (g_thread_done_event != 0)\n    {\n        g_delete_wait_obj(g_thread_done_event);\n    }\n    if (g_exec_event != 0)\n    {\n        g_delete_wait_obj(g_exec_event);\n        tc_mutex_delete(g_exec_mutex);\n        tc_sem_delete(g_exec_sem);\n    }\n    log_end();\n    config_free(g_cfg);\n    g_deinit(); /* os_calls */\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nget_log_path(char *path, int bytes)\n{\n    char *log_path;\n    int rv;\n\n    rv = 1;\n    if (g_cfg->log_file_path != NULL && g_cfg->log_file_path[0] != '\\0')\n    {\n        char uidstr[64];\n        char username[64];\n        const struct info_string_tag map[] =\n        {\n            {'u', uidstr},\n            {'U', username},\n            INFO_STRING_END_OF_LIST\n        };\n\n        int uid = g_getuid();\n        g_snprintf(uidstr, sizeof(uidstr), \"%d\", uid);\n        if (g_getlogin(username, sizeof(username)) != 0)\n        {\n            /* Fall back to UID */\n            g_strncpy(username, uidstr, sizeof(username) - 1);\n        }\n\n        (void)g_format_info_string(path, bytes, g_cfg->log_file_path, map);\n        if (g_directory_exist(path) || (g_mkdir(path) == 0))\n        {\n            rv = 0;\n        }\n    }\n    else if ((log_path = g_getenv(\"CHANSRV_LOG_PATH\")) != 0)\n    {\n        g_snprintf(path, bytes, \"%s\", log_path);\n        if (g_directory_exist(path) || (g_mkdir(path) == 0))\n        {\n            rv = 0;\n        }\n    }\n    else if ((log_path = g_getenv(\"XDG_DATA_HOME\")) != 0)\n    {\n        g_snprintf(path, bytes, \"%s%s\", log_path, \"/xrdp\");\n        if (g_directory_exist(path) || (g_mkdir(path) == 0))\n        {\n            rv = 0;\n        }\n    }\n\n    // Always fall back to the home directory\n    if (rv != 0)\n    {\n        log_path = g_getenv(\"HOME\");\n        if (log_path != 0)\n        {\n            g_snprintf(path, bytes, \"%s%s\", log_path, \"/.local\");\n            if (g_directory_exist(path) || (g_mkdir(path) == 0))\n            {\n                g_snprintf(path, bytes, \"%s%s\", log_path, \"/.local/share\");\n                if (g_directory_exist(path) || (g_mkdir(path) == 0))\n                {\n                    g_snprintf(path, bytes, \"%s%s\", log_path, \"/.local/share/xrdp\");\n                    if (g_directory_exist(path) || (g_mkdir(path) == 0))\n                    {\n                        rv = 0;\n                    }\n                }\n            }\n        }\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nrun_exec(void)\n{\n    int pid;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"run_exec:\");\n    pid = g_fork();\n\n    if (pid == 0)\n    {\n        trans_delete(g_con_trans);\n        g_close_wait_obj(g_term_event);\n        g_close_wait_obj(g_sigchld_event);\n        g_close_wait_obj(g_thread_done_event);\n        g_close_wait_obj(g_exec_event);\n        tc_mutex_delete(g_exec_mutex);\n        tc_sem_delete(g_exec_sem);\n        g_execlp3(g_exec_name, g_exec_name, 0);\n        g_exit(0);\n    }\n\n    g_exec_pid = pid;\n    tc_sem_inc(g_exec_sem);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Make sure XRDP_SOCKET_PATH exists\n *\n * We can't do anything without XRDP_SOCKET_PATH existing.\n *\n * Normally this is done by sesman before chansrv starts. If we're running\n * standalone however (i.e. with x11vnc) this won't be done. We don't have the\n * privilege to create the directory, so we have to ask sesman to do it\n * for us.\n */\nstatic int\nchansrv_create_xrdp_socket_path(void)\n{\n    char xrdp_socket_path[XRDP_SOCKETS_MAXPATH];\n    int rv = 1;\n\n    /* Use our UID to qualify XRDP_SOCKET_PATH */\n    g_snprintf(xrdp_socket_path, sizeof(xrdp_socket_path),\n               XRDP_SOCKET_PATH, g_getuid());\n\n    if (g_directory_exist(xrdp_socket_path))\n    {\n        rv = 0;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO, \"%s doesn't exist - asking sesman to create it\",\n            xrdp_socket_path);\n\n        struct trans *t = NULL;\n\n        if (!(t = scp_connect(g_cfg->listen_port, \"xrdp-chansrv\", g_is_term)))\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't connect to sesman\");\n        }\n        else if (scp_sync_uds_login_request(t) == 0 &&\n                 scp_sync_create_sockdir_request(t) == 0)\n        {\n            rv = 0;\n            (void)scp_send_close_connection_request(t);\n        }\n        trans_delete(t);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    tbus waiters[4];\n    int pid = 0;\n    char text[256];\n    const char *config_path;\n    char log_path[256];\n    char log_file[256];\n    enum logReturns error;\n    struct log_config *logconfig;\n    g_init(\"xrdp-chansrv\"); /* os_calls */\n    g_memset(g_drdynvcs, 0, sizeof(g_drdynvcs));\n\n    if (g_get_display_string(g_display_str, sizeof(g_display_str)) < 0)\n    {\n        g_writeln(\"Unable to get display string\");\n        main_cleanup();\n        return 1;\n    }\n\n    /*\n     * The user is unable at present to override the sysadmin-provided\n     * sesman.ini location */\n    config_path = XRDP_CFG_PATH \"/sesman.ini\";\n    if ((g_cfg = config_read(0, config_path)) == NULL)\n    {\n        main_cleanup();\n        return 1;\n    }\n    config_dump(g_cfg);\n\n    if (get_log_path(log_path, sizeof(log_path)) != 0)\n    {\n        g_writeln(\"error reading CHANSRV_LOG_PATH and HOME environment variable\");\n        main_cleanup();\n        return 1;\n    }\n\n    pid = g_getpid();\n\n    /* starting logging subsystem */\n    g_snprintf(log_file, sizeof(log_file),\n               \"%s/xrdp-chansrv.%s.log\", log_path, g_display_str);\n    g_writeln(\"chansrv::main: using log file [%s]\", log_file);\n    if (g_file_exist(log_file))\n    {\n        g_file_delete(log_file);\n    }\n\n    logconfig = log_config_init_from_config(config_path, \"xrdp-chansrv\", \"Chansrv\");\n    if (logconfig->log_file != NULL)\n    {\n        g_free(logconfig->log_file);\n    }\n    logconfig->log_file = log_file;\n    error = log_start_from_param(logconfig);\n    logconfig->log_file = NULL;\n    log_config_free(logconfig);\n    logconfig = NULL;\n\n    if (error != LOG_STARTUP_OK)\n    {\n        switch (error)\n        {\n            case LOG_ERROR_MALLOC:\n                g_writeln(\"error on malloc. cannot start logging. quitting.\");\n                break;\n            case LOG_ERROR_FILE_OPEN:\n                g_writeln(\"error opening log file [%s]. quitting.\",\n                          getLogFile(text, 255));\n                break;\n            default:\n                g_writeln(\"log_start error\");\n                break;\n        }\n\n        main_cleanup();\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"main: app started pid %d(0x%8.8x)\", pid, pid);\n\n    if (chansrv_create_xrdp_socket_path() != 0)\n    {\n        main_cleanup();\n        return 1;\n    }\n\n    /*  set up signal objects  */\n    g_snprintf(text, sizeof(text), \"xrdp_chansrv_%8.8x_main_term\", pid);\n    g_term_event = g_create_wait_obj(text);\n    g_snprintf(text, sizeof(text), \"xrdp_chansrv_%8.8x_sigchld\", pid);\n    g_sigchld_event = g_create_wait_obj(text);\n\n    /*  set up signal handlers */\n    g_signal_terminate(term_signal_handler); /* SIGTERM */\n    g_signal_user_interrupt(term_signal_handler); /* SIGINT */\n    g_signal_pipe(nil_signal_handler); /* SIGPIPE */\n    g_signal_child_stop(set_sigchld_event); /* SIGCHLD */\n    g_signal_segfault(segfault_signal_handler);\n\n    /* Cater for the X server exiting unexpectedly */\n    xcommon_set_x_server_fatal_handler(x_server_fatal_handler);\n\n    /* Set up RAIL sync objects */\n    g_snprintf(text, sizeof(text), \"xrdp_chansrv_%8.8x_exec\", pid);\n    g_exec_event = g_create_wait_obj(text);\n    g_exec_mutex = tc_mutex_create();\n    g_exec_sem = tc_sem_create(0);\n\n    /* Set up the channel thread */\n    g_snprintf(text, sizeof(text), \"xrdp_chansrv_%8.8x_thread_done\", pid);\n    g_thread_done_event = g_create_wait_obj(text);\n    tc_thread_create(channel_thread_loop, 0);\n\n    while (g_term_event > 0 && !g_is_wait_obj_set(g_term_event))\n    {\n        waiters[0] = g_term_event;\n        waiters[1] = g_exec_event;\n        waiters[2] = g_sigchld_event;\n\n        if (g_obj_wait(waiters, 3, 0, 0, -1) != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"main: error, g_obj_wait failed\");\n            break;\n        }\n\n        if (g_is_wait_obj_set(g_term_event))\n        {\n            break;\n        }\n\n        if (g_is_wait_obj_set(g_sigchld_event))\n        {\n            g_reset_wait_obj(g_sigchld_event);\n            child_signal_handler();\n        }\n\n        if (g_is_wait_obj_set(g_exec_event))\n        {\n            g_reset_wait_obj(g_exec_event);\n            run_exec();\n        }\n    }\n\n    while (g_thread_done_event > 0 && !g_is_wait_obj_set(g_thread_done_event))\n    {\n        /* wait for thread to exit */\n        if (g_obj_wait(&g_thread_done_event, 1, 0, 0, -1) != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"main: error, g_obj_wait failed\");\n            break;\n        }\n    }\n\n    /* cleanup */\n    main_cleanup();\n    LOG_DEVEL(LOG_LEVEL_INFO, \"main: app exiting pid %d(0x%8.8x)\", pid, pid);\n    return 0;\n}\n"
  },
  {
    "path": "sesman/chansrv/chansrv.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2009-2013\n * Copyright (C) Laxmikant Rashinkar 2009-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(CHANSRV_H)\n#define CHANSRV_H\n\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"log.h\"\n\nstruct chan_item\n{\n    int id;\n    int flags;\n    char name[16];\n};\n\nint\ng_is_term(void);\n\nint send_channel_data(int chan_id, const char *data, int size);\nint send_rail_drawing_orders(char *data, int size);\nint main_cleanup(void);\nint add_timeout(int msoffset, void (*callback)(void *data), void *data);\n\n#ifndef GSET_UINT8\n#define GSET_UINT8(_ptr, _offset, _data) \\\n    *((unsigned char*) (((unsigned char*)(_ptr)) + (_offset))) = (unsigned char)(_data)\n#define GGET_UINT8(_ptr, _offset) \\\n    (*((unsigned char*) (((unsigned char*)(_ptr)) + (_offset))))\n#define GSET_UINT16(_ptr, _offset, _data) \\\n    GSET_UINT8(_ptr, _offset, _data); \\\n    GSET_UINT8(_ptr, (_offset) + 1, (_data) >> 8)\n#define GGET_UINT16(_ptr, _offset) \\\n    (GGET_UINT8(_ptr, _offset)) | \\\n    ((GGET_UINT8(_ptr, (_offset) + 1)) << 8)\n#define GSET_UINT32(_ptr, _offset, _data) \\\n    GSET_UINT16(_ptr, _offset, _data); \\\n    GSET_UINT16(_ptr, (_offset) + 2, (_data) >> 16)\n#define GGET_UINT32(_ptr, _offset) \\\n    (GGET_UINT16(_ptr, _offset)) | \\\n    ((GGET_UINT16(_ptr, (_offset) + 2)) << 16)\n#endif\n\nstruct chansrv_drdynvc_procs\n{\n    int (*open_response)(int chan_id, int creation_status);\n    int (*close_response)(int chan_id);\n    int (*data_first)(int chan_id, char *data, int bytes, int total_bytes);\n    int (*data)(int chan_id, char *data, int bytes);\n};\n\nint\nchansrv_drdynvc_open(const char *name, int flags,\n                     struct chansrv_drdynvc_procs *procs, int *chan_id);\nint\nchansrv_drdynvc_close(int chan_id);\nint\nchansrv_drdynvc_data_first(int chan_id, const char *data, int data_bytes,\n                           int total_data_bytes);\nint\nchansrv_drdynvc_data(int chan_id, const char *data, int data_bytes);\nint\nchansrv_drdynvc_send_data(int chan_id, const char *data, int data_bytes);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/chansrv_common.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2009-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"chansrv_common.h\"\n\n/**\n * Assemble fragmented incoming packets into one stream\n *\n * @param  src           stream that contains partial data\n * @param  dest          stream that contains entire data\n * @param  chan_flags    fragmentation flags\n * @param  length        bytes in this packet\n * @param  total_length  total length of assembled packet\n *\n * @return 1 when all data has been assembled, 0 otherwise\n *\n * NOTE: it is the responsibility of the caller to free dest stream\n ****************************************************************************/\nint\nread_entire_packet(struct stream *src, struct stream **dest, int chan_flags,\n                   int length, int total_length)\n{\n    struct stream *ls;\n\n    if ((chan_flags & 3) == 3)\n    {\n        /* packet not fragmented */\n        xstream_new(ls, total_length);\n        xstream_copyin(ls, src->p, length);\n        s_mark_end(ls);\n        ls->p = ls->data;\n        *dest = ls;\n        return 1;\n    }\n\n    /* is this the first fragmented packet? */\n    if (chan_flags & 1)\n    {\n        xstream_new(ls, total_length);\n        *dest = ls;\n    }\n    else\n    {\n        ls = *dest;\n    }\n\n    xstream_copyin(ls, src->p, length);\n\n    /* in last packet, chan_flags & 0x02 will be true */\n    if (chan_flags & 0x02)\n    {\n        /* terminate and rewind stream */\n        s_mark_end(ls);\n        ls->p = ls->data;\n        return 1;\n    }\n\n    return 0;\n}\n\n"
  },
  {
    "path": "sesman/chansrv/chansrv_common.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2009-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _CHANSRV_COMMON_H\n#define _CHANSRV_COMMON_H\n\n#include \"parse.h\"\n#include \"os_calls.h\"\n\n/* Define bitmask values for restricting the clipboard */\n#define CLIP_RESTRICT_NONE 0\n#define CLIP_RESTRICT_TEXT (1<<0)\n#define CLIP_RESTRICT_FILE (1<<1)\n#define CLIP_RESTRICT_IMAGE (1<<2)\n#define CLIP_RESTRICT_ALL 0x7fffffff\n\nint read_entire_packet(struct stream *src, struct stream **dest, int chan_flags, int length, int total_length);\n\n#endif\n\n"
  },
  {
    "path": "sesman/chansrv/chansrv_config.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * This file implements the interface in chansrv_config.h\n */\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdarg.h>\n\n#include \"arch.h\"\n\n#include \"list.h\"\n#include \"log.h\"\n#include \"file.h\"\n#include \"os_calls.h\"\n\n#include \"chansrv_common.h\"\n#include \"chansrv_config.h\"\n#include \"string_calls.h\"\n#include \"sesman_clip_restrict.h\"\n\n/* Default settings */\n#define DEFAULT_RESTRICT_OUTBOUND_CLIPBOARD 0\n#define DEFAULT_RESTRICT_INBOUND_CLIPBOARD  0\n#define DEFAULT_ENABLE_FUSE_MOUNT           1\n#define DEFAULT_FUSE_MOUNT_NAME             \"xrdp-client\"\n#define DEFAULT_FUSE_MOUNT_NAME_COLON_CHAR_REPLACEMENT ':'\n#define DEFAULT_FUSE_DIRECT_IO              0\n#define DEFAULT_FILE_UMASK                  077\n#define DEFAULT_USE_NAUTILUS3_FLIST_FORMAT  0\n#define DEFAULT_FUSE_ROOT_REPORT_MAX_FREE   0\n#define DEFAULT_NUM_SILENT_FRAMES_AAC       4\n#define DEFAULT_NUM_SILENT_FRAMES_MP3       2\n#define DEFAULT_MSEC_DO_NOT_SEND            1000\n#define DEFAULT_LOG_FILE_PATH               \"\"\n/**\n * Type used for passing a logging function about\n */\ntypedef\nprintflike(2, 3)\nenum logReturns (*log_func_t)(const enum logLevels lvl,\n                              const char *msg, ...);\n\n/***************************************************************************//**\n * @brief Error logging function to use to log to stdout\n *\n * Has the same signature as the log_message() function\n */\nstatic enum logReturns\nlog_to_stdout(const enum logLevels lvl, const char *msg, ...)\n{\n    char buff[256];\n    va_list ap;\n\n    va_start(ap, msg);\n    vsnprintf(buff, sizeof(buff), msg, ap);\n    va_end(ap);\n    g_writeln(\"%s\", buff);\n\n    return LOG_STARTUP_OK;\n}\n\n/***************************************************************************//**\n * Reads the config values we need from the [Globals] section\n *\n * @param logmsg Function to use to log messages\n * @param names List of definitions in the section\n * @param values List of corresponding values for the names\n * @param cfg Pointer to structure we're filling in\n *\n * @return 0 for success\n */\nstatic int\nread_config_globals(log_func_t logmsg,\n                    struct list *names, struct list *values,\n                    struct config_chansrv *cfg)\n{\n    int error = 0;\n    int index;\n\n    for (index = 0; index < names->count; ++index)\n    {\n        const char *name = (const char *)list_get_item(names, index);\n        const char *value = (const char *)list_get_item(values, index);\n\n        char unrecognised[256];\n        if (g_strcasecmp(name, \"ListenPort\") == 0)\n        {\n            char *listen_port = strdup(value);\n            if (listen_port == NULL)\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Can't allocate config memory for ListenPort\");\n            }\n            else\n            {\n                g_free(cfg->listen_port);\n                cfg->listen_port = listen_port;\n            }\n        }\n        if (g_strcasecmp(name, \"RestrictInboundClipboard\") == 0)\n        {\n            cfg->restrict_inbound_clipboard =\n                sesman_clip_restrict_string_to_bitmask(\n                    value, unrecognised, sizeof(unrecognised));\n            if (unrecognised[0] != '\\0')\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Unrecognised tokens parsing 'RestrictInboundClipboard' %s\",\n                    unrecognised);\n            }\n        }\n    }\n\n    return error;\n}\n\n/***************************************************************************//**\n * Reads the config values we need from the [Security] section\n *\n * @param logmsg Function to use to log messages\n * @param names List of definitions in the section\n * @param values List of corresponding values for the names\n * @param cfg Pointer to structure we're filling in\n *\n * @return 0 for success\n */\nstatic int\nread_config_security(log_func_t logmsg,\n                     struct list *names, struct list *values,\n                     struct config_chansrv *cfg)\n{\n    int error = 0;\n    int index;\n\n    for (index = 0; index < names->count; ++index)\n    {\n        const char *name = (const char *)list_get_item(names, index);\n        const char *value = (const char *)list_get_item(values, index);\n\n        char unrecognised[256];\n        if (g_strcasecmp(name, \"RestrictOutboundClipboard\") == 0)\n        {\n            cfg->restrict_outbound_clipboard =\n                sesman_clip_restrict_string_to_bitmask(\n                    value, unrecognised, sizeof(unrecognised));\n            if (unrecognised[0] != '\\0')\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Unrecognised tokens parsing 'RestrictOutboundClipboard' %s\",\n                    unrecognised);\n            }\n        }\n        if (g_strcasecmp(name, \"RestrictInboundClipboard\") == 0)\n        {\n            cfg->restrict_inbound_clipboard =\n                sesman_clip_restrict_string_to_bitmask(\n                    value, unrecognised, sizeof(unrecognised));\n            if (unrecognised[0] != '\\0')\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Unrecognised tokens parsing 'RestrictInboundClipboard' %s\",\n                    unrecognised);\n            }\n        }\n    }\n\n    return error;\n}\n\n/***************************************************************************//**\n * Reads the config values we need from the [Chansrv] section\n *\n * @param logmsg Function to use to log messages\n * @param names List of definitions in the section\n * @param values List of corresponding values for the names\n * @param cfg Pointer to structure we're filling in\n *\n * @return 0 for success\n */\nstatic int\nread_config_chansrv(log_func_t logmsg,\n                    struct list *names, struct list *values,\n                    struct config_chansrv *cfg)\n{\n    int error = 0;\n    int index;\n\n    for (index = 0; index < names->count; ++index)\n    {\n        const char *name = (const char *)list_get_item(names, index);\n        const char *value = (const char *)list_get_item(values, index);\n\n        if (g_strcasecmp(name, \"EnableFuseMount\") == 0)\n        {\n            cfg->enable_fuse_mount = g_text2bool(value);\n        }\n        else if (g_strcasecmp(name, \"FuseMountName\") == 0)\n        {\n            g_free(cfg->fuse_mount_name);\n            cfg->fuse_mount_name = g_strdup(value);\n            if (cfg->fuse_mount_name == NULL)\n            {\n                logmsg(LOG_LEVEL_ERROR, \"Can't alloc FuseMountName\");\n                error = 1;\n                break;\n            }\n        }\n        else if (g_strcasecmp(name, \"FuseMountNameColonCharReplacement\") == 0)\n        {\n            size_t vallen = g_strlen(value);\n            if (vallen < 1)\n            {\n                cfg->fuse_mount_name_colon_char_replacement = '\\0';\n            }\n            else\n            {\n                if (vallen > 1)\n                {\n                    logmsg(LOG_LEVEL_WARNING, \"FuseMountNameColonCharReplacement \"\n                           \"must be 1 character length, now it is '%s'.\"\n                           \"Only first char will be used!\",\n                           value);\n                }\n                cfg->fuse_mount_name_colon_char_replacement = value[0];\n            }\n        }\n        else if (g_strcasecmp(name, \"FuseDirectIO\") == 0)\n        {\n            cfg->fuse_direct_io = g_text2bool(value);\n        }\n        else if (g_strcasecmp(name, \"FileUmask\") == 0)\n        {\n            cfg->file_umask = strtol(value, NULL, 0);\n        }\n        else if (g_strcasecmp(name, \"UseNautilus3FlistFormat\") == 0)\n        {\n            cfg->use_nautilus3_flist_format = g_text2bool(value);\n        }\n        else if (g_strcasecmp(name, \"FuseRootReportMaxFree\") == 0)\n        {\n            cfg->fuse_root_report_max_free = g_text2bool(value);\n        }\n        else if (g_strcasecmp(name, \"SoundNumSilentFramesAAC\") == 0)\n        {\n            cfg->num_silent_frames_aac = strtoul(value, NULL, 0);\n        }\n        else if (g_strcasecmp(name, \"SoundNumSilentFramesMP3\") == 0)\n        {\n            cfg->num_silent_frames_mp3 = strtoul(value, NULL, 0);\n        }\n        else if (g_strcasecmp(name, \"SoundMsecDoNotSend\") == 0)\n        {\n            cfg->msec_do_not_send = strtoul(value, NULL, 0);\n        }\n    }\n\n    return error;\n}\n\n/***************************************************************************//**\n * Reads the config values we need from the [ChansrvLogging] section\n *\n * @param logmsg Function to use to log messages\n * @param names List of definitions in the section\n * @param values List of corresponding values for the names\n * @param cfg Pointer to structure we're filling in\n *\n * @return 0 for success\n */\nstatic int\nread_config_chansrv_logging(log_func_t logmsg,\n                            struct list *names, struct list *values,\n                            struct config_chansrv *cfg)\n{\n    int error = 0;\n    int index;\n\n    for (index = 0; index < names->count; ++index)\n    {\n        const char *name = (const char *)list_get_item(names, index);\n        const char *value = (const char *)list_get_item(values, index);\n\n        if (g_strcasecmp(name, \"LogFilePath\") == 0)\n        {\n            g_free(cfg->log_file_path);\n            cfg->log_file_path = g_strdup(value);\n            if (cfg->log_file_path == NULL)\n            {\n                logmsg(LOG_LEVEL_ERROR, \"Can't alloc LogFilePath\");\n                error = 1;\n                break;\n            }\n        }\n    }\n\n    return error;\n}\n\n/***************************************************************************//**\n * @brief returns a config block with default values\n *\n * @return Block, or NULL for no memory\n */\nstatic struct config_chansrv *\nnew_config(void)\n{\n    /* Do all the allocations at the beginning, then check them together */\n    struct config_chansrv *cfg = g_new0(struct config_chansrv, 1);\n    char *fuse_mount_name = g_strdup(DEFAULT_FUSE_MOUNT_NAME);\n    char *log_file_path = g_strdup(DEFAULT_LOG_FILE_PATH);\n    if (cfg == NULL || fuse_mount_name == NULL || log_file_path == NULL)\n    {\n        /* At least one memory allocation failed */\n        g_free(log_file_path);\n        g_free(fuse_mount_name);\n        g_free(cfg);\n        cfg = NULL;\n    }\n    else\n    {\n        cfg->listen_port = NULL;\n        cfg->enable_fuse_mount = DEFAULT_ENABLE_FUSE_MOUNT;\n        cfg->restrict_outbound_clipboard = DEFAULT_RESTRICT_OUTBOUND_CLIPBOARD;\n        cfg->restrict_inbound_clipboard = DEFAULT_RESTRICT_INBOUND_CLIPBOARD;\n        cfg->fuse_mount_name = fuse_mount_name;\n        cfg->fuse_mount_name_colon_char_replacement = DEFAULT_FUSE_MOUNT_NAME_COLON_CHAR_REPLACEMENT;\n        cfg->fuse_direct_io = DEFAULT_FUSE_DIRECT_IO;\n        cfg->file_umask = DEFAULT_FILE_UMASK;\n        cfg->use_nautilus3_flist_format = DEFAULT_USE_NAUTILUS3_FLIST_FORMAT;\n        cfg->fuse_root_report_max_free = DEFAULT_FUSE_ROOT_REPORT_MAX_FREE;\n        cfg->num_silent_frames_aac = DEFAULT_NUM_SILENT_FRAMES_AAC;\n        cfg->num_silent_frames_mp3 = DEFAULT_NUM_SILENT_FRAMES_MP3;\n        cfg->msec_do_not_send = DEFAULT_MSEC_DO_NOT_SEND;\n        cfg->log_file_path = log_file_path;\n    }\n\n    return cfg;\n}\n\n/******************************************************************************/\nstruct config_chansrv *\nconfig_read(int use_logger, const char *sesman_ini)\n{\n    int error = 0;\n    struct config_chansrv *cfg = NULL;\n    log_func_t logmsg = (use_logger) ? log_message : log_to_stdout;\n    int fd;\n\n    fd = g_file_open_ro(sesman_ini);\n    if (fd < 0)\n    {\n        logmsg(LOG_LEVEL_ERROR, \"Can't open config file %s\", sesman_ini);\n        error = 1;\n    }\n    else\n    {\n        if ((cfg = new_config()) == NULL)\n        {\n            logmsg(LOG_LEVEL_ERROR, \"Can't alloc config block\");\n            error = 1;\n        }\n        else\n        {\n            struct list *names = list_create();\n            struct list *values = list_create();\n\n            names->auto_free = 1;\n            values->auto_free = 1;\n\n            if (!error && file_read_section(fd, \"Globals\", names, values) == 0)\n            {\n                error = read_config_globals(logmsg, names, values, cfg);\n            }\n\n            if (!error && file_read_section(fd, \"Security\", names, values) == 0)\n            {\n                error = read_config_security(logmsg, names, values, cfg);\n            }\n\n            if (!error && file_read_section(fd, \"Chansrv\", names, values) == 0)\n            {\n                error = read_config_chansrv(logmsg, names, values, cfg);\n            }\n\n            if (!error &&\n                    file_read_section(fd, \"ChansrvLogging\", names, values) == 0)\n            {\n                error = read_config_chansrv_logging(logmsg, names, values, cfg);\n            }\n\n            list_delete(names);\n            list_delete(values);\n        }\n\n        g_file_close(fd);\n    }\n\n    if (error)\n    {\n        config_free(cfg);\n        cfg = NULL;\n    }\n\n    return cfg;\n}\n\n/******************************************************************************/\nvoid\nconfig_dump(struct config_chansrv *config)\n{\n    char buf[256];\n\n    g_writeln(\"Global configuration:\");\n    g_writeln(\"    xrdp-sesman ListenPort:    %s\",\n              (config->listen_port) ? config->listen_port : \"<default>\");\n\n    g_writeln(\"\\nSecurity configuration:\");\n    sesman_clip_restrict_mask_to_string(\n        config->restrict_outbound_clipboard,\n        buf, sizeof(buf));\n    g_writeln(\"    RestrictOutboundClipboard: %s\", buf);\n\n    sesman_clip_restrict_mask_to_string(\n        config->restrict_inbound_clipboard,\n        buf, sizeof(buf));\n    g_writeln(\"    RestrictInboundClipboard:  %s\", buf);\n\n    g_writeln(\"\\nChansrv configuration:\");\n    g_writeln(\"    EnableFuseMount            %s\",\n              g_bool2text(config->enable_fuse_mount));\n    g_writeln(\"    FuseMountName:             %s\", config->fuse_mount_name);\n    g_writeln(\"    FuseMountNameColonCharReplacement:             %c\", config->fuse_mount_name_colon_char_replacement);\n    g_writeln(\"    FuseDirectIO:              %s\",\n              g_bool2text(config->fuse_direct_io));\n    g_writeln(\"    FileMask:                  0%o\", config->file_umask);\n    g_writeln(\"    Nautilus 3 Flist Format:   %s\",\n              g_bool2text(config->use_nautilus3_flist_format));\n    g_writeln(\"    FuseRootReportMaxFree:     %s\",\n              g_bool2text(config->fuse_root_report_max_free));\n    g_writeln(\"    LogFilePath            :   %s\",\n              (config->log_file_path[0]) ? config->log_file_path : \"<default>\");\n}\n\n/******************************************************************************/\nvoid\nconfig_free(struct config_chansrv *cc)\n{\n    if (cc != NULL)\n    {\n        g_free(cc->listen_port);\n        g_free(cc->fuse_mount_name);\n        g_free(cc->log_file_path);\n        g_free(cc);\n    }\n}\n"
  },
  {
    "path": "sesman/chansrv/chansrv_config.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * This file contains the chansrv configuration parameters from sesman.ini\n */\n\n#ifndef _CHANSRV_CONFIG\n#define _CHANSRV_CONFIG\n\n#include <sys/stat.h>\n\nstruct config_chansrv\n{\n    /** sesman listening port */\n    char *listen_port;\n\n    /** Whether the FUSE mount is enabled or not */\n    int enable_fuse_mount;\n\n    /** Whether to use direct I/O to FUSE filesystems */\n    int fuse_direct_io;\n\n    /** RestrictOutboundClipboard setting from sesman.ini */\n    int restrict_outbound_clipboard;\n    /** RestrictInboundClipboard setting from sesman.ini */\n    int restrict_inbound_clipboard;\n\n    /** * FuseMountName from sesman.ini */\n    char *fuse_mount_name;\n    /** * FuseMountNameColonCharReplacement from sesman.ini */\n    char fuse_mount_name_colon_char_replacement;\n    /** FileUmask from sesman.ini */\n    mode_t file_umask;\n\n    /** Whether to use nautilus3-compatible file lists for the clipboard */\n    int use_nautilus3_flist_format;\n\n    /** Whether to report max free space for the FUSE mountpoint */\n    int fuse_root_report_max_free;\n\n    /** Number of silent frames to send before SNDC_CLOSE is sent, setting from sesman.ini */\n    unsigned int num_silent_frames_aac;\n    unsigned int num_silent_frames_mp3;\n    /** Do net send sound data afer SNDC_CLOSE is sent. unit is millisecond, setting from sesman.ini */\n    unsigned int msec_do_not_send;\n\n    /** LogFilePath from sesman.ini ([ChansrvLogging]) */\n    char *log_file_path;\n};\n\n\n/**\n *\n * @brief Reads sesman configuration\n * @param use_logger Use logger to log errors (otherwise stdout)\n * @param sesman_ini Name of configuration file to read\n *\n * @return configuration on success, NULL on failure\n *\n * @pre logging is assumed to be active\n * @post pass return value to config_free() to prevent memory leaks\n *\n */\nstruct config_chansrv *\nconfig_read(int use_logger, const char *sesman_ini);\n\n/**\n *\n * @brief Dumps configuration to stdout\n * @param config pointer to a config_chansrv struct\n *\n */\nvoid\nconfig_dump(struct config_chansrv *config);\n\n/**\n *\n * @brief Frees configuration allocated by config_read()\n * @param cs pointer to a config_chansrv struct (may be NULL)\n *\n */\nvoid\nconfig_free(struct config_chansrv *cs);\n\n#endif /* _CHANSRV_CONFIG */\n"
  },
  {
    "path": "sesman/chansrv/chansrv_fuse.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar\\@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/* FUSE mount point */\nchar g_fuse_root_path[256] = \"\";\n#ifdef XRDP_FUSE\nstatic const char *g_fuse_root_path_basename; /* See xfuse_path_in_xfuse_fs() */\nstatic int g_fuse_root_parent_dev;   /* Ditto */\nstatic int g_fuse_root_parent_ino;   /* Ditto */\n#endif\nchar g_fuse_clipboard_path[256] = \"\"; /* for clipboard use */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#ifndef XRDP_FUSE\n\n/******************************************************************************\n**                                                                           **\n**                   when FUSE is NOT enabled in xrdp                        **\n**                                                                           **\n******************************************************************************/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"arch.h\"\n#include \"chansrv_fuse.h\"\n#include \"chansrv_xfs.h\"\n\n/* dummy calls when XRDP_FUSE is not defined */\nint xfuse_init(void)\n{\n    return 0;\n}\nint xfuse_deinit(void)\n{\n    return 0;\n}\nint xfuse_check_wait_objs(void)\n{\n    return 0;\n}\nint xfuse_get_wait_objs(tbus *objs, int *count, int *timeout)\n{\n    return 0;\n}\nint xfuse_create_share(tui32 device_id, const char *dirname)\n{\n    return 0;\n}\nvoid xfuse_delete_share(tui32 share_id) {}\nint xfuse_clear_clip_dir(void)\n{\n    return 0;\n}\nint xfuse_file_contents_range(int stream_id, const char *data, int data_bytes)\n{\n    return 0;\n}\nint xfuse_file_contents_size(int stream_id, int file_size)\n{\n    return 0;\n}\nint xfuse_add_clip_dir_item(const char *filename,\n                            int flags, int size, int lindex)\n{\n    return 0;\n}\n\nvoid xfuse_devredir_cb_enum_dir_add_entry(\n    struct state_dirscan *fip,\n    const char *name,\n    const struct file_attr *fattr)\n{}\nvoid xfuse_devredir_cb_enum_dir_done(struct state_dirscan *fip,\n                                     enum NTSTATUS IoStatus)\n{}\nvoid xfuse_devredir_cb_lookup_entry(struct state_lookup *fip,\n                                    enum NTSTATUS IoStatus,\n                                    const struct file_attr *file_info)\n{}\nvoid xfuse_devredir_cb_setattr(struct state_setattr *fip,\n                               enum NTSTATUS IoStatus)\n{}\nvoid xfuse_devredir_cb_create_file(struct state_create *fip,\n                                   enum NTSTATUS IoStatus,\n                                   tui32 DeviceId, tui32 FileId)\n{}\nvoid xfuse_devredir_cb_open_file(struct state_open *fip,\n                                 enum NTSTATUS IoStatus,\n                                 tui32 DeviceId, tui32 FileId)\n{}\nvoid xfuse_devredir_cb_read_file(struct state_read *fip,\n                                 enum NTSTATUS IoStatus,\n                                 const char *buf, size_t length)\n{}\nvoid xfuse_devredir_cb_write_file(\n    struct state_write *fip,\n    enum NTSTATUS IoStatus,\n    off_t offset,\n    size_t length)\n{}\nvoid xfuse_devredir_cb_rmdir_or_file(struct state_remove *fip,\n                                     enum NTSTATUS IoStatus)\n{}\nvoid xfuse_devredir_cb_rename_file(struct state_rename *fip,\n                                   enum NTSTATUS IoStatus)\n{}\nvoid xfuse_devredir_cb_file_close(struct state_close *fip)\n{}\n\nvoid xfuse_devredir_cb_statfs(struct state_statfs *fip,\n                              const struct statvfs *fss,\n                              enum NTSTATUS IoStatus)\n{}\n\nint xfuse_path_in_xfuse_fs(const char *path)\n{\n    return 0;\n}\n\n#else\n\n/******************************************************************************\n**                                                                           **\n**                     when FUSE is enabled in xrdp                          **\n**                                                                           **\n******************************************************************************/\n\n/* FUSE_USE_VERSION must be defined globally for other parts of\n * xrdp-chansrv which include <fuse_lowlevel.h> for definitions. Check\n * it's actually defined here */\n#ifndef FUSE_USE_VERSION\n#error Define FUSE_USE_VERSION in the make system and recompile\n#endif\n\n#include <fuse_lowlevel.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <errno.h>\n#include <time.h>\n#include <unistd.h>\n#include <string.h>\n#include <pthread.h>\n#include <sched.h>\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"clipboard_file.h\"\n#include \"chansrv_fuse.h\"\n#include \"chansrv_xfs.h\"\n#include \"chansrv.h\"\n#include \"chansrv_config.h\"\n#include \"devredir.h\"\n#include \"list.h\"\n#include \"file.h\"\n#include \"xrdp_constants.h\"\n\n/* Check for FUSE features we may wish to use\n *\n * Note that FUSE_VERSION might be more useful for some features than\n * FUSE_USE_VERSION\n */\n#if FUSE_VERSION >= FUSE_MAKE_VERSION(3,7)\n#define FUSE_SET_LOG_FUNC_AVAILABLE\n#endif\n\n#ifndef EREMOTEIO\n#define EREMOTEIO EIO\n#endif\n\n#define XFUSE_ATTR_TIMEOUT      5.0\n#define XFUSE_ENTRY_TIMEOUT     5.0\n\n\nextern struct config_chansrv *g_cfg; /* in chansrv.c */\n\n\n/* Local utility functions */\n\nstatic inline char *\n_fuse_mount_name_colon_char_replace(const char *dirname)\n{\n    char *newdirname = (char *) dirname;\n    if (g_cfg->fuse_mount_name_colon_char_replacement != ':')\n    {\n        newdirname = g_strdup(dirname);\n        if (newdirname == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR,\n                      \"Failed to duplicate fuse mount name string\");\n            return (char *) dirname;\n        }\n        char *colonptr = g_strrchr(newdirname, ':');\n        if (colonptr != NULL)\n        {\n            *colonptr = g_cfg->fuse_mount_name_colon_char_replacement;\n        }\n    }\n    return newdirname;\n}\n\n/* End of Local utility functions*/\n\n\n/* Type of buffer used for fuse_add_direntry() calls */\nstruct dirbuf1\n{\n    char buf[4096];\n    size_t  len;\n};\n\n/*\n * Record type used to maintain state when running a directory scan\n */\nstruct state_dirscan\n{\n    fuse_req_t             req;   /* Original FUSE request from opendir */\n    struct fuse_file_info  fi;    /* File info struct passed to opendir */\n    fuse_ino_t             pinum; /* inum of parent directory           */\n};\n\n\n/*\n * Record type used to maintain state when running an entry lookup\n */\nstruct state_lookup\n{\n    fuse_req_t        req;        /* Original FUSE request from lookup  */\n    fuse_ino_t        pinum;      /* inum of parent directory           */\n    char              name[XFS_MAXFILENAMELEN + 1];\n    /* Name to look up                    */\n    fuse_ino_t        existing_inum;\n    /* inum of an existing entry          */\n    tui32             existing_generation;\n    /* generation of the above            */\n};\n\n/*\n * Record type used to maintain state when running an entry setattr\n */\nstruct state_setattr\n{\n    fuse_req_t        req;        /* Original FUSE request from lookup  */\n    fuse_ino_t        inum;       /* inum of entry                      */\n    struct file_attr  fattr;      /* File attributes to set             */\n    tui32             change_mask; /* Attributes to set in fattr        */\n};\n\n\n/*\n * Record type used to maintain state when running an open\n */\nstruct state_open\n{\n    fuse_req_t        req;        /* Original FUSE request from lookup  */\n    struct fuse_file_info fi;     /* File info struct passed to open    */\n    fuse_ino_t        inum;       /* inum of file to open               */\n};\n\n\n/*\n * Record type used to maintain state when running a create\n */\nstruct state_create\n{\n    fuse_req_t        req;        /* Original FUSE request from lookup  */\n    struct fuse_file_info fi;     /* File info struct passed to open    */\n    fuse_ino_t        pinum;      /* inum of parent directory           */\n    char              name[XFS_MAXFILENAMELEN + 1];\n    /* Name of file in parent directory   */\n    mode_t            mode;       /* Mode of file to create             */\n};\n\n/*\n * Record type used to maintain state when running a read\n */\nstruct state_read\n{\n    fuse_req_t        req;        /* Original FUSE request from lookup  */\n};\n\n/*\n * Record type used to maintain state when running a write\n */\nstruct state_write\n{\n    fuse_req_t        req;        /* Original FUSE request from lookup  */\n    fuse_ino_t        inum;       /* inum of file we're writing         */\n};\n\n/*\n * Record type used to maintain state when running a remove\n */\nstruct state_remove\n{\n    fuse_req_t        req;        /* Original FUSE request from lookup  */\n    fuse_ino_t        inum;       /* inum of file we're removing        */\n};\n\n/*\n * Record type used to maintain state when running a rename\n */\nstruct state_rename\n{\n    fuse_req_t        req;        /* Original FUSE request from lookup  */\n    fuse_ino_t        pinum;      /* inum of parent of file             */\n    fuse_ino_t        new_pinum;  /* inum of new parent of file         */\n    char              name[XFS_MAXFILENAMELEN + 1];\n    /* New name of file in new parent dir */\n};\n\n/*\n * Record type used to maintain state when running a close\n */\nstruct state_close\n{\n    fuse_req_t        req;        /* Original FUSE request from lookup  */\n    struct fuse_file_info fi;     /* File info struct passed to open    */\n    fuse_ino_t        inum;       /* inum of file to open               */\n};\n\n/*\n * Record type used to maintain state when running a statfs\n */\nstruct state_statfs\n{\n    fuse_req_t        req;        /* Original FUSE request from statfs  */\n};\n\n\nstruct xfuse_handle\n{\n    tui32 DeviceId;\n    tui32 FileId;\n    int   is_loc_resource; /* this is not a redirected resource */\n\n    /* a directory handle, if this xfuse_handle represents a directory.\n     * NULL, if this xfuse_handle represents a file.\n     *\n     * Note: when this xfuse_handle represents a directory, then the other\n     *       fields of this structure contain invalid values.\n     */\n    struct xfs_dir_handle *dir_handle;\n};\ntypedef struct xfuse_handle XFUSE_HANDLE;\n\n/* used for file data request sent to client */\nstruct req_list_item\n{\n    fuse_req_t req;\n    int stream_id;\n    int lindex;\n    int off;\n    int size;\n};\n\n\nstatic struct list *g_req_list = 0;\nstatic struct xfs_fs *g_xfs;                 /* an inst of xrdp file system */\nstatic ino_t g_clipboard_inum;               /* inode of clipboard dir      */\nstatic struct fuse_lowlevel_ops g_xfuse_ops; /* setup FUSE callbacks        */\nstatic int g_xfuse_inited = 0;               /* true when FUSE is inited    */\nstatic struct fuse_session *g_se = 0;\n// For the below, see the source for the fuse_session_loop() function\nstatic struct fuse_buf g_buffer =\n{\n    .mem = NULL\n};\n\n/* forward declarations for internal access */\nstatic int xfuse_init_xrdp_fs(void);\nstatic int xfuse_deinit_xrdp_fs(void);\nstatic int xfuse_init_lib(struct fuse_args *args);\n\n/* forward declarations for FUSE callbacks */\nstatic void xfuse_cb_lookup(fuse_req_t req, fuse_ino_t parent,\n                            const char *name);\n\nstatic void xfuse_cb_getattr(fuse_req_t req, fuse_ino_t ino,\n                             struct fuse_file_info *fi);\n\n/* this is not a callback, but it's used by xfuse_cb_readdir() */\nstatic int xfuse_dirbuf_add1(fuse_req_t req, struct dirbuf1 *b,\n                             XFS_INODE *xinode, off_t offset);\n\nstatic void xfuse_cb_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,\n                             off_t off, struct fuse_file_info *fi);\n\nstatic void xfuse_cb_mkdir(fuse_req_t req, fuse_ino_t parent,\n                           const char *name, mode_t mode);\n\nstatic void xfuse_cb_unlink(fuse_req_t req, fuse_ino_t parent,\n                            const char *name);\n\nstatic void xfuse_cb_rename(fuse_req_t req,\n                            fuse_ino_t old_parent, const char *old_name,\n                            fuse_ino_t new_parent, const char *new_name,\n                            unsigned int flags);\n\n/* Whether to create a dir of file depends on whether S_IFDIR is set in the\n   mode field */\nstatic void xfuse_create_dir_or_file(fuse_req_t req, fuse_ino_t parent,\n                                     const char *name, mode_t mode,\n                                     struct fuse_file_info *fi);\n\nstatic void xfuse_cb_open(fuse_req_t req, fuse_ino_t ino,\n                          struct fuse_file_info *fi);\n\nstatic void xfuse_cb_release(fuse_req_t req, fuse_ino_t ino, struct\n                             fuse_file_info *fi);\n\nstatic void xfuse_cb_read(fuse_req_t req, fuse_ino_t ino, size_t size,\n                          off_t off, struct fuse_file_info *fi);\n\nstatic void xfuse_cb_write(fuse_req_t req, fuse_ino_t ino, const char *buf,\n                           size_t size, off_t off, struct fuse_file_info *fi);\n\nstatic void xfuse_cb_create(fuse_req_t req, fuse_ino_t parent,\n                            const char *name, mode_t mode,\n                            struct fuse_file_info *fi);\n\n#if 0\nstatic void xfuse_cb_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,\n                           struct fuse_file_info *fi);\n#endif\n\nstatic void xfuse_cb_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,\n                             int to_set, struct fuse_file_info *fi);\n\nstatic void xfuse_cb_opendir(fuse_req_t req, fuse_ino_t ino,\n                             struct fuse_file_info *fi);\n\nstatic void xfuse_cb_releasedir(fuse_req_t req, fuse_ino_t ino,\n                                struct fuse_file_info *fi);\n\nstatic void xfuse_cb_statfs(fuse_req_t req, fuse_ino_t ino);\n\n/* miscellaneous functions */\nstatic void xfs_inode_to_fuse_entry_param(const XFS_INODE *xinode,\n        struct fuse_entry_param *e);\nstatic void make_fuse_entry_reply(fuse_req_t req, const XFS_INODE *xinode);\nstatic void make_fuse_attr_reply(fuse_req_t req, const XFS_INODE *xinode);\nstatic const char *filename_on_device(const char *full_path);\nstatic void update_inode_file_attributes(const struct file_attr *fattr,\n        tui32 change_mask, XFS_INODE *xinode);\nstatic char *get_name_for_entry_in_parent(fuse_ino_t parent, const char *name);\nstatic unsigned int format_user_info(char *dest, unsigned int len,\n                                     const char *format);\n\n/*****************************************************************************/\nstatic int\nload_fuse_config(void)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nstatic XFUSE_HANDLE *\nxfuse_handle_create()\n{\n    return g_new0(XFUSE_HANDLE, 1);\n}\n\n/*****************************************************************************/\nstatic void\nxfuse_handle_delete(XFUSE_HANDLE *self)\n{\n    if (self == NULL)\n    {\n        return;\n    }\n\n    if (self->dir_handle != NULL)\n    {\n        free(self->dir_handle);\n    }\n    free(self);\n}\n\n/*****************************************************************************/\nstatic uint64_t\nxfuse_handle_to_fuse_handle(XFUSE_HANDLE *self)\n{\n    return (uint64_t) (tintptr) self;\n}\n\n/*****************************************************************************/\nstatic XFUSE_HANDLE *\nxfuse_handle_from_fuse_handle(uint64_t handle)\n{\n    return (XFUSE_HANDLE *) (tintptr) handle;\n}\n\n/*****************************************************************************\n**                                                                          **\n**         public functions - can be called from any code path              **\n**                                                                          **\n*****************************************************************************/\n\n/**\n * Initialize FUSE subsystem\n *\n * @return 0 on success, -1 on failure, 1 for feature disabled\n *****************************************************************************/\n\nint\nxfuse_init(void)\n{\n    struct fuse_args args = FUSE_ARGS_INIT(0, NULL);\n    char *p;\n\n    /* if already inited, just return */\n    if (g_xfuse_inited)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"already inited\");\n        return 0;\n    }\n\n    /* This feature may be disabled */\n    if (!g_cfg->enable_fuse_mount)\n    {\n        /*\n         * Only log the 'disabled mounts' message one time\n         */\n        static int disabled_mounts_msg_shown = 0;\n        if (!disabled_mounts_msg_shown)\n        {\n            LOG(LOG_LEVEL_INFO, \"FUSE mounts are disabled by config\");\n            disabled_mounts_msg_shown = 1;\n        }\n        return 1;\n    }\n\n    if (g_se != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"g_se is not zero\");\n        return -1;\n    }\n\n    load_fuse_config();\n\n    /* define FUSE mount point */\n    if (g_cfg->fuse_mount_name[0] == '/')\n    {\n        /* String is an absolute path to the mount point containing\n         * %u or %U characters */\n        format_user_info(g_fuse_root_path, sizeof(g_fuse_root_path),\n                         g_cfg->fuse_mount_name);\n    }\n    else\n    {\n        /* mount_name is relative to $HOME, e.g. ~/xrdp_client,\n         * or ~/thinclient_drives */\n        unsigned int len = g_snprintf(g_fuse_root_path, sizeof(g_fuse_root_path), \"%s/\", g_getenv(\"HOME\"));\n        if (len < sizeof(g_fuse_root_path))\n        {\n            format_user_info(g_fuse_root_path + len, sizeof(g_fuse_root_path) - len, g_cfg->fuse_mount_name);\n        }\n\n    }\n\n    /* Remove all trailing '/' from the root path */\n    p = g_fuse_root_path + g_strlen(g_fuse_root_path);\n    while ( p > g_fuse_root_path && *(p - 1) == '/')\n    {\n        --p;\n        *p = '\\0';\n    }\n\n    /* This shouldn't happen */\n    if (g_strlen(g_fuse_root_path) == 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Fuse root path is empty after removing trailing '/'\");\n        return -1;\n    }\n\n    g_snprintf(g_fuse_clipboard_path, sizeof(g_fuse_clipboard_path),\n               \"%s/.clipboard\", g_fuse_root_path);\n\n    /* if FUSE mount point does not exist, create it */\n    if (!g_directory_exist(g_fuse_root_path))\n    {\n        (void)g_create_path(g_fuse_root_path);\n        if (!g_create_dir(g_fuse_root_path))\n        {\n            LOG(LOG_LEVEL_ERROR, \"mkdir %s failed (%s)\",\n                g_fuse_root_path, g_get_strerror());\n            return -1;\n        }\n    }\n\n    /* Get the characteristics of the parent directory of the FUSE mount\n     * point. Used by xfuse_path_in_xfuse_fs() */\n    g_fuse_root_parent_dev = -1;\n    g_fuse_root_parent_ino = -1;\n    p = (char *)g_strrchr(g_fuse_root_path, '/');\n    if (p != NULL)\n    {\n        /* Temporarily finish the root path at this point */\n        *p = '\\0';\n        g_fuse_root_path_basename = p + 1;\n        g_fuse_root_parent_dev = g_file_get_device_number(g_fuse_root_path);\n        g_fuse_root_parent_ino = g_file_get_inode_num(g_fuse_root_path);\n        *p = '/';\n    }\n\n    if (g_fuse_root_parent_dev == -1 || g_fuse_root_parent_ino == -1)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Unable to obtain characteristics of directory containing %s\",\n            g_fuse_root_path);\n        return -1;\n    }\n\n    /* setup xrdp file system */\n    if (xfuse_init_xrdp_fs())\n    {\n        return -1;\n    }\n\n    /* setup FUSE callbacks */\n    g_memset(&g_xfuse_ops, 0, sizeof(g_xfuse_ops));\n    g_xfuse_ops.lookup      = xfuse_cb_lookup;\n    g_xfuse_ops.readdir     = xfuse_cb_readdir;\n    g_xfuse_ops.mkdir       = xfuse_cb_mkdir;\n    g_xfuse_ops.rmdir       = xfuse_cb_unlink;\n    g_xfuse_ops.unlink      = xfuse_cb_unlink;\n    g_xfuse_ops.rename      = xfuse_cb_rename;\n    g_xfuse_ops.open        = xfuse_cb_open;\n    g_xfuse_ops.release     = xfuse_cb_release;\n    g_xfuse_ops.read        = xfuse_cb_read;\n    g_xfuse_ops.write       = xfuse_cb_write;\n    g_xfuse_ops.create      = xfuse_cb_create;\n    //g_xfuse_ops.fsync     = xfuse_cb_fsync; /* LK_TODO delete this */\n    g_xfuse_ops.getattr     = xfuse_cb_getattr;\n    g_xfuse_ops.setattr     = xfuse_cb_setattr;\n    g_xfuse_ops.opendir     = xfuse_cb_opendir;\n    g_xfuse_ops.releasedir  = xfuse_cb_releasedir;\n    g_xfuse_ops.statfs      = xfuse_cb_statfs;\n\n    fuse_opt_add_arg(&args, \"xrdp-chansrv\");\n    fuse_opt_add_arg(&args, \"-o\");\n    fuse_opt_add_arg(&args, \"fsname=xrdp-chansrv\");\n    //fuse_opt_add_arg(&args, \"-s\"); /* single threaded mode */\n    //fuse_opt_add_arg(&args, \"-d\"); /* debug mode           */\n\n    if (xfuse_init_lib(&args))\n    {\n        fuse_opt_free_args(&args);\n        xfuse_deinit();\n        return -1;\n    }\n    fuse_opt_free_args(&args);\n\n    g_xfuse_inited = 1;\n    return 0;\n}\n\n/**\n * De-initialize FUSE subsystem\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint\nxfuse_deinit(void)\n{\n    if (g_se != NULL)\n    {\n        fuse_session_unmount(g_se);\n        fuse_session_destroy(g_se);\n        g_se = NULL;\n    }\n\n    free(g_buffer.mem);\n    g_buffer.mem = NULL;\n\n    list_delete(g_req_list);\n    g_req_list = 0;\n\n    xfuse_deinit_xrdp_fs();\n\n    g_xfuse_inited = 0;\n    return 0;\n}\n\n/**\n *\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\nint xfuse_check_wait_objs(void)\n{\n    if (g_se != NULL)\n    {\n        if (g_sck_can_recv(fuse_session_fd(g_se), 0))\n        {\n            int rval = fuse_session_receive_buf(g_se, &g_buffer);\n            if (rval == -EINTR)\n            {\n                return -1;\n            }\n\n            if (rval == -ENODEV)\n            {\n                return -1;\n            }\n\n            if (rval <= 0)\n            {\n                return -1;\n            }\n\n            fuse_session_process_buf(g_se, &g_buffer);\n        }\n    }\n\n    return 0;\n}\n\n/**\n *\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint xfuse_get_wait_objs(tbus *objs, int *count, int *timeout)\n{\n    if (g_se != NULL)\n    {\n        objs[*count] = fuse_session_fd(g_se);\n        ++(*count);\n    }\n\n    return 0;\n}\n\n/**\n * @brief Create specified share directory.\n *\n * This code gets called from devredir\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint xfuse_create_share(tui32 device_id, const char *dirname)\n{\n    int result = -1;\n    XFS_INODE  *xinode;\n\n    if (dirname != NULL && strlen(dirname) > 0 &&\n            xfuse_init_xrdp_fs() == 0)\n    {\n        char *newdirname = _fuse_mount_name_colon_char_replace(dirname);\n        xinode = xfs_add_entry(g_xfs, FUSE_ROOT_ID, newdirname, (0777 | S_IFDIR));\n        //free only if _fuse_mount_name_colon_char_replace allocated new string\n        if (newdirname != dirname)\n        {\n            g_free(newdirname);\n        }\n        if (xinode == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xfs_add_entry() failed\");\n        }\n        else\n        {\n            xinode->is_redirected = 1;\n            xinode->device_id = device_id;\n            result = 0;\n        }\n    }\n\n    return result;\n}\n\n/**\n * @brief Remove specified share directory.\n *\n * This code gets called from devredir\n *****************************************************************************/\n\nvoid xfuse_delete_share(tui32 device_id)\n{\n    xfs_delete_redirected_entries_with_device_id(g_xfs, device_id);\n}\n\n/**\n * Clear all clipboard entries in xrdp_fs\n *\n * This function is called by clipboard code\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint xfuse_clear_clip_dir(void)\n{\n    int result = 0;\n\n    if (g_xfs != NULL && g_clipboard_inum > 0)\n    {\n        xfs_remove_directory_contents(g_xfs, g_clipboard_inum);\n    }\n\n    return result;\n}\n\n/**\n * Return clipboard data to fuse\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint\nxfuse_file_contents_range(int stream_id, const char *data, int data_bytes)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: stream_id=%d data_bytes=%d\", stream_id, data_bytes);\n\n    struct req_list_item *rli;\n\n    if ((rli = (struct req_list_item *) list_get_item(g_req_list, 0)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"range error!\");\n        return -1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lindex=%d off=%d size=%d\", rli->lindex, rli->off, rli->size);\n\n    fuse_reply_buf(rli->req, data, data_bytes);\n\n    list_remove_item(g_req_list, 0);\n    if (g_req_list->count <= 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"completed all requests\");\n        return 0;\n    }\n\n    /* send next request */\n    rli = (struct req_list_item *) list_get_item(g_req_list, 0);\n    if (rli == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"range error!\");\n        return -1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"requesting clipboard file data\");\n\n    clipboard_request_file_data(rli->stream_id, rli->lindex,\n                                rli->off, rli->size);\n\n    return 0;\n}\n\n/**\n * Create a file in .clipboard dir\n *\n * This function is called by clipboard code\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint\nxfuse_add_clip_dir_item(const char *filename, int flags, int size, int lindex)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG,\n              \"entered: filename=%s flags=%d size=%d lindex=%d\",\n              filename, flags, size, lindex);\n\n    int result = -1;\n\n    if (g_xfs == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR,\n                  \"xfuse_add_clip_dir_item() called with no filesystem\");\n    }\n    else\n    {\n        /* add entry to xrdp_fs */\n        XFS_INODE *xinode = xfs_add_entry( g_xfs,\n                                           g_clipboard_inum, /* parent inode */\n                                           filename,\n                                           (0666 | S_IFREG));\n        if (xinode == NULL)\n        {\n            LOG(LOG_LEVEL_INFO,\n                \"failed to create file %s in xrdp filesystem\", filename);\n        }\n        else\n        {\n            xinode->size = size;\n            xinode->lindex = lindex;\n            result = 0;\n        }\n    }\n\n    return result;\n}\n\n/**\n *\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint xfuse_file_contents_size(int stream_id, int file_size)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: stream_id=%d file_size=%d\", stream_id, file_size);\n    return 0;\n}\n\n/*****************************************************************************\n**                                                                          **\n**       private functions - can only be called from within this file       **\n**                                                                          **\n*****************************************************************************/\n\n/*****************************************************************************/\n/**\n * FUSE logging function\n *\n * Used to get errors from FUSE for the log file\n * @param fuse_log_level Logging level understood by FUSE\n * @param fmt Logging format string\n * @param ap Arguments for above\n */\n#ifdef FUSE_SET_LOG_FUNC_AVAILABLE\nstatic void\nxfuse_log_func(enum fuse_log_level fuse_log_level, const char *fmt, va_list ap)\n{\n    char msg[512];\n    enum logLevels level;\n    switch (fuse_log_level)\n    {\n        case FUSE_LOG_ERR:\n            level = LOG_LEVEL_ERROR;\n            break;\n\n        case FUSE_LOG_WARNING:\n            level = LOG_LEVEL_WARNING;\n            break;\n\n        case FUSE_LOG_NOTICE:\n        case FUSE_LOG_INFO:\n            level = LOG_LEVEL_INFO;\n            break;\n\n        case FUSE_LOG_DEBUG:\n            level = LOG_LEVEL_DEBUG;\n            break;\n\n        default:\n            level = LOG_LEVEL_ALWAYS;\n            break;\n    }\n\n    vsnprintf(msg, sizeof(msg), fmt, ap);\n    LOG(level, \"%s\", msg);\n}\n#endif //FUSE_SET_LOG_FUNC_AVAILABLE\n\n/**\n * Initialize FUSE library\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\nstatic int xfuse_init_lib(struct fuse_args *args)\n{\n    int rv = -1;\n\n#ifdef FUSE_SET_LOG_FUNC_AVAILABLE\n    fuse_set_log_func(xfuse_log_func);\n#endif\n\n    g_se = fuse_session_new(args, &g_xfuse_ops, sizeof(g_xfuse_ops), 0);\n    if (g_se == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"fuse_session_new() failed\");\n    }\n    else if (fuse_session_mount(g_se, g_fuse_root_path) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"FUSE mount on %s failed.\"\n            \" If %s is already mounted, you must first unmount it\",\n            g_fuse_root_path, g_fuse_root_path);\n        fuse_session_destroy(g_se);\n        g_se = NULL;\n    }\n    else\n    {\n        g_req_list = list_create();\n        g_req_list->auto_free = 1;\n        rv = 0;\n    }\n\n    return rv;\n}\n\n/**\n * Initialize xrdp file system\n *\n * @return 0 on success, -1 on failure\n *\n *****************************************************************************/\n\nstatic int xfuse_init_xrdp_fs(void)\n{\n    XFS_INODE *xino;\n    int result = -1;\n\n    /* Already called? */\n    if (g_xfs != NULL)\n    {\n        result = 0;\n    }\n    else if ((g_xfs = xfs_create_xfs_fs(0, g_getuid(), g_getgid())) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n    }\n    else\n    {\n        /* Need a top-level .clipboard directory */\n        xino = xfs_add_entry(g_xfs, FUSE_ROOT_ID, \".clipboard\",\n                             (0777 | S_IFDIR));\n        if (xino == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            xfs_delete_xfs_fs(g_xfs);\n            g_xfs = NULL;\n        }\n        else\n        {\n            g_clipboard_inum = xino->inum;\n            result = 0;\n        }\n    }\n    return result;\n}\n\n/**\n * zap the xrdp file system\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nstatic int xfuse_deinit_xrdp_fs(void)\n{\n    xfs_delete_xfs_fs(g_xfs);\n    g_xfs = NULL;\n    g_clipboard_inum = 0;\n\n    return 0;\n}\n\n/******************************************************************************\n**                                                                           **\n**                         callbacks for devredir                            **\n**                                                                           **\n******************************************************************************/\n\n\n/**\n * Add a file or directory to xrdp file system as part of a\n * directory request\n *\n * If the file or directory already exists, no changes are made to it.\n *****************************************************************************/\n\nvoid xfuse_devredir_cb_enum_dir_add_entry(\n    struct state_dirscan *fip,\n    const char *name,\n    const struct file_attr *fattr)\n{\n    XFS_INODE *xinode = NULL;\n\n    if (!xfs_get(g_xfs, fip->pinum))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", fip->pinum);\n    }\n    else if ((strcmp(name, \".\") == 0) ||\n             (strcmp(name, \"..\") == 0))\n    {\n        ; /* filename is . or ..  - don't add it */\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"parent_inode=%ld name=%s\", fip->pinum, name);\n\n        /* Does the file already exist ? If it does it's important we\n         * don't mess with it, as we're only enumerating the directory, and\n         * we don't want to disrupt any existing operations on the file\n         */\n        xinode = xfs_lookup_in_dir(g_xfs, fip->pinum, name);\n        if (xinode == NULL)\n        {\n            /* Add a new node to the file system */\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"Creating name=%s in parent=%ld in xrdp_fs\",\n                      name, fip->pinum);\n            xinode = xfs_add_entry(g_xfs, fip->pinum, name, fattr->mode);\n            if (xinode == NULL)\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"xfs_add_entry() failed\");\n            }\n            else\n            {\n                xinode->size = fattr->size;\n                xinode->atime = fattr->atime;\n                xinode->mtime = fattr->mtime;\n                /* Initially, set the attribute change time to the file data\n                   change time */\n                xinode->ctime = fattr->mtime;\n\n                /* device_id is inherited from parent */\n            }\n        }\n    }\n}\n\n/**\n * This routine is called by devredir when the opendir request has\n * completed\n *****************************************************************************/\n\nvoid xfuse_devredir_cb_enum_dir_done(struct state_dirscan *fip,\n                                     enum NTSTATUS IoStatus)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"fip=%p IoStatus=0x%x\", fip, IoStatus);\n\n    /*\n     * STATUS_NO_SUCH_FILE is returned for empty directories\n     */\n    if (IoStatus != STATUS_SUCCESS && IoStatus != STATUS_NO_SUCH_FILE)\n    {\n        int status;\n        switch (IoStatus)\n        {\n            case STATUS_ACCESS_DENIED:\n                status = EACCES;\n                break;\n            default:\n                status = ENOENT;\n        }\n        fuse_reply_err(fip->req, status);\n    }\n    else if (!xfs_get(g_xfs, fip->pinum))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", fip->pinum);\n        fuse_reply_err(fip->req, ENOENT);\n    }\n    else\n    {\n        struct fuse_file_info *fi = &fip->fi;\n        XFUSE_HANDLE *xhandle = xfuse_handle_create();\n\n        if (xhandle == NULL)\n        {\n            fuse_reply_err(fip->req, ENOMEM);\n        }\n        else\n        {\n            // Coverity gets confused by xfuse_handle_to_fuse_handle(), and\n            // sees the dir_handle leaked\n            //coverity[RESOURCE_LEAK:FALSE]\n            xhandle->dir_handle = xfs_opendir(g_xfs, fip->pinum);\n            if (xhandle->dir_handle == NULL)\n            {\n                xfuse_handle_delete(xhandle);\n                fuse_reply_err(fip->req, ENOMEM);\n            }\n            else\n            {\n                fi->fh = xfuse_handle_to_fuse_handle(xhandle);\n                fuse_reply_open(fip->req, &fip->fi);\n            }\n        }\n    }\n\n    free(fip);\n}\n\n/**\n * This routine is caused as a result of a devredir remote lookup\n * instigated by xfuse_cb_lookup()\n *****************************************************************************/\n\nvoid xfuse_devredir_cb_lookup_entry(struct state_lookup *fip,\n                                    enum NTSTATUS IoStatus,\n                                    const struct file_attr *file_info)\n{\n    XFS_INODE *xinode = NULL;\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        switch (IoStatus)\n        {\n            case STATUS_SHARING_VIOLATION:\n            /* This can happen when trying to read the attributes of\n             * some system files (e.g. pagefile.sys) */\n            case STATUS_ACCESS_DENIED:\n                fuse_reply_err(fip->req, EACCES);\n                break;\n\n            case STATUS_UNSUCCESSFUL:\n                /* Happens if we try to lookup an illegal filename (e.g.\n                 * one with a '*' in it) */\n                fuse_reply_err(fip->req, ENOENT);\n                break;\n\n            case STATUS_NO_SUCH_FILE:\n                /* Remove our copy, if any */\n                if (fip->existing_inum  &&\n                        (xinode = xfs_get(g_xfs, fip->existing_inum)) != NULL &&\n                        xinode->generation == fip->existing_generation)\n                {\n                    xfs_remove_entry(g_xfs, fip->existing_inum);\n                }\n                fuse_reply_err(fip->req, ENOENT);\n                break;\n\n            default:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Error code %08x - fallthrough\", (int) IoStatus);\n                fuse_reply_err(fip->req, EIO);\n                break;\n        }\n    }\n    else if (!xfs_get(g_xfs, fip->pinum))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"parent inode %ld is not valid\", fip->pinum);\n        fuse_reply_err(fip->req, ENOENT);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"parent_inode=%ld name=%s\", fip->pinum, fip->name);\n\n        /* Does the file already exist ? */\n        xinode = xfs_lookup_in_dir(g_xfs, fip->pinum, fip->name);\n        if (xinode != NULL)\n        {\n            /* Is the existing file the same type ? */\n            if ((xinode->mode & (S_IFREG | S_IFDIR)) ==\n                    (file_info->mode & (S_IFREG | S_IFDIR)))\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"inode=%ld name=%s already exists in xrdp_fs as %ld\",\n                          fip->pinum, fip->name, xinode->inum);\n                if (xfs_get_file_open_count(g_xfs, xinode->inum) > 0)\n                {\n                    /*\n                     * Don't mess with open files. The local attributes are\n                     * almost certainly more up-to-date. A worst case scenario\n                     * would be truncating a file we're currently writing\n                     * to, as the lookup value for the size is stale.\n                     */\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"inode=%ld is open - \"\n                              \"preferring local attributes\", xinode->inum);\n                }\n                else\n                {\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"Updating attributes of inode=%ld\", xinode->inum);\n                    update_inode_file_attributes(file_info, TO_SET_ALL, xinode);\n                }\n            }\n            else\n            {\n                /* Type has changed from file to directory, or vice-versa */\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"inode=%ld name=%s of different type in xrdp_fs\"\n                          \" - removing\",\n                          fip->pinum, xinode->name);\n                xfs_remove_entry(g_xfs, xinode->inum);\n                xinode = NULL;\n            }\n        }\n\n        if (xinode == NULL)\n        {\n            /* Add a new node to the file system */\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"Creating name=%s in parent=%ld in xrdp_fs\",\n                      fip->name, fip->pinum);\n            xinode = xfs_add_entry(g_xfs, fip->pinum, fip->name,\n                                   file_info->mode);\n            if (xinode == NULL)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"xfs_add_entry() failed\");\n            }\n            else\n            {\n                xinode->size = file_info->size;\n                xinode->atime = file_info->atime;\n                xinode->mtime = file_info->mtime;\n                /* Initially, set the attribute change time to the file data\n                   change time */\n                xinode->ctime = file_info->mtime;\n                /* device_id is inherited from parent */\n            }\n        }\n        if (xinode != NULL)\n        {\n            make_fuse_entry_reply(fip->req, xinode);\n        }\n        else\n        {\n            fuse_reply_err(fip->req, EIO);\n        }\n    }\n\n    free(fip);\n}\n\n/**\n * This routine is caused as a result of a devredir remote setattr\n * instigated by xfuse_cb_setattr()\n *****************************************************************************/\nvoid xfuse_devredir_cb_setattr(struct state_setattr *fip,\n                               enum NTSTATUS IoStatus)\n{\n    XFS_INODE *xinode;\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        switch (IoStatus)\n        {\n            case STATUS_SHARING_VIOLATION:\n            /* This can happen when trying to read the attributes of\n             * some system files (e.g. pagefile.sys) */\n            case STATUS_ACCESS_DENIED:\n                fuse_reply_err(fip->req, EACCES);\n                break;\n\n            case STATUS_UNSUCCESSFUL:\n            /* Happens if we try to lookup an illegal filename */\n            case STATUS_NO_SUCH_FILE:\n                fuse_reply_err(fip->req, ENOENT);\n                break;\n\n            default:\n                LOG_DEVEL(LOG_LEVEL_INFO, \"Error code %08x - fallthrough\", (int) IoStatus);\n                fuse_reply_err(fip->req, EIO);\n                break;\n        }\n    }\n    else if ((xinode = xfs_get(g_xfs, fip->inum)) == NULL)\n    {\n        fuse_reply_err(fip->req, ENOENT);\n    }\n    else\n    {\n        update_inode_file_attributes(&fip->fattr, fip->change_mask, xinode);\n        make_fuse_attr_reply(fip->req, xinode);\n    }\n    free(fip);\n}\n\n/**\n * This routine is caused as a result of a file or directory\n * create request */\nvoid xfuse_devredir_cb_create_file(struct state_create *fip,\n                                   enum NTSTATUS IoStatus,\n                                   tui32 DeviceId, tui32 FileId)\n{\n    XFUSE_HANDLE *fh = NULL;\n\n    if (IoStatus != 0)\n    {\n        switch (IoStatus)\n        {\n            case STATUS_ACCESS_DENIED:\n                fuse_reply_err(fip->req, EACCES);\n                break;\n\n            case STATUS_OBJECT_NAME_INVALID:\n            case STATUS_OBJECT_NAME_NOT_FOUND:\n                fuse_reply_err(fip->req, ENOENT);\n                break;\n\n            default:\n                fuse_reply_err(fip->req, EIO);\n                break;\n        }\n    }\n    else\n    {\n        if ((fip->mode & S_IFREG) != 0)\n        {\n            /* We've created a regular file */\n            /* Allocate an XFUSE_HANDLE for future file operations */\n            if ((fh = xfuse_handle_create()) != NULL)\n            {\n                /* save file handle for later use */\n                fh->DeviceId = DeviceId;\n                fh->FileId = FileId;\n\n                fip->fi.fh = xfuse_handle_to_fuse_handle(fh);\n            }\n        }\n\n        if ((fip->mode & S_IFREG) != 0 && fh == NULL)\n        {\n            /* We failed to allocate a file handle */\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            fuse_reply_err(fip->req, ENOMEM);\n        }\n        else\n        {\n            XFS_INODE   *xinode;\n            /* create entry in xrdp file system */\n            xinode = xfs_add_entry(g_xfs, fip->pinum, fip->name, fip->mode);\n            if (xinode == NULL)\n            {\n                /* It's possible xfs_add_entry() has failed, as the\n                 * file has already been added (by a lookup request)\n                 * in the time between our request and the response\n                 * This can happen if an 'ls' is happening in the same\n                 * directory as this file is being created.\n                 *\n                 * We'll check for this before we fail the create */\n                if ((xinode = xfs_lookup_in_dir(g_xfs,\n                                                fip->pinum,\n                                                fip->name)) != NULL)\n                {\n                    /*\n                     * The mode should be correct anyway, but we'll\n                     * set it to the mode requested at creation\n                     */\n                    xinode->mode = fip->mode;\n                }\n            }\n\n            if (xinode == NULL)\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"Out of memory!\");\n                fuse_reply_err(fip->req, ENOMEM);\n            }\n            else\n            {\n\n                if ((fip->mode & S_IFDIR) != 0)\n                {\n                    make_fuse_entry_reply(fip->req, xinode);\n                }\n                else\n                {\n                    struct fuse_entry_param  e;\n                    xfs_inode_to_fuse_entry_param(xinode, &e);\n                    fuse_reply_create(fip->req, &e, &fip->fi);\n                    xfs_increment_file_open_count(g_xfs, xinode->inum);\n                }\n            }\n        }\n\n    }\n\n    free(fip);\n}\n\n\n/**\n * This routine is caused as a result of a file open request */\nvoid xfuse_devredir_cb_open_file(struct state_open *fip,\n                                 enum NTSTATUS IoStatus,\n                                 tui32 DeviceId, tui32 FileId)\n{\n    XFUSE_HANDLE *fh;\n\n    if (IoStatus != 0)\n    {\n        switch (IoStatus)\n        {\n            case STATUS_ACCESS_DENIED:\n                fuse_reply_err(fip->req, EACCES);\n                break;\n\n            case STATUS_OBJECT_NAME_INVALID:\n            case STATUS_OBJECT_NAME_NOT_FOUND:\n                fuse_reply_err(fip->req, ENOENT);\n                break;\n\n            default:\n                fuse_reply_err(fip->req, EIO);\n                break;\n        }\n    }\n    else\n    {\n        /* Allocate an XFUSE_HANDLE for future file operations */\n        if ((fh = xfuse_handle_create()) == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            fuse_reply_err(fip->req, ENOMEM);\n        }\n        else\n        {\n            /* save file handle for later use */\n            fh->DeviceId = DeviceId;\n            fh->FileId = FileId;\n\n            fip->fi.fh = xfuse_handle_to_fuse_handle(fh);\n\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"sending fuse_reply_open(); \"\n                      \"DeviceId=%d FileId=%d req=%p\",\n                      fh->DeviceId, fh->FileId, fip->req);\n\n            /* update open count */\n            xfs_increment_file_open_count(g_xfs, fip->inum);\n\n            fuse_reply_open(fip->req, &fip->fi);\n        }\n    }\n\n    free(fip);\n}\n\nvoid xfuse_devredir_cb_read_file(struct state_read *fip,\n                                 enum NTSTATUS IoStatus,\n                                 const char *buf, size_t length)\n{\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"Read NTSTATUS is %d\", (int) IoStatus);\n        fuse_reply_err(fip->req, EIO);\n    }\n    else\n    {\n        fuse_reply_buf(fip->req, buf, length);\n    }\n    free(fip);\n}\n\nvoid xfuse_devredir_cb_write_file(\n    struct state_write *fip,\n    enum NTSTATUS IoStatus,\n    off_t offset,\n    size_t length)\n{\n    XFS_INODE   *xinode;\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"Write NTSTATUS is %d\", (int) IoStatus);\n        fuse_reply_err(fip->req, EIO);\n    }\n    else\n    {\n        off_t new_size = offset + length;\n        fuse_reply_write(fip->req, length);\n\n        /* update file size */\n        if ((xinode = xfs_get(g_xfs, fip->inum)) != NULL)\n        {\n            if (new_size > xinode->size)\n            {\n                xinode->size = new_size;\n            }\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is invalid\", fip->inum);\n        }\n    }\n\n    free(fip);\n}\n\nvoid xfuse_devredir_cb_rmdir_or_file(struct state_remove *fip,\n                                     enum NTSTATUS IoStatus)\n{\n    XFS_INODE   *xinode = xfs_get(g_xfs, fip->inum);\n\n    switch (IoStatus)\n    {\n        case STATUS_SUCCESS:\n        case STATUS_NO_SUCH_FILE:\n            if (xinode != NULL)\n            {\n                xfs_remove_entry(g_xfs, xinode->inum); /* Remove local copy */\n            }\n            fuse_reply_err(fip->req, 0);\n            break;\n\n        case STATUS_SHARING_VIOLATION:\n        case STATUS_ACCESS_DENIED:\n            fuse_reply_err(fip->req, EACCES);\n            break;\n\n        default:\n            LOG_DEVEL(LOG_LEVEL_INFO, \"Error code %08x - fallthrough\", (int) IoStatus);\n            fuse_reply_err(fip->req, EBADF);\n            break;\n    }\n    free(fip);\n}\n\nvoid xfuse_devredir_cb_rename_file(struct state_rename *fip,\n                                   enum NTSTATUS IoStatus)\n{\n    int status;\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        status =\n            (IoStatus == STATUS_SHARING_VIOLATION) ? EBUSY  :\n            (IoStatus == STATUS_ACCESS_DENIED)     ? EACCES :\n            /* default */                        EEXIST ;\n    }\n    else\n    {\n        status = xfs_move_entry(g_xfs, fip->pinum,\n                                fip->new_pinum, fip->name);\n    }\n\n    fuse_reply_err(fip->req, status);\n    free(fip);\n}\n\nvoid xfuse_devredir_cb_file_close(struct state_close *fip)\n{\n    fuse_reply_err(fip->req, 0);\n    xfs_decrement_file_open_count(g_xfs, fip->inum);\n\n    free(fip);\n}\n\nvoid xfuse_devredir_cb_statfs(struct state_statfs *fip,\n                              const struct statvfs *fss,\n                              enum NTSTATUS IoStatus)\n{\n    int status;\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        status =\n            (IoStatus == STATUS_ACCESS_DENIED) ? EACCES :\n            /* default */                        EIO ;\n        fuse_reply_err(fip->req, status);\n    }\n    else\n    {\n        fuse_reply_statfs(fip->req, fss);\n    }\n\n    free(fip);\n}\n\n/*\n * Determine is a file is in the FUSE filesystem\n *\n * The whole purpose of this function is to avoid deadlocks. If we try\n * to determine the size (or any other attribute) of a file in the FUSE\n * filesystem, the kernel will block the calling thread and send a message\n * to libfuse. Since we're single-threaded, this will result in deadlock.\n *\n * Ideally we'd use a stat() of the file to compare with a stat() of\n * the mountpoint. This won't work however, for the reasons outline above.\n *\n * A simple implementation might be to compare the start of the filename\n * with the FUSE mount point. This will work, but can easily be defeated,\n * (perhaps unintentionally) by symlinks in the path.\n *\n * The approach taken here is to record the basename of the FUSE mount\n * point directory (e.g. 'thinclient_drives') and look for that in the\n * passed-in filename as a directory element. If we find it, we look\n * at the device name and inode number of the parent directory of the\n * FUSE mount point. If these match we consider the filename to be in\n * the FUSE filesystem.\n */\nint xfuse_path_in_xfuse_fs(const char *path)\n{\n    char *wpath = NULL; /* Writeable copy of path */\n    char *p;\n    int blen = g_strlen(g_fuse_root_path_basename);\n    int rv = 0;\n\n    if ((wpath = g_strdup(path)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"system out of memory\");\n    }\n    else\n    {\n        /* Look ahead in the string for the basename of the FUSE mount point */\n        for (p = wpath;\n                (p = g_strstr(p, g_fuse_root_path_basename)) != NULL ;\n                p = p + 1)\n        {\n            /* Is this string preceded by a '/' ? */\n            if (p == wpath || *(p - 1) != '/')\n            {\n                continue;\n            }\n\n            /* Is the string followed by a '/' or '\\0' ? We know it's\n             * valid to look ahead this far in the string, as g_strstr()\n             * tells us it is */\n            if (*(p + blen) != '/' && *(p + blen) != '\\0')\n            {\n                continue;\n            }\n\n            /* Temporarily terminate the string early, and check the\n             * file system characteristics of the preceding directory */\n            *(p - 1) = '\\0';\n\n            if (g_file_get_device_number(wpath) == g_fuse_root_parent_dev &&\n                    g_file_get_inode_num(wpath) == g_fuse_root_parent_ino)\n            {\n                rv = 1;\n                break;\n            }\n            *(p - 1) = '/';\n        }\n        g_free(wpath);\n    }\n    return rv;\n}\n\n/******************************************************************************\n**                                                                           **\n**                           callbacks for fuse                              **\n**                                                                           **\n******************************************************************************/\n\n/**\n * Look up a directory entry by name and get its attributes\n *****************************************************************************/\n\nstatic void xfuse_cb_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)\n{\n    XFS_INODE *parent_xinode;\n    XFS_INODE *xinode = NULL;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"looking for parent=%ld name=%s\", parent, name);\n\n    if (strlen(name) > XFS_MAXFILENAMELEN)\n    {\n        fuse_reply_err(req, ENAMETOOLONG);\n    }\n    else if ((parent_xinode = xfs_get(g_xfs, parent)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", parent);\n        fuse_reply_err(req, ENOENT);\n    }\n    else\n    {\n        if (!parent_xinode->is_redirected)\n        {\n            /* File cannot be remote - we either know about it or we don't */\n            if ((xinode = xfs_lookup_in_dir(g_xfs, parent, name)) != NULL)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"found entry for parent=%ld name=%s\",\n                          parent, name);\n                make_fuse_entry_reply(req, xinode);\n            }\n            else\n            {\n                fuse_reply_err(req, ENOENT);\n            }\n        }\n        else\n        {\n            /* specified file resides on redirected share\n             *\n             * We always look these up, and relying on libfuse to do sane\n             * caching */\n            struct state_lookup *fip = g_new0(struct state_lookup, 1);\n            char *full_path = get_name_for_entry_in_parent(parent, name);\n\n            if (fip == NULL || full_path == NULL)\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n                fuse_reply_err(req, ENOMEM);\n                free(fip);\n                free(full_path);\n            }\n            else\n            {\n                const char *cptr;\n\n                fip->req = req;\n                fip->pinum = parent;\n                strcpy(fip->name, name);\n\n                /* we want path minus 'root node of the share' */\n                cptr = filename_on_device(full_path);\n\n                /* If the file already exists on our side, save the inum\n                 * and generation. If it's not remote any more this means we\n                 * can remove it when we get the response\n                 */\n                if ((xinode = xfs_lookup_in_dir(g_xfs, parent, name)) != NULL)\n                {\n                    fip->existing_inum = xinode->inum;\n                    fip->existing_generation = xinode->generation;\n                }\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"Looking up %s in %s on %d\", name, cptr,\n                          parent_xinode->device_id);\n                /*\n                 * If this call succeeds, further request processing happens in\n                 * xfuse_devredir_cb_lookup_entry()\n                 */\n                if (devredir_lookup_entry(fip, parent_xinode->device_id, cptr))\n                {\n                    LOG_DEVEL(LOG_LEVEL_ERROR, \"failed to send devredir_lookup_entry() cmd\");\n                    fuse_reply_err(req, EREMOTEIO);\n                    free(fip);\n                }\n                free(full_path);\n            }\n        }\n    }\n}\n\n/**\n * Get file attributes\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n *****************************************************************************/\n\nstatic void xfuse_cb_getattr(fuse_req_t req, fuse_ino_t ino,\n                             struct fuse_file_info *fi)\n{\n    XFS_INODE *xino;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"req=%p ino=%ld\", req, ino);\n\n    /* if ino is not valid, just return */\n    if ((xino = xfs_get(g_xfs, ino)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", ino);\n        fuse_reply_err(req, ENOENT);\n    }\n    else\n    {\n        make_fuse_attr_reply(req, xino);\n    }\n}\n\n/**\n *\n *****************************************************************************/\n\n/*\n * Adds an entry to the buffer, using fuse_add_direnty()\n *\n * Returns 1 for success, or zero if the entry couldn't be added\n */\nstatic int xfuse_dirbuf_add1(fuse_req_t req, struct dirbuf1 *b,\n                             XFS_INODE *xinode, off_t offset)\n{\n    struct stat  stbuf;\n    size_t len;\n    int result = 0;\n\n    memset(&stbuf, 0, sizeof(stbuf));\n    stbuf.st_ino = xinode->inum;\n    stbuf.st_mode = xinode->mode & ~g_cfg->file_umask;\n\n    /*\n     * Try to add the entry. From the docs for fuse_add_direntry():-\n     *   \"Buffer needs to be large enough to hold the entry. If it's not,\n     *    then the entry is not filled in but the size of the entry is\n     *    still returned.\"\n     */\n    len = fuse_add_direntry(req,\n                            &b->buf[b->len], /* index where new entry will be added to buf */\n                            sizeof(b->buf) - b->len,  /* Space left */\n                            xinode->name,             /* name of entry */\n                            &stbuf,                   /* file attributes */\n                            offset                    /* offset of next entry */\n                           );\n    if (len + b->len <= sizeof(b->buf))\n    {\n        /* Entry fitted in OK */\n        b->len += len;\n        result = 1;\n    }\n\n    return result;\n}\n\n/**\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n *****************************************************************************/\n\nstatic void xfuse_cb_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,\n                             off_t off, struct fuse_file_info *fi)\n{\n    XFS_INODE      *xinode;\n    XFUSE_HANDLE   *xhandle;\n    struct xfs_dir_handle *dh;\n    struct dirbuf1   b;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"req=%p inode=%ld size=%zd offset=%lld\", req, ino, size, (long long) off);\n\n    /* On the first call, check the inode is valid */\n    if (off == 0 && !xfs_get(g_xfs, ino))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", ino);\n        fuse_reply_err(req, ENOENT);\n    }\n    else if ((xhandle = xfuse_handle_from_fuse_handle(fi->fh)) == NULL\n             || (dh = xhandle->dir_handle) == NULL)\n    {\n        /* something seriously wrong somewhere! */\n        fuse_reply_buf(req, 0, 0);\n    }\n    else\n    {\n        b.len = 0;\n\n        off_t new_off = off;\n        while ((xinode = xfs_readdir(g_xfs, dh, &new_off)) != NULL)\n        {\n            if (xfuse_dirbuf_add1(req, &b, xinode, new_off) == 0)\n            {\n                break; /* buffer is full */\n            }\n            /* Make sure we get the next entry next time */\n            off = new_off;\n        }\n\n        fuse_reply_buf(req, b.buf, b.len);\n    }\n}\n\n\n/**\n * Create a directory\n *****************************************************************************/\n\nstatic void xfuse_cb_mkdir(fuse_req_t req, fuse_ino_t parent,\n                           const char *name, mode_t mode)\n{\n    XFS_INODE               *xinode;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: parent_inode=%ld name=%s\", parent, name);\n\n    if ((xinode = xfs_lookup_in_dir(g_xfs, parent, name)) != NULL)\n    {\n        /* dir already exists, just return it */\n        make_fuse_entry_reply(req, xinode);\n    }\n    else\n    {\n        /* dir does not exist, create it */\n        xfuse_create_dir_or_file(req, parent, name, mode | S_IFDIR, NULL);\n    }\n}\n\n/**\n * Remove a dir or file\n *\n *****************************************************************************/\n\nstatic void xfuse_cb_unlink(fuse_req_t req, fuse_ino_t parent,\n                            const char *name)\n{\n    XFS_INODE *xinode;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: parent=%ld name=%s\", parent, name);\n\n    if (strlen(name) > XFS_MAXFILENAMELEN)\n    {\n        fuse_reply_err(req, ENAMETOOLONG);\n    }\n    else if ((xinode = xfs_lookup_in_dir(g_xfs, parent, name)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"did not find file with pinode=%ld name=%s\", parent, name);\n        fuse_reply_err(req, ENOENT);\n    }\n\n    else if ((xinode->mode & S_IFDIR) != 0 &&\n             !xfs_is_dir_empty(g_xfs, xinode->inum))\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"cannot rmdir; directory is not empty\");\n        fuse_reply_err(req, ENOTEMPTY);\n    }\n\n    else if (!xinode->is_redirected)\n    {\n        /* specified file is a local resource */\n        //XFUSE_HANDLE *fh;\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"LK_TODO: this is still a TODO\");\n        fuse_reply_err(req, EROFS);\n    }\n    else\n    {\n        /* specified file resides on redirected share */\n        struct state_remove *fip = g_new0(struct state_remove, 1);\n        char *full_path = xfs_get_full_path(g_xfs, xinode->inum);\n        if (!full_path || !fip)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            fuse_reply_err(req, ENOMEM);\n            free(fip);\n        }\n        else\n        {\n            const char *cptr;\n\n            fip->req = req;\n            fip->inum = xinode->inum;\n\n            /* we want path minus 'root node of the share' */\n            cptr = filename_on_device(full_path);\n\n            /* get devredir to open the remote file\n             *\n             * If this call succeeds, further request processing happens in\n             * xfuse_devredir_cb_rmdir_or_file()\n             */\n            if (devredir_rmdir_or_file(fip, xinode->device_id, cptr))\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"failed to send devredir_rmdir_or_file() cmd\");\n                fuse_reply_err(req, EREMOTEIO);\n                free(fip);\n            }\n\n        }\n        free(full_path);\n    }\n}\n\nstatic void xfuse_cb_rename(fuse_req_t req,\n                            fuse_ino_t old_parent, const char *old_name,\n                            fuse_ino_t new_parent, const char *new_name,\n                            unsigned int flags)\n{\n    XFS_INODE *old_xinode;\n    XFS_INODE *new_parent_xinode;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: old_parent=%ld old_name=%s new_parent=%ld new_name=%s\",\n              old_parent, old_name, new_parent, new_name);\n\n    // renameat2() flags (in stdio.h) are not supported\n    if (flags != 0)\n    {\n        fuse_reply_err(req, EINVAL);\n    }\n    else if (strlen(old_name) > XFS_MAXFILENAMELEN ||\n             strlen(new_name) > XFS_MAXFILENAMELEN)\n    {\n        fuse_reply_err(req, ENAMETOOLONG);\n    }\n    else if (!(old_xinode = xfs_lookup_in_dir(g_xfs, old_parent, old_name)))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"did not find file with pinode=%ld name=%s\",\n                  old_parent, old_name);\n        fuse_reply_err(req, ENOENT);\n    }\n\n    else if (!(new_parent_xinode = xfs_get(g_xfs, new_parent)))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", new_parent);\n        fuse_reply_err(req, ENOENT);\n    }\n\n    else if (!xfs_check_move_entry(g_xfs, old_xinode->inum,\n                                   new_parent, new_name))\n    {\n        /* Catchall -see rename(2). Fix when logging is improved */\n        fuse_reply_err(req, EINVAL);\n    }\n\n    else if (new_parent_xinode->is_redirected != old_xinode->is_redirected ||\n             new_parent_xinode->device_id != old_xinode->device_id)\n    {\n        fuse_reply_err(req, EXDEV);\n    }\n\n    else if (!old_xinode->is_redirected)\n    {\n        /* specified file is a local resource */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"LK_TODO: this is still a TODO\");\n        fuse_reply_err(req, EROFS);\n    }\n\n    else\n    {\n        /* resource is on a redirected share */\n        struct state_rename *fip = g_new0(struct state_rename, 1);\n        char *old_full_path = xfs_get_full_path(g_xfs, old_xinode->inum);\n        char *new_full_path = get_name_for_entry_in_parent(new_parent,\n                              new_name);\n\n        if (!old_full_path || !new_full_path || !fip)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            fuse_reply_err(req, ENOMEM);\n            free(fip);\n            free(old_full_path);\n            free(new_full_path);\n        }\n        else\n        {\n            const char *cptr;\n            const char *cp;\n\n            fip->req = req;\n            fip->pinum = old_xinode->inum;\n            fip->new_pinum = new_parent;\n            strcpy(fip->name, new_name);\n\n            /* we want path minus 'root node of the share' */\n            cptr = filename_on_device(old_full_path);\n            cp = filename_on_device(new_full_path);\n\n            /*\n             * If this call succeeds, further request processing happens in\n             * xfuse_devredir_cb_rename_file()\n             */\n            if (devredir_file_rename(fip, old_xinode->device_id, cptr, cp))\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"failed to send devredir_file_rename() cmd\");\n                fuse_reply_err(req, EREMOTEIO);\n                free(fip);\n            }\n            free(old_full_path);\n            free(new_full_path);\n        }\n    }\n}\n\n/**\n * Create a directory or file\n *\n * @param req    opaque FUSE object\n * @param parent parent inode\n * @param name   name of dir or file to create\n * @param mode   creation mode\n * @param fi     File info from fuse_lowlevel_ops.create, or NULL.\n *               This may need to be copied if we're not replying immediately\n *****************************************************************************/\n\nstatic void xfuse_create_dir_or_file(fuse_req_t req, fuse_ino_t parent,\n                                     const char *name, mode_t mode,\n                                     struct fuse_file_info *fi)\n{\n    XFS_INODE        *xinode;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: parent_ino=%ld name=%s mode=%o type=%s\",\n              parent, name, mode, (mode & S_IFDIR) ? \"dir\" : \"file\");\n\n    /* name must be valid */\n    if (strlen(name) > XFS_MAXFILENAMELEN)\n    {\n        fuse_reply_err(req, ENAMETOOLONG);\n    }\n    else\n    {\n        /* Sanitise the mode\n         *\n         * Currently group/world write is not allowed.\n         */\n        if (mode & S_IFDIR)\n        {\n            mode = (mode & 0777) | S_IFDIR;\n        }\n        else\n        {\n            mode = (mode & 0777) | S_IFREG;\n        }\n\n        /* is parent inode valid? */\n        if (parent == FUSE_ROOT_ID)\n        {\n            fuse_reply_err(req, EROFS);\n        }\n        else if ((xinode = xfs_get(g_xfs, parent)) == NULL)\n        {\n            fuse_reply_err(req, ENOENT);\n        }\n        else if ((xinode->mode & S_IFDIR) == 0)\n        {\n            fuse_reply_err(req, ENOTDIR);\n        }\n        else if (!xinode->is_redirected)\n        {\n            /* specified file is a local resource */\n            //XFUSE_HANDLE *fh;\n\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"LK_TODO: this is still a TODO\");\n            fuse_reply_err(req, EROFS);\n        }\n        else\n        {\n            struct state_create *fip = g_new0(struct state_create, 1);\n            char *full_path = get_name_for_entry_in_parent(parent, name);\n\n            if (full_path == NULL || fip == NULL)\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"Out of memory\");\n                fuse_reply_err(req, ENOMEM);\n                free(fip);\n                free(full_path);\n            }\n            else\n            {\n                const char *cptr;\n\n                fip->req = req;\n                if (fi != NULL)\n                {\n                    fip->fi = *fi;\n                }\n                fip->pinum = parent;\n                strcpy(fip->name, name);\n                fip->mode = mode;\n\n                /* we want path minus 'root node of the share' */\n                cptr = filename_on_device(full_path);\n\n                /*\n                 * If this call succeeds, further request processing happens\n                 * in xfuse_devredir_cb_create_file()\n                 */\n                if (devredir_file_create(fip, xinode->device_id, cptr, mode))\n                {\n                    LOG_DEVEL(LOG_LEVEL_ERROR, \"failed to send devredir_file_create() cmd\");\n                    fuse_reply_err(req, EREMOTEIO);\n                    free(fip);\n                }\n                free(full_path);\n            }\n        }\n    }\n}\n\n/**\n * Open specified file\n*\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n *****************************************************************************/\n\nstatic void xfuse_cb_open(fuse_req_t req, fuse_ino_t ino,\n                          struct fuse_file_info *fi)\n{\n    XFS_INODE        *xinode;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: ino=%ld\", ino);\n\n    if (!(xinode = xfs_get(g_xfs, ino)))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", ino);\n        fuse_reply_err(req, ENOENT);\n    }\n    else if (xinode->mode & S_IFDIR)\n    {\n        /* Can't open directories like this */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"reading/writing a dir not allowed!\");\n        fuse_reply_err(req, EISDIR);\n    }\n    else if ((fi->flags & O_ACCMODE) != O_RDONLY &&\n             (fi->flags & O_ACCMODE) != O_WRONLY &&\n             (fi->flags & O_ACCMODE) != O_RDWR)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"Invalid access mode specified\");\n        fuse_reply_err(req, EINVAL);\n    }\n    else if (!xinode->is_redirected)\n    {\n        /* specified file is a local resource */\n        if ((fi->flags & O_ACCMODE) != O_RDONLY)\n        {\n            fuse_reply_err(req, EROFS);\n        }\n        else\n        {\n            XFUSE_HANDLE *fh = xfuse_handle_create();\n            fh->is_loc_resource = 1;\n            fi->fh = xfuse_handle_to_fuse_handle(fh);\n            fuse_reply_open(req, fi);\n        }\n    }\n    else\n    {\n        /* specified file resides on redirected share */\n        struct state_open *fip = g_new0(struct state_open, 1);\n        char *full_path = xfs_get_full_path(g_xfs, ino);\n\n        if (!full_path || !fip)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            fuse_reply_err(req, ENOMEM);\n            free(fip);\n            free(full_path);\n        }\n        else\n        {\n            const char *cptr;\n\n            fip->req = req;\n            fip->fi = *fi;\n            fip->inum = ino;\n\n            if (g_cfg->fuse_direct_io)\n            {\n                fip->fi.direct_io = 1;\n            }\n\n            /* we want path minus 'root node of the share' */\n            cptr = filename_on_device(full_path);\n\n            /* get devredir to open the remote file\n             *\n             * If the caller has set O_TRUNC when writing the file,\n             * fuse should call us back via fuse_cb_setattr() to set\n             * the size to zero - we don't need to do this ourselves.\n             *\n             * If this call succeeds, further request processing happens in\n             * xfuse_devredir_cb_open_file()\n             */\n            if (devredir_file_open(fip, xinode->device_id, cptr, fi->flags))\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"failed to send devredir_file_open() cmd\");\n                fuse_reply_err(req, EREMOTEIO);\n                free(fip);\n            }\n            free(full_path);\n        }\n    }\n}\n\n/*\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n */\nstatic void xfuse_cb_release(fuse_req_t req, fuse_ino_t ino, struct\n                             fuse_file_info *fi)\n{\n    XFS_INODE   *xinode;\n\n    XFUSE_HANDLE *handle = xfuse_handle_from_fuse_handle(fi->fh);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: ino=%ld fi=%p fi->fh=0x%llx\", ino, fi,\n              (long long) fi->fh);\n\n    if ((xinode = xfs_get(g_xfs, ino)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", ino);\n        fuse_reply_err(req, ENOENT);\n    }\n    else if (!xinode->is_redirected)\n    {\n        /* specified file is a local resource */\n        fuse_reply_err(req, 0);\n    }\n    else\n    {\n        /* specified file resides on redirected share */\n\n        struct state_close *fip = g_new0(struct state_close, 1);\n        if (fip == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            fuse_reply_err(req, ENOMEM);\n            return;\n        }\n\n        fip->req = req;\n        fip->inum = ino;\n        fip->fi = *fi;\n\n        fi->fh = xfuse_handle_to_fuse_handle(NULL);\n\n        /*\n         * If this call succeeds, further request processing happens in\n         * xfuse_devredir_cb_file_close()\n         */\n        if (devredir_file_close(fip, xinode->device_id, handle->FileId))\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"failed to send devredir_close_file() cmd\");\n            fuse_reply_err(req, EREMOTEIO);\n            free(fip);\n        }\n\n        xfuse_handle_delete(handle);\n    }\n}\n\n/**\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n *****************************************************************************/\n\nstatic void xfuse_cb_read(fuse_req_t req, fuse_ino_t ino, size_t size,\n                          off_t off, struct fuse_file_info *fi)\n{\n    XFUSE_HANDLE          *fh;\n    struct state_read *fusep;\n    XFS_INODE            *xinode;\n    struct req_list_item  *rli;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"want_bytes %zd bytes at off %lld\", size, (long long) off);\n\n    if ((fh = xfuse_handle_from_fuse_handle(fi->fh)) == NULL)\n    {\n        fuse_reply_err(req, EINVAL);\n    }\n    else if (fh->is_loc_resource)\n    {\n        /* target file is in .clipboard dir */\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"target file is in .clipboard dir\");\n\n        if ((xinode = xfs_get(g_xfs, ino)) == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"ino does not exist in xrdp_fs\");\n            fuse_reply_buf(req, 0, 0);\n            return;\n        }\n\n        rli = g_new0(struct req_list_item, 1);\n\n        rli->stream_id = 0;\n        rli->req = req;\n        rli->lindex = xinode->lindex;\n        rli->off = off;\n        rli->size = size;\n        list_add_item(g_req_list, (tbus) rli);\n\n        if (g_req_list->count == 1)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"requesting clipboard file data lindex = %d off = %lld size = %zd\",\n                      rli->lindex, (long long) off, size);\n\n            clipboard_request_file_data(rli->stream_id, rli->lindex,\n                                        (int) off, (int) size);\n        }\n    }\n    else\n    {\n        /* target file is on a remote device */\n\n        fusep = g_new0(struct state_read, 1);\n        if (fusep == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            fuse_reply_err(req, ENOMEM);\n        }\n        else\n        {\n            fusep->req = req;\n\n            /*\n             * If this call succeeds, further request processing happens in\n             * xfuse_devredir_cb_read_file()\n             */\n            devredir_file_read(fusep, fh->DeviceId, fh->FileId, size, off);\n        }\n    }\n}\n\n/**\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n *****************************************************************************/\n\nstatic void xfuse_cb_write(fuse_req_t req, fuse_ino_t ino, const char *buf,\n                           size_t size, off_t off, struct fuse_file_info *fi)\n{\n    XFUSE_HANDLE *fh;\n    struct state_write *fusep;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"write %zd bytes at off %lld to inode=%ld\",\n              size, (long long) off, ino);\n\n    if ((fh = xfuse_handle_from_fuse_handle(fi->fh)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"file handle fi->fh is NULL\");\n        fuse_reply_err(req, EINVAL);\n    }\n    else if (fh->is_loc_resource)\n    {\n        /* target file is in .clipboard dir */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"THIS IS STILL A TODO!\");\n        fuse_reply_err(req, EROFS);\n    }\n    else\n    {\n        /* target file is on a remote device */\n\n        fusep = g_new0(struct state_write, 1);\n        if (fusep == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            fuse_reply_err(req, ENOMEM);\n        }\n        else\n        {\n            fusep->req = req;\n            fusep->inum = ino;\n\n            /*\n             * If this call succeeds, further request processing happens in\n             * xfuse_devredir_cb_write_file()\n             */\n            devredir_file_write(fusep, fh->DeviceId, fh->FileId, buf,\n                                size, off);\n        }\n    }\n}\n\n/**\n *****************************************************************************/\n\n/*\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n */\nstatic void xfuse_cb_create(fuse_req_t req, fuse_ino_t parent,\n                            const char *name, mode_t mode,\n                            struct fuse_file_info *fi)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: parent_inode=%ld, name=%s fi=%p\",\n              parent, name, fi);\n\n    xfuse_create_dir_or_file(req, parent, name, mode & ~S_IFDIR, fi);\n}\n\n/**\n *****************************************************************************/\n\n#if 0\nstatic void xfuse_cb_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,\n                           struct fuse_file_info *fi)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"#################### entered: ino=%ld datasync=%d\", ino, datasync);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"function not required\");\n    fuse_reply_err(req, EINVAL);\n}\n#endif\n\n/**\n * Sets attributes for a directory entry.\n *\n * If the file resides on a remote share, devredir\n * is asked to update it. This will result in the following\n * callbacks:-\n * - xfuse_devredir_cb_setattr() to update our copy and return status\n *\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n *****************************************************************************/\n\nstatic void xfuse_cb_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,\n                             int to_set, struct fuse_file_info *fi)\n{\n    XFS_INODE   *xinode;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered to_set=0x%x\", to_set);\n\n    if ((xinode = xfs_get(g_xfs, ino)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", ino);\n        fuse_reply_err(req, ENOENT);\n    }\n    else if (((to_set & FUSE_SET_ATTR_UID) && attr->st_uid != xinode->uid) ||\n             ((to_set & FUSE_SET_ATTR_GID) && attr->st_gid != xinode->gid))\n    {\n        /* We don't allow any of these */\n        fuse_reply_err(req, EPERM);\n    }\n    else if ((to_set & FUSE_SET_ATTR_MODE) &&\n             (attr->st_mode & ~(0777 | S_IFDIR | S_IFREG)) != 0)\n    {\n        /* We only support standard mode bits and S_IFDIR / S_IFREG */\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"Asking for invalid mode bits 0%o to be set\", attr->st_mode);\n        fuse_reply_err(req, EINVAL);\n    }\n    else\n    {\n        struct file_attr attrs = {0};\n        tui32 change_mask = 0;\n\n        if ((to_set & FUSE_SET_ATTR_MODE) && xinode->mode != attr->st_mode)\n        {\n            attrs.mode = attr->st_mode & (0777 | S_IFDIR | S_IFREG);\n            change_mask |= TO_SET_MODE;\n        }\n\n        if ((to_set & FUSE_SET_ATTR_SIZE) && xinode->size != attr->st_size)\n        {\n            attrs.size = attr->st_size;\n            change_mask |= TO_SET_SIZE;\n        }\n\n        if ((to_set & FUSE_SET_ATTR_ATIME) && xinode->atime != attr->st_atime)\n        {\n            attrs.atime = attr->st_atime;\n            change_mask |= TO_SET_ATIME;\n        }\n\n        if ((to_set & FUSE_SET_ATTR_MTIME) && xinode->mtime != attr->st_mtime)\n        {\n            attrs.mtime = attr->st_mtime;\n            change_mask |= TO_SET_MTIME;\n        }\n\n        if (change_mask == 0)\n        {\n            /* No changes have been made */\n            make_fuse_attr_reply(req, xinode);\n        }\n        else if (!xinode->is_redirected)\n        {\n            /* Update the local fs */\n            update_inode_file_attributes(&attrs, change_mask, xinode);\n            make_fuse_attr_reply(req, xinode);\n        }\n        else\n        {\n            struct state_setattr *fip = g_new0(struct state_setattr, 1);\n            char *full_path = xfs_get_full_path(g_xfs, ino);\n            if (!full_path || !fip)\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n                fuse_reply_err(req, ENOMEM);\n                free(fip);\n                free(full_path);\n            }\n            else\n            {\n                const char *cptr;\n                fip->req = req;\n                fip->inum = ino;\n                /* Save the important stuff so we can update our node if the\n                 * remote update is successful */\n                fip->fattr = attrs;\n                fip->change_mask = change_mask;\n\n                /* we want path minus 'root node of the share' */\n                cptr = filename_on_device(full_path);\n\n                /*\n                 * If this call succeeds, further request processing happens\n                 * in xfuse_devredir_cb_setattr()\n                 */\n                if (devredir_setattr_for_entry(fip, xinode->device_id,\n                                               cptr, &attrs, change_mask) < 0)\n                {\n                    fuse_reply_err(req, EIO);\n                    free(fip);\n                }\n\n                free(full_path);\n            }\n        }\n    }\n}\n\n/**\n * Get dir listing\n *\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n *****************************************************************************/\nstatic void xfuse_cb_opendir(fuse_req_t req, fuse_ino_t ino,\n                             struct fuse_file_info *fi)\n{\n    XFS_INODE      *xinode;\n    XFUSE_HANDLE   *xhandle;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"inode=%ld\", ino);\n\n    if ((xinode = xfs_get(g_xfs, ino)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", ino);\n        fuse_reply_err(req, ENOENT);\n    }\n    else if (!xinode->is_redirected)\n    {\n        if ((xhandle = xfuse_handle_create()) == NULL)\n        {\n            fuse_reply_err(req, ENOMEM);\n        }\n        else\n        {\n            // Coverity gets confused by xfuse_handle_to_fuse_handle(), and\n            // sees the dir_handle leaked\n            //coverity[RESOURCE_LEAK:FALSE]\n            xhandle->dir_handle = xfs_opendir(g_xfs, ino);\n            if (xhandle->dir_handle == NULL)\n            {\n                xfuse_handle_delete(xhandle);\n                fuse_reply_err(req, ENOMEM);\n            }\n            else\n            {\n                fi->fh = xfuse_handle_to_fuse_handle(xhandle);\n                fuse_reply_open(req, fi);\n            }\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"did not find entry; redirecting call to devredir\");\n        struct state_dirscan *fip = g_new0(struct state_dirscan, 1);\n        char *full_path = xfs_get_full_path(g_xfs, ino);\n\n        if (full_path == NULL || fip == NULL)\n        {\n            fuse_reply_err(req, ENOMEM);\n            free(fip);\n            free(full_path);\n        }\n        else\n        {\n            const char      *cptr;\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"dev_id=%d ino=%ld full_path=%s\",\n                      xinode->device_id, ino, full_path);\n\n            fip->req = req;\n            fip->pinum = ino;\n            fip->fi = *fi;\n\n            /* we want path minus 'root node of the share' */\n            cptr = filename_on_device(full_path);\n\n            /*\n             * If this call succeeds, further request processing happens in:-\n             * - xfuse_devredir_cb_enum_dir_add_entry()\n             *       Called for every file in the directory\n             * - xfuse_devredir_cb_enum_dir_done()\n             *       Called at the end of the directory scan\n             */\n            if (devredir_get_dir_listing(fip, xinode->device_id, cptr))\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"failed to send devredir_get_dir_listing() cmd\");\n                fuse_reply_buf(req, NULL, 0);\n                free(fip);\n            }\n            free(full_path);\n        }\n    }\n}\n\n/**\n * GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the\n *          stack by the caller, so must be copied if we're not using it\n *          to reply to FUSE immediately\n *****************************************************************************/\n\nstatic void xfuse_cb_releasedir(fuse_req_t req, fuse_ino_t ino,\n                                struct fuse_file_info *fi)\n{\n    XFUSE_HANDLE *xhandle = xfuse_handle_from_fuse_handle(fi->fh);\n    xfs_closedir(g_xfs, xhandle->dir_handle);\n    xhandle->dir_handle = NULL;\n    xfuse_handle_delete(xhandle);\n    fuse_reply_err(req, 0);\n}\n\n/*****************************************************************************/\nstatic void xfuse_cb_statfs(fuse_req_t req, fuse_ino_t ino)\n{\n    XFS_INODE        *xinode;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: ino=%ld\", ino);\n\n    if (!(xinode = xfs_get(g_xfs, ino)))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"inode %ld is not valid\", ino);\n        fuse_reply_err(req, ENOENT);\n    }\n    else if (!xinode->is_redirected)\n    {\n        /* specified file is a local resource */\n        struct statvfs vfs_stats = {0};\n        if (g_cfg->fuse_root_report_max_free)\n        {\n            // Report an 95% free max-size filesystem\n            vfs_stats.f_bsize = 0x1000;\n            vfs_stats.f_frsize = vfs_stats.f_bsize;\n#if SIZEOF_FSBLKCNT_T < 8\n            vfs_stats.f_blocks = (fsblkcnt_t) -1;\n#else\n            // Max-size is taken from XFS (8 * 2^60 bytes). Using -1\n            // as a value does not work here.\n            vfs_stats.f_blocks = (fsblkcnt_t)8 * 0x10000 * 0x10000 * 0x10000;\n#endif\n            vfs_stats.f_bfree = vfs_stats.f_blocks - vfs_stats.f_blocks / 20;\n            vfs_stats.f_bavail = vfs_stats.f_bfree;\n            vfs_stats.f_namemax = XFS_MAXFILENAMELEN;\n        }\n        fuse_reply_statfs(req, &vfs_stats);\n    }\n    else\n    {\n        /* specified file resides on redirected share */\n\n        struct state_statfs *fip = g_new0(struct state_statfs, 1);\n        char *full_path = xfs_get_full_path(g_xfs, ino);\n        if (full_path == NULL || fip == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n            fuse_reply_err(req, ENOMEM);\n            free(full_path);\n            free(fip);\n        }\n        else\n        {\n            const char      *cptr;\n            fip->req = req;\n\n            /* get devredir to statfs the filesystem for the file\n             *\n             * If this call succeeds, further request processing happens in\n             * xfuse_devredir_cb_statfs()\n             */\n            cptr = filename_on_device(full_path);\n            if (devredir_statfs(fip, xinode->device_id, cptr))\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"failed to send devredir_statfs() cmd\");\n                fuse_reply_err(req, EREMOTEIO);\n                free(fip);\n            }\n            free(full_path);\n        }\n    }\n}\n\n/******************************************************************************\n *                           miscellaneous functions\n *****************************************************************************/\n\nstatic void xfs_inode_to_fuse_entry_param(const XFS_INODE *xinode,\n        struct fuse_entry_param *e)\n{\n    memset(e, 0, sizeof(*e));\n    e->ino = xinode->inum;\n    e->attr_timeout = XFUSE_ATTR_TIMEOUT;\n    e->entry_timeout = XFUSE_ENTRY_TIMEOUT;\n    e->attr.st_ino = xinode->inum;\n    e->attr.st_mode = xinode->mode & ~g_cfg->file_umask;\n    e->attr.st_nlink = 1;\n    e->attr.st_uid = xinode->uid;\n    e->attr.st_gid = xinode->gid;\n    e->attr.st_size = xinode->size;\n    e->attr.st_atime = xinode->atime;\n    e->attr.st_mtime = xinode->mtime;\n    e->attr.st_ctime = xinode->ctime;\n    e->generation =  xinode->generation;\n}\n\nstatic void make_fuse_entry_reply(fuse_req_t req, const XFS_INODE *xinode)\n{\n    struct fuse_entry_param  e;\n    xfs_inode_to_fuse_entry_param(xinode, &e);\n    fuse_reply_entry(req, &e);\n}\n\nstatic void make_fuse_attr_reply(fuse_req_t req, const XFS_INODE *xinode)\n{\n    struct stat st;\n\n    memset(&st, 0, sizeof(st));\n    st.st_ino = xinode->inum;\n    st.st_mode = xinode->mode & ~g_cfg->file_umask;\n    st.st_nlink = 1;\n    st.st_uid = xinode->uid;\n    st.st_gid = xinode->gid;\n    st.st_size = xinode->size;\n    st.st_atime = xinode->atime;\n    st.st_mtime = xinode->mtime;\n    st.st_ctime = xinode->ctime;\n\n    fuse_reply_attr(req, &st, XFUSE_ATTR_TIMEOUT);\n}\n\n/*\n * Get the name of a file on the device\n *\n * For redirected devices, the routine xfs_get_full_path() returns names\n * like \"/C:/Windows/System32\".\n * This routine simply returns a pointer to the part of the name following\n * the device specification.\n */\nstatic const char *filename_on_device(const char *full_path)\n{\n    const char *result = NULL;\n    if (full_path[0] != '\\0')\n    {\n        result = strchr(full_path + 1, '/');\n    }\n    return result ? result : \"/\";\n}\n\n/*\n * Updates attributes on the filesystem, and bumps the inode ctime\n *\n * This call is used to set attributes, either locally, or following a\n * setattr devredir call\n */\nstatic void update_inode_file_attributes(const struct file_attr *fattr,\n        tui32 change_mask, XFS_INODE *xinode)\n{\n    int updated = 0;\n\n    if ((change_mask & TO_SET_MODE) != 0 && xinode->mode != fattr->mode)\n    {\n        xinode->mode = fattr->mode;\n        updated = 1;\n    }\n    if ((change_mask & TO_SET_SIZE) != 0 && xinode->size != fattr->size)\n    {\n        xinode->size = fattr->size;\n        updated = 1;\n    }\n    if ((change_mask & TO_SET_ATIME) != 0 && xinode->atime != fattr->atime)\n    {\n        xinode->atime = fattr->atime;\n        updated = 1;\n    }\n    if ((change_mask & TO_SET_MTIME) != 0 && xinode->mtime != fattr->mtime)\n    {\n        xinode->mtime = fattr->mtime;\n        updated = 1;\n    }\n\n    if (updated)\n    {\n        xinode->ctime = time(0);\n    }\n}\n\n/*\n * Gets the name for a file where we know the parent inode and the\n * name for the file under that inode\n *\n * Result must be freed after use\n */\nstatic char *get_name_for_entry_in_parent(fuse_ino_t parent, const char *name)\n{\n    char *result;\n\n    if ((result = xfs_get_full_path(g_xfs, parent)) != NULL)\n    {\n        char *p = (char *) realloc(result,\n                                   strlen(result) + 1 + strlen(name) + 1);\n        if (p == NULL)\n        {\n            /* See cppcheck trac #9292 and #9437 */\n            /* cppcheck-suppress doubleFree symbolName=result */\n            free(result);\n            result = NULL;\n        }\n        else\n        {\n            result = p;\n            strcat(result, \"/\");\n            strcat(result, name);\n        }\n    }\n\n    return result;\n}\n\n/*\n * Scans a user-provided string substituting %u/%U/ for UID/username\n * and %d/%D fordisplaynumber/DISPLAY\n */\nstatic unsigned int format_user_info(char *dest, unsigned int len,\n                                     const char *format)\n{\n    char uidstr[64];\n    char username[64];\n    char display[MAX_DISPLAY_NAME_SIZE];\n    const struct info_string_tag map[] =\n    {\n        {'u', uidstr},\n        {'U', username},\n        {'d', display},\n        INFO_STRING_END_OF_LIST\n    };\n\n    int uid = g_getuid();\n    g_snprintf(uidstr, sizeof(uidstr), \"%d\", uid);\n    if (g_getlogin(username, sizeof(username)) != 0)\n    {\n        /* Fall back to UID */\n        strlcpy(username, uidstr, sizeof(username));\n    }\n\n    if (g_get_display_string(display, sizeof(display)) < 0)\n    {\n        /* if environment variable is not set, set it to empty string */\n        display[0] = '\\0';\n    }\n\n    return g_format_info_string(dest, len, format, map);\n}\n\n#endif /* end else #ifndef XRDP_FUSE */\n"
  },
  {
    "path": "sesman/chansrv/chansrv_fuse.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _CHANSRV_FUSE_H\n#define _CHANSRV_FUSE_H\n\n#include <sys/types.h>\n#include <time.h>\n\n#include \"arch.h\"\n#include \"ms-erref.h\"\n\n/* Used to pass file info back to chansrv_fuse from devredir */\nstruct file_attr\n{\n    tui32           mode;              /* File mode.                        */\n    off_t           size;              /* Size of file, in bytes.           */\n    time_t          atime;             /* Time of last access.              */\n    time_t          mtime;             /* Time of last modification.        */\n};\n\n/* Bitmask values used to identify individual elements in\n * struct file_attr\n */\n#define TO_SET_MODE  (1<<0)\n#define TO_SET_SIZE  (1<<1)\n#define TO_SET_ATIME (1<<2)\n#define TO_SET_MTIME (1<<3)\n#define TO_SET_ALL   (TO_SET_MODE | TO_SET_SIZE | TO_SET_ATIME | TO_SET_MTIME)\n\n/* Private type passed into and back-from devredir */\ntypedef struct xfuse_info XFUSE_INFO;\n\nint xfuse_init(void);\nint xfuse_deinit(void);\nint xfuse_check_wait_objs(void);\nint xfuse_get_wait_objs(tbus *objs, int *count, int *timeout);\nint xfuse_create_share(tui32 share_id, const char *dirname);\nvoid xfuse_delete_share(tui32 share_id);\n\nint xfuse_clear_clip_dir(void);\nint xfuse_file_contents_range(int stream_id, const char *data, int data_bytes);\nint xfuse_file_contents_size(int stream_id, int file_size);\nint xfuse_add_clip_dir_item(const char *filename,\n                            int flags, int size, int lindex);\n\n/* State pointer types (opaque outside this module), used for\n * callback data\n */\nstruct state_dirscan;\nstruct state_lookup;\nstruct state_setattr;\nstruct state_open;\nstruct state_create;\nstruct state_read;\nstruct state_write;\nstruct state_remove;\nstruct state_rename;\nstruct state_close;\nstruct statvfs; // OS structure defined in <sys/statvfs.h>\nstruct state_statfs;\n\n\n/* functions that are invoked from devredir */\nvoid xfuse_devredir_cb_enum_dir_add_entry(\n    struct state_dirscan *fip,\n    const char *name,\n    const struct file_attr *fattr);\nvoid xfuse_devredir_cb_enum_dir_done(struct state_dirscan *fip,\n                                     enum NTSTATUS IoStatus);\n\nvoid xfuse_devredir_cb_lookup_entry(struct state_lookup *fip,\n                                    enum NTSTATUS IoStatus,\n                                    const struct file_attr *file_info);\n\nvoid xfuse_devredir_cb_setattr(struct state_setattr *fip,\n                               enum NTSTATUS IoStatus);\n\nvoid xfuse_devredir_cb_create_file(struct state_create *fip,\n                                   enum NTSTATUS IoStatus,\n                                   tui32 DeviceId, tui32 FileId);\n\nvoid xfuse_devredir_cb_open_file(struct state_open *fip,\n                                 enum NTSTATUS IoStatus,\n                                 tui32 DeviceId, tui32 FileId);\n\nvoid xfuse_devredir_cb_read_file(struct state_read *fip,\n                                 enum NTSTATUS IoStatus,\n                                 const char *buf, size_t length);\nvoid xfuse_devredir_cb_write_file(\n    struct state_write *fip,\n    enum NTSTATUS IoStatus,\n    off_t offset,\n    size_t length);\n\nvoid xfuse_devredir_cb_rmdir_or_file(struct state_remove *fip,\n                                     enum NTSTATUS IoStatus);\n\nvoid xfuse_devredir_cb_rename_file(struct state_rename *fip,\n                                   enum NTSTATUS IoStatus);\n\nvoid xfuse_devredir_cb_file_close(struct state_close *fip);\n\nvoid xfuse_devredir_cb_statfs(struct state_statfs *fip,\n                              const struct statvfs *fss,\n                              enum NTSTATUS IoStatus);\n\n/*\n * Returns true if a filesystem path lies in the FUSE filesystem\n *\n * Use to prevent deadlocks. For example, if chansrv tries to open\n * a file in the FUSE filesystem it will fail, as it will call back\n * into itself to handle the I/O\n */\nint xfuse_path_in_xfuse_fs(const char *path);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/chansrv_xfs.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * This file implements the interface in chansrv_fuse_fs.h\n */\n#include <stdlib.h>\n#include <string.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <errno.h>\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"os_calls.h\"\n#include \"log.h\"\n\n#include \"chansrv_xfs.h\"\n\n/*\n * Skip this module if FUSE is not supported. A standards-compliant C\n * translation unit must contain at least one declaration (C99:6.9), and we've\n * fulfilled that requirement by this stage.\n */\n#ifdef XRDP_FUSE\n\n#define INODE_TABLE_ALLOCATION_INITIAL     4096\n#define INODE_TABLE_ALLOCATION_GRANULARITY 100\n\n/* inum of the delete pending directory */\n#define DELETE_PENDING_ID 2\n\n/*\n * A double-linked list of inodes, sorted by inum\n *\n * The elements in the list are sorted in increasing inum order, as this\n * allows a directory enumeration to be easily resumed if elements\n * are removed or added. See xfs_readdir() for details on this.\n */\ntypedef struct xfs_inode_all XFS_INODE_ALL;\ntypedef struct xfs_list\n{\n    XFS_INODE_ALL *begin;\n    XFS_INODE_ALL *end;\n} XFS_LIST;\n\n/*\n * A complete inode, including the private elements used by the\n * implementation\n */\ntypedef struct xfs_inode_all\n{\n    XFS_INODE      pub;                /* Public elements                  */\n    /*\n     * Directory linkage elements\n     *\n     * Because we don't support hard-linking, elements can be stored in\n     * one and only one directory:-\n     */\n    struct xfs_inode_all *parent;      /* Parent inode                     */\n    struct xfs_inode_all *next;        /* Next entry in parent             */\n    struct xfs_inode_all *previous;    /* Previous entry in parent         */\n    XFS_LIST             dir;          /* Directory only - children        */\n    /*\n     * Other private elements\n     */\n    unsigned int         open_count;   /* Regular files only               */\n} XFS_INODE_ALL;\n\n\n/* the xrdp file system in memory\n *\n * inode_table    allows for O(1) access to any file based on the inum.\n *                Index 0 is unused, so we can use an inode of zero for\n *                an invalid inode, and avoid off-by-one errors index\n *                1 is our '.' directory.\n *                2 is the delete pending directory, where we can place\n *                  inodes with a positive open count which are\n *                  deleted.\n * free_list      List of free inode numbers. Allows for O(1) access to\n *                a free node, provided the free list is not empty.\n */\nstruct xfs_fs\n{\n    XFS_INODE_ALL    **inode_table;  /* a table of entries; can grow.        */\n    fuse_ino_t        *free_list;    /* Free inodes                          */\n    unsigned int inode_count;        /* Current number of inodes             */\n    unsigned int free_count;         /* Size of free_list                    */\n    unsigned int generation;         /* Changes when an inode is deleted     */\n};\n\n/* A directory handle\n *\n * inum           inum of the directory being scanned\n * generation     Generation of the inum we opened\n */\nstruct xfs_dir_handle\n{\n    fuse_ino_t  inum;\n    tui32       generation;\n};\n\n\n/*  ------------------------------------------------------------------------ */\nstatic int\ngrow_xfs(struct xfs_fs *xfs, unsigned int extra_inodes)\n{\n    int result = 0;\n    unsigned int new_count = xfs->inode_count + extra_inodes;\n    XFS_INODE_ALL **new_table;\n    fuse_ino_t *new_free_list;\n\n    new_table = (XFS_INODE_ALL **)\n                realloc(xfs->inode_table, new_count * sizeof(new_table[0]));\n    if (new_table != NULL)\n    {\n        unsigned int i;\n        for (i = xfs->inode_count ; i < new_count ; ++i)\n        {\n            new_table[i] = NULL;\n        }\n        xfs->inode_table = new_table;\n\n        new_free_list = (fuse_ino_t *)\n                        realloc(xfs->free_list,\n                                new_count * sizeof(new_free_list[0]));\n        if (new_free_list)\n        {\n            /* Add the new inodes in to the new_free_list, so the lowest\n             * number is allocated first\n             */\n            i = new_count;\n            while (i > xfs->inode_count)\n            {\n                new_free_list[xfs->free_count++] = --i;\n            }\n\n            xfs->free_list = new_free_list;\n            xfs->inode_count = new_count;\n\n            result = 1;\n        }\n    }\n\n    return result;\n}\n\n/*  ------------------------------------------------------------------------ */\nstatic void\nadd_inode_to_list(XFS_LIST *list, XFS_INODE_ALL *xino)\n{\n    fuse_ino_t inum = xino->pub.inum;\n\n    /* Find the element we need to insert after */\n    XFS_INODE_ALL *predecessor = list->end;\n    while (predecessor != NULL && predecessor->pub.inum > inum)\n    {\n        predecessor = predecessor->previous;\n    }\n\n    if (predecessor == NULL)\n    {\n        /* Inserting at the beginning */\n        /* Set up links in node */\n        xino->next = list->begin;\n        xino->previous = NULL;\n\n        /* Set up back-link to node */\n        if (list->begin == NULL)\n        {\n            /* We are the last node */\n            list->end = xino;\n        }\n        else\n        {\n            list->begin->previous = xino;\n        }\n        /* Set up forward-link to node */\n        list->begin = xino;\n    }\n    else\n    {\n        /* Set up links in node */\n        xino->next = predecessor->next;\n        xino->previous = predecessor;\n\n        /* Set up back-link to node */\n        if (predecessor->next == NULL)\n        {\n            list->end = xino;\n        }\n        else\n        {\n            predecessor->next->previous = xino;\n        }\n        /* Set up forward-link to node */\n        predecessor->next = xino;\n    }\n}\n\n/*  ------------------------------------------------------------------------ */\nstatic void\nremove_inode_from_list(XFS_LIST *list, XFS_INODE_ALL *xino)\n{\n    if (xino->previous == NULL)\n    {\n        /* First element */\n        list->begin = xino->next;\n    }\n    else\n    {\n        xino->previous->next = xino->next;\n    }\n\n    if (xino->next == NULL)\n    {\n        /* Last element */\n        list->end = xino->previous;\n    }\n    else\n    {\n        xino->next->previous = xino->previous;\n    }\n\n}\n\n/*  ------------------------------------------------------------------------ */\nstatic void\nlink_inode_into_directory_node(XFS_INODE_ALL *dinode, XFS_INODE_ALL *xino)\n{\n    xino->parent = dinode;\n    add_inode_to_list(&dinode->dir, xino);\n}\n\n/*  ------------------------------------------------------------------------ */\nstatic void\nunlink_inode_from_parent(XFS_INODE_ALL *xino)\n{\n    remove_inode_from_list(&xino->parent->dir, xino);\n\n    xino->next = NULL;\n    xino->previous = NULL;\n    xino->parent = NULL;\n}\n\n/*  ------------------------------------------------------------------------ */\nstruct xfs_fs *\nxfs_create_xfs_fs(mode_t umask, uid_t uid, gid_t gid)\n{\n    struct xfs_fs *xfs = g_new0(struct xfs_fs, 1);\n    XFS_INODE_ALL *xino1 = NULL;\n    XFS_INODE_ALL *xino2 = NULL;\n    char *xino1_name = NULL;\n    char *xino2_name = NULL;\n\n    if (xfs != NULL)\n    {\n        xfs->inode_count = 0;\n        xfs->free_count = 0;\n        xfs->inode_table = NULL;\n        xfs->free_list   = NULL;\n        xfs->generation = 1;\n\n        /* xfs->inode_table check should be superfluous here, but it\n         * prevents cppcheck 2.2/2.3 generating a false positive nullPointer\n         * report */\n        if (!grow_xfs(xfs, INODE_TABLE_ALLOCATION_INITIAL) ||\n                xfs->inode_table == NULL ||\n                (xino1 = g_new0(XFS_INODE_ALL, 1)) == NULL ||\n                (xino2 = g_new0(XFS_INODE_ALL, 1)) == NULL ||\n                (xino1_name = strdup(\".\")) == NULL ||\n                (xino2_name = strdup(\".delete-pending\")) == NULL ||\n                // This keeps Coverity happy (see below)\n                xfs->free_count < 3)\n        {\n            free(xino1);\n            free(xino2);\n            free(xino1_name);\n            free(xino2_name);\n            xfs_delete_xfs_fs(xfs);\n            xfs = NULL;\n        }\n        else\n        {\n            /*\n             * The use of grow_xfs to allocate the inode table will make\n             * inodes 0,  1 (FUSE_ROOT_ID) and 2 (DELETE_PENDING_ID) the first\n             * available free inodes. We can ignore these */\n            xfs->free_count -= 3;\n\n            xfs->inode_table[0] = NULL;\n            xfs->inode_table[FUSE_ROOT_ID] = xino1;\n            xfs->inode_table[DELETE_PENDING_ID] = xino2;\n\n            xino1->pub.inum = FUSE_ROOT_ID;\n            xino1->pub.mode = (S_IFDIR | 0777) & ~umask;\n            xino1->pub.uid = uid;\n            xino1->pub.gid = gid;\n            xino1->pub.size = 0;\n            xino1->pub.atime = time(0);\n            xino1->pub.mtime = xino1->pub.atime;\n            xino1->pub.ctime = xino1->pub.atime;\n            xino1->pub.name = xino1_name;\n            xino1->pub.generation = xfs->generation;\n            xino1->pub.is_redirected = 0;\n            xino1->pub.device_id = 0;\n\n            /*\n             * FUSE_ROOT_ID has no parent rather than being a parent\n             * of itself. This is intentional */\n            xino1->parent = NULL;\n            xino1->next = NULL;\n            xino1->previous = NULL;\n            xino1->dir.begin = NULL;\n            xino1->dir.end = NULL;\n\n            xino2->pub.inum = DELETE_PENDING_ID;\n            xino2->pub.mode = (S_IFDIR | 0777) & ~umask;\n            xino2->pub.uid = uid;\n            xino2->pub.gid = gid;\n            xino2->pub.size = 0;\n            xino2->pub.atime = time(0);\n            xino2->pub.mtime = xino2->pub.atime;\n            xino2->pub.ctime = xino2->pub.atime;\n            xino2->pub.name = xino2_name;\n            xino2->pub.generation = xfs->generation;\n            xino2->pub.is_redirected = 0;\n            xino2->pub.device_id = 0;\n\n            xino2->parent = NULL;\n            xino2->next = NULL;\n            xino2->previous = NULL;\n            xino2->dir.begin = NULL;\n            xino2->dir.end = NULL;\n            /*\n             * Uncomment this line to make the .delete-pending\n             * directory visible to the user in the root\n             */\n            /* link_inode_into_directory_node(xino1, xino2); */\n        }\n    }\n\n    return xfs;\n}\n\n/*  ------------------------------------------------------------------------ */\nstatic void\nxfs_free_inode(XFS_INODE_ALL *xino)\n{\n    if (xino != NULL)\n    {\n        free(xino->pub.name);\n        free(xino);\n    }\n}\n\n/*  ------------------------------------------------------------------------ */\nvoid\nxfs_delete_xfs_fs(struct xfs_fs *xfs)\n{\n    if (xfs == NULL)\n    {\n        return;\n    }\n\n    if (xfs->inode_table != NULL)\n    {\n        size_t i;\n        for (i = 0 ; i < xfs->inode_count; ++i)\n        {\n            xfs_free_inode(xfs->inode_table[i]);\n        }\n    }\n    free(xfs->inode_table);\n    free(xfs->free_list);\n    free(xfs);\n}\n\n/*  ------------------------------------------------------------------------ */\nXFS_INODE *\nxfs_add_entry(struct xfs_fs *xfs, fuse_ino_t parent_inum,\n              const char *name, mode_t mode)\n{\n    XFS_INODE *result = NULL;\n    XFS_INODE_ALL *parent = NULL;\n\n    /* Checks:-\n     * 1) the parent exists (and is a directory)\n     * 2) the caller is not inserting into the .delete-pending directory,\n     * 3) Name's not too long\n     * 4) Entry does not already exist\n     */\n    if (parent_inum < xfs->inode_count &&\n            ((parent = xfs->inode_table[parent_inum]) != NULL) &&\n            (parent->pub.mode & S_IFDIR) != 0 &&\n            parent_inum != DELETE_PENDING_ID &&\n            strlen(name) <= XFS_MAXFILENAMELEN &&\n            !xfs_lookup_in_dir(xfs, parent_inum, name))\n    {\n        /* Sanitise the mode so one-and-only-one of S_IFDIR and\n         * S_IFREG is set */\n        if ((mode & S_IFDIR) != 0)\n        {\n            mode = (mode & 0777) | S_IFDIR;\n        }\n        else\n        {\n            mode = (mode & 0777) | S_IFREG;\n        }\n\n        /* Space for a new entry? */\n        if (xfs->free_count > 0 ||\n                grow_xfs(xfs, INODE_TABLE_ALLOCATION_GRANULARITY))\n        {\n            XFS_INODE_ALL *xino = g_new0(XFS_INODE_ALL, 1);\n            char *cpyname = strdup(name);\n            if (xino == NULL || cpyname == NULL)\n            {\n                free(xino);\n                free(cpyname);\n            }\n            else\n            {\n                fuse_ino_t inum = xfs->free_list[--xfs->free_count];\n                if (xfs->inode_table[inum] != NULL)\n                {\n                    LOG_DEVEL(LOG_LEVEL_ERROR, \"Unexpected non-NULL value in inode table \"\n                              \"entry %ld\", inum);\n                }\n                xfs->inode_table[inum] = xino;\n                xino->pub.inum = inum;\n                xino->pub.mode = mode;\n                xino->pub.uid = parent->pub.uid;\n                xino->pub.gid = parent->pub.gid;\n                if (mode & S_IFDIR)\n                {\n                    xino->pub.size = 4096;\n                }\n                else\n                {\n                    xino->pub.size = 0;\n                }\n                xino->pub.atime = time(0);\n                xino->pub.mtime = xino->pub.atime;\n                xino->pub.ctime = xino->pub.atime;\n                xino->pub.name = cpyname;\n                xino->pub.generation = xfs->generation;\n                xino->pub.is_redirected = parent->pub.is_redirected;\n                xino->pub.device_id = parent->pub.device_id;\n                xino->pub.lindex = 0;\n\n                xino->parent = NULL;\n                xino->next = NULL;\n                xino->previous = NULL;\n                link_inode_into_directory_node(parent, xino);\n                result = &xino->pub;\n            }\n        }\n    }\n\n    return result;\n}\n\n/*  ------------------------------------------------------------------------ */\nvoid\nxfs_remove_directory_contents(struct xfs_fs *xfs, fuse_ino_t inum)\n{\n    XFS_INODE_ALL *xino =  NULL;\n\n    if (inum < xfs->inode_count &&\n            ((xino = xfs->inode_table[inum]) != NULL) &&\n            ((xino->pub.mode & S_IFDIR) != 0))\n    {\n        XFS_INODE_ALL *e;\n        while ((e = xino->dir.end) != NULL)\n        {\n            xfs_remove_entry(xfs, e->pub.inum);\n        }\n    }\n}\n\n/*  ------------------------------------------------------------------------ */\nvoid\nxfs_remove_entry(struct xfs_fs *xfs, fuse_ino_t inum)\n{\n    XFS_INODE_ALL *xino =  NULL;\n\n    if (inum < xfs->inode_count &&\n            ((xino = xfs->inode_table[inum]) != NULL))\n    {\n        if ((xino->pub.mode & S_IFDIR) != 0)\n        {\n            xfs_remove_directory_contents(xfs, inum);\n        }\n\n        unlink_inode_from_parent(xino);\n        if ((xino->pub.mode & S_IFREG) != 0 && xino->open_count > 0)\n        {\n            link_inode_into_directory_node(\n                xfs->inode_table[DELETE_PENDING_ID], xino);\n        }\n        else\n        {\n            xfs->free_list[xfs->free_count++] = inum;\n            xfs->inode_table[inum] = NULL;\n            /*\n             * Bump the generation when we return an inum to the free list,\n             * so that the caller can distinguish re-uses of the same inum.\n             */\n            ++xfs->generation;\n            xfs_free_inode(xino);\n        }\n    }\n}\n\n/*  ------------------------------------------------------------------------ */\nXFS_INODE *\nxfs_get(struct xfs_fs *xfs, fuse_ino_t inum)\n{\n    return (inum < xfs->inode_count) ? &xfs->inode_table[inum]->pub : NULL;\n}\n\n/*  ------------------------------------------------------------------------ */\nchar *\nxfs_get_full_path(struct xfs_fs *xfs, fuse_ino_t inum)\n{\n    char *result = NULL;\n    XFS_INODE_ALL *xino =  NULL;\n\n    if (inum < xfs->inode_count &&\n            ((xino = xfs->inode_table[inum]) != NULL))\n    {\n        if (xino->pub.inum == FUSE_ROOT_ID)\n        {\n            return strdup(\"/\");\n        }\n        else\n        {\n            /*\n             * Add up the lengths of all the names up to the root,\n             * allowing one extra char for a '/' prefix for each element\n             */\n            size_t len = 0;\n            XFS_INODE_ALL *p;\n            for (p = xino ; p && p->pub.inum != FUSE_ROOT_ID ; p = p->parent)\n            {\n                len += strlen(p->pub.name);\n                ++len; /* Allow for '/' prefix */\n            }\n\n            result = (char *) malloc(len + 1);\n            if (result != NULL)\n            {\n                /* Construct the path from the end */\n                char *end = result + len;\n                *end = '\\0';\n\n                for (p = xino ; p && p->pub.inum != FUSE_ROOT_ID ; p = p->parent)\n                {\n                    len = strlen(p->pub.name);\n                    end -= (len + 1);\n                    *end = '/';\n                    memcpy(end + 1, p->pub.name, len);\n                }\n            }\n        }\n    }\n\n    return result;\n}\n\n/*  ------------------------------------------------------------------------ */\nXFS_INODE *\nxfs_lookup_in_dir(struct xfs_fs *xfs, fuse_ino_t inum, const char *name)\n{\n    XFS_INODE_ALL *xino;\n    XFS_INODE *result = NULL;\n    if (inum < xfs->inode_count &&\n            ((xino = xfs->inode_table[inum]) != NULL) &&\n            (xino->pub.mode & S_IFDIR) != 0)\n    {\n        XFS_INODE_ALL *p;\n        for (p = xino->dir.begin ; p != NULL; p = p->next)\n        {\n            if (strcmp(p->pub.name, name) == 0)\n            {\n                result = &p->pub;\n                break;\n            }\n        }\n    }\n\n    return result;\n}\n\n/*  ------------------------------------------------------------------------ */\nint\nxfs_is_dir_empty(struct xfs_fs *xfs, fuse_ino_t inum)\n{\n    XFS_INODE_ALL *xino =  NULL;\n    int result = 0;\n\n    if (inum < xfs->inode_count &&\n            ((xino = xfs->inode_table[inum]) != NULL) &&\n            (xino->pub.mode & S_IFDIR) != 0)\n    {\n        result = (xino->dir.begin == NULL);\n    }\n\n    return result;\n}\n\n/*  ------------------------------------------------------------------------ */\nunsigned int\nxfs_is_under(struct xfs_fs *xfs, fuse_ino_t dir, fuse_ino_t entry)\n{\n    unsigned int result = 0;\n\n    XFS_INODE_ALL *dxino =  NULL;\n    XFS_INODE_ALL *exino =  NULL;\n\n    if (dir < xfs->inode_count &&\n            ((dxino = xfs->inode_table[dir]) != NULL) &&\n            (dxino->pub.mode & S_IFDIR) != 0 &&\n            entry < xfs->inode_count &&\n            ((exino = xfs->inode_table[entry]) != NULL))\n    {\n        unsigned int count = 0;\n\n        while (exino != NULL && exino != dxino)\n        {\n            ++count;\n            exino = exino->parent;\n        }\n\n        if (exino != NULL)\n        {\n            result = count;\n        }\n    }\n\n    return result;\n}\n\n/*  ------------------------------------------------------------------------ */\nstruct xfs_dir_handle *\nxfs_opendir(struct xfs_fs *xfs, fuse_ino_t dir)\n{\n    XFS_INODE_ALL *xino =  NULL;\n    struct xfs_dir_handle *result = NULL;\n\n    if (dir < xfs->inode_count &&\n            ((xino = xfs->inode_table[dir]) != NULL) &&\n            (xino->pub.mode & S_IFDIR) != 0)\n    {\n        result = g_new0(struct xfs_dir_handle, 1);\n        if (result)\n        {\n            result->inum = xino->pub.inum;\n            result->generation = xino->pub.generation;\n        }\n    }\n\n    return result;\n}\n\n/*  ------------------------------------------------------------------------ */\nXFS_INODE *\nxfs_readdir(struct xfs_fs *xfs, struct xfs_dir_handle *handle, off_t *off)\n{\n    XFS_INODE_ALL *result = NULL;\n    XFS_INODE_ALL *dxino = NULL;\n    XFS_INODE_ALL *xino = NULL;\n\n    /* Check the directory is still valid */\n    if (handle->inum < xfs->inode_count &&\n            ((dxino = xfs->inode_table[handle->inum]) != NULL) &&\n            (dxino->pub.mode & S_IFDIR) != 0 &&\n            handle->generation == dxino->pub.generation)\n    {\n        fuse_ino_t inum;\n\n        if (*off == (off_t) -1)\n        {\n            /* We're at the end already */\n        }\n        else if ((inum = *off) == 0)\n        {\n            /* First call */\n            result = dxino->dir.begin;\n        }\n        else if (inum < xfs->inode_count &&\n                 (xino = xfs->inode_table[inum]) != 0 &&\n                 xino->parent == dxino)\n        {\n            /* The node we're pointing to is still valid */\n            result = xino;\n        }\n        else\n        {\n            /*\n             * The file we wanted has been pulled out from under us.\n             * We will look forward in the inode table to try to\n             * discover the next inode in the directory. Because\n             * files are stored in inode order, this guarantees\n             * we'll meet POSIX requirements.\n             */\n            for (inum = inum + 1 ; inum < xfs->inode_count ; ++inum)\n            {\n                if ((xino = xfs->inode_table[inum]) != 0 &&\n                        xino->parent == dxino)\n                {\n                    result = xino;\n                    break;\n                }\n            }\n        }\n    }\n\n    /* Update the offset */\n    if (result == NULL || result->next == NULL)\n    {\n        /* We're done */\n        *off = (off_t) -1;\n    }\n    else\n    {\n        *off = (off_t)result->next->pub.inum;\n    }\n\n    /* Caller only sees public interface to the result */\n    return (result) ? &result->pub : NULL;\n}\n\n/*  ------------------------------------------------------------------------ */\nvoid\nxfs_closedir(struct xfs_fs *xfs, struct xfs_dir_handle *handle)\n{\n    free(handle);\n}\n\n/*  ------------------------------------------------------------------------ */\nvoid\nxfs_increment_file_open_count(struct xfs_fs *xfs, fuse_ino_t inum)\n{\n    XFS_INODE_ALL *xino;\n    if (inum < xfs->inode_count &&\n            ((xino = xfs->inode_table[inum]) != NULL) &&\n            (xino->pub.mode & S_IFREG) != 0)\n    {\n        ++xino->open_count;\n    }\n}\n\n/*  ------------------------------------------------------------------------ */\nvoid\nxfs_decrement_file_open_count(struct xfs_fs *xfs, fuse_ino_t inum)\n{\n    XFS_INODE_ALL *xino;\n    if (inum < xfs->inode_count &&\n            ((xino = xfs->inode_table[inum]) != NULL) &&\n            (xino->pub.mode & S_IFREG) != 0)\n    {\n        if (xino->open_count > 0)\n        {\n            --xino->open_count;\n        }\n\n        if (xino->open_count == 0 &&\n                xino->parent == xfs->inode_table[DELETE_PENDING_ID])\n        {\n            /* We can get rid of this one now */\n            xfs_remove_entry(xfs, inum);\n        }\n    }\n}\n\n/*  ------------------------------------------------------------------------ */\nunsigned int\nxfs_get_file_open_count(struct xfs_fs *xfs, fuse_ino_t inum)\n{\n    unsigned int result = 0;\n    XFS_INODE_ALL *xino;\n    if (inum < xfs->inode_count &&\n            ((xino = xfs->inode_table[inum]) != NULL) &&\n            (xino->pub.mode & S_IFREG) != 0)\n    {\n        result = xino->open_count;\n    }\n\n    return result;\n}\n\n/*  ------------------------------------------------------------------------ */\nvoid\nxfs_delete_redirected_entries_with_device_id(struct xfs_fs *xfs,\n        tui32 device_id)\n{\n    fuse_ino_t inum;\n    XFS_INODE_ALL *xino;\n\n    /* Using xfs_remove_entry() is convenient, but it recurses\n     * in to directories. To make sure all entries are removed, set the\n     * open_count of all affected files to 0 first\n     */\n    for (inum = FUSE_ROOT_ID; inum < xfs->inode_count; ++inum)\n    {\n        if ((xino = xfs->inode_table[inum]) != NULL &&\n                xino->pub.is_redirected != 0 &&\n                xino->pub.device_id == device_id &&\n                (xino->pub.mode & S_IFREG) != 0)\n        {\n            xino->open_count = 0;\n        }\n    }\n\n    /* Now we can be sure everything will be deleted correctly */\n    for (inum = FUSE_ROOT_ID; inum < xfs->inode_count; ++inum)\n    {\n        if ((xino = xfs->inode_table[inum]) != NULL &&\n                xino->pub.is_redirected != 0 &&\n                xino->pub.device_id == device_id)\n        {\n            xfs_remove_entry(xfs, xino->pub.inum);\n        }\n    }\n}\n\n/*  ------------------------------------------------------------------------ */\nint\nxfs_check_move_entry(struct xfs_fs *xfs, fuse_ino_t inum,\n                     fuse_ino_t new_parent_inum, const char *name)\n{\n    XFS_INODE_ALL *xino;\n    XFS_INODE_ALL *parent;\n\n    return\n        (strlen(name) <= XFS_MAXFILENAMELEN &&\n         inum < xfs->inode_count &&\n         ((xino = xfs->inode_table[inum]) != NULL) &&\n         new_parent_inum != DELETE_PENDING_ID &&\n         new_parent_inum < xfs->inode_count &&\n         ((parent = xfs->inode_table[new_parent_inum]) != NULL) &&\n         (parent->pub.mode & S_IFDIR) != 0 &&\n         xfs_is_under(xfs, inum, new_parent_inum) == 0);\n}\n\n/*  ------------------------------------------------------------------------ */\nint\nxfs_move_entry(struct xfs_fs *xfs, fuse_ino_t inum,\n               fuse_ino_t new_parent_inum, const char *name)\n{\n    int result = EINVAL;\n    XFS_INODE_ALL *xino;\n    XFS_INODE_ALL *parent;\n    XFS_INODE *dest;\n    char *cpyname;\n\n    /* Copy the new name. We'll either end up freeing it, or we'll\n     * use it to replace something else (which gets freed instead) */\n    if ((cpyname  = strdup(name)) == NULL)\n    {\n        result = ENOMEM;\n    }\n    else if (xfs_check_move_entry(xfs, inum, new_parent_inum, name))\n    {\n        xino = xfs->inode_table[inum];\n        parent = xfs->inode_table[new_parent_inum];\n\n        if (xino->parent != parent)\n        {\n            /* We're moving between directories */\n\n            /* Does the target name already exist in the destination? */\n            if ((dest = xfs_lookup_in_dir(xfs, new_parent_inum, name)) != NULL)\n            {\n                xfs_remove_entry(xfs, dest->inum);\n            }\n\n            unlink_inode_from_parent(xino);\n            link_inode_into_directory_node(parent, xino);\n\n            /* Swap the copy name and the inode name so we end up with the\n             * right name, and the old one gets freed */\n            char *t = xino->pub.name;\n            xino->pub.name = cpyname;\n            cpyname = t;\n        }\n        else if (strcmp(xino->pub.name, name) != 0)\n        {\n            /* Same directory, but name has changed */\n            if ((dest = xfs_lookup_in_dir(xfs, new_parent_inum, name)) != NULL)\n            {\n                /* Name collision - remove destination entry */\n                xfs_remove_entry(xfs, dest->inum);\n            }\n\n            /* Swap the copy name and the inode name so we end up with the\n             * right name, and the old one gets freed */\n            char *t = xino->pub.name;\n            xino->pub.name = cpyname;\n            cpyname = t;\n        }\n        result = 0;\n    }\n    free (cpyname);\n\n    return result;\n}\n#endif  /* XRDP_FUSE */\n"
  },
  {
    "path": "sesman/chansrv/chansrv_xfs.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * This file is the interface to the FUSE file system used by\n * chansrv\n */\n\n#ifndef _CHANSRV_XFS\n#define _CHANSRV_XFS\n\n/* Maximum length of filename supported (in bytes).\n * This is a sensible limit to a filename length. It is not used by\n * this module to allocate long-lived storage, so it can be increased\n * if necessary */\n#define XFS_MAXFILENAMELEN 1023\n\n/* Skip the rest of this include if there's no FUSE */\n#ifdef XRDP_FUSE\n\n#include <stddef.h>\n#include <fuse_lowlevel.h>\n#include <time.h>\n\n#include \"arch.h\"\n\n/*\n * Incomplete types for the public interface\n */\nstruct xfs_fs;\nstruct xfs_dir_handle;\n\n/**\n * Describe an inode in the XFS filesystem\n */\ntypedef struct xfs_inode\n{\n    fuse_ino_t      inum;              /* File serial number.               */\n    mode_t          mode;              /* File mode.                        */\n    uid_t           uid;               /* User ID of the file's owner.      */\n    gid_t           gid;               /* Group ID of the file's group.     */\n    off_t           size;              /* Size of file, in bytes.           */\n    time_t          atime;             /* Time of last access.              */\n    time_t          mtime;             /* Time of last modification.        */\n    time_t          ctime;             /* Time of last status change.       */\n    char            *name;             /* Short name (dynamically allocated) */\n    tui32           generation;        /* Changes if inode is reused        */\n    char            is_redirected;     /* file is on redirected device      */\n    tui32           device_id;         /* device ID of redirected device    */\n    int             lindex;            /* used in clipboard operations      */\n} XFS_INODE;\n\n/*\n * Create a new filesystem instance\n *\n * @param   umask Umask to apply to initial data structures\n * @param   uid Owner UID for initial root directory\n * @param   gid Owner GID for initial root directory\n * @return  Pointer to instance, or NULL if no memory\n */\nstruct xfs_fs *\nxfs_create_xfs_fs(mode_t umask, uid_t uid, gid_t gid);\n\n/*\n * Delete a filesystem instance\n *\n * @param xfs Filesystem instance\n */\nvoid\nxfs_delete_xfs_fs(struct xfs_fs *xfs);\n\n/*\n * Add an entry to the filesystem\n *\n * The returned element has default values inherited from the parent\n *\n * The specified mode is sanitised in that:-\n * - Bits other than the lowest nine permissions bits, the directory\n *   bit (S_IFDIR) and the regular bit (S_IFREG) are cleared.\n * - S_IFREG is cleared if S_IFDIR is set\n * - S_IFREG is set if neither S_IFDIR or S_IFREG is set\n *\n * NULL is returned for one of the following conditions:-\n * - the parent does not exist\n * - the parent is not a directory\n * - the name length exceeds XFS_MAXFILENAMELEN\n * - the entry already exists\n * - memory is exhausted.\n *\n * @param xfs  filesystem instance\n * @param parent_inode parent inode\n * @param name   Name of entry\n * @param mode   Initial mode for file.\n * @return inode, or NULL\n */\nXFS_INODE *\nxfs_add_entry(struct xfs_fs *xfs, fuse_ino_t parent_inum,\n              const char *name, mode_t mode);\n\n/*\n * Delete the contents of a directory\n *\n * If normal files are opened when they are deleted, the inode is not\n * released until the open count goes to zero.\n *\n * @param xfs  filesystem instance\n * @param inode Reference to entry to delete\n *\n */\nvoid\nxfs_remove_directory_contents(struct xfs_fs *xfs, fuse_ino_t inum);\n\n/*\n * Delete an entry from the filesystem\n *\n * If normal files are opened when they are deleted, the inode is not\n * released until the open count goes to zero.\n *\n * For directories, the contents are removed first.\n *\n * @param xfs  filesystem instance\n * @param inode Reference to entry to delete\n *\n */\nvoid\nxfs_remove_entry(struct xfs_fs *xfs, fuse_ino_t inum);\n\n/*\n * Get an XFS_INODE for an inum\n *\n * @param xfs  filesystem instance\n * @param inum Inumber\n * @return Pointer to XFS_INODE\n */\nXFS_INODE *\nxfs_get(struct xfs_fs *xfs, fuse_ino_t inum);\n\n/*\n * Get the full path for an inum\n *\n * The path is dynamically allocated, and must be freed after use\n *\n * @param xfs  filesystem instance\n * @param inum Inumber to get path for\n * @return Full path (free after use)\n */\nchar *\nxfs_get_full_path(struct xfs_fs *xfs, fuse_ino_t inum);\n\n/*\n * Lookup a file in a directory\n *\n * @param xfs  filesystem instance\n * @param inum Inumber of the directory\n * @param name Name of the file to lookup\n * @return Pointer to XFS_INODE if found\n */\nXFS_INODE *\nxfs_lookup_in_dir(struct xfs_fs *xfs, fuse_ino_t inum, const char *name);\n\n/*\n * Inquires as to whether a directory is empty.\n *\n * The caller must check that the inum is actually a directory, or\n * the result is undefined.\n *\n * @param xfs  filesystem instance\n * @param inum Inumber of the directory\n * @return True if the directory is empty\n */\nint\nxfs_is_dir_empty(struct xfs_fs *xfs, fuse_ino_t inum);\n\n/*\n * Inquires as to whether an entry is under a directory.\n *\n * This can be used to check for invalid renames, where we try to\n * rename a directory into one of its sub-directories.\n *\n * Returned value means one of the following:-\n * 0   Entry is not related to the directory\n * 1   Entry is an immediate member of the directory\n * 2.. Entry is a few levels below the directory\n *\n * @param xfs  filesystem instance\n * @param dir  Inumber of the directory\n * @param entry Inumber of the entry\n * @return Nesting count of entry in the directory, or 0 for\n *         no nesting\n */\nunsigned int\nxfs_is_under(struct xfs_fs *xfs, fuse_ino_t dir, fuse_ino_t entry);\n\n/*\n * Opens a directory for reading\n *\n * @param xfs  filesystem instance\n * @param dir  Inumber of the directory\n * @return handle to be passed to xfs_readdir() and xfs_closedir()\n */\nstruct xfs_dir_handle *\nxfs_opendir(struct xfs_fs *xfs, fuse_ino_t dir);\n\n/*\n * Gets the next entry from a directory\n *\n * This function is safe to call while the filesystem is being modified.\n * Whether files added or removed from the directory in question are\n * returned or not is unspecified by this interface.\n *\n * @param xfs  filesystem instance\n * @param handle Handle from xfs_opendir\n * @param off    Offset (by reference). Pass in zero to get the first\n *               entry. After the call, the offset is updated so that\n *               the next call gets the next entry.\n *\n * @return pointer to details of file entry, or NULL if no more\n *         entries are available.\n */\nXFS_INODE *\nxfs_readdir(struct xfs_fs *xfs, struct xfs_dir_handle *handle, off_t *off);\n\n\n/*\n * Closes a directory opened for reading\n *\n * @param xfs  filesystem instance\n * @param handle Earlier result of readdir() call\n */\nvoid\nxfs_closedir(struct xfs_fs *xfs, struct xfs_dir_handle *handle);\n\n/*\n * Increment the file open count\n *\n * The file open count is used to be sure when an entry can be deleted from\n * the data structures. It allows us to remove an entry while still retaining\n * enough state to manage the file\n *\n * This call is only necessary for regular files - not directories\n *\n * @param xfs  filesystem instance\n * @param inum File to increment the count of\n */\nvoid\nxfs_increment_file_open_count(struct xfs_fs *xfs, fuse_ino_t inum);\n\n/*\n * Decrement the file open count\n *\n * This call will ensure that deleted inodes are cleared up at the appropriate\n * time.\n *\n * This call is only necessary for regular files - not directories\n *\n * @param xfs  filesystem instance\n * @param inum File to decrement the count of\n */\nvoid\nxfs_decrement_file_open_count(struct xfs_fs *xfs, fuse_ino_t inum);\n\n/*\n * Return the file open count for a regular file\n */\nunsigned int\nxfs_get_file_open_count(struct xfs_fs *xfs, fuse_ino_t inum);\n\n/*\n * Deletes all redirected entries with the matching device id\n *\n * Files are deleted even if they are open\n *\n * @param device_id Device ID\n */\nvoid\nxfs_delete_redirected_entries_with_device_id(struct xfs_fs *xfs,\n        tui32 device_id);\n\n/*\n * Check an entry move will be successful\n *\n * A move will fail if:-\n * - Any of the parameters are invalid\n * - if the entry is a directory, and the new parent is below the\n *   entry in the existing hierarchy.\n *\n * @param xfs  filesystem instance\n * @param inum Inumber of entry\n * @param new_parent New parent\n * @param name New name\n *\n * @result != 0 if all looks OK\n */\nint\nxfs_check_move_entry(struct xfs_fs *xfs, fuse_ino_t inum,\n                     fuse_ino_t new_parent_inum, const char *name);\n\n\n/*\n * Move (rename) an entry\n *\n * @param xfs  filesystem instance\n * @param inum Inumber of entry\n * @param new_parent New parent\n * @param name New name\n *\n * @result 0, or a suitable errno value.\n */\nint\nxfs_move_entry(struct xfs_fs *xfs, fuse_ino_t inum,\n               fuse_ino_t new_parent_inum, const char *name);\n\n#endif /*  XRDP_FUSE   */\n#endif /* _CHANSRV_XFS */\n"
  },
  {
    "path": "sesman/chansrv/clipboard-notes.txt",
    "content": "LOG_LEVEL\n\ndolphin\nclipboard_event_selection_owner_notify:\nclipboard_event_selection_notify: 0x1f7 text/uri-list\nclipboard_event_selection_notify: 0x1f8 text/x-moz-url\nclipboard_event_selection_notify: 0x1f3 text/plain\nclipboard_event_selection_notify: 0xee UTF8_STRING\nclipboard_event_selection_notify: 0x1f STRING\nclipboard_event_selection_notify: 0x1a1 TEXT\nclipboard_event_selection_notify: 0x1a0 COMPOUND_TEXT\nclipboard_event_selection_notify: 0x1fa application/x-qiconlist\nclipboard_event_selection_notify: 0xec TARGETS\nclipboard_event_selection_notify: 0xed MULTIPLE\nclipboard_event_selection_notify: 0xeb TIMESTAMP\nclipboard_event_selection_notify: 0x183 SAVE_TARGETS\n\nthunar\nclipboard_event_selection_owner_notify:\nclipboard_event_selection_notify: 0xeb TIMESTAMP\nclipboard_event_selection_notify: 0xec TARGETS\nclipboard_event_selection_notify: 0xed MULTIPLE\nclipboard_event_selection_notify: 0x204 x-special/gnome-copied-files\nclipboard_event_selection_notify: 0xee UTF8_STRING\nclipboard_data_in:\nclipboard_data_in: 3\n\npcmanfm\nclipboard_event_selection_owner_notify:\nclipboard_event_selection_notify: 0xeb TIMESTAMP\nclipboard_event_selection_notify: 0xec TARGETS\nclipboard_event_selection_notify: 0xed MULTIPLE\nclipboard_event_selection_notify: 0x1f7 text/uri-list\nclipboard_event_selection_notify: 0x204 x-special/gnome-copied-files\nclipboard_event_selection_notify: 0x1f9 application/x-kde-cutselection\nclipboard_event_selection_notify: 0xee UTF8_STRING\n\nCAJA\nclipboard_event_selection_notify: 0x141 TIMESTAMP\nclipboard_event_selection_notify: 0x130 TARGETS\nclipboard_event_selection_notify: 0x142 MULTIPLE\nclipboard_event_selection_notify: 0x143 x-special/mate-copied-files\nclipboard_event_selection_notify: 0x144 text/uri-list\nclipboard_event_selection_notify: 0x0 (null)\nclipboard_event_selection_notify: 0x25 WM_ICON_NAME\nclipboard_event_selection_notify: 0x47524154 (null)\nclipboard_event_selection_notify: 0x50000078 (null)\nclipboard_event_selection_notify: 0x0 (null)\nclipboard_event_selection_notify: 0x25 WM_ICON_NAME\n\nnautilus\nclipboard_event_selection_notify: 0x141 TIMESTAMP\nclipboard_event_selection_notify: 0x130 TARGETS\nclipboard_event_selection_notify: 0x142 MULTIPLE\nclipboard_event_selection_notify: 0x154 x-special/gnome-copied-files\nclipboard_event_selection_notify: 0x144 text/uri-list\nclipboard_event_selection_notify: 0xfb UTF8_STRING\nclipboard_event_selection_notify: 0x0 (null)\nclipboard_event_selection_notify: 0x25 WM_ICON_NAME\nclipboard_event_selection_notify: 0x47524154 (null)\nclipboard_event_selection_notify: 0x50000078 (null)\nclipboard_event_selection_notify: 0x0 (null)\nclipboard_event_selection_notify: 0x25 WM_ICON_NAME\n"
  },
  {
    "path": "sesman/chansrv/clipboard.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2009-2012\n * Copyright (C) Laxmikant Rashinkar 2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/*\n   for help see\n   http://tronche.com/gui/x/icccm/sec-2.html#s-2\n   .../kde/kdebase/workspace/klipper/clipboardpoll.cpp\n\n  Revision:\n  Aug 05, 2012:\n    Laxmikant Rashinkar (LK dot Rashinkar at gmail.com)\n    added clipboard support for BMP images\n\n  http://msdn.microsoft.com/en-us/library/cc241066%28v=prot.20%29.aspx\n\n*/\n\n/*\nTARGETS\nMULTIPLE\nimage/tiff\nimage/jpeg\nimage/x-MS-bmp\nimage/x-bmp\nimage/bmp\nimage/png\nSAVE_TARGETS\nTIMESTAMP\n\nwininfo - show window info\nxlsatoms - dump atoms\n\ndolphin 1.4 KDE 4.4.5 (debian 6) copy one file\ntext/uri-list\ntext/x-moz-url\ntext/plain\nUTF8_STRING\nSTRING\nTEXT\nCOMPOUND_TEXT\napplication/x-qiconlist\nTARGETS\nMULTIPLE\nTIMESTAMP\nSAVE_TARGETS\n\ndolphin 1.6.1 KDE 4.6.5 (kubuntu 11.04) copy one file\ntext/uri-list\ntext/x-moz-url\ntext/plain\nUTF8_STRING\nSTRING\nTEXT\nCOMPOUND_TEXT\napplication/x-qiconlist\nTARGETS\nMULTIPLE\nTIMESTAMP\nSAVE_TARGETS\n\nkolourpaint 4.4.5 KDE 4.4.5 copy image area\napplication/x-kolourpaint-selection-400\napplication/x-qt-image\nimage/png\nimage/bw\nimage/eps\nimage/epsf\nimage/epsi\nimage/pcx\nimage/rgb\nimage/rgba\nimage/sgi\nimage/tga\nimage/bmp\nimage/ico\nimage/jp2\nimage/jpeg\nimage/jpg\nimage/ppm\nPIXMAP\nimage/tif\nimage/tiff\nimage/xbm\nimage/xpm\nimage/xv\nTARGETS\nMULTIPLE\nTIMESTAMP\nSAVE_TARGETS\n\nkate 3.4.5 KDE 4.4.5 copy text\ntext/plain\nUTF8_STRING\nSTRING\nTEXT\nCOMPOUND_TEXT\nTARGETS\nMULTIPLE\nTIMESTAMP\nSAVE_TARGETS\n\ngimp 2.6.10 copy image area\nTIMESTAMP\nTARGETS\nMULTIPLE\nSAVE_TARGETS\nimage/png\nimage/bmp\nimage/x-bmp\nimage/x-MS-bmp\nimage/tiff\nimage/x-icon\nimage/x-ico\nimage/x-win-bitmap\nimage/jpeg\n\nthunar 1.2.1 copy a file\nTIMESTAMP\nTARGETS\nMULTIPLE\nx-special/gnome-copied-files\nUTF8_STRING\n\ndolphin 1.6.1 KDE 4.6.5 (kubuntu 11.04) copy two files\ntext/uri-list\n/home/jay/temp/jetstream1.txt\n/home/jay/temp/jpeg64x64.jpg\n0000 66 69 6c 65 3a 2f 2f 2f 68 6f 6d 65 2f 6a 61 79 file:///home/jay\n0010 2f 74 65 6d 70 2f 6a 65 74 73 74 72 65 61 6d 31 /temp/jetstream1\n0020 2e 74 78 74 0d 0a 66 69 6c 65 3a 2f 2f 2f 68 6f .txt..file:///ho\n0030 6d 65 2f 6a 61 79 2f 74 65 6d 70 2f 6a 70 65 67 me/jay/temp/jpeg\n0040 36 34 78 36 34 2e 6a 70 67                      64x64.jpg\n\nthunar 1.2.1 (kubuntu 11.04)  copy two files\nx-special/gnome-copied-files\n/home/jay/temp/jetstream1.txt\n/home/jay/temp/jpeg64x64.jpg\n0000 63 6f 70 79 0a 66 69 6c 65 3a 2f 2f 2f 68 6f 6d copy.file:///hom\n0010 65 2f 6a 61 79 2f 74 65 6d 70 2f 6a 65 74 73 74 e/jay/temp/jetst\n0020 72 65 61 6d 31 2e 74 78 74 0d 0a 66 69 6c 65 3a ream1.txt..file:\n0030 2f 2f 2f 68 6f 6d 65 2f 6a 61 79 2f 74 65 6d 70 ///home/jay/temp\n0040 2f 6a 70 65 67 36 34 78 36 34 2e 6a 70 67 0d 0a /jpeg64x64.jpg..\n\n\n*/\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <X11/Xlib.h>\n#include <X11/Xatom.h>\n#include <X11/extensions/Xfixes.h>\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"chansrv.h\"\n#include \"chansrv_common.h\"\n#include \"chansrv_config.h\"\n#include \"clipboard.h\"\n#include \"clipboard_file.h\"\n#include \"clipboard_common.h\"\n#include \"xcommon.h\"\n#include \"chansrv_fuse.h\"\n#include \"ms-rdpeclip.h\"\n#include \"xrdp_constants.h\"\n\n#define BMPFILEHEADER_LEN       14\n#define BMPINFOHEADER_LEN       40\n\nextern int g_cliprdr_chan_id;   /* in chansrv.c */\n\nextern Display *g_display;      /* in xcommon.c */\nextern int g_x_socket;          /* in xcommon.c */\nextern tbus g_x_wait_obj;       /* in xcommon.c */\nextern Screen *g_screen;        /* in xcommon.c */\nextern int g_screen_num;        /* in xcommon.c */\n\nextern struct config_chansrv *g_cfg; /* in chansrv.c */\n\nint g_clip_up = 0;\n\nstatic Atom g_clipboard_atom = 0;      /* CLIPBOARD */\nstatic Atom g_clip_property_atom = 0;  /* XRDP_CLIP_PROPERTY_ATOM */\nstatic Atom g_timestamp_atom = 0;      /* TIMESTAMP */\nstatic Atom g_multiple_atom = 0;       /* MULTIPLE */\nstatic Atom g_targets_atom = 0;        /* TARGETS */\nstatic Atom g_primary_atom = 0;        /* PRIMARY */\nstatic Atom g_secondary_atom = 0;      /* SECONDARY */\nstatic Atom g_get_time_atom = 0;       /* XRDP_GET_TIME_ATOM */\nstatic Atom g_utf8_atom = 0;           /* UTF8_STRING */\nstatic Atom g_image_bmp_atom = 0;      /* image/bmp */\nstatic Atom g_file_atom1 = 0;          /* text/uri-list */\nstatic Atom g_file_atom2 = 0;          /* x-special/gnome-copied-files */\nstatic Atom g_incr_atom = 0;           /* INCR */\n\nstatic Window g_wnd = 0;\nstatic int g_xfixes_event_base = 0;\n\nstatic int g_got_selection = 0; /* boolean */\nstatic Time g_selection_time = 0;\n\nstatic struct stream *g_ins = 0;\n\n/* for image data */\nstatic XSelectionRequestEvent g_saved_selection_req_event;\n\n/* xserver maximum request size in bytes */\nstatic int g_incr_max_req_size = 0;\n\n/* server to client, pasting from linux app to mstsc */\nstruct clip_s2c g_clip_s2c;\n/* client to server, pasting from mstsc to linux app */\nstruct clip_c2s g_clip_c2s;\n\n/* default version and flags */\nstatic int g_cliprdr_version = CB_CAPS_VERSION_2;\nstatic int g_cliprdr_flags = CB_USE_LONG_FORMAT_NAMES |\n                             CB_STREAM_FILECLIP_ENABLED |\n                             CB_FILECLIP_NO_FILE_PATHS;\n\n/* from client to server */\n/* last received CLIPRDR_FORMAT_LIST(CLIPRDR_FORMAT_ANNOUNCE) */\nstatic int g_formatIds[16];\nstatic int g_num_formatIds = 0;\n\n/* Format ID assigned to \"FileGroupDescriptorW\" by the client */\nstatic int g_file_group_descriptor_format_id = -1;\n\nstatic char g_last_atom_name[256] = \"\";\n\n/*\n * Values for the named formats we send to the client in\n * a Format List PDU\n */\n\nenum\n{\n    CB_FORMAT_FILE_GROUP_DESCRIPTOR = 0xc0bc\n};\n\n\n/*****************************************************************************/\nstatic char *\nget_atom_text(Atom atom)\n{\n    char *name;\n    int failed;\n\n    failed = 0;\n    /* sanity check */\n    if ((atom < 1) || (atom > 512))\n    {\n        failed = 1;\n    }\n    if (!failed)\n    {\n        name = XGetAtomName(g_display, atom);\n        if (name == 0)\n        {\n            failed = 1;\n        }\n    }\n    if (failed)\n    {\n        g_snprintf(g_last_atom_name, 255, \"unknown atom 0x%8.8x\", (int)atom);\n        return g_last_atom_name;\n    }\n    g_strncpy(g_last_atom_name, name, 255);\n    XFree(name);\n    return g_last_atom_name;\n}\n\n/*****************************************************************************/\n/* this is one way to get the current time from the x server */\nstatic Time\nclipboard_get_server_time(void)\n{\n    XEvent xevent;\n    unsigned char no_text[4];\n\n    /* append nothing */\n    no_text[0] = 0;\n    XChangeProperty(g_display, g_wnd, g_get_time_atom, XA_STRING, 8,\n                    PropModeAppend, no_text, 0);\n\n    /* wait for PropertyNotify */\n    do\n    {\n        XMaskEvent(g_display, PropertyChangeMask, &xevent);\n    }\n    while (xevent.type != PropertyNotify);\n\n    return xevent.xproperty.time;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_find_format_id(int format_id)\n{\n    int index;\n\n    for (index = 0; index < g_num_formatIds; index++)\n    {\n        if (g_formatIds[index] == format_id)\n        {\n            return index;\n        }\n    }\n    return -1;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nclipboard_init(void)\n{\n    struct stream *s;\n    int size;\n    int rv;\n    int input_mask;\n    int dummy;\n    int ver_maj;\n    int ver_min;\n    Status st;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"clipboard_init:\");\n\n    if (g_clip_up)\n    {\n        return 0;\n    }\n\n    xfuse_init();\n    xcommon_init();\n    g_incr_max_req_size = XMaxRequestSize(g_display) * 4 - 24;\n    g_memset(&g_clip_c2s, 0, sizeof(g_clip_c2s));\n    g_memset(&g_clip_s2c, 0, sizeof(g_clip_s2c));\n    rv = 0;\n    if (rv == 0)\n    {\n        g_clipboard_atom = XInternAtom(g_display, \"CLIPBOARD\", False);\n\n        if (g_clipboard_atom == None)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_init: XInternAtom failed\");\n            rv = 3;\n        }\n    }\n\n    if (rv == 0)\n    {\n        if (!XFixesQueryExtension(g_display, &g_xfixes_event_base, &dummy))\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_init: no xfixes\");\n            rv = 5;\n        }\n    }\n\n    if (rv == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_init: g_xfixes_event_base %d\",\n                  g_xfixes_event_base);\n        st = XFixesQueryVersion(g_display, &ver_maj, &ver_min);\n        LOG(LOG_LEVEL_DEBUG, \"clipboard_init st %d, maj %d min %d\", st,\n            ver_maj, ver_min);\n        g_clip_property_atom = XInternAtom(g_display, \"XRDP_CLIP_PROPERTY_ATOM\",\n                                           False);\n        g_get_time_atom = XInternAtom(g_display, \"XRDP_GET_TIME_ATOM\",\n                                      False);\n        g_timestamp_atom = XInternAtom(g_display, \"TIMESTAMP\", False);\n        g_targets_atom = XInternAtom(g_display, \"TARGETS\", False);\n        g_multiple_atom = XInternAtom(g_display, \"MULTIPLE\", False);\n        g_primary_atom = XInternAtom(g_display, \"PRIMARY\", False);\n        g_secondary_atom = XInternAtom(g_display, \"SECONDARY\", False);\n        g_utf8_atom = XInternAtom(g_display, \"UTF8_STRING\", False);\n\n        g_image_bmp_atom = XInternAtom(g_display, \"image/bmp\", False);\n        g_file_atom1 = XInternAtom(g_display, \"text/uri-list\", False);\n        g_file_atom2 = XInternAtom(g_display, \"x-special/gnome-copied-files\", False);\n        g_incr_atom = XInternAtom(g_display, \"INCR\", False);\n\n        if (g_image_bmp_atom == None)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_init: g_image_bmp_atom was \"\n                      \"not allocated\");\n        }\n\n        g_wnd = XCreateSimpleWindow(g_display, RootWindowOfScreen(g_screen),\n                                    0, 0, 4, 4, 0, 0, 0);\n        input_mask = StructureNotifyMask | PropertyChangeMask;\n        XSelectInput(g_display, g_wnd, input_mask);\n        //XMapWindow(g_display, g_wnd);\n        XFixesSelectSelectionInput(g_display, g_wnd,\n                                   g_clipboard_atom,\n                                   XFixesSetSelectionOwnerNotifyMask |\n                                   XFixesSelectionWindowDestroyNotifyMask |\n                                   XFixesSelectionClientCloseNotifyMask);\n    }\n\n    make_stream(s);\n    if (rv == 0)\n    {\n        /* set clipboard caps first */\n        init_stream(s, 8192);\n        /* CLIPRDR_HEADER */\n        out_uint16_le(s, CB_CLIP_CAPS); /* msgType */\n        out_uint16_le(s, 0); /* msgFlags */\n        out_uint32_le(s, 16); /* dataLen */\n        out_uint16_le(s, 1); /* cCapabilitiesSets */\n        out_uint16_le(s, 0); /* pad1 */\n        /* CLIPRDR_GENERAL_CAPABILITY */\n        out_uint16_le(s, CB_CAPSTYPE_GENERAL); /* capabilitySetType */\n        out_uint16_le(s, 12); /* lengthCapability */\n        out_uint32_le(s, g_cliprdr_version); /* version */\n        out_uint32_le(s, g_cliprdr_flags); /* generalFlags */\n        out_uint32_le(s, 0); /* extra 4 bytes ? */\n        s_mark_end(s);\n        size = (int)(s->end - s->data);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_init: data out, sending \"\n                  \"CB_CLIP_CAPS (clip_msg_id = 1)\");\n        rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n        if (rv != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_init: send_channel_data failed \"\n                      \"rv = %d\", rv);\n            rv = 4;\n        }\n    }\n\n    if (rv == 0)\n    {\n        /* report clipboard ready */\n        init_stream(s, 8192);\n        out_uint16_le(s, CB_MONITOR_READY); /* msgType */\n        out_uint16_le(s, 0); /* msgFlags */\n        out_uint32_le(s, 0); /* dataLen */\n        out_uint32_le(s, 0); /* extra 4 bytes ? */\n        s_mark_end(s);\n        size = (int)(s->end - s->data);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_init: data out, sending \"\n                  \"CB_MONITOR_READY (clip_msg_id = 1)\");\n        rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n        if (rv != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_init: send_channel_data failed \"\n                      \"rv = %d\", rv);\n            rv = 4;\n        }\n    }\n    free_stream(s);\n\n    if (rv == 0)\n    {\n        g_clip_up = 1;\n        make_stream(g_ins);\n        init_stream(g_ins, 8192);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"xrdp-chansrv: clipboard_init: error on exit\");\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nclipboard_deinit(void)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"clipboard_deinit:\");\n    if (g_wnd != 0)\n    {\n        XDestroyWindow(g_display, g_wnd);\n        g_wnd = 0;\n    }\n\n    xfuse_deinit();\n\n    g_free(g_clip_c2s.data);\n    g_clip_c2s.data = 0;\n    g_free(g_clip_s2c.data);\n    g_clip_s2c.data = 0;\n\n    free_stream(g_ins);\n    g_ins = 0;\n    g_clip_up = 0;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_send_data_request(int format_id)\n{\n    struct stream *s;\n    int size;\n    int rv;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_request:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_request: %d\", format_id);\n    g_clip_c2s.in_request = 1;\n    make_stream(s);\n    init_stream(s, 8192);\n    out_uint16_le(s, CB_FORMAT_DATA_REQUEST); /* 4 CLIPRDR_DATA_REQUEST */\n    out_uint16_le(s, 0); /* status */\n    out_uint32_le(s, 4); /* length */\n    out_uint32_le(s, format_id);\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_request: data out, sending \"\n              \"CLIPRDR_DATA_REQUEST (clip_msg_id = 4)\");\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_send_format_ack(void)\n{\n    struct stream *s;\n    int size;\n    int rv;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    out_uint16_le(s, CB_FORMAT_LIST_RESPONSE); /* 3 CLIPRDR_FORMAT_ACK */\n    out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */\n    out_uint32_le(s, 0); /* length */\n    out_uint32_le(s, 0); /* extra 4 bytes */\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_ack: data out, sending \"\n              \"CLIPRDR_FORMAT_ACK (clip_msg_id = 3)\");\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\n/**\n * Output null-terminated string as Unicode with a null terminator\n * @param s stream\n * @param text UTF-8 String\n */\nstatic void\nclipboard_out_utf8_as_utf16_le(struct stream *s, const char *text)\n{\n    out_utf8_as_utf16_le(s, text, strlen(text) + 1);\n}\n\n/*****************************************************************************/\nunsigned int\nclipboard_in_utf16_le_as_utf8(struct stream *s, char *text,\n                              unsigned int num_chars)\n{\n    char *orig_p = s->p;\n    unsigned int needed_chars;\n\n    if ((num_chars < 1) || (text == 0))\n    {\n        return 0;\n    }\n\n    needed_chars = in_utf16_le_terminated_as_utf8(s, text, num_chars);\n    if (needed_chars > num_chars)\n    {\n        LOG(LOG_LEVEL_WARNING, \"UTF-16 string was truncated on input\");\n    }\n    return s->p - orig_p;\n}\n\nstatic char windows_native_format[] =\n{\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n};\n\n/*****************************************************************************/\nstatic int\nclipboard_send_format_announce(int xrdp_clip_type)\n{\n    struct stream *s;\n    int size;\n    int rv;\n    char *holdp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce:\");\n    make_stream(s);\n    init_stream(s, 8192);\n    out_uint16_le(s, CB_FORMAT_LIST); /* 2 CLIPRDR_FORMAT_ANNOUNCE */\n    out_uint16_le(s, 0); /* status */\n    holdp = s->p;\n    out_uint32_le(s, 0); /* set later */\n    if (g_cliprdr_flags & CB_USE_LONG_FORMAT_NAMES)\n    {\n        switch (xrdp_clip_type)\n        {\n            case XRDP_CB_FILE:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce: XRDP_CB_FILE\");\n                /* canned response for \"file\" */\n                out_uint32_le(s, CB_FORMAT_FILE_GROUP_DESCRIPTOR);\n                clipboard_out_utf8_as_utf16_le(s, \"FileGroupDescriptorW\");\n                out_uint32_le(s, 0x0000c0ba);\n                clipboard_out_utf8_as_utf16_le(s, \"FileContents\");\n                out_uint32_le(s, 0x0000c0c1);\n                clipboard_out_utf8_as_utf16_le(s, \"DropEffect\");\n                break;\n            case XRDP_CB_BITMAP:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce: XRDP_CB_BITMAP\");\n                /* canned response for \"bitmap\" */\n                out_uint32_le(s, 0x0000c004);\n                clipboard_out_utf8_as_utf16_le(s, \"Native\");\n                out_uint32_le(s, 0x00000003);\n                clipboard_out_utf8_as_utf16_le(s, \"\");\n                out_uint32_le(s, 0x00000008);\n                clipboard_out_utf8_as_utf16_le(s, \"\");\n                out_uint32_le(s, 0x00000011);\n                clipboard_out_utf8_as_utf16_le(s, \"\");\n                break;\n            case XRDP_CB_TEXT:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce: XRDP_CB_TEXT\");\n                /* canned response for \"bitmap\" */\n                out_uint32_le(s, 0x0000000d);\n                clipboard_out_utf8_as_utf16_le(s, \"\");\n                out_uint32_le(s, 0x00000010);\n                clipboard_out_utf8_as_utf16_le(s, \"\");\n                out_uint32_le(s, 0x00000001);\n                clipboard_out_utf8_as_utf16_le(s, \"\");\n                out_uint32_le(s, 0x00000007);\n                clipboard_out_utf8_as_utf16_le(s, \"\");\n                break;\n            default:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce: unknown \"\n                          \"xrdp_clip_type %d\", xrdp_clip_type);\n                break;\n        }\n    }\n    else /* old method */\n    {\n        switch (xrdp_clip_type)\n        {\n            case XRDP_CB_FILE:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce: XRDP_CB_FILE\");\n                /* canned response for \"file\" */\n                out_uint32_le(s, CB_FORMAT_FILE_GROUP_DESCRIPTOR);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                out_uint32_le(s, 0x0000c0ba);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                out_uint32_le(s, 0x0000c0c1);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                break;\n            case XRDP_CB_BITMAP:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce: XRDP_CB_BITMAP\");\n                /* canned response for \"bitmap\" */\n                out_uint32_le(s, 0x0000c004);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                out_uint32_le(s, 0x00000003);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                out_uint32_le(s, 0x00000008);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                out_uint32_le(s, 0x00000011);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                break;\n            case XRDP_CB_TEXT:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce: XRDP_CB_TEXT\");\n                /* canned response for \"bitmap\" */\n                out_uint32_le(s, 0x0000000d);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                out_uint32_le(s, 0x00000010);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                out_uint32_le(s, 0x00000001);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                out_uint32_le(s, 0x00000007);\n                out_uint8p(s, windows_native_format, sizeof(windows_native_format));\n                break;\n            default:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce: unknown \"\n                          \"xrdp_clip_type %d\", xrdp_clip_type);\n                break;\n        }\n    }\n    size = (int)(s->p - holdp);\n    size -= 4;\n    holdp[0] = (size >> 0) & 0xff;\n    holdp[1] = (size >> 8) & 0xff;\n    holdp[2] = (size >> 16) & 0xff;\n    holdp[3] = (size >> 24) & 0xff;\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"clipboard data:\", s->data, size);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_format_announce: data out, sending \"\n              \"CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)\");\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_send_data_response_for_image(const char *data, int data_size)\n{\n    struct stream *s;\n    int size;\n    int rv;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_response_for_image: data_size %d\",\n              data_size);\n    make_stream(s);\n    init_stream(s, 64 + data_size);\n    out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */\n    out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */\n    out_uint32_le(s, data_size); /* length */\n    out_uint8p(s, data, data_size);\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_send_data_response_for_text(const char *data, int data_size)\n{\n    struct stream *s;\n    int size;\n    int rv;\n    int num_words;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_response_for_text: data_size %d\",\n              data_size);\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"clipboard send data response:\", data, data_size);\n    num_words = utf8_as_utf16_word_count(data, data_size);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_response_for_text: data_size %d \"\n              \"num_words %d\", data_size, num_words);\n    make_stream(s);\n    init_stream(s, 64 + num_words * 2);\n    out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */\n    out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */\n    out_uint32_le(s, num_words * 2 + 2); /* length */\n    out_utf8_as_utf16_le(s, data, data_size);\n    out_uint16_le(s, 0); /* nil for string */\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_response_for_text: data out, \"\n              \"sending CLIPRDR_DATA_RESPONSE (clip_msg_id = 5) size %d \"\n              \"num_words %d\", size, num_words);\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_send_data_response(int xrdp_clip_type, const char *data, int data_size)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_response:\");\n    if (data != 0)\n    {\n        if (xrdp_clip_type == XRDP_CB_FILE)\n        {\n            return clipboard_send_data_response_for_file(data, data_size);\n        }\n        else if (xrdp_clip_type == XRDP_CB_BITMAP)\n        {\n            return clipboard_send_data_response_for_image(data, data_size);\n        }\n        else if (xrdp_clip_type == XRDP_CB_TEXT)\n        {\n            return clipboard_send_data_response_for_text(data, data_size);\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_response: unknown \"\n                      \"xrdp_clip_type %d\", xrdp_clip_type);\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_send_data_response: data is nil\");\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_set_selection_owner(void)\n{\n    Window owner;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_set_selection_owner:\");\n    g_selection_time = clipboard_get_server_time();\n    XSetSelectionOwner(g_display, g_clipboard_atom, g_wnd, g_selection_time);\n    owner = XGetSelectionOwner(g_display, g_clipboard_atom);\n\n    if (owner != g_wnd)\n    {\n        g_got_selection = 0;\n        return 1;\n    }\n\n    g_got_selection = 1;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_provide_selection_c2s(XSelectionRequestEvent *req, Atom type)\n{\n    XEvent xev;\n    long val1[2];\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_provide_selection_c2s: bytes %d\",\n              g_clip_c2s.total_bytes);\n    if (g_clip_c2s.total_bytes < g_incr_max_req_size)\n    {\n        XChangeProperty(g_display, req->requestor, req->property,\n                        type, 8, PropModeReplace,\n                        (tui8 *)g_clip_c2s.data, g_clip_c2s.total_bytes);\n        g_memset(&xev, 0, sizeof(xev));\n        xev.xselection.type = SelectionNotify;\n        xev.xselection.send_event = True;\n        xev.xselection.display = req->display;\n        xev.xselection.requestor = req->requestor;\n        xev.xselection.selection = req->selection;\n        xev.xselection.target = req->target;\n        xev.xselection.property = req->property;\n        xev.xselection.time = req->time;\n        XSendEvent(g_display, req->requestor, False, NoEventMask, &xev);\n    }\n    else\n    {\n        /* start the INCR process */\n        g_clip_c2s.incr_in_progress = 1;\n        g_clip_c2s.incr_bytes_done = 0;\n        g_clip_c2s.type = type;\n        g_clip_c2s.property = req->property;\n        g_clip_c2s.window = req->requestor;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_provide_selection_c2s: start INCR property %s \"\n                  \"type %s\", get_atom_text(req->property),\n                  get_atom_text(type));\n        val1[0] = g_clip_c2s.total_bytes;\n        val1[1] = 0;\n        XChangeProperty(g_display, req->requestor, req->property,\n                        g_incr_atom, 32, PropModeReplace, (tui8 *)val1, 1);\n        /* we need events from that other window */\n        XSelectInput(g_display, req->requestor, PropertyChangeMask);\n        g_memset(&xev, 0, sizeof(xev));\n        xev.xselection.type = SelectionNotify;\n        xev.xselection.send_event = True;\n        xev.xselection.display = req->display;\n        xev.xselection.requestor = req->requestor;\n        xev.xselection.selection = req->selection;\n        xev.xselection.target = req->target;\n        xev.xselection.property = req->property;\n        xev.xselection.time = req->time;\n        XSendEvent(g_display, req->requestor, False, NoEventMask, &xev);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_provide_selection(XSelectionRequestEvent *req, Atom type, int format,\n                            char *data, int length)\n{\n    XEvent xev;\n    int bytes;\n\n    bytes = FORMAT_TO_BYTES(format);\n    bytes *= length;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_provide_selection: bytes %d\", bytes);\n    if (bytes < g_incr_max_req_size)\n    {\n        XChangeProperty(g_display, req->requestor, req->property,\n                        type, format, PropModeReplace, (tui8 *)data, length);\n        g_memset(&xev, 0, sizeof(xev));\n        xev.xselection.type = SelectionNotify;\n        xev.xselection.send_event = True;\n        xev.xselection.display = req->display;\n        xev.xselection.requestor = req->requestor;\n        xev.xselection.selection = req->selection;\n        xev.xselection.target = req->target;\n        xev.xselection.property = req->property;\n        xev.xselection.time = req->time;\n        XSendEvent(g_display, req->requestor, False, NoEventMask, &xev);\n        return 0;\n    }\n    return 1;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_refuse_selection(XSelectionRequestEvent *req)\n{\n    XEvent xev;\n\n    g_memset(&xev, 0, sizeof(xev));\n    xev.xselection.type = SelectionNotify;\n    xev.xselection.send_event = True;\n    xev.xselection.display = req->display;\n    xev.xselection.requestor = req->requestor;\n    xev.xselection.selection = req->selection;\n    xev.xselection.target = req->target;\n    xev.xselection.property = None;\n    xev.xselection.time = req->time;\n    XSendEvent(g_display, req->requestor, False, NoEventMask, &xev);\n    return 0;\n}\n\n/*****************************************************************************/\n/* sent by client or server when its local system clipboard is\n   updated with new clipboard data; contains Clipboard Format ID\n   and name pairs of new Clipboard Formats on the clipboard. */\nstatic int\nclipboard_process_format_announce(struct stream *s, int clip_msg_status,\n                                  int clip_msg_len)\n{\n    int formatId;\n    int bytes;\n    char desc[256];\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_format_announce: \"\n              \"CLIPRDR_FORMAT_ANNOUNCE\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_format_announce %d\", clip_msg_len);\n    clipboard_send_format_ack();\n\n    xfuse_clear_clip_dir();\n    g_clip_c2s.converted = 0;\n\n    desc[0] = 0;\n    g_num_formatIds = 0;\n    while (clip_msg_len > 3)\n    {\n        in_uint32_le(s, formatId);\n        clip_msg_len -= 4;\n        if (g_cliprdr_flags & CB_USE_LONG_FORMAT_NAMES)\n        {\n            /* CLIPRDR_LONG_FORMAT_NAME */\n            bytes = clipboard_in_utf16_le_as_utf8(s, desc, sizeof(desc));\n            clip_msg_len -= bytes;\n        }\n        else\n        {\n            /* CLIPRDR_SHORT_FORMAT_NAME */\n            /* 32 ASCII 8 characters or 16 Unicode characters */\n            in_utf16_le_fixed_as_utf8(s, 16, desc, sizeof(desc));\n            desc[15] = 0;\n            clip_msg_len -= 32;\n        }\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_format_announce: formatId 0x%8.8x \"\n                  \"wszFormatName [%s] clip_msg_len %d\", formatId, desc,\n                  clip_msg_len);\n        if (g_num_formatIds <= 15)\n        {\n            g_formatIds[g_num_formatIds] = formatId;\n            g_num_formatIds++;\n        }\n        if (g_num_formatIds > 15)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_format_announce: max formats\");\n        }\n\n        /* format id for file copy copy is dynamic and announced by the\n         * client */\n        if (g_strcmp(desc, \"FileGroupDescriptorW\") == 0)\n        {\n            g_file_group_descriptor_format_id = formatId;\n        }\n    }\n\n    if ((g_num_formatIds > 0) &&\n            (g_clip_c2s.incr_in_progress == 0) && /* don't interrupt incr */\n            (g_clip_s2c.incr_in_progress == 0))\n    {\n        if (clipboard_set_selection_owner() != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_process_format_announce: \"\n                      \"XSetSelectionOwner failed\");\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* response to CB_FORMAT_LIST; used to indicate whether\n   processing of the Format List PDU was successful */\nstatic int\nclipboard_process_format_ack(struct stream *s, int clip_msg_status,\n                             int clip_msg_len)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_format_ack: CLIPRDR_FORMAT_ACK\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_format_ack:\");\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_send_data_response_failed(void)\n{\n    struct stream *s;\n    int size;\n    int rv;\n\n    LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_send_data_response_failed:\");\n    make_stream(s);\n    init_stream(s, 64);\n    out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */\n    out_uint16_le(s, CB_RESPONSE_FAIL); /* 2 status */\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\n/* sent from server to client\n * sent by recipient of CB_FORMAT_LIST; used to request data for one\n * of the formats that was listed in CB_FORMAT_LIST */\nstatic int\nclipboard_process_data_request(struct stream *s, int clip_msg_status,\n                               int clip_msg_len)\n{\n    int requestedFormatId;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_request: \"\n              \"CLIPRDR_DATA_REQUEST\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_request:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  %d\", g_clip_s2c.xrdp_clip_type);\n    in_uint32_le(s, requestedFormatId);\n    switch (requestedFormatId)\n    {\n        case CB_FORMAT_FILE_GROUP_DESCRIPTOR:\n            if ((g_clip_s2c.xrdp_clip_type == XRDP_CB_FILE) && g_clip_s2c.converted)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_request: CB_FORMAT_FILE_GROUP_DESCRIPTOR\");\n                clipboard_send_data_response(XRDP_CB_FILE, g_clip_s2c.data,\n                                             g_clip_s2c.total_bytes);\n            }\n            else\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_request: CB_FORMAT_FILE_GROUP_DESCRIPTOR, \"\n                          \"calling XConvertSelection to g_utf8_atom\");\n                g_clip_s2c.xrdp_clip_type = XRDP_CB_FILE;\n                XConvertSelection(g_display, g_clipboard_atom, g_clip_s2c.type,\n                                  g_clip_property_atom, g_wnd, CurrentTime);\n            }\n            break;\n        case CF_DIB:\n            if ((g_clip_s2c.xrdp_clip_type == XRDP_CB_BITMAP) && g_clip_s2c.converted)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_request: CF_DIB\");\n                clipboard_send_data_response(XRDP_CB_BITMAP, g_clip_s2c.data,\n                                             g_clip_s2c.total_bytes);\n            }\n            else\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_request: CF_DIB, \"\n                          \"calling XConvertSelection to g_image_bmp_atom\");\n                g_clip_s2c.xrdp_clip_type = XRDP_CB_BITMAP;\n                XConvertSelection(g_display, g_clipboard_atom, g_image_bmp_atom,\n                                  g_clip_property_atom, g_wnd, CurrentTime);\n            }\n            break;\n        case CF_UNICODETEXT:\n            if ((g_clip_s2c.xrdp_clip_type == XRDP_CB_TEXT) && g_clip_s2c.converted)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_request: CF_UNICODETEXT\");\n                clipboard_send_data_response(XRDP_CB_TEXT, g_clip_s2c.data,\n                                             g_clip_s2c.total_bytes);\n            }\n            else\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_request: CF_UNICODETEXT, \"\n                          \"calling XConvertSelection to g_utf8_atom\");\n                g_clip_s2c.xrdp_clip_type = XRDP_CB_TEXT;\n                XConvertSelection(g_display, g_clipboard_atom, g_utf8_atom,\n                                  g_clip_property_atom, g_wnd, CurrentTime);\n            }\n            break;\n        default:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_request: unknown type %d\",\n                      requestedFormatId);\n            clipboard_send_data_response_failed();\n            break;\n    }\n    return 0;\n}\n\n/**************************************************************************//**\n * Process a CB_FORMAT_DATA_RESPONSE for an X client requesting an image\n *\n * @param s Stream containing CLIPRDR_FILELIST ([MS-RDPECLIP])\n * @param clip_msg_status msgFlags from Clipboard PDU Header\n * @param clip_msg_len dataLen from Clipboard PDU Header\n *\n * @return Status\n */\nstatic int\nclipboard_process_data_response_for_image(struct stream *s,\n        int clip_msg_status,\n        int clip_msg_len)\n{\n    XSelectionRequestEvent *lxev;\n    int len;\n    struct stream *bmp_hs;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_response_for_image: \"\n              \"CLIPRDR_DATA_RESPONSE_FOR_IMAGE\");\n    lxev = &g_saved_selection_req_event;\n    len = (int)(s->end - s->p);\n    if (len < 1)\n    {\n        return 0;\n    }\n    if (g_clip_c2s.type != g_image_bmp_atom)\n    {\n        return 0;\n    }\n\n    g_free(g_clip_c2s.data);\n    g_clip_c2s.data = (char *) g_malloc(len + BMPFILEHEADER_LEN, 0);\n    if (g_clip_c2s.data == 0)\n    {\n        g_clip_c2s.total_bytes = 0;\n        return 0;\n    }\n    g_clip_c2s.total_bytes = len + BMPFILEHEADER_LEN;\n    g_clip_c2s.read_bytes_done = g_clip_c2s.total_bytes;\n\n    /*\n     * Assemble bitmap file header\n     * https://en.wikipedia.org/wiki/BMP_file_format#Bitmap_file_header\n     */\n    make_stream(bmp_hs);\n    if (bmp_hs == 0)\n    {\n        g_free(g_clip_c2s.data);\n        g_clip_c2s.total_bytes = 0;\n        return 0;\n    }\n    init_stream(bmp_hs, BMPFILEHEADER_LEN);\n    out_uint8(bmp_hs, 'B');\n    out_uint8(bmp_hs, 'M');\n    out_uint32_le(bmp_hs, g_clip_c2s.total_bytes);\n    out_uint16_le(bmp_hs, 0);\n    out_uint16_le(bmp_hs, 0);\n    out_uint32_le(bmp_hs, BMPFILEHEADER_LEN + BMPINFOHEADER_LEN);\n\n    /* Copy header and data to output stream */\n    g_memcpy(g_clip_c2s.data, bmp_hs->data, BMPFILEHEADER_LEN);\n    in_uint8a(s, g_clip_c2s.data + BMPFILEHEADER_LEN, len);\n\n    free_stream(bmp_hs);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_response_for_image: calling \"\n              \"clipboard_provide_selection_c2s\");\n    clipboard_provide_selection_c2s(lxev, lxev->target);\n\n    return 0;\n}\n\n/**************************************************************************//**\n * Process a CB_FORMAT_DATA_RESPONSE for an X client requesting a file list\n *\n * @param s Stream containing CLIPRDR_FILELIST ([MS-RDPECLIP])\n * @param clip_msg_status msgFlags from Clipboard PDU Header\n * @param clip_msg_len dataLen from Clipboard PDU Header\n *\n * @return Status\n */\nstatic int\nclipboard_process_data_response_for_file(struct stream *s,\n        int clip_msg_status,\n        int clip_msg_len)\n{\n    XSelectionRequestEvent *lxev;\n    int rv = 0;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"clipboard_process_data_response_for_file: \");\n    lxev = &g_saved_selection_req_event;\n\n    const int flist_size = 1024 * 1024;\n    g_free(g_clip_c2s.data);\n    g_clip_c2s.data = (char *)g_malloc(flist_size, 0);\n    if (g_clip_c2s.data == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_process_data_response_for_file: \"\n            \"Can't allocate memory\");\n        rv = 1;\n    }\n    /* text/uri-list */\n    else if (g_clip_c2s.type == g_file_atom1)\n    {\n        rv = clipboard_c2s_in_files(s, g_clip_c2s.data, flist_size,\n                                    \"file://\");\n    }\n    /* x-special/gnome-copied-files */\n    else if (g_clip_c2s.type == g_file_atom2)\n    {\n        g_strcpy(g_clip_c2s.data, \"copy\\n\");\n        rv = clipboard_c2s_in_files(s, g_clip_c2s.data + 5, flist_size - 5,\n                                    \"file://\");\n    }\n    else if ((g_clip_c2s.type == XA_STRING) ||\n             (g_clip_c2s.type == g_utf8_atom))\n    {\n        if (g_cfg->use_nautilus3_flist_format)\n        {\n            /*\n             * This file list format is only used by GNOME 3\n             * versions >= 3.29.92. It is not used by GNOME 4. Remove\n             * this workaround when GNOME 3 is no longer supported by\n             * long-term distros */\n#define LIST_PREFIX \"x-special/nautilus-clipboard\\ncopy\\n\"\n#define LIST_PREFIX_LEN (sizeof(LIST_PREFIX) - 1)\n            g_strcpy(g_clip_c2s.data, LIST_PREFIX);\n            rv = clipboard_c2s_in_files(s,\n                                        g_clip_c2s.data + LIST_PREFIX_LEN,\n                                        flist_size - LIST_PREFIX_LEN - 1,\n                                        \"file://\");\n            g_strcat(g_clip_c2s.data, \"\\n\");\n#undef LIST_PREFIX_LEN\n#undef LIST_PREFIX\n        }\n        else\n        {\n            rv = clipboard_c2s_in_files(s, g_clip_c2s.data, flist_size, \"\");\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR,\n                  \"clipboard_process_data_response_for_file: \"\n                  \"Unrecognised target\");\n        rv = 1;\n    }\n\n    if (rv != 0 && g_clip_c2s.data != NULL)\n    {\n        g_clip_c2s.data[0] = '\\0';\n    }\n\n    g_clip_c2s.total_bytes =\n        (g_clip_c2s.data == NULL) ? 0 : g_strlen(g_clip_c2s.data);\n    g_clip_c2s.read_bytes_done = g_clip_c2s.total_bytes;\n    clipboard_provide_selection_c2s(lxev, lxev->target);\n\n    return rv;\n}\n\n/**************************************************************************//**\n * Process a CB_FORMAT_DATA_RESPONSE for an X client requesting text\n *\n * @param s Stream containing CLIPRDR_FILELIST ([MS-RDPECLIP])\n * @param clip_msg_status msgFlags from Clipboard PDU Header\n * @param clip_msg_len dataLen from Clipboard PDU Header\n *\n * @return Status\n */\nstatic int\nclipboard_process_data_response_for_text(struct stream *s,\n        int clip_msg_status,\n        int clip_msg_len)\n{\n    XSelectionRequestEvent *lxev = &g_saved_selection_req_event;\n    unsigned int byte_count;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_response_for_text: \");\n\n    /* Get the buffer size we need */\n    byte_count = in_utf16_le_terminated_as_utf8_length(s);\n\n    g_free(g_clip_c2s.data);\n    g_clip_c2s.total_bytes = 0;\n    if ((g_clip_c2s.data = (char *)g_malloc(byte_count, 0)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't allocate %u bytes for text clip response\",\n            byte_count);\n\n        clipboard_refuse_selection(lxev);\n    }\n    else\n    {\n        /* Re-parse the data into the allocated buffer */\n        in_utf16_le_terminated_as_utf8(s, g_clip_c2s.data, byte_count);\n        --byte_count; /* Ignore the terminator at the end */\n\n        g_clip_c2s.total_bytes = byte_count;\n        g_clip_c2s.read_bytes_done = byte_count;\n        clipboard_provide_selection_c2s(lxev, lxev->target);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* client to server */\n/* sent as a reply to CB_FORMAT_DATA_REQUEST; used to indicate whether\n   processing of the CB_FORMAT_DATA_REQUEST was successful; if processing was\n   successful, CB_FORMAT_DATA_RESPONSE includes contents of requested\n   clipboard data. */\n/*****************************************************************************/\nstatic int\nclipboard_process_data_response(struct stream *s, int clip_msg_status,\n                                int clip_msg_len)\n{\n    int rv = 0;\n\n    XSelectionRequestEvent *lxev = &g_saved_selection_req_event;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_data_response:\");\n    g_clip_c2s.in_request = 0;\n\n    if ((clip_msg_status & CB_RESPONSE_FAIL) != 0)\n    {\n        /* Requested data was not returned from the client. Most likely\n         * the client has lost the selection between announcing it and\n         * responding to our request */\n        clipboard_refuse_selection(lxev);\n    }\n    else if ((clip_msg_status & CB_RESPONSE_OK) == 0)\n    {\n        /* One of CB_RESPONSE_FAIL or CB_RESPONSE_OK MUST be set in\n         * a CLIPRDR_FORMAT_DATA_RESPONSE msg */\n        LOG(LOG_LEVEL_ERROR, \"CLIPRDR_FORMAT_DATA_RESPONSE is badly formed\");\n        clipboard_refuse_selection(lxev);\n    }\n    else if (g_clip_c2s.xrdp_clip_type == XRDP_CB_BITMAP)\n    {\n        clipboard_process_data_response_for_image(s, clip_msg_status,\n                clip_msg_len);\n    }\n    else if (g_clip_c2s.xrdp_clip_type == XRDP_CB_FILE)\n    {\n        clipboard_process_data_response_for_file(s, clip_msg_status,\n                clip_msg_len);\n    }\n    else\n    {\n        clipboard_process_data_response_for_text(s, clip_msg_status,\n                clip_msg_len);\n    }\n    return rv;\n}\n\n\n/*****************************************************************************/\nstatic int\nclipboard_process_clip_caps(struct stream *s, int clip_msg_status,\n                            int clip_msg_len)\n{\n    int cCapabilitiesSets;\n    int capabilitySetType;\n    int lengthCapability;\n    int index;\n    int version;\n    int flags;\n    char *holdp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_clip_caps:\");\n    //LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", s->p, s->end - s->p);\n    in_uint16_le(s, cCapabilitiesSets);\n    in_uint8s(s, 2); /* pad */\n    for (index = 0; index < cCapabilitiesSets; index++)\n    {\n        holdp = s->p;\n        in_uint16_le(s, capabilitySetType);\n        in_uint16_le(s, lengthCapability);\n        switch (capabilitySetType)\n        {\n            case CB_CAPSTYPE_GENERAL:\n                in_uint32_le(s, version); /* version */\n                in_uint32_le(s, flags); /* generalFlags */\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_clip_caps: \"\n                          \"g_cliprdr_version %d version %d \"\n                          \"g_cliprdr_flags 0x%x flags 0x%x\",\n                          g_cliprdr_version, version,\n                          g_cliprdr_flags, flags);\n                if (version < g_cliprdr_version)\n                {\n                    g_cliprdr_version = version;\n                }\n                g_cliprdr_flags &= flags;\n                break;\n            default:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_clip_caps: unknown \"\n                          \"capabilitySetType %d\", capabilitySetType);\n                break;\n        }\n        s->p = holdp + lengthCapability;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nclipboard_data_in(struct stream *s, int chan_id, int chan_flags, int length,\n                  int total_length)\n{\n    int clip_msg_id;\n    int clip_msg_len;\n    int clip_msg_status;\n    int rv;\n    struct stream *ls;\n\n    if (!g_clip_up)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"aborting clipboard_data_in - clipboard has not \"\n                  \"been initialized\");\n        /* we return 0 here to indicate no protocol problem occurred */\n        return 0;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_data_in: chan_id %d \"\n              \"chan_flags 0x%x length %d total_length %d \"\n              \"in_request %d g_ins->size %d\",\n              chan_id, chan_flags, length, total_length,\n              g_clip_c2s.in_request, g_ins->size);\n\n    if ((chan_flags & 3) == 3)\n    {\n        ls = s;\n    }\n    else\n    {\n        if (chan_flags & 1)\n        {\n            init_stream(g_ins, total_length);\n        }\n\n        in_uint8a(s, g_ins->end, length);\n        g_ins->end += length;\n\n        if ((chan_flags & 2) == 0)\n        {\n            return 0;\n        }\n\n        ls = g_ins;\n    }\n\n    in_uint16_le(ls, clip_msg_id);\n    in_uint16_le(ls, clip_msg_status);\n    in_uint32_le(ls, clip_msg_len);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_data_in: clip_msg_id %d \"\n              \"clip_msg_status %d clip_msg_len %d\",\n              clip_msg_id, clip_msg_status, clip_msg_len);\n    rv = 0;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_data_in: %d\", clip_msg_id);\n    switch (clip_msg_id)\n    {\n        /* sent by client or server when its local system clipboard is   */\n        /* updated with new clipboard data; contains Clipboard Format ID */\n        /* and name pairs of new Clipboard Formats on the clipboard.     */\n        case CB_FORMAT_LIST: /* 2 CLIPRDR_FORMAT_ANNOUNCE */\n            rv = clipboard_process_format_announce(ls, clip_msg_status,\n                                                   clip_msg_len);\n            break;\n        /* response to CB_FORMAT_LIST; used to indicate whether */\n        /* processing of the Format List PDU was successful     */\n        case CB_FORMAT_LIST_RESPONSE: /* 3 CLIPRDR_FORMAT_ACK */\n            rv = clipboard_process_format_ack(ls, clip_msg_status,\n                                              clip_msg_len);\n            break;\n        /* sent by recipient of CB_FORMAT_LIST; used to request data for one */\n        /* of the formats that was listed in CB_FORMAT_LIST                  */\n        case CB_FORMAT_DATA_REQUEST: /* 4 CLIPRDR_DATA_REQUEST */\n            rv = clipboard_process_data_request(ls, clip_msg_status,\n                                                clip_msg_len);\n            break;\n        /* sent as a reply to CB_FORMAT_DATA_REQUEST; used to indicate */\n        /* whether processing of the CB_FORMAT_DATA_REQUEST was        */\n        /* successful; if processing was successful,                   */\n        /* CB_FORMAT_DATA_RESPONSE includes contents of requested      */\n        /* clipboard data.                                             */\n        case CB_FORMAT_DATA_RESPONSE: /* 5 CLIPRDR_DATA_RESPONSE */\n            rv = clipboard_process_data_response(ls, clip_msg_status,\n                                                 clip_msg_len);\n            break;\n        case CB_CLIP_CAPS: /* 7 */\n            rv = clipboard_process_clip_caps(ls, clip_msg_status,\n                                             clip_msg_len);\n            break;\n        case CB_FILECONTENTS_REQUEST: /* 8 */\n            rv = clipboard_process_file_request(ls, clip_msg_status,\n                                                clip_msg_len);\n            break;\n        case CB_FILECONTENTS_RESPONSE: /* 9 */\n            rv = clipboard_process_file_response(ls, clip_msg_status,\n                                                 clip_msg_len);\n            break;\n        default:\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_data_in: unknown clip_msg_id %d\", clip_msg_id);\n            break;\n    }\n\n    XFlush(g_display);\n    return rv;\n}\n\n/*****************************************************************************/\n/* this happens when a new app copies something to the clipboard\n   'CLIPBOARD' Atom\n   typedef struct\n   {\n    int type;\n    unsigned long serial;\n    Bool send_event;\n    Display *display;\n    Window window;\n    int subtype;\n    Window owner;\n    Atom selection;\n    Time timestamp;\n    Time selection_timestamp;\n   } XFixesSelectionNotifyEvent; */\nstatic int\nclipboard_event_selection_owner_notify(XEvent *xevent)\n{\n    XFixesSelectionNotifyEvent *lxevent;\n\n    lxevent = (XFixesSelectionNotifyEvent *)xevent;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_owner_notify: 0x%lx\", lxevent->owner);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_owner_notify: \"\n              \"window %ld subtype %d owner %ld g_wnd %ld\",\n              lxevent->window, lxevent->subtype, lxevent->owner, g_wnd);\n\n    if (lxevent->owner == g_wnd)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_owner_notify: matches g_wnd\");\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_owner_notify: skipping, \"\n                  \"owner == g_wnd\");\n        g_got_selection = 1;\n        return 0;\n    }\n\n    g_got_selection = 0;\n    if (lxevent->owner != 0) /* nil owner comes when selection */\n    {\n        /* window is closed */\n        XConvertSelection(g_display, g_clipboard_atom, g_targets_atom,\n                          g_clip_property_atom, g_wnd, lxevent->timestamp);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error\n   get a window property from wnd */\nstatic int\nclipboard_get_window_property(Window wnd, Atom prop, Atom *type, int *fmt,\n                              int *n_items, char **xdata, int *xdata_size)\n{\n    int lfmt;\n    int lxdata_size;\n    unsigned long ln_items;\n    unsigned long llen_after;\n    tui8 *lxdata;\n    Atom ltype;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_get_window_property:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  prop %ld name %s\", prop, get_atom_text(prop));\n    lxdata = 0;\n    ltype = 0;\n    XGetWindowProperty(g_display, wnd, prop, 0, 0, 0,\n                       AnyPropertyType, &ltype, &lfmt, &ln_items,\n                       &llen_after, &lxdata);\n    if (lxdata != 0)\n    {\n        XFree(lxdata);\n    }\n    if (ltype == 0)\n    {\n        /* XGetWindowProperty failed */\n        return 4;\n    }\n    if (llen_after < 1)\n    {\n        /* no data, ok */\n        return 0;\n    }\n    lxdata = 0;\n    ltype = 0;\n    XGetWindowProperty(g_display, wnd, prop, 0, (llen_after + 3) / 4, 0,\n                       AnyPropertyType, &ltype, &lfmt, &ln_items,\n                       &llen_after, &lxdata);\n    if (ltype == 0)\n    {\n        /* XGetWindowProperty failed */\n        if (lxdata != 0)\n        {\n            XFree(lxdata);\n        }\n        return 1;\n    }\n    lxdata_size = FORMAT_TO_BYTES(lfmt);\n    lxdata_size *= ln_items;\n    if (lxdata_size < 1)\n    {\n        /* should not happen */\n        if (lxdata != 0)\n        {\n            XFree(lxdata);\n        }\n        return 2;\n    }\n    if (llen_after > 0)\n    {\n        /* should not happen */\n        if (lxdata != 0)\n        {\n            XFree(lxdata);\n        }\n        return 3;\n    }\n    if (xdata != 0)\n    {\n        *xdata = (char *) g_malloc(lxdata_size, 0);\n        g_memcpy(*xdata, lxdata, lxdata_size);\n    }\n    if (lxdata != 0)\n    {\n        XFree(lxdata);\n    }\n    if (xdata_size != 0)\n    {\n        *xdata_size = lxdata_size;\n    }\n    if (fmt != 0)\n    {\n        *fmt = (int)lfmt;\n    }\n    if (n_items != 0)\n    {\n        *n_items = (int)ln_items;\n    }\n    if (type != 0)\n    {\n        *type = ltype;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error\n   process the SelectionNotify X event, uses XSelectionEvent\n   typedef struct {\n     int type;             // SelectionNotify\n     unsigned long serial; // # of last request processed by server\n     Bool send_event;      // true if this came from a SendEvent request\n     Display *display;     // Display the event was read from\n     Window requestor;\n     Atom selection;\n     Atom target;\n     Atom property;        // atom or None\n     Time time;\n   } XSelectionEvent; */\nstatic int\nclipboard_event_selection_notify(XEvent *xevent)\n{\n    XSelectionEvent *lxevent;\n    char *data;\n    int data_size;\n    int n_items;\n    int fmt;\n    int rv;\n    int index;\n    int got_string;\n    int got_utf8;\n    int got_bmp_image;\n    int send_format_announce;\n    Atom got_file_atom;\n    Atom atom;\n    Atom *atoms;\n    Atom type;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify:\");\n    data_size = 0;\n    n_items = 0;\n    fmt = 0;\n    got_string = 0;\n    got_utf8 = 0;\n    got_bmp_image = 0;\n    got_file_atom = 0;\n    send_format_announce = 0;\n    rv = 0;\n    data = 0;\n    type = 0;\n    lxevent = (XSelectionEvent *)xevent;\n\n    if (lxevent->property == None)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_event_selection_notify: clip could \"\n                  \"not be converted\");\n        rv = 1;\n    }\n\n    if (rv == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify: wnd 0x%lx prop %s\",\n                  lxevent->requestor,\n                  get_atom_text(lxevent->property));\n        rv = clipboard_get_window_property(lxevent->requestor, lxevent->property,\n                                           &type, &fmt,\n                                           &n_items, &data, &data_size);\n        if (rv != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_event_selection_notify: \"\n                      \"clipboard_get_window_property failed error %d\", rv);\n            return 0;\n        }\n        //LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", data, data_size);\n        XDeleteProperty(g_display, lxevent->requestor, lxevent->property);\n        if (type == g_incr_atom)\n        {\n            /* nothing more to do here, the data is coming in through\n               PropertyNotify */\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify: type is INCR \"\n                      \"data_size %d property name %s type %s\", data_size,\n                      get_atom_text(lxevent->property),\n                      get_atom_text(lxevent->type));\n            g_clip_s2c.incr_in_progress = 1;\n            g_clip_s2c.property = lxevent->property;\n            g_clip_s2c.type = lxevent->target;\n            g_clip_s2c.total_bytes = 0;\n            g_free(g_clip_s2c.data);\n            g_clip_s2c.data = 0;\n            //LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", data, sizeof(long));\n            g_free(data);\n            return 0;\n        }\n    }\n\n    if (rv == 0)\n    {\n        if (lxevent->selection == g_clipboard_atom)\n        {\n            if (lxevent->target == g_targets_atom)\n            {\n                /* 32 implies long */\n                if ((type == XA_ATOM) && (fmt == 32))\n                {\n                    atoms = (Atom *)data;\n                    for (index = 0; index < n_items; index++)\n                    {\n                        atom = atoms[index];\n                        LOG_DEVEL(LOG_LEVEL_DEBUG,\n                                  \"clipboard_event_selection_notify: 0x%lx %s 0x%lx\",\n                                  atom, get_atom_text(atom), XA_STRING);\n                        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify: 0x%lx %s\",\n                                  atom, get_atom_text(atom));\n                        if (atom == g_utf8_atom)\n                        {\n                            got_utf8 = 1;\n                        }\n                        else if (atom == XA_STRING)\n                        {\n                            got_string = 1;\n                        }\n                        else if (atom == g_image_bmp_atom)\n                        {\n                            got_bmp_image = 1;\n                        }\n                        else if ((atom == g_file_atom1) || (atom == g_file_atom2))\n                        {\n                            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify: file\");\n                            got_file_atom = atom;\n                        }\n                        else\n                        {\n                            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_event_selection_notify: unknown atom 0x%lx\", atom);\n                        }\n                    }\n                }\n                else\n                {\n                    LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_event_selection_notify: error, \"\n                              \"target is 'TARGETS' and type[%ld] or fmt[%d] not right, \"\n                              \"should be type[%ld], fmt[%d]\", type, fmt, XA_ATOM, 32);\n                }\n            }\n            else if (lxevent->target == g_utf8_atom)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify: UTF8_STRING \"\n                          \"data_size %d\", data_size);\n                if ((g_clip_s2c.incr_in_progress == 0) && (data_size >= 0))\n                {\n                    g_free(g_clip_s2c.data);\n                    g_clip_s2c.total_bytes = data_size;\n                    g_clip_s2c.data = (char *) g_malloc(g_clip_s2c.total_bytes + 1, 0);\n                    g_memcpy(g_clip_s2c.data, data, g_clip_s2c.total_bytes);\n                    g_clip_s2c.data[g_clip_s2c.total_bytes] = 0;\n                    if (g_clip_s2c.xrdp_clip_type == XRDP_CB_FILE)\n                    {\n                        if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_FILE)\n                        {\n                            LOG(LOG_LEVEL_DEBUG,\n                                \"outbound clipboard(file) UTF8_STRING(%s) is restricted because of config\",\n                                g_clip_s2c.data);\n                        }\n                        else\n                        {\n                            clipboard_send_data_response_for_file(g_clip_s2c.data,\n                                                                  g_clip_s2c.total_bytes);\n                        }\n                    }\n                    else\n                    {\n                        if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_TEXT)\n                        {\n                            LOG(LOG_LEVEL_DEBUG,\n                                \"outbound clipboard(text) UTF8_STRING(%s) is restricted because of config\",\n                                g_clip_s2c.data);\n                        }\n                        else\n                        {\n                            clipboard_send_data_response_for_text(g_clip_s2c.data,\n                                                                  g_clip_s2c.total_bytes);\n                        }\n                    }\n\n                }\n            }\n            else if (lxevent->target == XA_STRING)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify: XA_STRING \"\n                          \"data_size %d\", data_size);\n                if ((g_clip_s2c.incr_in_progress == 0) && (data_size > 0))\n                {\n                    g_free(g_clip_s2c.data);\n                    g_clip_s2c.total_bytes = data_size;\n                    g_clip_s2c.data = (char *) g_malloc(g_clip_s2c.total_bytes + 1, 0);\n                    g_memcpy(g_clip_s2c.data, data, g_clip_s2c.total_bytes);\n                    g_clip_s2c.data[g_clip_s2c.total_bytes] = 0;\n                    if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_TEXT)\n                    {\n                        LOG(LOG_LEVEL_DEBUG,\n                            \"outbound clipboard(text) XA_STRING(%s) is restricted because of config\",\n                            g_clip_s2c.data);\n                    }\n                    else\n                    {\n                        clipboard_send_data_response_for_text(g_clip_s2c.data,\n                                                              g_clip_s2c.total_bytes);\n                    }\n\n                }\n            }\n            else if (lxevent->target == g_image_bmp_atom)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify: image/bmp \"\n                          \"data_size %d\", data_size);\n                if ((g_clip_s2c.incr_in_progress == 0) && (data_size > 14))\n                {\n                    g_free(g_clip_s2c.data);\n\n                    if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_IMAGE)\n                    {\n                        LOG(LOG_LEVEL_DEBUG,\n                            \"outbound clipboard(image) image/bmp is restricted because of config\");\n                    }\n                    else\n                    {\n                        g_clip_s2c.total_bytes = data_size;\n                        g_clip_s2c.data = (char *) g_malloc(data_size, 0);\n                        g_memcpy(g_clip_s2c.data, data, data_size);\n                        clipboard_send_data_response_for_image(g_clip_s2c.data + 14,\n                                                               data_size - 14);\n                    }\n\n                }\n            }\n            else if (lxevent->target == g_file_atom1)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify: text/uri-list \"\n                          \"data_size %d\", data_size);\n                if ((g_clip_s2c.incr_in_progress == 0) && (data_size > 0))\n                {\n                    g_free(g_clip_s2c.data);\n                    g_clip_s2c.total_bytes = data_size;\n                    g_clip_s2c.data = (char *) g_malloc(g_clip_s2c.total_bytes + 1, 0);\n                    g_memcpy(g_clip_s2c.data, data, g_clip_s2c.total_bytes);\n                    g_clip_s2c.data[g_clip_s2c.total_bytes] = 0;\n                    if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_FILE)\n                    {\n                        LOG(LOG_LEVEL_DEBUG,\n                            \"outbound clipboard(file) text/uri-list(%s) is restricted because of config\",\n                            g_clip_s2c.data);\n                    }\n                    else\n                    {\n                        clipboard_send_data_response_for_file(g_clip_s2c.data,\n                                                              g_clip_s2c.total_bytes);\n\n                    }\n\n                }\n            }\n            else if (lxevent->target == g_file_atom2)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_notify: x-special/gnome-copied-files \"\n                          \"data_size %d\", data_size);\n                if ((g_clip_s2c.incr_in_progress == 0) && (data_size > 0))\n                {\n                    g_free(g_clip_s2c.data);\n                    g_clip_s2c.total_bytes = data_size;\n                    g_clip_s2c.data = (char *) g_malloc(g_clip_s2c.total_bytes + 1, 0);\n                    g_memcpy(g_clip_s2c.data, data, g_clip_s2c.total_bytes);\n                    g_clip_s2c.data[g_clip_s2c.total_bytes] = 0;\n                    if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_FILE)\n                    {\n                        LOG(LOG_LEVEL_DEBUG,\n                            \"outbound clipboard(file) x-special/gnome-copied-files(%s) is restricted because of config\",\n                            g_clip_s2c.data);\n                    }\n                    else\n                    {\n                        clipboard_send_data_response_for_file(g_clip_s2c.data,\n                                                              g_clip_s2c.total_bytes);\n                    }\n\n                }\n            }\n            else\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_event_selection_notify: \"\n                          \"unknown target\");\n            }\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_event_selection_notify: \"\n                      \"unknown selection\");\n        }\n    }\n\n    if (got_file_atom != 0)\n    {\n        /* text/uri-list or x-special/gnome-copied-files */\n\n        if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_FILE)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"outbound clipboard(file) is restricted because of config\");\n        }\n        else\n        {\n            g_clip_s2c.type = got_file_atom;\n            g_clip_s2c.xrdp_clip_type = XRDP_CB_FILE;\n            g_clip_s2c.converted = 0;\n            g_clip_s2c.clip_time = lxevent->time;\n            send_format_announce = 1;\n        }\n\n    }\n    else if (got_utf8)\n    {\n\n        if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_TEXT)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"outbound clipboard(text) is restricted because of config\");\n        }\n        else\n        {\n            g_clip_s2c.type = g_utf8_atom;\n            g_clip_s2c.xrdp_clip_type = XRDP_CB_TEXT;\n            g_clip_s2c.converted = 0;\n            g_clip_s2c.clip_time = lxevent->time;\n            send_format_announce = 1;\n        }\n\n    }\n    else if (got_string)\n    {\n\n        /*\n         * In most cases, when copying text, TARGETS atom and UTF8_STRING atom exists,\n         * it means that this code block which checks STRING atom might not be never executed\n         * in recent platforms.\n         * Use echo foo | xclip -selection clipboard -noutf8 to reproduce it.\n         */\n        if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_TEXT)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"outbound clipboard(text) is restricted because of config\");\n        }\n        else\n        {\n            g_clip_s2c.type = XA_STRING;\n            g_clip_s2c.xrdp_clip_type = XRDP_CB_TEXT;\n            g_clip_s2c.converted = 0;\n            g_clip_s2c.clip_time = lxevent->time;\n            send_format_announce = 1;\n        }\n\n    }\n    else if (got_bmp_image)\n    {\n\n        if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_IMAGE)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"outbound clipboard(image) is restricted because of config\");\n        }\n        else\n        {\n            g_clip_s2c.type = g_image_bmp_atom;\n            g_clip_s2c.xrdp_clip_type = XRDP_CB_BITMAP;\n            g_clip_s2c.converted = 0;\n            g_clip_s2c.clip_time = lxevent->time;\n            send_format_announce = 1;\n        }\n\n    }\n\n    if (send_format_announce)\n    {\n        if (clipboard_send_format_announce(g_clip_s2c.xrdp_clip_type) != 0)\n        {\n            rv = 4;\n        }\n    }\n\n    g_free(data);\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error\n   process the SelectionRequest X event, uses XSelectionRequestEvent\n   typedef struct {\n     int type;             // SelectionRequest\n     unsigned long serial; // # of last request processed by server\n     Bool send_event;      // true if this came from a SendEvent request\n     Display *display;     // Display the event was read from\n     Window owner;\n     Window requestor;\n     Atom selection;\n     Atom target;\n     Atom property;\n     Time time;\n   } XSelectionRequestEvent; */\n/*\n * When XGetWindowProperty and XChangeProperty talk about \"format 32\" it\n * doesn't mean a 32bit value, but actually a long. So 32 means 4 bytes on\n * a 32bit machine and 8 bytes on a 64 machine\n */\nstatic int\nclipboard_event_selection_request(XEvent *xevent)\n{\n    XSelectionRequestEvent *lxev;\n    Atom atom_buf[10];\n    Atom type;\n    int atom_count;\n    int fmt;\n    int n_items;\n    int xdata_size;\n    char *xdata;\n\n    lxev = (XSelectionRequestEvent *)xevent;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: 0x%lx\", lxev->property);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: g_wnd %ld, \"\n              \".requestor %ld .owner %ld .selection %ld '%s' .target %ld .property %ld\",\n              g_wnd, lxev->requestor, lxev->owner, lxev->selection,\n              get_atom_text(lxev->selection),\n              lxev->target, lxev->property);\n\n    if (lxev->property == None)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: \"\n                  \"lxev->property is None\");\n    }\n    else if (lxev->target == g_targets_atom)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: g_targets_atom\");\n        /* requestor is asking what the selection can be converted to */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: \"\n                  \"g_targets_atom\");\n        atom_buf[0] = g_targets_atom;\n        atom_buf[1] = g_timestamp_atom;\n        atom_buf[2] = g_multiple_atom;\n        atom_count = 3;\n\n        /* Only announce text if the client is advertising text, or\n         * a file list */\n        if (clipboard_find_format_id(CF_UNICODETEXT) >= 0 ||\n                clipboard_find_format_id(CF_OEMTEXT) >= 0 ||\n                clipboard_find_format_id(CF_TEXT) >= 0 ||\n                clipboard_find_format_id(g_file_group_descriptor_format_id) >= 0)\n        {\n            if ((g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_TEXT) == 0)\n            {\n                atom_buf[atom_count] = XA_STRING;\n                atom_count++;\n                atom_buf[atom_count] = g_utf8_atom;\n                atom_count++;\n            }\n        }\n        if (clipboard_find_format_id(CF_DIB) >= 0 &&\n                (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_IMAGE) == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  reporting image/bmp\");\n            atom_buf[atom_count] = g_image_bmp_atom;\n            atom_count++;\n        }\n        if (clipboard_find_format_id(g_file_group_descriptor_format_id) >= 0 &&\n                (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE) == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  reporting text/uri-list\");\n            atom_buf[atom_count] = g_file_atom1;\n            atom_count++;\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  reporting x-special/gnome-copied-files\");\n            atom_buf[atom_count] = g_file_atom2;\n            atom_count++;\n        }\n        atom_buf[atom_count] = 0;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  reporting %d formats\", atom_count);\n        return clipboard_provide_selection(lxev, XA_ATOM, 32,\n                                           (char *)atom_buf, atom_count);\n    }\n    else if (lxev->target == g_timestamp_atom)\n    {\n        /* requestor is asking the time I got the selection */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: \"\n                  \"g_timestamp_atom\");\n        atom_buf[0] = g_selection_time;\n        atom_buf[1] = 0;\n        return clipboard_provide_selection(lxev, XA_INTEGER, 32,\n                                           (char *)atom_buf, 1);\n    }\n    else if (lxev->target == g_multiple_atom)\n    {\n        /* target, property pairs */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: \"\n                  \"g_multiple_atom\");\n\n        xdata = 0;\n        if (clipboard_get_window_property(lxev->requestor, lxev->property,\n                                          &type, &fmt, &n_items, &xdata,\n                                          &xdata_size) == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: g_multiple_atom \"\n                      \"n_items %d\", n_items);\n            /* todo */\n            g_free(xdata);\n        }\n    }\n    else if ((lxev->target == XA_STRING) || (lxev->target == g_utf8_atom))\n    {\n        if (clipboard_find_format_id(g_file_group_descriptor_format_id) >= 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: \"\n                      \"text requested when files available\");\n\n            if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)\n            {\n                LOG(LOG_LEVEL_DEBUG,\n                    \"inbound clipboard %s is restricted because of config\",\n                    lxev->target == XA_STRING ? \"XA_STRING\" : \"UTF8_STRING\");\n                clipboard_refuse_selection(lxev);\n            }\n            else\n            {\n                g_memcpy(&g_saved_selection_req_event, lxev,\n                         sizeof(g_saved_selection_req_event));\n                g_clip_c2s.type = lxev->target;\n                g_clip_c2s.xrdp_clip_type = XRDP_CB_FILE;\n                clipboard_send_data_request(g_file_group_descriptor_format_id);\n            }\n\n        }\n        else\n        {\n\n            if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_TEXT)\n            {\n                LOG(LOG_LEVEL_DEBUG,\n                    \"inbound clipboard %s is restricted because of config\",\n                    lxev->target == XA_STRING ? \"XA_STRING\" : \"UTF8_STRING\");\n                clipboard_refuse_selection(lxev);\n            }\n            else\n            {\n                /* The client may have advertised CF_TEXT or CF_OEMTEXT,\n                 * but the Windows clipboard will convert these formats\n                 * to Unicode if asked */\n                g_memcpy(&g_saved_selection_req_event, lxev,\n                         sizeof(g_saved_selection_req_event));\n                g_clip_c2s.type = lxev->target;\n                g_clip_c2s.xrdp_clip_type = XRDP_CB_TEXT;\n                clipboard_send_data_request(CF_UNICODETEXT);\n            }\n\n        }\n        return 0;\n    }\n    else if (lxev->target == g_image_bmp_atom)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: image/bmp\");\n        if ((g_clip_c2s.type == lxev->target) && g_clip_c2s.converted)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: -------------------------------------------\");\n\n            if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_IMAGE)\n            {\n                LOG(LOG_LEVEL_DEBUG,\n                    \"inbound clipboard image/bmp converted is restricted because of config\");\n                clipboard_refuse_selection(lxev);\n            }\n            else\n            {\n                clipboard_provide_selection_c2s(lxev, lxev->target);\n            }\n            return 0;\n\n        }\n\n        if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_IMAGE)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"inbound clipboard image/bmp is restricted because of config\");\n            clipboard_refuse_selection(lxev);\n        }\n        else\n        {\n            g_memcpy(&g_saved_selection_req_event, lxev,\n                     sizeof(g_saved_selection_req_event));\n            g_clip_c2s.type = g_image_bmp_atom;\n            g_clip_c2s.xrdp_clip_type = XRDP_CB_BITMAP;\n            clipboard_send_data_request(CF_DIB);\n        }\n        return 0;\n\n    }\n    else if (lxev->target == g_file_atom1)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: g_file_atom1\");\n        if ((g_clip_c2s.type == lxev->target) && g_clip_c2s.converted)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: -------------------------------------------\");\n            if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)\n            {\n                LOG(LOG_LEVEL_DEBUG,\n                    \"inbound clipboard text/uri-list is restricted because of config\");\n                clipboard_refuse_selection(lxev);\n                return 0;\n            }\n            else\n            {\n                clipboard_provide_selection_c2s(lxev, lxev->target);\n                return 0;\n            }\n        }\n        if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"inbound clipboard text/uri-list is restricted because of config\");\n            clipboard_refuse_selection(lxev);\n            return 0;\n        }\n        else\n        {\n            g_memcpy(&g_saved_selection_req_event, lxev,\n                     sizeof(g_saved_selection_req_event));\n            g_clip_c2s.type = g_file_atom1;\n            g_clip_c2s.xrdp_clip_type = XRDP_CB_FILE;\n            clipboard_send_data_request(g_file_group_descriptor_format_id);\n            return 0;\n        }\n\n    }\n    else if (lxev->target == g_file_atom2)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: g_file_atom2\");\n\n        if ((g_clip_c2s.type == lxev->target) && g_clip_c2s.converted)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_request: -------------------------------------------\");\n            if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)\n            {\n                LOG(LOG_LEVEL_DEBUG,\n                    \"inbound clipboard x-special/gnome-copied-files converted is restricted because of config\");\n                clipboard_refuse_selection(lxev);\n                return 0;\n            }\n            else\n            {\n                clipboard_provide_selection_c2s(lxev, lxev->target);\n                return 0;\n            }\n        }\n        if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"inbound clipboard x-special/gnome-copied-files is restricted because of config\");\n            clipboard_refuse_selection(lxev);\n            return 0;\n        }\n        else\n        {\n            g_memcpy(&g_saved_selection_req_event, lxev,\n                     sizeof(g_saved_selection_req_event));\n            g_clip_c2s.type = g_file_atom2;\n            g_clip_c2s.xrdp_clip_type = XRDP_CB_FILE;\n            clipboard_send_data_request(g_file_group_descriptor_format_id);\n            return 0;\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_event_selection_request: unknown \"\n            \"target %s\", get_atom_text(lxev->target));\n    }\n\n    clipboard_refuse_selection(lxev);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error\n   process the SelectionClear X event, uses XSelectionClearEvent\n   typedef struct {\n     int type;                // SelectionClear\n     unsigned long serial;    // # of last request processed by server\n     Bool send_event;         // true if this came from a SendEvent request\n     Display *display;        // Display the event was read from\n     Window window;\n     Atom selection;\n     Time time;\n} XSelectionClearEvent; */\nstatic int\nclipboard_event_selection_clear(XEvent *xevent)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_selection_clear:\");\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error\n   typedef struct {\n     int type;                // PropertyNotify\n     unsigned long serial;    // # of last request processed by server\n     Bool send_event;         // true if this came from a SendEvent request\n     Display *display;        // Display the event was read from\n     Window window;\n     Atom atom;\n     Time time;\n     int state;               // PropertyNewValue or PropertyDelete\n} XPropertyEvent; */\nstatic int\nclipboard_event_property_notify(XEvent *xevent)\n{\n    Atom actual_type_return;\n    int actual_format_return;\n    unsigned long nitems_returned;\n    unsigned long bytes_left;\n    unsigned char *data;\n    int rv;\n    int format_in_bytes;\n    int new_data_len;\n    int data_bytes;\n    char *cptr;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_property_notify: PropertyNotify .window %ld \"\n              \".state %d .atom %ld %s\", xevent->xproperty.window,\n              xevent->xproperty.state, xevent->xproperty.atom,\n              get_atom_text(xevent->xproperty.atom));\n\n    if (g_clip_c2s.incr_in_progress &&\n            (xevent->xproperty.window == g_clip_c2s.window) &&\n            (xevent->xproperty.atom == g_clip_c2s.property) &&\n            (xevent->xproperty.state == PropertyDelete))\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_property_notify: INCR PropertyDelete\");\n        /* this is used for when copying a large clipboard to the other app,\n           it will delete the property so we know to send the next one */\n\n        if ((g_clip_c2s.data == 0) || (g_clip_c2s.total_bytes < 1))\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_property_notify: INCR error\");\n            return 0;\n        }\n        data = (tui8 *)(g_clip_c2s.data + g_clip_c2s.incr_bytes_done);\n        data_bytes = g_clip_c2s.read_bytes_done - g_clip_c2s.incr_bytes_done;\n        if ((data_bytes < 1) &&\n                (g_clip_c2s.read_bytes_done < g_clip_c2s.total_bytes))\n        {\n            g_clip_c2s.incr_in_progress = 0;\n            return 0;\n        }\n        if (data_bytes > g_incr_max_req_size)\n        {\n            data_bytes = g_incr_max_req_size;\n        }\n        g_clip_c2s.incr_bytes_done += data_bytes;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_property_notify: data_bytes %d\", data_bytes);\n        XChangeProperty(xevent->xproperty.display, xevent->xproperty.window,\n                        xevent->xproperty.atom, g_clip_c2s.type, 8,\n                        PropModeReplace, data, data_bytes);\n        if (data_bytes < 1)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_property_notify: INCR done\");\n            g_clip_c2s.incr_in_progress = 0;\n            /* we no longer need property notify */\n            XSelectInput(xevent->xproperty.display, xevent->xproperty.window,\n                         NoEventMask);\n            g_clip_c2s.converted = 1;\n        }\n    }\n    if (g_clip_s2c.incr_in_progress &&\n            (xevent->xproperty.window == g_wnd) &&\n            (xevent->xproperty.atom == g_clip_s2c.property) &&\n            (xevent->xproperty.state == PropertyNewValue))\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_property_notify: INCR PropertyNewValue\");\n        rv = XGetWindowProperty(g_display, g_wnd, g_clip_s2c.property, 0, 0, 0,\n                                AnyPropertyType, &actual_type_return, &actual_format_return,\n                                &nitems_returned, &bytes_left, &data);\n\n        if (rv != Success)\n        {\n            return 1;\n        }\n\n        if (data != 0)\n        {\n            XFree(data);\n            data = 0;\n        }\n\n        if (bytes_left <= 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_property_notify: INCR done\");\n            /* clipboard INCR cycle has completed */\n            g_clip_s2c.incr_in_progress = 0;\n            if (g_clip_s2c.type == g_image_bmp_atom)\n            {\n                g_clip_s2c.xrdp_clip_type = XRDP_CB_BITMAP;\n                //LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", g_last_clip_data, 64);\n                /* skip header */\n                clipboard_send_data_response(g_clip_s2c.xrdp_clip_type,\n                                             g_clip_s2c.data + 14,\n                                             g_clip_s2c.total_bytes - 14);\n            }\n            else if ((g_clip_s2c.type == XA_STRING) ||\n                     (g_clip_s2c.type == g_utf8_atom))\n            {\n                g_clip_s2c.xrdp_clip_type = XRDP_CB_TEXT;\n                clipboard_send_data_response(g_clip_s2c.xrdp_clip_type,\n                                             g_clip_s2c.data,\n                                             g_clip_s2c.total_bytes);\n            }\n            else\n            {\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_event_property_notify: error unknown type %ld\",\n                          g_clip_s2c.type);\n                clipboard_send_data_response_failed();\n            }\n\n            XDeleteProperty(g_display, g_wnd, g_clip_s2c.property);\n        }\n        else\n        {\n            rv = XGetWindowProperty(g_display, g_wnd, g_clip_s2c.property, 0, bytes_left, 0,\n                                    AnyPropertyType, &actual_type_return, &actual_format_return,\n                                    &nitems_returned, &bytes_left, &data);\n\n            if (rv != Success)\n            {\n                return 1;\n            }\n\n            format_in_bytes = FORMAT_TO_BYTES(actual_format_return);\n            new_data_len = nitems_returned * format_in_bytes;\n            cptr = (char *) g_malloc(g_clip_s2c.total_bytes + new_data_len, 0);\n            if (cptr == NULL)\n            {\n                /* cannot add any more data */\n                g_free(g_clip_s2c.data);\n                g_clip_s2c.data = 0;\n\n                if (data != 0)\n                {\n                    XFree(data);\n                }\n\n                XDeleteProperty(g_display, g_wnd, g_clip_s2c.property);\n                return 0;\n            }\n            g_memcpy(cptr, g_clip_s2c.data, g_clip_s2c.total_bytes);\n            g_free(g_clip_s2c.data);\n\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_event_property_notify: new_data_len %d\", new_data_len);\n            g_clip_s2c.data = cptr;\n            if (data)\n            {\n                g_memcpy(g_clip_s2c.data + g_clip_s2c.total_bytes, data, new_data_len);\n                g_clip_s2c.total_bytes += new_data_len;\n                XFree(data);\n            }\n\n            XDeleteProperty(g_display, g_wnd, g_clip_s2c.property);\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns 0, event handled, 1 unhandled */\nint\nclipboard_xevent(void *xevent)\n{\n    XEvent *lxevent;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_xevent: event detected\");\n\n    if (!g_clip_up)\n    {\n        return 1;\n    }\n\n    lxevent = (XEvent *)xevent;\n\n    switch (lxevent->type)\n    {\n        case SelectionNotify:\n            clipboard_event_selection_notify(lxevent);\n            break;\n        case SelectionRequest:\n            clipboard_event_selection_request(lxevent);\n            break;\n        case SelectionClear:\n            clipboard_event_selection_clear(lxevent);\n            break;\n        case MappingNotify:\n            break;\n        case PropertyNotify:\n            clipboard_event_property_notify(lxevent);\n            break;\n        case UnmapNotify:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::clipboard_xevent: got UnmapNotify\");\n            break;\n        case ClientMessage:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::clipboard_xevent: got ClientMessage\");\n            break;\n        default:\n\n            if (lxevent->type == g_xfixes_event_base +\n                    XFixesSetSelectionOwnerNotify)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_xevent: got XFixesSetSelectionOwnerNotify\");\n                clipboard_event_selection_owner_notify(lxevent);\n                break;\n            }\n            if (lxevent->type == g_xfixes_event_base +\n                    XFixesSelectionWindowDestroyNotify)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_xevent: got XFixesSelectionWindowDestroyNotify\");\n                break;\n            }\n            if (lxevent->type == g_xfixes_event_base +\n                    XFixesSelectionClientCloseNotify)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_xevent: got XFixesSelectionClientCloseNotify\");\n                break;\n            }\n\n            /* we didn't handle this message */\n            return 1;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "sesman/chansrv/clipboard.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2009-2013\n * Copyright (C) Laxmikant Rashinkar 2012-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(CLIPBOARD_H)\n#define CLIPBOARD_H\n\n#include \"arch.h\"\n#include \"parse.h\"\n\nint clipboard_init(void);\nint clipboard_deinit(void);\nint clipboard_data_in(struct stream *s, int chan_id, int chan_flags, int length, int total_length);\nint clipboard_xevent(void *xevent);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/clipboard_common.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(CLIPBOARD_COMMON_H)\n#define CLIPBOARD_COMMON_H\n\n#include \"arch.h\"\n#include \"parse.h\"\n\n/* these are the supported general types */\n#define XRDP_CB_TEXT   1\n#define XRDP_CB_BITMAP 2\n#define XRDP_CB_FILE   3\n\nstruct clip_s2c /* server to client, pasting from linux app to mstsc */\n{\n    int incr_in_progress;\n    int total_bytes;\n    char *data;\n    Atom type; /* UTF8_STRING, image/bmp, ... */\n    Atom property; /* XRDP_CLIP_PROPERTY_ATOM, _QT_SELECTION, ... */\n    int xrdp_clip_type; /* XRDP_CB_TEXT, XRDP_CB_BITMAP, XRDP_CB_FILE, ... */\n    int converted;\n    Time clip_time;\n};\n\nstruct clip_c2s /* client to server, pasting from mstsc to linux app */\n{\n    int incr_in_progress;\n    int incr_bytes_done;\n    int read_bytes_done;\n    int total_bytes;\n    char *data;\n    Atom type; /* UTF8_STRING, image/bmp, ... */\n    Atom property; /* XRDP_CLIP_PROPERTY_ATOM, _QT_SELECTION, ... */\n    Window window; /* Window used in INCR transfer */\n    int xrdp_clip_type; /* XRDP_CB_TEXT, XRDP_CB_BITMAP, XRDP_CB_FILE, ... */\n    int converted;\n    int in_request; /* a data request has been sent to client */\n};\n\nstruct clip_file_desc /* CLIPRDR_FILEDESCRIPTOR */\n{\n    tui32 flags;\n    tui32 fileAttributes;\n    tui32 lastWriteTimeLow;\n    tui32 lastWriteTimeHigh;\n    tui32 fileSizeHigh;\n    tui32 fileSizeLow;\n    char cFileName[260 * 4]; /* Allow each UCS-16 char to become 32 bits */\n};\n\n/**\n * Input a terminated UTF-16 string from a stream as UTF-8.\n * @param s stream\n * @param text UTF-8 String buffer\n * @param num_chars Length of above\n * @return number of bytes copied from stream\n */\nunsigned int\nclipboard_in_utf16_le_as_utf8(struct stream *s, char *text,\n                              unsigned int num_chars);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/clipboard_file.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/* MS-RDPECLIP\n * http://msdn.microsoft.com/en-us/library/cc241066%28prot.20%29.aspx\n *\n * CLIPRDR_FILEDESCRIPTOR\n * http://msdn.microsoft.com/en-us/library/ff362447%28prot.20%29.aspx */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <ctype.h>\n#include <sys/time.h>\n#include <X11/Xlib.h>\n#include <X11/Xatom.h>\n#include <X11/extensions/Xfixes.h>\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"list.h\"\n#include \"chansrv.h\"\n#include \"clipboard.h\"\n#include \"clipboard_file.h\"\n#include \"clipboard_common.h\"\n#include \"xcommon.h\"\n#include \"chansrv_fuse.h\"\n#include \"ms-rdpeclip.h\"\n\nextern int g_cliprdr_chan_id; /* in chansrv.c */\n\nextern struct clip_s2c g_clip_s2c; /* in clipboard.c */\nextern struct clip_c2s g_clip_c2s; /* in clipboard.c */\n\nextern char g_fuse_clipboard_path[];\n\nstruct cb_file_info\n{\n    char *pathname;\n    char *filename;\n    int flags;\n    int size;\n    tui64 time;\n};\n\nstatic struct list *g_files_list = 0;\n\n/* used when server is asking for file info from the client */\nstatic int g_file_request_sent_type = 0;\n\n/* number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC */\n#define CB_EPOCH_DIFF 11644473600LL\n\n/*****************************************************************************/\n#if 0\nstatic tui64\ntimeval2wintime(struct timeval *tv)\n{\n    tui64 result;\n\n    result = CB_EPOCH_DIFF;\n    result += tv->tv_sec;\n    result *= 10000000LL;\n    result += tv->tv_usec * 10;\n    return result;\n}\n#endif\n\n/**\n * Gets a useable filename from a file specification passed to us\n *\n * The passed-in specification may contain instances of RFC3986 encoded\n * octets '%xx' where 'x' is a hex digit (e.g. %20 == ASCII SPACE). For\n * UTF-8, there may be many of these (e.g. %E6%97%A5 maps to the U+65E5\n * Unicode character)\n *\n * The result must be free'd by the caller.\n */\nstatic char *\ndecode_rfc3986(const char *rfc3986, int len)\n{\n    char *result = (char *)malloc(len + 1);\n    if (result != NULL)\n    {\n        int i = 0;\n        int j = 0;\n        /* Copy the passed-in filename so we can modify it */\n        while (i < len)\n        {\n            /* Check for %xx for a character (e.g. %20 == ASCII 32 == SPACE) */\n            if (rfc3986[i] == '%' && (len - i) > 2 &&\n                    isxdigit(rfc3986[i + 1]) && isxdigit(rfc3986[i + 2]))\n            {\n                const char jchr[] = { rfc3986[i + 1], rfc3986[i + 2], '\\0' };\n                result[j++] = g_htoi(jchr);\n                i += 3;\n            }\n            else\n            {\n                result[j++] = rfc3986[i++];\n            }\n        }\n        result[j] = '\\0';\n    }\n\n    return result;\n}\n\n/**\n * Allocates a alloc_cb_file_info struct\n *\n * The memory for the struct is allocated in such a way that a single\n * free() call can be used to de-allocate it\n *\n * Filename elements are copied into the struct\n */\nstatic struct cb_file_info *\nalloc_cb_file_info(const char *full_name)\n{\n    struct cb_file_info *result = NULL;\n\n    /* Find the last path separator in the string */\n    const char *psep = strrchr(full_name, '/');\n\n    /* Separate the name into a path and an unqualified name */\n    const char *path_ptr = \"/\";\n    unsigned int path_len = 1;\n    const char *name_ptr;\n\n    if (psep == NULL)\n    {\n        name_ptr = full_name;\n    }\n    else if (psep == full_name)\n    {\n        name_ptr = full_name + 1;\n    }\n    else\n    {\n        path_ptr = full_name;\n        path_len = psep - full_name;\n        name_ptr = psep + 1;\n    }\n\n    /* Allocate a block big enough for the struct, and\n     * for both the strings */\n    unsigned int name_len = strlen(name_ptr);\n    unsigned int alloc_size = sizeof(struct cb_file_info) +\n                              (path_len + 1) + (name_len + 1);\n\n    result = (struct cb_file_info *)malloc(alloc_size);\n    if (result != NULL)\n    {\n        /* Get a pointer to the first byte past the struct */\n        result->pathname = (char *)(result + 1);\n        result->filename = result->pathname + path_len + 1;\n        memcpy(result->pathname, path_ptr, path_len);\n        result->pathname[path_len] = '\\0';\n        memcpy(result->filename, name_ptr, name_len);\n        result->filename[name_len] = '\\0';\n    }\n\n    return result;\n}\n\n/***\n * See MS-RDPECLIP 3.1.5.4.7\n *\n * Sends a failure response to a CLIPRDR_FILECONTENTS_REQUEST\n * @param streamId Stream ID from CLIPRDR_FILECONTENTS_REQUEST\n * @return 0 for success\n */\n\nstatic int\nclipboard_send_filecontents_response_fail(int streamId)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"clipboardn_send_filecontents_response_fail:\");\n\n    struct stream *s;\n    int size;\n    int rv;\n\n    make_stream(s);\n    init_stream(s, 64);\n\n    out_uint16_le(s, CB_FILECONTENTS_RESPONSE);\n    out_uint16_le(s, CB_RESPONSE_FAIL);\n    out_uint32_le(s, 4);\n    out_uint32_le(s, streamId);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nclipboard_get_file(const char *file, int bytes)\n{\n    char *full_fn;\n    struct cb_file_info *cfi;\n    int result = 1;\n\n    /* x-special/gnome-copied-files */\n    if ((g_strncmp(file, \"copy\", 4) == 0) && (bytes == 4))\n    {\n        return 0;\n    }\n    if ((g_strncmp(file, \"cut\", 3) == 0) && (bytes == 3))\n    {\n        return 0;\n    }\n\n    /* text/uri-list */\n    /* x-special/gnome-copied-files */\n    if (bytes > 7 && g_strncmp(file, \"file://\", 7) == 0)\n    {\n        full_fn = decode_rfc3986(file + 7, bytes - 7);\n    }\n    else\n    {\n        full_fn = decode_rfc3986(file, bytes);\n    }\n\n    if (full_fn == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_get_file: Out of memory\");\n        return 1;\n    }\n\n    /*\n     * Before we look at the file, see if it's in the FUSE filesystem. If it is,\n     * we can't call normal file checking functions, as these will result in\n     * a deadlock */\n    if (xfuse_path_in_xfuse_fs(full_fn))\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_get_file: Can't add client-side file \"\n            \"%s to clipboard\", full_fn);\n    }\n    else if (g_directory_exist(full_fn))\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_get_file: file [%s] is a directory, \"\n            \"not supported\", full_fn);\n    }\n    else if (!g_file_exist(full_fn))\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_get_file: file [%s] does not exist\",\n            full_fn);\n    }\n    else if ((cfi = alloc_cb_file_info(full_fn)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_get_file: Out of memory\");\n    }\n    else\n    {\n        list_add_item(g_files_list, (tintptr)cfi);\n        cfi->size = g_file_get_size(full_fn);\n        cfi->flags = CB_FILE_ATTRIBUTE_ARCHIVE;\n        cfi->time = (time(NULL) + CB_EPOCH_DIFF) * 10000000LL;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"ok filename [%s] pathname [%s] size [%d]\",\n                  cfi->filename, cfi->pathname, cfi->size);\n        result = 0;\n    }\n\n    free(full_fn);\n    return result;\n}\n\n/*****************************************************************************/\n/*\n * Calls clipboard_get_file() for each filename in a list.\n *\n * List items are separated by line terminators. Blank items are ignored */\nstatic int\nclipboard_get_files(const char *files, int bytes)\n{\n    const char *start = files;\n    const char *end = files + bytes;\n    const char *p;\n\n    for (p = start ; p < end ; ++p)\n    {\n        if (*p == '\\n' || *p == '\\r')\n        {\n            /* Skip zero-length files (which might be caused by\n             * multiple line terminators */\n            if (p > start)\n            {\n                /* Get file. Errors are logged */\n                (void)clipboard_get_file(start, p - start);\n            }\n\n            /* Move the start of filename pointer to either 'end', or\n             * the next character which will either be a filename or\n             * another terminator */\n            start = p + 1;\n        }\n    }\n    if (end > start)\n    {\n        (void)clipboard_get_file(start, end - start);\n    }\n    if (g_files_list->count < 1)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* server to client */\n/* response to client asking for clipboard contents that is file list */\nint\nclipboard_send_data_response_for_file(const char *data, int data_size)\n{\n    struct stream *s;\n    int size;\n    int rv;\n    int bytes_after_header;\n    int cItems;\n    int flags;\n    int index;\n    tui32 ui32;\n    unsigned int utf8_count;\n    unsigned int utf16_count;\n    struct cb_file_info *cfi;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_data_response_for_file: data_size %d\",\n              data_size);\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", data, data_size);\n    if (g_files_list == 0)\n    {\n        g_files_list = list_create();\n        g_files_list->auto_free = 1;\n    }\n    list_clear(g_files_list);\n    clipboard_get_files(data, data_size);\n    cItems = g_files_list->count;\n    bytes_after_header = cItems * 592 + 4;\n    make_stream(s);\n    init_stream(s, 64 + bytes_after_header);\n    out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */\n    out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */\n    out_uint32_le(s, bytes_after_header);\n    out_uint32_le(s, cItems);\n    for (index = 0; index < cItems; index++)\n    {\n        cfi = (struct cb_file_info *)list_get_item(g_files_list, index);\n        flags = CB_FD_ATTRIBUTES | CB_FD_FILESIZE | CB_FD_WRITESTIME | CB_FD_PROGRESSUI;\n        out_uint32_le(s, flags);\n        out_uint8s(s, 32); /* reserved1 */\n        flags = cfi->flags;\n        out_uint32_le(s, flags);\n        out_uint8s(s, 16); /* reserved2 */\n        /* file time */\n        /* 100-nanoseconds intervals since 1 January 1601 */\n        //out_uint32_le(s, 0x2c305d08); /* 25 October 2009, 21:17 */\n        //out_uint32_le(s, 0x01ca55f3);\n        ui32 = cfi->time & 0xffffffff;\n        out_uint32_le(s, ui32);\n        ui32 = cfi->time >> 32;\n        out_uint32_le(s, ui32);\n        /* file size */\n        out_uint32_le(s, 0);\n        out_uint32_le(s, cfi->size);\n        /* Name is fixed-size 260 UTF-16 words */\n        utf8_count = strlen(cfi->filename) + 1;  // Include terminator\n        utf16_count = utf8_as_utf16_word_count(cfi->filename, utf8_count);\n        if (utf16_count > 260)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"clipboard_send_data_response_for_file:\"\n                \" filename overflow (%u words)\", utf16_count);\n            utf8_count = 0;\n            utf16_count = 0;\n        }\n        out_utf8_as_utf16_le(s, cfi->filename, utf8_count);\n        out_uint8s(s, (260 - utf16_count) * 2);\n    }\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\n/* send the file size from server to the client */\nstatic int\nclipboard_send_file_size(int streamId, int lindex)\n{\n    struct stream *s;\n    int size;\n    int rv;\n    int file_size;\n    struct cb_file_info *cfi;\n\n    if (g_files_list == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_send_file_size: error g_files_list is nil\");\n        clipboard_send_filecontents_response_fail(streamId);\n        return 1;\n    }\n    cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex);\n    if (cfi == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_send_file_size: error cfi is nil\");\n        clipboard_send_filecontents_response_fail(streamId);\n        return 1;\n    }\n    if (cfi->size < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_send_file_size: error cfi->size is negative\"\n            \"value [%d]\", cfi->size);\n        clipboard_send_filecontents_response_fail(streamId);\n        return 1;\n    }\n    file_size = cfi->size;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_file_size: streamId %d file_size %d\",\n              streamId, file_size);\n    make_stream(s);\n    init_stream(s, 8192);\n    out_uint16_le(s, CB_FILECONTENTS_RESPONSE); /* 9 */\n    out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */\n    out_uint32_le(s, 12);\n    out_uint32_le(s, streamId);\n    out_uint32_le(s, file_size);\n    out_uint32_le(s, 0);\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    return rv;\n}\n\n/*****************************************************************************/\n/* ask the client to send the file size */\nint\nclipboard_request_file_size(int stream_id, int lindex)\n{\n    struct stream *s;\n    int size;\n    int rv;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_request_file_size:\");\n    if (g_file_request_sent_type != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_request_file_size: warning, still waiting \"\n                  \"for CB_FILECONTENTS_RESPONSE\");\n    }\n    make_stream(s);\n    init_stream(s, 8192);\n    out_uint16_le(s, CB_FILECONTENTS_REQUEST); /* 8 */\n    out_uint16_le(s, 0);\n    out_uint32_le(s, 28);\n    out_uint32_le(s, stream_id);\n    out_uint32_le(s, lindex);\n    out_uint32_le(s, CB_FILECONTENTS_SIZE);\n    out_uint32_le(s, 0); /* nPositionLow */\n    out_uint32_le(s, 0); /* nPositionHigh */\n    out_uint32_le(s, 0); /* cbRequested */\n    out_uint32_le(s, 0); /* clipDataId */\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    g_file_request_sent_type = CB_FILECONTENTS_SIZE;\n    return rv;\n}\n\n/*****************************************************************************/\n/* send a chunk of the file from server to client */\nstatic int\nclipboard_send_file_data(int streamId, int lindex,\n                         int nPositionLow, int cbRequested)\n{\n    struct stream *s;\n    int size;\n    int rv;\n    int fd;\n    char full_fn[256];\n    struct cb_file_info *cfi;\n\n    if (g_files_list == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_send_file_data: error g_files_list is nil\");\n        clipboard_send_filecontents_response_fail(streamId);\n        return 1;\n    }\n    cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex);\n    if (cfi == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_send_file_data: error cfi is nil\");\n        clipboard_send_filecontents_response_fail(streamId);\n        return 1;\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_send_file_data: streamId %d lindex %d \"\n              \"nPositionLow %d cbRequested %d\", streamId, lindex,\n              nPositionLow, cbRequested);\n    g_snprintf(full_fn, 255, \"%s/%s\", cfi->pathname, cfi->filename);\n    fd = g_file_open_ro(full_fn);\n    if (fd == -1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_send_file_data: file open [%s] failed: %s\",\n            full_fn, g_get_strerror());\n        clipboard_send_filecontents_response_fail(streamId);\n        return 1;\n    }\n    if (g_file_seek(fd, nPositionLow) < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_send_file_data: seek error in file [%s]: %s\",\n            full_fn, g_get_strerror());\n        g_file_close(fd);\n        clipboard_send_filecontents_response_fail(streamId);\n        return 1;\n    }\n    make_stream(s);\n    init_stream(s, cbRequested + 64);\n    size = g_file_read(fd, s->data + 12, cbRequested);\n    // If we're at end-of-file, 0 is a valid response\n    if (size < 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR,\n                  \"clipboard_send_file_data: read error, want %d got [%s]\",\n                  cbRequested, g_get_strerror());\n        free_stream(s);\n        g_file_close(fd);\n        clipboard_send_filecontents_response_fail(streamId);\n        return 1;\n    }\n    out_uint16_le(s, CB_FILECONTENTS_RESPONSE); /* 9 */\n    out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */\n    out_uint32_le(s, size + 4);\n    out_uint32_le(s, streamId);\n    s->p += size;\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    g_file_close(fd);\n\n    /* Log who transferred which file via clipboard for the purpose of audit */\n    LOG(LOG_LEVEL_INFO, \"S2C: Transferred a file: filename=%s, uid=%d\", full_fn, g_getuid());\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* ask the client to send the file size */\nint\nclipboard_request_file_data(int stream_id, int lindex, int offset,\n                            int request_bytes)\n{\n    struct stream *s;\n    int size;\n    int rv;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_request_file_data: stream_id=%d lindex=%d off=%d request_bytes=%d\",\n              stream_id, lindex, offset, request_bytes);\n\n    if (g_file_request_sent_type != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_request_file_data: warning, still waiting \"\n                  \"for CB_FILECONTENTS_RESPONSE\");\n    }\n    make_stream(s);\n    init_stream(s, 8192);\n    out_uint16_le(s, CB_FILECONTENTS_REQUEST); /* 8 */\n    out_uint16_le(s, 0);\n    out_uint32_le(s, 28);\n    out_uint32_le(s, stream_id);\n    out_uint32_le(s, lindex);\n    out_uint32_le(s, CB_FILECONTENTS_RANGE);\n    out_uint32_le(s, offset); /* nPositionLow */\n    out_uint32_le(s, 0); /* nPositionHigh */\n    out_uint32_le(s, request_bytes); /* cbRequested */\n    out_uint32_le(s, 0); /* clipDataId */\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    size = (int)(s->end - s->data);\n    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);\n    free_stream(s);\n    g_file_request_sent_type = CB_FILECONTENTS_RANGE;\n    return rv;\n}\n\n\n/*****************************************************************************/\n/* client is asking from info about a file */\nint\nclipboard_process_file_request(struct stream *s, int clip_msg_status,\n                               int clip_msg_len)\n{\n    int streamId;\n    int lindex;\n    int dwFlags;\n    int nPositionLow;\n    int cbRequested;\n    //int clipDataId;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_file_request:\");\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", s->p, clip_msg_len);\n    in_uint32_le(s, streamId);\n    in_uint32_le(s, lindex);\n    in_uint32_le(s, dwFlags);\n    in_uint32_le(s, nPositionLow);\n    in_uint8s(s, 4); /* nPositionHigh */\n    in_uint32_le(s, cbRequested);\n    //in_uint32_le(s, clipDataId); /* options, used when locking */\n    if (dwFlags & CB_FILECONTENTS_SIZE)\n    {\n        clipboard_send_file_size(streamId, lindex);\n    }\n    if (dwFlags & CB_FILECONTENTS_RANGE)\n    {\n        clipboard_send_file_data(streamId, lindex, nPositionLow, cbRequested);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* server requested info about the file and this is the response\n   it's either the file size or file data */\nint\nclipboard_process_file_response(struct stream *s, int clip_msg_status,\n                                int clip_msg_len)\n{\n    int streamId;\n    int file_size;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_file_response:\");\n    if (g_file_request_sent_type == CB_FILECONTENTS_SIZE)\n    {\n        g_file_request_sent_type = 0;\n        in_uint32_le(s, streamId);\n        in_uint32_le(s, file_size);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_process_file_response: streamId %d \"\n                  \"file_size %d\", streamId, file_size);\n        xfuse_file_contents_size(streamId, file_size);\n    }\n    else if (g_file_request_sent_type == CB_FILECONTENTS_RANGE)\n    {\n        g_file_request_sent_type = 0;\n        in_uint32_le(s, streamId);\n        xfuse_file_contents_range(streamId, s->p, clip_msg_len - 4);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"clipboard_process_file_response: error\");\n        g_file_request_sent_type = 0;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* read in CLIPRDR_FILEDESCRIPTOR [MS-RDPECLIP] 2.2.5.2.3.1 */\nstatic int\nclipboard_c2s_in_file_info(struct stream *s, struct clip_file_desc *cfd)\n{\n    int filename_bytes;\n    int ex_bytes;\n\n    if (!s_check_rem_and_log(s, 4 + 32 + 4 + 16 + 8 + 8 + 520,\n                             \"Parsing [MS-RDPECLIP] CLIPRDR_FILEDESCRIPTOR\"))\n    {\n        return 1;\n    }\n    in_uint32_le(s, cfd->flags);\n    in_uint8s(s, 32); /* reserved1 */\n    in_uint32_le(s, cfd->fileAttributes);\n    in_uint8s(s, 16); /* reserved2 */\n    in_uint32_le(s, cfd->lastWriteTimeLow);\n    in_uint32_le(s, cfd->lastWriteTimeHigh);\n    in_uint32_le(s, cfd->fileSizeHigh);\n    in_uint32_le(s, cfd->fileSizeLow);\n    filename_bytes =\n        clipboard_in_utf16_le_as_utf8(s, cfd->cFileName,\n                                      sizeof(cfd->cFileName));\n    if (filename_bytes > 520)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Filename in CLIPRDR_FILEDESCRIPTOR is too long (%d bytes)\",\n            filename_bytes);\n        return 1;\n    }\n    ex_bytes = 520 - filename_bytes;\n    in_uint8s(s, ex_bytes);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_c2s_in_file_info:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  flags 0x%8.8x\", cfd->flags);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  fileAttributes 0x%8.8x\", cfd->fileAttributes);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  lastWriteTime 0x%8.8x%8.8x\", cfd->lastWriteTimeHigh,\n              cfd->lastWriteTimeLow);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  fileSize 0x%8.8x%8.8x\", cfd->fileSizeHigh,\n              cfd->fileSizeLow);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  cFileName [%s]\", cfd->cFileName);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nclipboard_c2s_in_files(struct stream *s, char *file_list, int file_list_size,\n                       const char *fprefix)\n{\n    int citems;\n    int lindex;\n    int str_len;\n    struct clip_file_desc cfd;\n    char *ptr;\n    char *last; /* Last writeable char in buffer */\n    int dropped_files = 0; /* # files we can't add to buffer */\n\n    if (file_list_size < 1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_c2s_in_files: No space in string\");\n        return 1;\n    }\n    if (!s_check_rem(s, 4))\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_c2s_in_files: parse error\");\n        return 1;\n    }\n    in_uint32_le(s, citems);\n    if (citems < 0 || citems > 64 * 1024) /* sanity check */\n    {\n        LOG(LOG_LEVEL_ERROR, \"clipboard_c2s_in_files: \"\n            \"Bad number of files in list (%d)\", citems);\n        return 1;\n    }\n    xfuse_clear_clip_dir();\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"clipboard_c2s_in_files: cItems %d\", citems);\n    ptr = file_list;\n    last = file_list + file_list_size - 1;\n\n    for (lindex = 0; lindex < citems; lindex++)\n    {\n        g_memset(&cfd, 0, sizeof(struct clip_file_desc));\n        if (clipboard_c2s_in_file_info(s, &cfd) != 0)\n        {\n            return 1;\n        }\n        if ((g_pos(cfd.cFileName, \"\\\\\") >= 0) ||\n                (cfd.fileAttributes & CB_FILE_ATTRIBUTE_DIRECTORY))\n        {\n            LOG(LOG_LEVEL_WARNING, \"clipboard_c2s_in_files: skipping \"\n                \"directory not supported [%s]\", cfd.cFileName);\n            continue;\n        }\n\n        /* Have we already run out of room in the list? */\n        if (dropped_files > 0)\n        {\n            dropped_files += 1;\n            continue;\n        }\n\n        /* Room for this file? */\n        str_len = (ptr == file_list) ? 0 : 1; /* Delimiter */\n        str_len += g_strlen(fprefix); /* e.g. \"file://\" */\n        str_len += g_strlen(g_fuse_clipboard_path);\n        str_len += 1; /* '/' */\n        str_len += g_strlen(cfd.cFileName);\n        if (str_len > (last - ptr))\n        {\n            dropped_files += 1;\n            continue;\n        }\n\n        if (xfuse_add_clip_dir_item(cfd.cFileName, 0, cfd.fileSizeLow, lindex) == -1)\n        {\n            LOG(LOG_LEVEL_WARNING, \"clipboard_c2s_in_files: \"\n                \"failed to add clip dir item %s\", cfd.cFileName);\n            continue;\n        }\n\n        if (ptr > file_list)\n        {\n            *ptr++ = '\\n';\n        }\n\n        str_len = g_strlen(fprefix);\n        g_strcpy(ptr, fprefix);\n        ptr += str_len;\n\n        str_len = g_strlen(g_fuse_clipboard_path);\n        g_strcpy(ptr, g_fuse_clipboard_path);\n        ptr += str_len;\n        *ptr++ = '/';\n\n        str_len = g_strlen(cfd.cFileName);\n        g_strcpy(ptr, cfd.cFileName);\n        ptr += str_len;\n    }\n    *ptr = '\\0';\n\n    if (dropped_files > 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"clipboard_c2s_in_files: \"\n            \"Dropped %d files from the clip buffer due to insufficient space\",\n            dropped_files);\n    }\n    return 0;\n}\n"
  },
  {
    "path": "sesman/chansrv/clipboard_file.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(CLIPBOARD_FILE_H)\n#define CLIPBOARD_FILE_H\n\n#include \"arch.h\"\n#include \"parse.h\"\n\nint\nclipboard_send_data_response_for_file(const char *data, int data_size);\nint\nclipboard_process_file_request(struct stream *s, int clip_msg_status,\n                               int clip_msg_len);\nint\nclipboard_process_file_response(struct stream *s, int clip_msg_status,\n                                int clip_msg_len);\n/**\n * Process a CLIPRDR_FILELIST - see [MS-RDPECLIP] 2.2.5.2.3\n *\n * Files in the list are added to the xfs filesystem in the clipboard\n * directory. The filenames names are added to the 'file_list' for the user.\n * Files are prefixed with '<fprefix><clipboard_dir>/' and separated by '\\\\n'.\n *\n * If the list is not big enough, whole filenames are omitted, and a warning\n * message is logged. This is not an error.\n *\n * @param s Input stream containing CLIPRDR_FILELIST\n * @param file_list Output buffer for filenames\n * @param file_list_size Size of buffer, including space for '\\0'.\n * @param fprefix Prefix for each file in the file list (e.g. \"file://\")\n *\n * @return Zero for success.\n */\nint\nclipboard_c2s_in_files(struct stream *s, char *file_list, int file_list_size,\n                       const char *fprefix);\n\nint\nclipboard_request_file_size(int stream_id, int lindex);\n\nint\nclipboard_request_file_data(int stream_id, int lindex, int offset,\n                            int request_bytes);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/devredir.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * xrdp device redirection - only drive redirection is currently supported\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * TODO\n *      o there is one difference in the protocol initialization\n *        sequence upon reconnection: if a user is already logged on,\n *        send a SERVER_USER_LOGGED_ON msg as per section 3.3.5.1.5\n *\n *      o how to announce / delete a drive after a connection has been\n *        established?\n *\n *      o need to support multiple drives;\n *      o for multiple drives, we cannot have global device_id's and file_id's\n *        and all functions must be reenterant\n *      o replace printf's with log_xxx\n *      o mark local funcs with static\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <sys/statvfs.h>\n#include <fcntl.h>\n#include <string.h>\n\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"log.h\"\n#include \"chansrv.h\"\n#include \"chansrv_fuse.h\"\n#include \"chansrv_xfs.h\"\n#include \"devredir.h\"\n#include \"smartcard.h\"\n#include \"ms-rdpefs.h\"\n#include \"ms-smb2.h\"\n#include \"ms-fscc.h\"\n#include \"ms-erref.h\"\n\n\n/* client minor versions */\n#define RDP_CLIENT_50                   0x0002\n#define RDP_CLIENT_51                   0x0005\n#define RDP_CLIENT_52                   0x000a\n#define RDP_CLIENT_60_61                0x000c\n\n/* Windows time starts on Jan 1, 1601 */\n/* Linux   time starts on Jan 1, 1970 */\n#define EPOCH_DIFF 11644473600LL\n#define WINDOWS_TO_LINUX_TIME(_t) (((_t) / 10000000) - EPOCH_DIFF);\n#define LINUX_TO_WINDOWS_TIME(_t) (((_t) + EPOCH_DIFF) * 10000000)\n\n/*\n * CompletionID types, used in IRPs to indicate I/O operation\n */\n\nenum COMPLETION_TYPE\n{\n    CID_CREATE_DIR_REQ = 1,\n    CID_DIRECTORY_CONTROL,\n    CID_CREATE_REQ,\n    CID_OPEN_REQ,\n    CID_READ,\n    CID_WRITE,\n    CID_CLOSE,\n    CID_FILE_CLOSE,\n    CID_RMDIR_OR_FILE,\n    CID_RMDIR_OR_FILE_RESP,\n    CID_RENAME_FILE,\n    CID_RENAME_FILE_RESP,\n    CID_LOOKUP,\n    CID_SETATTR,\n    CID_STATFS,\n    CID_STATFS_RESP\n};\n\n\n/* globals */\nextern int g_rdpdr_chan_id; /* in chansrv.c */\n\n/* Capabilities from GENERAL_CAPS_SET in Client Core Capability Response */\nstruct client_caps\n{\n    tui32 extended_pdu;\n    int printer_redir_supported;\n    int port_redir_supported;\n    int drive_redir_supported;\n    int smartcard_redir_supported;\n    unsigned int drive_redir_version;\n};\n\nstatic struct client_caps g_ccap;\n\ntui32 g_completion_id = 1;\n\ntui32 g_clientID;           /* unique client ID - announced by client */\ntui32 g_device_id;          /* unique device ID - announced by client */\ntui16 g_client_rdp_version; /* returned by client                     */\nstruct stream *g_input_stream = NULL;\n\n/*\n * Local functions called from devredir_proc_device_iocompletion()\n */\nstatic void devredir_proc_cid_rmdir_or_file(IRP *irp, enum NTSTATUS IoStatus);\nstatic void devredir_proc_cid_rmdir_or_file_resp(IRP *irp,\n        enum NTSTATUS IoStatus);\nstatic void devredir_proc_cid_rename_file(IRP *irp, enum NTSTATUS IoStatus);\nstatic void devredir_proc_cid_rename_file_resp(IRP *irp,\n        enum NTSTATUS IoStatus);\nstatic void devredir_proc_cid_lookup(  IRP *irp,\n                                       struct stream *s_in,\n                                       enum NTSTATUS IoStatus);\nstatic void devredir_proc_cid_setattr( IRP *irp,\n                                       struct stream *s_in,\n                                       enum NTSTATUS IoStatus);\nstatic void devredir_proc_cid_statfs(  IRP *irp,\n                                       struct stream *s_in,\n                                       enum NTSTATUS IoStatus);\nstatic void devredir_proc_cid_statfs_resp(IRP *irp,\n        struct stream *s_in,\n        enum NTSTATUS IoStatus);\n/* Other local functions */\nstatic void devredir_send_server_core_cap_req(void);\nstatic void devredir_send_server_clientID_confirm(void);\nstatic void devredir_send_server_user_logged_on(void);\n\nstatic int devredir_proc_client_core_cap_resp(struct stream *s);\nstatic int devredir_proc_client_devlist_announce_req(struct stream *s);\nstatic int devredir_proc_client_devlist_remove_req(struct stream *s);\nstatic int devredir_proc_device_iocompletion(struct stream *s);\nstatic int devredir_proc_query_dir_response(IRP *irp,\n        struct stream *s_in,\n        tui32 DeviceId,\n        tui32 CompletionId,\n        enum NTSTATUS IoStatus);\n\nstatic void devredir_cvt_slash(char *path);\nstatic int  devredir_string_ends_with(const char *string, char c);\n\n/*****************************************************************************/\nint\ndevredir_init(void)\n{\n    struct  stream *s;\n    int     bytes;\n    tui32 clientID;\n\n    /* get a random number that will act as a unique clientID */\n    g_random((char *) &clientID, sizeof(clientID));\n\n    /* setup stream */\n    xstream_new(s, 1024);\n\n    /* initiate drive redirection protocol by sending Server Announce Req  */\n    xstream_wr_u16_le(s, RDPDR_CTYP_CORE);\n    xstream_wr_u16_le(s, PAKID_CORE_SERVER_ANNOUNCE);\n    xstream_wr_u16_le(s, 0x0001);  /* server major ver                      */\n    xstream_wr_u16_le(s, 0x000C);  /* server minor ver  - pretend 2 b Win 7 */\n    xstream_wr_u32_le(s, clientID); /* unique ClientID                      */\n\n    /* send data to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    xstream_free(s);\n    return 0;\n}\n\n/*****************************************************************************/\nint\ndevredir_deinit(void)\n{\n    scard_deinit();\n    return 0;\n}\n\n/*****************************************************************************/\n\n#ifdef USE_DEVEL_LOGGING\n/*\n * Convert a COMPLETION_TYPE to a string\n */\nstatic const char *completion_type_to_str(enum COMPLETION_TYPE cid)\n{\n    return\n        (cid == CID_CREATE_DIR_REQ)     ?  \"CID_CREATE_DIR_REQ\" :\n        (cid == CID_DIRECTORY_CONTROL)  ?  \"CID_DIRECTORY_CONTROL\" :\n        (cid == CID_CREATE_REQ)         ?  \"CID_CREATE_REQ\" :\n        (cid == CID_OPEN_REQ)           ?  \"CID_OPEN_REQ\" :\n        (cid == CID_READ)               ?  \"CID_READ\" :\n        (cid == CID_WRITE)              ?  \"CID_WRITE\" :\n        (cid == CID_CLOSE)              ?  \"CID_CLOSE\" :\n        (cid == CID_FILE_CLOSE)         ?  \"CID_FILE_CLOSE\" :\n        (cid == CID_RMDIR_OR_FILE)      ?  \"CID_RMDIR_OR_FILE\" :\n        (cid == CID_RMDIR_OR_FILE_RESP) ?  \"CID_RMDIR_OR_FILE_RESP\" :\n        (cid == CID_RENAME_FILE)        ?  \"CID_RENAME_FILE\" :\n        (cid == CID_RENAME_FILE_RESP)   ?  \"CID_RENAME_FILE_RESP\" :\n        (cid == CID_LOOKUP)             ?  \"CID_LOOKUP\" :\n        (cid == CID_SETATTR)            ?  \"CID_SETATTR\" :\n        (cid == CID_STATFS)             ?  \"CID_STATFS\" :\n        (cid == CID_STATFS_RESP)        ?  \"CID_STATFS_RESP\" :\n        /* default */                      \"<unknown>\";\n};\n#endif\n\n/*****************************************************************************/\n\n/*\n * Convert Windows permissions to Linux permissions.\n *\n * We can't currently support group or other permissions as separate from the\n * owner (not that there's much point). We'll assume our caller will provide\n * a umask if appropriate\n */\nstatic tui32\nWindowsToLinuxFilePerm(tui32 wperm)\n{\n    tui32 result;\n    if (wperm & W_FILE_ATTRIBUTE_DIRECTORY)\n    {\n        result = S_IFDIR | 0555; /* dirs are always readable and executable */\n    }\n    else\n    {\n        result = S_IFREG | 0444; /* files are always readable */\n        if (wperm & W_FILE_ATTRIBUTE_SYSTEM)\n        {\n            result |= 0111;    /* Executable */\n        }\n    }\n\n    if ((wperm & W_FILE_ATTRIBUTE_READONLY) == 0)\n    {\n        result |= 0222;\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nstatic tui32\nLinuxToWindowsFilePerm(tui32 lperm)\n{\n    tui32 result = 0;\n\n    /* Writeable flag is common to files and directories */\n    if ((lperm & S_IWUSR) == 0)\n    {\n        result |= W_FILE_ATTRIBUTE_READONLY;\n    }\n\n    if (lperm & S_IFDIR)\n    {\n        result |= W_FILE_ATTRIBUTE_DIRECTORY;\n    }\n    else\n    {\n        /* For normal files the system attribute is used to store the owner\n           executable bit */\n        if (lperm & S_IXUSR)\n        {\n            result |= W_FILE_ATTRIBUTE_SYSTEM;\n        }\n        if (result == 0)\n        {\n            /* See MS-FSCC section 2.6 */\n            result = W_FILE_ATTRIBUTE_NORMAL;\n        }\n    }\n\n    return result;\n}\n\n\n/**\n * @brief process incoming data\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint\ndevredir_data_in(struct stream *s, int chan_id, int chan_flags, int length,\n                 int total_length)\n{\n    struct stream *ls;\n    tui16          comp_type;\n    tui16          pktID;\n    tui16          minor_ver;\n    int            rv = 0;\n\n    /*\n     * handle packet fragmentation\n     */\n    if ((chan_flags & 3) == 3)\n    {\n        /* all data contained in one packet */\n        ls = s;\n    }\n    else\n    {\n        /* is this is the first packet? */\n        if (chan_flags & 1)\n        {\n            xstream_new(g_input_stream, total_length);\n        }\n\n        xstream_copyin(g_input_stream, s->p, length);\n\n        /* in last packet, chan_flags & 0x02 will be true */\n        if ((chan_flags & 2) == 0)\n        {\n            return 0;\n        }\n\n        s_mark_end(g_input_stream);\n        g_input_stream->p = g_input_stream->data;\n        ls = g_input_stream;\n    }\n\n    /* read header from incoming data */\n    if (!s_check_rem_and_log(ls, 4, \"Parsing [MS-RDPEFS] RDPDR_HEADER\"))\n    {\n        rv = -1;\n        goto done;\n    }\n    xstream_rd_u16_le(ls, comp_type);\n    xstream_rd_u16_le(ls, pktID);\n\n    /* for now we only handle core type, not printers */\n    if (comp_type != RDPDR_CTYP_CORE)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"invalid component type in response; expected 0x%x got 0x%x\",\n                  RDPDR_CTYP_CORE, comp_type);\n\n        rv = -1;\n        goto done;\n    }\n\n    /* figure out what kind of response we have gotten */\n    switch (pktID)\n    {\n        case PAKID_CORE_CLIENTID_CONFIRM:\n            if (!s_check_rem_and_log(ls, 6, \"Parsing [MS-RDPEFS] DR_CORE_CLIENT_ANNOUNCE_RSP\"))\n            {\n                rv = -1;\n            }\n            else\n            {\n                xstream_seek(ls, 2);  /* major version, we ignore it */\n                xstream_rd_u16_le(ls, minor_ver);\n                xstream_rd_u32_le(ls, g_clientID);\n\n                g_client_rdp_version = minor_ver;\n\n                switch (minor_ver)\n                {\n                    case RDP_CLIENT_50:\n                        break;\n\n                    case RDP_CLIENT_51:\n                        break;\n\n                    case RDP_CLIENT_52:\n                        break;\n\n                    case RDP_CLIENT_60_61:\n                        break;\n                }\n            }\n            break;\n\n        case PAKID_CORE_CLIENT_NAME:\n            /* client is telling us its computer name; do we even care? */\n\n            /* See 3.3.5.1.6 for sequencing rules */\n            if (g_client_rdp_version >= RDP_CLIENT_51)\n            {\n                /* let client know our capabilities */\n                devredir_send_server_core_cap_req();\n            }\n\n            /* send confirm clientID */\n            devredir_send_server_clientID_confirm();\n            break;\n\n        case PAKID_CORE_CLIENT_CAPABILITY:\n            rv = devredir_proc_client_core_cap_resp(ls);\n            if (rv == 0)\n            {\n                if ((g_ccap.extended_pdu & RDPDR_USER_LOGGEDON_PDU) != 0)\n                {\n                    /* Tell client to announce remaining devices */\n                    devredir_send_server_user_logged_on();\n                }\n                else if (g_client_rdp_version >= RDP_CLIENT_51)\n                {\n                    /* See 3.3.5.1.7 */\n                    devredir_send_server_clientID_confirm();\n                }\n            }\n            break;\n\n        case PAKID_CORE_DEVICELIST_ANNOUNCE:\n            rv = devredir_proc_client_devlist_announce_req(ls);\n            break;\n\n        case PAKID_CORE_DEVICELIST_REMOVE:\n            rv = devredir_proc_client_devlist_remove_req(ls);\n            break;\n\n        case PAKID_CORE_DEVICE_IOCOMPLETION:\n            rv = devredir_proc_device_iocompletion(ls);\n            break;\n\n        default:\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"got unknown response 0x%x\", pktID);\n            break;\n    }\n\ndone:\n\n    if (g_input_stream)\n    {\n        xstream_free(g_input_stream);\n        g_input_stream = NULL;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\ndevredir_get_wait_objs(tbus *objs, int *count, int *timeout)\n{\n    if (g_ccap.smartcard_redir_supported)\n    {\n        return scard_get_wait_objs(objs, count, timeout);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\ndevredir_check_wait_objs(void)\n{\n    if (g_ccap.smartcard_redir_supported)\n    {\n        return scard_check_wait_objs();\n    }\n    return 0;\n}\n\n/**\n * @brief let client know our capabilities\n *****************************************************************************/\n\nstatic void\ndevredir_send_server_core_cap_req(void)\n{\n    struct stream *s;\n    int            bytes;\n    int caps_count = 4;\n\n#ifdef XRDP_SMARTCARD\n    ++caps_count;\n#endif\n    xstream_new(s, 1024);\n\n    /* setup header */\n    xstream_wr_u16_le(s, RDPDR_CTYP_CORE);\n    xstream_wr_u16_le(s, PAKID_CORE_SERVER_CAPABILITY);\n\n    xstream_wr_u16_le(s, caps_count);       /* num of caps we are sending     */\n    xstream_wr_u16_le(s, 0x0000);           /* padding                        */\n\n    /* setup general capability */\n    xstream_wr_u16_le(s, CAP_GENERAL_TYPE); /* CapabilityType                 */\n    xstream_wr_u16_le(s, 44);               /* CapabilityLength - len of this */\n    /* CAPABILITY_SET in bytes, inc   */\n    /* the header                     */\n    xstream_wr_u32_le(s, 2);                /* Version                        */\n    xstream_wr_u32_le(s, 2);                /* O.S type                       */\n    xstream_wr_u32_le(s, 0);                /* O.S version                    */\n    xstream_wr_u16_le(s, 1);                /* protocol major version         */\n    xstream_wr_u16_le(s, g_client_rdp_version); /* protocol minor version     */\n    xstream_wr_u32_le(s, 0xffff);           /* I/O code 1                     */\n    xstream_wr_u32_le(s, 0);                /* I/O code 2                     */\n    xstream_wr_u32_le(s, 7);                /* Extended PDU                   */\n    xstream_wr_u32_le(s, 0);                /* extra flags 1                  */\n    xstream_wr_u32_le(s, 0);                /* extra flags 2                  */\n    xstream_wr_u32_le(s, 2);                /* special type device cap        */\n\n    /* setup printer capability */\n    xstream_wr_u16_le(s, CAP_PRINTER_TYPE);\n    xstream_wr_u16_le(s, 8);\n    xstream_wr_u32_le(s, 1);\n\n    /* setup serial port capability */\n    xstream_wr_u16_le(s, CAP_PORT_TYPE);\n    xstream_wr_u16_le(s, 8);\n    xstream_wr_u32_le(s, 1);\n\n    /* setup file system capability */\n    xstream_wr_u16_le(s, CAP_DRIVE_TYPE);   /* CapabilityType                 */\n    xstream_wr_u16_le(s, 8);                /* CapabilityLength - len of this */\n    /* CAPABILITY_SET in bytes, inc   */\n    /* the header                     */\n    xstream_wr_u32_le(s, 2);                /* Version                        */\n\n#ifdef XRDP_SMARTCARD\n    /* setup smart card capability */\n    xstream_wr_u16_le(s, CAP_SMARTCARD_TYPE);\n    xstream_wr_u16_le(s, 8);\n    xstream_wr_u32_le(s, 1);\n#endif\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    xstream_free(s);\n}\n\nstatic void\ndevredir_send_server_clientID_confirm(void)\n{\n    struct stream *s;\n    int            bytes;\n\n    xstream_new(s, 1024);\n\n    /* setup stream */\n    xstream_wr_u16_le(s, RDPDR_CTYP_CORE);\n    xstream_wr_u16_le(s, PAKID_CORE_CLIENTID_CONFIRM);\n    xstream_wr_u16_le(s, 0x0001);\n    xstream_wr_u16_le(s, g_client_rdp_version);\n    xstream_wr_u32_le(s, g_clientID);\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    xstream_free(s);\n}\n\nstatic void\ndevredir_send_server_user_logged_on(void)\n{\n    struct stream *s;\n    int            bytes;\n\n    xstream_new(s, 1024);\n\n    /* setup stream */\n    xstream_wr_u16_le(s, RDPDR_CTYP_CORE);\n    xstream_wr_u16_le(s, PAKID_CORE_USER_LOGGEDON);\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    xstream_free(s);\n}\n\nstatic void\ndevredir_send_server_device_announce_resp(tui32 device_id,\n        enum NTSTATUS result_code)\n{\n    struct stream *s;\n    int            bytes;\n\n    xstream_new(s, 1024);\n\n    /* setup stream */\n    xstream_wr_u16_le(s, RDPDR_CTYP_CORE);\n    xstream_wr_u16_le(s, PAKID_CORE_DEVICE_REPLY);\n    xstream_wr_u32_le(s, device_id);\n    xstream_wr_u32_le(s, (tui32)result_code);\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    xstream_free(s);\n}\n\n/**\n * Create a file system object\n *\n * See [MS-RDPEFS] 2.2.1.4.1 (DR_CREATE_REQ)\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\nstatic int\ndevredir_send_drive_create_request(tui32 device_id,\n                                   const char *path,\n                                   tui32 DesiredAccess,\n                                   tui32 CreateOptions,\n                                   tui32 FileAttributes,\n                                   tui32 CreateDisposition,\n                                   tui32 completion_id)\n{\n    struct stream *s;\n    int            bytes;\n    int            path_len;\n    unsigned int   unicode_byte_count;\n    tui32          SharedAccess;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"device_id=%d path=\\\"%s\\\"\"\n              \" DesiredAccess=0x%x CreateDisposition=0x%x\"\n              \" FileAttributes=0x%x CreateOptions=0x%x\"\n              \" CompletionId=%d\",\n              device_id, path,\n              DesiredAccess, CreateDisposition,\n              FileAttributes, CreateOptions,\n              completion_id);\n\n    /* Find number of bytes required for Unicode path  + terminator */\n    path_len = strlen(path) + 1; // includes terminator\n    unicode_byte_count = utf8_as_utf16_word_count(path, path_len) * 2;\n\n    xstream_new(s, (int)(64 + unicode_byte_count));\n\n    /* FILE_SHARE_DELETE allows files to be renamed while in use\n       (in some circumstances) */\n    SharedAccess = SA_FILE_SHARE_READ | SA_FILE_SHARE_WRITE |\n                   SA_FILE_SHARE_DELETE;\n\n    devredir_insert_DeviceIoRequest(s,\n                                    device_id,\n                                    0,\n                                    completion_id,\n                                    IRP_MJ_CREATE,\n                                    IRP_MN_NONE);\n\n    xstream_wr_u32_le(s, DesiredAccess);     /* DesiredAccess              */\n    xstream_wr_u32_le(s, 0);                 /* AllocationSize high unused */\n    xstream_wr_u32_le(s, 0);                 /* AllocationSize low  unused */\n    xstream_wr_u32_le(s, FileAttributes);    /* FileAttributes             */\n    xstream_wr_u32_le(s, SharedAccess);      /* SharedAccess               */\n    xstream_wr_u32_le(s, CreateDisposition); /* CreateDisposition          */\n    xstream_wr_u32_le(s, CreateOptions);     /* CreateOptions              */\n    xstream_wr_u32_le(s, unicode_byte_count);/* PathLength                 */\n    out_utf8_as_utf16_le(s, path, path_len); /* Path */\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    xstream_free(s);\n    return 0;\n}\n\n/**\n * Close a request previously created by devredir_send_drive_create_request()\n *****************************************************************************/\n\nstatic int\ndevredir_send_drive_close_request(tui16 Component, tui16 PacketId,\n                                  tui32 DeviceId,\n                                  tui32 FileId,\n                                  tui32 CompletionId,\n                                  enum IRP_MJ MajorFunction,\n                                  enum IRP_MN MinorFunc,\n                                  int pad_len)\n{\n    struct stream *s;\n    int            bytes;\n\n    xstream_new(s, 1024);\n\n    devredir_insert_DeviceIoRequest(s, DeviceId, FileId, CompletionId,\n                                    MajorFunction, MinorFunc);\n\n    if (pad_len)\n    {\n        xstream_seek(s, pad_len);\n    }\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    xstream_free(s);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sent close request; expect CID_FILE_CLOSE\");\n    return 0;\n}\n\n/**\n * @brief ask client to enumerate directory\n *\n * See [MS-RDPEFS] 2.2.3.3.10 (DR_DRIVE_QUERY_DIRECTORY_REQ)\n *****************************************************************************/\nstatic void\ndevredir_send_drive_dir_request(IRP *irp, tui32 device_id,\n                                tui32 InitialQuery, char *Path)\n{\n    struct stream *s;\n    int            bytes;\n    unsigned int   path_len;\n    unsigned int   unicode_byte_count;\n\n    /* during Initial Query, Path cannot be NULL */\n    if (InitialQuery && Path != NULL)\n    {\n        /* Find number of words required for Unicode path */\n        path_len = strlen(Path) + 1; // includes terminator\n        unicode_byte_count = utf8_as_utf16_word_count(Path, path_len) * 2;\n    }\n    else\n    {\n        path_len = 0;\n        unicode_byte_count = 0;\n    }\n\n    xstream_new(s, (int)(64 + unicode_byte_count));\n\n    irp->completion_type = CID_DIRECTORY_CONTROL;\n    devredir_insert_DeviceIoRequest(s,\n                                    device_id,\n                                    irp->FileId,\n                                    irp->CompletionId,\n                                    IRP_MJ_DIRECTORY_CONTROL,\n                                    IRP_MN_QUERY_DIRECTORY);\n\n    xstream_wr_u32_le(s, FileDirectoryInformation);  /* FsInformationClass */\n    xstream_wr_u8(s, InitialQuery);                  /* InitialQuery       */\n\n    xstream_wr_u32_le(s, unicode_byte_count);        /* PathLength         */\n    xstream_seek(s, 23);                             /* Padding            */\n    out_utf8_as_utf16_le(s, Path, path_len);         /* Path */\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    xstream_free(s);\n}\n\n/******************************************************************************\n**                   process data received from client                       **\n******************************************************************************/\n\n/**\n * Process a GENERAL_CAPS_SET packet from the client\n * @param s Stream. CAPABILITY_HEADER is already read\n * @param cap_len Amount of data left in stream for the packet\n * @return 0 for success, -1 otherwise\n *\n * Caller is responsible for skipping unused data from this\n * capability in the input stream.\n */\nstatic int\nprocess_client_general_caps_set(struct stream *s, unsigned int cap_len,\n                                struct client_caps *ccap)\n{\n    int rv = -1;\n\n    // Data we don't check at the start of the packet\n#define PACKET_SKIP_LENGTH ( \\\n                             4 + /* osType */ \\\n                             4 + /* osVersion */ \\\n                             2 + /* protocolMajorVersion */ \\\n                             2 + /* protocolMinorVersion */ \\\n                             4 + /* ioCode1 */ \\\n                             4) /* ioCode2 */\n\n    if (cap_len < (PACKET_SKIP_LENGTH + 4))\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"[MS-RDPEFS] GENERAL_CAPS_SET: Short packet (%u bytes) encountered\",\n            cap_len);\n    }\n    else\n    {\n        xstream_seek(s, PACKET_SKIP_LENGTH);\n        xstream_rd_u32_le(s, ccap->extended_pdu);\n        rv = 0;\n    }\n\n    return rv;\n#undef PACKET_SKIP_LENGTH\n}\n\n/**\n * @brief process client's response to our core_capability_req() msg\n *\n * @param   s   stream containing client's response\n * @return  0   for success, -1 otherwise\n *****************************************************************************/\nstatic int\ndevredir_proc_client_core_cap_resp(struct stream *s)\n{\n#define CAPABILITY_HEADER_LEN 8\n    int i;\n    tui16 num_caps;\n    tui16 cap_type;\n    tui16 cap_len;\n    tui32 cap_version;\n\n    // Reset to defaults\n    memset(&g_ccap, 0, sizeof(g_ccap));\n    g_ccap.drive_redir_version = 1;\n\n    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_CORE_CAPABLITY_RSP\"))\n    {\n        return -1;\n    }\n    xstream_rd_u16_le(s, num_caps);\n    xstream_seek(s, 2);  /* padding */\n\n    for (i = 0; i < num_caps; i++)\n    {\n        if (!s_check_rem_and_log(s, CAPABILITY_HEADER_LEN,\n                                 \"Parsing [MS-RDPEFS] CAPABILITY_HEADER\"))\n        {\n            return -1;\n        }\n        xstream_rd_u16_le(s, cap_type);\n        xstream_rd_u16_le(s, cap_len);\n        xstream_rd_u32_le(s, cap_version);\n        /* Convert the length to a remaining length. Underflow is possible,\n         * but this is an unsigned type so that's OK */\n        cap_len -= CAPABILITY_HEADER_LEN;\n        if (!s_check_rem_and_log(s, cap_len,\n                                 \"Parsing [MS-RDPEFS] CAPABILITY_HEADER data\"))\n        {\n            return -1;\n        }\n\n        // Save our stream position. iso_hdr is otherwise\n        // unused in this stream\n        s_push_layer(s, iso_hdr, 0);\n        switch (cap_type)\n        {\n            case CAP_GENERAL_TYPE:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"got CAP_GENERAL_TYPE\");\n                if (process_client_general_caps_set(s, cap_len, &g_ccap) < 0)\n                {\n                    return -1;\n                }\n                break;\n\n            case CAP_PRINTER_TYPE:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"got CAP_PRINTER_TYPE\");\n                g_ccap.printer_redir_supported = 1;\n                break;\n\n            case CAP_PORT_TYPE:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"got CAP_PORT_TYPE\");\n                g_ccap.port_redir_supported = 1;\n                break;\n\n            case CAP_DRIVE_TYPE:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"got CAP_DRIVE_TYPE\");\n                g_ccap.drive_redir_supported = 1;\n                if (cap_version == 2)\n                {\n                    g_ccap.drive_redir_version = 2;\n                }\n                break;\n\n            case CAP_SMARTCARD_TYPE:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"got CAP_SMARTCARD_TYPE\");\n                g_ccap.smartcard_redir_supported = (scard_init() == 0);\n                break;\n        }\n        s_pop_layer(s, iso_hdr); // Move back to start of capability data\n        xstream_seek(s, cap_len);\n    }\n    return 0;\n#undef CAPABILITY_HEADER_LEN\n}\n\nstatic int\ndevredir_proc_client_devlist_announce_req(struct stream *s)\n{\n    unsigned int i;\n    int   j;\n    tui32 device_count;\n    tui32 device_type;\n    tui32 device_data_len;\n    char  preferred_dos_name[9];\n    enum NTSTATUS response_status;\n\n    /* get number of devices being announced */\n    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_CORE_DEVICELIST_ANNOUNCE_REQ\"))\n    {\n        return -1;\n    }\n\n    xstream_rd_u32_le(s, device_count);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"num of devices announced: %d\", device_count);\n\n    for (i = 0; i < device_count; i++)\n    {\n        if (!s_check_rem_and_log(s, 4 + 4 + 8 + 4,\n                                 \"Parsing [MS-RDPEFS] DEVICE_ANNOUNCE\"))\n        {\n            return -1;\n        }\n        xstream_rd_u32_le(s, device_type);\n        xstream_rd_u32_le(s, g_device_id);\n        /* get preferred DOS name\n         * DOS names that are 8 chars long are not NULL terminated */\n        for (j = 0; j < 8; j++)\n        {\n            preferred_dos_name[j] = *s->p++;\n        }\n        preferred_dos_name[8] = 0;\n\n        /* Assume this device isn't supported by us */\n        response_status = STATUS_NOT_SUPPORTED;\n\n        /* Read the device data length from the stream */\n        xstream_rd_u32_le(s, device_data_len);\n        if (device_data_len > 0 &&\n                !s_check_rem_and_log(s, device_data_len,\n                                     \"Parsing [MS-RDPEFS] DEVICE_ANNOUNCE devdata\"))\n        {\n            return -1;\n        }\n\n        switch (device_type)\n        {\n            case RDPDR_DTYP_FILESYSTEM:\n                /* At present we don't use the full name - see\n                 * [MS-RDPEFS] 2.2.3.1 for details of the contents */\n                xstream_skip_u8(s, device_data_len);\n\n                LOG(LOG_LEVEL_INFO, \"Detected remote drive '%s'\",\n                    preferred_dos_name);\n\n                LOG_DEVEL(LOG_LEVEL_DEBUG,\n                          \"device_type=FILE_SYSTEM device_id=0x%x dosname=%s \"\n                          \"device_data_len=%d\", g_device_id,\n                          preferred_dos_name,\n                          device_data_len);\n\n                response_status = STATUS_SUCCESS;\n\n                /* create share directory in xrdp file system;    */\n                /* think of this as the mount point for this share */\n                xfuse_create_share(g_device_id, preferred_dos_name);\n                break;\n\n            case RDPDR_DTYP_SMARTCARD:\n                xstream_skip_u8(s, device_data_len);\n\n                LOG(LOG_LEVEL_INFO, \"Detected remote smartcard '%s'\",\n                    preferred_dos_name);\n\n                LOG_DEVEL(LOG_LEVEL_DEBUG,\n                          \"device_type=SMARTCARD device_id=0x%x dosname=%s\",\n                          g_device_id, preferred_dos_name);\n\n                if (scard_device_announce(g_device_id) == 0)\n                {\n                    response_status = STATUS_SUCCESS;\n                }\n                break;\n\n            default:\n            {\n                /* All other devices are unsupported */\n                const char *description =\n                    (device_type == RDPDR_DTYP_SERIAL) ? \"serial port\" :\n                    (device_type == RDPDR_DTYP_PARALLEL) ? \"parallel port\" :\n                    (device_type == RDPDR_DTYP_PRINT) ?  \"printer\" :\n                    /* default */ \"unknown device\";\n\n                xstream_skip_u8(s, device_data_len);\n                LOG(LOG_LEVEL_INFO, \"Detected remote %s '%s' (not supported)\",\n                    description, preferred_dos_name);\n                LOG_DEVEL(LOG_LEVEL_DEBUG,\n                          \"description=%s dosname=%s device_id=0x%x\",\n                          description, preferred_dos_name, g_device_id);\n            }\n            break;\n        }\n\n        /* Tell the client wheth or not we're supporting this one */\n        devredir_send_server_device_announce_resp(g_device_id,\n                response_status);\n    }\n\n    return 0;\n}\n\nstatic int\ndevredir_proc_client_devlist_remove_req(struct stream *s)\n{\n    unsigned int i;\n    tui32 device_count;\n    tui32 device_id;\n\n    /* get number of devices being announced */\n    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_DEVICELIST_REMOVE\"))\n    {\n        return -1;\n    }\n    xstream_rd_u32_le(s, device_count);\n    if (!s_check_rem_and_log(s, 4 * device_count,\n                             \"Parsing [MS-RDPEFS] DR_DEVICELIST_REMOVE list\"))\n    {\n        return -1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"num of devices removed: %d\", device_count);\n    {\n        for (i = 0; i < device_count; i++)\n        {\n            xstream_rd_u32_le(s, device_id);\n            xfuse_delete_share(device_id);\n        }\n    }\n    return 0;\n}\n\nstatic int\ndevredir_proc_device_iocompletion(struct stream *s)\n{\n    IRP       *irp       = NULL;\n\n    tui32      DeviceId;\n    tui32      CompletionId;\n    tui32      IoStatus32;\n    tui32      Length;\n    enum COMPLETION_TYPE comp_type;\n\n    if (!s_check_rem_and_log(s, 12, \"Parsing [MS-RDPEFS] DR_DEVICE_IOCOMPLETION\"))\n    {\n        return -1;\n    }\n    xstream_rd_u32_le(s, DeviceId);\n    xstream_rd_u32_le(s, CompletionId);\n    xstream_rd_u32_le(s, IoStatus32);\n    enum NTSTATUS IoStatus = (enum NTSTATUS) IoStatus32; /* Needed by C++ */\n\n    if ((irp = devredir_irp_find(CompletionId)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"IRP with completion ID %d not found\", CompletionId);\n    }\n    else if (irp->callback)\n    {\n        /* Callback has been set -  call it */\n        (*irp->callback)(s, irp, DeviceId, CompletionId, IoStatus);\n    }\n    else\n    {\n        comp_type = (enum COMPLETION_TYPE) irp->completion_type;\n        /* Log something about the IRP */\n        if (IoStatus == STATUS_SUCCESS ||\n                IoStatus == STATUS_NO_MORE_FILES ||\n                (IoStatus == STATUS_NO_SUCH_FILE && comp_type == CID_LOOKUP))\n        {\n            /* Successes or common occurrences - debug logging only */\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"got %s\", completion_type_to_str(comp_type));\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"CompletionType = %s, IoStatus=%08x \"\n                      \"Pathname = %s\",\n                      completion_type_to_str(comp_type),\n                      IoStatus,\n                      (irp->pathname) ? irp->pathname : \"<none>\");\n        }\n\n        switch (comp_type)\n        {\n            case CID_CREATE_DIR_REQ:\n                if (IoStatus != STATUS_SUCCESS)\n                {\n                    xfuse_devredir_cb_enum_dir_done(\n                        (struct state_dirscan *) irp->fuse_info, IoStatus);\n                    devredir_irp_delete(irp);\n                }\n                else\n                {\n                    if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_CREATE_RSP\"))\n                    {\n                        return -1;\n                    }\n                    xstream_rd_u32_le(s, irp->FileId);\n                    devredir_send_drive_dir_request(irp, DeviceId,\n                                                    1, irp->pathname);\n                }\n                break;\n\n            case CID_CREATE_REQ:\n                if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_CREATE_RSP\"))\n                {\n                    return -1;\n                }\n                xstream_rd_u32_le(s, irp->FileId);\n\n                xfuse_devredir_cb_create_file(\n                    (struct state_create *) irp->fuse_info,\n                    IoStatus, DeviceId, irp->FileId);\n                if (irp->gen.create.creating_dir || IoStatus != STATUS_SUCCESS)\n                {\n                    devredir_irp_delete(irp);\n                }\n                break;\n\n            case CID_OPEN_REQ:\n                if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_CREATE_RSP\"))\n                {\n                    return -1;\n                }\n                xstream_rd_u32_le(s, irp->FileId);\n\n                xfuse_devredir_cb_open_file((struct state_open *) irp->fuse_info,\n                                            IoStatus, DeviceId, irp->FileId);\n                if (IoStatus != STATUS_SUCCESS)\n                {\n                    devredir_irp_delete(irp);\n                }\n                break;\n\n            case CID_READ:\n                if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_READ_RSP\"))\n                {\n                    return -1;\n                }\n                xstream_rd_u32_le(s, Length);\n                if (!s_check_rem_and_log(s, Length, \"Parsing [MS-RDPEFS] DR_READ_RSP\"))\n                {\n                    return -1;\n                }\n                xfuse_devredir_cb_read_file((struct state_read *) irp->fuse_info,\n                                            IoStatus,\n                                            s->p, Length);\n                devredir_irp_delete(irp);\n                break;\n\n            case CID_WRITE:\n                if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_WRITE_RSP\"))\n                {\n                    return -1;\n                }\n                xstream_rd_u32_le(s, Length);\n                xfuse_devredir_cb_write_file((struct state_write *) irp->fuse_info,\n                                             IoStatus,\n                                             irp->gen.write.offset, Length);\n                devredir_irp_delete(irp);\n                break;\n\n            case CID_CLOSE:\n                devredir_irp_delete(irp);\n                break;\n\n            case CID_FILE_CLOSE:\n                xfuse_devredir_cb_file_close((struct state_close *) irp->fuse_info);\n                devredir_irp_delete(irp);\n                break;\n\n            case CID_DIRECTORY_CONTROL:\n                if (devredir_proc_query_dir_response(irp, s, DeviceId,\n                                                     CompletionId,\n                                                     IoStatus) != 0)\n                {\n                    return -1;\n                }\n                break;\n\n            case CID_RMDIR_OR_FILE:\n                if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_CREATE_RSP\"))\n                {\n                    return -1;\n                }\n                xstream_rd_u32_le(s, irp->FileId);\n                devredir_proc_cid_rmdir_or_file(irp, IoStatus);\n                break;\n\n            case CID_RMDIR_OR_FILE_RESP:\n                devredir_proc_cid_rmdir_or_file_resp(irp, IoStatus);\n                break;\n\n            case CID_RENAME_FILE:\n                if (!s_check_rem_and_log(s, 4, \"Parsing [MS-RDPEFS] DR_CREATE_RSP\"))\n                {\n                    return -1;\n                }\n                xstream_rd_u32_le(s, irp->FileId);\n                devredir_proc_cid_rename_file(irp, IoStatus);\n                break;\n\n            case CID_RENAME_FILE_RESP:\n                devredir_proc_cid_rename_file_resp(irp, IoStatus);\n                break;\n\n            case CID_LOOKUP:\n                devredir_proc_cid_lookup(irp, s, IoStatus);\n                break;\n\n            case CID_SETATTR:\n                devredir_proc_cid_setattr(irp, s, IoStatus);\n                break;\n\n            case CID_STATFS:\n                devredir_proc_cid_statfs(irp, s, IoStatus);\n                break;\n\n            case CID_STATFS_RESP:\n                devredir_proc_cid_statfs_resp(irp, s, IoStatus);\n                break;\n\n            default:\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"got unknown CompletionID: DeviceId=0x%x \"\n                          \"CompletionId=0x%x IoStatus=0x%x\",\n                          DeviceId, CompletionId, IoStatus);\n                break;\n        }\n    }\n    return 0;\n}\n\n/**\n * Parse a query directory response\n *\n * See:-\n * - [MS-RDPEFS] 2.2.3.4.10 (DR_DRIVE_QUERY_DIRECTORY_RSP)\n * - [MS-FSCC] 2.4.10 (FileDirectoryInformation)\n *\n *   return 0 on success, -1 on failure\n */\nstatic int\ndevredir_proc_query_dir_response(IRP *irp,\n                                 struct stream *s_in,\n                                 tui32 DeviceId,\n                                 tui32 CompletionId,\n                                 enum NTSTATUS IoStatus)\n{\n    // Size of FILE_DIRECTORY_INFORMATION structure with a particular\n    // filename length\n#define FILE_DIRECTORY_INFORMATION_SIZE(FileNameLength) \\\n    ((4 + 4 + 8 + 8 + 8 + 8 + 8 + 8 + 4 + 4) + FileNameLength)\n\n    xstream_seek(s_in, 4);  /* Length */\n\n    if (IoStatus == STATUS_SUCCESS)\n    {\n        /* process FILE_DIRECTORY_INFORMATION structures */\n        while (1)\n        {\n            /* Can we read up to the filename? */\n            if (!s_check_rem_and_log(s_in,\n                                     FILE_DIRECTORY_INFORMATION_SIZE(0),\n                                     \"FILE_DIRECTORY_INFORMATION\"))\n            {\n                return -1;\n            }\n\n            // Size the filename buffer so it's big enough for\n            // storing the file in our filesystem if we need to.\n            char  filename[XFS_MAXFILENAMELEN + 1];\n            tui64 LastAccessTime;\n            tui64 LastWriteTime;\n            tui64 EndOfFile;\n            tui32 NextEntryOffset;\n            tui32 FileAttributes;\n            tui32 FileNameLength;\n            struct file_attr fattr;\n            unsigned int flen;\n\n            xstream_rd_u32_le(s_in, NextEntryOffset);\n            xstream_seek(s_in, 4);  /* FileIndex */\n            xstream_seek(s_in, 8);  /* CreationTime */\n            xstream_rd_u64_le(s_in, LastAccessTime);\n            xstream_rd_u64_le(s_in, LastWriteTime);\n            xstream_seek(s_in, 8);  /* ChangeTime */\n            xstream_rd_u64_le(s_in, EndOfFile);\n            xstream_seek(s_in, 8);  /* AllocationSize */\n            xstream_rd_u32_le(s_in, FileAttributes);\n            xstream_rd_u32_le(s_in, FileNameLength);\n            if (!s_check_rem_and_log(s_in,\n                                     FileNameLength,\n                                     \"FILE_DIRECTORY_INFORMATION:FileName\"))\n            {\n                return -1;\n            }\n            flen = in_utf16_le_fixed_as_utf8(s_in, FileNameLength / 2,\n                                             filename, sizeof(filename));\n            if (flen > sizeof(filename))\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Buffer was %d bytes too small for filename\",\n                    (int)(flen - sizeof(filename)));\n            }\n\n            //LOG_DEVEL(LOG_LEVEL_DEBUG, \"LastAccessTime:    0x%llx\", LastAccessTime);\n            //LOG_DEVEL(LOG_LEVEL_DEBUG, \"LastWriteTime:     0x%llx\", LastWriteTime);\n            //LOG_DEVEL(LOG_LEVEL_DEBUG, \"EndOfFile:         %lld\", EndOfFile);\n            //LOG_DEVEL(LOG_LEVEL_DEBUG, \"FileAttributes:    0x%x\", FileAttributes);\n            //LOG_DEVEL(LOG_LEVEL_DEBUG, \"FileNameLength:    %d\", FileNameLength);\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"FileName:          %s\", filename);\n\n            fattr.mode = WindowsToLinuxFilePerm(FileAttributes);\n            fattr.size = (size_t) EndOfFile;\n            fattr.atime = WINDOWS_TO_LINUX_TIME(LastAccessTime);\n            fattr.mtime = WINDOWS_TO_LINUX_TIME(LastWriteTime);\n\n            /* add this entry to xrdp file system */\n            xfuse_devredir_cb_enum_dir_add_entry(\n                (struct state_dirscan *) irp->fuse_info,\n                filename, &fattr);\n\n            /* From [MS-FSCC]\n             * {NextEntryOffset} MUST be zero if no other entries follow\n             * this one. An implementation MUST use this value to determine\n             * the location of the next entry (if multiple entries are\n             * present in a buffer). */\n            if (NextEntryOffset == 0)\n            {\n                break;\n            }\n\n            int pad = NextEntryOffset -\n                      FILE_DIRECTORY_INFORMATION_SIZE(FileNameLength);\n            if (pad > 0)\n            {\n                if (!s_check_rem_and_log(s_in,\n                                         pad,\n                                         \"FILE_DIRECTORY_INFORMATION:pad\"))\n                {\n                    return -1;\n                }\n                xstream_seek(s_in, pad);\n            }\n        }\n\n        /* Ask for more directory entries */\n        devredir_send_drive_dir_request(irp, DeviceId, 0, NULL);\n    }\n    else\n    {\n        if (IoStatus == STATUS_NO_MORE_FILES)\n        {\n            IoStatus = STATUS_SUCCESS;\n        }\n        xfuse_devredir_cb_enum_dir_done((struct state_dirscan *)irp->fuse_info,\n                                        IoStatus);\n        irp->completion_type = CID_CLOSE;\n        devredir_send_drive_close_request(RDPDR_CTYP_CORE,\n                                          PAKID_CORE_DEVICE_IOREQUEST,\n                                          DeviceId,\n                                          irp->FileId,\n                                          irp->CompletionId,\n                                          IRP_MJ_CLOSE, IRP_MN_NONE, 32);\n    }\n\n    return 0;\n#undef FILE_DIRECTORY_INFORMATION_SIZE\n}\n\n/**\n * FUSE calls this function whenever it wants us to enumerate a dir\n *\n * @param fusep     opaque data struct that we just pass back to FUSE when done\n * @param device_id device_id of the redirected share\n * @param path      the dir path to enumerate\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint\ndevredir_get_dir_listing(struct state_dirscan *fusep, tui32 device_id,\n                         const char *path)\n{\n    tui32  DesiredAccess;\n    tui32  CreateOptions;\n    tui32  CreateDisposition;\n    int    rval = -1;\n    IRP   *irp;\n\n    /*\n     * We need to be able to append two additional characters to the\n     * path after we create the IRP\n     */\n    if ((irp = devredir_irp_with_pathnamelen_new(strlen(path) + 2)) != NULL)\n    {\n        /* convert / to windows compatible \\ */\n        strcpy(irp->pathname, path);\n        devredir_cvt_slash(irp->pathname);\n\n        irp->CompletionId = g_completion_id++;\n        irp->completion_type = CID_CREATE_DIR_REQ;\n        irp->DeviceId = device_id;\n        irp->fuse_info = fusep;\n\n        DesiredAccess = DA_FILE_READ_DATA | DA_SYNCHRONIZE;\n        CreateOptions = CO_FILE_DIRECTORY_FILE |\n                        CO_FILE_SYNCHRONOUS_IO_NONALERT;\n        CreateDisposition = CD_FILE_OPEN;\n\n        rval = devredir_send_drive_create_request(device_id, irp->pathname,\n               DesiredAccess, CreateOptions,\n               0, CreateDisposition,\n               irp->CompletionId);\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"looking for device_id=%d path=%s\", device_id, irp->pathname);\n\n        /* when we get a response to devredir_send_drive_create_request(), we\n         * call devredir_send_drive_dir_request(), which needs the following\n         * at the end of the path argument */\n        if (devredir_string_ends_with(irp->pathname, '\\\\'))\n        {\n            strcat(irp->pathname, \"*\");\n        }\n        else\n        {\n            strcat(irp->pathname, \"\\\\*\");\n        }\n    }\n    return rval;\n}\n\n/**\n * FUSE calls this function whenever it wants us to lookup a file or directory\n *\n * @param fusep     opaque data struct that we just pass back to FUSE when done\n * @param device_id device_id of the redirected share\n * @param path      the name of the directory containing the file\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint\ndevredir_lookup_entry(struct state_lookup *fusep, tui32 device_id,\n                      const char *path)\n{\n    tui32  DesiredAccess;\n    tui32  CreateOptions;\n    tui32  CreateDisposition;\n    int    rval = -1;\n    IRP   *irp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"fusep=%p\", fusep);\n\n    if ((irp = devredir_irp_with_pathname_new(path)) != NULL)\n    {\n        /* convert / to windows compatible \\ */\n        devredir_cvt_slash(irp->pathname);\n\n        /*\n         * Allocate an IRP to open the file, read the basic attributes,\n         * read the standard attributes, and then close the file\n         */\n        irp->CompletionId = g_completion_id++;\n        irp->completion_type = CID_LOOKUP;\n        irp->DeviceId = device_id;\n        irp->gen.lookup.state = E_LOOKUP_GET_FH;\n        irp->fuse_info = fusep;\n\n        DesiredAccess = DA_FILE_READ_ATTRIBUTES | DA_SYNCHRONIZE;\n        CreateOptions = 0;\n        CreateDisposition = CD_FILE_OPEN;\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lookup for device_id=%d path=%s CompletionId=%d\",\n                  device_id, irp->pathname, irp->CompletionId);\n\n        rval = devredir_send_drive_create_request(device_id,\n               irp->pathname,\n               DesiredAccess, CreateOptions,\n               0, CreateDisposition,\n               irp->CompletionId);\n    }\n\n    return rval;\n}\n\n/**\n * FUSE calls this function whenever it wants us to set the attributes for\n * a file or directory.\n *\n * @param fusep     opaque data struct that we just pass back to FUSE when done\n * @param device_id device_id of the redirected share\n * @param filename  the name of the file\n * @param fattr     the file attributes to set for the file\n * @param to_set    Which bits of the file attributes have changed\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\nint\ndevredir_setattr_for_entry(struct state_setattr *fusep, tui32 device_id,\n                           const char *filename,\n                           const struct file_attr *fattr,\n                           tui32 to_set)\n{\n    tui32  DesiredAccess;\n    tui32  CreateOptions;\n    tui32  CreateDisposition;\n    int    rval = -1;\n    IRP   *irp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"fusep=%p\", fusep);\n\n    if ((irp = devredir_irp_with_pathname_new(filename)) != NULL)\n    {\n        /* convert / to windows compatible \\ */\n        devredir_cvt_slash(irp->pathname);\n\n        /*\n         * Allocate an IRP to open the file, update the attributes\n         * and close the file.\n         */\n        irp->CompletionId = g_completion_id++;\n        irp->completion_type = CID_SETATTR;\n        irp->DeviceId = device_id;\n        irp->fuse_info = fusep;\n\n        irp->gen.setattr.state = E_SETATTR_GET_FH;\n        irp->gen.setattr.to_set = to_set;\n        irp->gen.setattr.fattr = *fattr;\n\n        /*\n         * Don't set DA_FILE_WRITE_DATA unless we're changing the\n         * EndOfFile pointer. Otherwise we can't change the attributes\n         * of read-only files! */\n        DesiredAccess = DA_FILE_WRITE_ATTRIBUTES;\n        if (to_set & TO_SET_SIZE)\n        {\n            DesiredAccess |= DA_FILE_WRITE_DATA;\n        }\n        CreateOptions = 0;\n        CreateDisposition = CD_FILE_OPEN;\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"lookup for device_id=%d path=%s\",\n                  device_id, irp->pathname);\n\n        rval = devredir_send_drive_create_request(device_id,\n               irp->pathname,\n               DesiredAccess, CreateOptions,\n               0, CreateDisposition,\n               irp->CompletionId);\n    }\n\n    return rval;\n}\n\n/**\n * FUSE calls this function whenever it wants us to run a statfs\n *\n * @param fusep     opaque data struct that we just pass back to FUSE when done\n * @param device_id device_id of the redirected share\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint\ndevredir_statfs(struct state_statfs *fusep, tui32 device_id, const char *path)\n{\n    tui32  DesiredAccess;\n    tui32  CreateOptions;\n    tui32  CreateDisposition;\n    int    rval = -1;\n    IRP   *irp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"fusep=%p\", fusep);\n\n    if ((irp = devredir_irp_with_pathname_new(path)) != NULL)\n    {\n        /* convert / to windows compatible \\ */\n        devredir_cvt_slash(irp->pathname);\n\n        /*\n         * Allocate an IRP to open the file, read the filesystem size\n         * attributes and then close the file\n         */\n        irp->CompletionId = g_completion_id++;\n        irp->completion_type = CID_STATFS;\n        irp->DeviceId = device_id;\n        irp->fuse_info = fusep;\n\n        DesiredAccess = DA_SYNCHRONIZE;\n        CreateOptions = 0;\n        CreateDisposition = CD_FILE_OPEN;\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"statfs for device_id=%d CompletionId=%d\",\n                  device_id, irp->CompletionId);\n\n        rval = devredir_send_drive_create_request(device_id,\n               irp->pathname,\n               DesiredAccess, CreateOptions,\n               0, CreateDisposition,\n               irp->CompletionId);\n    }\n\n    return rval;\n}\n\nint\ndevredir_file_create(struct state_create *fusep, tui32 device_id,\n                     const char *path, int mode)\n{\n    tui32  DesiredAccess;\n    tui32  CreateOptions;\n    tui32  FileAttributes;\n    tui32  CreateDisposition;\n    int    rval = -1;\n    IRP   *irp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"device_id=%d path=%s mode=0%o\", device_id, path, mode);\n\n    if ((irp = devredir_irp_with_pathname_new(path)) != NULL)\n    {\n        /* convert / to windows compatible \\ */\n        devredir_cvt_slash(irp->pathname);\n\n        irp->completion_type = CID_CREATE_REQ;\n        irp->CompletionId = g_completion_id++;\n        irp->DeviceId = device_id;\n        irp->fuse_info = fusep;\n\n\n        DesiredAccess = 0x0016019f; /* got this value from windows */\n        FileAttributes = LinuxToWindowsFilePerm(mode);\n        if (mode & S_IFDIR)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"creating dir\");\n            CreateOptions = CO_FILE_DIRECTORY_FILE | CO_FILE_SYNCHRONOUS_IO_NONALERT;\n            irp->gen.create.creating_dir = 1;\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"creating file\");\n            CreateOptions = 0x44; /* got this value from windows */\n            irp->gen.create.creating_dir = 0;\n        }\n\n        //CreateDisposition = CD_FILE_CREATE;\n        CreateDisposition  = 0x02; /* got this value from windows */\n\n        rval = devredir_send_drive_create_request(device_id, path,\n               DesiredAccess, CreateOptions,\n               FileAttributes,\n               CreateDisposition,\n               irp->CompletionId);\n    }\n\n    return rval;\n}\n\nint\ndevredir_file_open(struct state_open *fusep, tui32 device_id,\n                   const char *path, int flags)\n{\n    tui32  DesiredAccess;\n    tui32  CreateOptions;\n    tui32  FileAttributes = 0;\n    tui32  CreateDisposition;\n    int    rval = -1;\n    IRP   *irp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"device_id=%d path=%s flags=0%x\",\n              device_id, path, flags);\n\n    if ((irp = devredir_irp_with_pathname_new(path)) != NULL)\n    {\n        /* convert / to windows compatible \\ */\n        devredir_cvt_slash(irp->pathname);\n\n        irp->completion_type = CID_OPEN_REQ;\n        irp->CompletionId = g_completion_id++;\n        irp->DeviceId = device_id;\n\n        irp->fuse_info = fusep;\n\n        switch (flags & O_ACCMODE)\n        {\n            case O_RDONLY:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"open file in O_RDONLY\");\n                DesiredAccess = DA_FILE_READ_DATA | DA_SYNCHRONIZE;\n                break;\n\n            case O_WRONLY:\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"open file in O_WRONLY\");\n                DesiredAccess = DA_FILE_WRITE_DATA | DA_SYNCHRONIZE;\n                break;\n\n            default:\n                /*\n                 * The access mode could conceivably be invalid here,\n                 * but we assume this has been checked by the caller\n                 */\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"open file in O_RDWR\");\n                /* without the 0x00000010 rdesktop opens files in */\n                /* O_RDONLY instead of O_RDWR mode                */\n                DesiredAccess = DA_FILE_READ_DATA | DA_FILE_WRITE_DATA |\n                                DA_SYNCHRONIZE | 0x00000010;\n        }\n\n        CreateOptions = CO_FILE_SYNCHRONOUS_IO_NONALERT;\n        CreateDisposition = CD_FILE_OPEN; // WAS 1\n\n        rval = devredir_send_drive_create_request(device_id, path,\n               DesiredAccess, CreateOptions,\n               FileAttributes,\n               CreateDisposition,\n               irp->CompletionId);\n    }\n\n    return rval;\n}\n\nint devredir_file_close(struct state_close *fusep, tui32 device_id,\n                        tui32 FileId)\n{\n    IRP *irp;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: fusep=%p device_id=%d FileId=%d\",\n              fusep, device_id, FileId);\n\n#if 0\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        return -1;\n    }\n\n    irp->CompletionId = g_completion_id++;\n#else\n    if ((irp = devredir_irp_find_by_fileid(FileId)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"no IRP found with FileId = %d\", FileId);\n        return -1;\n    }\n#endif\n    irp->completion_type = CID_FILE_CLOSE;\n    irp->DeviceId = device_id;\n    irp->fuse_info = fusep;\n\n    return devredir_send_drive_close_request(RDPDR_CTYP_CORE,\n            PAKID_CORE_DEVICE_IOREQUEST,\n            device_id,\n            FileId,\n            irp->CompletionId,\n            IRP_MJ_CLOSE,\n            IRP_MN_NONE, 32);\n}\n\n/**\n * Remove (delete) a directory or file\n *****************************************************************************/\n\nint\ndevredir_rmdir_or_file(struct state_remove *fusep, tui32 device_id,\n                       const char *path)\n{\n    tui32  DesiredAccess;\n    tui32  CreateOptions;\n    tui32  CreateDisposition;\n    int    rval = -1;\n    IRP   *irp;\n\n    if ((irp = devredir_irp_with_pathname_new(path)) != NULL)\n    {\n        /* convert / to windows compatible \\ */\n        devredir_cvt_slash(irp->pathname);\n\n        irp->CompletionId = g_completion_id++;\n        irp->completion_type = CID_RMDIR_OR_FILE;\n        irp->DeviceId = device_id;\n\n        irp->fuse_info = fusep;\n\n        //DesiredAccess = DA_DELETE | DA_FILE_READ_ATTRIBUTES | DA_SYNCHRONIZE;\n        DesiredAccess = 0x00100080; /* got this value from windows */\n\n        //CreateOptions = CO_FILE_DELETE_ON_CLOSE | CO_FILE_DIRECTORY_FILE |\n        //                CO_FILE_SYNCHRONOUS_IO_NONALERT;\n        CreateOptions = 0x020; /* got this value from windows */\n\n        //CreateDisposition = CD_FILE_OPEN; // WAS 1\n        CreateDisposition = 0x01; /* got this value from windows */\n\n        rval = devredir_send_drive_create_request(device_id, path,\n               DesiredAccess, CreateOptions,\n               0, CreateDisposition,\n               irp->CompletionId);\n    }\n\n    return rval;\n}\n\n/**\n * Read data from previously opened file\n *\n * Errors are reported via xfuse_devredir_cb_read_file()\n *****************************************************************************/\n\nvoid\ndevredir_file_read(struct state_read *fusep, tui32 DeviceId, tui32 FileId,\n                   tui32 Length, tui64 Offset)\n{\n    struct stream *s;\n    IRP           *new_irp;\n    int            bytes;\n\n    xstream_new(s, 1024);\n\n    /* Check we've got an open IRP for this file already */\n    if (devredir_irp_find_by_fileid(FileId) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"no IRP found with FileId = %d\", FileId);\n        xfuse_devredir_cb_read_file(fusep, STATUS_UNSUCCESSFUL, NULL, 0);\n        xstream_free(s);\n    }\n    /* create a new IRP for this request */\n    else if ((new_irp = devredir_irp_new()) == NULL)\n    {\n        /* system out of memory */\n        xfuse_devredir_cb_read_file(fusep, STATUS_UNSUCCESSFUL, NULL, 0);\n        xstream_free(s);\n    }\n    else\n    {\n        new_irp->DeviceId = DeviceId;\n        new_irp->FileId = FileId;\n        new_irp->completion_type = CID_READ;\n        new_irp->CompletionId = g_completion_id++;\n        new_irp->fuse_info = fusep;\n\n        devredir_insert_DeviceIoRequest(s,\n                                        DeviceId,\n                                        FileId,\n                                        new_irp->CompletionId,\n                                        IRP_MJ_READ,\n                                        IRP_MN_NONE);\n\n        xstream_wr_u32_le(s, Length);\n        xstream_wr_u64_le(s, Offset);\n        xstream_seek(s, 20);\n\n        /* send to client */\n        bytes = xstream_len(s);\n        send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n        xstream_free(s);\n    }\n}\n\n/**\n * Read data from previously opened file\n *\n * Errors are reported via xfuse_devredir_cb_write_file()\n *****************************************************************************/\n\nvoid\ndevredir_file_write(struct state_write *fusep, tui32 DeviceId, tui32 FileId,\n                    const char *buf, int Length, tui64 Offset)\n{\n    struct stream *s;\n    IRP           *new_irp;\n    int            bytes;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"DeviceId=%d FileId=%d Length=%d Offset=%lld\",\n              DeviceId, FileId, Length, (long long)Offset);\n\n    xstream_new(s, 1024 + Length);\n\n    if (devredir_irp_find_by_fileid(FileId) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"no IRP found with FileId = %d\", FileId);\n        xfuse_devredir_cb_write_file(fusep, STATUS_UNSUCCESSFUL, 0, 0);\n        xstream_free(s);\n    }\n    /* create a new IRP for this request */\n    else if ((new_irp = devredir_irp_new()) == NULL)\n    {\n        /* system out of memory */\n        xfuse_devredir_cb_write_file(fusep, STATUS_UNSUCCESSFUL, 0, 0);\n        xstream_free(s);\n    }\n    else\n    {\n        new_irp->DeviceId = DeviceId;\n        new_irp->FileId = FileId;\n        new_irp->completion_type = CID_WRITE;\n        new_irp->CompletionId = g_completion_id++;\n        new_irp->fuse_info = fusep;\n        /* Offset needed after write to calculate new EOF */\n        new_irp->gen.write.offset = Offset;\n\n        devredir_insert_DeviceIoRequest(s,\n                                        DeviceId,\n                                        FileId,\n                                        new_irp->CompletionId,\n                                        IRP_MJ_WRITE,\n                                        IRP_MN_NONE);\n\n        xstream_wr_u32_le(s, Length);\n        xstream_wr_u64_le(s, Offset);\n        xstream_seek(s, 20); /* padding */\n\n        /* now insert real data */\n        xstream_copyin(s, buf, Length);\n\n        /* send to client */\n        bytes = xstream_len(s);\n        send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n        xstream_free(s);\n    }\n\n}\n\n\nint devredir_file_rename(struct state_rename *fusep, tui32 device_id,\n                         const char *old_name,\n                         const char *new_name)\n{\n    tui32  DesiredAccess;\n    tui32  CreateOptions;\n    tui32  FileAttributes = 0;\n    tui32  CreateDisposition;\n    int    rval = -1;\n    IRP   *irp;\n    unsigned int len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"device_id=%d old_name=%s new_name=%s\",\n              device_id, old_name, new_name);\n\n    /*\n     * Allocate an IRP with enough space for both the old and new names.\n     * We'll store the new name after the old name:-\n     *\n     *                 | n | a | m | e | 1 | \\0 | n | a | m | e | 2 | \\0 |\n     *                   ^                        ^\n     * irp->pathname ----+                        |\n     * irp->gen.rename.new_name ------------------+\n     */\n    len = strlen(old_name) + 1 + strlen(new_name);\n    if ((irp = devredir_irp_with_pathnamelen_new(len)) != NULL)\n    {\n        /* Set up pointer to new name string */\n        irp->gen.rename.new_name = irp->pathname + strlen(old_name) + 1;\n\n        /* Copy both strings, and change'/' to '\\\\' characters */\n        strcpy(irp->pathname, old_name);\n        devredir_cvt_slash(irp->pathname);\n        strcpy(irp->gen.rename.new_name, new_name);\n        devredir_cvt_slash(irp->gen.rename.new_name);\n\n        irp->completion_type = CID_RENAME_FILE;\n        irp->CompletionId = g_completion_id++;\n        irp->DeviceId = device_id;\n\n        irp->fuse_info = fusep;\n\n        DesiredAccess = DA_FILE_WRITE_ATTRIBUTES | DA_DELETE;\n        CreateOptions = 0;\n        CreateDisposition = CD_FILE_OPEN; // WAS 1\n\n        rval = devredir_send_drive_create_request(device_id, old_name,\n               DesiredAccess, CreateOptions,\n               FileAttributes,\n               CreateDisposition,\n               irp->CompletionId);\n    }\n\n    return rval;\n}\n\n\n/******************************************************************************\n**                           miscellaneous stuff                             **\n******************************************************************************/\n\nvoid\ndevredir_insert_DeviceIoRequest(struct stream *s,\n                                tui32 DeviceId,\n                                tui32 FileId,\n                                tui32 CompletionId,\n                                enum IRP_MJ MajorFunction,\n                                enum IRP_MN MinorFunction)\n{\n    /* setup DR_DEVICE_IOREQUEST header */\n    xstream_wr_u16_le(s, RDPDR_CTYP_CORE);\n    xstream_wr_u16_le(s, PAKID_CORE_DEVICE_IOREQUEST);\n    xstream_wr_u32_le(s, DeviceId);\n    xstream_wr_u32_le(s, FileId);\n    xstream_wr_u32_le(s, CompletionId);\n    xstream_wr_u32_le(s, MajorFunction);\n    xstream_wr_u32_le(s, MinorFunction);\n}\n\n/**\n * Convert / to windows compatible \\\n *****************************************************************************/\n\nstatic void\ndevredir_cvt_slash(char *path)\n{\n    char *cptr = path;\n\n    while (*cptr != 0)\n    {\n        if (*cptr == '/')\n        {\n            *cptr = '\\\\';\n        }\n        cptr++;\n    }\n}\n\nstatic int\ndevredir_string_ends_with(const char *string, char c)\n{\n    size_t len;\n\n    len = strlen(string);\n    return (len > 0 && string[len - 1] == c) ? 1 : 0;\n}\n\nstatic void\ndevredir_proc_cid_rmdir_or_file(IRP *irp, enum NTSTATUS IoStatus)\n{\n    struct stream *s;\n    int            bytes;\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        xfuse_devredir_cb_rmdir_or_file((struct state_remove *) irp->fuse_info,\n                                        IoStatus);\n        devredir_irp_delete(irp);\n        return;\n    }\n\n    xstream_new(s, 1024);\n\n    irp->completion_type = CID_RMDIR_OR_FILE_RESP;\n    devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,\n                                    irp->CompletionId,\n                                    IRP_MJ_SET_INFORMATION, IRP_MN_NONE);\n\n    xstream_wr_u32_le(s, FileDispositionInformation);\n    xstream_wr_u32_le(s, 0); /* length is zero */\n    xstream_seek(s, 24);     /* padding        */\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n    xstream_free(s);\n\n    return;\n}\n\nstatic void\ndevredir_proc_cid_rmdir_or_file_resp(IRP *irp, enum NTSTATUS IoStatus)\n{\n    xfuse_devredir_cb_rmdir_or_file((struct state_remove *)irp->fuse_info,\n                                    IoStatus);\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        devredir_irp_delete(irp);\n        return;\n    }\n\n    irp->completion_type = CID_CLOSE;\n    devredir_send_drive_close_request(RDPDR_CTYP_CORE,\n                                      PAKID_CORE_DEVICE_IOREQUEST,\n                                      irp->DeviceId,\n                                      irp->FileId,\n                                      irp->CompletionId,\n                                      IRP_MJ_CLOSE, IRP_MN_NONE, 32);\n}\n\n/**\n * Rename a file on response to the create drive request\n *\n * See :-\n * - [MS-RDPEFS] 2.2.3.3.9 (DR_DRIVE_SET_INFORMATION_REQ)`\n * - [MS-RDPEFS] 2.2.3.3.9.1 (RDP_FILE_RENAME_INFORMATION)\n *****************************************************************************/\nstatic void\ndevredir_proc_cid_rename_file(IRP *irp, enum NTSTATUS IoStatus)\n{\n    struct stream *s;\n    int            bytes;\n    unsigned int   flen;  /* FileNameLength */\n    unsigned int   unicode_byte_count; /* Bytes to represent new name in UTF-16 */\n    unsigned int   sblen; /* SetBuffer length */\n\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"rename returned with IoStatus=0x%x\", IoStatus);\n\n        xfuse_devredir_cb_rename_file((struct state_rename *)irp->fuse_info,\n                                      IoStatus);\n        devredir_irp_delete(irp);\n        return;\n    }\n\n    /* Find number of words required for Unicode path */\n    flen = strlen(irp->gen.rename.new_name) + 1; // includes terminator\n    unicode_byte_count = utf8_as_utf16_word_count(irp->gen.rename.new_name, flen) * 2;\n    /* Length of RDP_FILE_RENAME_INFORMATION struct */\n    sblen = (1 + 1 + 4) + unicode_byte_count;\n\n    xstream_new(s, (int)(64 + unicode_byte_count));\n\n    irp->completion_type = CID_RENAME_FILE_RESP;\n    devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,\n                                    irp->CompletionId,\n                                    IRP_MJ_SET_INFORMATION, IRP_MN_NONE);\n\n    xstream_wr_u32_le(s, FileRenameInformation);\n    xstream_wr_u32_le(s, sblen);     /* number of bytes after padding */\n    xstream_seek(s, 24);             /* padding                       */\n    xstream_wr_u8(s, 1);             /* ReplaceIfExists               */\n    xstream_wr_u8(s, 0);             /* RootDirectory                 */\n    xstream_wr_u32_le(s, unicode_byte_count); /* FileNameLength       */\n    /* filename in Unicode */\n    out_utf8_as_utf16_le(s, irp->gen.rename.new_name, flen);\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n    xstream_free(s);\n\n    return;\n}\n\nstatic void\ndevredir_proc_cid_rename_file_resp(IRP *irp, enum NTSTATUS IoStatus)\n{\n    xfuse_devredir_cb_rename_file((struct state_rename *)irp->fuse_info,\n                                  IoStatus);\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        devredir_irp_delete(irp);\n        return;\n    }\n\n    irp->completion_type = CID_CLOSE;\n    devredir_send_drive_close_request(RDPDR_CTYP_CORE,\n                                      PAKID_CORE_DEVICE_IOREQUEST,\n                                      irp->DeviceId,\n                                      irp->FileId,\n                                      irp->CompletionId,\n                                      IRP_MJ_CLOSE, IRP_MN_NONE, 32);\n}\n\n\n/*\n * Re-uses the specified IRP to issue a request to get file attributes\n * of varying types\n *\n * References : [MS-RDPEFS] 2.2.3.3.9  [MS-FSCC] 2.4\n *****************************************************************************/\nstatic void issue_lookup(IRP *irp, int lookup_type)\n{\n    struct stream *s;\n    int  bytes;\n\n    bytes =\n        lookup_type == FileBasicInformation    ? FILE_BASIC_INFORMATION_SIZE :\n        lookup_type == FileStandardInformation ? FILE_STD_INFORMATION_SIZE :\n        0;\n    xstream_new(s, 1024);\n    devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,\n                                    irp->CompletionId,\n                                    IRP_MJ_QUERY_INFORMATION, IRP_MN_NONE);\n\n    xstream_wr_u32_le(s, lookup_type);\n    xstream_wr_u32_le(s, bytes);     /* buffer length                 */\n    xstream_seek(s, 24);             /* padding                       */\n    xstream_seek(s, bytes);          /* buffer                        */\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n    xstream_free(s);\n}\n\n/*\n * Parses an incoming FileBasicInformation structure\n *****************************************************************************/\nstatic void lookup_read_basic_attributes(IRP *irp, struct stream *s_in)\n{\n    tui64 LastAccessTime;\n    tui64 LastWriteTime;\n    tui32 FileAttributes;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"processing FILE_BASIC_INFORMATION\");\n\n    xstream_seek(s_in, 8);  /* CreationTime */\n    xstream_rd_u64_le(s_in, LastAccessTime);\n    xstream_rd_u64_le(s_in, LastWriteTime);\n    xstream_seek(s_in, 8);  /* ChangeTime */\n    xstream_rd_u32_le(s_in, FileAttributes);\n\n    //LOG_DEVEL(LOG_LEVEL_DEBUG, \"LastAccessTime:    0x%llx\",\n    //          (unsigned long long)LastAccessTime);\n    //LOG_DEVEL(LOG_LEVEL_DEBUG, \"LastWriteTime:     0x%llx\",\n    //          (unsigned long long)LastWriteTime);\n    //LOG_DEVEL(LOG_LEVEL_DEBUG, \"ChangeTime:        0x%llx\",\n    //          (unsigned long long)ChangeTime);\n    //LOG_DEVEL(LOG_LEVEL_DEBUG, \"FileAttributes:    0x%x\", (unsigned int)FileAttributes);\n\n    /* Save the basic attributes in the IRP */\n    irp->gen.lookup.fattr.mode = WindowsToLinuxFilePerm(FileAttributes);\n    irp->gen.lookup.fattr.atime = WINDOWS_TO_LINUX_TIME(LastAccessTime);\n    irp->gen.lookup.fattr.mtime = WINDOWS_TO_LINUX_TIME(LastWriteTime);\n}\n\n/*\n * Parses an incoming FileStandardInformation structure\n *****************************************************************************/\nstatic void lookup_read_standard_attributes(IRP *irp, struct stream *s_in)\n{\n    tui64 EndOfFile;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"processing FILE_STD_INFORMATION\");\n    xstream_seek(s_in, 8);  /* AllocationSize */\n    xstream_rd_u64_le(s_in, EndOfFile);\n    //LOG_DEVEL(LOG_LEVEL_DEBUG, \"EndOfFile:         %lld\",\n    //          (unsigned long long)EndOfFile);\n\n    irp->gen.lookup.fattr.size = EndOfFile;\n}\n\n/*\n * Completes a lookup request and returns status to the caller.\n *\n * Unless IoStatus is STATUS_SUCCESS, the lookup has failed.\n *****************************************************************************/\nstatic void lookup_done(IRP *irp, enum NTSTATUS IoStatus)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"Lookup with completion_id=%d returning 0x%x\",\n              irp->CompletionId, IoStatus);\n    xfuse_devredir_cb_lookup_entry((struct state_lookup *)irp->fuse_info,\n                                   IoStatus,\n                                   &irp->gen.lookup.fattr);\n\n    if (irp->FileId == 0)\n    {\n        /* Open failed - no file handle */\n        devredir_irp_delete(irp);\n    }\n    else\n    {\n        /* Close the file handle */\n        irp->completion_type = CID_CLOSE;\n        devredir_send_drive_close_request(RDPDR_CTYP_CORE,\n                                          PAKID_CORE_DEVICE_IOREQUEST,\n                                          irp->DeviceId,\n                                          irp->FileId,\n                                          irp->CompletionId,\n                                          IRP_MJ_CLOSE, IRP_MN_NONE, 32);\n    }\n}\n\n\n/*\n * lookup has a mini state machine built-in, as it needs to issue\n * multiple I/O requests, but unlike lookup these are not always the same.\n */\nstatic void\ndevredir_proc_cid_lookup(IRP *irp,\n                         struct stream *s_in,\n                         enum NTSTATUS IoStatus)\n{\n    tui32 Length;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entry state is %d\", irp->gen.lookup.state);\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        /* This is common to all setattr states */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"last lookup returned with IoStatus=0x%08x\", IoStatus);\n        lookup_done(irp, IoStatus);\n    }\n    else\n    {\n        /* Read and validate any data we've got queued up */\n        switch (irp->gen.lookup.state)\n        {\n            case E_LOOKUP_GET_FH:\n                /* We've been sent the file ID */\n                xstream_rd_u32_le(s_in, irp->FileId);\n                issue_lookup(irp, FileBasicInformation);\n                irp->gen.lookup.state = E_LOOKUP_CHECK_BASIC;\n                break;\n\n            case E_LOOKUP_CHECK_BASIC:\n                /* Returned length what we expected? */\n                xstream_rd_u32_le(s_in, Length);\n                if (Length != FILE_BASIC_INFORMATION_SIZE)\n                {\n                    LOG_DEVEL(LOG_LEVEL_ERROR, \"Expected FILE_BASIC_INFORMATION length\"\n                              \"%d, got len=%d\",\n                              FILE_BASIC_INFORMATION_SIZE, Length);\n                    IoStatus = STATUS_INFO_LENGTH_MISMATCH;\n                    lookup_done(irp, IoStatus);\n                }\n                else\n                {\n                    lookup_read_basic_attributes(irp, s_in);\n                    issue_lookup(irp, FileStandardInformation);\n                    irp->gen.lookup.state = E_LOOKUP_CHECK_EOF;\n                }\n                break;\n\n            case E_LOOKUP_CHECK_EOF:\n                /* Returned length what we expected? */\n                xstream_rd_u32_le(s_in, Length);\n                if (Length != FILE_STD_INFORMATION_SIZE)\n                {\n                    LOG_DEVEL(LOG_LEVEL_ERROR, \"Expected FILE_STD_INFORMATION length\"\n                              \"%d, got len=%d\",\n                              FILE_STD_INFORMATION_SIZE, Length);\n                    IoStatus = STATUS_INFO_LENGTH_MISMATCH;\n                }\n                else\n                {\n                    lookup_read_standard_attributes(irp, s_in);\n                }\n                lookup_done(irp, IoStatus);\n                break;\n        }\n    }\n}\n\n\n/*****************************************************************************/\nstatic void\ndevredir_proc_cid_statfs(IRP *irp,\n                         struct stream *s_in,\n                         enum NTSTATUS IoStatus)\n{\n    struct stream *s;\n    int            bytes;\n    char size_info_struct[FILE_FS_FULL_SIZE_INFORMATION_SIZE] = {0};\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        struct statvfs fss = {0};\n        LOG_DEVEL(LOG_LEVEL_DEBUG,\n                  \"statfs returned with IoStatus=0x%x\", IoStatus);\n\n        xfuse_devredir_cb_statfs((struct state_statfs *)irp->fuse_info,\n                                 &fss,\n                                 IoStatus);\n        devredir_irp_delete(irp);\n        return;\n    }\n\n    xstream_new(s, (int)(64 + sizeof(size_info_struct)));\n\n    irp->completion_type = CID_STATFS_RESP;\n    devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,\n                                    irp->CompletionId,\n                                    IRP_MJ_QUERY_VOLUME_INFORMATION,\n                                    IRP_MN_NONE);\n\n    xstream_wr_u32_le(s, FileFsFullSizeInformation);\n    xstream_wr_u32_le(s, sizeof(size_info_struct));\n    /* number of bytes after padding */\n    xstream_seek(s, 24);             /* padding                       */\n    xstream_copyin(s, size_info_struct, sizeof(size_info_struct));\n    /* Queried structure             */\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n    xstream_free(s);\n}\n\n/* [MS-RDPEFS] 2.2.3.4.6 */\nstatic void\ndevredir_proc_cid_statfs_resp(IRP *irp,\n                              struct stream *s_in,\n                              enum NTSTATUS IoStatus)\n{\n    struct statvfs fss = {0};\n    tui32 Length;\n    if (IoStatus == STATUS_SUCCESS)\n    {\n        xstream_rd_u32_le(s_in, Length);\n        if (Length != FILE_FS_FULL_SIZE_INFORMATION_SIZE)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR,\n                      \"Expected FILE_FS_FULL_SIZE_INFORMATION_SIZE length\"\n                      \" %d, got len=%d\",\n                      FILE_FS_FULL_SIZE_INFORMATION_SIZE, Length);\n            IoStatus = STATUS_INFO_LENGTH_MISMATCH;\n        }\n        else\n        {\n            tui64 TotalAllocationUnits;\n            tui64 CallerAvailableAllocationUnits;\n            tui64 ActualAvailableAllocationUnits;\n            tui32 SectorsPerAllocationUnit;\n            tui32 BytesPerSector;\n            unsigned int block_size;\n\n            xstream_rd_u64_le(s_in, TotalAllocationUnits);\n            xstream_rd_u64_le(s_in, CallerAvailableAllocationUnits);\n            xstream_rd_u64_le(s_in, ActualAvailableAllocationUnits);\n            xstream_rd_u32_le(s_in, SectorsPerAllocationUnit);\n            xstream_rd_u32_le(s_in, BytesPerSector);\n\n            block_size = SectorsPerAllocationUnit * BytesPerSector;\n            if (block_size < 512 ||  block_size > 131072)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"Unreasonable block size for file system : %u\",\n                    block_size);\n            }\n            else\n            {\n                fss.f_bsize = block_size;\n                fss.f_frsize = block_size;\n                fss.f_blocks = TotalAllocationUnits;\n                fss.f_bfree = ActualAvailableAllocationUnits;\n                fss.f_bavail = CallerAvailableAllocationUnits;\n                // Following values do not seem to be needed by\n                // any applications. btrfs also returns 0 for these\n                //fss.f_files = ???;\n                //fss.f_ffree = ???;\n                //fss.f_favail = fss.f_ffree;\n                // Chromium 130 needs this set, or the user can't save\n                // to our filesystem\n                fss.f_namemax = XFS_MAXFILENAMELEN;\n            }\n        }\n    }\n    xfuse_devredir_cb_statfs((struct state_statfs *)irp->fuse_info,\n                             &fss, IoStatus);\n\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        devredir_irp_delete(irp);\n    }\n    else\n    {\n        irp->completion_type = CID_CLOSE;\n        devredir_send_drive_close_request(RDPDR_CTYP_CORE,\n                                          PAKID_CORE_DEVICE_IOREQUEST,\n                                          irp->DeviceId,\n                                          irp->FileId,\n                                          irp->CompletionId,\n                                          IRP_MJ_CLOSE, IRP_MN_NONE, 32);\n    }\n}\n\n/*\n * Re-uses the specified IRP to issue a request to set basic file attributes\n *\n * References : [MS-RDPEFS] 2.2.3.3.9  [MS-FSCC] 2.4.7\n *****************************************************************************/\nstatic void issue_setattr_basic(IRP *irp)\n{\n    struct stream *s;\n    int  bytes;\n    const struct file_attr *fattr = &irp->gen.setattr.fattr;\n    tui32 to_set = irp->gen.setattr.to_set;\n\n    tui32 FileAttributes = 0;\n    tui64 atime = 0;\n    tui64 mtime = 0;\n\n    if (to_set & TO_SET_MODE)\n    {\n        FileAttributes = LinuxToWindowsFilePerm(fattr->mode);\n    }\n    if (to_set & TO_SET_ATIME)\n    {\n        atime = LINUX_TO_WINDOWS_TIME(fattr->atime);\n    }\n    if (to_set & TO_SET_MTIME)\n    {\n        mtime = LINUX_TO_WINDOWS_TIME(fattr->mtime);\n    }\n\n    xstream_new(s, 1024);\n    devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,\n                                    irp->CompletionId,\n                                    IRP_MJ_SET_INFORMATION, IRP_MN_NONE);\n\n    xstream_wr_u32_le(s, FileBasicInformation);\n    xstream_wr_u32_le(s, FILE_BASIC_INFORMATION_SIZE);\n    /* buffer length                 */\n    xstream_seek(s, 24);             /* padding                       */\n\n    xstream_wr_u64_le(s, 0LL);            /* CreationTime */\n    xstream_wr_u64_le(s, atime);          /* LastAccessTime */\n    xstream_wr_u64_le(s, mtime);          /* LastWriteTime */\n    xstream_wr_u64_le(s, 0LL);            /* ChangeTime */\n    xstream_wr_u32_le(s, FileAttributes); /* FileAttributes */\n\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n    xstream_free(s);\n}\n\n\n/*\n * Re-uses the specified IRP to issue a request to set file EOF\n *\n * References : [MS-RDPEFS] 2.2.3.3.9  [MS-FSCC] 2.4.13\n *****************************************************************************/\nstatic void issue_setattr_eof(IRP *irp)\n{\n    struct stream *s;\n    int  bytes;\n\n    xstream_new(s, 1024);\n    devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,\n                                    irp->CompletionId,\n                                    IRP_MJ_SET_INFORMATION, IRP_MN_NONE);\n\n    xstream_wr_u32_le(s, FileEndOfFileInformation);\n    xstream_wr_u32_le(s, FILE_END_OF_FILE_INFORMATION_SIZE);\n    /* buffer length             */\n    xstream_seek(s, 24);         /* padding                   */\n    xstream_wr_u64_le(s, (tui64)irp->gen.setattr.fattr.size);\n    /* File size                 */\n    /* send to client */\n    bytes = xstream_len(s);\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n    xstream_free(s);\n}\n\n/*\n * Completes a setattr request and returns status to the caller.\n *****************************************************************************/\nstatic void setattr_done(IRP *irp, enum NTSTATUS IoStatus)\n{\n    xfuse_devredir_cb_setattr((struct state_setattr *) irp->fuse_info,\n                              IoStatus);\n\n    if (irp->FileId == 0)\n    {\n        /* Open failed - no file handle */\n        devredir_irp_delete(irp);\n    }\n    else\n    {\n        /* Close the file handle */\n        irp->completion_type = CID_CLOSE;\n        devredir_send_drive_close_request(RDPDR_CTYP_CORE,\n                                          PAKID_CORE_DEVICE_IOREQUEST,\n                                          irp->DeviceId,\n                                          irp->FileId,\n                                          irp->CompletionId,\n                                          IRP_MJ_CLOSE, IRP_MN_NONE, 32);\n    }\n}\n\n\n/*\n * setattr has a mini state machine built-in, as it needs to issue\n * multiple I/O requests, but unlike lookup these are not always the same.\n */\nstatic void\ndevredir_proc_cid_setattr(IRP *irp,\n                          struct stream *s_in,\n                          enum NTSTATUS IoStatus)\n{\n#define TO_SET_BASIC_ATTRS (TO_SET_MODE | \\\n                            TO_SET_ATIME | TO_SET_MTIME)\n    tui32 Length;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entry state is %d\", irp->gen.setattr.state);\n    if (IoStatus != STATUS_SUCCESS)\n    {\n        /* This is common to all setattr states */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"last setattr returned with IoStatus=0x%08x\", IoStatus);\n        setattr_done(irp, IoStatus);\n    }\n    else\n    {\n        /* Read and validate any data we've got queued up */\n        switch (irp->gen.setattr.state)\n        {\n            case E_SETATTR_GET_FH:\n                /* We've been sent the file ID */\n                xstream_rd_u32_le(s_in, irp->FileId);\n                break;\n\n            case E_SETATTR_CHECK_BASIC:\n                /* Returned length what we expected? */\n                xstream_rd_u32_le(s_in, Length);\n                if (Length != FILE_BASIC_INFORMATION_SIZE)\n                {\n                    LOG_DEVEL(LOG_LEVEL_ERROR, \"Expected FILE_BASIC_INFORMATION length\"\n                              \"%d, got len=%d\",\n                              FILE_BASIC_INFORMATION_SIZE, Length);\n                }\n\n                /* Clear the basic bits so we don't end up in here again */\n                irp->gen.setattr.to_set &= ~TO_SET_BASIC_ATTRS;\n                break;\n\n            case E_SETATTR_CHECK_EOF:\n                /* Returned length what we expected? */\n                xstream_rd_u32_le(s_in, Length);\n                if (Length != FILE_END_OF_FILE_INFORMATION_SIZE)\n                {\n                    LOG_DEVEL(LOG_LEVEL_ERROR, \"Expected FILE_END_OF_FILE_INFORMATION length\"\n                              \"%d, got len=%d\",\n                              FILE_END_OF_FILE_INFORMATION_SIZE, Length);\n                }\n\n                /* Clear the size bits so we don't end up in here again */\n                irp->gen.setattr.to_set &= ~TO_SET_SIZE;\n                break;\n        }\n\n        /* Work out the next call to issue */\n        if (irp->gen.setattr.to_set & TO_SET_BASIC_ATTRS)\n        {\n            issue_setattr_basic(irp);\n            irp->gen.setattr.state = E_SETATTR_CHECK_BASIC;\n        }\n        else if (irp->gen.setattr.to_set & TO_SET_SIZE)\n        {\n            issue_setattr_eof(irp);\n            irp->gen.setattr.state = E_SETATTR_CHECK_EOF;\n        }\n        else\n        {\n            setattr_done(irp, IoStatus);\n        }\n    }\n#undef TO_SET_BASIC_ATTRS\n}\n"
  },
  {
    "path": "sesman/chansrv/devredir.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * xrdp device redirection - we mainly use it for drive redirection\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(DEVREDIR_H)\n#define DEVREDIR_H\n\n#include \"irp.h\"\n#include \"ms-rdpefs.h\"\n\nint devredir_init(void);\nint devredir_deinit(void);\n\nint devredir_data_in(struct stream *s, int chan_id, int chan_flags,\n                     int length, int total_length);\n\nint devredir_get_wait_objs(tbus *objs, int *count, int *timeout);\nint devredir_check_wait_objs(void);\n\n/* misc stuff */\nvoid devredir_insert_DeviceIoRequest(struct stream *s,\n                                     tui32 DeviceId,\n                                     tui32 FileId,\n                                     tui32 CompletionId,\n                                     enum IRP_MJ MajorFunction,\n                                     enum IRP_MN MinorFunction);\n\n/* State pointer types (opaque outside this module), used for\n * callback data\n */\nstruct state_dirscan;\nstruct state_lookup;\nstruct state_setattr;\nstruct state_open;\nstruct state_create;\nstruct state_read;\nstruct state_write;\nstruct state_remove;\nstruct state_close;\nstruct state_statfs;\n\n/* called from FUSE module */\n\nint devredir_get_dir_listing(struct state_dirscan *fusep, tui32 device_id,\n                             const char *path);\n\nint devredir_lookup_entry(struct state_lookup *fusep, tui32 device_id,\n                          const char *path);\n\nint devredir_setattr_for_entry(\n    struct state_setattr *fusep, tui32 device_id,\n    const char *filename,\n    const struct file_attr *fattr,\n    tui32 to_set);\n\nint devredir_file_create(\n    struct state_create *fusep, tui32 device_id,\n    const char *path, int mode);\n\nint devredir_file_open(struct state_open *fusep, tui32 device_id,\n                       const char *path, int flags);\n\nint devredir_file_close(struct state_close *fusep, tui32 device_id,\n                        tui32 file_id);\n\nvoid\ndevredir_file_read(struct state_read *fusep, tui32 device_id, tui32 FileId,\n                   tui32 Length, tui64 Offset);\n\nvoid\ndevredir_file_write(struct state_write *fusep, tui32 DeviceId, tui32 FileId,\n                    const char *buf, int Length, tui64 Offset);\n\nint devredir_file_rename(\n    struct state_rename *fusep, tui32 device_id,\n    const char *old_name,\n    const char *new_name);\n\nint\ndevredir_rmdir_or_file(struct state_remove *fusep, tui32 device_id,\n                       const char *path);\n\nint\ndevredir_statfs(struct state_statfs *fusep, tui32 device_id, const char *path);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/input.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n#if !defined(INPUT_H)\n#define INPUT_H\n\n#include \"arch.h\"\n#include \"parse.h\"\n\nint\nxrdp_input_send_unicode(char32_t unicode);\n\nint\nxrdp_input_unicode_init(void);\n\nint\nxrdp_input_unicode_destroy(void);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/input_ibus.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2009-2013\n * Copyright (C) Laxmikant Rashinkar 2009-2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <glib.h>\n#include <glib-object.h>\n#include <glib/gstdio.h>\n#include <ibus.h>\n#include \"input.h\"\n#include \"thread_calls.h\"\n\nstatic IBusBus *bus;\nstatic IBusEngine *g_engine;\n/* This is the engine name enabled before unicode engine enabled */\nstatic const gchar *last_input_name;\nstatic int id = 0;\n\nstatic int\nxrdp_input_enable(void)\n{\n    IBusEngineDesc *desc;\n    const gchar *name;\n\n    if (last_input_name)\n    {\n        /* already enabled */\n        return 0;\n    }\n\n    if (!bus)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_ibus_init: input method switched failed, ibus not connected\");\n        return 1;\n    }\n\n    desc = ibus_bus_get_global_engine(bus);\n    name = ibus_engine_desc_get_name (desc);\n    if (!g_ascii_strcasecmp(name, \"XrdpIme\"))\n    {\n        return 0;\n    }\n\n    /* remember user's input method, will switch back when disconnect */\n    last_input_name = name;\n\n    if (!ibus_bus_set_global_engine(bus, \"XrdpIme\"))\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_input_enable: input method enable failed\");\n        return 1;\n    }\n\n    LOG(LOG_LEVEL_INFO, \"xrdp_ibus_init: input method switched sucessfully, old input name: %s\", last_input_name);\n\n    return 0;\n}\n\nint\nxrdp_input_send_unicode(char32_t unicode)\n{\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_input_send_unicode: received unicode input %i\", unicode);\n\n    if (xrdp_input_enable())\n    {\n        return 1;\n    }\n\n    gunichar chr = unicode;\n    ibus_engine_commit_text(g_engine, ibus_text_new_from_unichar(chr));\n\n    return 0;\n}\n\nstatic void\nxrdp_input_ibus_engine_enable(IBusEngine *engine)\n{\n    LOG(LOG_LEVEL_INFO, \"xrdp_ibus_engine_enable: IM enabled\");\n    g_engine = engine;\n}\n\nstatic void\nxrdp_input_ibus_engine_disable(IBusEngine *engine)\n{\n    LOG(LOG_LEVEL_INFO, \"xrdp_ibus_engine_disable: IM disabled\");\n}\n\nstatic void\nxrdp_input_ibus_disconnect(IBusEngine *engine)\n{\n    LOG(LOG_LEVEL_INFO, \"xrdp_ibus_engine_disable: IM disabled\");\n    g_object_unref(g_engine);\n    g_object_unref(bus);\n}\n\nstatic gboolean\nengine_process_key_event_cb(IBusEngine *engine,\n                            guint keyval,\n                            guint keycode,\n                            guint state)\n{\n    /* Pass the keyboard event to system */\n    return FALSE;\n}\n\nstatic IBusEngine *\nxrdp_input_ibus_create_engine(IBusFactory *factory,\n                              gchar *engine_name,\n                              gpointer user_data)\n{\n    IBusEngine *engine;\n    gchar *path = g_strdup_printf(\"/org/freedesktop/IBus/Engine/%i\", 1);\n    engine = ibus_engine_new(engine_name,\n                             path,\n                             ibus_bus_get_connection(bus));\n\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_input_ibus_create_engine: Creating IM Engine with name:%s and id:%d\\n\", engine_name, ++id);\n\n    g_signal_connect(engine, \"process-key-event\", G_CALLBACK(engine_process_key_event_cb), NULL);\n    g_signal_connect(engine, \"enable\", G_CALLBACK(xrdp_input_ibus_engine_enable), NULL);\n    g_signal_connect(engine, \"disable\", G_CALLBACK(xrdp_input_ibus_engine_disable), NULL);\n\n    return engine;\n}\n\n/*****************************************************************************/\nstatic THREAD_RV THREAD_CC\nxrdp_input_main_loop(void *in_val)\n{\n    IBusFactory *factory;\n    IBusComponent *component;\n    IBusEngineDesc *desc;\n    THREAD_RV rv = 0;\n\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_input_main_loop: Entering ibus loop\");\n\n    g_signal_connect(bus, \"disconnected\", G_CALLBACK(xrdp_input_ibus_disconnect), NULL);\n\n    factory = ibus_factory_new(ibus_bus_get_connection(bus));\n    g_object_ref_sink(factory);\n    g_signal_connect(factory, \"create-engine\", G_CALLBACK(xrdp_input_ibus_create_engine), NULL);\n\n    ibus_factory_add_engine(factory, \"XrdpIme\", IBUS_TYPE_ENGINE);\n\n    component = ibus_component_new(\"org.freedesktop.IBus.XrdpIme\", /* name */\n                                   \"Xrdp input method\",            /* description */\n                                   \"1.1\",                          /* version */\n                                   \"MIT\",                          /* license */\n                                   \"seflerZ\",                      /* author */\n                                   \"default\",                      /* homepage */\n                                   \"default\",                      /* cmd */\n                                   \"xrdpime\");                     /* text domain */\n\n    desc = ibus_engine_desc_new(\"XrdpIme\",\n                                \"unicode input method for xrdp\",\n                                \"unicode input method for xrdp\",\n                                \"unicode\",\n                                \"MIT\",\n                                \"seflerZ\",\n                                \"default\",  /* icon */\n                                \"default\"); /* layout */\n\n    ibus_component_add_engine(component, desc);\n    ibus_bus_register_component(bus, component);\n\n    ibus_main();\n\n    g_object_unref(desc);\n    g_object_unref(component);\n    g_object_unref(factory);\n\n    return rv;\n}\n\nint\nxrdp_input_unicode_destroy(void)\n{\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_input_unicode_destory: ibus input is under destory\");\n    if (last_input_name)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_input_unicode_destory: ibus engine rolling back to origin: %s\", last_input_name);\n        ibus_bus_set_global_engine(bus, last_input_name);\n    }\n\n    g_object_unref(g_engine);\n    g_object_unref(bus);\n\n    last_input_name = NULL;\n    bus = NULL;\n    g_engine = NULL;\n\n    return 0;\n}\n\nint\nxrdp_input_unicode_init(void)\n{\n    if (bus)\n    {\n        /* Already initialized, just re-enable it */\n        xrdp_input_enable();\n        return 0;\n    }\n\n    /* Wait because the ibus daemon may not be ready on first login */\n    const char *addr = ibus_get_address();\n    unsigned int cnt = 0;\n    while (!addr && cnt < 10)\n    {\n        usleep(500 * 1000); // half a second\n        addr = ibus_get_address();\n        ++cnt;\n    }\n    if (!addr)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_ibus_init: Timed out waiting for iBus daemon\");\n        return 1;\n    }\n\n    LOG(LOG_LEVEL_INFO, \"xrdp_ibus_init: Initializing the iBus engine\");\n    ibus_init();\n    bus = ibus_bus_new();\n    g_object_ref_sink(bus);\n\n    if (!ibus_bus_is_connected(bus))\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_ibus_init: Connect to iBus failed\");\n        return 1;\n    }\n\n    LOG(LOG_LEVEL_INFO, \"xrdp_ibus_init: iBus connected\");\n\n    tc_thread_create(xrdp_input_main_loop, NULL);\n\n    if (!ibus_bus_get_global_engine(bus))\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_ibus_init: failed to get origin global engine\");\n        return 1;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "sesman/chansrv/irp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/*\n * manage I/O for redirected file system and devices\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"chansrv.h\"\n#include \"parse.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"irp.h\"\n\nIRP *g_irp_head = NULL;\n\n/**\n * Create a new IRP and append to linked list\n *\n * @return new IRP or NULL on error\n *****************************************************************************/\n\nIRP *devredir_irp_new(void)\n{\n    IRP *irp;\n    IRP *irp_last;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* create new IRP */\n    irp = g_new0(IRP, 1);\n    if (irp == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory!\");\n        return NULL;\n    }\n\n    /* insert at end of linked list */\n    if ((irp_last = devredir_irp_get_last()) == NULL)\n    {\n        /* list is empty, this is the first entry */\n        g_irp_head = irp;\n    }\n    else\n    {\n        irp_last->next = irp;\n        irp->prev = irp_last;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"new IRP=%p\", irp);\n    return irp;\n}\n\n/**\n * Create a new IRP with a copied pathname, and append to linked list.\n *\n * Allocation is made in such a way that the IRP can be freed with a single\n * free() operation\n *\n * @return new IRP or NULL on error\n *****************************************************************************/\n\nIRP *devredir_irp_with_pathname_new(const char *pathname)\n{\n    unsigned int len = g_strlen(pathname);\n    IRP *irp = devredir_irp_with_pathnamelen_new(len);\n    if (irp != NULL)\n    {\n        g_strcpy(irp->pathname, pathname);\n    }\n\n    return irp;\n}\n\n/**\n * Create a new IRP with space allocated for a pathname, and append to\n * linked list.\n *\n * Allocation is made in such a way that the IRP can be freed with a single\n * free() operation\n *\n * @return new IRP or NULL on error\n *****************************************************************************/\n\nIRP *devredir_irp_with_pathnamelen_new(unsigned int pathnamelen)\n{\n    IRP *irp;\n    IRP *irp_last;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* create new IRP with space on end for the pathname and a terminator */\n    irp = (IRP *)g_malloc(sizeof(IRP) + (pathnamelen + 1), 1);\n    if (irp == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory!\");\n        return NULL;\n    }\n\n    irp->pathname = (char *)irp + sizeof(IRP); /* Initialise pathname pointer */\n\n    /* insert at end of linked list */\n    if ((irp_last = devredir_irp_get_last()) == NULL)\n    {\n        /* list is empty, this is the first entry */\n        g_irp_head = irp;\n    }\n    else\n    {\n        irp_last->next = irp;\n        irp->prev = irp_last;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"new IRP=%p\", irp);\n    return irp;\n}\n\n/**\n * Delete specified IRP from linked list\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\n\nint devredir_irp_delete(IRP *irp)\n{\n    IRP *lirp = g_irp_head;\n\n    if ((irp == NULL) || (lirp == NULL))\n    {\n        return -1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"irp=%p completion_id=%d type=%d\",\n              irp, irp->CompletionId, irp->completion_type);\n\n    devredir_irp_dump(); // LK_TODO\n\n    while (lirp)\n    {\n        if (lirp == irp)\n        {\n            break;\n        }\n\n        lirp = lirp->next;\n    }\n\n    if (lirp == NULL)\n    {\n        return -1;    /* did not find specified irp */\n    }\n\n    if (lirp->prev == NULL)\n    {\n        /* we are at head of linked list */\n        if (lirp->next == NULL)\n        {\n            /* only one element in list */\n            g_free(lirp);\n            g_irp_head = NULL;\n            devredir_irp_dump(); // LK_TODO\n            return 0;\n        }\n\n        lirp->next->prev = NULL;\n        g_irp_head = lirp->next;\n        g_free(lirp);\n    }\n    else if (lirp->next == NULL)\n    {\n        /* we are at tail of linked list */\n        lirp->prev->next = NULL;\n        g_free(lirp);\n    }\n    else\n    {\n        /* we are in between */\n        lirp->prev->next = lirp->next;\n        lirp->next->prev = lirp->prev;\n        g_free(lirp);\n    }\n\n    devredir_irp_dump(); // LK_TODO\n\n    return 0;\n}\n\n/**\n * Return IRP containing specified completion_id\n *****************************************************************************/\n\nIRP *devredir_irp_find(tui32 completion_id)\n{\n    IRP *irp = g_irp_head;\n\n    while (irp)\n    {\n        if (irp->CompletionId == completion_id)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"returning irp=%p\", irp);\n            return irp;\n        }\n\n        irp = irp->next;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"returning irp=NULL\");\n    return NULL;\n}\n\nIRP *devredir_irp_find_by_fileid(tui32 FileId)\n{\n    IRP *irp = g_irp_head;\n\n    while (irp)\n    {\n        if (irp->FileId == FileId)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"returning irp=%p\", irp);\n            return irp;\n        }\n\n        irp = irp->next;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"returning irp=NULL\");\n    return NULL;\n}\n\n/**\n * Return last IRP in linked list\n *****************************************************************************/\n\nIRP *devredir_irp_get_last(void)\n{\n    IRP *irp = g_irp_head;\n\n    while (irp)\n    {\n        if (irp->next == NULL)\n        {\n            break;\n        }\n\n        irp = irp->next;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"returning irp=%p\", irp);\n    return irp;\n}\n\nvoid devredir_irp_dump(void)\n{\n    IRP *irp = g_irp_head;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"------- dumping IRPs --------\");\n    while (irp)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"        completion_id=%d\\tcompletion_type=%d\\tFileId=%d\",\n                  irp->CompletionId, irp->completion_type, irp->FileId);\n\n        irp = irp->next;\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"------- dumping IRPs done ---\");\n}\n"
  },
  {
    "path": "sesman/chansrv/irp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/*\n * manage I/O for redirected file system and devices\n */\n\n#ifndef __IRP_H\n#define __IRP_H\n\n#ifndef _TIME_H_\n#include <time.h>\n#endif\n#include \"chansrv_fuse.h\"\n\n/* Opaque data types to us */\ntypedef struct xfuse_info XFUSE_INFO;\n\nenum irp_lookup_state\n{\n    E_LOOKUP_GET_FH = 0,\n    E_LOOKUP_CHECK_BASIC,\n    E_LOOKUP_CHECK_EOF\n} ;\n\nenum irp_setattr_state\n{\n    E_SETATTR_GET_FH = 0,\n    E_SETATTR_CHECK_BASIC,\n    E_SETATTR_CHECK_EOF\n} ;\n\nstruct irp_lookup\n{\n    enum irp_lookup_state state; /* Next state to consider */\n    struct file_attr fattr;      /* Attributes to get */\n};\n\nstruct irp_setattr\n{\n    enum irp_setattr_state state; /* Next state to consider */\n    tui32            to_set;      /* Bit mask for elements in use */\n    struct file_attr fattr;       /* Attributes to set */\n};\n\nstruct irp_write\n{\n    tui64            offset;      /* Offset the write was made at */\n};\n\nstruct irp_create\n{\n    int             creating_dir; /* We're creating a directory */\n};\n\nstruct irp_rename\n{\n    char           *new_name;     /* New name for file */\n};\n\n/* An I/O Resource Packet to track I/O calls */\n\ntypedef struct irp IRP;\n\nstruct irp\n{\n    tui32      CompletionId;        /* unique number                     */\n    tui32      DeviceId;            /* identifies remote device          */\n    tui32      FileId;              /* RDP client provided unique number */\n    char       completion_type;     /* describes I/O type                */\n    char       *pathname;           /* absolute pathname\n                                     * Allocate with\n                                     * devredir_irp_with_pathname_new()  */\n    union\n    {\n        struct irp_lookup  lookup;  /* Used by lookup                    */\n        struct irp_setattr setattr; /* Used by setattr                   */\n        struct irp_write   write;   /* Used by write                     */\n        struct irp_create  create;  /* Used by create                    */\n        struct irp_rename  rename;  /* Use by rename                     */\n    } gen;                          /* Additional state data for some ops */\n    void      *fuse_info;           /* Fuse info pointer for FUSE calls  */\n    IRP       *next;                /* point to next IRP                 */\n    IRP       *prev;                /* point to previous IRP             */\n    int        scard_index;         /* used to smart card to locate dev  */\n\n    void     (*callback)(struct stream *s, IRP *irp, tui32 DeviceId,\n                         tui32 CompletionId, tui32 IoStatus);\n    void      *user_data;\n};\n\nIRP *devredir_irp_new(void);\n/* As above, but allocates sufficient space for the specified\n * pathname, and copies it in to the pathname field */\nIRP *devredir_irp_with_pathname_new(const char *pathname);\n/* As above, but specifies a pathname length with pathname\n * initially set to \"\". Use if you need to modify the pathname\n * significantly */\nIRP *devredir_irp_with_pathnamelen_new(unsigned int pathnamelen);\nint   devredir_irp_delete(IRP *irp);\nIRP *devredir_irp_find(tui32 completion_id);\nIRP *devredir_irp_find_by_fileid(tui32 FileId);\nIRP *devredir_irp_get_last(void);\nvoid  devredir_irp_dump(void);\n\n#endif /* end ifndef __IRP_H */\n"
  },
  {
    "path": "sesman/chansrv/pcsc/.gitignore",
    "content": "!Makefile\n"
  },
  {
    "path": "sesman/chansrv/pcsc/Makefile",
    "content": "\nOBJS = xrdp_pcsc.o\n\nCFLAGS = -Wall -O2 -fPIC\n\nall: libpcsclite.so\n\nlibpcsclite.so: $(OBJS)\n\t$(CC) $(LDFLAGS) -shared -o libpcsclite.so $(OBJS)\n\nclean:\n\trm -f $(OBJS) libpcsclite.so\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-begin-tranaction.txt",
    "content": "TS_SCardBeginTransaction:\n0000 03 00 00 93 02 f0 80 68 00 01 03 ed f0 80 84 08 .......h........\n0010 00 00 00 de 14 5c 5a 9e 86 37 2b 70 00 00 00 03 .....\\Z..7+p....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 02 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 38 ...............8\n0040 00 00 00 bc 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 28 00 00 00 00 00 00 00 04 00 00 00 00 ...(............\n0070 00 02 00 04 00 00 00 04 00 02 00 00 00 00 00 04 ................\n0080 00 00 00 02 00 00 00 04 00 00 00 0a 00 00 00 00 ................\n0090 00 00 00                                        ...\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-connect.txt",
    "content": "TS_SCardConnect:\n0000 03 00 00 cb 02 f0 80 68 00 01 03 ed f0 80 bc 08 .......h........\n0010 00 00 00 7b 28 f8 7e 5c c8 16 e8 a8 00 00 00 03 ...{(.~\\........\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 70 ...............p\n0040 00 00 00 b0 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 60 00 00 00 00 00 00 00 00 00 02 00 04 ...`............\n0070 00 00 00 04 00 02 00 02 00 00 00 03 00 00 00 19 ................\n0080 00 00 00 00 00 00 00 19 00 00 00 47 00 65 00 6d ...........G.e.m\n0090 00 70 00 6c 00 75 00 73 00 20 00 47 00 65 00 6d .p.l.u.s. .G.e.m\n00a0 00 50 00 43 00 20 00 54 00 77 00 69 00 6e 00 20 .P.C. .T.w.i.n. \n00b0 00 30 00 30 00 20 00 30 00 30 00 00 00 00 00 04 .0.0. .0.0......\n00c0 00 00 00 01 00 00 00 00 00 00 00                ...........\nTS_SCardConnect:\n0000 03 00 00 cb 02 f0 80 68 00 01 03 ed f0 80 bc 08 .......h........\n0010 00 00 00 7b 28 f8 7e 5c c8 16 e8 a8 00 00 00 03 ...{(.~\\........\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 70 ...............p\n0040 00 00 00 b0 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 60 00 00 00 00 00 00 00 00 00 02 00 04 ...`............\n0070 00 00 00 04 00 02 00 02 00 00 00 03 00 00 00 19 ................\n0080 00 00 00 00 00 00 00 19 00 00 00 47 00 65 00 6d ...........G.e.m\n0090 00 70 00 6c 00 75 00 73 00 20 00 47 00 65 00 6d .p.l.u.s. .G.e.m\n00a0 00 50 00 43 00 20 00 54 00 77 00 69 00 6e 00 20 .P.C. .T.w.i.n. \n00b0 00 30 00 30 00 20 00 30 00 30 00 00 00 00 00 04 .0.0. .0.0......\n00c0 00 00 00 01 00 00 00 00 00 00 00                ...........\n\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-control.txt",
    "content": "TS_SCardControl:\n0000 03 00 00 a3 02 f0 80 68 00 01 03 ed f0 80 94 08 .......h........\n0010 00 00 00 05 18 7c 3e ca 9f 03 76 80 00 00 00 03 .....|>...v.....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 00 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 48 ...............H\n0040 00 00 00 d4 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 38 00 00 00 00 00 00 00 04 00 00 00 00 ...8............\n0070 00 02 00 04 00 00 00 04 00 02 00 20 35 31 00 00 ........... 51..\n0080 00 00 00 00 00 00 00 00 00 00 00 c8 00 00 00 04 ................\n0090 00 00 00 05 00 00 00 04 00 00 00 06 00 00 00 00 ................\n00a0 00 00 00                                        ...\nTS_SCardControl:\n0000 03 00 00 a3 02 f0 80 68 00 01 03 ed f0 80 94 08 .......h........\n0010 00 00 00 99 4c 06 de f1 41 78 64 80 00 00 00 03 ....L...Axd.....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 48 ...............H\n0040 00 00 00 d4 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 38 00 00 00 00 00 00 00 04 00 00 00 00 ...8............\n0070 00 02 00 04 00 00 00 04 00 02 00 20 35 31 00 00 ........... 51..\n0080 00 00 00 00 00 00 00 00 00 00 00 c8 00 00 00 04 ................\n0090 00 00 00 05 00 00 00 04 00 00 00 06 00 00 00 00 ................\n00a0 00 00 00                                        ...\nTS_SCardControl:\n0000 03 00 00 a3 02 f0 80 68 00 01 03 ed f0 80 94 08 .......h........\n0010 00 00 00 05 18 7c 3e ca 9f 03 76 80 00 00 00 03 .....|>...v.....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 00 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 48 ...............H\n0040 00 00 00 d4 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 38 00 00 00 00 00 00 00 04 00 00 00 00 ...8............\n0070 00 02 00 04 00 00 00 04 00 02 00 20 35 31 00 00 ........... 51..\n0080 00 00 00 00 00 00 00 00 00 00 00 c8 00 00 00 04 ................\n0090 00 00 00 05 00 00 00 04 00 00 00 06 00 00 00 00 ................\n00a0 00 00 00                                        ...\nTS_SCardControl:\n0000 03 00 00 a3 02 f0 80 68 00 01 03 ed f0 80 94 08 .......h........\n0010 00 00 00 99 4c 06 de f1 41 78 64 80 00 00 00 03 ....L...Axd.....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 48 ...............H\n0040 00 00 00 d4 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 38 00 00 00 00 00 00 00 04 00 00 00 00 ...8............\n0070 00 02 00 04 00 00 00 04 00 02 00 20 35 31 00 00 ........... 51..\n0080 00 00 00 00 00 00 00 00 00 00 00 c8 00 00 00 04 ................\n0090 00 00 00 05 00 00 00 04 00 00 00 06 00 00 00 00 ................\n00a0 00 00 00                                        ...\nTS_SCardControl:\n0000 03 00 00 a3 02 f0 80 68 00 01 03 ed f0 80 94 08 .......h........\n0010 00 00 00 87 62 bd 62 13 81 8a d6 80 00 00 00 03 ....b.b.........\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 48 ...............H\n0040 00 00 00 d4 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 38 00 00 00 00 00 00 00 04 00 00 00 00 ...8............\n0070 00 02 00 04 00 00 00 04 00 02 00 20 35 31 00 00 ........... 51..\n0080 00 00 00 00 00 00 00 00 00 00 00 02 01 00 00 04 ................\n0090 00 00 00 07 00 00 00 04 00 00 00 0b 00 00 00 00 ................\n00a0 00 00 00                                        ...\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-disconnect.txt",
    "content": "TS_SCardDisconnect:\n0000 03 00 00 93 02 f0 80 68 00 01 03 ed f0 80 84 08 .......h........\n0010 00 00 00 87 b4 3a 7f a4 2a 6d ad 70 00 00 00 03 .....:..*m.p....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 00 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 38 ...............8\n0040 00 00 00 b8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 28 00 00 00 00 00 00 00 04 00 00 00 00 ...(............\n0070 00 02 00 04 00 00 00 04 00 02 00 00 00 00 00 04 ................\n0080 00 00 00 03 00 00 00 04 00 00 00 04 00 00 00 00 ................\n0090 00 00 00                                        ...\nTS_SCardDisconnect:\n0000 03 00 00 93 02 f0 80 68 00 01 03 ed f0 80 84 08 .......h........\n0010 00 00 00 72 7f fb 24 4e b1 36 c8 70 00 00 00 03 ...r..$N.6.p....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 38 ...............8\n0040 00 00 00 b8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 28 00 00 00 00 00 00 00 04 00 00 00 00 ...(............\n0070 00 02 00 04 00 00 00 04 00 02 00 00 00 00 00 04 ................\n0080 00 00 00 04 00 00 00 04 00 00 00 05 00 00 00 00 ................\n0090 00 00 00                                        ...\n\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-end-tranaction.txt",
    "content": "TS_SCardEndTransaction:\n0000 03 00 00 93 02 f0 80 68 00 01 03 ed f0 80 84 08 .......h........\n0010 00 00 00 51 1c 06 7b 0a 94 e3 7f 70 00 00 00 03 ...Q..{....p....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 02 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 38 ...............8\n0040 00 00 00 c0 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 28 00 00 00 00 00 00 00 04 00 00 00 00 ...(............\n0070 00 02 00 04 00 00 00 04 00 02 00 00 00 00 00 04 ................\n0080 00 00 00 09 00 00 00 04 00 00 00 0a 00 00 00 00 ................\n0090 00 00 00                                        ...\nTS_SCardEndTransaction:\n0000 03 00 00 93 02 f0 80 68 00 01 03 ed f0 80 84 08 .......h........\n0010 00 00 00 51 1c 06 7b 0a 94 e3 7f 70 00 00 00 03 ...Q..{....p....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 02 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 38 ...............8\n0040 00 00 00 c0 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 28 00 00 00 00 00 00 00 04 00 00 00 00 ...(............\n0070 00 02 00 04 00 00 00 04 00 02 00 00 00 00 00 04 ................\n0080 00 00 00 09 00 00 00 04 00 00 00 0a 00 00 00 00 ................\n0090 00 00 00                                        ...\nTS_SCardEndTransaction:\n0000 03 00 00 93 02 f0 80 68 00 01 03 ed f0 80 84 08 .......h........\n0010 00 00 00 fe 1c ea fb 2e a3 58 a6 70 00 00 00 03 .........X.p....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 03 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 38 ...............8\n0040 00 00 00 c0 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 28 00 00 00 00 00 00 00 04 00 00 00 00 ...(............\n0070 00 02 00 04 00 00 00 04 00 02 00 00 00 00 00 04 ................\n0080 00 00 00 09 00 00 00 04 00 00 00 0a 00 00 00 00 ................\n0090 00 00 00                                        ...\n\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-establish-context.txt",
    "content": "TS_SCardEstablishContext:\n0000 03 00 00 72 02 f0 80 68 00 01 03 ed f0 64 08 00 ...r...h.....d..\n0010 00 00 a7 8d 52 74 fd 96 bc b4 50 00 00 00 03 00 ....Rt....P.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 00 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 18 00 ................\n0040 00 00 14 00 09 00 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 08 00 00 00 00 00 00 00 02 00 00 00 00 00 ................\n0070 00 00                                           ..\nTS_SCardEstablishContext:\n0000 03 00 00 72 02 f0 80 68 00 01 03 ed f0 64 08 00 ...r...h.....d..\n0010 00 00 51 f7 43 00 73 65 44 53 50 00 00 00 03 00 ..Q.C.seDSP.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 00 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 18 00 ................\n0040 00 00 14 00 09 00 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 08 00 00 00 00 00 00 00 00 00 00 00 00 00 ................\n0070 00 00                                           ..\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-get-status-change.txt",
    "content": "TS_SCardGetStatusChange:\n0000 03 00 01 6b 02 f0 80 68 00 01 03 ed f0 81 5c 08 ...k...h......\\.\n0010 00 00 00 bf 53 5b 23 43 71 9b 2b 48 01 00 00 03 ....S[#Cq.+H....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 00 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 10 ................\n0040 01 00 00 a4 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 00 01 00 00 00 00 00 00 04 00 00 00 00 ................\n0070 00 02 00 ff ff ff ff 02 00 00 00 04 00 02 00 04 ................\n0080 00 00 00 01 00 00 00 02 00 00 00 08 00 02 00 00 ................\n0090 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................\n00a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................\n00b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c ................\n00c0 00 02 00 10 00 00 00 00 00 00 00 00 00 00 00 00 ................\n00d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................\n00e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................\n00f0 00 00 00 15 00 00 00 00 00 00 00 15 00 00 00 5c ...............\\\n0100 00 5c 00 3f 00 50 00 6e 00 50 00 3f 00 5c 00 4e .\\.?.P.n.P.?.\\.N\n0110 00 6f 00 74 00 69 00 66 00 69 00 63 00 61 00 74 .o.t.i.f.i.c.a.t\n0120 00 69 00 6f 00 6e 00 00 00 00 00 19 00 00 00 00 .i.o.n..........\n0130 00 00 00 19 00 00 00 47 00 65 00 6d 00 70 00 6c .......G.e.m.p.l\n0140 00 75 00 73 00 20 00 47 00 65 00 6d 00 50 00 43 .u.s. .G.e.m.P.C\n0150 00 20 00 54 00 77 00 69 00 6e 00 20 00 30 00 30 . .T.w.i.n. .0.0\n0160 00 20 00 30 00 30 00 00 00 00 00                . .0.0.....\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-list-readers.txt",
    "content": "TS_SCardListReaders:\n0000 03 00 00 b3 02 f0 80 68 00 01 03 ed f0 80 a4 08 .......h........\n0010 00 00 00 07 b5 7d d1 ba 7c 7e e9 90 00 00 00 03 .....}..|~......\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 00 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 58 ...............X\n0040 00 00 00 2c 00 09 00 00 00 00 00 00 00 00 00 00 ...,............\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 48 00 00 00 00 00 00 00 04 00 00 00 00 ...H............\n0070 00 02 00 24 00 00 00 04 00 02 00 00 00 00 00 ff ...$............\n0080 ff ff ff 04 00 00 00 01 00 00 00 24 00 00 00 53 ...........$...S\n0090 00 43 00 61 00 72 00 64 00 24 00 41 00 6c 00 6c .C.a.r.d.$.A.l.l\n00a0 00 52 00 65 00 61 00 64 00 65 00 72 00 73 00 00 .R.e.a.d.e.r.s..\n00b0 00 00 00                                        ...\nTS_SCardListReaders:\n0000 03 00 00 8a 02 f0 80 68 00 01 03 ed f0 7c 08 00 .......h.....|..\n0010 00 00 ae 89 33 c1 0d 6b e2 bb 68 00 00 00 03 00 ....3..k..h.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 30 00 ..............0.\n0040 00 00 28 00 09 00 00 00 00 00 00 00 00 00 00 00 ..(.............\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 20 00 00 00 00 00 00 00 04 00 00 00 00 00 .. .............\n0070 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................\n0080 00 00 04 00 00 00 02 00 00 00                   ..........\nTS_SCardListReaders:\n0000 03 00 00 8a 02 f0 80 68 00 01 03 ed f0 7c 08 00 .......h.....|..\n0010 00 00 ef be 3f 08 43 ae 89 9b 68 00 00 00 03 00 ....?.C...h.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 02 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 30 00 ..............0.\n0040 00 00 28 00 09 00 00 00 00 00 00 00 00 00 00 00 ..(.............\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 20 00 00 00 00 00 00 00 04 00 00 00 00 00 .. .............\n0070 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................\n0080 00 00 04 00 00 00 02 00 00 00                   ..........\nTS_SCardListReaders:\n0000 03 00 00 8a 02 f0 80 68 00 01 03 ed f0 7c 08 00 .......h.....|..\n0010 00 00 ae 89 33 c1 0d 6b e2 bb 68 00 00 00 03 00 ....3..k..h.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 30 00 ..............0.\n0040 00 00 28 00 09 00 00 00 00 00 00 00 00 00 00 00 ..(.............\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 20 00 00 00 00 00 00 00 04 00 00 00 00 00 .. .............\n0070 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................\n0080 00 00 04 00 00 00 02 00 00 00                   ..........\nTS_SCardListReaders:\n0000 03 00 00 8a 02 f0 80 68 00 01 03 ed f0 7c 08 00 .......h.....|..\n0010 00 00 ae 89 33 c1 0d 6b e2 bb 68 00 00 00 03 00 ....3..k..h.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 30 00 ..............0.\n0040 00 00 28 00 09 00 00 00 00 00 00 00 00 00 00 00 ..(.............\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 20 00 00 00 00 00 00 00 04 00 00 00 00 00 .. .............\n0070 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................\n0080 00 00 04 00 00 00 02 00 00 00                   ..........\nTS_SCardListReaders:\n0000 03 00 00 8a 02 f0 80 68 00 01 03 ed f0 7c 08 00 .......h.....|..\n0010 00 00 ae 89 33 c1 0d 6b e2 bb 68 00 00 00 03 00 ....3..k..h.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 30 00 ..............0.\n0040 00 00 28 00 09 00 00 00 00 00 00 00 00 00 00 00 ..(.............\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 20 00 00 00 00 00 00 00 04 00 00 00 00 00 .. .............\n0070 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................\n0080 00 00 04 00 00 00 02 00 00 00                   ..........\nTS_SCardListReaders:\n0000 03 00 00 8a 02 f0 80 68 00 01 03 ed f0 7c 08 00 .......h.....|..\n0010 00 00 78 0a 67 31 92 fc d0 29 68 00 00 00 03 00 ..x.g1...)h.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 03 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 30 00 ..............0.\n0040 00 00 28 00 09 00 00 00 00 00 00 00 00 00 00 00 ..(.............\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 20 00 00 00 00 00 00 00 04 00 00 00 00 00 .. .............\n0070 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................\n0080 00 00 04 00 00 00 02 00 00 00                   ..........\nTS_SCardListReaders:\n0000 03 00 00 8a 02 f0 80 68 00 01 03 ed f0 7c 08 00 .......h.....|..\n0010 00 00 ae 89 33 c1 0d 6b e2 bb 68 00 00 00 03 00 ....3..k..h.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 30 00 ..............0.\n0040 00 00 28 00 09 00 00 00 00 00 00 00 00 00 00 00 ..(.............\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 20 00 00 00 00 00 00 00 04 00 00 00 00 00 .. .............\n0070 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................\n0080 00 00 04 00 00 00 02 00 00 00                   ..........\nTS_SCardListReaders:\n0000 03 00 00 8a 02 f0 80 68 00 01 03 ed f0 7c 08 00 .......h.....|..\n0010 00 00 ae 89 33 c1 0d 6b e2 bb 68 00 00 00 03 00 ....3..k..h.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 30 00 ..............0.\n0040 00 00 28 00 09 00 00 00 00 00 00 00 00 00 00 00 ..(.............\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 20 00 00 00 00 00 00 00 04 00 00 00 00 00 .. .............\n0070 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................\n0080 00 00 04 00 00 00 02 00 00 00 \n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-release-context.txt",
    "content": "0000 03 00 00 7a 02 f0 80 68 00 01 03 ed f0 6c 08 00 ...z...h.....l..\n0010 00 00 c9 9d 01 9e ec 30 a3 4c 58 00 00 00 03 00 .......0.LX.....\n0020 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 00 ..rDRI..........\n0030 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 20 00 .............. .\n0040 00 00 18 00 09 00 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc cc ................\n0060 cc cc 10 00 00 00 00 00 00 00 04 00 00 00 00 00 ................\n0070 02 00 04 00 00 00 02 00 00 00                   ..........\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-status.txt",
    "content": "TS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 0e 8b f9 50 1f 35 28 35 78 00 00 00 03 ......P.5(5x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 00 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 cc 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 00 00 00 00 ff ................\n0080 ff ff ff 20 00 00 00 04 00 00 00 05 00 00 00 04 ... ............\n0090 00 00 00 06 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 0e 8b f9 50 1f 35 28 35 78 00 00 00 03 ......P.5(5x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 00 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 cc 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 00 00 00 00 ff ................\n0080 ff ff ff 20 00 00 00 04 00 00 00 05 00 00 00 04 ... ............\n0090 00 00 00 06 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 88 05 07 8b 2a 3c f5 16 78 00 00 00 03 .......*<..x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 cc 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 00 00 00 00 ff ................\n0080 ff ff ff 20 00 00 00 04 00 00 00 05 00 00 00 04 ... ............\n0090 00 00 00 06 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 3b cf 96 d8 27 3f cd 9f 78 00 00 00 03 ...;...'?..x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 01 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 c8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 01 00 00 00 00 ................\n0080 00 00 00 40 00 00 00 04 00 00 00 07 00 00 00 04 ...@............\n0090 00 00 00 09 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 a3 8c 93 16 6c 49 59 23 78 00 00 00 03 .......lIY#x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 02 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 c8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 01 00 00 00 00 ................\n0080 00 00 00 40 00 00 00 04 00 00 00 07 00 00 00 04 ...@............\n0090 00 00 00 09 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 6d d0 36 aa 65 50 4c 88 78 00 00 00 03 ...m.6.ePL.x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 03 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 c8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 01 00 00 00 00 ................\n0080 00 00 00 40 00 00 00 04 00 00 00 07 00 00 00 04 ...@............\n0090 00 00 00 09 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 a3 8c 93 16 6c 49 59 23 78 00 00 00 03 .......lIY#x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 02 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 c8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 01 00 00 00 00 ................\n0080 00 00 00 40 00 00 00 04 00 00 00 07 00 00 00 04 ...@............\n0090 00 00 00 09 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 6d d0 36 aa 65 50 4c 88 78 00 00 00 03 ...m.6.ePL.x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 03 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 c8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 01 00 00 00 00 ................\n0080 00 00 00 40 00 00 00 04 00 00 00 07 00 00 00 04 ...@............\n0090 00 00 00 09 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 6d d0 36 aa 65 50 4c 88 78 00 00 00 03 ...m.6.ePL.x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 03 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 c8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 01 00 00 00 00 ................\n0080 00 00 00 40 00 00 00 04 00 00 00 07 00 00 00 04 ...@............\n0090 00 00 00 09 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 a3 8c 93 16 6c 49 59 23 78 00 00 00 03 .......lIY#x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 02 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 c8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 01 00 00 00 00 ................\n0080 00 00 00 40 00 00 00 04 00 00 00 07 00 00 00 04 ...@............\n0090 00 00 00 09 00 00 00 00 00 00 00                ...........\nTS_SCardStatus:\n0000 03 00 00 9b 02 f0 80 68 00 01 03 ed f0 80 8c 08 .......h........\n0010 00 00 00 6d d0 36 aa 65 50 4c 88 78 00 00 00 03 ...m.6.ePL.x....\n0020 00 00 00 72 44 52 49 00 00 00 00 01 00 00 00 03 ...rDRI.........\n0030 00 00 00 0e 00 00 00 00 00 00 00 00 08 00 00 40 ...............@\n0040 00 00 00 c8 00 09 00 00 00 00 00 00 00 00 00 00 ................\n0050 00 00 00 00 00 00 00 00 00 00 00 01 10 08 00 cc ................\n0060 cc cc cc 30 00 00 00 00 00 00 00 04 00 00 00 00 ...0............\n0070 00 02 00 04 00 00 00 04 00 02 00 01 00 00 00 00 ................\n0080 00 00 00 40 00 00 00 04 00 00 00 07 00 00 00 04 ...@............\n0090 00 00 00 09 00 00 00 00 00 00 00                ...........\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/dumps/scard-transmit.txt",
    "content": "TS_SCardTransmit:\n0000 01 10 08 00 cc cc cc cc 58 00 00 00 00 00 00 00 ........X.......\n0010 04 00 00 00 00 00 02 00 04 00 00 00 04 00 02 00 ................\n0020 01 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 ................\n0030 08 00 02 00 0c 00 02 00 00 00 00 00 02 01 00 00 ................\n0040 04 00 00 00 05 00 00 00 04 00 00 00 0b 00 00 00 ................\n0050 07 00 00 00 00 a4 02 0c 02 ef 0f 00 01 00 00 00 ................\n0060 00 00 00 00 00 00 00 00                         ........\nTS_SCardTransmit:\n0000 01 10 08 00 cc cc cc cc 58 00 00 00 00 00 00 00 ........X.......\n0010 04 00 00 00 00 00 02 00 04 00 00 00 04 00 02 00 ................\n0020 01 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 ................\n0030 08 00 02 00 0c 00 02 00 00 00 00 00 02 01 00 00 ................\n0040 04 00 00 00 05 00 00 00 04 00 00 00 0b 00 00 00 ................\n0050 05 00 00 00 00 b0 07 5b 10 00 00 00 01 00 00 00 .......[........\n0060 00 00 00 00 00 00 00 00                         ........\nTS_SCardTransmit:\n0000 01 10 08 00 cc cc cc cc 58 00 00 00 00 00 00 00 ........X.......\n0010 04 00 00 00 00 00 02 00 04 00 00 00 04 00 02 00 ................\n0020 01 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 ................\n0030 08 00 02 00 0c 00 02 00 00 00 00 00 02 01 00 00 ................\n0040 04 00 00 00 05 00 00 00 04 00 00 00 0b 00 00 00 ................\n0050 07 00 00 00 00 a4 02 0c 02 ef 10 00 01 00 00 00 ................\n0060 00 00 00 00 00 00 00 00                         ........\nTS_SCardTransmit:\n0000 01 10 08 00 cc cc cc cc 58 00 00 00 00 00 00 00 ........X.......\n0010 04 00 00 00 00 00 02 00 04 00 00 00 04 00 02 00 ................\n0020 01 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 ................\n0030 08 00 02 00 0c 00 02 00 00 00 00 00 02 01 00 00 ................\n0040 04 00 00 00 05 00 00 00 04 00 00 00 0b 00 00 00 ................\n0050 05 00 00 00 00 b0 07 04 10 00 00 00 01 00 00 00 ................\n0060 00 00 00 00 00 00 00 00                         ........\n\n\n"
  },
  {
    "path": "sesman/chansrv/pcsc/wrapper/Makefile",
    "content": "\nCC=bcc32.exe\n\nCFLAGS=-O2\n\nOBJS=winscard.obj\n\nwinscard.dll: $(OBJS)\n\t$(CC) -ewinscard.dll -tWD $(OBJS)\n\nclean:\n\t-del winscard.dll\n\t-del *.obj\n\t-del *.tds\n"
  },
  {
    "path": "sesman/chansrv/pcsc/wrapper/winscard-func-names.txt",
    "content": "ClassInstall32\nSCardAccessNewReaderEvent\nSCardReleaseAllEvents\nSCardReleaseNewReaderEvent\nSCardAccessStartedEvent\n\ndone SCardAddReaderToGroupA\ndone SCardAddReaderToGroupW\ndone SCardBeginTransaction\ndone SCardCancel\ndone SCardConnectA\ndone SCardConnectW\ndone SCardControl\ndone SCardDisconnect\ndone SCardEndTransaction\ndone SCardEstablishContext\ndone SCardForgetCardTypeA\ndone SCardForgetCardTypeW\ndone SCardForgetReaderA\ndone SCardForgetReaderGroupA\ndone SCardForgetReaderGroupW\ndone SCardForgetReaderW\ndone SCardFreeMemory\ndone SCardGetAttrib\ndone SCardGetCardTypeProviderNameA\ndone SCardGetCardTypeProviderNameW\ndone SCardGetProviderIdA\ndone SCardGetProviderIdW\ndone SCardGetStatusChangeA\ndone SCardGetStatusChangeW\n\nSCardGetTransmitCount\n\ndone SCardIntroduceCardTypeA\ndone SCardIntroduceCardTypeW\ndone SCardIntroduceReaderA\ndone SCardIntroduceReaderGroupA\ndone SCardIntroduceReaderGroupW\ndone SCardIntroduceReaderW\ndone SCardIsValidContext\ndone SCardListCardsA\ndone SCardListCardsW\ndone SCardListInterfacesA\ndone SCardListInterfacesW\ndone SCardListReaderGroupsA\ndone SCardListReaderGroupsW\ndone SCardListReadersA\ndone SCardListReadersW\ndone SCardLocateCardsA\n\nSCardLocateCardsByATRA\nSCardLocateCardsByATRW\n\ndone SCardLocateCardsW\n\nSCardReadCacheA\nSCardReadCacheW\n\ndone SCardReconnect\ndone SCardReleaseContext\n\nSCardReleaseStartedEvent\n\ndone SCardRemoveReaderFromGroupA\ndone SCardRemoveReaderFromGroupW\ndone SCardSetAttrib\ndone SCardSetCardTypeProviderNameA\ndone SCardSetCardTypeProviderNameW\ndone SCardState\ndone SCardStatusA\ndone SCardStatusW\ndone SCardTransmit\n\nSCardWriteCacheA\nSCardWriteCacheW\ng_rgSCardRawPci\ng_rgSCardT0Pci\ng_rgSCardT1Pci\n"
  },
  {
    "path": "sesman/chansrv/pcsc/wrapper/winscard-funcs.h",
    "content": "\n#ifndef _WINSCARD_FUNCS_H\n#define _WINSCARD_FUNCS_H\n\ntypedef LONG WINAPI\n(*tSCardEstablishContext)(DWORD dwScope, LPCVOID pvReserved1,\n                          LPCVOID pvReserved2, LPSCARDCONTEXT phContext);\ntypedef LONG WINAPI\n(*tSCardReleaseContext)(SCARDCONTEXT hContext);\ntypedef LONG WINAPI\n(*tSCardIsValidContext)(SCARDCONTEXT hContext);\ntypedef LONG WINAPI\n(*tSCardListReaderGroupsA)(SCARDCONTEXT hContext, LPSTR mszGroups,\n                           LPDWORD pcchGroups);\ntypedef LONG WINAPI\n(*tSCardListReaderGroupsW)(SCARDCONTEXT hContext, LPWSTR mszGroups,\n                           LPDWORD pcchGroups);\ntypedef LONG WINAPI\n(*tSCardListReadersA)(SCARDCONTEXT hContext, LPCSTR mszGroups,\n                      LPSTR mszReaders, LPDWORD pcchReaders);\ntypedef LONG WINAPI\n(*tSCardListReadersW)(SCARDCONTEXT hContext, LPCWSTR mszGroups,\n                      LPWSTR mszReaders, LPDWORD pcchReaders);\ntypedef LONG WINAPI\n(*tSCardListCardsA)(SCARDCONTEXT hContext, LPCBYTE pbAtr,\n                    LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount,\n                    LPSTR mszCards, LPDWORD pcchCards);\ntypedef LONG WINAPI\n(*tSCardListCardsW)(SCARDCONTEXT hContext, LPCBYTE pbAtr,\n                    LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount,\n                    LPWSTR mszCards, LPDWORD pcchCards);\ntypedef LONG WINAPI\n(*tSCardListInterfacesA)(SCARDCONTEXT hContext, LPCSTR szCard,\n                         LPGUID pguidInterfaces, LPDWORD pcguidInterfaces);\ntypedef LONG WINAPI\n(*tSCardListInterfacesW)(SCARDCONTEXT hContext, LPCWSTR szCard,\n                         LPGUID pguidInterfaces, LPDWORD pcguidInterfaces);\ntypedef LONG WINAPI\n(*tSCardGetProviderIdA)(SCARDCONTEXT hContext, LPCSTR szCard,\n                        LPGUID pguidProviderId);\ntypedef LONG WINAPI\n(*tSCardGetProviderIdW)(SCARDCONTEXT hContext, LPCWSTR szCard,\n                        LPGUID pguidProviderId);\ntypedef LONG WINAPI\n(*tSCardGetCardTypeProviderNameA)(SCARDCONTEXT hContext, LPCSTR szCardName,\n                                  DWORD dwProviderId, LPSTR szProvider,\n                                  LPDWORD pcchProvider);\ntypedef LONG WINAPI\n(*tSCardGetCardTypeProviderNameW)(SCARDCONTEXT hContext, LPCWSTR szCardName,\n                                  DWORD dwProviderId, LPWSTR szProvider,\n                                  LPDWORD pcchProvider);\ntypedef LONG WINAPI\n(*tSCardIntroduceReaderGroupA)(SCARDCONTEXT hContext, LPCSTR szGroupName);\ntypedef LONG WINAPI\n(*tSCardIntroduceReaderGroupW)(SCARDCONTEXT hContext, LPCWSTR szGroupName);\n\ntypedef LONG WINAPI\n(*tSCardForgetReaderGroupA)(SCARDCONTEXT hContext, LPCSTR szGroupName);\ntypedef LONG WINAPI\n(*tSCardForgetReaderGroupW)(SCARDCONTEXT hContext, LPCWSTR szGroupName);\ntypedef LONG WINAPI\n(*tSCardIntroduceReaderA)(SCARDCONTEXT hContext, LPCSTR szReaderName,\n                          LPCSTR szDeviceName);\ntypedef LONG WINAPI\n(*tSCardIntroduceReaderW)(SCARDCONTEXT hContext, LPCWSTR szReaderName,\n                          LPCWSTR szDeviceName);\ntypedef LONG WINAPI\n(*tSCardForgetReaderA)(SCARDCONTEXT hContext, LPCSTR szReaderName);\ntypedef LONG WINAPI\n(*tSCardForgetReaderW)(SCARDCONTEXT hContext, LPCWSTR szReaderName);\n\ntypedef LONG WINAPI\n(*tSCardAddReaderToGroupA)(SCARDCONTEXT hContext, LPCSTR szReaderName,\n                           LPCSTR szGroupName);\ntypedef LONG WINAPI\n(*tSCardAddReaderToGroupW)(SCARDCONTEXT hContext, LPCWSTR szReaderName,\n                           LPCWSTR szGroupName);\ntypedef LONG WINAPI\n(*tSCardRemoveReaderFromGroupA)(SCARDCONTEXT hContext, LPCSTR szReaderName,\n                                LPCSTR szGroupName);\ntypedef LONG WINAPI\n(*tSCardRemoveReaderFromGroupW)(SCARDCONTEXT hContext, LPCWSTR szReaderName,\n                                LPCWSTR szGroupName);\ntypedef LONG WINAPI\n(*tSCardIntroduceCardTypeA)(SCARDCONTEXT hContext, LPCSTR szCardName,\n                            LPCGUID pguidPrimaryProvider,\n                            LPCGUID rgguidInterfaces,\n                            DWORD dwInterfaceCount, LPCBYTE pbAtr,\n                            LPCBYTE pbAtrMask, DWORD cbAtrLen);\ntypedef LONG WINAPI\n(*tSCardIntroduceCardTypeW)(SCARDCONTEXT hContext, LPCWSTR szCardName,\n                            LPCGUID pguidPrimaryProvider,\n                            LPCGUID rgguidInterfaces,\n                            DWORD dwInterfaceCount, LPCBYTE pbAtr,\n                            LPCBYTE pbAtrMask, DWORD cbAtrLen);\ntypedef LONG WINAPI\n(*tSCardSetCardTypeProviderNameA)(SCARDCONTEXT hContext, LPCSTR szCardName,\n                                  DWORD dwProviderId, LPCSTR szProvider);\ntypedef LONG WINAPI\n(*tSCardSetCardTypeProviderNameW)(SCARDCONTEXT hContext, LPCWSTR szCardName,\n                                  DWORD dwProviderId, LPCWSTR szProvider);\ntypedef LONG WINAPI\n(*tSCardForgetCardTypeA)(SCARDCONTEXT hContext, LPCSTR szCardName);\ntypedef LONG WINAPI\n(*tSCardForgetCardTypeW)(SCARDCONTEXT hContext, LPCWSTR szCardName);\ntypedef LONG WINAPI\n(*tSCardFreeMemory)(SCARDCONTEXT hContext, LPCVOID pvMem);\ntypedef LONG WINAPI\n(*tSCardLocateCardsA)(SCARDCONTEXT hContext, LPCSTR mszCards,\n                      LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders);\ntypedef LONG WINAPI\n(*tSCardLocateCardsW)(SCARDCONTEXT hContext, LPCWSTR mszCards,\n                      LPSCARD_READERSTATEW rgReaderStates, DWORD cReaders);\ntypedef LONG WINAPI\n(*tSCardGetStatusChangeA)(SCARDCONTEXT hContext, DWORD dwTimeout,\n                          LPSCARD_READERSTATEA rgReaderStates,\n                          DWORD cReaders);\ntypedef LONG WINAPI\n(*tSCardGetStatusChangeW)(SCARDCONTEXT hContext, DWORD dwTimeout,\n                          LPSCARD_READERSTATEW rgReaderStates,\n                          DWORD cReaders);\ntypedef LONG WINAPI\n(*tSCardCancel)(SCARDCONTEXT hContext);\ntypedef LONG WINAPI\n(*tSCardConnectA)(SCARDCONTEXT hContext, LPCSTR szReader,\n                  DWORD dwShareMode, DWORD dwPreferredProtocols,\n                  LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol);\ntypedef LONG WINAPI\n(*tSCardConnectW)(SCARDCONTEXT hContext, LPCWSTR szReader,\n                  DWORD dwShareMode, DWORD dwPreferredProtocols,\n                  LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol);\ntypedef LONG WINAPI\n(*tSCardReconnect)(SCARDHANDLE hCard, DWORD dwShareMode,\n                   DWORD dwPreferredProtocols, DWORD dwInitialization,\n                   LPDWORD pdwActiveProtocol);\ntypedef LONG WINAPI\n(*tSCardDisconnect)(SCARDHANDLE hCard, DWORD dwDisposition);\ntypedef LONG WINAPI\n(*tSCardBeginTransaction)(SCARDHANDLE hCard);\ntypedef LONG WINAPI\n(*tSCardEndTransaction)(SCARDHANDLE hCard, DWORD dwDisposition);\ntypedef LONG WINAPI\n(*tSCardCancelTransaction)(SCARDHANDLE hCard);\ntypedef LONG WINAPI\n(*tSCardState)(SCARDHANDLE hCard, LPDWORD pdwState, LPDWORD pdwProtocol,\n               LPBYTE pbAtr, LPDWORD pcbAtrLen);\ntypedef LONG WINAPI\n(*tSCardStatusA)(SCARDHANDLE hCard, LPSTR szReaderName, LPDWORD pcchReaderLen,\n                 LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr,\n                 LPDWORD pcbAtrLen);\ntypedef LONG WINAPI\n(*tSCardStatusW)(SCARDHANDLE hCard, LPWSTR szReaderName, LPDWORD pcchReaderLen,\n                 LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr,\n                 LPDWORD pcbAtrLen);\ntypedef LONG WINAPI\n(*tSCardTransmit)(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci,\n                  LPCBYTE pbSendBuffer, DWORD cbSendLength,\n                  LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer,\n                  LPDWORD pcbRecvLength);\ntypedef LONG WINAPI\n(*tSCardControl)(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID lpInBuffer,\n                 DWORD nInBufferSize, LPVOID lpOutBuffer,\n                 DWORD nOutBufferSize, LPDWORD lpBytesReturned);\ntypedef LONG WINAPI\n(*tSCardGetAttrib)(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr,\n                   LPDWORD pcbAttrLen);\ntypedef LONG WINAPI\n(*tSCardSetAttrib)(SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr,\n                   DWORD cbAttrLen);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/pcsc/wrapper/winscard.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdarg.h>\n#include <windows.h>\n\n#include \"winscard-funcs.h\"\n\n#define LUNUSED(_param) (void) _param\n\nstatic tSCardEstablishContext aSCardEstablishContext;\nstatic tSCardReleaseContext aSCardReleaseContext;\nstatic tSCardIsValidContext aSCardIsValidContext;\nstatic tSCardListReaderGroupsA aSCardListReaderGroupsA;\nstatic tSCardListReaderGroupsW aSCardListReaderGroupsW;\nstatic tSCardListReadersA aSCardListReadersA;\nstatic tSCardListReadersW aSCardListReadersW;\nstatic tSCardListCardsA aSCardListCardsA;\nstatic tSCardListCardsW aSCardListCardsW;\nstatic tSCardListInterfacesA aSCardListInterfacesA;\nstatic tSCardListInterfacesW aSCardListInterfacesW;\nstatic tSCardGetProviderIdA aSCardGetProviderIdA;\nstatic tSCardGetProviderIdW aSCardGetProviderIdW;\nstatic tSCardGetCardTypeProviderNameA aSCardGetCardTypeProviderNameA;\nstatic tSCardGetCardTypeProviderNameW aSCardGetCardTypeProviderNameW;\nstatic tSCardIntroduceReaderGroupA aSCardIntroduceReaderGroupA;\nstatic tSCardIntroduceReaderGroupW aSCardIntroduceReaderGroupW;\nstatic tSCardForgetReaderGroupA aSCardForgetReaderGroupA;\nstatic tSCardForgetReaderGroupW aSCardForgetReaderGroupW;\nstatic tSCardIntroduceReaderA aSCardIntroduceReaderA;\nstatic tSCardIntroduceReaderW aSCardIntroduceReaderW;\nstatic tSCardForgetReaderA aSCardForgetReaderA;\nstatic tSCardForgetReaderW aSCardForgetReaderW;\nstatic tSCardAddReaderToGroupA aSCardAddReaderToGroupA;\nstatic tSCardAddReaderToGroupW aSCardAddReaderToGroupW;\nstatic tSCardRemoveReaderFromGroupA aSCardRemoveReaderFromGroupA;\nstatic tSCardRemoveReaderFromGroupW aSCardRemoveReaderFromGroupW;\nstatic tSCardIntroduceCardTypeA aSCardIntroduceCardTypeA;\nstatic tSCardIntroduceCardTypeW aSCardIntroduceCardTypeW;\nstatic tSCardSetCardTypeProviderNameA aSCardSetCardTypeProviderNameA;\nstatic tSCardSetCardTypeProviderNameW aSCardSetCardTypeProviderNameW;\nstatic tSCardForgetCardTypeA aSCardForgetCardTypeA;\nstatic tSCardForgetCardTypeW aSCardForgetCardTypeW;\nstatic tSCardFreeMemory aSCardFreeMemory;\nstatic tSCardLocateCardsA aSCardLocateCardsA;\nstatic tSCardLocateCardsW aSCardLocateCardsW;\nstatic tSCardGetStatusChangeA aSCardGetStatusChangeA;\nstatic tSCardGetStatusChangeW aSCardGetStatusChangeW;\nstatic tSCardCancel aSCardCancel;\nstatic tSCardConnectA aSCardConnectA;\nstatic tSCardConnectW aSCardConnectW;\nstatic tSCardReconnect aSCardReconnect;\nstatic tSCardDisconnect aSCardDisconnect;\nstatic tSCardBeginTransaction aSCardBeginTransaction;\nstatic tSCardEndTransaction aSCardEndTransaction;\nstatic tSCardCancelTransaction aSCardCancelTransaction;\nstatic tSCardState aSCardState;\nstatic tSCardStatusA aSCardStatusA;\nstatic tSCardStatusW aSCardStatusW;\nstatic tSCardTransmit aSCardTransmit;\nstatic tSCardControl aSCardControl;\nstatic tSCardGetAttrib aSCardGetAttrib;\nstatic tSCardSetAttrib aSCardSetAttrib;\n\n//__declspec(dllexport) const SCARD_IO_REQUEST g_rgSCardT0Pci = { 0 };\n//__declspec(dllexport) const SCARD_IO_REQUEST g_rgSCardT1Pci = { 0 };\n//__declspec(dllexport) const SCARD_IO_REQUEST g_rgSCardRawPci = { 0 };\n\nstatic int g_true = 1;\n\n#define LLOGLN(_level, _args) do { if ((_level < 11) && g_true) { writeln _args ; } } while (0)\n\n/*****************************************************************************/\nstatic int\nwriteln(const char *format, ...)\n{\n    va_list ap;\n    char text[256];\n\n    va_start(ap, format);\n    vsnprintf(text, 255, format, ap);\n    va_end(ap);\n    OutputDebugString(text);\n    return 0;\n}\n\n#define LLOAD(_func, _type, _name) \\\n    do { \\\n        _func = (_type) GetProcAddress(lib, _name); \\\n        if (_func == 0) \\\n        { \\\n            writeln(\"LLOAD error %s\", _name); \\\n        } \\\n    } while (0)\n\nstatic int g_funcs_loaded = 0;\n\n/*****************************************************************************/\nstatic int __fastcall\nload_funcs(void)\n{\n    HMODULE lib;\n\n    if (g_funcs_loaded)\n    {\n        return 0;\n    }\n    g_funcs_loaded = 1;\n    lib = LoadLibrary(\"winscard-org.dll\");\n    LLOGLN(0, (\"load_funcs: lib %p\", lib));\n    LLOAD(aSCardEstablishContext, tSCardEstablishContext, \"SCardEstablishContext\");\n    LLOAD(aSCardReleaseContext, tSCardReleaseContext, \"SCardReleaseContext\");\n    LLOAD(aSCardIsValidContext, tSCardIsValidContext, \"SCardIsValidContext\");\n    LLOAD(aSCardListReaderGroupsA, tSCardListReaderGroupsA, \"SCardListReaderGroupsA\");\n    LLOAD(aSCardListReaderGroupsW, tSCardListReaderGroupsW, \"SCardListReaderGroupsW\");\n    LLOAD(aSCardListReadersA, tSCardListReadersA, \"SCardListReadersA\");\n    LLOAD(aSCardListReadersW, tSCardListReadersW, \"SCardListReadersW\");\n    LLOAD(aSCardListCardsA, tSCardListCardsA, \"SCardListCardsA\");\n    LLOAD(aSCardListCardsW, tSCardListCardsW, \"SCardListCardsW\");\n    LLOAD(aSCardListInterfacesA, tSCardListInterfacesA, \"SCardListInterfacesA\");\n    LLOAD(aSCardListInterfacesW, tSCardListInterfacesW, \"SCardListInterfacesW\");\n    LLOAD(aSCardGetProviderIdA, tSCardGetProviderIdA, \"SCardGetProviderIdA\");\n    LLOAD(aSCardGetProviderIdW, tSCardGetProviderIdW, \"SCardGetProviderIdW\");\n    LLOAD(aSCardGetCardTypeProviderNameA, tSCardGetCardTypeProviderNameA, \"SCardGetCardTypeProviderNameA\");\n    LLOAD(aSCardGetCardTypeProviderNameW, tSCardGetCardTypeProviderNameW, \"SCardGetCardTypeProviderNameW\");\n    LLOAD(aSCardIntroduceReaderGroupA, tSCardIntroduceReaderGroupA, \"SCardIntroduceReaderGroupA\");\n    LLOAD(aSCardIntroduceReaderGroupW, tSCardIntroduceReaderGroupW, \"SCardIntroduceReaderGroupW\");\n    LLOAD(aSCardForgetReaderGroupA, tSCardForgetReaderGroupA, \"SCardForgetReaderGroupA\");\n    LLOAD(aSCardForgetReaderGroupW, tSCardForgetReaderGroupW, \"SCardForgetReaderGroupW\");\n    LLOAD(aSCardIntroduceReaderA, tSCardIntroduceReaderA, \"SCardIntroduceReaderA\");\n    LLOAD(aSCardIntroduceReaderW, tSCardIntroduceReaderW, \"SCardIntroduceReaderW\");\n    LLOAD(aSCardForgetReaderA, tSCardForgetReaderA, \"SCardForgetReaderA\");\n    LLOAD(aSCardForgetReaderW, tSCardForgetReaderW, \"SCardForgetReaderW\");\n    LLOAD(aSCardAddReaderToGroupA, tSCardAddReaderToGroupA, \"SCardAddReaderToGroupA\");\n    LLOAD(aSCardAddReaderToGroupW, tSCardAddReaderToGroupW, \"SCardAddReaderToGroupW\");\n    LLOAD(aSCardRemoveReaderFromGroupA, tSCardRemoveReaderFromGroupA, \"SCardRemoveReaderFromGroupA\");\n    LLOAD(aSCardRemoveReaderFromGroupW, tSCardRemoveReaderFromGroupW, \"SCardRemoveReaderFromGroupW\");\n    LLOAD(aSCardIntroduceCardTypeA, tSCardIntroduceCardTypeA, \"SCardIntroduceCardTypeA\");\n    LLOAD(aSCardIntroduceCardTypeW, tSCardIntroduceCardTypeW, \"SCardIntroduceCardTypeW\");\n    LLOAD(aSCardSetCardTypeProviderNameA, tSCardSetCardTypeProviderNameA, \"SCardSetCardTypeProviderNameA\");\n    LLOAD(aSCardSetCardTypeProviderNameW, tSCardSetCardTypeProviderNameW, \"SCardSetCardTypeProviderNameW\");\n    LLOAD(aSCardForgetCardTypeA, tSCardForgetCardTypeA, \"SCardForgetCardTypeA\");\n    LLOAD(aSCardForgetCardTypeW, tSCardForgetCardTypeW, \"SCardForgetCardTypeW\");\n    LLOAD(aSCardFreeMemory, tSCardFreeMemory, \"SCardFreeMemory\");\n    LLOAD(aSCardLocateCardsA, tSCardLocateCardsA, \"SCardLocateCardsA\");\n    LLOAD(aSCardLocateCardsW, tSCardLocateCardsW, \"SCardLocateCardsW\");\n    LLOAD(aSCardGetStatusChangeA, tSCardGetStatusChangeA, \"SCardGetStatusChangeA\");\n    LLOAD(aSCardGetStatusChangeW, tSCardGetStatusChangeW, \"SCardGetStatusChangeW\");\n    LLOAD(aSCardCancel, tSCardCancel, \"SCardCancel\");\n    LLOAD(aSCardConnectA, tSCardConnectA, \"SCardConnectA\");\n    LLOAD(aSCardConnectW, tSCardConnectW, \"SCardConnectW\");\n    LLOAD(aSCardReconnect, tSCardReconnect, \"SCardReconnect\");\n    LLOAD(aSCardDisconnect, tSCardDisconnect, \"SCardDisconnect\");\n    LLOAD(aSCardBeginTransaction, tSCardBeginTransaction, \"SCardBeginTransaction\");\n    LLOAD(aSCardEndTransaction, tSCardEndTransaction, \"SCardEndTransaction\");\n    LLOAD(aSCardCancelTransaction, tSCardCancelTransaction, \"SCardCancelTransaction\");\n    LLOAD(aSCardState, tSCardState, \"SCardState\");\n    LLOAD(aSCardStatusA, tSCardStatusA, \"SCardStatusA\");\n    LLOAD(aSCardStatusW, tSCardStatusW, \"SCardStatusW\");\n    LLOAD(aSCardTransmit, tSCardTransmit, \"SCardTransmit\");\n    LLOAD(aSCardControl, tSCardControl, \"SCardControl\");\n    LLOAD(aSCardGetAttrib, tSCardGetAttrib, \"SCardGetAttrib\");\n    LLOAD(aSCardSetAttrib, tSCardSetAttrib, \"SCardSetAttrib\");\n\n    return 0;\n}\n\n/*****************************************************************************/\nBOOL WINAPI\nDllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)\n{\n    BOOL rv;\n    LUNUSED(hinstDLL);\n    LUNUSED(lpvReserved);\n\n    LLOGLN(10, (\"DllEntryPoint: hinstDLL %p fdwReason %d\", hinstDLL, fdwReason));\n    rv = FALSE;\n    switch (fdwReason)\n    {\n        case DLL_PROCESS_ATTACH:\n            LLOGLN(0, (\"DllEntryPoint: DLL_PROCESS_ATTACH\"));\n            load_funcs();\n            rv = TRUE;\n            break;\n        case DLL_THREAD_ATTACH:\n            LLOGLN(10, (\"DllEntryPoint: DLL_THREAD_ATTACH\"));\n            rv = TRUE;\n            break;\n        case DLL_THREAD_DETACH:\n            LLOGLN(10, (\"DllEntryPoint: DLL_THREAD_DETACH\"));\n            rv = TRUE;\n            break;\n        case DLL_PROCESS_DETACH:\n            LLOGLN(0, (\"DllEntryPoint: DLL_PROCESS_DETACH\"));\n            rv = TRUE;\n            break;\n        default:\n            LLOGLN(0, (\"DllEntryPoint: unknown fdwReason %d\", fdwReason));\n            break;\n\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1,\n                      LPCVOID pvReserved2, LPSCARDCONTEXT phContext)\n{\n    LLOGLN(0, (\"SCardEstablishContext:\"));\n    return aSCardEstablishContext(dwScope, pvReserved1, pvReserved2, phContext);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardReleaseContext(SCARDCONTEXT hContext)\n{\n    LLOGLN(0, (\"SCardReleaseContext:\"));\n    return aSCardReleaseContext(hContext);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardIsValidContext(SCARDCONTEXT hContext)\n{\n    LLOGLN(0, (\"SCardIsValidContext:\"));\n    return aSCardIsValidContext(hContext);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardListReaderGroupsA(SCARDCONTEXT hContext, LPSTR mszGroups,\n                       LPDWORD pcchGroups)\n{\n    LLOGLN(0, (\"SCardListReaderGroupsA:\"));\n    return aSCardListReaderGroupsA(hContext, mszGroups, pcchGroups);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardListReaderGroupsW(SCARDCONTEXT hContext, LPWSTR mszGroups,\n                       LPDWORD pcchGroups)\n{\n    LLOGLN(0, (\"SCardListReaderGroupsW:\"));\n    return aSCardListReaderGroupsW(hContext, mszGroups, pcchGroups);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardListReadersA(SCARDCONTEXT hContext, LPCSTR mszGroups,\n                  LPSTR mszReaders, LPDWORD pcchReaders)\n{\n    LLOGLN(0, (\"SCardListReadersA:\"));\n    return aSCardListReadersA(hContext, mszGroups, mszReaders, pcchReaders);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardListReadersW(SCARDCONTEXT hContext, LPCWSTR mszGroups,\n                  LPWSTR mszReaders, LPDWORD pcchReaders)\n{\n    char text[256];\n    LONG rv;\n    DWORD cchReaders;\n\n    text[0] = 0;\n    if (mszGroups != 0)\n    {\n        wcstombs(text, mszGroups, 255);\n    }\n    cchReaders = *pcchReaders;\n    LLOGLN(0, (\"SCardListReadersW: mszGroups [%s] cchReaders [%d]\", text, *pcchReaders));\n    rv = aSCardListReadersW(hContext, mszGroups, mszReaders, pcchReaders);\n    text[0] = 0;\n    if (cchReaders > 0)\n    {\n        wcstombs(text, mszReaders, 255);\n    }\n    LLOGLN(0, (\"  mszReaders [%s] cchReaders [%d]\", text, *pcchReaders));\n    return rv;\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardListCardsA(SCARDCONTEXT hContext, LPCBYTE pbAtr,\n                LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount,\n                LPSTR mszCards, LPDWORD pcchCards)\n{\n    LLOGLN(0, (\"SCardListCardsA:\"));\n    return aSCardListCardsA(hContext, pbAtr, rgquidInterfaces,\n                            cguidInterfaceCount, mszCards, pcchCards);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardListCardsW(SCARDCONTEXT hContext, LPCBYTE pbAtr,\n                LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount,\n                LPWSTR mszCards, LPDWORD pcchCards)\n{\n    LLOGLN(0, (\"SCardListCardsW:\"));\n    return aSCardListCardsW(hContext, pbAtr, rgquidInterfaces,\n                            cguidInterfaceCount, mszCards, pcchCards);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardListInterfacesA(SCARDCONTEXT hContext, LPCSTR szCard,\n                     LPGUID pguidInterfaces, LPDWORD pcguidInterfaces)\n{\n    LLOGLN(0, (\"SCardListInterfacesA:\"));\n    return aSCardListInterfacesA(hContext, szCard, pguidInterfaces,\n                                 pcguidInterfaces);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardListInterfacesW(SCARDCONTEXT hContext, LPCWSTR szCard,\n                     LPGUID pguidInterfaces, LPDWORD pcguidInterfaces)\n{\n    LLOGLN(0, (\"SCardListInterfacesW:\"));\n    return aSCardListInterfacesW(hContext, szCard, pguidInterfaces,\n                                 pcguidInterfaces);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardGetProviderIdA(SCARDCONTEXT hContext, LPCSTR szCard,\n                    LPGUID pguidProviderId)\n{\n    LLOGLN(0, (\"SCardGetProviderIdA:\"));\n    return aSCardGetProviderIdA(hContext, szCard, pguidProviderId);\n}\n\n/****************************************************************************/\nLONG WINAPI\nSCardGetProviderIdW(SCARDCONTEXT hContext, LPCWSTR szCard,\n                    LPGUID pguidProviderId)\n{\n    LLOGLN(0, (\"SCardGetProviderIdW:\"));\n    return aSCardGetProviderIdW(hContext, szCard, pguidProviderId);\n}\n\n/****************************************************************************/\nLONG WINAPI\nSCardGetCardTypeProviderNameA(SCARDCONTEXT hContext, LPCSTR szCardName,\n                              DWORD dwProviderId, LPSTR szProvider,\n                              LPDWORD pcchProvider)\n{\n    LLOGLN(0, (\"SCardGetCardTypeProviderNameA:\"));\n    return aSCardGetCardTypeProviderNameA(hContext, szCardName, dwProviderId,\n                                          szProvider, pcchProvider);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardGetCardTypeProviderNameW(SCARDCONTEXT hContext, LPCWSTR szCardName,\n                              DWORD dwProviderId, LPWSTR szProvider,\n                              LPDWORD pcchProvider)\n{\n    LLOGLN(0, (\"SCardGetCardTypeProviderNameW:\"));\n    return aSCardGetCardTypeProviderNameW(hContext, szCardName, dwProviderId,\n                                          szProvider, pcchProvider);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardIntroduceReaderGroupA(SCARDCONTEXT hContext, LPCSTR szGroupName)\n{\n    LLOGLN(0, (\"SCardIntroduceReaderGroupA:\"));\n    return aSCardIntroduceReaderGroupA(hContext, szGroupName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardIntroduceReaderGroupW(SCARDCONTEXT hContext, LPCWSTR szGroupName)\n{\n    LLOGLN(0, (\"SCardIntroduceReaderGroupW:\"));\n    return aSCardIntroduceReaderGroupW(hContext, szGroupName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardForgetReaderGroupA(SCARDCONTEXT hContext, LPCSTR szGroupName)\n{\n    LLOGLN(0, (\"SCardForgetReaderGroupA:\"));\n    return aSCardForgetReaderGroupA(hContext, szGroupName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardForgetReaderGroupW(SCARDCONTEXT hContext, LPCWSTR szGroupName)\n{\n    LLOGLN(0, (\"SCardForgetReaderGroupW:\"));\n    return aSCardForgetReaderGroupW(hContext, szGroupName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardIntroduceReaderA(SCARDCONTEXT hContext, LPCSTR szReaderName,\n                      LPCSTR szDeviceName)\n{\n    LLOGLN(0, (\"SCardIntroduceReaderA:\"));\n    return aSCardIntroduceReaderA(hContext, szReaderName, szDeviceName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardIntroduceReaderW(SCARDCONTEXT hContext, LPCWSTR szReaderName,\n                      LPCWSTR szDeviceName)\n{\n    LLOGLN(0, (\"SCardIntroduceReaderW:\"));\n    return aSCardIntroduceReaderW(hContext, szReaderName, szDeviceName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardForgetReaderA(SCARDCONTEXT hContext, LPCSTR szReaderName)\n{\n    LLOGLN(0, (\"SCardForgetReaderA:\"));\n    return aSCardForgetReaderA(hContext, szReaderName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardForgetReaderW(SCARDCONTEXT hContext, LPCWSTR szReaderName)\n{\n    LLOGLN(0, (\"SCardForgetReaderW:\"));\n    return aSCardForgetReaderW(hContext, szReaderName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardAddReaderToGroupA(SCARDCONTEXT hContext, LPCSTR szReaderName,\n                       LPCSTR szGroupName)\n{\n    LLOGLN(0, (\"SCardAddReaderToGroupA:\"));\n    return aSCardAddReaderToGroupA(hContext, szReaderName, szGroupName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardAddReaderToGroupW(SCARDCONTEXT hContext, LPCWSTR szReaderName,\n                       LPCWSTR szGroupName)\n{\n    LLOGLN(0, (\"SCardAddReaderToGroupW:\"));\n    return aSCardAddReaderToGroupW(hContext, szReaderName, szGroupName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardRemoveReaderFromGroupA(SCARDCONTEXT hContext, LPCSTR szReaderName,\n                            LPCSTR szGroupName)\n{\n    LLOGLN(0, (\"SCardRemoveReaderFromGroupA:\"));\n    return aSCardRemoveReaderFromGroupA(hContext, szReaderName, szGroupName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardRemoveReaderFromGroupW(SCARDCONTEXT hContext, LPCWSTR szReaderName,\n                            LPCWSTR szGroupName)\n{\n    LLOGLN(0, (\"SCardRemoveReaderFromGroupW:\"));\n    return aSCardRemoveReaderFromGroupW(hContext, szReaderName, szGroupName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardIntroduceCardTypeA(SCARDCONTEXT hContext, LPCSTR szCardName,\n                        LPCGUID pguidPrimaryProvider,\n                        LPCGUID rgguidInterfaces,\n                        DWORD dwInterfaceCount, LPCBYTE pbAtr,\n                        LPCBYTE pbAtrMask, DWORD cbAtrLen)\n{\n    LLOGLN(0, (\"SCardIntroduceCardTypeA:\"));\n    return aSCardIntroduceCardTypeA(hContext, szCardName, pguidPrimaryProvider,\n                                    rgguidInterfaces, dwInterfaceCount, pbAtr,\n                                    pbAtrMask, cbAtrLen);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardIntroduceCardTypeW(SCARDCONTEXT hContext, LPCWSTR szCardName,\n                        LPCGUID pguidPrimaryProvider, LPCGUID rgguidInterfaces,\n                        DWORD dwInterfaceCount, LPCBYTE pbAtr,\n                        LPCBYTE pbAtrMask, DWORD cbAtrLen)\n{\n    LLOGLN(0, (\"SCardIntroduceCardTypeW:\"));\n    return aSCardIntroduceCardTypeW(hContext, szCardName, pguidPrimaryProvider,\n                                    rgguidInterfaces, dwInterfaceCount, pbAtr,\n                                    pbAtrMask, cbAtrLen);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardSetCardTypeProviderNameA(SCARDCONTEXT hContext, LPCSTR szCardName,\n                              DWORD dwProviderId, LPCSTR szProvider)\n{\n    LLOGLN(0, (\"SCardSetCardTypeProviderNameA:\"));\n    return aSCardSetCardTypeProviderNameA(hContext, szCardName,\n                                          dwProviderId, szProvider);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardSetCardTypeProviderNameW(SCARDCONTEXT hContext, LPCWSTR szCardName,\n                              DWORD dwProviderId, LPCWSTR szProvider)\n{\n    LLOGLN(0, (\"SCardSetCardTypeProviderNameW:\"));\n    return aSCardSetCardTypeProviderNameW(hContext, szCardName,\n                                          dwProviderId, szProvider);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardForgetCardTypeA(SCARDCONTEXT hContext, LPCSTR szCardName)\n{\n    LLOGLN(0, (\"SCardForgetCardTypeA:\"));\n    return aSCardForgetCardTypeA(hContext, szCardName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardForgetCardTypeW(SCARDCONTEXT hContext, LPCWSTR szCardName)\n{\n    LLOGLN(0, (\"SCardForgetCardTypeW:\"));\n    return aSCardForgetCardTypeW(hContext, szCardName);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardFreeMemory(SCARDCONTEXT hContext, LPCVOID pvMem)\n{\n    LLOGLN(0, (\"SCardFreeMemory:\"));\n    return aSCardFreeMemory(hContext, pvMem);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardLocateCardsA(SCARDCONTEXT hContext, LPCSTR mszCards,\n                  LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders)\n{\n    LLOGLN(0, (\"SCardLocateCardsA:\"));\n    return aSCardLocateCardsA(hContext, mszCards, rgReaderStates, cReaders);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardLocateCardsW(SCARDCONTEXT hContext, LPCWSTR mszCards,\n                  LPSCARD_READERSTATEW rgReaderStates, DWORD cReaders)\n{\n    LLOGLN(0, (\"SCardLocateCardsW:\"));\n    return aSCardLocateCardsW(hContext, mszCards, rgReaderStates, cReaders);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardGetStatusChangeA(SCARDCONTEXT hContext, DWORD dwTimeout,\n                      LPSCARD_READERSTATEA rgReaderStates,\n                      DWORD cReaders)\n{\n    LLOGLN(0, (\"SCardGetStatusChangeA:\"));\n    return aSCardGetStatusChangeA(hContext, dwTimeout, rgReaderStates, cReaders);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardGetStatusChangeW(SCARDCONTEXT hContext, DWORD dwTimeout,\n                      LPSCARD_READERSTATEW rgReaderStates,\n                      DWORD cReaders)\n{\n    LLOGLN(0, (\"SCardGetStatusChangeW:\"));\n    return aSCardGetStatusChangeW(hContext, dwTimeout, rgReaderStates, cReaders);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardCancel(SCARDCONTEXT hContext)\n{\n    LLOGLN(0, (\"SCardCancel:\"));\n    return aSCardCancel(hContext);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardConnectA(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode,\n              DWORD dwPreferredProtocols, LPSCARDHANDLE phCard,\n              LPDWORD pdwActiveProtocol)\n{\n    LLOGLN(0, (\"SCardConnectA:\"));\n    return aSCardConnectA(hContext, szReader, dwShareMode,\n                          dwPreferredProtocols, phCard,\n                          pdwActiveProtocol);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardConnectW(SCARDCONTEXT hContext, LPCWSTR szReader, DWORD dwShareMode,\n              DWORD dwPreferredProtocols, LPSCARDHANDLE phCard,\n              LPDWORD pdwActiveProtocol)\n{\n    LLOGLN(0, (\"SCardConnectW:\"));\n    return aSCardConnectW(hContext, szReader, dwShareMode,\n                          dwPreferredProtocols, phCard,\n                          pdwActiveProtocol);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardReconnect(SCARDHANDLE hCard, DWORD dwShareMode,\n               DWORD dwPreferredProtocols, DWORD dwInitialization,\n               LPDWORD pdwActiveProtocol)\n{\n    LLOGLN(0, (\"SCardReconnect:\"));\n    return SCardReconnect(hCard, dwShareMode, dwPreferredProtocols,\n                          dwInitialization, pdwActiveProtocol);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)\n{\n    LLOGLN(0, (\"SCardDisconnect:\"));\n    return aSCardDisconnect(hCard, dwDisposition);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardBeginTransaction(SCARDHANDLE hCard)\n{\n    LLOGLN(0, (\"SCardBeginTransaction:\"));\n    return aSCardBeginTransaction(hCard);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisposition)\n{\n    LLOGLN(0, (\"SCardEndTransaction:\"));\n    return aSCardEndTransaction(hCard, dwDisposition);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardCancelTransaction(SCARDHANDLE hCard)\n{\n    LLOGLN(0, (\"SCardCancelTransaction:\"));\n    return aSCardCancelTransaction(hCard);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardState(SCARDHANDLE hCard, LPDWORD pdwState, LPDWORD pdwProtocol,\n           LPBYTE pbAtr, LPDWORD pcbAtrLen)\n{\n    LLOGLN(0, (\"SCardState:\"));\n    return aSCardState(hCard, pdwState, pdwProtocol, pbAtr, pcbAtrLen);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardStatusA(SCARDHANDLE hCard, LPSTR szReaderName, LPDWORD pcchReaderLen,\n             LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr,\n             LPDWORD pcbAtrLen)\n{\n    LLOGLN(0, (\"SCardStatusA:\"));\n    return aSCardStatusA(hCard, szReaderName, pcchReaderLen,\n                         pdwState, pdwProtocol, pbAtr, pcbAtrLen);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardStatusW(SCARDHANDLE hCard, LPWSTR szReaderName, LPDWORD pcchReaderLen,\n             LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr,\n             LPDWORD pcbAtrLen)\n{\n    LONG rv;\n\n    LLOGLN(0, (\"SCardStatusW:\"));\n    LLOGLN(0, (\"  cchReaderLen %d\", *pcchReaderLen));\n    LLOGLN(0, (\"  cbAtrLen %d\", *pcbAtrLen));\n    rv = aSCardStatusW(hCard, szReaderName, pcchReaderLen,\n                       pdwState, pdwProtocol, pbAtr, pcbAtrLen);\n    LLOGLN(0, (\"  rv %d cchReaderLen %d\", rv, *pcchReaderLen));\n    return rv;\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardTransmit(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci,\n              LPCBYTE pbSendBuffer, DWORD cbSendLength,\n              LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer,\n              LPDWORD pcbRecvLength)\n{\n    LONG rv;\n\n    LLOGLN(10, (\"SCardTransmit:\"));\n    LLOGLN(10, (\"  hCard %p\", hCard));\n    LLOGLN(10, (\"  cbSendLength %d\", cbSendLength));\n    LLOGLN(10, (\"  cbRecvLength %d\", *pcbRecvLength));\n    LLOGLN(10, (\"  pioSendPci->dwProtocol %d\", pioSendPci->dwProtocol));\n    LLOGLN(10, (\"  pioSendPci->cbPciLength %d\", pioSendPci->cbPciLength));\n    LLOGLN(10, (\"  pioRecvPci %p\", pioRecvPci));\n    if (pioRecvPci != NULL)\n    {\n        LLOGLN(10, (\"    pioRecvPci->dwProtocol %d\", pioRecvPci->dwProtocol));\n        LLOGLN(10, (\"    pioRecvPci->cbPciLength %d\", pioRecvPci->cbPciLength));\n    }\n    rv = aSCardTransmit(hCard, pioSendPci, pbSendBuffer, cbSendLength,\n                        pioRecvPci, pbRecvBuffer, pcbRecvLength);\n    LLOGLN(10, (\"  rv %d cbRecvLength %d\", rv, *pcbRecvLength));\n    return rv;\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardControl(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID lpInBuffer,\n             DWORD nInBufferSize, LPVOID lpOutBuffer,\n             DWORD nOutBufferSize, LPDWORD lpBytesReturned)\n{\n    LONG rv;\n\n    LLOGLN(10, (\"SCardControl:\"));\n    LLOGLN(10, (\"  hCard %p\", hCard));\n    LLOGLN(10, (\"  dwControlCode 0x%8.8x\", dwControlCode));\n    LLOGLN(10, (\"  lpInBuffer %p\", lpInBuffer));\n    LLOGLN(10, (\"  nInBufferSize %d\", nInBufferSize));\n    LLOGLN(10, (\"  lpOutBuffer %p\", lpOutBuffer));\n    LLOGLN(10, (\"  nOutBufferSize %d\", nOutBufferSize));\n    LLOGLN(10, (\"  lpBytesReturned %p\", lpBytesReturned));\n    rv = aSCardControl(hCard, dwControlCode,\n                       lpInBuffer, nInBufferSize,\n                       lpOutBuffer, nOutBufferSize,\n                       lpBytesReturned);\n    LLOGLN(10, (\"  rv %d BytesReturned %d\", rv, *lpBytesReturned));\n    return rv;\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr,\n               LPDWORD pcbAttrLen)\n{\n    LLOGLN(0, (\"SCardGetAttrib:\"));\n    return aSCardGetAttrib(hCard, dwAttrId, pbAttr, pcbAttrLen);\n}\n\n/*****************************************************************************/\nLONG WINAPI\nSCardSetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr,\n               DWORD cbAttrLen)\n{\n    LLOGLN(0, (\"SCardSetAttrib:\"));\n    return aSCardSetAttrib(hCard, dwAttrId, pbAttr, cbAttrLen);\n}\n"
  },
  {
    "path": "sesman/chansrv/pcsc/wrapper/winscard.def",
    "content": "EXPORTS\nSCardEstablishContext\nSCardReleaseContext\nSCardIsValidContext\nSCardListReaderGroupsA\nSCardListReaderGroupsW\nSCardListReadersA\nSCardListReadersW\nSCardListCardsA\nSCardListCardsW\nSCardListInterfacesA\nSCardListInterfacesW\nSCardGetProviderIdA\nSCardGetProviderIdW\nSCardGetCardTypeProviderNameA\nSCardGetCardTypeProviderNameW\nSCardIntroduceReaderGroupA\nSCardIntroduceReaderGroupW\nSCardForgetReaderGroupA\nSCardForgetReaderGroupW\nSCardIntroduceReaderA\nSCardIntroduceReaderW\nSCardForgetReaderA\nSCardForgetReaderW\nSCardAddReaderToGroupA\nSCardAddReaderToGroupW\nSCardRemoveReaderFromGroupA\nSCardRemoveReaderFromGroupW\nSCardIntroduceCardTypeA\nSCardIntroduceCardTypeW\nSCardSetCardTypeProviderNameA\nSCardSetCardTypeProviderNameW\nSCardForgetCardTypeA\nSCardForgetCardTypeW\nSCardFreeMemory\nSCardLocateCardsA\nSCardLocateCardsW\nSCardGetStatusChangeA\nSCardGetStatusChangeW\nSCardCancel\nSCardConnectA\nSCardConnectW\nSCardReconnect\nSCardDisconnect\nSCardBeginTransaction\nSCardEndTransaction\nSCardState\nSCardStatusA\nSCardStatusW\nSCardTransmit\nSCardControl\nSCardGetAttrib\nSCardSetAttrib\n"
  },
  {
    "path": "sesman/chansrv/pcsc/xrdp_pcsc.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <pthread.h>\n#include <sys/types.h>\n#include <sys/socket.h>\n#include <sys/un.h>\n#include <sys/stat.h>\n#include <poll.h>\n\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"xrdp_constants.h\"\n\n#define PCSC_API\n\ntypedef unsigned char BYTE;\ntypedef BYTE *LPBYTE;\n#ifdef __APPLE__\ntypedef int LONG;\ntypedef unsigned int DWORD;\n#else\ntypedef long LONG;\ntypedef unsigned long DWORD;\n#endif\ntypedef DWORD *LPDWORD;\ntypedef const void *LPCVOID;\ntypedef const char *LPCSTR;\ntypedef char *LPSTR;\ntypedef void *LPVOID;\ntypedef const BYTE *LPCBYTE;\n\ntypedef LONG SCARDCONTEXT;\ntypedef SCARDCONTEXT *LPSCARDCONTEXT;\n\ntypedef LONG SCARDHANDLE;\ntypedef SCARDHANDLE *LPSCARDHANDLE;\n\n#define MAX_ATR_SIZE 33\n\ntypedef struct _SCARD_READERSTATE\n{\n    const char *szReader;\n    void *pvUserData;\n    DWORD dwCurrentState;\n    DWORD dwEventState;\n    DWORD cbAtr;\n    unsigned char rgbAtr[MAX_ATR_SIZE];\n} SCARD_READERSTATE, *LPSCARD_READERSTATE;\n\ntypedef struct _SCARD_IO_REQUEST\n{\n    unsigned long dwProtocol;\n    unsigned long cbPciLength;\n} SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST;\n\n#define SCARD_PROTOCOL_T0       0x0001 /**< T=0 active protocol. */\n#define SCARD_PROTOCOL_T1       0x0002 /**< T=1 active protocol. */\n#define SCARD_PROTOCOL_RAW      0x0004 /**< Raw active protocol. */\n\nPCSC_API SCARD_IO_REQUEST g_rgSCardT0Pci  = { SCARD_PROTOCOL_T0,  8 };\nPCSC_API SCARD_IO_REQUEST g_rgSCardT1Pci  = { SCARD_PROTOCOL_T1,  8 };\nPCSC_API SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 };\n\n#define LLOG_LEVEL 5\n#define LLOGLN(_level, _args) \\\n    do { if (_level < LLOG_LEVEL) { printf _args ; printf(\"\\n\"); } } while (0)\n#define LHEXDUMP(_level, _args) \\\n    do { if  (_level < LLOG_LEVEL) { lhexdump _args ; } } while (0)\n\n#define SCARD_ESTABLISH_CONTEXT  0x01\n#define SCARD_RELEASE_CONTEXT    0x02\n#define SCARD_LIST_READERS       0x03\n#define SCARD_CONNECT            0x04\n#define SCARD_RECONNECT          0x05\n#define SCARD_DISCONNECT         0x06\n#define SCARD_BEGIN_TRANSACTION  0x07\n#define SCARD_END_TRANSACTION    0x08\n#define SCARD_TRANSMIT           0x09\n#define SCARD_CONTROL            0x0A\n#define SCARD_STATUS             0x0B\n#define SCARD_GET_STATUS_CHANGE  0x0C\n#define SCARD_CANCEL             0x0D\n#define SCARD_CANCEL_TRANSACTION 0x0E\n#define SCARD_GET_ATTRIB         0x0F\n#define SCARD_SET_ATTRIB         0x10\n\n#define SCARD_S_SUCCESS 0x00000000\n#define SCARD_F_INTERNAL_ERROR ((LONG)0x80100001)\n\n#define SET_UINT32(_data, _offset, _val) do { \\\n        (((BYTE*)(_data)) + (_offset))[0] = ((_val) >> 0)  & 0xff; \\\n        (((BYTE*)(_data)) + (_offset))[1] = ((_val) >> 8)  & 0xff; \\\n        (((BYTE*)(_data)) + (_offset))[2] = ((_val) >> 16) & 0xff; \\\n        (((BYTE*)(_data)) + (_offset))[3] = ((_val) >> 24) & 0xff; } while (0)\n\n#define GET_UINT32(_data, _offset) \\\n    ((((BYTE*)(_data)) + (_offset))[0] << 0)  | \\\n    ((((BYTE*)(_data)) + (_offset))[1] << 8)  | \\\n    ((((BYTE*)(_data)) + (_offset))[2] << 16) | \\\n    ((((BYTE*)(_data)) + (_offset))[3] << 24)\n\n#define LMIN(_val1, _val2) (_val1) < (_val2) ? (_val1) : (_val2)\n#define LMAX(_val1, _val2) (_val1) > (_val2) ? (_val1) : (_val2)\n\nstatic int g_sck = -1; /* unix domain socket */\n\nstatic pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;\n\n/* for pcsc_stringify_error */\nstatic char g_error_str[512];\n\n/*****************************************************************************/\n/* produce a hex dump */\nstatic void\nlhexdump(void *p, int len)\n{\n    unsigned char *line;\n    int i;\n    int thisline;\n    int offset;\n\n    line = (unsigned char *)p;\n    offset = 0;\n\n    while (offset < len)\n    {\n        printf(\"%04x \", offset);\n        thisline = len - offset;\n\n        if (thisline > 16)\n        {\n            thisline = 16;\n        }\n\n        for (i = 0; i < thisline; i++)\n        {\n            printf(\"%02x \", line[i]);\n        }\n\n        for (; i < 16; i++)\n        {\n            printf(\"   \");\n        }\n\n        for (i = 0; i < thisline; i++)\n        {\n            printf(\"%c\", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');\n        }\n\n        printf(\"\\n\");\n        offset += thisline;\n        line += thisline;\n    }\n}\n\n/*****************************************************************************/\nstatic int\nconnect_to_chansrv(void)\n{\n    int bytes;\n    char disstr[MAX_DISPLAY_NAME_SIZE];\n    int error;\n    char *xrdp_session;\n    char *home_str;\n    struct sockaddr_un saddr;\n    struct sockaddr *psaddr;\n\n    if (g_sck != -1)\n    {\n        /* already connected */\n        return 0;\n    }\n    xrdp_session = getenv(\"XRDP_SESSION\");\n    if (xrdp_session == NULL)\n    {\n        /* XRDP_SESSION must be set */\n        LLOGLN(0, (\"connect_to_chansrv: error, not xrdp session\"));\n        return 1;\n    }\n\n    if (g_get_display_string(disstr, sizeof(disstr)) < 0)\n    {\n        LLOGLN(0, (\"connect_to_chansrv: error, don't understand DISPLAY\"));\n        return 1;\n    }\n    home_str = getenv(\"HOME\");\n    if (home_str == NULL)\n    {\n        /* HOME must be set */\n        LLOGLN(0, (\"connect_to_chansrv: error, home not set\"));\n        return 1;\n    }\n    g_sck = socket(PF_LOCAL, SOCK_STREAM, 0);\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"connect_to_chansrv: error, socket failed\"));\n        return 1;\n    }\n    memset(&saddr, 0, sizeof(struct sockaddr_un));\n    saddr.sun_family = AF_UNIX;\n    bytes = sizeof(saddr.sun_path);\n    snprintf(saddr.sun_path, bytes, \"%s/.pcsc%s/pcscd.comm\", home_str, disstr);\n    saddr.sun_path[bytes - 1] = 0;\n    LLOGLN(10, (\"connect_to_chansrv: connecting to %s\", saddr.sun_path));\n    psaddr = (struct sockaddr *) &saddr;\n    bytes = sizeof(struct sockaddr_un);\n    error = connect(g_sck, psaddr, bytes);\n    if (error == 0)\n    {\n    }\n    else\n    {\n        perror(\"connect_to_chansrv\");\n        close(g_sck);\n        g_sck = -1;\n        LLOGLN(0, (\"connect_to_chansrv: error, open %s\", saddr.sun_path));\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nsend_message(int code, char *data, int bytes)\n{\n    char header[8];\n\n    pthread_mutex_lock(&g_mutex);\n    SET_UINT32(header, 0, bytes);\n    SET_UINT32(header, 4, code);\n    if (send(g_sck, header, 8, 0) != 8)\n    {\n        pthread_mutex_unlock(&g_mutex);\n        return 1;\n    }\n    if (send(g_sck, data, bytes, 0) != bytes)\n    {\n        pthread_mutex_unlock(&g_mutex);\n        return 1;\n    }\n    LLOGLN(10, (\"send_message:\"));\n    LHEXDUMP(10, (data, bytes));\n    pthread_mutex_unlock(&g_mutex);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nget_message(int *code, char *data, int *bytes)\n{\n    char header[8];\n    int max_bytes;\n    int error;\n    int recv_rv;\n    int lcode;\n    struct pollfd pollfd;\n\n    LLOGLN(10, (\"get_message:\"));\n    while (1)\n    {\n        LLOGLN(10, (\"get_message: loop\"));\n        pollfd.fd = g_sck;\n        pollfd.events = POLLIN;\n        pollfd.revents = 0;\n        error = poll(&pollfd, 1, 1000);\n        if (error == 1)\n        {\n            pthread_mutex_lock(&g_mutex);\n            pollfd.fd = g_sck;\n            pollfd.events = POLLIN;\n            pollfd.revents = 0;\n            error = poll(&pollfd, 1, 0);\n            if (error == 1)\n            {\n                /* just take a look at the next message */\n                recv_rv = recv(g_sck, header, 8, MSG_PEEK);\n                if (recv_rv == 8)\n                {\n                    lcode = GET_UINT32(header, 4);\n                    if (lcode == *code)\n                    {\n                        /* still have mutex lock */\n                        break;\n                    }\n                    else\n                    {\n                        LLOGLN(10, (\"get_message: lcode %d *code %d\",\n                                    lcode, *code));\n                    }\n                }\n                else if (recv_rv == 0)\n                {\n                    pthread_mutex_unlock(&g_mutex);\n                    LLOGLN(0, (\"get_message: recv_rv 0, disconnect\"));\n                    return 1;\n                }\n                else\n                {\n                    LLOGLN(10, (\"get_message: recv_rv %d\", recv_rv));\n                }\n            }\n            else\n            {\n                LLOGLN(10, (\"get_message: select return %d\", error));\n            }\n            pthread_mutex_unlock(&g_mutex);\n            usleep(1000);\n        }\n    }\n\n    if (recv(g_sck, header, 8, 0) != 8)\n    {\n        pthread_mutex_unlock(&g_mutex);\n        return 1;\n    }\n    max_bytes = *bytes;\n    *bytes = GET_UINT32(header, 0);\n    *code = GET_UINT32(header, 4);\n    if (*bytes > max_bytes)\n    {\n        pthread_mutex_unlock(&g_mutex);\n        return 1;\n    }\n    if (recv(g_sck, data, *bytes, 0) != *bytes)\n    {\n        pthread_mutex_unlock(&g_mutex);\n        return 1;\n    }\n    pthread_mutex_unlock(&g_mutex);\n    return 0;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2,\n                      LPSCARDCONTEXT phContext)\n{\n    char msg[256];\n    DWORD context;\n    int code;\n    int bytes;\n    int status;\n\n    LLOGLN(10, (\"SCardEstablishContext:\"));\n    if (g_sck == -1)\n    {\n        if (connect_to_chansrv() != 0)\n        {\n            LLOGLN(0, (\"SCardEstablishContext: error, can not connect \"\n                       \"to chansrv\"));\n            return SCARD_F_INTERNAL_ERROR;\n        }\n    }\n    SET_UINT32(msg, 0, dwScope);\n    if (send_message(SCARD_ESTABLISH_CONTEXT, msg, 4) != 0)\n    {\n        LLOGLN(0, (\"SCardEstablishContext: error, send_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 256;\n    code = SCARD_ESTABLISH_CONTEXT;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardEstablishContext: error, get_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if ((code != SCARD_ESTABLISH_CONTEXT) || (bytes != 8))\n    {\n        LLOGLN(0, (\"SCardEstablishContext: error, bad code\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    context = GET_UINT32(msg, 0);\n    status = GET_UINT32(msg, 4);\n    LLOGLN(10, (\"SCardEstablishContext: got context 0x%8.8x\", (int)context));\n    *phContext = context;\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardReleaseContext(SCARDCONTEXT hContext)\n{\n    char msg[256];\n    int code;\n    int bytes;\n    int status;\n\n    LLOGLN(10, (\"SCardReleaseContext:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardReleaseContext: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    SET_UINT32(msg, 0, hContext);\n    if (send_message(SCARD_RELEASE_CONTEXT, msg, 4) != 0)\n    {\n        LLOGLN(0, (\"SCardReleaseContext: error, send_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 256;\n    code = SCARD_RELEASE_CONTEXT;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardReleaseContext: error, get_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if ((code != SCARD_RELEASE_CONTEXT) || (bytes != 4))\n    {\n        LLOGLN(0, (\"SCardReleaseContext: error, bad code\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    status = GET_UINT32(msg, 0);\n    LLOGLN(10, (\"SCardReleaseContext: got status 0x%8.8x\", status));\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardIsValidContext(SCARDCONTEXT hContext)\n{\n    LLOGLN(10, (\"SCardIsValidContext:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardIsValidContext: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    return SCARD_S_SUCCESS;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardConnect(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode,\n             DWORD dwPreferredProtocols, LPSCARDHANDLE phCard,\n             LPDWORD pdwActiveProtocol)\n{\n    char msg[256];\n    int code;\n    int bytes;\n    int status;\n    int offset;\n\n    LLOGLN(10, (\"SCardConnect:\"));\n    LLOGLN(10, (\"SCardConnect: hContext 0x%8.8x szReader %s dwShareMode %d \"\n                \"dwPreferredProtocols %d\",\n                (int)hContext, szReader, (int)dwShareMode, (int)dwPreferredProtocols));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardConnect: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    offset = 0;\n    SET_UINT32(msg, offset, hContext);\n    offset += 4;\n    bytes = strlen(szReader);\n    if (bytes > 99)\n    {\n        LLOGLN(0, (\"SCardConnect: error, name too long\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    memcpy(msg + offset, szReader, bytes);\n    memset(msg + offset + bytes, 0, 100 - bytes);\n    offset += 100;\n    SET_UINT32(msg, offset, dwShareMode);\n    offset += 4;\n    SET_UINT32(msg, offset, dwPreferredProtocols);\n    offset += 4;\n    if (send_message(SCARD_CONNECT, msg, offset) != 0)\n    {\n        LLOGLN(0, (\"SCardConnect: error, send_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 256;\n    code = SCARD_CONNECT;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardConnect: error, get_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if (code != SCARD_CONNECT)\n    {\n        LLOGLN(0, (\"SCardConnect: error, bad code\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    *phCard = GET_UINT32(msg, 0);\n    *pdwActiveProtocol = GET_UINT32(msg, 4);\n    status = GET_UINT32(msg, 8);\n    LLOGLN(10, (\"SCardConnect: got status 0x%8.8x hCard 0x%8.8x \"\n                \"dwActiveProtocol %d\",\n                status, (int)*phCard, (int)*pdwActiveProtocol));\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardReconnect(SCARDHANDLE hCard, DWORD dwShareMode,\n               DWORD dwPreferredProtocols, DWORD dwInitialization,\n               LPDWORD pdwActiveProtocol)\n{\n    LLOGLN(0, (\"SCardReconnect:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardReconnect: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    return SCARD_S_SUCCESS;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)\n{\n    char msg[256];\n    int code;\n    int bytes;\n    int status;\n\n    LLOGLN(10, (\"SCardDisconnect: hCard 0x%8.8x dwDisposition %d\",\n                (int)hCard, (int)dwDisposition));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardDisconnect: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    SET_UINT32(msg, 0, hCard);\n    SET_UINT32(msg, 4, dwDisposition);\n    if (send_message(SCARD_DISCONNECT, msg, 8) != 0)\n    {\n        LLOGLN(0, (\"SCardDisconnect: error, send_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 256;\n    code = SCARD_DISCONNECT;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardDisconnect: error, get_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if ((code != SCARD_DISCONNECT) || (bytes != 4))\n    {\n        LLOGLN(0, (\"SCardDisconnect: error, bad code\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    status = GET_UINT32(msg, 0);\n    LLOGLN(10, (\"SCardDisconnect: got status 0x%8.8x\", status));\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardBeginTransaction(SCARDHANDLE hCard)\n{\n    char msg[256];\n    int code;\n    int bytes;\n    int status;\n\n    LLOGLN(10, (\"SCardBeginTransaction: hCard 0x%8.8x\", (int)hCard));\n    if (hCard == 0)\n    {\n        LLOGLN(0, (\"SCardBeginTransaction: error, bad hCard\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardBeginTransaction: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    SET_UINT32(msg, 0, hCard);\n    if (send_message(SCARD_BEGIN_TRANSACTION, msg, 4) != 0)\n    {\n        LLOGLN(0, (\"SCardBeginTransaction: error, send_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 256;\n    code = SCARD_BEGIN_TRANSACTION;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardBeginTransaction: error, get_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if ((code != SCARD_BEGIN_TRANSACTION) || (bytes != 4))\n    {\n        LLOGLN(0, (\"SCardBeginTransaction: error, bad code\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    status = GET_UINT32(msg, 0);\n    LLOGLN(10, (\"SCardBeginTransaction: got status 0x%8.8x\", status));\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisposition)\n{\n    char msg[256];\n    int code;\n    int bytes;\n    int status;\n\n    LLOGLN(10, (\"SCardEndTransaction:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardEndTransaction: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    SET_UINT32(msg, 0, hCard);\n    SET_UINT32(msg, 4, dwDisposition);\n    if (send_message(SCARD_END_TRANSACTION, msg, 8) != 0)\n    {\n        LLOGLN(0, (\"SCardEndTransaction: error, send_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 256;\n    code = SCARD_END_TRANSACTION;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardEndTransaction: error, get_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if ((code != SCARD_END_TRANSACTION) || (bytes != 4))\n    {\n        LLOGLN(0, (\"SCardEndTransaction: error, bad code\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    status = GET_UINT32(msg, 0);\n    LLOGLN(10, (\"SCardEndTransaction: got status 0x%8.8x\", status));\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardStatus(SCARDHANDLE hCard, LPSTR mszReaderName, LPDWORD pcchReaderLen,\n            LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr,\n            LPDWORD pcbAtrLen)\n{\n    char *msg;\n    int code;\n    int bytes;\n    int status;\n    int offset;\n    int cchReaderLen;\n    int to_copy;\n\n    LLOGLN(10, (\"SCardStatus:\"));\n    if (hCard == 0)\n    {\n        LLOGLN(10, (\"SCardStatus: error, bad hCard\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardStatus: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    LLOGLN(10, (\"  hCard 0x%8.8x\", (int)hCard));\n    LLOGLN(10, (\"  cchReaderLen %d\", (int)*pcchReaderLen));\n    LLOGLN(10, (\"  cbAtrLen %d\", (int)*pcbAtrLen));\n\n    cchReaderLen = *pcchReaderLen;\n    msg = (char *) g_malloc_nofail(8192);\n    SET_UINT32(msg, 0, hCard);\n    SET_UINT32(msg, 4, cchReaderLen);\n    SET_UINT32(msg, 8, *pcbAtrLen);\n    if (send_message(SCARD_STATUS, msg, 12) != 0)\n    {\n        LLOGLN(0, (\"SCardStatus: error, send_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 8192;\n    code = SCARD_STATUS;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardStatus: error, get_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if (code != SCARD_STATUS)\n    {\n        LLOGLN(0, (\"SCardStatus: error, bad code\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n\n    LLOGLN(10, (\"SCardStatus: cchReaderLen in %d\", (int)*pcchReaderLen));\n    offset = 0;\n    *pcchReaderLen = GET_UINT32(msg, offset);\n    LLOGLN(10, (\"SCardStatus: cchReaderLen out %d\", (int)*pcchReaderLen));\n    offset += 4;\n    if (cchReaderLen > 0)\n    {\n        to_copy = cchReaderLen - 1;\n        if (*pcchReaderLen < to_copy)\n        {\n            to_copy = *pcchReaderLen;\n        }\n        memcpy(mszReaderName, msg + offset, to_copy);\n        mszReaderName[to_copy] = 0;\n    }\n    LLOGLN(10, (\"SCardStatus: mszReaderName out %s\", mszReaderName));\n    offset += *pcchReaderLen;\n    *pdwState = GET_UINT32(msg, offset);\n    if (*pdwState == 1)\n    {\n        *pdwState = 0x34;\n    }\n    LLOGLN(10, (\"SCardStatus: dwState %d\", (int)*pdwState));\n    offset += 4;\n    *pdwProtocol = GET_UINT32(msg, offset);\n    LLOGLN(10, (\"SCardStatus: dwProtocol %d\", (int)*pdwProtocol));\n    offset += 4;\n    *pcbAtrLen = GET_UINT32(msg, offset);\n    offset += 4;\n    LLOGLN(10, (\"SCardStatus: cbAtrLen %d\", (int)*pcbAtrLen));\n    memcpy(pbAtr, msg + offset, *pcbAtrLen);\n    offset += *pcbAtrLen;\n    status = GET_UINT32(msg, offset);\n    LLOGLN(10, (\"SCardStatus: status %d\", status));\n    offset += 4;\n    free(msg);\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardGetStatusChange(SCARDCONTEXT hContext, DWORD dwTimeout,\n                     LPSCARD_READERSTATE rgReaderStates, DWORD cReaders)\n{\n    char *msg;\n    const char *rname;\n    int bytes;\n    int code;\n    int index;\n    int offset;\n    int str_len;\n    int status;\n    int dwCurrentState;\n    int dwEventState;\n    int cbAtr;\n    char atr[36];\n\n    LLOGLN(10, (\"SCardGetStatusChange:\"));\n    LLOGLN(10, (\"  dwTimeout %d cReaders %d\", (int)dwTimeout, (int)cReaders));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardGetStatusChange: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    msg = (char *) g_malloc_nofail(8192);\n    SET_UINT32(msg, 0, hContext);\n    SET_UINT32(msg, 4, dwTimeout);\n    SET_UINT32(msg, 8, cReaders);\n    offset = 12;\n    for (index = 0; index < cReaders; index++)\n    {\n        rgReaderStates[index].dwCurrentState &= ~2;\n        rgReaderStates[index].dwEventState &= ~2;\n        rname = rgReaderStates[index].szReader;\n        if (strcmp(rname, \"\\\\\\\\?PnP?\\\\Notification\") == 0)\n        {\n            LLOGLN(10, (\"  \\\\\\\\?PnP?\\\\Notification present\"));\n            dwCurrentState = 0;\n            dwEventState = 0;\n            cbAtr = 0;\n            memset(atr, 0, 36);\n        }\n        else\n        {\n            dwCurrentState = rgReaderStates[index].dwCurrentState;\n            dwEventState = rgReaderStates[index].dwEventState;\n            cbAtr = rgReaderStates[index].cbAtr;\n            memset(atr, 0, 36);\n            memcpy(atr, rgReaderStates[index].rgbAtr, 33);\n        }\n        str_len = strlen(rname);\n        str_len = LMIN(str_len, 99);\n        memset(msg + offset, 0, 100);\n        memcpy(msg + offset, rname, str_len);\n        LLOGLN(10, (\"  in szReader       %s\", rname));\n        offset += 100;\n        LLOGLN(10, (\"  in dwCurrentState 0x%8.8x\", dwCurrentState));\n        SET_UINT32(msg, offset, dwCurrentState);\n        offset += 4;\n        LLOGLN(10, (\"  in dwEventState   0x%8.8x\", dwEventState));\n        SET_UINT32(msg, offset, dwEventState);\n        offset += 4;\n        LLOGLN(10, (\"  in cbAtr          %d\", cbAtr));\n        SET_UINT32(msg, offset, cbAtr);\n        offset += 4;\n        memcpy(msg + offset, atr, 36);\n        offset += 36;\n    }\n    if (send_message(SCARD_GET_STATUS_CHANGE, msg, offset) != 0)\n    {\n        LLOGLN(0, (\"SCardGetStatusChange: error, send_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 8192;\n    code = SCARD_GET_STATUS_CHANGE;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardGetStatusChange: error, get_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if (code != SCARD_GET_STATUS_CHANGE)\n    {\n        LLOGLN(0, (\"SCardGetStatusChange: error, bad code\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    cReaders = GET_UINT32(msg, 0);\n    offset = 4;\n    LLOGLN(10, (\"SCardGetStatusChange: got back cReaders %d\", (int)cReaders));\n    for (index = 0; index < cReaders; index++)\n    {\n        rname = rgReaderStates[index].szReader;\n#if 1\n        if (strcmp(rname, \"\\\\\\\\?PnP?\\\\Notification\") == 0)\n        {\n            LLOGLN(10, (\"  out szReader       %s\", rgReaderStates[index].szReader));\n            dwCurrentState = GET_UINT32(msg, offset);\n            rgReaderStates[index].dwCurrentState = dwCurrentState;\n            offset += 4;\n            LLOGLN(10, (\"  out dwCurrentState 0x%8.8x\", dwCurrentState));\n            // disable PnP for now\n            dwEventState = 4; // GET_UINT32(msg, offset);\n            rgReaderStates[index].dwEventState = dwEventState;\n            offset += 4;\n            LLOGLN(10, (\"  out dwEventState   0x%8.8x\", dwEventState));\n            cbAtr = GET_UINT32(msg, offset);\n            rgReaderStates[index].cbAtr = cbAtr;\n            offset += 4;\n            LLOGLN(10, (\"  out cbAtr          %d\", cbAtr));\n            memcpy(rgReaderStates[index].rgbAtr, msg + offset, 33);\n            offset += 36;\n        }\n        else\n#endif\n        {\n            LLOGLN(10, (\"  out szReader       %s\", rgReaderStates[index].szReader));\n            dwCurrentState = GET_UINT32(msg, offset);\n            rgReaderStates[index].dwCurrentState = dwCurrentState;\n            offset += 4;\n            LLOGLN(10, (\"  out dwCurrentState 0x%8.8x\", dwCurrentState));\n            dwEventState = GET_UINT32(msg, offset);\n            rgReaderStates[index].dwEventState = dwEventState;\n            offset += 4;\n            LLOGLN(10, (\"  out dwEventState   0x%8.8x\", dwEventState));\n            cbAtr = GET_UINT32(msg, offset);\n            rgReaderStates[index].cbAtr = cbAtr;\n            offset += 4;\n            LLOGLN(10, (\"  out cbAtr          %d\", cbAtr));\n            memcpy(rgReaderStates[index].rgbAtr, msg + offset, 33);\n            offset += 36;\n        }\n    }\n    status = GET_UINT32(msg, offset);\n    offset += 4;\n    free(msg);\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardControl(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer,\n             DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength,\n             LPDWORD lpBytesReturned)\n{\n    char *msg;\n    int bytes;\n    int code;\n    int offset;\n    int status = 0;\n\n    LLOGLN(10, (\"SCardControl:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardControl: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    LLOGLN(10, (\"  hCard 0x%8.8x\", (int)hCard));\n    LLOGLN(10, (\"  dwControlCode 0x%8.8x\", (int)dwControlCode));\n    LLOGLN(10, (\"  cbSendLength %d\", (int)cbSendLength));\n    LLOGLN(10, (\"  cbRecvLength %d\", (int)cbRecvLength));\n\n    /* #define SCARD_CTL_CODE(code) (0x42000000 + (code))\n       control_code = (control_code & 0x3ffc) >> 2;\n       control_code = SCARD_CTL_CODE(control_code); */\n\n    /* PCSC to Windows control code conversion */\n    dwControlCode = dwControlCode - 0x42000000;\n    dwControlCode = dwControlCode << 2;\n    dwControlCode = dwControlCode | (49 << 16);\n    LLOGLN(10, (\"  MS dwControlCode 0x%8.8d\", (int)dwControlCode));\n\n    msg = (char *) g_malloc_nofail(8192);\n    offset = 0;\n    SET_UINT32(msg, offset, hCard);\n    offset += 4;\n    SET_UINT32(msg, offset, dwControlCode);\n    offset += 4;\n    SET_UINT32(msg, offset, cbSendLength);\n    offset += 4;\n    memcpy(msg + offset, pbSendBuffer, cbSendLength);\n    offset += cbSendLength;\n    SET_UINT32(msg, offset, cbRecvLength);\n    offset += 4;\n    if (send_message(SCARD_CONTROL, msg, offset) != 0)\n    {\n        LLOGLN(0, (\"SCardControl: error, send_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 8192;\n    code = SCARD_CONTROL;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardControl: error, get_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if (code != SCARD_CONTROL)\n    {\n        LLOGLN(0, (\"SCardControl: error, bad code\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    offset = 0;\n    *lpBytesReturned = GET_UINT32(msg, offset);\n    LLOGLN(10, (\"  cbRecvLength %d\", (int)*lpBytesReturned));\n    offset += 4;\n    memcpy(pbRecvBuffer, msg + offset, *lpBytesReturned);\n    offset += *lpBytesReturned;\n    status = GET_UINT32(msg, offset);\n    free(msg);\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardTransmit(SCARDHANDLE hCard, const SCARD_IO_REQUEST *pioSendPci,\n              LPCBYTE pbSendBuffer, DWORD cbSendLength,\n              SCARD_IO_REQUEST *pioRecvPci, LPBYTE pbRecvBuffer,\n              LPDWORD pcbRecvLength)\n{\n    char *msg;\n    int bytes;\n    int code;\n    int offset;\n    int status;\n    int extra_len;\n    int got_recv_pci;\n\n    LLOGLN(10, (\"SCardTransmit:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardTransmit: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n\n    LLOGLN(10, (\"  hCard 0x%8.8x\", (int)hCard));\n    LLOGLN(10, (\"  cbSendLength %d\", (int)cbSendLength));\n    LLOGLN(10, (\"  cbRecvLength %d\", (int)*pcbRecvLength));\n    LLOGLN(10, (\"  pioSendPci->dwProtocol %d\", (int)(pioSendPci->dwProtocol)));\n    LLOGLN(10, (\"  pioSendPci->cbPciLength %d\", (int)(pioSendPci->cbPciLength)));\n    LLOGLN(10, (\"  pioRecvPci %p\", pioRecvPci));\n    if (pioRecvPci != 0)\n    {\n        LLOGLN(10, (\"    pioRecvPci->dwProtocol %d\", (int)(pioRecvPci->dwProtocol)));\n        LLOGLN(10, (\"    pioRecvPci->cbPciLength %d\", (int)(pioRecvPci->cbPciLength)));\n    }\n    msg = (char *) g_malloc_nofail(8192);\n    offset = 0;\n    SET_UINT32(msg, offset, hCard);\n    offset += 4;\n    SET_UINT32(msg, offset, pioSendPci->dwProtocol);\n    offset += 4;\n    /*  SET_UINT32(msg, offset, pioSendPci->cbPciLength); */\n    SET_UINT32(msg, offset, 8);\n    offset += 4;\n    /*  extra_len = pioSendPci->cbPciLength - 8;  */\n    extra_len = 0;\n    SET_UINT32(msg, offset, extra_len);\n    offset += 4;\n    memcpy(msg + offset, pioSendPci + 1, extra_len);\n    offset += extra_len;\n    SET_UINT32(msg, offset, cbSendLength);\n    offset += 4;\n    memcpy(msg + offset, pbSendBuffer, cbSendLength);\n    offset += cbSendLength;\n    got_recv_pci = (pioRecvPci != NULL) && (pioRecvPci->cbPciLength >= 8);\n    // TODO figure out why recv pci does not work\n    got_recv_pci = 0;\n    if (got_recv_pci == 0)\n    {\n        SET_UINT32(msg, offset, 0); /* dwProtocol */\n        offset += 4;\n        SET_UINT32(msg, offset, 0); /* cbPciLength */\n        offset += 4;\n        SET_UINT32(msg, offset, 0); /* extra_len */\n        offset += 4;\n    }\n    else\n    {\n        SET_UINT32(msg, offset, pioRecvPci->dwProtocol);\n        offset += 4;\n        SET_UINT32(msg, offset, pioRecvPci->cbPciLength);\n        offset += 4;\n        extra_len = pioRecvPci->cbPciLength - 8;\n        SET_UINT32(msg, offset, extra_len);\n        offset += 4;\n        memcpy(msg + offset, pioRecvPci + 1, extra_len);\n        offset += extra_len;\n    }\n    SET_UINT32(msg, offset, *pcbRecvLength);\n    offset += 4;\n    if (send_message(SCARD_TRANSMIT, msg, offset) != 0)\n    {\n        LLOGLN(0, (\"SCardTransmit: error, send_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 8192;\n    code = SCARD_TRANSMIT;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardTransmit: error, get_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if (code != SCARD_TRANSMIT)\n    {\n        LLOGLN(0, (\"SCardTransmit: error, bad code\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    offset = 0;\n    if (got_recv_pci == 0)\n    {\n        offset += 8;\n        extra_len = GET_UINT32(msg, offset);\n        offset += 4;\n        offset += extra_len;\n    }\n    else\n    {\n        pioRecvPci->dwProtocol = GET_UINT32(msg, offset);\n        offset += 4;\n        pioRecvPci->cbPciLength = GET_UINT32(msg, offset);\n        offset += 4;\n        extra_len = GET_UINT32(msg, offset);\n        offset += 4;\n        offset += extra_len;\n    }\n    *pcbRecvLength = GET_UINT32(msg, offset);\n    offset += 4;\n    LLOGLN(10, (\"  cbRecvLength %d\", (int)*pcbRecvLength));\n    memcpy(pbRecvBuffer, msg + offset, *pcbRecvLength);\n    LHEXDUMP(10, (pbRecvBuffer, *pcbRecvLength));\n    offset += *pcbRecvLength;\n    status = GET_UINT32(msg, offset);\n    free(msg);\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardListReaderGroups(SCARDCONTEXT hContext, LPSTR mszGroups,\n                      LPDWORD pcchGroups)\n{\n    LLOGLN(10, (\"SCardListReaderGroups:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardListReaderGroups: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    return SCARD_S_SUCCESS;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardListReaders(SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders,\n                 LPDWORD pcchReaders)\n{\n    char *msg;\n    char *reader_names;\n    int reader_names_index;\n    int code;\n    int bytes;\n    int num_readers;\n    int status;\n    int offset;\n    int index;\n    int val;\n    int llen;\n    char reader[100];\n\n    LLOGLN(10, (\"SCardListReaders:\"));\n    LLOGLN(10, (\"SCardListReaders: mszGroups %s\", mszGroups));\n    LLOGLN(10, (\"SCardListReaders: *pcchReaders %d\", (int)*pcchReaders));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardListReaders: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if ((mszGroups == NULL) && (mszReaders == NULL))\n    {\n        *pcchReaders = 0;\n    }\n    msg = (char *) g_malloc_nofail(8192);\n    offset = 0;\n    SET_UINT32(msg, offset, hContext);\n    offset += 4;\n    if (mszGroups != 0)\n    {\n        unsigned int bytes_groups = strlen(mszGroups);\n        SET_UINT32(msg, offset, bytes_groups);\n        offset += 4;\n        memcpy(msg + offset, mszGroups, bytes_groups);\n        offset += bytes_groups;\n    }\n    else\n    {\n        SET_UINT32(msg, offset, 0);\n        offset += 4;\n    }\n    val = *pcchReaders;\n    SET_UINT32(msg, offset, val);\n    offset += 4;\n    if (send_message(SCARD_LIST_READERS, msg, offset) != 0)\n    {\n        LLOGLN(0, (\"SCardListReaders: error, send_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 8192;\n    code = SCARD_LIST_READERS;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardListReaders: error, get_message\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if (code != SCARD_LIST_READERS)\n    {\n        LLOGLN(0, (\"SCardListReaders: error, bad code\"));\n        free(msg);\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    offset = 0;\n    llen = GET_UINT32(msg, offset);\n    offset += 4;\n    num_readers = GET_UINT32(msg, offset);\n    offset += 4;\n    LLOGLN(10, (\"SCardListReaders: mszReaders %p pcchReaders %p num_readers %d\",\n                mszReaders, pcchReaders, num_readers));\n    reader_names = (char *) g_malloc_nofail(8192);\n    reader_names_index = 0;\n    for (index = 0; index < num_readers; index++)\n    {\n        memcpy(reader, msg + offset, 100);\n        bytes = strlen(reader);\n        memcpy(reader_names + reader_names_index, reader, bytes);\n        reader_names_index += bytes;\n        reader_names[reader_names_index] = 0;\n        reader_names_index++;\n        offset += 100;\n        LLOGLN(10, (\"SCardListReaders: readername %s\", reader));\n    }\n    reader_names[reader_names_index] = 0;\n    reader_names_index++;\n    status = GET_UINT32(msg, offset);\n    LLOGLN(10, (\"SCardListReaders: status 0x%8.8x\", status));\n    offset += 4;\n    if (mszReaders == 0)\n    {\n        reader_names_index = llen / 2;\n    }\n    if (pcchReaders != 0)\n    {\n        *pcchReaders = reader_names_index;\n    }\n    if (mszReaders != 0)\n    {\n        memcpy(mszReaders, reader_names, reader_names_index);\n    }\n    free(msg);\n    free(reader_names);\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardFreeMemory(SCARDCONTEXT hContext, LPCVOID pvMem)\n{\n    LLOGLN(0, (\"SCardFreeMemory:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardFreeMemory: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    return SCARD_S_SUCCESS;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardCancel(SCARDCONTEXT hContext)\n{\n    char msg[256];\n    int code;\n    int bytes;\n    int status;\n\n    LLOGLN(10, (\"SCardCancel:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardCancel: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    SET_UINT32(msg, 0, hContext);\n    if (send_message(SCARD_CANCEL, msg, 4) != 0)\n    {\n        LLOGLN(0, (\"SCardCancel: error, send_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    bytes = 256;\n    code = SCARD_CANCEL;\n    if (get_message(&code, msg, &bytes) != 0)\n    {\n        LLOGLN(0, (\"SCardCancel: error, get_message\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    if ((code != SCARD_RELEASE_CONTEXT) || (bytes != 4))\n    {\n        LLOGLN(0, (\"SCardCancel: error, bad code\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    status = GET_UINT32(msg, 0);\n    LLOGLN(10, (\"SCardCancel: got status 0x%8.8x\", status));\n    return status;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr,\n               LPDWORD pcbAttrLen)\n{\n    LLOGLN(0, (\"SCardGetAttrib:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardGetAttrib: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    return SCARD_S_SUCCESS;\n}\n\n/*****************************************************************************/\nPCSC_API LONG\nSCardSetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr,\n               DWORD cbAttrLen)\n{\n    LLOGLN(0, (\"SCardSetAttrib:\"));\n    if (g_sck == -1)\n    {\n        LLOGLN(0, (\"SCardSetAttrib: error, not connected\"));\n        return SCARD_F_INTERNAL_ERROR;\n    }\n    return SCARD_S_SUCCESS;\n}\n\n/*****************************************************************************/\nPCSC_API char *\npcsc_stringify_error(const long code)\n{\n    LLOGLN(10, (\"pcsc_stringify_error: 0x%8.8x\", (int)code));\n    switch (code)\n    {\n        case SCARD_S_SUCCESS:\n            snprintf(g_error_str, 511, \"Command successful.\");\n            break;\n        case SCARD_F_INTERNAL_ERROR:\n            snprintf(g_error_str, 511, \"Internal error.\");\n            break;\n        default:\n            snprintf(g_error_str, 511, \"error 0x%8.8x\", (int)code);\n            break;\n    }\n    g_error_str[511] = 0;\n    return g_error_str;\n}\n"
  },
  {
    "path": "sesman/chansrv/rail.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n   window manager info\n   http://www.freedesktop.org/wiki/Specifications/wm-spec\n\n   rail\n   [MS-RDPERP]: Remote Desktop Protocol:\n   Remote Programs Virtual Channel Extension\n   http://msdn.microsoft.com/en-us/library/cc242568(v=prot.20).aspx\n*/\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <X11/Xlib.h>\n#include <X11/Xatom.h>\n#include <X11/extensions/Xrandr.h>\n#include <X11/cursorfont.h>\n#include \"chansrv.h\"\n#include \"rail.h\"\n#include \"xcommon.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"thread_calls.h\"\n#include \"list.h\"\n\nextern int g_rail_chan_id;      /* in chansrv.c */\nextern char g_display_str[];    /* in chansrv.c */\nextern char *g_exec_name;       /* in chansrv.c */\nextern tbus g_exec_event;       /* in chansrv.c */\nextern tbus g_exec_mutex;       /* in chansrv.c */\nextern tbus g_exec_sem;         /* in chansrv.c */\n\nextern Display *g_display;           /* in xcommon.c */\nextern Screen *g_screen;             /* in xcommon.c */\nextern Window g_root_window;         /* in xcommon.c */\nextern Atom g_wm_delete_window_atom; /* in xcommon.c */\nextern Atom g_wm_protocols_atom;     /* in xcommon.c */\nextern Atom g_utf8_string;           /* in xcommon.c */\nextern Atom g_net_wm_name;           /* in xcommon.c */\nextern Atom g_wm_state;              /* in xcommon.c */\n\nstatic Atom g_rwd_atom = 0;\n\nint g_rail_up = 0;\n\n/* for rail_is_another_wm_running */\nstatic int g_rail_running = 1;\n/* list of valid rail windows */\nstatic struct list *g_window_list = 0;\n\nstatic int g_got_focus = 0;\nstatic int g_focus_counter = 0;\nstatic Window g_focus_win = 0;\n\nstatic int g_xrr_event_base = 0; /* non zero means we got extension */\n\nstatic Cursor g_default_cursor = 0;\n\nstatic char *g_override_window_title = 0;\n\n/* used in valid field of struct rail_window_data */\n#define RWD_X       (1 << 0)\n#define RWD_Y       (1 << 1)\n#define RWD_WIDTH   (1 << 2)\n#define RWD_HEIGHT  (1 << 3)\n#define RWD_TITLE   (1 << 4)\n\nstruct rail_window_data\n{\n    int valid; /* bits for which fields are valid */\n    int x;\n    int y;\n    int width;\n    int height;\n    int title_crc; /* crc of title for compare */\n};\n\n/* Indicates a Client Execute PDU from client to server. */\n#define TS_RAIL_ORDER_EXEC 0x0001\n/* Indicates a Client Activate PDU from client to server. */\n#define TS_RAIL_ORDER_ACTIVATE 0x0002\n/* Indicates a Client System Parameters Update PDU from client\n   to server or a Server System Parameters Update PDU\n   from server to client. */\n#define TS_RAIL_ORDER_SYSPARAM 0x0003\n/* Indicates a Client System Command PDU from client to server. */\n#define TS_RAIL_ORDER_SYSCOMMAND 0x0004\n/* Indicates a bi-directional Handshake PDU. */\n#define TS_RAIL_ORDER_HANDSHAKE 0x0005\n/* Indicates a Client Notify Event PDU from client to server. */\n#define TS_RAIL_ORDER_NOTIFY_EVENT 0x0006\n/* Indicates a Client Window Move PDU from client to server. */\n#define TS_RAIL_ORDER_WINDOWMOVE 0x0008\n/* Indicates a Server Move/Size Start PDU and a Server Move/Size\n   End PDU from server to client. */\n#define TS_RAIL_ORDER_LOCALMOVESIZE 0x0009\n/* Indicates a Server Min Max Info PDU from server to client. */\n#define TS_RAIL_ORDER_MINMAXINFO 0x000a\n/* Indicates a Client Information PDU from client to server. */\n#define TS_RAIL_ORDER_CLIENTSTATUS 0x000b\n/* Indicates a Client System Menu PDU from client to server. */\n#define TS_RAIL_ORDER_SYSMENU 0x000c\n/* Indicates a Server Language Bar Information PDU from server to\n   client, or a Client Language Bar Information PDU from client to server. */\n#define TS_RAIL_ORDER_LANGBARINFO 0x000d\n/* Indicates a Server Execute Result PDU from server to client. */\n#define TS_RAIL_ORDER_EXEC_RESULT 0x0080\n/* Indicates a Client Get Application ID PDU from client to server. */\n#define TS_RAIL_ORDER_GET_APPID_REQ 0x000E\n/* Indicates a Server Get Application ID Response PDU from\n   server to client. */\n#define TS_RAIL_ORDER_GET_APPID_RESP 0x000F\n\n/* Resize the window. */\n#define SC_SIZE 0xF000\n/* Move the window. */\n#define SC_MOVE 0xF010\n/* Minimize the window. */\n#define SC_MINIMIZE 0xF020\n/* Maximize the window. */\n#define SC_MAXIMIZE 0xF030\n/* Close the window. */\n#define SC_CLOSE 0xF060\n/* The ALT + SPACE key combination was pressed; display\n   the window's system menu. */\n#define SC_KEYMENU 0xF100\n/* Restore the window to its original shape and size. */\n#define SC_RESTORE 0xF120\n/* Perform the default action of the window's system menu. */\n#define SC_DEFAULT 0xF160\n\n/* for tooltips */\n#define RAIL_STYLE_TOOLTIP (0x80000000)\n#define RAIL_EXT_STYLE_TOOLTIP (0x00000080 | 0x00000008)\n\n/* for normal desktop windows */\n#define RAIL_STYLE_NORMAL (0x00C00000 | 0x00080000 | 0x00040000 | 0x00010000 | 0x00020000)\n#define RAIL_EXT_STYLE_NORMAL (0x00040000)\n\n/* for dialogs */\n#define RAIL_STYLE_DIALOG (0x80000000)\n#define RAIL_EXT_STYLE_DIALOG (0x00040000)\n\nstatic int rail_win_get_state(Window win);\nstatic int rail_create_window(Window window_id, Window owner_id);\nstatic int rail_win_set_state(Window win, unsigned long state);\nstatic int rail_show_window(Window window_id, int show_state);\nstatic int rail_win_send_text(Window win);\n\n/*****************************************************************************/\nstatic int\nrail_send_key_esc(int window_id)\n{\n    XEvent event;\n\n    g_memset(&event, 0, sizeof(event));\n    event.type = KeyPress;\n    event.xkey.same_screen = True;\n    event.xkey.root = g_root_window;\n    event.xkey.window = window_id;\n    event.xkey.keycode = 9;\n    XSendEvent(g_display, window_id, True, 0xfff, &event);\n    event.type = KeyRelease;\n    XSendEvent(g_display, window_id, True, 0xfff, &event);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic struct rail_window_data *\nrail_get_window_data(Window window)\n{\n    unsigned int bytes;\n    Atom actual_type_return;\n    int actual_format_return;\n    unsigned long nitems_return;\n    unsigned long bytes_after_return;\n    unsigned char *prop_return;\n    struct rail_window_data *rv;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_get_window_data:\");\n    rv = 0;\n    actual_type_return = 0;\n    actual_format_return = 0;\n    nitems_return = 0;\n    prop_return = 0;\n    bytes = sizeof(struct rail_window_data);\n    XGetWindowProperty(g_display, window, g_rwd_atom, 0, bytes, 0,\n                       XA_STRING, &actual_type_return,\n                       &actual_format_return, &nitems_return,\n                       &bytes_after_return, &prop_return);\n    if (prop_return == 0)\n    {\n        return 0;\n    }\n    if (nitems_return == bytes)\n    {\n        rv = (struct rail_window_data *)prop_return;\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nrail_set_window_data(Window window, struct rail_window_data *rwd)\n{\n    int bytes;\n\n    bytes = sizeof(struct rail_window_data);\n    XChangeProperty(g_display, window, g_rwd_atom, XA_STRING, 8,\n                    PropModeReplace, (unsigned char *)rwd, bytes);\n    return 0;\n}\n\n/*****************************************************************************/\n/* get the rail window data, if not exist, try to create it and return */\nstatic struct rail_window_data *\nrail_get_window_data_safe(Window window)\n{\n    struct rail_window_data *rv;\n\n    rv = rail_get_window_data(window);\n    if (rv != 0)\n    {\n        return rv;\n    }\n    rv = g_new0(struct rail_window_data, 1);\n    rail_set_window_data(window, rv);\n    g_free(rv);\n    return rail_get_window_data(window);\n}\n\n/******************************************************************************/\nstatic int\nis_window_valid_child_of_root(unsigned int window_id)\n{\n    int found;\n    unsigned int i;\n    unsigned int nchild;\n    Window r;\n    Window p;\n    Window *children;\n\n    found = 0;\n    XQueryTree(g_display, g_root_window, &r, &p, &children, &nchild);\n\n    for (i = 0; i < nchild; i++)\n    {\n        if (window_id == children[i])\n        {\n            found = 1;\n            break;\n        }\n    }\n\n    XFree(children);\n    return found;\n}\n\n/*****************************************************************************/\nstatic int\nrail_send_init(void)\n{\n    struct stream *s;\n    int bytes;\n    char *size_ptr;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_send_init:\");\n    make_stream(s);\n    init_stream(s, 8182);\n    out_uint16_le(s, TS_RAIL_ORDER_HANDSHAKE);\n    size_ptr = s->p;\n    out_uint16_le(s, 0);        /* size, set later */\n    out_uint32_le(s, 1);        /* build number */\n    s_mark_end(s);\n    bytes = (int)((s->end - s->data) - 4);\n    size_ptr[0] = bytes;\n    size_ptr[1] = bytes >> 8;\n    bytes = (int)(s->end - s->data);\n    send_channel_data(g_rail_chan_id, s->data, bytes);\n    free_stream(s);\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nanotherWMRunning(Display *display, XErrorEvent *xe)\n{\n    g_rail_running = 0;\n    return -1;\n}\n\n/******************************************************************************/\nstatic int\nrail_is_another_wm_running(void)\n{\n    XErrorHandler old;\n\n    g_rail_running = 1;\n    old = XSetErrorHandler((XErrorHandler)anotherWMRunning);\n    XSelectInput(g_display, g_root_window,\n                 PropertyChangeMask | StructureNotifyMask |\n                 SubstructureRedirectMask | ButtonPressMask |\n                 SubstructureNotifyMask | FocusChangeMask |\n                 EnterWindowMask | LeaveWindowMask);\n    XSync(g_display, 0);\n    XSetErrorHandler((XErrorHandler)old);\n    g_rail_up = g_rail_running;\n\n    if (!g_rail_up)\n    {\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nrail_init(void)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_init:\");\n    xcommon_init();\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nrail_deinit(void)\n{\n    if (g_rail_up)\n    {\n        list_delete(g_window_list);\n        g_window_list = 0;\n        /* no longer window manager */\n        XSelectInput(g_display, g_root_window, 0);\n        g_rail_up = 0;\n    }\n\n    return 0;\n}\n\nstatic int\nrail_startup(void)\n{\n    int dummy;\n    int ver_maj;\n    int ver_min;\n    Status st;\n\n    if (rail_is_another_wm_running())\n    {\n        LOG(LOG_LEVEL_ERROR, \"rail_init: another window manager \"\n            \"is running\");\n    }\n\n    list_delete(g_window_list);\n    g_window_list = list_create();\n    rail_send_init();\n    g_rail_up = 1;\n    g_rwd_atom = XInternAtom(g_display, \"XRDP_RAIL_WINDOW_DATA\", 0);\n\n    if (!XRRQueryExtension(g_display, &g_xrr_event_base, &dummy))\n    {\n        g_xrr_event_base = 0;\n        LOG(LOG_LEVEL_ERROR, \"rail_init: RandR extension not found\");\n    }\n\n    if (g_xrr_event_base > 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO, \"rail_init: found RandR extension\");\n        st = XRRQueryVersion(g_display, &ver_maj, &ver_min);\n        if (st)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"rail_init: RandR version major %d minor %d\", ver_maj, ver_min);\n        }\n        XRRSelectInput(g_display, g_root_window, RRScreenChangeNotifyMask);\n    }\n\n    if (g_default_cursor == 0)\n    {\n        g_default_cursor = XCreateFontCursor(g_display, XC_left_ptr);\n        XDefineCursor(g_display, g_root_window, g_default_cursor);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic char *\nread_uni(struct stream *s, unsigned int num_bytes)\n{\n    char *rv = NULL;\n    if (s_check_rem_and_log(s, num_bytes, \"Reading RAIL string\"))\n    {\n        unsigned int num_words = num_bytes / 2;\n        unsigned int utf8len = in_utf16_le_fixed_as_utf8_length(s, num_words);\n\n        // Allocate space for a back-stop terminator\n        rv = (char *)g_malloc(utf8len + 1, 0);\n        if (rv != NULL)\n        {\n            rv[utf8len] = '\\0';\n            in_utf16_le_fixed_as_utf8(s, num_words, rv, utf8len);\n            if ((num_bytes % 2) != 0)\n            {\n                /* Skip unused character */\n                in_uint8s(s, 1);\n            }\n        }\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* See [MS-RDPERP] 2.2.2.3.1 (TS_RAIL_ORDER_EXEC) */\nstatic int\nrail_process_exec(struct stream *s, int size)\n{\n    int rv = 1;\n\n    int flags;\n    unsigned int ExeOrFileLength;\n    unsigned int WorkingDirLength;\n    unsigned int ArgumentsLen;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"chansrv::rail_process_exec:\");\n    in_uint16_le(s, flags);\n    in_uint16_le(s, ExeOrFileLength);\n    in_uint16_le(s, WorkingDirLength);\n    in_uint16_le(s, ArgumentsLen);\n    // The constants below are taken from [MS-RDPERP] 2.2.2.3.1\n    if (ExeOrFileLength == 0 || ExeOrFileLength > 520)\n    {\n        LOG(LOG_LEVEL_ERROR, \"ExeOrFileLength field is out of range %u\",\n            ExeOrFileLength);\n    }\n    else if (WorkingDirLength > 520)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WorkingDirLength field is out of range %d\",\n            WorkingDirLength);\n    }\n    else if (ArgumentsLen > 16000)\n    {\n        LOG(LOG_LEVEL_ERROR, \"ArgumentsLen field is out of range %d\",\n            ArgumentsLen);\n    }\n    else\n    {\n        char *ExeOrFile = read_uni(s, ExeOrFileLength);\n        char *WorkingDir = read_uni(s, WorkingDirLength);\n        char *Arguments = read_uni(s, ArgumentsLen);\n        if (ExeOrFile == NULL || WorkingDir == NULL || Arguments == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Out of memory reading TS_RAIL_ORDER_EXEC PDU\");\n        }\n        else\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"  flags 0x%8.8x ExeOrFileLength %d WorkingDirLength %d \"\n                \"ArgumentsLen %d ExeOrFile [%s] WorkingDir [%s] \"\n                \"Arguments [%s]\", flags, ExeOrFileLength, WorkingDirLength,\n                ArgumentsLen, ExeOrFile, WorkingDir, Arguments);\n\n            rail_startup();\n\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"rail_process_exec: pre\");\n            /* ask main thread to fork */\n            tc_mutex_lock(g_exec_mutex);\n            g_exec_name = ExeOrFile;\n            g_set_wait_obj(g_exec_event);\n            tc_sem_dec(g_exec_sem);\n            tc_mutex_unlock(g_exec_mutex);\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"rail_process_exec: post\");\n\n            rv = 0;\n        }\n\n        /* TODO : Looks like a race condition here */\n        g_free(ExeOrFile);\n        g_free(WorkingDir);\n        g_free(Arguments);\n    }\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nrail_win_popdown(void)\n{\n    int rv = 0;\n    int i;\n    unsigned int nchild;\n    Window r;\n    Window p;\n    Window *children;\n    XWindowAttributes window_attributes;\n\n    /*\n     * Check the tree of current existing X windows and dismiss\n     * the managed rail popups by simulating a esc key, so\n     * that the requested window can be closed properly.\n     */\n\n    XQueryTree(g_display, g_root_window, &r, &p, &children, &nchild);\n    for (i = nchild - 1; i >= 0; i--)\n    {\n        XGetWindowAttributes(g_display, children[i], &window_attributes);\n        if (window_attributes.override_redirect &&\n                window_attributes.map_state == IsViewable &&\n                list_index_of(g_window_list, children[i]) >= 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  dismiss pop up 0x%8.8lx\", children[i]);\n            rail_send_key_esc(children[i]);\n            rv = 1;\n        }\n    }\n\n    XFree(children);\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nrail_close_window(int window_id)\n{\n    XEvent ce;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"chansrv::rail_close_window:\");\n\n    rail_win_popdown();\n\n    g_memset(&ce, 0, sizeof(ce));\n    ce.xclient.type = ClientMessage;\n    ce.xclient.message_type = g_wm_protocols_atom;\n    ce.xclient.display = g_display;\n    ce.xclient.window = window_id;\n    ce.xclient.format = 32;\n    ce.xclient.data.l[0] = g_wm_delete_window_atom;\n    ce.xclient.data.l[1] = CurrentTime;\n    XSendEvent(g_display, window_id, False, NoEventMask, &ce);\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic void\nmy_timeout(void *data)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_timeout: g_got_focus %d\", g_got_focus);\n    if (g_focus_counter == (int)(long)data)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_timeout: g_focus_counter %d\", g_focus_counter);\n        rail_win_popdown();\n    }\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_activate(struct stream *s, int size)\n{\n    unsigned int window_id;\n    int enabled;\n    int index;\n    XWindowAttributes window_attributes;\n    Window transient_for = 0;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_activate:\");\n    in_uint32_le(s, window_id);\n    in_uint8(s, enabled);\n\n    index = list_index_of(g_window_list, window_id);\n    if (index < 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_activate: window 0x%8.8x not in list\",\n                  window_id);\n        return 0;\n    }\n\n    g_focus_counter++;\n    g_got_focus = enabled;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x enabled %d\", window_id, enabled);\n\n    XGetWindowAttributes(g_display, window_id, &window_attributes);\n\n    if (enabled)\n    {\n        if (g_focus_win == window_id)\n        {\n            /* In case that window is unmapped upon minimization and not yet mapped*/\n            XMapWindow(g_display, window_id);\n        }\n        else\n        {\n            rail_win_popdown();\n            if (window_attributes.map_state != IsViewable)\n            {\n                /* In case that window is unmapped upon minimization and not yet mapped */\n                XMapWindow(g_display, window_id);\n            }\n            XGetTransientForHint(g_display, window_id, &transient_for);\n            if (transient_for > 0)\n            {\n                /* Owner window should be raised up as well */\n                XRaiseWindow(g_display, transient_for);\n            }\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_activate: calling XRaiseWindow 0x%8.8x\", window_id);\n            XRaiseWindow(g_display, window_id);\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_activate: calling XSetInputFocus 0x%8.8x\", window_id);\n            XSetInputFocus(g_display, window_id, RevertToParent, CurrentTime);\n        }\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_activate: calling XRaiseWindow 0x%8.8x\", window_id);\n        XRaiseWindow(g_display, window_id);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_activate: calling XSetInputFocus 0x%8.8x\", window_id);\n        XSetInputFocus(g_display, window_id, RevertToParent, CurrentTime);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window attributes: override_redirect %d\",\n                  window_attributes.override_redirect);\n        add_timeout(200, my_timeout, (void *)(long)g_focus_counter);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_select_input(Window window_id)\n{\n    XSelectInput(g_display, window_id,\n                 PropertyChangeMask | StructureNotifyMask |\n                 SubstructureNotifyMask | FocusChangeMask |\n                 EnterWindowMask | LeaveWindowMask);\n    XSync(g_display, 0);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_restore_windows(void)\n{\n    unsigned int i;\n    unsigned int nchild;\n    Window r;\n    Window p;\n    Window *children;\n\n    XQueryTree(g_display, g_root_window, &r, &p, &children, &nchild);\n    for (i = 0; i < nchild; i++)\n    {\n        XWindowAttributes window_attributes;\n        XGetWindowAttributes(g_display, children[i], &window_attributes);\n        if (!window_attributes.override_redirect)\n        {\n            rail_select_input(children[i]);\n            if (window_attributes.map_state == IsViewable)\n            {\n                rail_win_set_state(children[i], 0x0); /* WithdrawnState */\n                rail_create_window(children[i], g_root_window);\n                rail_win_set_state(children[i], 0x1); /* NormalState */\n                rail_win_send_text(children[i]);\n            }\n        }\n    }\n    XFree(children);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_system_param(struct stream *s, int size)\n{\n    int system_param;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_system_param:\");\n    in_uint32_le(s, system_param);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  system_param 0x%8.8x\", system_param);\n    /*\n     * Ask client to re-create the existing rail windows. This is supposed\n     * to be done after handshake and client is initialised properly, we\n     * consider client is ready when it sends \"SET_WORKAREA\" sysparam.\n     */\n    if (system_param == 0x0000002F) /*SPI_SET_WORK_AREA*/\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  restore rail windows\");\n        rail_restore_windows();\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_get_property(Display *display, Window target, Atom type, Atom property,\n                  unsigned char **data, unsigned long *count)\n{\n    Atom atom_return;\n    int size;\n    unsigned long nitems, bytes_left;\n    char *prop_name;\n\n    int ret = XGetWindowProperty(display, target, property,\n                                 0l, 1l, False,\n                                 type, &atom_return, &size,\n                                 &nitems, &bytes_left, data);\n    if ((ret != Success || nitems < 1) && atom_return == None)\n    {\n        prop_name = XGetAtomName(g_display, property);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  rail_get_property %s: failed\", prop_name);\n        XFree(prop_name);\n        return 1;\n    }\n\n    if (bytes_left != 0)\n    {\n        XFree(*data);\n        unsigned long remain = ((size / 8) * nitems) + bytes_left;\n        ret = XGetWindowProperty(g_display, target,\n                                 property, 0l, remain, False,\n                                 atom_return, &atom_return, &size,\n                                 &nitems, &bytes_left, data);\n        if (ret != Success)\n        {\n            return 1;\n        }\n    }\n\n    *count = nitems;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_win_get_state(Window win)\n{\n    unsigned long nitems = 0;\n    int rv = -1;\n    char *data = 0;\n\n    rail_get_property(g_display, win, g_wm_state, g_wm_state,\n                      (unsigned char **)&data,\n                      &nitems);\n\n    if (data && nitems > 0)\n    {\n        rv = *(unsigned long *)data;\n        XFree(data);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  rail_win_get_state: %d\", rv);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nrail_win_set_state(Window win, unsigned long state)\n{\n    int old_state;\n    unsigned long data[2] = { state, None };\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  rail_win_set_state: %ld\", state);\n    /* check whether WM_STATE exists */\n    old_state = rail_win_get_state(win);\n    if (old_state == -1)\n    {\n        /* create WM_STATE property */\n        XChangeProperty(g_display, win, g_wm_state, g_wm_state, 32, PropModeAppend,\n                        (unsigned char *)data, 2);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  rail_win_set_state: create WM_STATE property\");\n    }\n    else\n    {\n        XChangeProperty(g_display, win, g_wm_state, g_wm_state, 32, PropModeReplace,\n                        (unsigned char *)data, 2);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* *data pointer that needs g_free */\nstatic int\nrail_win_get_text(Window win, char **data)\n{\n    int ret = 0;\n    int i = 0;\n    unsigned long nitems = 0;\n    unsigned char *ldata = 0;\n    char *lldata = 0;\n\n    if (g_override_window_title != 0)\n    {\n        *data = g_strdup(g_override_window_title);\n        return g_strlen(*data);\n    }\n    ret = rail_get_property(g_display, win, g_utf8_string, g_net_wm_name,\n                            &ldata, &nitems);\n    if (ret != 0)\n    {\n        /* _NET_WM_NAME isn't set, use WM_NAME (XFetchName) instead */\n        XFetchName(g_display, win, &lldata);\n        *data = g_strdup(lldata);\n        i = g_strlen(*data);\n        XFree(lldata);\n        return i;\n    }\n\n    *data = 0;\n    if (ldata)\n    {\n        *data = g_strdup((char *)ldata);\n        i = g_strlen(*data);\n        XFree(ldata);\n        return i;\n    }\n\n    return i;\n}\n\n/******************************************************************************/\nstatic int\nrail_minmax_window(int window_id, int max)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_minmax_window 0x%8.8x:\", window_id);\n    if (max)\n    {\n\n    }\n    else\n    {\n        XUnmapWindow(g_display, window_id);\n        /* change window state to IconicState (3) */\n        rail_win_set_state(window_id, 0x3);\n        /*\n         * TODO dismiss popups opened so far\n         */\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_restore_window(int window_id)\n{\n    XWindowAttributes window_attributes;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_restore_window 0x%8.8x:\", window_id);\n    XGetWindowAttributes(g_display, window_id, &window_attributes);\n    if (window_attributes.map_state != IsViewable)\n    {\n        XMapWindow(g_display, window_id);\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_activate: calling XRaiseWindow 0x%8.8x\", window_id);\n    XRaiseWindow(g_display, window_id);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_activate: calling XSetInputFocus 0x%8.8x\", window_id);\n    XSetInputFocus(g_display, window_id, RevertToParent, CurrentTime);\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_system_command(struct stream *s, int size)\n{\n    int window_id;\n    int command;\n    int index;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_system_command:\");\n    in_uint32_le(s, window_id);\n    in_uint16_le(s, command);\n\n    index = list_index_of(g_window_list, window_id);\n    if (index < 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_system_command: window 0x%8.8x not in list\",\n                  window_id);\n        return 0;\n    }\n\n    switch (command)\n    {\n        case SC_SIZE:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x SC_SIZE\", window_id);\n            break;\n        case SC_MOVE:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x SC_MOVE\", window_id);\n            break;\n        case SC_MINIMIZE:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x SC_MINIMIZE\", window_id);\n            rail_minmax_window(window_id, 0);\n            break;\n        case SC_MAXIMIZE:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x SC_MAXIMIZE\", window_id);\n            break;\n        case SC_CLOSE:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x SC_CLOSE\", window_id);\n            rail_close_window(window_id);\n            break;\n        case SC_KEYMENU:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x SC_KEYMENU\", window_id);\n            break;\n        case SC_RESTORE:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x SC_RESTORE\", window_id);\n            rail_restore_window(window_id);\n            break;\n        case SC_DEFAULT:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x SC_DEFAULT\", window_id);\n            break;\n        default:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x unknown command command %d\",\n                      window_id, command);\n            break;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_handshake(struct stream *s, int size)\n{\n    int build_number;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_handshake:\");\n    in_uint32_le(s, build_number);\n    LOG(LOG_LEVEL_DEBUG, \"  build_number 0x%8.8x\", build_number);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_notify_event(struct stream *s, int size)\n{\n    int window_id;\n    int notify_id;\n    int message;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_notify_event:\");\n    in_uint32_le(s, window_id);\n    in_uint32_le(s, notify_id);\n    in_uint32_le(s, message);\n    LOG(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x notify_id 0x%8.8x message 0x%8.8x\",\n        window_id, notify_id, message);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_window_move(struct stream *s, int size)\n{\n    int window_id;\n    int left;\n    int top;\n    int right;\n    int bottom;\n    tsi16 si16;\n    struct rail_window_data *rwd;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_window_move:\");\n    in_uint32_le(s, window_id);\n    in_uint16_le(s, si16);\n    left = si16;\n    in_uint16_le(s, si16);\n    top = si16;\n    in_uint16_le(s, si16);\n    right = si16;\n    in_uint16_le(s, si16);\n    bottom = si16;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x left %d top %d right %d bottom %d width %d height %d\",\n              window_id, left, top, right, bottom, right - left, bottom - top);\n    XMoveResizeWindow(g_display, window_id, left, top, right - left, bottom - top);\n    rwd = (struct rail_window_data *)\n          g_malloc(sizeof(struct rail_window_data), 1);\n    rwd->x = left;\n    rwd->y = top;\n    rwd->width = right - left;\n    rwd->height = bottom - top;\n    rail_set_window_data(window_id, rwd);\n    g_free(rwd);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_local_move_size(struct stream *s, int size)\n{\n    int window_id;\n    int is_move_size_start;\n    int move_size_type;\n    int pos_x;\n    int pos_y;\n    tsi16 si16;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_local_move_size:\");\n    in_uint32_le(s, window_id);\n    in_uint16_le(s, is_move_size_start);\n    in_uint16_le(s, move_size_type);\n    in_uint16_le(s, si16);\n    pos_x = si16;\n    in_uint16_le(s, si16);\n    pos_y = si16;\n    LOG(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x is_move_size_start %d move_size_type %d \"\n        \"pos_x %d pos_y %d\", window_id, is_move_size_start, move_size_type,\n        pos_x, pos_y);\n    return 0;\n}\n\n/*****************************************************************************/\n/* server to client only */\nstatic int\nrail_process_min_max_info(struct stream *s, int size)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_min_max_info:\");\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_client_status(struct stream *s, int size)\n{\n    int flags;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_client_status:\");\n    in_uint32_le(s, flags);\n    LOG(LOG_LEVEL_DEBUG, \"  flags 0x%8.8x\", flags);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_sys_menu(struct stream *s, int size)\n{\n    int window_id;\n    int left;\n    int top;\n    tsi16 si16;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_sys_menu:\");\n    in_uint32_le(s, window_id);\n    in_uint16_le(s, si16);\n    left = si16;\n    in_uint16_le(s, si16);\n    top = si16;\n    LOG(LOG_LEVEL_DEBUG, \"  window_id 0x%8.8x left %d top %d\", window_id, left, top);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_lang_bar_info(struct stream *s, int size)\n{\n    int language_bar_status;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_lang_bar_info:\");\n    in_uint32_le(s, language_bar_status);\n    LOG(LOG_LEVEL_DEBUG, \"  language_bar_status 0x%8.8x\", language_bar_status);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_appid_req(struct stream *s, int size)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_appid_req:\");\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_process_appid_resp(struct stream *s, int size)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_appid_resp:\");\n    return 0;\n}\n\n/*****************************************************************************/\n/* server to client only */\nstatic int\nrail_process_exec_result(struct stream *s, int size)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_process_exec_result:\");\n    return 0;\n}\n\n/*****************************************************************************/\n/* data in from client ( client -> xrdp -> chansrv ) */\nint\nrail_data_in(struct stream *s, int chan_id, int chan_flags, int length,\n             int total_length)\n{\n    int code;\n    int size;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_data_in:\");\n    in_uint8(s, code);\n    in_uint8s(s, 1);\n    in_uint16_le(s, size);\n\n    switch (code)\n    {\n        case TS_RAIL_ORDER_EXEC: /* 1 */\n            rail_process_exec(s, size);\n            break;\n        case TS_RAIL_ORDER_ACTIVATE: /* 2 */\n            rail_process_activate(s, size);\n            break;\n        case TS_RAIL_ORDER_SYSPARAM: /* 3 */\n            rail_process_system_param(s, size);\n            break;\n        case TS_RAIL_ORDER_SYSCOMMAND: /* 4 */\n            rail_process_system_command(s, size);\n            break;\n        case TS_RAIL_ORDER_HANDSHAKE: /* 5 */\n            rail_process_handshake(s, size);\n            break;\n        case TS_RAIL_ORDER_NOTIFY_EVENT: /* 6 */\n            rail_process_notify_event(s, size);\n            break;\n        case TS_RAIL_ORDER_WINDOWMOVE: /* 8 */\n            rail_process_window_move(s, size);\n            break;\n        case TS_RAIL_ORDER_LOCALMOVESIZE: /* 9 */\n            rail_process_local_move_size(s, size);\n            break;\n        case TS_RAIL_ORDER_MINMAXINFO: /* 10 */\n            rail_process_min_max_info(s, size);\n            break;\n        case TS_RAIL_ORDER_CLIENTSTATUS: /* 11 */\n            rail_process_client_status(s, size);\n            break;\n        case TS_RAIL_ORDER_SYSMENU: /* 12 */\n            rail_process_sys_menu(s, size);\n            break;\n        case TS_RAIL_ORDER_LANGBARINFO: /* 13 */\n            rail_process_lang_bar_info(s, size);\n            break;\n        case TS_RAIL_ORDER_GET_APPID_REQ: /* 14 */\n            rail_process_appid_req(s, size);\n            break;\n        case TS_RAIL_ORDER_GET_APPID_RESP: /* 15 */\n            rail_process_appid_resp(s, size);\n            break;\n        case TS_RAIL_ORDER_EXEC_RESULT: /* 128 */\n            rail_process_exec_result(s, size);\n            break;\n        default:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"rail_data_in: unknown code %d size %d\", code, size);\n            break;\n    }\n\n    XFlush(g_display);\n    return  0;\n}\n\nstatic const unsigned int g_crc_seed = 0xffffffff;\nstatic const unsigned int g_crc_table[256] =\n{\n    0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,\n    0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n    0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,\n    0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n    0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n    0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n    0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,\n    0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n    0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,\n    0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n    0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,\n    0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n    0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,\n    0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n    0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n    0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n    0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,\n    0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n    0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,\n    0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n    0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,\n    0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n    0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,\n    0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n    0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n    0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n    0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,\n    0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n    0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,\n    0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n    0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,\n    0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n    0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,\n    0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n    0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n    0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n    0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,\n    0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n    0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,\n    0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n    0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\n    0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n    0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d\n};\n\n#define CRC_START(in_crc) (in_crc) = g_crc_seed\n#define CRC_PASS(in_pixel, in_crc) \\\n    (in_crc) = g_crc_table[((in_crc) ^ (in_pixel)) & 0xff] ^ ((in_crc) >> 8)\n#define CRC_END(in_crc) (in_crc) = ((in_crc) ^ g_crc_seed)\n\n/*****************************************************************************/\nstatic int\nget_string_crc(const char *text)\n{\n    int index;\n    int crc;\n\n    CRC_START(crc);\n    index = 0;\n    while (text[index] != 0)\n    {\n        CRC_PASS(text[index], crc);\n        index++;\n    }\n    CRC_END(crc);\n    return crc;\n}\n\n/*****************************************************************************/\n/* returns 0, event handled, 1 unhandled */\nstatic int\nrail_win_send_text(Window win)\n{\n    char *data = 0;\n    struct stream *s;\n    int len = 0;\n    int flags;\n    int crc;\n    struct rail_window_data *rwd;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_win_send_text:\");\n    len = rail_win_get_text(win, &data);\n    rwd = rail_get_window_data_safe(win);\n    if (rwd != 0)\n    {\n        if (data != 0)\n        {\n            if (rwd->valid & RWD_TITLE)\n            {\n                crc = get_string_crc(data);\n                if (rwd->title_crc == crc)\n                {\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_win_send_text: skipping, title not changed\");\n                    g_free(data);\n                    XFree(rwd);\n                    return 0;\n                }\n            }\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"chansrv::rail_win_send_text: error rail_get_window_data_safe failed\");\n        g_free(data);\n        return 1;\n    }\n    if (data && len > 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_win_send_text: 0x%8.8lx text %s length %d\",\n                  win, data, len);\n        make_stream(s);\n        init_stream(s, len + 1024);\n        flags = WINDOW_ORDER_TYPE_WINDOW | WINDOW_ORDER_FIELD_TITLE;\n        out_uint32_le(s, 8); /* update title info */\n        out_uint32_le(s, win); /* window id */\n        out_uint32_le(s, flags); /* flags */\n        out_uint32_le(s, len); /* title size */\n        out_uint8a(s, data, len); /* title */\n        s_mark_end(s);\n        send_rail_drawing_orders(s->data, (int)(s->end - s->data));\n        free_stream(s);\n        /* update rail window data */\n        rwd->valid |= RWD_TITLE;\n        crc = get_string_crc(data);\n        rwd->title_crc = crc;\n        rail_set_window_data(win, rwd);\n    }\n    g_free(data);\n    XFree(rwd);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_destroy_window(Window window_id)\n{\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_destroy_window 0x%8.8lx\", window_id);\n    make_stream(s);\n    init_stream(s, 1024);\n\n    out_uint32_le(s, 4); /* destroy_window */\n    out_uint32_le(s, window_id);\n    s_mark_end(s);\n    send_rail_drawing_orders(s->data, (int)(s->end - s->data));\n    free_stream(s);\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nrail_show_window(Window window_id, int show_state)\n{\n    int flags;\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_show_window 0x%8.8lx 0x%x\", window_id, show_state);\n    make_stream(s);\n    init_stream(s, 1024);\n\n    flags = WINDOW_ORDER_TYPE_WINDOW | WINDOW_ORDER_FIELD_SHOW;\n    out_uint32_le(s, 6); /* show_window */\n    out_uint32_le(s, window_id); /* window_id */\n    out_uint32_le(s, flags); /* flags */\n    out_uint32_le(s, show_state); /* show_state */\n    s_mark_end(s);\n    send_rail_drawing_orders(s->data, (int)(s->end - s->data));\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nrail_create_window(Window window_id, Window owner_id)\n{\n    int x;\n    int y;\n    tui32 width;\n    tui32 height;\n    tui32 border;\n    Window root;\n    tui32 depth;\n    char *title_bytes = 0;\n    int title_size = 0;\n    XWindowAttributes attributes;\n    tui32 style;\n    int ext_style;\n    int num_window_rects = 1;\n    int num_visibility_rects = 1;\n    int i = 0;\n\n    int flags;\n    int index;\n    int crc;\n    Window transient_for = 0;\n    struct rail_window_data *rwd;\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_create_window 0x%8.8lx\", window_id);\n\n    rwd = rail_get_window_data_safe(window_id);\n    if (rwd == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"chansrv::rail_create_window: error rail_get_window_data_safe failed\");\n        return 0;\n    }\n    XGetGeometry(g_display, window_id, &root, &x, &y, &width, &height,\n                 &border, &depth);\n    XGetWindowAttributes(g_display, window_id, &attributes);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  x %d y %d width %d height %d border_width %d\", x, y, width,\n              height, border);\n\n    index = list_index_of(g_window_list, window_id);\n    if (index == -1)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  create new window\");\n        flags = WINDOW_ORDER_TYPE_WINDOW | WINDOW_ORDER_STATE_NEW;\n        list_add_item(g_window_list, window_id);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  update existing window\");\n        flags = WINDOW_ORDER_TYPE_WINDOW;\n    }\n\n    title_size = 0;\n    title_bytes = 0;\n\n    XGetTransientForHint(g_display, window_id, &transient_for);\n\n    if (attributes.override_redirect)\n    {\n        style = RAIL_STYLE_TOOLTIP;\n        ext_style = RAIL_EXT_STYLE_TOOLTIP;\n        /* for tooltips, we don't grab the window text */\n    }\n    else if (transient_for > 0)\n    {\n        style = RAIL_STYLE_DIALOG;\n        ext_style = RAIL_EXT_STYLE_DIALOG;\n        owner_id = transient_for;\n        title_size = rail_win_get_text(window_id, &title_bytes);\n    }\n    else\n    {\n        style = RAIL_STYLE_NORMAL;\n        ext_style = RAIL_EXT_STYLE_NORMAL;\n        title_size = rail_win_get_text(window_id, &title_bytes);\n    }\n\n    make_stream(s);\n    init_stream(s, title_size + 1024 + num_window_rects * 8 + num_visibility_rects * 8);\n\n    out_uint32_le(s, 2); /* create_window */\n    out_uint32_le(s, window_id); /* window_id */\n    out_uint32_le(s, owner_id); /* owner_window_id */\n    flags |= WINDOW_ORDER_FIELD_OWNER;\n    out_uint32_le(s, style); /* style */\n    out_uint32_le(s, ext_style); /* extended_style */\n    flags |= WINDOW_ORDER_FIELD_STYLE;\n    out_uint32_le(s, 0x05); /* show_state */\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  title %s\", title_bytes);\n    flags |= WINDOW_ORDER_FIELD_SHOW;\n    if (title_size > 0)\n    {\n        out_uint16_le(s, title_size); /* title_size */\n        out_uint8a(s, title_bytes, title_size); /* title */\n        rwd->valid |= RWD_TITLE;\n        crc = get_string_crc(title_bytes);\n        rwd->title_crc = crc;\n    }\n    else\n    {\n        out_uint16_le(s, 5); /* title_size */\n        out_uint8a(s, \"title\", 5); /* title */\n        rwd->valid |= RWD_TITLE;\n        rwd->title_crc = 0;\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  set title info %d\", title_size);\n    flags |= WINDOW_ORDER_FIELD_TITLE;\n    out_uint32_le(s, 0); /* client_offset_x */\n    out_uint32_le(s, 0); /* client_offset_y */\n    flags |= WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET;\n    out_uint32_le(s, width); /* client_area_width */\n    out_uint32_le(s, height); /* client_area_height */\n    flags |= WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE;\n    out_uint32_le(s, 0); /* rp_content */\n    out_uint32_le(s, g_root_window); /* root_parent_handle */\n    flags |= WINDOW_ORDER_FIELD_ROOT_PARENT;\n    out_uint32_le(s, x); /* window_offset_x */\n    out_uint32_le(s, y); /* window_offset_y */\n    flags |= WINDOW_ORDER_FIELD_WND_OFFSET;\n    out_uint32_le(s, 0); /* window_client_delta_x */\n    out_uint32_le(s, 0); /* window_client_delta_y */\n    flags |= WINDOW_ORDER_FIELD_WND_CLIENT_DELTA;\n    out_uint32_le(s, width); /* window_width */\n    out_uint32_le(s, height); /* window_height */\n    flags |= WINDOW_ORDER_FIELD_WND_SIZE;\n    out_uint16_le(s, num_window_rects); /* num_window_rects */\n    for (i = 0; i < num_window_rects; i++)\n    {\n        out_uint16_le(s, 0); /* left */\n        out_uint16_le(s, 0); /* top */\n        out_uint16_le(s, width); /* right */\n        out_uint16_le(s, height); /* bottom */\n    }\n    flags |= WINDOW_ORDER_FIELD_WND_RECTS;\n    out_uint32_le(s, x); /* visible_offset_x */\n    out_uint32_le(s, y); /* visible_offset_y */\n    flags |= WINDOW_ORDER_FIELD_VIS_OFFSET;\n    out_uint16_le(s, num_visibility_rects); /* num_visibility_rects */\n    for (i = 0; i < num_visibility_rects; i++)\n    {\n        out_uint16_le(s, 0); /* left */\n        out_uint16_le(s, 0); /* top */\n        out_uint16_le(s, width); /* right */\n        out_uint16_le(s, height); /* bottom */\n    }\n    flags |= WINDOW_ORDER_FIELD_VISIBILITY;\n    out_uint32_le(s, flags); /*flags*/\n\n    s_mark_end(s);\n    send_rail_drawing_orders(s->data, (int)(s->end - s->data));\n    free_stream(s);\n    g_free(title_bytes);\n    rail_set_window_data(window_id, rwd);\n    XFree(rwd);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns 0, event handled, 1 unhandled */\nstatic int\nrail_configure_request_window(XConfigureRequestEvent *config)\n{\n    int num_window_rects = 1;\n    int num_visibility_rects = 1;\n    int i = 0;\n    int flags;\n    int index;\n    int window_id;\n    int mask;\n    int resized = 0;\n    struct rail_window_data *rwd;\n\n    struct stream *s;\n\n    window_id = config->window;\n    mask = config->value_mask;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_configure_request_window: mask %d\", mask);\n    if (mask & CWStackMode)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_configure_request_window: CWStackMode \"\n                  \"detail 0x%8.8x above 0x%8.8lx\", config->detail, config->above);\n        if (config->detail == Above)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_configure_request_window: bring to front \"\n                      \"window_id 0x%8.8x\", window_id);\n            /* 0x05 - Show the window in its current size and position. */\n            rail_show_window(window_id, 5);\n        }\n    }\n    rwd = rail_get_window_data(window_id);\n    if (rwd == 0)\n    {\n        rwd = (struct rail_window_data *)g_malloc(sizeof(struct rail_window_data), 1);\n        rwd->x = config->x;\n        rwd->y = config->y;\n        rwd->width = config->width;\n        rwd->height = config->height;\n        rwd->valid |= RWD_X | RWD_Y | RWD_WIDTH | RWD_HEIGHT;\n        rail_set_window_data(window_id, rwd);\n        g_free(rwd);\n        return 0;\n    }\n    if (!resized)\n    {\n        if (mask & CWX)\n        {\n            if (rwd->valid & RWD_X)\n            {\n                if (rwd->x != config->x)\n                {\n                    resized = 1;\n                    rwd->x = config->x;\n                }\n            }\n            else\n            {\n                resized = 1;\n                rwd->x = config->x;\n                rwd->valid |= RWD_X;\n            }\n        }\n    }\n    if (!resized)\n    {\n        if (mask & CWY)\n        {\n            if (rwd->valid & RWD_Y)\n            {\n                if (rwd->y != config->y)\n                {\n                    resized = 1;\n                    rwd->y = config->y;\n                }\n            }\n            else\n            {\n                resized = 1;\n                rwd->y = config->y;\n                rwd->valid |= RWD_Y;\n            }\n        }\n    }\n    if (!resized)\n    {\n        if (mask & CWWidth)\n        {\n            if (rwd->valid & RWD_WIDTH)\n            {\n                if (rwd->width != config->width)\n                {\n                    resized = 1;\n                    rwd->width = config->width;\n                }\n            }\n            else\n            {\n                resized = 1;\n                rwd->width = config->width;\n                rwd->valid |= RWD_WIDTH;\n            }\n        }\n    }\n    if (!resized)\n    {\n        if (mask & CWHeight)\n        {\n            if (rwd->valid & RWD_HEIGHT)\n            {\n                if (rwd->height != config->height)\n                {\n                    resized = 1;\n                    rwd->height = config->height;\n                }\n            }\n            else\n            {\n                resized = 1;\n                rwd->height = config->height;\n                rwd->valid |= RWD_HEIGHT;\n            }\n        }\n    }\n    if (resized)\n    {\n        rail_set_window_data(window_id, rwd);\n        XFree(rwd);\n    }\n    else\n    {\n        XFree(rwd);\n        return 0;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_configure_request_window: 0x%8.8x\", window_id);\n\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  x %d y %d width %d height %d border_width %d\", config->x,\n              config->y, config->width, config->height, config->border_width);\n\n    index = list_index_of(g_window_list, window_id);\n    if (index == -1)\n    {\n        /* window isn't mapped yet */\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"chansrv::rail_configure_request_window: window not mapped\");\n        return 0;\n    }\n\n    flags = WINDOW_ORDER_TYPE_WINDOW;\n\n    make_stream(s);\n    init_stream(s, 1024 + num_window_rects * 8 + num_visibility_rects * 8);\n\n    out_uint32_le(s, 10); /* configure_window */\n    out_uint32_le(s, window_id); /* window_id */\n\n    out_uint32_le(s, 0); /* client_offset_x */\n    out_uint32_le(s, 0); /* client_offset_y */\n    flags |= WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET;\n    out_uint32_le(s, config->width); /* client_area_width */\n    out_uint32_le(s, config->height); /* client_area_height */\n    flags |= WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE;\n    out_uint32_le(s, 0); /* rp_content */\n    out_uint32_le(s, g_root_window); /* root_parent_handle */\n    flags |= WINDOW_ORDER_FIELD_ROOT_PARENT;\n    out_uint32_le(s, config->x); /* window_offset_x */\n    out_uint32_le(s, config->y); /* window_offset_y */\n    flags |= WINDOW_ORDER_FIELD_WND_OFFSET;\n    out_uint32_le(s, 0); /* window_client_delta_x */\n    out_uint32_le(s, 0); /* window_client_delta_y */\n    flags |= WINDOW_ORDER_FIELD_WND_CLIENT_DELTA;\n    out_uint32_le(s, config->width); /* window_width */\n    out_uint32_le(s, config->height); /* window_height */\n    flags |= WINDOW_ORDER_FIELD_WND_SIZE;\n    out_uint16_le(s, num_window_rects); /* num_window_rects */\n    for (i = 0; i < num_window_rects; i++)\n    {\n        out_uint16_le(s, 0); /* left */\n        out_uint16_le(s, 0); /* top */\n        out_uint16_le(s, config->width); /* right */\n        out_uint16_le(s, config->height); /* bottom */\n    }\n    flags |= WINDOW_ORDER_FIELD_WND_RECTS;\n    out_uint32_le(s, config->x); /* visible_offset_x */\n    out_uint32_le(s, config->y); /* visible_offset_y */\n    flags |= WINDOW_ORDER_FIELD_VIS_OFFSET;\n    out_uint16_le(s, num_visibility_rects); /* num_visibility_rects */\n    for (i = 0; i < num_visibility_rects; i++)\n    {\n        out_uint16_le(s, 0); /* left */\n        out_uint16_le(s, 0); /* top */\n        out_uint16_le(s, config->width); /* right */\n        out_uint16_le(s, config->height); /* bottom */\n    }\n    flags |= WINDOW_ORDER_FIELD_VISIBILITY;\n    out_uint32_le(s, flags); /*flags*/\n\n    s_mark_end(s);\n    send_rail_drawing_orders(s->data, (int)(s->end - s->data));\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n#if 0\n/* returns 0, event handled, 1 unhandled */\nstatic int\nrail_configure_window(XConfigureEvent *config)\n{\n    int num_window_rects = 1;\n    int num_visibility_rects = 1;\n    int i = 0;\n    int flags;\n    int index;\n    int window_id;\n\n    struct stream *s;\n\n    window_id = config->window;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_configure_window 0x%8.8x\", window_id);\n\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  x %d y %d width %d height %d border_width %d\", config->x,\n              config->y, config->width, config->height, config->border_width);\n\n    index = list_index_of(g_window_list, window_id);\n    if (index == -1)\n    {\n        /* window isn't mapped yet */\n        return 0;\n    }\n\n    flags = WINDOW_ORDER_TYPE_WINDOW;\n\n    make_stream(s);\n    init_stream(s, 1024 + num_window_rects * 8 + num_visibility_rects * 8);\n\n    out_uint32_le(s, 10); /* configure_window */\n    out_uint32_le(s, window_id); /* window_id */\n\n    out_uint32_le(s, 0); /* client_offset_x */\n    out_uint32_le(s, 0); /* client_offset_y */\n    flags |= WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET;\n    out_uint32_le(s, config->width); /* client_area_width */\n    out_uint32_le(s, config->height); /* client_area_height */\n    flags |= WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE;\n    out_uint32_le(s, 0); /* rp_content */\n    out_uint32_le(s, g_root_window); /* root_parent_handle */\n    flags |= WINDOW_ORDER_FIELD_ROOT_PARENT;\n    out_uint32_le(s, config->x); /* window_offset_x */\n    out_uint32_le(s, config->y); /* window_offset_y */\n    flags |= WINDOW_ORDER_FIELD_WND_OFFSET;\n    out_uint32_le(s, 0); /* window_client_delta_x */\n    out_uint32_le(s, 0); /* window_client_delta_y */\n    flags |= WINDOW_ORDER_FIELD_WND_CLIENT_DELTA;\n    out_uint32_le(s, config->width); /* window_width */\n    out_uint32_le(s, config->height); /* window_height */\n    flags |= WINDOW_ORDER_FIELD_WND_SIZE;\n    out_uint16_le(s, num_window_rects); /* num_window_rects */\n    for (i = 0; i < num_window_rects; i++)\n    {\n        out_uint16_le(s, 0); /* left */\n        out_uint16_le(s, 0); /* top */\n        out_uint16_le(s, config->width); /* right */\n        out_uint16_le(s, config->height); /* bottom */\n    }\n    flags |= WINDOW_ORDER_FIELD_WND_RECTS;\n    out_uint32_le(s, config->x); /* visible_offset_x */\n    out_uint32_le(s, config->y); /* visible_offset_y */\n    flags |= WINDOW_ORDER_FIELD_VIS_OFFSET;\n    out_uint16_le(s, num_visibility_rects); /* num_visibility_rects */\n    for (i = 0; i < num_visibility_rects; i++)\n    {\n        out_uint16_le(s, 0); /* left */\n        out_uint16_le(s, 0); /* top */\n        out_uint16_le(s, config->width); /* right */\n        out_uint16_le(s, config->height); /* bottom */\n    }\n    flags |= WINDOW_ORDER_FIELD_VISIBILITY;\n    out_uint32_le(s, flags); /*flags*/\n\n    s_mark_end(s);\n    send_rail_drawing_orders(s->data, (int)(s->end - s->data));\n    free_stream(s);\n    return 0;\n}\n#endif\n\n/*****************************************************************************/\nstatic int\nrail_desktop_resize(XEvent *lxevent)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"rail_desktop_resize:\");\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns 0, event handled, 1 unhandled */\nint\nrail_xevent(void *xevent)\n{\n    XEvent *lxevent;\n    XEvent lastevent;\n    XWindowChanges xwc;\n    int rv;\n    int index;\n    XWindowAttributes wnd_attributes;\n    char *prop_name;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"chansrv::rail_xevent:\");\n\n    if (!g_rail_up)\n    {\n        return 1;\n    }\n\n    rv = 1;\n    lxevent = (XEvent *)xevent;\n\n    switch (lxevent->type)\n    {\n        case PropertyNotify:\n            prop_name = XGetAtomName(g_display, lxevent->xproperty.atom);\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got PropertyNotify window_id 0x%8.8lx %s state new %d\",\n                      lxevent->xproperty.window, prop_name,\n                      lxevent->xproperty.state == PropertyNewValue);\n\n            if (list_index_of(g_window_list, lxevent->xproperty.window) < 0)\n            {\n                break;\n            }\n\n            if (g_strcmp(prop_name, \"WM_NAME\") == 0 ||\n                    g_strcmp(prop_name, \"_NET_WM_NAME\") == 0)\n            {\n                XGetWindowAttributes(g_display, lxevent->xproperty.window, &wnd_attributes);\n                if (wnd_attributes.map_state == IsViewable)\n                {\n                    rail_win_send_text(lxevent->xproperty.window);\n                    rv = 0;\n                }\n            }\n            XFree(prop_name);\n            break;\n\n        case ConfigureRequest:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got ConfigureRequest window_id 0x%8.8lx\", lxevent->xconfigurerequest.window);\n            g_memset(&xwc, 0, sizeof(xwc));\n            xwc.x = lxevent->xconfigurerequest.x;\n            xwc.y = lxevent->xconfigurerequest.y;\n            xwc.width = lxevent->xconfigurerequest.width;\n            xwc.height = lxevent->xconfigurerequest.height;\n            xwc.border_width = lxevent->xconfigurerequest.border_width;\n            xwc.sibling = lxevent->xconfigurerequest.above;\n            xwc.stack_mode = lxevent->xconfigurerequest.detail;\n            XConfigureWindow(g_display,\n                             lxevent->xconfigurerequest.window,\n                             lxevent->xconfigurerequest.value_mask,\n                             &xwc);\n            rail_configure_request_window(&(lxevent->xconfigurerequest));\n            rv = 0;\n            break;\n\n        case CreateNotify:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \" got CreateNotify window 0x%8.8lx parent 0x%8.8lx\",\n                      lxevent->xcreatewindow.window, lxevent->xcreatewindow.parent);\n            rail_select_input(lxevent->xcreatewindow.window);\n            break;\n\n        case DestroyNotify:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got DestroyNotify window 0x%8.8lx event 0x%8.8lx\",\n                      lxevent->xdestroywindow.window, lxevent->xdestroywindow.event);\n            if (lxevent->xdestroywindow.window != lxevent->xdestroywindow.event)\n            {\n                break;\n            }\n            index = list_index_of(g_window_list, lxevent->xdestroywindow.window);\n            if (index >= 0)\n            {\n                rail_destroy_window(lxevent->xdestroywindow.window);\n                list_remove_item(g_window_list, index);\n            }\n            rv = 0;\n            break;\n\n        case MapRequest:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got MapRequest window 0x%8.8lx\", lxevent->xmaprequest.window);\n            XMapWindow(g_display, lxevent->xmaprequest.window);\n            break;\n\n        case MapNotify:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got MapNotify window 0x%8.8lx event 0x%8.8lx\",\n                      lxevent->xmap.window, lxevent->xmap.event);\n            if (lxevent->xmap.window != lxevent->xmap.event)\n            {\n                break;\n            }\n\n            if (!is_window_valid_child_of_root(lxevent->xmap.window))\n            {\n                break;\n            }\n\n            XGetWindowAttributes(g_display, lxevent->xmap.window, &wnd_attributes);\n            if (wnd_attributes.map_state == IsViewable)\n            {\n                rail_create_window(lxevent->xmap.window, g_root_window);\n                if (!wnd_attributes.override_redirect)\n                {\n                    rail_win_set_state(lxevent->xmap.window, 0x1); /* NormalState */\n                    rail_win_send_text(lxevent->xmap.window);\n                }\n                rv = 0;\n            }\n            break;\n\n        case UnmapNotify:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got UnmapNotify 0x%8.8lx\", lxevent->xunmap.event);\n            if (lxevent->xunmap.window != lxevent->xunmap.event)\n            {\n                break;\n            }\n            if (is_window_valid_child_of_root(lxevent->xunmap.window))\n            {\n                index = list_index_of(g_window_list, lxevent->xunmap.window);\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"  window 0x%8.8lx is unmapped\", lxevent->xunmap.window);\n                if (index >= 0)\n                {\n                    XGetWindowAttributes(g_display, lxevent->xunmap.window, &wnd_attributes);\n                    if (wnd_attributes.override_redirect)\n                    {\n                        // remove popups\n                        rail_destroy_window(lxevent->xunmap.window);\n                        list_remove_item(g_window_list, index);\n                    }\n                    else\n                    {\n                        rail_show_window(lxevent->xunmap.window, 0x0);\n                    }\n\n                    rv = 0;\n                }\n            }\n            break;\n\n        case ConfigureNotify:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got ConfigureNotify 0x%8.8lx event 0x%8.8lx\", lxevent->xconfigure.window,\n                      lxevent->xconfigure.event);\n            rv = 0;\n            if (lxevent->xconfigure.event != lxevent->xconfigure.window ||\n                    lxevent->xconfigure.override_redirect)\n            {\n                break;\n            }\n            /* skip dup ConfigureNotify */\n            while (XCheckTypedWindowEvent(g_display,\n                                          lxevent->xconfigure.window,\n                                          ConfigureNotify, &lastevent))\n            {\n                if (lastevent.xconfigure.event == lastevent.xconfigure.window &&\n                        lxevent->xconfigure.override_redirect == 0)\n                {\n                    lxevent = &lastevent;\n                }\n            }\n#if 0\n            rail_configure_window(&(lxevent->xconfigure));\n#endif\n            break;\n\n        case FocusIn:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got FocusIn\");\n            g_focus_win = lxevent->xfocus.window;\n            break;\n\n        case FocusOut:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got FocusOut\");\n            break;\n\n        case ButtonPress:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got ButtonPress\");\n            break;\n\n        case EnterNotify:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got EnterNotify\");\n            break;\n\n        case LeaveNotify:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got LeaveNotify\");\n            break;\n\n        case ReparentNotify:\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  got ReparentNotify window 0x%8.8lx parent 0x%8.8lx \"\n                      \"event 0x%8.8lx x %d y %d override redirect %d\",\n                      lxevent->xreparent.window, lxevent->xreparent.parent,\n                      lxevent->xreparent.event, lxevent->xreparent.x,\n                      lxevent->xreparent.y, lxevent->xreparent.override_redirect);\n\n            if (lxevent->xreparent.window != lxevent->xreparent.event)\n            {\n                break;\n            }\n            if (lxevent->xreparent.parent != g_root_window)\n            {\n                index = list_index_of(g_window_list, lxevent->xreparent.window);\n                if (index >= 0)\n                {\n                    rail_destroy_window(lxevent->xreparent.window);\n                    list_remove_item(g_window_list, index);\n                }\n            }\n            rv = 0;\n            break;\n\n        default:\n            if (g_xrr_event_base > 0)\n            {\n                if (lxevent->type == g_xrr_event_base + RRScreenChangeNotify)\n                {\n                    rail_desktop_resize(lxevent);\n                    rv = 0;\n                    break;\n                }\n            }\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "sesman/chansrv/rail.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _RAIL_H_\n#define _RAIL_H_\n\n#include \"../../common/rail.h\"\n#include \"arch.h\"\n#include \"parse.h\"\n\nint\nrail_init(void);\nint\nrail_deinit(void);\nint\nrail_data_in(struct stream *s, int chan_id, int chan_flags,\n             int length, int total_length);\nint\nrail_xevent(void *xevent);\nint rail_request_title(int window_id);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/smartcard.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n * Copyright (C) Jay Sorg 2013 jay.sorg@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file sesman/chansrv/smartcard.c\n *\n * smartcard redirection support\n *\n * This file implements some of the PDUs detailed in [MS-RDPESC].\n *\n * The PDUs use DCE IDL structs. These are required to be re-interpreted\n * in DCE NDR (Netword Data Representation)\n *\n * For more information on this subject see DCE publication C706\n * \"DCE 1.1: Remote Procedure Call\" 1997. In particular:-\n * Section 4.2 : Describes the IDL\n * Section 14 : Describes the NDR\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <string.h>\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"smartcard.h\"\n#include \"smartcard_internal.h\"\n#include \"log.h\"\n#include \"irp.h\"\n#include \"devredir.h\"\n#include \"smartcard_pcsc.h\"\n#include \"chansrv.h\"\n\n/*\n * TODO\n *\n * o ensure that all wide calls are handled correctly\n *\n * o need to query client for build number and determine whether we should use\n *   SCREDIR_VERSION_XP or SCREDIR_VERSION_LONGHORN\n *\n * o need to call scard_release_resources()\n *\n * o why is win 7 sending SCARD_IOCTL_ACCESS_STARTED_EVENT first\n * 0000 00 01 00 00 04 00 00 00 e0 00 09 00 00 00 00 00 ................\n * 0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................\n * 0020 28 b7 9d 02\n */\n\n/*\n * Notes:\n *\n * XP and Server 2003 use version    SCREDIR_VERSION_XP       functions 5 - 58\n * Vista and Server 2008 use version SCREDIR_VERSION_LONGHORN functions 5 - 64\n * if TS Client's build number is >= 4,034 use SCREDIR_VERSION_LONGHORN\n */\n\n/* [MS-RDPESC] 3.1.4 */\n#define SCARD_IOCTL_ESTABLISH_CONTEXT        0x00090014 /* EstablishContext     */\n#define SCARD_IOCTL_RELEASE_CONTEXT          0x00090018 /* ReleaseContext       */\n#define SCARD_IOCTL_IS_VALID_CONTEXT         0x0009001C /* IsValidContext       */\n#define SCARD_IOCTL_LIST_READER_GROUPS       0x00090020 /* ListReaderGroups     */\n#define SCARD_IOCTL_LIST_READERS_A           0x00090028 /* ListReaders ASCII    */\n#define SCARD_IOCTL_LIST_READERS_W           0x0009002C /* ListReaders Wide     */\n#define SCARD_IOCTL_INTRODUCE_READER_GROUP   0x00090050 /* IntroduceReaderGroup */\n#define SCARD_IOCTL_FORGET_READER_GROUP      0x00090058 /* ForgetReader         */\n#define SCARD_IOCTL_INTRODUCE_READER         0x00090060 /* IntroduceReader      */\n#define SCARD_IOCTL_FORGET_READER            0x00090068 /* IntroduceReader      */\n#define SCARD_IOCTL_ADD_READER_TO_GROUP      0x00090070 /* AddReaderToGroup     */\n#define SCARD_IOCTL_REMOVE_READER_FROM_GROUP 0x00090078 /* RemoveReaderFromGroup*/\n#define SCARD_IOCTL_GET_STATUS_CHANGE_A      0x000900A0 /* GetStatusChangeA     */\n#define SCARD_IOCTL_GET_STATUS_CHANGE_W      0x000900A4 /* GetStatusChangeW     */\n#define SCARD_IOCTL_CANCEL                   0x000900A8 /* Cancel               */\n#define SCARD_IOCTL_CONNECT_A                0x000900AC /* ConnectA             */\n#define SCARD_IOCTL_CONNECT_W                0x000900B0 /* ConnectW             */\n#define SCARD_IOCTL_RECONNECT                0x000900B4 /* Reconnect            */\n#define SCARD_IOCTL_DISCONNECT               0x000900B8 /* Disconnect           */\n#define SCARD_IOCTL_BEGIN_TRANSACTION        0x000900BC /* BeginTransaction     */\n#define SCARD_IOCTL_END_TRANSACTION          0x000900C0 /* EndTransaction       */\n#define SCARD_IOCTL_STATE                    0x000900C4 /* State                */\n#define SCARD_IOCTL_STATUS_A                 0x000900C8 /* StatusA              */\n#define SCARD_IOCTL_STATUS_W                 0x000900CC /* StatusW              */\n#define SCARD_IOCTL_TRANSMIT                 0x000900D0 /* Transmit             */\n#define SCARD_IOCTL_CONTROL                  0x000900D4 /* Control              */\n#define SCARD_IOCTL_GETATTRIB                0x000900D8 /* GetAttrib            */\n#define SCARD_IOCTL_SETATTRIB                0x000900DC /* SetAttrib            */\n#define SCARD_IOCTL_ACCESS_STARTED_EVENT     0x000900E0 /* SCardAccessStartedEvent */\n#define SCARD_IOCTL_LOCATE_CARDS_BY_ATR      0x000900E8 /* LocateCardsByATR     */\n\n/* scope used in EstablishContextCall */\n#define SCARD_SCOPE_USER                     0x00000000\n#define SCARD_SCOPE_TERMINAL                 0x00000001\n#define SCARD_SCOPE_SYSTEM                   0x00000002\n\n/* disposition - action to take on card */\n#define SCARD_LEAVE_CARD                     0x00000000\n#define SCARD_RESET_CARD                     0x00000001\n#define SCARD_UNPOWER_CARD                   0x00000002\n#define SCARD_EJECT_CARD                     0x00000003\n\n#define MAX_SMARTCARDS                       16\n\n/* stores info about a smart card */\ntypedef struct smartcard\n{\n    tui32 DeviceId;\n} SMARTCARD;\n\n/* globals */\nSMARTCARD   *smartcards[MAX_SMARTCARDS];\nint          g_smartcards_inited = 0;\nstatic tui32 g_device_id = 0;\nstatic int   g_scard_index = 0;\n\n/* externs */\nextern tui32 g_completion_id;\nextern int   g_rdpdr_chan_id;    /* in chansrv.c */\n\n\n/******************************************************************************\n**                   static functions local to this file                     **\n******************************************************************************/\nstatic struct stream *scard_make_new_ioctl(IRP *irp, tui32 ioctl);\nstatic int  scard_add_new_device(tui32 device_id);\nstatic int  scard_get_free_slot(void);\nstatic void scard_release_resources(void);\nstatic void scard_send_EstablishContext(IRP *irp, int scope);\nstatic void scard_send_ReleaseContext(IRP *irp,\n                                      char *context, int context_bytes);\nstatic void scard_send_IsContextValid(IRP *irp,\n                                      char *context, int context_bytes);\nstatic void scard_send_ListReaders(IRP *irp,\n                                   char *context, int context_bytes,\n                                   char *groups, int cchReaders,\n                                   int wide);\nstatic void scard_send_GetStatusChange(IRP *irp,\n                                       char *context, int context_bytes,\n                                       int wide,\n                                       tui32 timeout, tui32 num_readers,\n                                       READER_STATE *rsa);\nstatic void scard_send_Connect(IRP *irp,\n                               char *context, int context_bytes,\n                               int wide,\n                               READER_STATE *rs);\nstatic void scard_send_Reconnect(IRP *irp,\n                                 char *context, int context_bytes,\n                                 char *card, int card_bytes,\n                                 READER_STATE *rs);\nstatic void scard_send_BeginTransaction(IRP *irp,\n                                        char *context, int context_bytes,\n                                        char *card, int card_bytes);\nstatic void scard_send_EndTransaction(IRP *irp,\n                                      char *context, int context_bytes,\n                                      char *card, int card_bytes,\n                                      tui32 dwDisposition);\nstatic void scard_send_Status(IRP *irp, int wide,\n                              char *context, int context_bytes,\n                              char *card, int card_bytes,\n                              int cchReaderLen, int cbAtrLen);\nstatic void scard_send_Disconnect(IRP *irp,\n                                  char *context, int context_bytes,\n                                  char *card, int card_bytes,\n                                  int dwDisposition);\nstatic int  scard_send_Transmit(IRP *irp,\n                                char *context, int context_byte,\n                                char *card, int card_bytes,\n                                char *send_data, int send_bytes,\n                                int recv_bytes,\n                                struct xrdp_scard_io_request *send_ior,\n                                struct xrdp_scard_io_request *recv_ior);\nstatic int scard_send_Control(IRP *irp, char *context, int context_bytes,\n                              char *card, int card_bytes,\n                              char *send_data, int send_bytes,\n                              int recv_bytes, int control_code);\nstatic int scard_send_Cancel(IRP *irp, char *context, int context_bytes);\nstatic int scard_send_GetAttrib(IRP *irp, char *card, int card_bytes,\n                                READER_STATE *rs);\n\n/******************************************************************************\n**                    local callbacks into this module                       **\n******************************************************************************/\n\nstatic void scard_handle_EstablishContext_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId, tui32 CompletionId,\n        tui32 IoStatus);\n\nstatic void scard_handle_ReleaseContext_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId, tui32 CompletionId,\n        tui32 IoStatus);\n\n\nstatic void scard_handle_IsContextValid_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId, tui32 CompletionId,\n        tui32 IoStatus);\n\nstatic void scard_handle_ListReaders_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId, tui32 CompletionId,\n        tui32 IoStatus);\n\nstatic void scard_handle_GetStatusChange_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId, tui32 CompletionId,\n        tui32 IoStatus);\n\nstatic void scard_handle_Connect_Return(struct stream *s, IRP *irp,\n                                        tui32 DeviceId, tui32 CompletionId,\n                                        tui32 IoStatus);\n\nstatic void scard_handle_Reconnect_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId, tui32 CompletionId,\n        tui32 IoStatus);\n\nstatic void scard_handle_BeginTransaction_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId, tui32 CompletionId,\n        tui32 IoStatus);\n\nstatic void scard_handle_EndTransaction_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId,\n        tui32 CompletionId,\n        tui32 IoStatus);\n\nstatic void scard_handle_Status_Return(struct stream *s, IRP *irp,\n                                       tui32 DeviceId, tui32 CompletionId,\n                                       tui32 IoStatus);\n\nstatic void scard_handle_Disconnect_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId, tui32 CompletionId,\n        tui32 IoStatus);\n\n\nstatic void scard_handle_Transmit_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId,\n        tui32 CompletionId,\n        tui32 IoStatus);\n\nstatic void scard_handle_Control_Return(struct stream *s, IRP *irp,\n                                        tui32 DeviceId,\n                                        tui32 CompletionId,\n                                        tui32 IoStatus);\n\nstatic void scard_handle_Cancel_Return(struct stream *s, IRP *irp,\n                                       tui32 DeviceId,\n                                       tui32 CompletionId,\n                                       tui32 IoStatus);\n\nstatic void scard_handle_GetAttrib_Return(struct stream *s, IRP *irp,\n        tui32 DeviceId,\n        tui32 CompletionId,\n        tui32 IoStatus);\n\n/******************************************************************************\n**                                                                           **\n**          externally accessible functions, defined in smartcard.h          **\n**                                                                           **\n******************************************************************************/\n\n/**\n *****************************************************************************/\nint\nscard_device_announce(tui32 device_id)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered: device_id=%d\", device_id);\n    int rv;\n\n    if (g_smartcards_inited)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"already init\");\n        rv = (device_id == g_device_id) ? 0 : 1;\n    }\n    else\n    {\n        g_memset(&smartcards, 0, sizeof(smartcards));\n        g_smartcards_inited = 1;\n        g_scard_index = scard_add_new_device(device_id);\n\n        if (g_scard_index < 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_add_new_device failed with DeviceId=%d\", g_device_id);\n            rv = 1;\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"added smartcard with DeviceId=%d to list\", g_device_id);\n            g_device_id = device_id;\n            rv = 0;\n        }\n    }\n    return rv;\n}\n\n/**\n *\n *****************************************************************************/\nint\nscard_get_wait_objs(tbus *objs, int *count, int *timeout)\n{\n    return scard_pcsc_get_wait_objs(objs, count, timeout);\n}\n\n/**\n *\n *****************************************************************************/\nint\nscard_check_wait_objs(void)\n{\n    return scard_pcsc_check_wait_objs();\n}\n\n/**\n *\n *****************************************************************************/\nint\nscard_init(void)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"scard_init:\");\n    return scard_pcsc_init();\n}\n\n/**\n *\n *****************************************************************************/\nint\nscard_deinit(void)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"scard_deinit:\");\n    scard_pcsc_deinit();\n    scard_release_resources();\n    g_smartcards_inited = 0;\n    return 0;\n}\n\n/**\n *\n *****************************************************************************/\nint\nscard_send_establish_context(void *user_data, int scope)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_EstablishContext_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_EstablishContext(irp, scope);\n\n    return 0;\n}\n\n/**\n * Release a previously established Smart Card context\n *****************************************************************************/\nint\nscard_send_release_context(void *user_data,\n                           char *context, int context_bytes)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_ReleaseContext_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_ReleaseContext(irp, context, context_bytes);\n\n    return 0;\n}\n\n/**\n * Checks if a previously established context is still valid\n *****************************************************************************/\nint\nscard_send_is_valid_context(void *user_data, char *context, int context_bytes)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_IsContextValid_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_IsContextValid(irp, context, context_bytes);\n\n    return 0;\n}\n\n/**\n *\n *****************************************************************************/\nint\nscard_send_list_readers(void *user_data, char *context, int context_bytes,\n                        char *groups, int cchReaders, int wide)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_ListReaders_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_ListReaders(irp, context, context_bytes, groups,\n                           cchReaders, wide);\n\n    return 0;\n}\n\n/**\n * Send get change in status command\n *\n * @param  wide         TRUE if unicode string\n * @param  timeout      timeout in milliseconds, -1 for infinity\n * @param  num_readers  number of entries in rsa\n * @param  rsa          array of READER_STATEs\n *****************************************************************************/\nint\nscard_send_get_status_change(void *user_data, char *context, int context_bytes,\n                             int wide, tui32 timeout, tui32 num_readers,\n                             READER_STATE *rsa)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_GetStatusChange_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_GetStatusChange(irp, context, context_bytes, wide, timeout,\n                               num_readers, rsa);\n\n    return 0;\n}\n\n/**\n * Open a connection to the smart card located in the reader\n *\n * @param  wide  TRUE if unicode string\n *****************************************************************************/\nint\nscard_send_connect(void *user_data, char *context, int context_bytes,\n                   int wide, READER_STATE *rs)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_Connect_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_Connect(irp, context, context_bytes, wide, rs);\n\n    return 0;\n}\n\n/**\n * The reconnect method re-establishes a smart card reader handle. On success,\n * the handle is valid once again.\n *\n * @param  rs         reader state where following fields are set\n *                        rs.shared_mode_flag\n *                        rs.preferred_protocol\n *                        rs.init_type\n *****************************************************************************/\nint\nscard_send_reconnect(void *user_data, char *context, int context_bytes,\n                     char *card, int card_bytes, READER_STATE *rs)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_Reconnect_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_Reconnect(irp, context, context_bytes, card, card_bytes, rs);\n\n    return 0;\n}\n\n/**\n * Lock smart card reader for exclusive access for specified smart\n * card reader handle.\n *\n *****************************************************************************/\nint\nscard_send_begin_transaction(void *user_data, char *context, int context_bytes,\n                             char *card, int card_bytes)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_BeginTransaction_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_BeginTransaction(irp, context, context_bytes, card, card_bytes);\n\n    return 0;\n}\n\n/**\n * Release a smart card reader after being locked by a previously\n * successful call to Begin Transaction\n *\n *****************************************************************************/\nint\nscard_send_end_transaction(void *user_data, char *context, int context_bytes,\n                           char *card, int card_bytes,\n                           tui32 dwDisposition)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_EndTransaction_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_EndTransaction(irp, context, context_bytes,\n                              card, card_bytes, dwDisposition);\n\n    return 0;\n}\n\n/**\n * Get the status of a connection for a valid smart card reader handle\n *\n * @param  wide  TRUE if unicode string\n *****************************************************************************/\nint\nscard_send_status(void *user_data, int wide, char *context, int context_bytes,\n                  char *card, int card_bytes,\n                  int cchReaderLen, int cbAtrLen)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_Status_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_Status(irp, wide, context, context_bytes, card, card_bytes,\n                      cchReaderLen, cbAtrLen);\n\n    return 0;\n}\n\n/**\n * Release a smart card reader handle that was acquired in ConnectA/ConnectW\n *\n *****************************************************************************/\nint\nscard_send_disconnect(void *user_data, char *context, int context_bytes,\n                      char *card, int card_bytes, int dwDisposition)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_Disconnect_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_Disconnect(irp, context, context_bytes,\n                          card, card_bytes, dwDisposition);\n\n    return 0;\n}\n\n/**\n * The Transmit_Call structure is used to send data to the smart card\n * associated with a valid context.\n *****************************************************************************/\nint\nscard_send_transmit(void *user_data, char *context, int context_bytes,\n                    char *card, int card_bytes,\n                    char *send_data, int send_bytes, int recv_bytes,\n                    struct xrdp_scard_io_request *send_ior,\n                    struct xrdp_scard_io_request *recv_ior)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_Transmit_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_Transmit(irp, context, context_bytes, card, card_bytes,\n                        send_data, send_bytes,\n                        recv_bytes, send_ior, recv_ior);\n\n    return 0;\n}\n\n/**\n * Communicate directly with the smart card reader\n *****************************************************************************/\nint\nscard_send_control(void *user_data, char *context, int context_bytes,\n                   char *card, int card_bytes,\n                   char *send_data, int send_bytes,\n                   int recv_bytes, int control_code)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_Control_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_Control(irp, context, context_bytes,\n                       card, card_bytes,\n                       send_data, send_bytes,\n                       recv_bytes, control_code);\n\n    return 0;\n}\n\n/**\n * Cancel any outstanding calls\n *****************************************************************************/\nint\nscard_send_cancel(void *user_data, char *context, int context_bytes)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_Cancel_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_Cancel(irp, context, context_bytes);\n\n    return 0;\n}\n\n/**\n * Get reader attributes\n *****************************************************************************/\nint\nscard_send_get_attrib(void *user_data, char *card, int card_bytes,\n                      READER_STATE *rs)\n{\n    IRP *irp;\n\n    /* setup up IRP */\n    if ((irp = devredir_irp_new()) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return 1;\n    }\n\n    irp->scard_index = g_scard_index;\n    irp->CompletionId = g_completion_id++;\n    irp->DeviceId = g_device_id;\n    irp->callback = scard_handle_GetAttrib_Return;\n    irp->user_data = user_data;\n\n    /* send IRP to client */\n    scard_send_GetAttrib(irp, card, card_bytes, rs);\n\n    return 0;\n}\n\n/******************************************************************************\n**                                                                           **\n**                   static functions local to this file                     **\n**                                                                           **\n******************************************************************************/\n\n/**\n * Create a new stream and insert specified IOCTL\n *\n * @param  irp    information about the I/O\n * @param  ioctl  the IOCTL code\n *\n * @return stream with IOCTL inserted in it, NULL on error\n *****************************************************************************/\nstatic struct stream *\nscard_make_new_ioctl(IRP *irp, tui32 ioctl)\n{\n    /*\n     * format of device control request\n     *\n     * DeviceIoRequest\n     * u16       RDPDR_CTYP_CORE\n     * u16       PAKID_CORE_DEVICE_IOREQUEST\n     * u32       DeviceId\n     * u32       FileId\n     * u32       CompletionId\n     * u32       MajorFunction\n     * u32       MinorFunction\n     *\n     * u32       OutputBufferLength SHOULD be 2048\n     * u32       InputBufferLength\n     * u32       IoControlCode\n     * 20 bytes  padding\n     * xx bytes  InputBuffer (variable)\n     */\n\n    struct stream *s;\n\n    xstream_new(s, 1024 * 4);\n\n    devredir_insert_DeviceIoRequest(s,\n                                    irp->DeviceId,\n                                    irp->FileId,\n                                    irp->CompletionId,\n                                    IRP_MJ_DEVICE_CONTROL,\n                                    IRP_MN_NONE);\n\n    xstream_wr_u32_le(s, 2048);        /* OutputBufferLength               */\n    s_push_layer(s, iso_hdr, 4);       /* InputBufferLength - insert later */\n    xstream_wr_u32_le(s, ioctl);       /* Ioctl Code                       */\n    out_uint8s(s, 20);                 /* padding                          */\n\n    /* [MS-RPCE] 2.2.6.1 */\n    xstream_wr_u32_le(s, 0x00081001);  /* len 8, LE, v1                    */\n    xstream_wr_u32_le(s, 0xcccccccc);  /* filler                           */\n\n    return s;\n}\n\n/**\n * Create a new smart card device entry and insert it into smartcards[]\n *\n * @param  device_id  DeviceId of new card\n *\n * @return index into smartcards[] on success, -1 on failure\n *****************************************************************************/\nstatic int\nscard_add_new_device(tui32 device_id)\n{\n    int        index;\n    SMARTCARD *sc;\n\n    if ((index = scard_get_free_slot()) < 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_get_free_slot failed\");\n        return -1;\n    }\n\n    sc = g_new0(SMARTCARD, 1);\n    if (sc == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"system out of memory\");\n        return -1;\n    }\n\n    sc->DeviceId = device_id;\n    smartcards[index] = sc;\n\n    return index;\n}\n\n/**\n * Find first unused entry in smartcards\n *\n * @return index of first unused entry in smartcards or -1 if smartcards\n * is full\n *****************************************************************************/\nstatic int\nscard_get_free_slot(void)\n{\n    int i;\n\n    for (i = 0; i < MAX_SMARTCARDS; i++)\n    {\n        if (smartcards[i] == NULL)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"found free slot at index %d\", i);\n            return i;\n        }\n    }\n\n    LOG_DEVEL(LOG_LEVEL_ERROR, \"too many smart card devices; rejecting this one\");\n    return -1;\n}\n\n/**\n * Release resources prior to shutting down\n *****************************************************************************/\nstatic void\nscard_release_resources(void)\n{\n    int i;\n\n    for (i = 0; i < MAX_SMARTCARDS; i++)\n    {\n        if (smartcards[i] != NULL)\n        {\n            g_free(smartcards[i]);\n            smartcards[i] = NULL;\n        }\n    }\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_send_EstablishContext(IRP *irp, int scope)\n{\n    struct stream *s;\n    int            bytes;\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_ESTABLISH_CONTEXT)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    out_uint32_le(s, scope);\n    out_uint32_le(s, 0x00000000);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n}\n\n/**\n * Release a previously established Smart Card context\n *****************************************************************************/\nstatic void\nscard_send_ReleaseContext(IRP *irp, char *context, int context_bytes)\n{\n    /* see [MS-RDPESC] 3.1.4.2 */\n\n    struct stream *s;\n    int            bytes;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_RELEASE_CONTEXT)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000);\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n}\n\n/**\n * Checks if a previously established context is still valid\n *****************************************************************************/\nstatic void\nscard_send_IsContextValid(IRP *irp, char *context, int context_bytes)\n{\n    /* see [MS-RDPESC] 3.1.4.3 */\n\n    struct stream *s;\n    int            bytes;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_IS_VALID_CONTEXT)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    /*\n     * command format\n     *\n     * ......\n     *       20 bytes    padding\n     * u32    4 bytes    len 8, LE, v1\n     * u32    4 bytes    filler\n     *       16 bytes    unused (s->p currently pointed here at unused[0])\n     * u32    4 bytes    context len\n     * u32    4 bytes    context\n     */\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n\n    /* insert context */\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n}\n\n/*****************************************************************************/\nstatic void\nalign_s(struct stream *s, unsigned int boundary)\n{\n    unsigned int over = (unsigned int)(s->p - s->data) % boundary;\n    if (over != 0)\n    {\n        out_uint8s(s, boundary - over);\n    }\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_send_ListReaders(IRP *irp, char *context, int context_bytes,\n                       char *groups, int cchReaders, int wide)\n{\n    /* see [MS-RDPESC] 2.2.2.4\n     *\n     * IDL:-\n     *\n     * typedef struct _REDIR_SCARDCONTEXT {\n     *    [range(0,16)] unsigned long cbContext;\n     *    [unique] [size_is(cbContext)] byte *pbContext;\n     *    } REDIR_SCARDCONTEXT;\n     *\n     * struct _ListReaders_Call {\n     *     REDIR_SCARDCONTEXT Context;\n     *     [range(0, 65536)] unsigned long cBytes;\n     *     [unique] [size_is(cBytes)] const byte *mszGroups;\n     *     long fmszReadersIsNULL;\n     *     unsigned long cchReaders;\n     *     } ListReaders_Call;\n     *\n     * Type summary:-\n     *\n     * Context.cbContext  Unsigned 32-bit word\n     * Context.pbContext  Embedded full pointer to conformant array of bytes\n     * cBytes             Unsigned 32-bit word\n     * mszGroups          Embedded full pointer to conformant array of bytes\n     * fmszReaders        32-bit word\n     * cchReaders         Unsigned 32-bit word\n     *\n     * NDL:-\n     *\n     * Offset   Decription\n     * 0        Context.cbContext\n     * 4        Referent Identifier for pbContext\n     * 8        cBytes\n     * 12       Referent Identifier for mszGroups (or NULL)\n     * 16       fmszReadersIsNULL\n     * 20       cchReaders\n     * 24       Conformant Array pointed to by pbContext\n     * ??       Conformant Array pointed to by mszGroups\n     *\n     */\n\n    struct stream *s;\n    int            bytes;\n    int            bytes_groups = 0; // Length of NDR for groups + 2 terminators\n    int            val = 0;    // Referent Id for mszGroups (assume NULL)\n    int            groups_len = 0; // strlen(groups)\n    tui32          ioctl;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    ioctl = (wide) ? SCARD_IOCTL_LIST_READERS_W :\n            SCARD_IOCTL_LIST_READERS_A;\n\n    if ((s = scard_make_new_ioctl(irp, ioctl)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    if (groups != NULL && *groups != '\\0')\n    {\n        groups_len = g_strlen(groups);\n        if (wide)\n        {\n            bytes_groups = (utf8_as_utf16_word_count(groups, groups_len) + 2) * 2;\n        }\n        else\n        {\n            bytes_groups = groups_len + 2;\n        }\n        val = 0x00020004;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    // REDIR_SCARDCONTEXT Context;\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000);\n    // [range(0, 65536)] unsigned long cBytes;\n    out_uint32_le(s, bytes_groups);\n    // [unique] [size_is(cBytes)] const byte *mszGroups; (pointer)\n    out_uint32_le(s, val);\n    // long fmszReadersIsNULL;\n    out_uint32_le(s, 0x00000000);\n    // unsigned long cchReaders;\n    out_uint32_le(s, cchReaders);\n\n    // At the end of the struct come the pointed-to structures\n\n    // Context field pbContext is a Uni-dimensional conformant array\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    // mszGroups is also a Uni-dimensional conformant array of bytes\n    if (bytes_groups > 0)\n    {\n        align_s(s, 4);\n        out_uint32_le(s, bytes_groups);\n        if (wide)\n        {\n            out_utf8_as_utf16_le(s, groups, groups_len);\n            out_uint16_le(s, 0);\n            out_uint16_le(s, 0);\n        }\n        else\n        {\n            out_uint8p(s, groups, groups_len);\n            out_uint8(s, 0);\n            out_uint8(s, 0);\n        }\n    }\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"scard_send_ListReaders:\", s->data, bytes);\n\n    free_stream(s);\n}\n\n/*****************************************************************************/\n/**\n * Outputs the pointed-to-data for one of these IDL pointer types:-\n *     [string] const wchar_t* str;  (wide != 0)\n *     [string] const char* str;     (wide == 0)\n *\n * It is assumed that the referent identifier for the string has already\n * been sent\n *\n * @param s Output stream\n * @param str UTF-8 string to output\n * @param wide Whether to output as a wide string or ASCII\n *\n * Note that wchar_t on Windows is 16-bit\n * TODO: These strings have two terminators. Is this necessary?\n */\nstatic void\nout_conformant_and_varying_string(struct stream *s, const char *str, int wide)\n{\n    align_s(s, 4);\n    unsigned int len = strlen(str);\n    if (wide)\n    {\n        unsigned int num_chars = utf8_as_utf16_word_count(str, len);\n        // Max number, offset and actual count\n        out_uint32_le(s, num_chars + 2);\n        out_uint32_le(s, 0);\n        out_uint32_le(s, num_chars + 2);\n        out_utf8_as_utf16_le(s, str, len);\n        out_uint16_le(s, 0);  // Terminate string\n        out_uint16_le(s, 0); // ?\n    }\n    else\n    {\n        out_uint32_le(s, len + 2);\n        out_uint32_le(s, 0);\n        out_uint32_le(s, len + 2);\n        out_uint8p(s, str, len);\n        out_uint8(s, 0);\n        out_uint8(s, 0);\n    }\n}\n\n/**\n * Get change in status\n *\n * @param  irp          I/O resource pkt\n * @param  wide         TRUE if unicode string\n * @param  timeout      timeout in milliseconds, -1 for infinity\n * @param  num_readers  number of entries in rsa\n * @param  rsa          array of READER_STATEs\n *****************************************************************************/\nstatic void\nscard_send_GetStatusChange(IRP *irp, char *context, int context_bytes,\n                           int wide, tui32 timeout,\n                           tui32 num_readers, READER_STATE *rsa)\n{\n    /* see [MS-RDPESC] 2.2.2.11 for ASCII\n     * see [MS-RDPESC] 2.2.2.12 for Wide char\n     *\n     * Here is a breakdown of the Wide-char variant\n     *\n     * IDL:-\n     *\n     * typedef struct _REDIR_SCARDCONTEXT {\n     *    [range(0,16)] unsigned long cbContext;\n     *    [unique] [size_is(cbContext)] byte *pbContext;\n     *    } REDIR_SCARDCONTEXT;\n     *\n     * typedef struct _ReaderState_Common_Call {\n     *    unsigned long dwCurrentState;\n     *    unsigned long dwEventState;\n     *    [range(0,36)] unsigned long cbAtr;\n     *    byte rgbAtr[36];\n     *    } ReaderState_Common_Call;\n     *\n     * typedef struct _ReaderStateW {\n     *   [string] const wchar_t* szReader;\n     *   ReaderState_Common_Call Common;\n     *   } ReaderStateW;\n     *\n     * struct _GetStatusChangeW_Call {\n     *    REDIR_SCARDCONTEXT Context;\n     *    unsigned long dwTimeOut;\n     *    [range(0,11)] unsigned long cReaders;\n     *    [size_is(cReaders)] ReaderStateW* rgReaderStates;\n     *    } GetStatusChangeW_Call;\n     *\n     * Type summary:-\n     *\n     * Context.cbContext  Unsigned 32-bit word\n     * Context.pbContext  Embedded full pointer to conformant array of bytes\n     * dwTimeOut          Unsigned 32-bit word\n     * cReaders           Unsigned 32-bit word\n     * rgReaderStates\n     *                    Embedded full pointer to array of rgReaderStates\n     * rgReaderStates.szReader\n     *                    Embedded full pointer to conformant and varying\n     *                    string of [Windows] wchar_t\n     * rgReaderStates.Common.dwCurrentState\n     *                    Unsigned 32-bit word\n     * rgReaderStates.Common.dwEventState\n     *                    Unsigned 32-bit word\n     * rgReaderStates.Common.cbAtr\n     *                    Unsigned 32-bit word\n     * rgReaderStates.Common.rgbAtr[36]\n     *                    Uni-dimensional fixed array\n     *\n     * NDL:-\n     * Offset   Decription\n     * 0        Context.cbContext\n     * 4        Referent Identifier for pbContext\n     * 8        dwTimeOut;\n     * 12       cReaders;\n     * 16       Referent Identifier for rgReaderStates\n     * 20       Conformant Array pointed to by pbContext\n     * ??       Conformant Array pointed to by rgReaderStates. Each element\n     *          of this array has a pointer to a string for the name\n     * ??       String names pointed to in the above array.\n     */\n\n    READER_STATE  *rs;\n    struct stream *s;\n    tui32          ioctl;\n    int            bytes;\n    unsigned int   i;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    ioctl = (wide) ? SCARD_IOCTL_GET_STATUS_CHANGE_W :\n            SCARD_IOCTL_GET_STATUS_CHANGE_A;\n\n    if ((s = scard_make_new_ioctl(irp, ioctl)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    // REDIR_SCARDCONTEXT Context;\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000);\n\n    // unsigned long dwTimeOut;\n    out_uint32_le(s, timeout);\n    // [range(0,11)] unsigned long cReaders;\n    out_uint32_le(s, num_readers);\n    // [size_is(cReaders)] ReaderStateW* rgReaderStates;\n    out_uint32_le(s, 0x00020004);\n\n    // At the end of the struct come the pointed-to structures\n\n    // Context field pbContext is a Uni-dimensional conformant array\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    // rgReaderState is a Uni-dimensional conformant array\n    align_s(s, 4);\n    out_uint32_le(s, num_readers);\n\n    /* insert card reader state */\n    for (i = 0; i < num_readers; i++)\n    {\n        rs = &rsa[i];\n        //  [string] const wchar_t* szReader (wide)\n        //  [string] const char_t* szReader (ASCII)\n        out_uint32_le(s, 0x00020008 + (i * 4));\n        //  unsigned long dwCurrentState;\n        out_uint32_le(s, rs->current_state);\n        //  unsigned long dwEventState;\n        out_uint32_le(s, rs->event_state);\n        //  [range(0,36)] unsigned long cbAtr;\n        out_uint32_le(s, rs->atr_len);\n        //  byte rgbAtr[36];\n        out_uint8p(s, rs->atr, 33);\n        out_uint8s(s, 3);\n    }\n\n    /* insert card reader names */\n    for (i = 0; i < num_readers; i++)\n    {\n        rs = &rsa[i];\n        out_conformant_and_varying_string(s, rs->reader_name, wide);\n    }\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"scard_send_GetStatusChange:\", s->data, bytes);\n\n    free_stream(s);\n}\n\n/**\n * Send connect command\n *\n * @param  irp  I/O resource pkt\n * @param  wide TRUE if unicode string\n * @param  rs   reader state\n *****************************************************************************/\nstatic void\nscard_send_Connect(IRP *irp, char *context, int context_bytes,\n                   int wide, READER_STATE *rs)\n{\n    /* see [MS-RDPESC] 2.2.2.13 for ASCII\n     * see [MS-RDPESC] 2.2.2.14 for Wide char\n     *\n     * Here is a breakdown of the Wide-char variant\n     *\n     * IDL:-\n     *\n     * typedef struct _REDIR_SCARDCONTEXT {\n     *    [range(0,16)] unsigned long cbContext;\n     *    [unique] [size_is(cbContext)] byte *pbContext;\n     *    } REDIR_SCARDCONTEXT;\n     *\n     * typedef struct _Connect_Common {\n     *     REDIR_SCARDCONTEXT Context;\n     *     unsigned long dwShareMode;\n     *     unsigned long dwPreferredProtocols;\n     * } Connect_Common;\n     *\n     * typedef struct _ConnectW_Call {\n     *     [string] const wchar_t* szReader;\n     *     Connect_Common Common;\n     * } ConnectW_Call;\n     *\n     * Type summary:-\n     *\n     * szReader           Embedded full pointer to conformant and varying\n     *                    string of [Windows] wchar_t\n     * Common.Context.cbContext\n     *                    Unsigned 32-bit word\n     * Common.Context.pbContext\n     *                    Embedded full pointer to conformant array of bytes\n     * Common.dwShareMode Unsigned 32-bit word\n     * Common.dwPreferredProtocols\n     *                    Unsigned 32-bit word\n     *\n     * NDL:-\n     *\n     * Offset   Decription\n     * 0        Referent Identifier for szReader\n     * 4        Context.cbContext\n     * 8        Referent Identifier for pbContext\n     * 12       dwShareMode\n     * 16       dwPreferredProtocols\n     * 20       Conformant Array pointed to by szReader\n     * ??       Conformant Array pointed to by pbContext\n     *\n     */\n    struct stream *s;\n    tui32          ioctl;\n    int            bytes;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    ioctl = (wide) ? SCARD_IOCTL_CONNECT_W :\n            SCARD_IOCTL_CONNECT_A;\n\n    if ((s = scard_make_new_ioctl(irp, ioctl)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    // [string] const wchar_t* szReader;\n    out_uint32_le(s, 0x00020000);\n\n    // REDIR_SCARDCONTEXT Context;\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020004);\n\n    // unsigned long dwShareMode;\n    out_uint32_le(s, rs->dwShareMode);\n    // unsigned long dwPreferredProtocols;\n    out_uint32_le(s, rs->dwPreferredProtocols);\n\n    /* insert card reader name */\n    out_conformant_and_varying_string(s, rs->reader_name, wide);\n\n    /* insert context */\n    align_s(s, 4);\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n    out_uint32_le(s, 0); // ?\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n}\n\n/**\n * The reconnect method re-establishes a smart card reader handle. On success,\n * the handle is valid once again.\n *\n * @param  rs         reader state where following fields are set\n *                        rs.shared_mode_flag\n *                        rs.preferred_protocol\n *                        rs.init_type\n *****************************************************************************/\nstatic void\nscard_send_Reconnect(IRP *irp, char *context, int context_bytes,\n                     char *card, int card_bytes, READER_STATE *rs)\n{\n    /* see [MS-RDPESC] 2.2.2.15 */\n    /* see [MS-RDPESC] 3.1.4.36 */\n\n    struct stream *s;\n    int            bytes;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_RECONNECT)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    /*\n     * command format\n     *\n     * ......\n     *       20 bytes    padding\n     * u32    4 bytes    len 8, LE, v1\n     * u32    4 bytes    filler\n     *       24 bytes    unused (s->p currently pointed here at unused[0])\n     * u32    4 bytes    dwShareMode\n     * u32    4 bytes    dwPreferredProtocols\n     * u32    4 bytes    dwInitialization\n     * u32    4 bytes    context length\n     * u32    4 bytes    context\n     * u32    4 bytes    handle length\n     * u32    4 bytes    handle\n     */\n\n    xstream_seek(s, 24); /* TODO */\n\n    out_uint32_le(s, rs->dwShareMode);\n    out_uint32_le(s, rs->dwPreferredProtocols);\n    out_uint32_le(s, rs->init_type);\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n    out_uint32_le(s, card_bytes);\n    out_uint8a(s, card, card_bytes);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n}\n\n/**\n * Lock smart card reader for exclusive access for specified smart\n * card reader handle.\n *\n *****************************************************************************/\nstatic void\nscard_send_BeginTransaction(IRP *irp, char *context, int context_bytes,\n                            char *card, int card_bytes)\n{\n    /* see [MS-RDPESC] 4.9 */\n\n    struct stream *s;\n    int            bytes;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_BEGIN_TRANSACTION)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000);\n    out_uint32_le(s, card_bytes);\n    out_uint32_le(s, 0x00020004);\n    out_uint32_le(s, 0x00000000);\n\n    /* insert context */\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    /* insert card */\n    out_uint32_le(s, card_bytes);\n    out_uint8a(s, card, card_bytes);\n\n    out_uint32_le(s, 0x00000000);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n}\n\n/**\n * Release a smart card reader after being locked by a previously\n * successful call to Begin Transaction\n *\n *****************************************************************************/\nstatic void\nscard_send_EndTransaction(IRP *irp, char *context, int context_bytes,\n                          char *card, int card_bytes,\n                          tui32 dwDisposition)\n{\n    /* see [MS-RDPESC] 3.1.4.32 */\n\n    struct stream *s;\n    int            bytes;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_END_TRANSACTION)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000);\n    out_uint32_le(s, card_bytes);\n    out_uint32_le(s, 0x00020004);\n    out_uint32_le(s, dwDisposition);\n\n    /* insert context */\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    /* insert card */\n    out_uint32_le(s, card_bytes);\n    out_uint8a(s, card, card_bytes);\n\n    out_uint32_le(s, 0);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n}\n\n/**\n * Get the status of a connection for a valid smart card reader handle\n *\n * @param  wide  TRUE if unicode string\n *****************************************************************************/\nstatic void\nscard_send_Status(IRP *irp, int wide, char *context, int context_bytes,\n                  char *card, int card_bytes,\n                  int cchReaderLen, int cbAtrLen)\n{\n    /* see [MS-RDPESC] 2.2.2.18 */\n\n    struct stream *s;\n    int            bytes;\n    tui32          ioctl;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    ioctl = wide ? SCARD_IOCTL_STATUS_W : SCARD_IOCTL_STATUS_A;\n    if ((s = scard_make_new_ioctl(irp, ioctl)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl\");\n        return;\n    }\n    /*\n              30 00 00 00\n              00 00 00 00\n              04 00 00 00\n              00 00 02 00\n              04 00 00 00\n              04 00 02 00\n              01 00 00 00\n              00 00 00 00 dwReaderLen\n              40 00 00 00 dwAtrLen\n              04 00 00 00\n              07 00 00 00\n              04 00 00 00\n              09 00 00 00 hCard\n              00 00 00 00\n    */\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000);\n    out_uint32_le(s, card_bytes);\n    out_uint32_le(s, 0x00020004);\n    out_uint32_le(s, 0x00000001);\n    out_uint32_le(s, cchReaderLen); /* readerLen, see [MS-RDPESC] 4.11 */\n    out_uint32_le(s, cbAtrLen); /* atrLen,    see [MS-RDPESC] 4.11 */\n\n    /* insert context */\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    /* insert card */\n    out_uint32_le(s, card_bytes);\n    out_uint8a(s, card, card_bytes);\n\n    out_uint32_le(s, 0);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", s->data, bytes);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n}\n\n/**\n * Release a smart card reader handle that was acquired in ConnectA/ConnectW\n *\n *****************************************************************************/\nstatic void\nscard_send_Disconnect(IRP *irp, char *context, int context_bytes,\n                      char *card, int card_bytes, int dwDisposition)\n{\n    /* see [MS-RDPESC] 3.1.4.30 */\n\n    struct stream *s;\n    int            bytes;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_DISCONNECT)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl failed\");\n        return;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000);\n    out_uint32_le(s, card_bytes);\n    out_uint32_le(s, 0x00020004);\n    out_uint32_le(s, dwDisposition);\n\n    /* insert context */\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    /* insert card */\n    out_uint32_le(s, card_bytes);\n    out_uint8a(s, card, card_bytes);\n\n    out_uint32_le(s, 0x00000000);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n}\n\n/**\n * The Transmit_Call structure is used to send data to the smart card\n * associated with a valid context.\n *****************************************************************************/\nstatic int\nscard_send_Transmit(IRP *irp, char *context, int context_bytes,\n                    char *card, int card_bytes, char *send_data,\n                    int send_bytes, int recv_bytes,\n                    struct xrdp_scard_io_request *send_ior,\n                    struct xrdp_scard_io_request *recv_ior)\n{\n    /* see [MS-RDPESC] 2.2.2.19 */\n\n    struct stream *s;\n    int            bytes;\n    int            val;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return 1;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_TRANSMIT)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl\");\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"send_bytes %d recv_bytes %d send dwProtocol %d cbPciLength %d \"\n              \"extra_bytes %d recv dwProtocol %d cbPciLength %d extra_bytes %d\",\n              send_bytes, recv_bytes, send_ior->dwProtocol, send_ior->cbPciLength,\n              send_ior->extra_bytes, recv_ior->dwProtocol, recv_ior->cbPciLength,\n              recv_ior->extra_bytes);\n\n    /*\n     * command format\n     *\n     * ......\n     *       20 bytes    padding\n     * u32    4 bytes    len 8, LE, v1\n     * u32    4 bytes    filler\n     *       12 bytes    unused (s->p currently pointed here at unused[0])\n     * u32    4 bytes    map0\n     *        4 bytes    unused\n     * u32    4 bytes    map1\n     * u32    4 bytes    dwProtocol\n     * u32    4 bytes    cbPciLength\n     * u32    4 bytes    map2\n     * u32    4 bytes    cbSendLength\n     * u32    4 bytes    map3\n     * u32    4 bytes    map4\n     * u32    4 bytes    map5\n     * u32    4 bytes    map6\n     * u32    4 bytes    cbRecvLength\n     * u32    4 bytes    len of sc_handle\n     * u32    4 bytes    sc_handle\n     */\n\n    //g_writeln(\"send_bytes %d\", send_bytes);\n    //g_writeln(\"recv_bytes %d\", recv_bytes);\n\n#if 0\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_be(s, 0x00000000);\n    out_uint32_be(s, 0x04000000);\n    out_uint32_be(s, 0x00000200); // map 0\n    out_uint32_be(s, 0x04000000);\n    out_uint32_be(s, 0x04000200); // map 1\n    out_uint32_be(s, 0x01000000);\n    out_uint32_be(s, 0x00000000);\n    out_uint32_be(s, 0x00000000);\n\n    //out_uint32_be(s, 0x05000000);\n    out_uint32_le(s, send_bytes);\n\n    out_uint32_be(s, 0x08000200);\n    out_uint32_be(s, 0x0c000200);\n    out_uint32_be(s, 0x00000000);\n\n    //out_uint32_be(s, 0x02010000);\n    out_uint32_le(s, recv_bytes);\n\n    out_uint32_be(s, 0x04000000);\n    out_uint32_be(s, 0x05000000);\n    out_uint32_be(s, 0x04000000);\n    out_uint32_be(s, 0x0b000000);\n\n    //out_uint32_be(s, 0x05000000);\n    //out_uint32_be(s, 0x00b00704);\n    //out_uint32_be(s, 0x10000000);\n    out_uint32_le(s, send_bytes);\n    out_uint8p(s, send_data, send_bytes);\n    align_s(s, 4);\n\n    out_uint32_be(s, 0x01000000);\n    out_uint32_be(s, 0x00000000);\n    out_uint32_be(s, 0x00000000);\n#else\n\n    //g_printf(\"send cbPciLength %d\\n\", send_ior->cbPciLength);\n    //g_printf(\"send extra_bytes %d\\n\", send_ior->extra_bytes);\n    //g_printf(\"recv cbPciLength %d\\n\", recv_ior->cbPciLength);\n    //g_printf(\"recv extra_bytes %d\\n\", recv_ior->extra_bytes);\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000); /* map0 */\n\n    out_uint32_le(s, card_bytes);\n    out_uint32_le(s, 0x00020004); /* map1 */\n\n    out_uint32_le(s, send_ior->dwProtocol);\n    out_uint32_le(s, send_ior->cbPciLength - 8);\n\n    val = send_ior->extra_bytes > 0 ? 1 : 0;\n    out_uint32_le(s, val); /* map2 */\n\n    out_uint32_le(s, send_bytes);\n\n    val = send_bytes > 0 ? 0x00020008 : 0;\n    out_uint32_le(s, val); /* map3 */\n\n    val = recv_ior->cbPciLength > 0 ? 0x0002000c : 0;\n    out_uint32_le(s, val); /* map 4 */\n\n    out_uint32_le(s, 0); // map5\n    out_uint32_le(s, recv_bytes);\n\n    /* map0 */\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    /* map1 */\n    out_uint32_le(s, card_bytes);\n    out_uint8a(s, card, card_bytes);\n\n    if (send_ior->extra_bytes > 0)\n    {\n        out_uint32_le(s, send_ior->extra_bytes);\n        out_uint8a(s, send_ior->extra_data, send_ior->extra_bytes);\n    }\n\n    if (send_bytes > 0)\n    {\n        out_uint32_le(s, send_bytes);\n        out_uint8a(s, send_data, send_bytes);\n        align_s(s, 4);\n    }\n\n    if (recv_ior->cbPciLength > 0)\n    {\n        /* map4 */\n        out_uint32_le(s, recv_ior->dwProtocol);\n        out_uint32_le(s, recv_ior->cbPciLength - 8);\n        val = recv_ior->extra_bytes > 0 ? 1 : 0;\n        out_uint32_le(s, val); /* map6*/\n        if (val)\n        {\n            out_uint32_le(s, recv_ior->extra_bytes);\n            out_uint8a(s, recv_ior->extra_data, recv_ior->extra_bytes);\n        }\n    }\n#endif\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"scard_send_Transmit:\", s->data, bytes);\n\n    free_stream(s);\n    return 0;\n}\n\n/**\n * Communicate directly with the smart card reader\n *****************************************************************************/\nstatic int\nscard_send_Control(IRP *irp, char *context, int context_bytes,\n                   char *card, int card_bytes, char *send_data,\n                   int send_bytes, int recv_bytes, int control_code)\n{\n    /* see [MS-RDPESC] 2.2.2.19 */\n\n    struct stream *s;\n    int            bytes;\n    int            val;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return 1;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_CONTROL)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl\");\n        return 1;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000); /* map0 */\n    out_uint32_le(s, card_bytes);\n    out_uint32_le(s, 0x00020004); /* map1 */\n    out_uint32_le(s, control_code);\n    out_uint32_le(s, send_bytes);\n    val = send_bytes > 0 ? 0x00020008 : 0;\n    out_uint32_le(s, val);        /* map2 */\n    out_uint32_le(s, 0x00000000);\n    out_uint32_le(s, recv_bytes);\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n    out_uint32_le(s, card_bytes);\n    out_uint8a(s, card, card_bytes);\n    if (send_bytes > 0)\n    {\n        out_uint32_le(s, send_bytes);\n        out_uint8a(s, send_data, send_bytes);\n    }\n    else\n    {\n        out_uint32_le(s, 0x00000000);\n    }\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", s->data, bytes);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n    return 0;\n}\n\n/**\n * Cancel any outstanding calls\n *****************************************************************************/\nstatic int\nscard_send_Cancel(IRP *irp, char *context, int context_bytes)\n{\n    /* see [MS-RDPESC] 3.1.4.27 */\n\n    struct stream *s;\n    int            bytes;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return 1;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_CANCEL)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl\");\n        return 1;\n    }\n\n    s_push_layer(s, mcs_hdr, 4); /* bytes, set later */\n    out_uint32_le(s, 0x00000000);\n    out_uint32_le(s, context_bytes);\n    out_uint32_le(s, 0x00020000);\n    out_uint32_le(s, context_bytes);\n    out_uint8a(s, context, context_bytes);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, mcs_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 8;\n    out_uint32_le(s, bytes);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n    return 0;\n}\n\n/**\n * Get reader attributes\n *****************************************************************************/\nstatic int\nscard_send_GetAttrib(IRP *irp, char *card, int card_bytes, READER_STATE *rs)\n{\n    /* see [MS-RDPESC] 2.2.2.21 */\n\n    struct stream *s;\n    int            bytes;\n\n    if (smartcards[irp->scard_index] == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"smartcards[%d] is NULL\", irp->scard_index);\n        return 1;\n    }\n\n    if ((s = scard_make_new_ioctl(irp, SCARD_IOCTL_GETATTRIB)) == NULL)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"scard_make_new_ioctl\");\n        return 1;\n    }\n\n    /*\n     * command format\n     *\n     * ......\n     *       20 bytes    padding\n     * u32    4 bytes    len 8, LE, v1\n     * u32    4 bytes    filler\n     *       24 bytes    unused (s->p currently pointed here at unused[0])\n     * u32    4 bytes    dwAttribId\n     *        4 bytes    unused\n     * u32    4 bytes    dwAttrLen\n     *        8 bytes    unused\n     * u32    4 bytes    handle len\n     * u32    4 bytes    handle\n     */\n\n    xstream_seek(s, 24); /* TODO */\n    out_uint32_le(s, rs->dwAttribId);\n    out_uint32_le(s, 0);\n    out_uint32_le(s, rs->dwAttrLen);\n    xstream_seek(s, 8);\n    out_uint32_le(s, card_bytes);\n    out_uint8a(s, card, card_bytes);\n\n    s_mark_end(s);\n\n    s_pop_layer(s, iso_hdr);\n    bytes = (int) (s->end - s->p);\n    bytes -= 28;\n    out_uint32_le(s, bytes);\n\n    bytes = (int) (s->end - s->data);\n\n    /* send to client */\n    send_channel_data(g_rdpdr_chan_id, s->data, bytes);\n\n    free_stream(s);\n    return 0;\n}\n\n/******************************************************************************\n**                                                                           **\n**                    local callbacks into this module                       **\n**                                                                           **\n******************************************************************************/\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_EstablishContext_Return(struct stream *s, IRP *irp,\n                                     tui32 DeviceId, tui32 CompletionId,\n                                     tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_establish_context_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_ReleaseContext_Return(struct stream *s, IRP *irp,\n                                   tui32 DeviceId, tui32 CompletionId,\n                                   tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_release_context_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_IsContextValid_Return(struct stream *s, IRP *irp,\n                                   tui32 DeviceId, tui32 CompletionId,\n                                   tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_is_context_valid_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_ListReaders_Return(struct stream *s, IRP *irp,\n                                tui32 DeviceId, tui32 CompletionId,\n                                tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_list_readers_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_GetStatusChange_Return(struct stream *s, IRP *irp,\n                                    tui32 DeviceId, tui32 CompletionId,\n                                    tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_get_status_change_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_Connect_Return(struct stream *s, IRP *irp,\n                            tui32 DeviceId, tui32 CompletionId,\n                            tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n\n    scard_function_connect_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_Reconnect_Return(struct stream *s, IRP *irp,\n                              tui32 DeviceId, tui32 CompletionId,\n                              tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_reconnect_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_BeginTransaction_Return(struct stream *s, IRP *irp,\n                                     tui32 DeviceId, tui32 CompletionId,\n                                     tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_begin_transaction_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_EndTransaction_Return(struct stream *s, IRP *irp,\n                                   tui32 DeviceId, tui32 CompletionId,\n                                   tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_end_transaction_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_Status_Return(struct stream *s, IRP *irp,\n                           tui32 DeviceId, tui32 CompletionId,\n                           tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_status_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_Disconnect_Return(struct stream *s, IRP *irp,\n                               tui32 DeviceId, tui32 CompletionId,\n                               tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_disconnect_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_Transmit_Return(struct stream *s, IRP *irp, tui32 DeviceId,\n                             tui32 CompletionId, tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_transmit_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_Control_Return(struct stream *s, IRP *irp, tui32 DeviceId,\n                            tui32 CompletionId, tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_control_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_Cancel_Return(struct stream *s, IRP *irp, tui32 DeviceId,\n                           tui32 CompletionId, tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_cancel_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n\n/**\n *\n *****************************************************************************/\nstatic void\nscard_handle_GetAttrib_Return(struct stream *s, IRP *irp, tui32 DeviceId,\n                              tui32 CompletionId, tui32 IoStatus)\n{\n    tui32 len;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"entered\");\n\n    /* sanity check */\n    if ((DeviceId != irp->DeviceId) || (CompletionId != irp->CompletionId))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"DeviceId/CompletionId do not match those in IRP\");\n        return;\n    }\n\n    /* get OutputBufferLen */\n    xstream_rd_u32_le(s, len);\n    scard_function_get_attrib_return(irp->user_data, s, len, IoStatus);\n    devredir_irp_delete(irp);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"leaving\");\n}\n"
  },
  {
    "path": "sesman/chansrv/smartcard.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/*\n * smartcard redirection support\n *\n * External interface to the smartcard function\n */\n\n#ifndef SMARTCARD_H\n#define SMARTCARD_H\n\n#include \"arch.h\"\n\nint scard_device_announce(tui32 device_id);\nint scard_get_wait_objs(tbus *objs, int *count, int *timeout);\nint scard_check_wait_objs(void);\nint scard_init(void);\nint scard_deinit(void);\n\n#endif /* end #ifndef SMARTCARD_H */\n"
  },
  {
    "path": "sesman/chansrv/smartcard_dummy.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n * Copyright (C) Jay Sorg 2013 jay.sorg@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n * @file sesman/chansrv/smartcard_dummy.c\n *\n * smartcard redirection support\n *\n * Dummy file used when smartcard support is not enabled.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"smartcard.h\"\n\n/*****************************************************************************/\nint\nscard_device_announce(tui32 device_id)\n{\n    return 1; // Not supported\n}\n\n/*****************************************************************************/\nint\nscard_get_wait_objs(tbus *objs, int *count, int *timeout)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nint\nscard_check_wait_objs(void)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nint\nscard_init(void)\n{\n    return 1;\n}\n\n/*****************************************************************************/\nint\nscard_deinit(void)\n{\n    return 0;\n}\n"
  },
  {
    "path": "sesman/chansrv/smartcard_internal.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/*\n * smartcard redirection support\n *\n * Routines internal to the smartcard function\n */\n\n#ifndef SMARTCARD_INTERNAL_H\n#define SMARTCARD_INTERNAL_H\n\n#include \"parse.h\"\n#include \"irp.h\"\n#include \"trans.h\"\n\n#define SCARD_SHARE_EXCLUSIVE       0x00000001\n#define SCARD_SHARE_SHARED          0x00000002\n#define SCARD_SHARE_DIRECT          0x00000003\n\n/* see [MS-RDPESC] 2.2.5 protocol identifier - Table A */\n#define SCARD_PROTOCOL_UNDEFINED    0x00000000\n#define SCARD_PROTOCOL_T0           0x00000001\n#define SCARD_PROTOCOL_T1           0x00000002\n#define SCARD_PROTOCOL_Tx           0x00000003\n#define SCARD_PROTOCOL_RAW          0x00010000\n\n/* see [MS-RDPESC] 2.2.5 protocol identifier - Table B */\n#define SCARD_PROTOCOL_DEFAULT      0x80000000\n#define SCARD_PROTOCOL_OPTIMAL      0x00000000\n\n/* initialization type */\n#define SCARD_LEAVE_CARD            0x00000000 /* do not do anything      */\n#define SCARD_RESET_CARD            0x00000001 /* reset smart card        */\n#define SCARD_UNPOWER_CARD          0x00000002 /* turn off and reset card */\n\nstruct xrdp_scard_io_request\n{\n    tui32 dwProtocol;\n    tui32 cbPciLength;\n    int extra_bytes;\n    char *extra_data;\n};\n\ntypedef struct reader_state\n{\n    char   reader_name[128];\n    tui32  current_state;\n    tui32  event_state;\n    tui32  atr_len; /* number of bytes in atr[] */\n    tui8   atr[36];\n\n    /*\n     * share mode flag, can be one of:\n     *  SCARD_SHARE_EXCLUSIVE  app not willing to share smartcard with other apps\n     *  SCARD_SHARE_SHARED     app willing to share smartcard with other apps\n     *  SCARD_SHARE_DIRECT     app demands direct control of smart card, hence\n     *                         it is not available to other readers\n     */\n    tui32  dwShareMode;\n\n    /*\n     * This field MUST have a value from Table A which is logically\n     * OR'ed with a value from Table B.\n     */\n    tui32  dwPreferredProtocols;\n\n    /*\n     * initialization type, must be one of the initialization type\n     * defined above\n     */\n    tui32  init_type;\n\n    /* required by scard_send_transmit(), scard_send_control() */\n    tui32 map0;\n    tui32 map1;\n    tui32 map2;\n    tui32 map3;\n    tui32 map4;\n    tui32 map5;\n    tui32 map6;\n\n    tui32 dwProtocol;\n    tui32 cbPciLength;\n    tui32 cbSendLength;\n    tui32 cbRecvLength;\n    tui32 dwControlCode;\n    tui32 cbOutBufferSize;\n    tui32 dwAttribId;\n    tui32 dwAttrLen;\n\n} READER_STATE;\n\nint  scard_send_establish_context(void *user_data, int scope);\nint  scard_send_release_context(void *user_data,\n                                char *context, int context_bytes);\nint  scard_send_is_valid_context(void *user_data,\n                                 char *context, int context_bytes);\nint  scard_send_list_readers(void *user_data,\n                             char *context, int context_bytes,\n                             char *groups, int cchReaders, int wide);\n\nint  scard_send_get_status_change(void *user_data,\n                                  char *context, int context_bytes,\n                                  int wide, tui32 timeout,\n                                  tui32 num_readers, READER_STATE *rsa);\n\nint  scard_send_connect(void *user_data,\n                        char *context, int context_bytes, int wide,\n                        READER_STATE *rs);\n\nint  scard_send_reconnect(void *user_data,\n                          char *context, int context_bytes,\n                          char *card, int card_bytes,\n                          READER_STATE *rs);\n\nint  scard_send_begin_transaction(void *user_data,\n                                  char *context, int context_bytes,\n                                  char *card, int card_bytes);\nint  scard_send_end_transaction(void *user_data,\n                                char *context, int context_bytes,\n                                char *card, int card_bytes,\n                                tui32 dwDisposition);\nint  scard_send_status(void *user_data, int wide,\n                       char *context, int context_bytes,\n                       char *card, int card_bytes,\n                       int cchReaderLen, int cbAtrLen);\nint  scard_send_disconnect(void *user_data,\n                           char *context, int context_bytes,\n                           char *card, int card_bytes,\n                           int dwDisposition);\n\nint  scard_send_transmit(void *user_data,\n                         char *context, int context_bytes,\n                         char *card, int card_bytes,\n                         char *send_data, int send_bytes, int recv_bytes,\n                         struct xrdp_scard_io_request *send_ior,\n                         struct xrdp_scard_io_request *recv_ior);\n\nint  scard_send_control(void *user_data,\n                        char *context, int context_bytes,\n                        char *card, int card_bytes,\n                        char *send_data, int send_bytes,\n                        int recv_bytes, int control_code);\n\nint  scard_send_cancel(void *user_data,\n                       char *context, int context_bytes);\n\nint  scard_send_get_attrib(void *user_data, char *card, int card_bytes,\n                           READER_STATE *rs);\n\n/*\n * Notes:\n *      SCardTransmit - partially done\n *      SCardControl - partially done\n *      SCardListReaderGroups - not supported\n *      SCardSetAttrib - not supported\n */\n#endif /* end #ifndef SMARTCARD_INTERNAL_H */\n"
  },
  {
    "path": "sesman/chansrv/smartcard_pcsc.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2013 jay.sorg@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/*\n * smartcard redirection support, PCSC daemon standin\n * this will act like pcsc daemon\n * pcsc lib and daemon write struct on unix domain socket for communication\n *\n * Currently this file implements some of the PDUs detailed in [MS-RDPESC].\n *\n * The PDUs use DCE IDL structs. These are required to be re-interpreted\n * in DCE NDR (Netword Data Representation)\n *\n * For more information on this subject see DCE publication C706\n * \"DCE 1.1: Remote Procedure Call\" 1997. In particular:-\n * Section 4.2 : Describes the IDL\n * Section 14 : Describes the NDR\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#define JAY_TODO_CONTEXT    0\n#define JAY_TODO_WIDE       1\n\n#define PCSC_STANDIN 1\n\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"smartcard_internal.h\"\n#include \"log.h\"\n#include \"irp.h\"\n#include \"devredir.h\"\n#include \"trans.h\"\n#include \"chansrv.h\"\n#include \"list.h\"\n#include \"smartcard_pcsc.h\"\n#include \"xrdp_sockets.h\"\n\n#if PCSC_STANDIN\n\n\nextern char g_display_str[]; /* in chansrv.c */\n\nstatic int g_autoinc = 0; /* general purpose autoinc */\n\nstruct pcsc_card /* item for list of open cards in one context */\n{\n    tui32 app_card;  /* application card, always 4 bytes */\n    int card_bytes;  /* client card bytes */\n    char card[16];   /* client card */\n};\n\nstruct pcsc_context\n{\n    tui32 app_context;  /* application context, always 4 byte */\n    int context_bytes;  /* client context bytes */\n    char context[16];   /* client context */\n    struct list *cards; /* these need to be released on close */\n};\n\n/*****************************************************************************/\nstruct pcsc_uds_client\n{\n    int uds_client_id;     /* unique id represents each app */\n    struct trans *con;     /* the connection to the app */\n    struct list *contexts; /* list of struct pcsc_context */\n    struct pcsc_context *connect_context;\n};\n\nstatic struct list *g_uds_clients = 0; /* struct pcsc_uds_client */\n\nstatic struct trans *g_lis = 0;\nstatic char g_pcsclite_ipc_dir[256] = \"\";\nstatic char g_pcsclite_ipc_file[256] = \"\";\n\n/*****************************************************************************/\n/* got a new unix domain socket connection */\nstatic struct pcsc_uds_client *\ncreate_uds_client(struct trans *con)\n{\n    struct pcsc_uds_client *uds_client;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"create_uds_client:\");\n    if (con == 0)\n    {\n        return 0;\n    }\n    uds_client = g_new0(struct pcsc_uds_client, 1);\n    if (uds_client == 0)\n    {\n        return 0;\n    }\n    g_autoinc++;\n    uds_client->uds_client_id = g_autoinc;\n    uds_client->con = con;\n    con->callback_data = uds_client;\n    return uds_client;\n}\n\n/*****************************************************************************/\nstatic struct pcsc_uds_client *\nget_uds_client_by_id(int uds_client_id)\n{\n    struct pcsc_uds_client *uds_client;\n    int index;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"get_uds_client_by_id:\");\n    if (uds_client_id == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"get_uds_client_by_id: uds_client_id is zero\");\n        return 0;\n    }\n    if (g_uds_clients == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"get_uds_client_by_id: g_uds_clients is nil\");\n        return 0;\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  count %d\", g_uds_clients->count);\n    for (index = 0; index < g_uds_clients->count; index++)\n    {\n        uds_client = (struct pcsc_uds_client *)\n                     list_get_item(g_uds_clients, index);\n        if (uds_client->uds_client_id == uds_client_id)\n        {\n            return uds_client;\n        }\n    }\n    LOG(LOG_LEVEL_ERROR, \"get_uds_client_by_id: can't find uds_client_id %d\",\n        uds_client_id);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic struct pcsc_context *\nget_pcsc_context_by_app_context(struct pcsc_uds_client *uds_client,\n                                tui32 app_context)\n{\n    struct pcsc_context *rv;\n    int index;\n\n    if (uds_client == 0)\n    {\n        return 0;\n    }\n    if (uds_client->contexts == 0)\n    {\n        return 0;\n    }\n    for (index = 0; index < uds_client->contexts->count; index++)\n    {\n        rv = (struct pcsc_context *)\n             list_get_item(uds_client->contexts, index);\n        if (rv->app_context == app_context)\n        {\n            return rv;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic struct pcsc_card *\nget_pcsc_card_by_app_card(struct pcsc_uds_client *uds_client,\n                          tui32 app_card, struct pcsc_context **acontext)\n{\n    struct pcsc_card *lcard;\n    struct pcsc_context *lcontext;\n    int index;\n    int index1;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"get_pcsc_card_by_app_card: app_card %d\",\n              app_card);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"get_pcsc_card_by_app_card: uds_client is null\");\n        return 0;\n    }\n    if (uds_client->contexts == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"get_pcsc_card_by_app_card: uds_client->contexts is null\");\n        return 0;\n    }\n    for (index = 0; index < uds_client->contexts->count; index++)\n    {\n        lcontext = (struct pcsc_context *)\n                   list_get_item(uds_client->contexts, index);\n        if (lcontext != 0)\n        {\n            if (lcontext->cards != 0)\n            {\n                for (index1 = 0; index1 < lcontext->cards->count; index1++)\n                {\n                    lcard = (struct pcsc_card *)\n                            list_get_item(lcontext->cards, index1);\n                    if (lcard != 0)\n                    {\n                        if (lcard->app_card == app_card)\n                        {\n                            if (acontext != 0)\n                            {\n                                *acontext = lcontext;\n                            }\n                            return lcard;\n                        }\n                    }\n                }\n            }\n        }\n    }\n    LOG(LOG_LEVEL_ERROR, \"get_pcsc_card_by_app_card: app_card %d \"\n        \"not found in uds_client->contexts->cards\", app_card);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nfree_uds_client(struct pcsc_uds_client *uds_client)\n{\n    int i;\n    int j;\n    struct pcsc_context *context;\n    struct pcsc_card *card;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"free_uds_client:\");\n    if (uds_client == 0)\n    {\n        return 0;\n    }\n    if (uds_client->contexts != 0)\n    {\n        for (i = 0; i < uds_client->contexts->count; i++)\n        {\n            context = (struct pcsc_context *)\n                      list_get_item(uds_client->contexts, i);\n            if (context != 0)\n            {\n                if (context->cards != 0)\n                {\n                    for (j = 0; j < context->cards->count; j++)\n                    {\n                        card = (struct pcsc_card *)\n                               list_get_item(context->cards, j);\n                        if (card != 0)\n                        {\n                            /* TODO: send free card to client */\n                            g_free(card);\n                        }\n                    }\n                    list_delete(context->cards);\n                }\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"  left over context %p\", context->context);\n                scard_send_cancel(0, context->context, context->context_bytes);\n                scard_send_release_context(0, context->context,\n                                           context->context_bytes);\n                g_free(context);\n            }\n        }\n        list_delete(uds_client->contexts);\n    }\n    trans_delete(uds_client->con);\n    g_free(uds_client);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic struct pcsc_context *\nuds_client_add_context(struct pcsc_uds_client *uds_client,\n                       char *context, int context_bytes)\n{\n    struct pcsc_context *pcscContext;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"uds_client_add_context:\");\n    pcscContext = (struct pcsc_context *)\n                  g_malloc(sizeof(struct pcsc_context), 1);\n    if (pcscContext == 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"uds_client_add_context: failed to allocate memory for pcsc_context\");\n        return 0;\n    }\n    g_autoinc++;\n    pcscContext->app_context = g_autoinc;\n    pcscContext->context_bytes = context_bytes;\n    g_memcpy(pcscContext->context, context, context_bytes);\n    if (uds_client->contexts == 0)\n    {\n        uds_client->contexts = list_create();\n        if (uds_client->contexts == 0)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"uds_client_add_context: failed to allocate memory for \"\n                \"uds_client->contexts\");\n            return 0;\n        }\n    }\n    list_add_item(uds_client->contexts, (tintptr) pcscContext);\n    return pcscContext;\n}\n\n/*****************************************************************************/\nstatic int\nuds_client_remove_context(struct pcsc_uds_client *uds_client,\n                          struct pcsc_context *acontext)\n{\n    int index;\n\n    if (uds_client->contexts == 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"uds_client_remove_context: uds_client->contexts is null\");\n        return 1;\n    }\n    index = list_index_of(uds_client->contexts, (tintptr) acontext);\n    if (index < 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"uds_client_remove_context: pcsc_context not found in uds_client->contexts\");\n        return 1;\n    }\n    list_remove_item(uds_client->contexts, index);\n    g_free(acontext); // TODO free cards\n    return 0;\n}\n\n/*****************************************************************************/\nstatic struct pcsc_card *\ncontext_add_card(struct pcsc_uds_client *uds_client,\n                 struct pcsc_context *acontext,\n                 char *card, int card_bytes)\n{\n    struct pcsc_card *pcscCard;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"context_add_card: card_bytes %d\", card_bytes);\n    pcscCard = (struct pcsc_card *)\n               g_malloc(sizeof(struct pcsc_card), 1);\n    if (pcscCard == 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"context_add_card: failed to allocate memory for pcsc_card\");\n        return 0;\n    }\n    g_autoinc++;\n    pcscCard->app_card = g_autoinc;\n    pcscCard->card_bytes = card_bytes;\n    g_memcpy(pcscCard->card, card, card_bytes);\n    if (acontext->cards == 0)\n    {\n        acontext->cards = list_create();\n        if (acontext->cards == 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"context_add_card: failed to allocate \"\n                \"memory for uds_client->contexts->cards\");\n            return 0;\n        }\n    }\n    list_add_item(acontext->cards, (tintptr) pcscCard);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  new app_card %d\", pcscCard->app_card);\n    return pcscCard;\n}\n\n/*****************************************************************************/\nint\nscard_pcsc_get_wait_objs(tbus *objs, int *count, int *timeout)\n{\n    struct pcsc_uds_client *uds_client;\n    int index;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_pcsc_get_wait_objs:\");\n    if (g_lis != 0)\n    {\n        trans_get_wait_objs(g_lis, objs, count);\n    }\n    if (g_uds_clients != 0)\n    {\n        for (index = 0; index < g_uds_clients->count; index++)\n        {\n            uds_client = (struct pcsc_uds_client *)\n                         list_get_item(g_uds_clients, index);\n            if (uds_client != 0)\n            {\n                trans_get_wait_objs(uds_client->con, objs, count);\n            }\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nscard_pcsc_check_wait_objs(void)\n{\n    struct pcsc_uds_client *uds_client;\n    int index;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_pcsc_check_wait_objs:\");\n    if (g_lis != 0)\n    {\n        if (trans_check_wait_objs(g_lis) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"scard_pcsc_check_wait_objs: g_lis trans_check_wait_objs error\");\n        }\n    }\n    if (g_uds_clients != 0)\n    {\n        index = 0;\n        while (index < g_uds_clients->count)\n        {\n            uds_client = (struct pcsc_uds_client *)\n                         list_get_item(g_uds_clients, index);\n            if (uds_client != 0)\n            {\n                if (trans_check_wait_objs(uds_client->con) != 0)\n                {\n                    free_uds_client(uds_client);\n                    list_remove_item(g_uds_clients, index);\n                    continue;\n                }\n            }\n            index++;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_establish_context(struct trans *con, struct stream *in_s)\n{\n    int dwScope;\n    struct pcsc_uds_client *uds_client;\n    void *user_data;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_establish_context:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    in_uint32_le(in_s, dwScope);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_establish_context: dwScope 0x%8.8x\", dwScope);\n    user_data = (void *) (tintptr) (uds_client->uds_client_id);\n    scard_send_establish_context(user_data, dwScope);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_establish_context_return(void *user_data,\n                                        struct stream *in_s,\n                                        int len, int status)\n{\n    int bytes;\n    int uds_client_id;\n    int context_bytes;\n    int app_context;\n    char context[16];\n    struct stream *out_s;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n    struct pcsc_context *lcontext;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_establish_context_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    uds_client_id = (int) (tintptr) user_data;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_establish_context_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n    app_context = 0;\n    g_memset(context, 0, 16);\n    if (status == 0)\n    {\n        in_uint8s(in_s, 28);\n        in_uint32_le(in_s, context_bytes);\n        if (context_bytes > 16)\n        {\n            LOG(LOG_LEVEL_ERROR, \"scard_function_establish_context_return: opps \"\n                \"context_bytes %d\", context_bytes);\n            LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", in_s->p, context_bytes);\n            return 1;\n        }\n        in_uint8a(in_s, context, context_bytes);\n        lcontext = uds_client_add_context(uds_client, context, context_bytes);\n        app_context = lcontext->app_context;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_establish_context_return: \"\n                  \"app_context %d\", app_context);\n    }\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    out_uint32_le(out_s, app_context);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x01); /* SCARD_ESTABLISH_CONTEXT 0x01 */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_release_context(struct trans *con, struct stream *in_s)\n{\n    int hContext;\n    struct pcsc_uds_client *uds_client;\n    struct pcsc_context *lcontext;\n    void *user_data;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_release_context:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    in_uint32_le(in_s, hContext);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_release_context: hContext 0x%8.8x\", hContext);\n    user_data = (void *) (tintptr) (uds_client->uds_client_id);\n    lcontext = get_pcsc_context_by_app_context(uds_client, hContext);\n    if (lcontext == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_release_context: \"\n            \"get_pcsc_context_by_app_context failed\");\n        return 1;\n    }\n    scard_send_release_context(user_data, lcontext->context,\n                               lcontext->context_bytes);\n    uds_client_remove_context(uds_client, lcontext);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_release_context_return(void *user_data,\n                                      struct stream *in_s,\n                                      int len, int status)\n{\n    int bytes;\n    int uds_client_id;\n    struct stream *out_s;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_release_context_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    uds_client_id = (int) (tintptr) user_data;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_release_context_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x02); /* SCARD_RELEASE_CONTEXT 0x02 */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\nstruct pcsc_list_readers\n{\n    int uds_client_id;\n    int cchReaders;\n};\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_list_readers(struct trans *con, struct stream *in_s)\n{\n    int hContext;\n    unsigned int bytes_groups;\n    int cchReaders;\n    /*\n     * At the time of writing, the groups strings which can be sent\n     * over this interface are all small:-\n     *\n     * \"SCard$AllReaders\", \"SCard$DefaultReaders\", \"SCard$LocalReaders\" and\n     * \"SCard$SystemReaders\"\n     *\n     * We'll allow a bit extra in case the interface changes\n     */\n    char groups[256];\n    struct pcsc_uds_client *uds_client;\n    struct pcsc_context *lcontext;\n    struct pcsc_list_readers *pcscListReaders;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_list_readers:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    in_uint32_le(in_s, hContext);\n    in_uint32_le(in_s, bytes_groups);\n    if (bytes_groups > (sizeof(groups) - 1))\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_list_readers: Unreasonable string length %u\",\n            bytes_groups);\n        return 1;\n    }\n    in_uint8a(in_s, groups, bytes_groups);\n    groups[bytes_groups] = '\\0';\n    in_uint32_le(in_s, cchReaders);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_list_readers: hContext 0x%8.8x cchReaders %d\",\n              hContext, cchReaders);\n    lcontext = get_pcsc_context_by_app_context(uds_client, hContext);\n    if (lcontext == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_list_readers: \"\n            \"get_pcsc_context_by_app_context failed\");\n        return 1;\n    }\n    pcscListReaders = g_new0(struct pcsc_list_readers, 1);\n    pcscListReaders->uds_client_id = uds_client->uds_client_id;\n    pcscListReaders->cchReaders = cchReaders;\n    scard_send_list_readers(pcscListReaders, lcontext->context,\n                            lcontext->context_bytes, groups, cchReaders, 1);\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Counts the number of non-NULL strings in a multistring\n *\n * [MS-RDPESC] A multistring is \"A series of null-terminated character\n * strings terminated by a final null character stored in a contiguous\n * block of memory.\"\n *\n * The string is guaranteed to have at least the returned number of NULL\n * characters in it\n */\nstatic unsigned int\ncount_multistring_elements(const char *str, unsigned int len)\n{\n    unsigned int rv = 0;\n\n    if (str != NULL)\n    {\n        while (len > 0)\n        {\n            // Look for a terminator\n            const char *p = (const char *)memchr(str, '\\0', len);\n            if (!p || p == str)\n            {\n                // No terminator, or an empty string encountered */\n                break;\n            }\n\n            ++rv;\n            ++p; // Skip terminator\n            len -= (p - str);\n            str = p;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nscard_function_list_readers_return(void *user_data,\n                                   struct stream *in_s,\n                                   int len, int status)\n{\n    /* see [MS-RDPESC] 2.2.3.4\n     *\n     * IDL:-\n     *\n     * typedef struct _longAndMultiString_Return {\n     *     long ReturnCode;\n     *     [range(0,65536)] unsigned long cBytes;\n     *     [unique] [size_is(cBytes)] byte *msz;\n     *     } ListReaderGroups_Return, ListReaders_Return;\n     *\n     * Type summary:-\n     *\n     * ReturnCode         32-bit word\n     * CBytes             Unsigned 32-bit word\n     * msz                Embedded full pointer to conformant array of bytes\n     *\n     * NDR:-\n     *\n     * Offset   Decription\n     * 0        ReturnCode\n     * 4        cBytes\n     * 8        msz pointer Referent Identifier\n     * 12       length of multistring in bytes\n     * 16       Multistring data\n     */\n    struct stream *out_s;\n    int            readers;\n    int            index;\n    int            bytes;\n    int            cchReaders;\n    int            llen;\n    int uds_client_id;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n    struct pcsc_list_readers *pcscListReaders;\n    char *msz_readers = NULL;\n    int rv;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_list_readers_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    pcscListReaders = (struct pcsc_list_readers *) user_data;\n    if (pcscListReaders == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_list_readers_return: \"\n            \"pcscListReaders is nil\");\n        return 1;\n    }\n    uds_client_id = pcscListReaders->uds_client_id;\n    cchReaders = pcscListReaders->cchReaders;\n    g_free(pcscListReaders);\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_list_readers_return: \"\n            \"get_uds_client_by_id failed, could not find id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n    readers = 0;\n    llen = 0;\n    if (status == 0)\n    {\n        // Skip [C706] PDU Header\n        in_uint8s(in_s, 16);\n        // Move to length of multistring in bytes\n        in_uint8s(in_s, 12);\n\n        in_uint32_le(in_s, llen);\n        if (cchReaders > 0)\n        {\n            // Convert the wide multistring to a UTF-8 multistring\n            unsigned int u8len;\n            u8len = in_utf16_le_fixed_as_utf8_length(in_s, len / 2);\n            msz_readers = (char *)malloc(u8len);\n            if (msz_readers == NULL)\n            {\n                LOG(LOG_LEVEL_ERROR, \"scard_function_list_readers_return: \"\n                    \"Can't allocate %u bytes of memory\", u8len);\n                readers = 0;\n            }\n            else\n            {\n                in_utf16_le_fixed_as_utf8(in_s, len / 2, msz_readers, u8len);\n                readers = count_multistring_elements(msz_readers, u8len);\n            }\n        }\n    }\n\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        rv = 1;\n    }\n    else\n    {\n        s_push_layer(out_s, iso_hdr, 8);\n        out_uint32_le(out_s, llen);\n        out_uint32_le(out_s, readers);\n        {\n            const char *p = msz_readers;\n            for (index = 0; index < readers; index++)\n            {\n                unsigned int slen = strlen(p);\n                if (slen < 100)\n                {\n                    out_uint8a(out_s, p, slen);\n                    out_uint8s(out_s, 100 - slen);\n                }\n                else\n                {\n                    out_uint8a(out_s, p, 99);\n                    out_uint8s(out_s, 1);\n                }\n                p += (slen + 1);\n            }\n        }\n        out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n        s_mark_end(out_s);\n        bytes = (int) (out_s->end - out_s->data);\n        s_pop_layer(out_s, iso_hdr);\n        out_uint32_le(out_s, bytes - 8);\n        out_uint32_le(out_s, 0x03); /* SCARD_LIST_READERS 0x03 */\n        rv = trans_force_write(con);\n    }\n    free(msz_readers);\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_connect(struct trans *con, struct stream *in_s)\n{\n    int hContext;\n    READER_STATE rs;\n    struct pcsc_uds_client *uds_client;\n    void *user_data;\n    struct pcsc_context *lcontext;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_connect:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    g_memset(&rs, 0, sizeof(rs));\n    in_uint32_le(in_s, hContext);\n    in_uint8a(in_s, rs.reader_name, 100);\n    in_uint32_le(in_s, rs.dwShareMode);\n    in_uint32_le(in_s, rs.dwPreferredProtocols);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_connect: rs.reader_name %s dwShareMode 0x%8.8x \"\n              \"dwPreferredProtocols 0x%8.8x\", rs.reader_name, rs.dwShareMode,\n              rs.dwPreferredProtocols);\n    user_data = (void *) (tintptr) (uds_client->uds_client_id);\n    lcontext = get_pcsc_context_by_app_context(uds_client, hContext);\n    if (lcontext == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_connect: \"\n            \"get_pcsc_context_by_app_context failed\");\n        return 1;\n    }\n    uds_client->connect_context = lcontext;\n    scard_send_connect(user_data, lcontext->context, lcontext->context_bytes,\n                       1, &rs);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nscard_function_connect_return(void *user_data,\n                              struct stream *in_s,\n                              int len, int status)\n{\n    int dwActiveProtocol;\n    int hCard;\n    int bytes;\n    int uds_client_id;\n    struct stream *out_s;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n    char *card;\n    int card_bytes;\n    struct pcsc_card *lcard;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_connect_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    uds_client_id = (int) (tintptr) user_data;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_connect_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n    dwActiveProtocol = 0;\n    hCard = 0;\n    if (status == 0)\n    {\n        in_uint8s(in_s, 36);\n        in_uint32_le(in_s, dwActiveProtocol);\n        if (len > 40)\n        {\n            in_uint32_le(in_s, card_bytes);\n            in_uint8p(in_s, card, card_bytes);\n            lcard = context_add_card(uds_client, uds_client->connect_context,\n                                     card, card_bytes);\n            hCard = lcard->app_card;\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"  hCard %d dwActiveProtocol %d\", hCard,\n                      dwActiveProtocol);\n        }\n        else\n        {\n            status = 0x8010000F; /* SCARD_E_PROTO_MISMATCH */\n        }\n    }\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    out_uint32_le(out_s, hCard);\n    out_uint32_le(out_s, dwActiveProtocol);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x04); /* SCARD_CONNECT 0x04 */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_disconnect(struct trans *con, struct stream *in_s)\n{\n    int hCard;\n    int dwDisposition;\n    struct pcsc_uds_client *uds_client;\n    void *user_data;\n    struct pcsc_context *lcontext;\n    struct pcsc_card *lcard;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_disconnect:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    in_uint32_le(in_s, hCard);\n    in_uint32_le(in_s, dwDisposition);\n    user_data = (void *) (tintptr) (uds_client->uds_client_id);\n    lcard = get_pcsc_card_by_app_card(uds_client, hCard, &lcontext);\n    if ((lcontext == 0) || (lcard == 0))\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_disconnect: \"\n            \"get_pcsc_card_by_app_card failed\");\n        return 1;\n    }\n    scard_send_disconnect(user_data,\n                          lcontext->context, lcontext->context_bytes,\n                          lcard->card, lcard->card_bytes, dwDisposition);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nscard_function_disconnect_return(void *user_data,\n                                 struct stream *in_s,\n                                 int len, int status)\n{\n    int bytes;\n    int uds_client_id;\n    struct stream *out_s;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_disconnect_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    uds_client_id = (int) (tintptr) user_data;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_disconnect_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x06); /* SCARD_DISCONNECT 0x06 */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_begin_transaction(struct trans *con, struct stream *in_s)\n{\n    int hCard;\n    struct pcsc_uds_client *uds_client;\n    void *user_data;\n    struct pcsc_card *lcard;\n    struct pcsc_context *lcontext;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_begin_transaction:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    in_uint32_le(in_s, hCard);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_begin_transaction: hCard 0x%8.8x\", hCard);\n    user_data = (void *) (tintptr) (uds_client->uds_client_id);\n    lcard = get_pcsc_card_by_app_card(uds_client, hCard, &lcontext);\n    if ((lcard == 0) || (lcontext == 0))\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_begin_transaction: \"\n            \"get_pcsc_card_by_app_card failed\");\n        return 1;\n    }\n    scard_send_begin_transaction(user_data,\n                                 lcontext->context, lcontext->context_bytes,\n                                 lcard->card, lcard->card_bytes);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_begin_transaction_return(void *user_data,\n                                        struct stream *in_s,\n                                        int len, int status)\n{\n    struct stream *out_s;\n    int bytes;\n    int uds_client_id;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_begin_transaction_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    uds_client_id = (int) (tintptr) user_data;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_begin_transaction_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x07); /* SCARD_BEGIN_TRANSACTION 0x07 */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_end_transaction(struct trans *con, struct stream *in_s)\n{\n    int hCard;\n    int dwDisposition;\n    struct pcsc_uds_client *uds_client;\n    void *user_data;\n    struct pcsc_card *lcard;\n    struct pcsc_context *lcontext;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_end_transaction:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    in_uint32_le(in_s, hCard);\n    in_uint32_le(in_s, dwDisposition);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_end_transaction: hCard 0x%8.8x\", hCard);\n    user_data = (void *) (tintptr) (uds_client->uds_client_id);\n    lcard = get_pcsc_card_by_app_card(uds_client, hCard, &lcontext);\n    if ((lcard == 0) || (lcontext == 0))\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_end_transaction: \"\n            \"get_pcsc_card_by_app_card failed\");\n        return 1;\n    }\n    scard_send_end_transaction(user_data,\n                               lcontext->context, lcontext->context_bytes,\n                               lcard->card, lcard->card_bytes,\n                               dwDisposition);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_end_transaction_return(void *user_data,\n                                      struct stream *in_s,\n                                      int len, int status)\n{\n    struct stream *out_s;\n    int bytes;\n    int uds_client_id;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_end_transaction_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    uds_client_id = (int) (tintptr) user_data;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_end_transaction_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x08); /* SCARD_END_TRANSACTION 0x08 */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_get_attrib_return(void *user_data,\n                                 struct stream *in_s,\n                                 int len, int status)\n{\n    return 0;\n}\n\n/*****************************************************************************/\nstruct pcsc_transmit\n{\n    int uds_client_id;\n    struct xrdp_scard_io_request recv_ior;\n    int cbRecvLength;\n};\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_transmit(struct trans *con, struct stream *in_s)\n{\n    int hCard;\n    int recv_bytes;\n    int send_bytes;\n    char *send_data;\n    struct xrdp_scard_io_request send_ior;\n    struct xrdp_scard_io_request recv_ior;\n    struct pcsc_uds_client *uds_client;\n    struct pcsc_card *lcard;\n    struct pcsc_context *lcontext;\n    struct pcsc_transmit *pcscTransmit;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_transmit:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_transmit:\");\n    in_uint32_le(in_s, hCard);\n    in_uint32_le(in_s, send_ior.dwProtocol);\n    in_uint32_le(in_s, send_ior.cbPciLength);\n    in_uint32_le(in_s, send_ior.extra_bytes);\n    in_uint8p(in_s, send_ior.extra_data, send_ior.extra_bytes);\n    in_uint32_le(in_s, send_bytes);\n    in_uint8p(in_s, send_data, send_bytes);\n    in_uint32_le(in_s, recv_ior.dwProtocol);\n    in_uint32_le(in_s, recv_ior.cbPciLength);\n    in_uint32_le(in_s, recv_ior.extra_bytes);\n    in_uint8p(in_s, recv_ior.extra_data, recv_ior.extra_bytes);\n    in_uint32_le(in_s, recv_bytes);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_transmit: send dwProtocol %d cbPciLength %d \"\n              \"recv dwProtocol %d cbPciLength %d send_bytes %d \",\n              send_ior.dwProtocol, send_ior.cbPciLength, recv_ior.dwProtocol,\n              recv_ior.cbPciLength, send_bytes);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_transmit: recv_bytes %d\", recv_bytes);\n    lcard = get_pcsc_card_by_app_card(uds_client, hCard, &lcontext);\n    if ((lcard == 0) || (lcontext == 0))\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_transmit: \"\n            \"get_pcsc_card_by_app_card failed\");\n        return 1;\n    }\n\n    pcscTransmit = (struct pcsc_transmit *)\n                   g_malloc(sizeof(struct pcsc_transmit), 1);\n    pcscTransmit->uds_client_id = uds_client->uds_client_id;\n    pcscTransmit->recv_ior = recv_ior;\n    pcscTransmit->cbRecvLength = recv_bytes;\n\n    scard_send_transmit(pcscTransmit,\n                        lcontext->context, lcontext->context_bytes,\n                        lcard->card, lcard->card_bytes,\n                        send_data, send_bytes, recv_bytes,\n                        &send_ior, &recv_ior);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_transmit_return(void *user_data,\n                               struct stream *in_s,\n                               int len, int status)\n{\n    struct stream *out_s;\n    int bytes;\n    int val;\n    int cbRecvLength;\n    char *recvBuf;\n    struct xrdp_scard_io_request recv_ior;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n    struct pcsc_transmit *pcscTransmit;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_transmit_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    pcscTransmit = (struct pcsc_transmit *) user_data;\n    recv_ior = pcscTransmit->recv_ior;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(pcscTransmit->uds_client_id);\n    g_free(pcscTransmit);\n\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_transmit_return: \"\n            \"get_uds_client_by_id failed\");\n        return 1;\n    }\n    con = uds_client->con;\n    cbRecvLength = 0;\n    recvBuf = 0;\n    if (status == 0)\n    {\n        in_uint8s(in_s, 20);\n        in_uint32_le(in_s, val);\n        if (val != 0)\n        {\n            /* pioRecvPci */\n            in_uint8s(in_s, 8);\n            in_uint32_le(in_s, recv_ior.dwProtocol);\n            in_uint32_le(in_s, recv_ior.cbPciLength);\n            recv_ior.cbPciLength += 8;\n            in_uint32_le(in_s, recv_ior.extra_bytes);\n            if (recv_ior.extra_bytes > 0)\n            {\n                in_uint8p(in_s, recv_ior.extra_data, recv_ior.extra_bytes);\n            }\n        }\n\n        in_uint8s(in_s, 4);\n        in_uint32_le(in_s, val);\n        if (val != 0)\n        {\n            in_uint32_le(in_s, cbRecvLength);\n            in_uint8p(in_s, recvBuf, cbRecvLength);\n        }\n\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_transmit_return: cbRecvLength %d\", cbRecvLength);\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    out_uint32_le(out_s, recv_ior.dwProtocol);\n    out_uint32_le(out_s, recv_ior.cbPciLength);\n    out_uint32_le(out_s, recv_ior.extra_bytes);\n    out_uint8a(out_s, recv_ior.extra_data, recv_ior.extra_bytes);\n    out_uint32_le(out_s, cbRecvLength);\n    out_uint8a(out_s, recvBuf, cbRecvLength);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x09); /* SCARD_TRANSMIT 0x09 */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_control(struct trans *con, struct stream *in_s)\n{\n    int hCard;\n    int send_bytes;\n    int recv_bytes;\n    int control_code;\n    char *send_data;\n    struct pcsc_uds_client *uds_client;\n    void *user_data;\n    struct pcsc_context *lcontext;\n    struct pcsc_card *lcard;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_control:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_control:\");\n\n    in_uint32_le(in_s, hCard);\n    in_uint32_le(in_s, control_code);\n    in_uint32_le(in_s, send_bytes);\n    in_uint8p(in_s, send_data, send_bytes);\n    in_uint32_le(in_s, recv_bytes);\n\n    user_data = (void *) (tintptr) (uds_client->uds_client_id);\n    lcard = get_pcsc_card_by_app_card(uds_client, hCard, &lcontext);\n    if ((lcard == 0) || (lcontext == 0))\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_control: \"\n            \"get_pcsc_card_by_app_card failed\");\n        return 1;\n    }\n    scard_send_control(user_data, lcontext->context, lcontext->context_bytes,\n                       lcard->card, lcard->card_bytes,\n                       send_data, send_bytes, recv_bytes,\n                       control_code);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_control_return(void *user_data,\n                              struct stream *in_s,\n                              int len, int status)\n{\n    struct stream *out_s;\n    int bytes;\n    int cbRecvLength;\n    char *recvBuf;\n    int uds_client_id;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_control_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    uds_client_id = (int) (tintptr) user_data;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_control_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n    cbRecvLength = 0;\n    recvBuf = 0;\n    if (status == 0)\n    {\n        in_uint8s(in_s, 28);\n        in_uint32_le(in_s, cbRecvLength);\n        in_uint8p(in_s, recvBuf, cbRecvLength);\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_control_return: cbRecvLength %d\", cbRecvLength);\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    out_uint32_le(out_s, cbRecvLength);\n    out_uint8a(out_s, recvBuf, cbRecvLength);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x0A); /* SCARD_CONTROL 0x0A */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\nstruct pcsc_status\n{\n    int uds_client_id;\n    int cchReaderLen;\n};\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_status(struct trans *con, struct stream *in_s)\n{\n    int hCard;\n    int cchReaderLen;\n    int cbAtrLen;\n    struct pcsc_uds_client *uds_client;\n    struct pcsc_card *lcard;\n    struct pcsc_context *lcontext;\n    struct pcsc_status *pcscStatus;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_status:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n\n    in_uint32_le(in_s, hCard);\n    in_uint32_le(in_s, cchReaderLen);\n    in_uint32_le(in_s, cbAtrLen);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_status: hCard 0x%8.8x cchReaderLen %d \"\n              \"cbAtrLen %d\", hCard, cchReaderLen, cbAtrLen);\n\n    lcard = get_pcsc_card_by_app_card(uds_client, hCard, &lcontext);\n    if ((lcard == 0) || (lcontext == 0))\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_status: \"\n            \"get_pcsc_card_by_app_card failed\");\n        return 1;\n    }\n    pcscStatus = (struct pcsc_status *) g_malloc(sizeof(struct pcsc_status), 1);\n    pcscStatus->uds_client_id = uds_client->uds_client_id;\n    pcscStatus->cchReaderLen = cchReaderLen;\n    scard_send_status(pcscStatus, 1,\n                      lcontext->context, lcontext->context_bytes,\n                      lcard->card, lcard->card_bytes,\n                      cchReaderLen, cbAtrLen);\n\n    return 0;\n}\n\n#define MS_SCARD_UNKNOWN    0\n#define MS_SCARD_ABSENT     1\n#define MS_SCARD_PRESENT    2\n#define MS_SCARD_SWALLOWED  3\n#define MS_SCARD_POWERED    4\n#define MS_SCARD_NEGOTIABLE 5\n#define MS_SCARD_SPECIFIC   6\n\n#define PC_SCARD_UNKNOWN    0x0001 /**< Unknown state */\n#define PC_SCARD_ABSENT     0x0002 /**< Card is absent */\n#define PC_SCARD_PRESENT    0x0004 /**< Card is present */\n#define PC_SCARD_SWALLOWED  0x0008 /**< Card not powered */\n#define PC_SCARD_POWERED    0x0010 /**< Card is powered */\n#define PC_SCARD_NEGOTIABLE 0x0020 /**< Ready for PTS */\n#define PC_SCARD_SPECIFIC   0x0040 /**< PTS has been set */\n\nstatic int g_ms2pc[] = { PC_SCARD_UNKNOWN, PC_SCARD_ABSENT,\n                         PC_SCARD_PRESENT, PC_SCARD_SWALLOWED,\n                         PC_SCARD_POWERED, PC_SCARD_NEGOTIABLE,\n                         PC_SCARD_SPECIFIC\n                       };\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_status_return(void *user_data,\n                             struct stream *in_s,\n                             int len, int status)\n{\n    /* see [MS-RDPESC] 2.2.3.10\n     *\n     * IDL:-\n     *\n     * typedef struct _Status_Return {\n     *     long ReturnCode;\n     *     unsigned long cBytes;\n     *     [unique] [size_is(cBytes)] byte *mszReaderNames;\n     *     unsigned long dwState;\n     *     unsigned long dwProtocol;\n     *     byte pbAtr[32];\n     *     [range(0,32)] unsigned long cbAtrLen;\n     * } Status_Return;\n     *\n     * NDR:-\n     *\n     * Offset   Decription\n     * 0        ReturnCode\n     * 4        cBytes\n     * 8        Referent Identifier for mszReaderNames;\n     * 12       dwState\n     * 16       dwProtocol\n     * 20       pbAtr\n     * 52       cbAtrLen\n     * 56       length of multistring in bytes (same as cBytes)\n     * 60       Multistring data\n     */\n    struct stream *out_s;\n    int bytes;\n    int dwReaderLen;\n    int dwState;\n    int dwProtocol;\n    int dwAtrLen;\n    char attr[32];\n    char lreader_name[100];\n    int uds_client_id;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n    struct pcsc_status *pcscStatus;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_status_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n\n    pcscStatus = (struct pcsc_status *) user_data;\n    if (pcscStatus == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_status_return: pcscStatus is nil\");\n        return 1;\n    }\n\n    uds_client_id = pcscStatus->uds_client_id;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_status_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        g_free(pcscStatus);\n        return 1;\n    }\n    g_free(pcscStatus);\n    con = uds_client->con;\n    dwReaderLen = 0;\n    dwState = 0;\n    dwProtocol = 0;\n    dwAtrLen = 0;\n    lreader_name[0] = 0;\n    if (status == 0)\n    {\n        in_uint8s(in_s, 16); // Skip [C706] PDU Header\n        in_uint8s(in_s, 4);  // ReturnCode\n        in_uint32_le(in_s, dwReaderLen);\n        in_uint8s(in_s, 4); // Referent Identifier\n        in_uint32_le(in_s, dwState);\n        dwState = g_ms2pc[dwState % 6];\n        in_uint32_le(in_s, dwProtocol);\n        in_uint8a(in_s, attr, 32);\n        in_uint32_le(in_s, dwAtrLen);\n\n        // Length of multistring and multistring data\n        if (dwReaderLen <= 0)\n        {\n            lreader_name[0] = '\\0';\n        }\n        else\n        {\n            in_uint8s(in_s, 4);  // Skip length of msz in bytes\n\n            // TODO: why are we just returning the first name of the card?\n            in_utf16_le_terminated_as_utf8(in_s, lreader_name,\n                                           sizeof(lreader_name));\n        }\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_status_return: dwAtrLen %d dwReaderLen %d \"\n              \"dwProtocol %d dwState %d name %s\",\n              dwAtrLen, dwReaderLen, dwProtocol, dwState, lreader_name);\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    dwReaderLen = g_strlen(lreader_name);\n    out_uint32_le(out_s, dwReaderLen);\n    out_uint8a(out_s, lreader_name, dwReaderLen);\n    out_uint32_le(out_s, dwState);\n    out_uint32_le(out_s, dwProtocol);\n    out_uint32_le(out_s, dwAtrLen);\n    out_uint8a(out_s, attr, dwAtrLen);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x0B); /* SCARD_STATUS 0x0B */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_get_status_change(struct trans *con, struct stream *in_s)\n{\n    int index;\n    int hContext;\n    int dwTimeout;\n    int cReaders;\n    READER_STATE *rsa;\n    struct pcsc_uds_client *uds_client;\n    void *user_data;\n    struct pcsc_context *lcontext;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_get_status_change:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    in_uint32_le(in_s, hContext);\n    in_uint32_le(in_s, dwTimeout);\n    in_uint32_le(in_s, cReaders);\n    if ((cReaders < 0) || (cReaders > 16))\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_get_status_change: bad cReaders %d\", cReaders);\n        return 1;\n    }\n    rsa = (READER_STATE *) g_malloc(sizeof(READER_STATE) * cReaders, 1);\n\n    for (index = 0; index < cReaders; index++)\n    {\n        in_uint8a(in_s, rsa[index].reader_name, 100);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_get_status_change: reader_name %s\",\n                  rsa[index].reader_name);\n        in_uint32_le(in_s, rsa[index].current_state);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_get_status_change: current_state %d\",\n                  rsa[index].current_state);\n        in_uint32_le(in_s, rsa[index].event_state);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_get_status_change: event_state %d\",\n                  rsa[index].event_state);\n        in_uint32_le(in_s, rsa[index].atr_len);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_get_status_change: atr_len %d\",\n                  rsa[index].atr_len);\n        in_uint8a(in_s, rsa[index].atr, 36);\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_get_status_change: hContext 0x%8.8x dwTimeout \"\n              \"%d cReaders %d\", hContext, dwTimeout, cReaders);\n\n    user_data = (void *) (tintptr) (uds_client->uds_client_id);\n    lcontext = get_pcsc_context_by_app_context(uds_client, hContext);\n    if (lcontext == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_get_status_change: \"\n            \"get_pcsc_context_by_app_context failed\");\n        g_free(rsa);\n        return 1;\n    }\n    scard_send_get_status_change(user_data,\n                                 lcontext->context, lcontext->context_bytes,\n                                 1, dwTimeout, cReaders, rsa);\n    g_free(rsa);\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nscard_function_get_status_change_return(void *user_data,\n                                        struct stream *in_s,\n                                        int len, int status)\n{\n    int bytes;\n    int index;\n    int cReaders;\n    tui32 current_state;\n    tui32 event_state;\n    tui32 atr_len; /* number of bytes in atr[] */\n    tui8 atr[36];\n    struct stream *out_s;\n    int uds_client_id;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_get_status_change_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    uds_client_id = (int) (tintptr) user_data;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_get_status_change_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    if (status != 0)\n    {\n        out_uint32_le(out_s, 0); /* cReaders */\n        out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    }\n    else\n    {\n        in_uint8s(in_s, 28);\n        in_uint32_le(in_s, cReaders);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  cReaders %d\", cReaders);\n        out_uint32_le(out_s, cReaders);\n        if (cReaders > 0)\n        {\n            for (index = 0; index < cReaders; index++)\n            {\n                in_uint32_le(in_s, current_state);\n                out_uint32_le(out_s, current_state);\n                in_uint32_le(in_s, event_state);\n                out_uint32_le(out_s, event_state);\n                in_uint32_le(in_s, atr_len);\n                out_uint32_le(out_s, atr_len);\n                in_uint8a(in_s, atr, 36);\n                out_uint8a(out_s, atr, 36);\n            }\n        }\n        out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    }\n\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x0C); /* SCARD_ESTABLISH_CONTEXT 0x0C */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_cancel(struct trans *con, struct stream *in_s)\n{\n    int hContext;\n    struct pcsc_uds_client *uds_client;\n    void *user_data;\n    struct pcsc_context *lcontext;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_cancel:\");\n    uds_client = (struct pcsc_uds_client *) (con->callback_data);\n    in_uint32_le(in_s, hContext);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_cancel: hContext 0x%8.8x\", hContext);\n    user_data = (void *) (tintptr) (uds_client->uds_client_id);\n    lcontext = get_pcsc_context_by_app_context(uds_client, hContext);\n    if (lcontext == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_process_cancel: \"\n            \"get_pcsc_context_by_app_context failed\");\n        return 1;\n    }\n    scard_send_cancel(user_data, lcontext->context, lcontext->context_bytes);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_cancel_return(void *user_data,\n                             struct stream *in_s,\n                             int len, int status)\n{\n    int bytes;\n    int uds_client_id;\n    struct stream *out_s;\n    struct pcsc_uds_client *uds_client;\n    struct trans *con;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_function_cancel_return:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  status 0x%8.8x\", status);\n    uds_client_id = (int) (tintptr) user_data;\n    uds_client = (struct pcsc_uds_client *)\n                 get_uds_client_by_id(uds_client_id);\n    if (uds_client == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scard_function_cancel_return: \"\n            \"get_uds_client_by_id failed to find uds_client_id %d\",\n            uds_client_id);\n        return 1;\n    }\n    con = uds_client->con;\n    out_s = trans_get_out_s(con, 8192);\n    if (out_s == NULL)\n    {\n        return 1;\n    }\n    s_push_layer(out_s, iso_hdr, 8);\n    out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */\n    s_mark_end(out_s);\n    bytes = (int) (out_s->end - out_s->data);\n    s_pop_layer(out_s, iso_hdr);\n    out_uint32_le(out_s, bytes - 8);\n    out_uint32_le(out_s, 0x0D); /* SCARD_CANCEL 0x0D */\n    return trans_force_write(con);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nscard_function_is_context_valid_return(void *user_data,\n                                       struct stream *in_s,\n                                       int len, int status)\n{\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint scard_function_reconnect_return(void *user_data,\n                                    struct stream *in_s,\n                                    int len, int status)\n{\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nscard_process_msg(struct trans *con, struct stream *in_s, int command)\n{\n    int rv;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_process_msg: command 0x%4.4x\", command);\n    rv = 0;\n    switch (command)\n    {\n        case 0x01: /* SCARD_ESTABLISH_CONTEXT */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_ESTABLISH_CONTEXT\");\n            rv = scard_process_establish_context(con, in_s);\n            break;\n        case 0x02: /* SCARD_RELEASE_CONTEXT */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_RELEASE_CONTEXT\");\n            rv = scard_process_release_context(con, in_s);\n            break;\n\n        case 0x03: /* SCARD_LIST_READERS */\n            /* This is only called from xrdp_pcsc.c */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_LIST_READERS\");\n            rv = scard_process_list_readers(con, in_s);\n            break;\n\n        case 0x04: /* SCARD_CONNECT */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_CONNECT\");\n            rv = scard_process_connect(con, in_s);\n            break;\n\n        case 0x05: /* SCARD_RECONNECT */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_RECONNECT\");\n            break;\n\n        case 0x06: /* SCARD_DISCONNECT */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_DISCONNECT\");\n            rv = scard_process_disconnect(con, in_s);\n            break;\n\n        case 0x07: /* SCARD_BEGIN_TRANSACTION */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_BEGIN_TRANSACTION\");\n            rv = scard_process_begin_transaction(con, in_s);\n            break;\n\n        case 0x08: /* SCARD_END_TRANSACTION */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_END_TRANSACTION\");\n            rv = scard_process_end_transaction(con, in_s);\n            break;\n\n        case 0x09: /* SCARD_TRANSMIT */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_TRANSMIT\");\n            rv = scard_process_transmit(con, in_s);\n            break;\n\n        case 0x0A: /* SCARD_CONTROL */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_CONTROL\");\n            rv = scard_process_control(con, in_s);\n            break;\n\n        case 0x0B: /* SCARD_STATUS */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_STATUS\");\n            rv = scard_process_status(con, in_s);\n            break;\n\n        case 0x0C: /* SCARD_GET_STATUS_CHANGE */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_GET_STATUS_CHANGE\");\n            rv = scard_process_get_status_change(con, in_s);\n            break;\n\n        case 0x0D: /* SCARD_CANCEL */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_CANCEL\");\n            rv = scard_process_cancel(con, in_s);\n            break;\n\n        case 0x0E: /* SCARD_CANCEL_TRANSACTION */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_CANCEL_TRANSACTION\");\n            break;\n\n        case 0x0F: /* SCARD_GET_ATTRIB */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_GET_ATTRIB\");\n            break;\n\n        case 0x10: /* SCARD_SET_ATTRIB */\n            LOG_DEVEL(LOG_LEVEL_INFO, \"scard_process_msg: SCARD_SET_ATTRIB\");\n            break;\n\n        default:\n            LOG_DEVEL(LOG_LEVEL_WARNING, \"scard_process_msg: unknown mtype 0x%4.4x\", command);\n            rv = 1;\n            break;\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nmy_pcsc_trans_data_in(struct trans *trans)\n{\n    struct stream *s;\n    int size;\n    int command;\n    int error;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_pcsc_trans_data_in:\");\n    if (trans == 0)\n    {\n        return 0;\n    }\n    s = trans_get_in_s(trans);\n    in_uint32_le(s, size);\n    in_uint32_le(s, command);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_pcsc_trans_data_in: size %d command %d\", size, command);\n    error = trans_force_read(trans, size);\n    if (error == 0)\n    {\n        error = scard_process_msg(trans, s, command);\n    }\n    return error;\n}\n\n/*****************************************************************************/\n/* got a new connection from libpcsclite */\nstatic int\nmy_pcsc_trans_conn_in(struct trans *trans, struct trans *new_trans)\n{\n    struct pcsc_uds_client *uds_client;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"my_pcsc_trans_conn_in:\");\n\n    if (trans == 0)\n    {\n        return 1;\n    }\n\n    if (trans != g_lis)\n    {\n        return 1;\n    }\n\n    if (new_trans == 0)\n    {\n        return 1;\n    }\n\n    uds_client = create_uds_client(new_trans);\n    if (uds_client == 0)\n    {\n        return 1;\n    }\n    uds_client->con->trans_data_in = my_pcsc_trans_data_in;\n    uds_client->con->header_size = 8;\n\n    if (g_uds_clients == 0)\n    {\n        g_uds_clients = list_create();\n    }\n    list_add_item(g_uds_clients, (tbus)uds_client);\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nscard_pcsc_init(void)\n{\n    char *home;\n    int error;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_pcsc_init:\");\n    if (g_lis == 0)\n    {\n        g_lis = trans_create(2, 8192, 8192);\n        // TODO: See #2501. Use needs a way to move PCSCLITE_CSOCK_NAME\n        // to a location not under $HOME.\n        home = g_getenv(\"HOME\");\n        g_snprintf(g_pcsclite_ipc_dir, sizeof(g_pcsclite_ipc_dir),\n                   \"%s/.pcsc%s\", home, g_display_str);\n\n        if (g_directory_exist(g_pcsclite_ipc_dir))\n        {\n            if (!g_remove_dir(g_pcsclite_ipc_dir))\n            {\n                LOG_DEVEL(LOG_LEVEL_WARNING, \"scard_pcsc_init: g_remove_dir failed\");\n            }\n        }\n        if (!g_directory_exist(g_pcsclite_ipc_dir))\n        {\n            if (!g_create_dir(g_pcsclite_ipc_dir))\n            {\n                if (!g_directory_exist(g_pcsclite_ipc_dir))\n                {\n                    LOG_DEVEL(LOG_LEVEL_WARNING, \"scard_pcsc_init: g_create_dir failed\");\n                }\n            }\n        }\n        /* Only the current user should be able to access the remote\n         * smartcard */\n        g_chmod_hex(g_pcsclite_ipc_dir, 0x700);\n        g_snprintf(g_pcsclite_ipc_file, sizeof(g_pcsclite_ipc_file),\n                   \"%s/pcscd.comm\", g_pcsclite_ipc_dir);\n        g_lis->trans_conn_in = my_pcsc_trans_conn_in;\n        error = trans_listen(g_lis, g_pcsclite_ipc_file);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"scard_pcsc_init: trans_listen failed for port %s\",\n                g_pcsclite_ipc_file);\n            return 1;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nscard_pcsc_deinit(void)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"scard_pcsc_deinit:\");\n\n    if (g_lis != 0)\n    {\n        trans_delete(g_lis);\n        g_lis = 0;\n    }\n\n    if (g_pcsclite_ipc_dir[0] != 0)\n    {\n        g_file_delete(g_pcsclite_ipc_file);\n        if (!g_remove_dir(g_pcsclite_ipc_dir))\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING, \"scard_pcsc_deinit: g_remove_dir failed\");\n        }\n        g_pcsclite_ipc_dir[0] = 0;\n    }\n\n    return 0;\n}\n\n#else\n\nint\nscard_pcsc_get_wait_objs(tbus *objs, int *count, int *timeout)\n{\n    return 0;\n}\nint\nscard_pcsc_check_wait_objs(void)\n{\n    return 0;\n}\nint\nscard_pcsc_init(void)\n{\n    return 0;\n}\nint\nscard_pcsc_deinit(void)\n{\n    return 0;\n}\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/smartcard_pcsc.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2013 jay.sorg@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/*\n * smartcard redirection support, PCSC daemon standin\n */\n\n#ifndef _SMARTCARD_PCSC_H\n#define _SMARTCARD_PCSC_H\n\nint scard_pcsc_get_wait_objs(tbus *objs, int *count, int *timeout);\nint scard_pcsc_check_wait_objs(void);\nint scard_pcsc_init(void);\nint scard_pcsc_deinit(void);\nint scard_function_establish_context_return(void *user_data,\n        struct stream *in_s,\n        int len, int status);\nint scard_function_release_context_return(void *user_data,\n        struct stream *in_s,\n        int len, int status);\nint scard_function_list_readers_return(void *user_data,\n                                       struct stream *in_s,\n                                       int len, int status);\n\nint scard_function_transmit_return(void *user_data,\n                                   struct stream *in_s,\n                                   int len, int status);\n\nint scard_function_control_return(void *user_data,\n                                  struct stream *in_s,\n                                  int len, int status);\n\nint scard_function_get_status_change_return(void *user_data,\n        struct stream *in_s,\n        int len, int status);\n\nint scard_function_connect_return(void *user_data,\n                                  struct stream *in_s,\n                                  int len, int status);\n\nint scard_function_status_return(void *user_data,\n                                 struct stream *in_s,\n                                 int len, int status);\n\nint scard_function_begin_transaction_return(void *user_data,\n        struct stream *in_s,\n        int len, int status);\n\nint scard_function_end_transaction_return(void *user_data,\n        struct stream *in_s,\n        int len, int status);\n\nint scard_function_is_context_valid_return(void *user_data,\n        struct stream *in_s,\n        int len, int status);\n\nint scard_function_reconnect_return(void *user_data,\n                                    struct stream *in_s,\n                                    int len, int status);\n\nint scard_function_disconnect_return(void *user_data,\n                                     struct stream *in_s,\n                                     int len, int status);\n\nint scard_function_cancel_return(void *user_data,\n                                 struct stream *in_s,\n                                 int len, int status);\n\nint scard_function_get_attrib_return(void *user_data,\n                                     struct stream *in_s,\n                                     int len, int status);\n\n#endif /* end #ifndef _SMARTCARD_PCSC_H */\n"
  },
  {
    "path": "sesman/chansrv/sound.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2009-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/socket.h>\n#include <errno.h>\n#include <signal.h>\n#include <sys/un.h>\n\n#include \"sound.h\"\n#include \"thread_calls.h\"\n#include \"defines.h\"\n#include \"fifo.h\"\n#include \"xrdp_constants.h\"\n#include \"xrdp_sockets.h\"\n#include \"chansrv_common.h\"\n#include \"chansrv_config.h\"\n#include \"list.h\"\n#include \"audin.h\"\n\n#if defined(XRDP_FDK_AAC)\n#include <fdk-aac/aacenc_lib.h>\nstatic HANDLE_AACENCODER g_fdk_aac_encoder = 0;\n\n#if defined(AACENCODER_LIB_VL0)\n#define AACENCODER_LIB_VER_GTEQ(vl0, vl1, vl2) \\\n    ((AACENCODER_LIB_VL0 > vl0) || \\\n     (AACENCODER_LIB_VL0 == vl0 && AACENCODER_LIB_VL1 > vl1) || \\\n     (AACENCODER_LIB_VL0 == vl0 && AACENCODER_LIB_VL1 == vl1 && AACENCODER_LIB_VL2 >= vl2))\n#else\n#define AACENCODER_LIB_VER_GTEQ(vl0, vl1, vl2) 0\n#endif // AACENCODER_LIB_VL0\n#endif // XRDP_FDK_AAC\n\n#if defined(XRDP_OPUS)\n#include <opus/opus.h>\nstatic OpusEncoder *g_opus_encoder = 0;\n#endif\n\n#if defined(XRDP_MP3LAME)\n#include <lame/lame.h>\nstatic lame_global_flags *g_lame_encoder = 0;\n#endif\n\nextern int g_rdpsnd_chan_id;    /* in chansrv.c */\nextern char g_display_str[];    /* in chansrv.c */\nextern struct config_chansrv *g_cfg; /* in chansrv.c */\n\n/* audio out: sound_server -> xrdp -> NeutrinoRDP */\nstatic struct trans *g_audio_l_trans_out = 0; /* listener */\nstatic struct trans *g_audio_c_trans_out = 0; /* connection */\n\n/* audio in:  sound_server <- xrdp <- NeutrinoRDP */\nstatic struct trans *g_audio_l_trans_in = 0;  /* listener */\nstatic struct trans *g_audio_c_trans_in = 0;  /* connection */\n\nstatic unsigned int g_training_sent_time = 0;\nstatic int    g_cBlockNo = 0;\nstatic int    g_bytes_in_stream = 0;\nstruct fifo  *g_in_fifo;\nint    g_bytes_in_fifo = 0;\nstatic int    g_time_diff = 0;\nstatic int    g_best_time_diff = 0;\n\n\nstatic struct stream *g_stream_inp = NULL;\nstatic struct stream *g_stream_incoming_packet = NULL;\n\n#define MAX_BBUF_SIZE (1024 * 16)\nstatic char g_buffer[MAX_BBUF_SIZE];\nstatic int g_buf_index = 0;\nstatic unsigned int g_sent_time[256];\n\nstatic int g_bbuf_size = 1024 * 8; /* may change later */\n\nstatic struct list *g_ack_time_diff = 0;\n\nstruct xr_wave_format_ex\n{\n    int wFormatTag;\n    int nChannels;\n    int nSamplesPerSec;\n    int nAvgBytesPerSec;\n    int nBlockAlign;\n    int wBitsPerSample;\n    int cbSize;\n    tui8 *data;\n};\n\n/* output formats */\n\nstatic tui8 g_pcm_22050_data[] = { 0 };\nstatic struct xr_wave_format_ex g_pcm_22050 =\n{\n    WAVE_FORMAT_PCM, /* wFormatTag */\n    2,               /* num of channels */\n    22050,           /* samples per sec */\n    88200,           /* avg bytes per sec */\n    4,               /* block align */\n    16,              /* bits per sample */\n    0,               /* data size */\n    g_pcm_22050_data /* data */\n};\n\nstatic tui8 g_pcm_44100_data[] = { 0 };\nstatic struct xr_wave_format_ex g_pcm_44100 =\n{\n    WAVE_FORMAT_PCM, /* wFormatTag */\n    2,               /* num of channels */\n    44100,           /* samples per sec */\n    176400,          /* avg bytes per sec */\n    4,               /* block align */\n    16,              /* bits per sample */\n    0,               /* data size */\n    g_pcm_44100_data /* data */\n};\n\n#if defined(XRDP_FDK_AAC)\nstatic tui8 g_fdk_aac_44100_data[] = { 0 };\nstatic struct xr_wave_format_ex g_fdk_aac_44100 =\n{\n    WAVE_FORMAT_AAC,     /* wFormatTag */\n    2,                   /* num of channels */\n    44100,               /* samples per sec */\n    12000,               /* avg bytes per sec */\n    4,                   /* block align */\n    16,                  /* bits per sample */\n    0,                   /* data size */\n    g_fdk_aac_44100_data /* data */\n};\n#endif\n\n#if defined(XRDP_OPUS)\nstatic tui8 g_opus_44100_data[] = { 0 };\nstatic struct xr_wave_format_ex g_opus_44100 =\n{\n    WAVE_FORMAT_OPUS, /* wFormatTag */\n    2,                /* num of channels */\n    44100,            /* samples per sec */\n    176400,           /* avg bytes per sec */\n    4,                /* block align */\n    16,               /* bits per sample */\n    0,                /* data size */\n    g_opus_44100_data /* data */\n};\n#endif\n\n#if defined(XRDP_MP3LAME)\nstatic tui8 g_mp3lame_44100_data[] = { 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0xb6, 0x00, 0x01, 0x00, 0x71, 0x05 };\nstatic struct xr_wave_format_ex g_mp3lame_44100 =\n{\n    WAVE_FORMAT_MPEGLAYER3, /* wFormatTag */\n    2,                      /* num of channels */\n    44100,                  /* samples per sec */\n    176400,                 /* avg bytes per sec */\n    4,                      /* block align */\n    0,                      /* bits per sample */\n    12,                     /* data size */\n    g_mp3lame_44100_data    /* data */\n};\n#endif\n\nstatic struct xr_wave_format_ex *g_wave_outp_formats[] =\n{\n    &g_pcm_44100,\n    &g_pcm_22050,\n#if defined(XRDP_FDK_AAC)\n    &g_fdk_aac_44100,\n#endif\n#if defined(XRDP_OPUS)\n    &g_opus_44100,\n#endif\n#if defined(XRDP_MP3LAME)\n    &g_mp3lame_44100,\n#endif\n    0\n};\n\nstatic int g_client_does_fdk_aac = 0;\nstatic int g_client_fdk_aac_index = 0;\n\nstatic int g_client_does_opus = 0;\nstatic int g_client_opus_index = 0;\n\nstatic int g_client_does_mp3lame = 0;\nstatic int g_client_mp3lame_index = 0;\n\n/* index into list from client */\nstatic int g_current_client_format_index = 0;\n\n/* index into list from server */\nstatic int g_current_server_format_index = 0;\n\n/* input formats */\n\nstatic tui8 g_pcm_inp_22050_data[] = { 0 };\nstatic struct xr_wave_format_ex g_pcm_inp_22050 =\n{\n    WAVE_FORMAT_PCM, /* wFormatTag */\n    2,               /* num of channels */\n    22050,           /* samples per sec */\n    88200,           /* avg bytes per sec */\n    4,               /* block align */\n    16,              /* bits per sample */\n    0,               /* data size */\n    g_pcm_inp_22050_data /* data */\n};\n\nstatic tui8 g_pcm_inp_44100_data[] = { 0 };\nstatic struct xr_wave_format_ex g_pcm_inp_44100 =\n{\n    WAVE_FORMAT_PCM, /* wFormatTag */\n    2,               /* num of channels */\n    44100,           /* samples per sec */\n    176400,          /* avg bytes per sec */\n    4,               /* block align */\n    16,              /* bits per sample */\n    0,               /* data size */\n    g_pcm_inp_44100_data /* data */\n};\n\nstatic struct xr_wave_format_ex *g_wave_inp_formats[] =\n{\n    &g_pcm_inp_44100,\n    &g_pcm_inp_22050,\n    0\n};\n\nstatic int g_rdpsnd_can_rec = 0;\n\nstatic int g_client_input_format_index = 0;\nstatic int g_server_input_format_index = 0;\n\n/* microphone related */\nstatic int sound_send_server_input_formats(void);\nstatic int sound_process_input_format(int aindex, int wFormatTag,\n                                      int nChannels, int nSamplesPerSec,\n                                      int nAvgBytesPerSec, int nBlockAlign,\n                                      int wBitsPerSample, int cbSize, char *data);\nstatic int sound_process_input_formats(struct stream *s, int size);\nstatic int sound_input_start_recording(void);\nstatic int sound_input_stop_recording(void);\nstatic int sound_process_input_data(struct stream *s, int bytes);\nstatic int sound_sndsrvr_source_data_in(struct trans *trans);\nstatic int sound_start_source_listener(void);\nstatic int sound_start_sink_listener(void);\n\n/*****************************************************************************/\nstatic int\nsound_send_server_output_formats(void)\n{\n    struct stream *s;\n    int bytes;\n    int index;\n    int num_formats;\n    char *size_ptr;\n\n    num_formats = sizeof(g_wave_outp_formats) /\n                  sizeof(g_wave_outp_formats[0]) - 1;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_send_server_output_formats: num_formats %d\", num_formats);\n\n    make_stream(s);\n    init_stream(s, 8182);\n    out_uint16_le(s, SNDC_FORMATS);\n    size_ptr = s->p;\n    out_uint16_le(s, 0);                    /* size, set later */\n    out_uint32_le(s, 0);                    /* dwFlags */\n    out_uint32_le(s, 0);                    /* dwVolume */\n    out_uint32_le(s, 0);                    /* dwPitch */\n    out_uint16_le(s, 0);                    /* wDGramPort */\n    out_uint16_le(s, num_formats);          /* wNumberOfFormats */\n    out_uint8(s, g_cBlockNo);               /* cLastBlockConfirmed */\n    out_uint16_le(s, 5);                    /* wVersion */\n    out_uint8(s, 0);                        /* bPad */\n\n    /* sndFormats */\n    /*\n        wFormatTag      2 byte offset 0\n        nChannels       2 byte offset 2\n        nSamplesPerSec  4 byte offset 4\n        nAvgBytesPerSec 4 byte offset 8\n        nBlockAlign     2 byte offset 12\n        wBitsPerSample  2 byte offset 14\n        cbSize          2 byte offset 16\n        data            variable offset 18\n    */\n\n    /*  examples\n        01 00 02 00 44 ac 00 00 10 b1 02 00 04 00 10 00 ....D...........\n        00 00\n        01 00 02 00 22 56 00 00 88 58 01 00 04 00 10 00 ....\"V...X......\n        00 00\n    */\n\n    for (index = 0; index < num_formats; index++)\n    {\n        out_uint16_le(s, g_wave_outp_formats[index]->wFormatTag);\n        out_uint16_le(s, g_wave_outp_formats[index]->nChannels);\n        out_uint32_le(s, g_wave_outp_formats[index]->nSamplesPerSec);\n        out_uint32_le(s, g_wave_outp_formats[index]->nAvgBytesPerSec);\n        out_uint16_le(s, g_wave_outp_formats[index]->nBlockAlign);\n        out_uint16_le(s, g_wave_outp_formats[index]->wBitsPerSample);\n        bytes = g_wave_outp_formats[index]->cbSize;\n        out_uint16_le(s, bytes);\n        if (bytes > 0)\n        {\n            out_uint8p(s, g_wave_outp_formats[index]->data, bytes);\n        }\n    }\n\n    s_mark_end(s);\n    bytes = (int)((s->end - s->data) - 4);\n    size_ptr[0] = bytes;\n    size_ptr[1] = bytes >> 8;\n    bytes = (int)(s->end - s->data);\n    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nsound_send_training(void)\n{\n    struct stream *s;\n    int bytes;\n    unsigned int time;\n    char *size_ptr;\n\n    make_stream(s);\n    init_stream(s, 8182);\n    out_uint16_le(s, SNDC_TRAINING);\n    size_ptr = s->p;\n    out_uint16_le(s, 0); /* size, set later */\n    time = g_get_elapsed_ms();\n    g_training_sent_time = time;\n    out_uint16_le(s, time);\n    out_uint16_le(s, 1024);\n    out_uint8s(s, (1024 - 4));\n    s_mark_end(s);\n    bytes = (int)((s->end - s->data) - 4);\n    size_ptr[0] = bytes;\n    size_ptr[1] = bytes >> 8;\n    bytes = (int)(s->end - s->data);\n    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nsound_process_output_format(int aindex, int wFormatTag, int nChannels,\n                            int nSamplesPerSec, int nAvgBytesPerSec,\n                            int nBlockAlign, int wBitsPerSample,\n                            int cbSize, char *data)\n{\n    LOG(LOG_LEVEL_INFO, \"sound_process_output_format:\");\n    LOG(LOG_LEVEL_INFO, \"      wFormatNo       %d\", aindex);\n    LOG(LOG_LEVEL_INFO, \"      wFormatTag      %s\", audin_wave_format_tag_to_str(wFormatTag));\n    LOG(LOG_LEVEL_INFO, \"      nChannels       %d\", nChannels);\n    LOG(LOG_LEVEL_INFO, \"      nSamplesPerSec  %d\", nSamplesPerSec);\n    LOG(LOG_LEVEL_INFO, \"      nAvgBytesPerSec %d\", nAvgBytesPerSec);\n    LOG(LOG_LEVEL_INFO, \"      nBlockAlign     %d\", nBlockAlign);\n    LOG(LOG_LEVEL_INFO, \"      wBitsPerSample  %d\", wBitsPerSample);\n    LOG(LOG_LEVEL_INFO, \"      cbSize          %d\", cbSize);\n\n    LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"\", data, cbSize);\n\n    /* select CD quality audio */\n    if (wFormatTag == g_pcm_44100.wFormatTag &&\n            nChannels == g_pcm_44100.nChannels &&\n            nSamplesPerSec == g_pcm_44100.nSamplesPerSec &&\n            nAvgBytesPerSec == g_pcm_44100.nAvgBytesPerSec &&\n            nBlockAlign == g_pcm_44100.nBlockAlign &&\n            wBitsPerSample == g_pcm_44100.wBitsPerSample)\n    {\n        g_current_client_format_index = aindex;\n        g_current_server_format_index = 0;\n    }\n#if 0\n    for (lindex = 0; lindex < NUM_BUILT_IN; lindex++)\n    {\n        if (wFormatTag == g_wave_formats[lindex]->wFormatTag &&\n                nChannels == g_wave_formats[lindex]->nChannels &&\n                nSamplesPerSec == g_wave_formats[lindex]->nSamplesPerSec &&\n                nAvgBytesPerSec == g_wave_formats[lindex]->nAvgBytesPerSec &&\n                nBlockAlign == g_wave_formats[lindex]->nBlockAlign &&\n                wBitsPerSample == g_wave_formats[lindex]->wBitsPerSample)\n        {\n            g_current_client_format_index = aindex;\n            g_current_server_format_index = lindex;\n        }\n    }\n#endif\n\n    switch (wFormatTag)\n    {\n        case WAVE_FORMAT_AAC:\n            LOG_DEVEL(LOG_LEVEL_INFO, \"wFormatTag, fdk aac\");\n            g_client_does_fdk_aac = 1;\n            g_client_fdk_aac_index = aindex;\n            break;\n        case WAVE_FORMAT_MPEGLAYER3:\n            LOG_DEVEL(LOG_LEVEL_INFO, \"wFormatTag, mp3\");\n            g_client_does_mp3lame = 1;\n            g_client_mp3lame_index = aindex;\n            break;\n        case WAVE_FORMAT_OPUS:\n            LOG_DEVEL(LOG_LEVEL_INFO, \"wFormatTag, opus\");\n            g_client_does_opus = 1;\n            g_client_opus_index = aindex;\n            break;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/*\n    0000 07 02 26 00 03 00 80 00 ff ff ff ff 00 00 00 00 ..&.............\n    0010 00 00 01 00 00 02 00 00 01 00 02 00 44 ac 00 00 ............D...\n    0020 10 b1 02 00 04 00 10 00 00 00\n*/\n\nstatic int\nsound_process_output_formats(struct stream *s, int size)\n{\n    int num_formats;\n    int index;\n    int wFormatTag;\n    int nChannels;\n    int nSamplesPerSec;\n    int nAvgBytesPerSec;\n    int nBlockAlign;\n    int wBitsPerSample;\n    int cbSize;\n    char *data;\n\n    if (size < 16)\n    {\n        return 1;\n    }\n\n    in_uint8s(s, 14);\n    in_uint16_le(s, num_formats);\n    in_uint8s(s, 4);\n\n    if (num_formats > 0)\n    {\n        for (index = 0; index < num_formats; index++)\n        {\n            in_uint16_le(s, wFormatTag);\n            in_uint16_le(s, nChannels);\n            in_uint32_le(s, nSamplesPerSec);\n            in_uint32_le(s, nAvgBytesPerSec);\n            in_uint16_le(s, nBlockAlign);\n            in_uint16_le(s, wBitsPerSample);\n            in_uint16_le(s, cbSize);\n            in_uint8p(s, data, cbSize);\n            sound_process_output_format(index, wFormatTag, nChannels, nSamplesPerSec,\n                                        nAvgBytesPerSec, nBlockAlign, wBitsPerSample,\n                                        cbSize, data);\n        }\n        sound_send_training();\n    }\n\n    return 0;\n}\n\n#if defined(XRDP_FDK_AAC)\n\n/*****************************************************************************/\nstatic int\nsound_wave_compress_fdk_aac(char *data, int data_bytes, int *format_index)\n{\n    int rv;\n    int cdata_bytes;\n    char *cdata;\n\n    AACENC_ERROR error;\n    int aot;\n    int sample_rate;\n    int mode;\n    int bitrate;\n    int afterburner;\n    int channel_order;\n    AACENC_InfoStruct info;\n    AACENC_BufDesc in_buf;\n    AACENC_BufDesc out_buf;\n    AACENC_InArgs in_args;\n    AACENC_OutArgs out_args;\n    void *in_buffer;\n    int in_identifier;\n    int in_size;\n    int in_elem_size;\n    void *out_buffer;\n    int out_identifier;\n    int out_size;\n    int out_elem_size;\n\n    rv = data_bytes;\n\n    if (g_client_does_fdk_aac == 0)\n    {\n        return rv;\n    }\n\n    if (g_fdk_aac_encoder == 0)\n    {\n        /* init fdk aac encoder */\n        LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: using fdk aac\");\n\n        error = aacEncOpen(&g_fdk_aac_encoder, 0, 2);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"sound_wave_compress_fdk_aac: aacEncOpen() failed\");\n            return rv;\n        }\n\n        aot = 2; /* MPEG-4 AAC Low Complexity. */\n        error = aacEncoder_SetParam(g_fdk_aac_encoder, AACENC_AOT, aot);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: aacEncoder_SetParam() \"\n                      \"AACENC_AOT failed\");\n        }\n\n        sample_rate = g_fdk_aac_44100.nSamplesPerSec;\n        error = aacEncoder_SetParam(g_fdk_aac_encoder, AACENC_SAMPLERATE,\n                                    sample_rate);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: aacEncoder_SetParam() \"\n                      \"AACENC_SAMPLERATE failed\");\n        }\n\n        mode = MODE_2;\n        error = aacEncoder_SetParam(g_fdk_aac_encoder,\n                                    AACENC_CHANNELMODE, mode);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: aacEncoder_SetParam() \"\n                      \"AACENC_CHANNELMODE failed\");\n        }\n\n        channel_order = 1; /* WAVE file format channel ordering */\n        error = aacEncoder_SetParam(g_fdk_aac_encoder, AACENC_CHANNELORDER,\n                                    channel_order);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: aacEncoder_SetParam() \"\n                      \"AACENC_CHANNELORDER failed\");\n        }\n\n        /* bytes rate to bit rate */\n        bitrate = g_fdk_aac_44100.nAvgBytesPerSec * 8;\n        error = aacEncoder_SetParam(g_fdk_aac_encoder, AACENC_BITRATE,\n                                    bitrate);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: aacEncoder_SetParam() \"\n                      \"AACENC_BITRATE failed\");\n        }\n\n        error = aacEncoder_SetParam(g_fdk_aac_encoder, AACENC_TRANSMUX, 0);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: aacEncoder_SetParam() \"\n                      \"AACENC_TRANSMUX failed\");\n        }\n\n        afterburner = 1;\n        error = aacEncoder_SetParam(g_fdk_aac_encoder, AACENC_AFTERBURNER,\n                                    afterburner);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: aacEncoder_SetParam() \"\n                      \"AACENC_AFTERBURNER failed\");\n        }\n\n        error = aacEncEncode(g_fdk_aac_encoder, NULL, NULL, NULL, NULL);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: Unable to initialize \"\n                      \"the encoder\");\n        }\n\n        g_memset(&info, 0, sizeof(info));\n        error = aacEncInfo(g_fdk_aac_encoder, &info);\n        if (error != AACENC_OK)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac: aacEncInfo failed\");\n        }\n\n        LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_fdk_aac:\");\n        LOG_DEVEL(LOG_LEVEL_INFO, \"  AACENC_InfoStruct\");\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    maxOutBufBytes %d\", info.maxOutBufBytes);\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    maxAncBytes %d\", info.maxAncBytes);\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    inBufFillLevel %d\", info.inBufFillLevel);\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    inputChannels %d\", info.inputChannels);\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    frameLength %d\", info.frameLength);\n#if AACENCODER_LIB_VER_GTEQ(4, 0, 0)\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    nDelay %d\", info.nDelay);\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    nDelayCore %d\", info.nDelayCore);\n#else\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    encoderDelay %d\", info.encoderDelay);\n#endif\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    confBuf\");\n        LOG_DEVEL(LOG_LEVEL_INFO, \"    confSize %d\", info.confSize);\n    }\n\n    rv = data_bytes;\n    cdata_bytes = data_bytes;\n    cdata = (char *) g_malloc(cdata_bytes, 0);\n    if (data_bytes < g_bbuf_size)\n    {\n        g_memset(data + data_bytes, 0, g_bbuf_size - data_bytes);\n        data_bytes = g_bbuf_size;\n    }\n\n    in_buffer = data;\n    in_identifier = IN_AUDIO_DATA;\n    in_size = data_bytes;\n    in_elem_size = 2;\n\n    g_memset(&in_args, 0, sizeof(in_args));\n    in_args.numInSamples = data_bytes / 2;\n    g_memset(&in_buf, 0, sizeof(in_buf));\n    in_buf.numBufs = 1;\n    in_buf.bufs = &in_buffer;\n    in_buf.bufferIdentifiers = &in_identifier;\n    in_buf.bufSizes = &in_size;\n    in_buf.bufElSizes = &in_elem_size;\n\n    out_buffer = cdata;\n    out_identifier = OUT_BITSTREAM_DATA;\n    out_size = cdata_bytes;\n    out_elem_size = 1;\n\n    g_memset(&out_buf, 0, sizeof(out_buf));\n    out_buf.numBufs = 1;\n    out_buf.bufs = &out_buffer;\n    out_buf.bufferIdentifiers = &out_identifier;\n    out_buf.bufSizes = &out_size;\n    out_buf.bufElSizes = &out_elem_size;\n\n    g_memset(&out_args, 0, sizeof(out_args));\n    error = aacEncEncode(g_fdk_aac_encoder, &in_buf, &out_buf,\n                         &in_args, &out_args);\n    if (error == AACENC_OK)\n    {\n        cdata_bytes = out_args.numOutBytes;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_wave_compress_fdk_aac: aacEncEncode ok \"\n                  \"cdata_bytes %d\", cdata_bytes);\n        *format_index = g_client_fdk_aac_index;\n        g_memcpy(data, cdata, cdata_bytes);\n        rv = cdata_bytes;\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"sound_wave_compress_fdk_aac: aacEncEncode failed\");\n    }\n    g_free(cdata);\n\n    return rv;\n}\n\n#else\n\n/*****************************************************************************/\nstatic int\nsound_wave_compress_fdk_aac(char *data, int data_bytes, int *format_index)\n{\n    return data_bytes;\n}\n\n#endif\n\n#if defined(XRDP_OPUS)\n\n/*****************************************************************************/\nstatic int\nsound_wave_compress_opus(char *data, int data_bytes, int *format_index)\n{\n    unsigned char *cdata;\n    int cdata_bytes;\n    int rv;\n    int error;\n    int data_bytes_org;\n    opus_int16 *os16;\n\n    if (g_client_does_opus == 0)\n    {\n        return data_bytes;\n    }\n    if (g_opus_encoder == 0)\n    {\n        /* NB (narrowband)       8 kHz\n           MB (medium-band)     12 kHz\n           WB (wideband)        16 kHz\n           SWB (super-wideband) 24 kHz\n           FB (fullband)        48 kHz */\n        g_opus_encoder = opus_encoder_create(48000, 2,\n                                             OPUS_APPLICATION_AUDIO,\n                                             &error);\n        if (g_opus_encoder == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"sound_wave_compress_opus: opus_encoder_create failed\");\n            return data_bytes;\n        }\n    }\n    data_bytes_org = data_bytes;\n    rv = data_bytes;\n    cdata_bytes = data_bytes;\n    cdata = (unsigned char *) g_malloc(cdata_bytes, 0);\n    os16 = (opus_int16 *) data;\n    /* at 48000 we have\n       2.5 ms   480\n       5   ms   960\n       10  ms  1920\n       20  ms  3840\n       40  ms  7680\n       60  ms 11520 */\n    if (data_bytes < g_bbuf_size)\n    {\n        g_memset(data + data_bytes, 0, g_bbuf_size - data_bytes);\n        data_bytes = g_bbuf_size;\n    }\n    cdata_bytes = opus_encode(g_opus_encoder, os16, data_bytes / 4,\n                              cdata, cdata_bytes);\n    if ((cdata_bytes > 0) && (cdata_bytes < data_bytes_org))\n    {\n        *format_index = g_client_opus_index;\n        g_memcpy(data, cdata, cdata_bytes);\n        rv = cdata_bytes;\n    }\n    g_free(cdata);\n    return rv;\n}\n\n#else\n\n/*****************************************************************************/\nstatic int\nsound_wave_compress_opus(char *data, int data_bytes, int *format_index)\n{\n    return data_bytes;\n}\n\n#endif\n\n#if defined(XRDP_MP3LAME)\n\n/*****************************************************************************/\nstatic int\nsound_wave_compress_mp3lame(char *data, int data_bytes, int *format_index)\n{\n    int rv;\n    int cdata_bytes;\n    int odata_bytes;\n    unsigned char *cdata;\n\n    cdata = NULL;\n    rv = data_bytes;\n\n    if (g_client_does_mp3lame == 0)\n    {\n        return rv;\n    }\n\n    if (g_lame_encoder == 0)\n    {\n        /* init mp3 lame encoder */\n        LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_mp3lame: using mp3lame\");\n\n        g_lame_encoder = lame_init();\n        if (g_lame_encoder == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_mp3lame: lame_init() failed\");\n            return rv;\n        }\n        lame_set_num_channels(g_lame_encoder, g_mp3lame_44100.nChannels);\n        lame_set_in_samplerate(g_lame_encoder, g_mp3lame_44100.nSamplesPerSec);\n        //lame_set_brate(g_lame_encoder, 64);\n        lame_set_quality(g_lame_encoder, 7);\n        if (lame_init_params(g_lame_encoder) == -1)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"sound_wave_compress_mp3lame: lame_init_params() failed\");\n            return rv;\n        }\n\n        LOG_DEVEL(LOG_LEVEL_INFO, \"sound_wave_compress_mp3lame: lame config:\");\n        LOG_DEVEL(LOG_LEVEL_INFO, \"                             brate            : %d\", lame_get_brate(g_lame_encoder));\n        LOG_DEVEL(LOG_LEVEL_INFO, \"                             compression ratio: %f\", lame_get_compression_ratio(g_lame_encoder));\n        LOG_DEVEL(LOG_LEVEL_INFO, \"                             encoder delay    : %d\", lame_get_encoder_delay(g_lame_encoder));\n        LOG_DEVEL(LOG_LEVEL_INFO, \"                             frame size       : %d\", lame_get_framesize(g_lame_encoder));\n        LOG_DEVEL(LOG_LEVEL_INFO, \"                             encoder padding  : %d\", lame_get_encoder_padding(g_lame_encoder));\n        LOG_DEVEL(LOG_LEVEL_INFO, \"                             mode             : %d\", lame_get_mode(g_lame_encoder));\n    }\n\n    odata_bytes = data_bytes;\n    cdata_bytes = data_bytes;\n    cdata = (unsigned char *) g_malloc(cdata_bytes, 0);\n    if (data_bytes < g_bbuf_size)\n    {\n        g_memset(data + data_bytes, 0, g_bbuf_size - data_bytes);\n        data_bytes = g_bbuf_size;\n    }\n    cdata_bytes = lame_encode_buffer_interleaved(g_lame_encoder,\n                  (short int *) data,\n                  data_bytes / 4,\n                  cdata,\n                  cdata_bytes);\n    if (cdata_bytes < 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"sound_wave_compress: lame_encode_buffer_interleaved() \"\n                  \"failed, error %d\", cdata_bytes);\n        return rv;\n    }\n    if ((cdata_bytes > 0) && (cdata_bytes < odata_bytes))\n    {\n        *format_index = g_client_mp3lame_index;\n        g_memcpy(data, cdata, cdata_bytes);\n        rv = cdata_bytes;\n    }\n\n    g_free(cdata);\n    return rv;\n}\n\n#else\n\n/*****************************************************************************/\nstatic int\nsound_wave_compress_mp3lame(char *data, int data_bytes, int *format_index)\n{\n    return data_bytes;\n}\n\n#endif\n\n/*****************************************************************************/\nstatic int\nsound_wave_compress(char *data, int data_bytes, int *format_index)\n{\n    if (g_client_does_fdk_aac)\n    {\n        g_bbuf_size = 4096;\n        return sound_wave_compress_fdk_aac(data, data_bytes, format_index);\n    }\n    else if (g_client_does_opus)\n    {\n        g_bbuf_size = 11520;\n        return sound_wave_compress_opus(data, data_bytes, format_index);\n    }\n    else if (g_client_does_mp3lame)\n    {\n        g_bbuf_size = 11520;\n        return sound_wave_compress_mp3lame(data, data_bytes, format_index);\n    }\n    return data_bytes;\n}\n\n/*****************************************************************************/\n/* send wave message to client */\nstatic int\nsound_send_wave_data_chunk(char *data, int data_bytes)\n{\n    struct stream *s;\n    int bytes;\n    unsigned int time;\n    int format_index;\n    char *size_ptr;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_send_wave_data_chunk: data_bytes %d\", data_bytes);\n\n    if ((data_bytes < 4) || (data_bytes > 128 * 1024))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"sound_send_wave_data_chunk: bad data_bytes %d\", data_bytes);\n        return 1;\n    }\n\n    /* compress, if available */\n    format_index = g_current_client_format_index;\n    data_bytes = sound_wave_compress(data, data_bytes, &format_index);\n\n    LOG(LOG_LEVEL_TRACE, \"sound_send_wave_data_chunk: wFormatNo %d\", format_index);\n\n    /* part one of 2 PDU wave info */\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_send_wave_data_chunk: sending %d bytes\", data_bytes);\n\n    make_stream(s);\n    init_stream(s, 16 + data_bytes); /* some extra space */\n    out_uint16_le(s, SNDC_WAVE);\n    size_ptr = s->p;\n    out_uint16_le(s, 0); /* size, set later */\n    time = g_get_elapsed_ms();\n    out_uint16_le(s, time);\n    out_uint16_le(s, format_index); /* wFormatNo */\n    g_cBlockNo++;\n    out_uint8(s, g_cBlockNo);\n    g_sent_time[g_cBlockNo & 0xff] = time;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_send_wave_data_chunk: sending time %d, g_cBlockNo %d\",\n              time & 0xffff, g_cBlockNo & 0xff);\n\n    out_uint8s(s, 3);\n    out_uint8a(s, data, 4);\n    s_mark_end(s);\n    bytes = (int)((s->end - s->data) - 4);\n    bytes += data_bytes;\n    bytes -= 4;\n    size_ptr[0] = bytes;\n    size_ptr[1] = bytes >> 8;\n    bytes = (int)(s->end - s->data);\n    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);\n\n    /* part two of 2 PDU wave info\n       even is zero, we have to send this */\n    init_stream(s, data_bytes);\n    out_uint32_le(s, 0);\n    out_uint8a(s, data + 4, data_bytes - 4);\n    s_mark_end(s);\n    bytes = (int)(s->end - s->data);\n    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);\n\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/* send wave message to client, buffer first */\nstatic int\nsound_send_wave_data(char *data, int data_bytes)\n{\n    int space_left;\n    int chunk_bytes;\n    int data_index;\n    int error;\n    int res;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_send_wave_data: sending %d bytes\", data_bytes);\n    if (g_time_diff > g_best_time_diff + 250)\n    {\n        data_bytes = data_bytes / 4;\n        data_bytes = data_bytes & ~3;\n        g_memset(data, 0, data_bytes);\n        g_time_diff = 0;\n    }\n    data_index = 0;\n    error = 0;\n    while (data_bytes > 0)\n    {\n        space_left = g_bbuf_size - g_buf_index;\n        chunk_bytes = MIN(space_left, data_bytes);\n        if (chunk_bytes < 1)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_send_wave_data: error\");\n            error = 1;\n            break;\n        }\n        g_memcpy(g_buffer + g_buf_index, data + data_index, chunk_bytes);\n        g_buf_index += chunk_bytes;\n        if (g_buf_index >= g_bbuf_size)\n        {\n            g_buf_index = 0;\n            res = sound_send_wave_data_chunk(g_buffer, g_bbuf_size);\n            if (res == 2)\n            {\n                /* don't need to error on this */\n                LOG_DEVEL(LOG_LEVEL_ERROR, \"sound_send_wave_data: dropped, no room\");\n                break;\n            }\n            else if (res != 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_send_wave_data: error\");\n                error = 1;\n                break;\n            }\n        }\n        data_bytes -= chunk_bytes;\n        data_index += chunk_bytes;\n    }\n\n    return error;\n}\n\n/*****************************************************************************/\n/* send close message to client */\nstatic int\nsound_send_close(void)\n{\n    struct stream *s;\n    int bytes;\n    char *size_ptr;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_send_close:\");\n\n    g_best_time_diff = 0;\n    g_buf_index = 0;\n\n    /* send close msg */\n    make_stream(s);\n    init_stream(s, 8182);\n    out_uint16_le(s, SNDC_CLOSE);\n    size_ptr = s->p;\n    out_uint16_le(s, 0); /* size, set later */\n    s_mark_end(s);\n    bytes = (int)((s->end - s->data) - 4);\n    size_ptr[0] = bytes;\n    size_ptr[1] = bytes >> 8;\n    bytes = (int)(s->end - s->data);\n    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);\n    free_stream(s);\n    return 0;\n}\n\n/*****************************************************************************/\n/* from client */\nstatic int\nsound_process_training(struct stream *s, int size)\n{\n    int time_diff;\n\n    time_diff = g_get_elapsed_ms() - g_training_sent_time;\n    LOG(LOG_LEVEL_INFO, \"sound_process_training: round trip time %u\", time_diff);\n    return 0;\n}\n\n/*****************************************************************************/\n/* from client */\nstatic int\nsound_process_wave_confirm(struct stream *s, int size)\n{\n    int wTimeStamp;\n    int cConfirmedBlockNo;\n    unsigned int time;\n    int time_diff;\n    int index;\n    int acc;\n\n    time = g_get_elapsed_ms();\n    in_uint16_le(s, wTimeStamp);\n    in_uint8(s, cConfirmedBlockNo);\n    time_diff = time - g_sent_time[cConfirmedBlockNo & 0xff];\n\n    LOG(LOG_LEVEL_TRACE, \"sound_process_wave_confirm: wTimeStamp %d, \"\n        \"cConfirmedBlockNo %d time diff %d\",\n        wTimeStamp, cConfirmedBlockNo, time_diff);\n\n    acc = 0;\n    list_add_item(g_ack_time_diff, time_diff);\n    if (g_ack_time_diff->count >= 50)\n    {\n        while (g_ack_time_diff->count > 50)\n        {\n            list_remove_item(g_ack_time_diff, 0);\n        }\n        for (index = 0; index < g_ack_time_diff->count; index++)\n        {\n            acc += list_get_item(g_ack_time_diff, index);\n        }\n        acc = acc / g_ack_time_diff->count;\n        if ((g_best_time_diff < 1) || (g_best_time_diff > acc))\n        {\n            g_best_time_diff = acc;\n        }\n    }\n    g_time_diff = acc;\n    return 0;\n}\n\n/*****************************************************************************/\n/* process message in from the audio source, eg pulse, alsa\n   on it's way to the client. returns error */\nstatic int\nprocess_pcm_message(int id, int size, struct stream *s)\n{\n    static int sending_silence = 0;\n    static unsigned int silence_start_time = 0;\n    switch (id)\n    {\n        case 0:\n            if ((g_client_does_fdk_aac || g_client_does_mp3lame) && sending_silence)\n            {\n                if ((g_get_elapsed_ms() - silence_start_time) < g_cfg->msec_do_not_send)\n                {\n                    /* do not send data within msec_do_not_send msec after SNDC_CLOSE is sent, to avoid stutter. setting from sesman.ini */\n                    return 0;\n                }\n                sending_silence = 0;\n            }\n            return sound_send_wave_data(s->p, size);\n            break;\n        case 1:\n            if ((g_client_does_fdk_aac || g_client_does_mp3lame) && sending_silence == 0)\n            {\n                /* workaround for mstsc.exe. send silence data before send close */\n                int send_silence_times = g_client_does_fdk_aac ? g_cfg->num_silent_frames_aac : g_cfg->num_silent_frames_mp3;  /* setting from sesman.ini */\n                char *buf = (char *) g_malloc(g_bbuf_size, 0);\n                if (buf != NULL)\n                {\n                    int i;\n                    silence_start_time = g_get_elapsed_ms();\n                    sending_silence = 1;\n                    for (i = 0; i < send_silence_times; i++)\n                    {\n                        g_memset(buf, 0, g_bbuf_size);\n                        sound_send_wave_data_chunk(buf, g_bbuf_size);\n                    }\n                    free(buf);\n                    g_time_diff = 0;\n                }\n            }\n            return sound_send_close();\n            break;\n        default:\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"process_pcm_message: unknown id %d\", id);\n            break;\n    }\n    return 1;\n}\n\n/*****************************************************************************/\n\n/* data in from sound_server_sink */\n\nstatic int\nsound_sndsrvr_sink_data_in(struct trans *trans)\n{\n    struct stream *s;\n    int id;\n    int size;\n    int error;\n\n    if (trans == 0)\n    {\n        return 0;\n    }\n\n    if (trans != g_audio_c_trans_out)\n    {\n        return 1;\n    }\n\n    s = trans_get_in_s(trans);\n    in_uint32_le(s, id);\n    in_uint32_le(s, size);\n\n    if ((id & ~3) || (size > 128 * 1024 + 8) || (size < 8))\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"sound_sndsrvr_sink_data_in: bad message id %d size %d\", id, size);\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_sndsrvr_sink_data_in: good message id %d size %d\", id, size);\n\n    error = trans_force_read(trans, size - 8);\n\n    if (error == 0)\n    {\n        /* here, the entire message block is read in, process it */\n        error = process_pcm_message(id, size - 8, s);\n    }\n\n    return error;\n}\n\n/*****************************************************************************/\n\n/* incoming connection on unix domain socket - sound_server_sink -> xrdp */\n\nstatic int\nsound_sndsrvr_sink_conn_in(struct trans *trans, struct trans *new_trans)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"sound_sndsrvr_sink_conn_in:\");\n\n    if (trans == 0)\n    {\n        return 1;\n    }\n\n    if (trans != g_audio_l_trans_out)\n    {\n        return 1;\n    }\n\n    if (g_audio_c_trans_out != 0) /* if already set, error */\n    {\n        return 1;\n    }\n\n    if (new_trans == 0)\n    {\n        return 1;\n    }\n\n    g_audio_c_trans_out = new_trans;\n    g_audio_c_trans_out->trans_data_in = sound_sndsrvr_sink_data_in;\n    g_audio_c_trans_out->header_size = 8;\n    trans_delete(g_audio_l_trans_out);\n    g_audio_l_trans_out = 0;\n\n    return 0;\n}\n\n/*****************************************************************************/\n\n/* incoming connection on unix domain socket - sound_server_source -> xrdp */\n\nstatic int\nsound_sndsrvr_source_conn_in(struct trans *trans, struct trans *new_trans)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"sound_sndsrvr_source_conn_in: client connected\");\n\n    if (trans == 0)\n    {\n        return 1;\n    }\n\n    if (trans != g_audio_l_trans_in)\n    {\n        return 1;\n    }\n\n    if (g_audio_c_trans_in != 0) /* if already set, error */\n    {\n        return 1;\n    }\n\n    if (new_trans == 0)\n    {\n        return 1;\n    }\n\n    g_audio_c_trans_in = new_trans;\n    g_audio_c_trans_in->trans_data_in = sound_sndsrvr_source_data_in;\n    g_audio_c_trans_in->header_size = 8;\n    trans_delete(g_audio_l_trans_in);\n    g_audio_l_trans_in = 0;\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* Item destructor for g_in_fifo\n */\nstatic void\nin_fifo_item_destructor(void *item, void *closure)\n{\n    xstream_free((struct stream *)item);\n}\n\n/*****************************************************************************/\nint\nsound_init(void)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"sound_init:\");\n\n    g_stream_incoming_packet = NULL;\n\n    /* init sound output */\n    sound_send_server_output_formats();\n    sound_start_sink_listener();\n\n    /* init sound input */\n    sound_send_server_input_formats();\n    sound_start_source_listener();\n\n    /* save data from sound_server_source */\n    g_in_fifo = fifo_create(in_fifo_item_destructor);\n\n    g_client_does_fdk_aac = 0;\n    g_client_fdk_aac_index = 0;\n\n    g_client_does_opus = 0;\n    g_client_opus_index = 0;\n\n    g_client_does_mp3lame = 0;\n    g_client_mp3lame_index = 0;\n\n    if (g_ack_time_diff == 0)\n    {\n        g_ack_time_diff = list_create();\n    }\n    list_clear(g_ack_time_diff);\n\n#if defined(XRDP_FDK_AAC) || defined(XRDP_MP3LAME)\n    LOG(LOG_LEVEL_INFO, \"num_silent_frames_aac: %d\", g_cfg->num_silent_frames_aac);\n    LOG(LOG_LEVEL_INFO, \"num_silent_frames_mp3: %d\", g_cfg->num_silent_frames_mp3);\n    LOG(LOG_LEVEL_INFO, \"msec_do_not_send: %d\", g_cfg->msec_do_not_send);\n#endif\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nsound_deinit(void)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_deinit:\");\n    if (g_audio_l_trans_out != 0)\n    {\n        trans_delete(g_audio_l_trans_out);\n        g_audio_l_trans_out = 0;\n    }\n\n    if (g_audio_c_trans_out != 0)\n    {\n        trans_delete(g_audio_c_trans_out);\n        g_audio_c_trans_out = 0;\n    }\n\n    if (g_audio_l_trans_in != 0)\n    {\n        trans_delete(g_audio_l_trans_in);\n        g_audio_l_trans_in = 0;\n    }\n\n    if (g_audio_c_trans_in != 0)\n    {\n        trans_delete(g_audio_c_trans_in);\n        g_audio_c_trans_in = 0;\n    }\n\n#if defined(XRDP_MP3LAME)\n    if (g_lame_encoder)\n    {\n        lame_close(g_lame_encoder);\n        g_lame_encoder = 0;\n        g_client_does_mp3lame = 0;\n    }\n#endif\n\n    fifo_delete(g_in_fifo, NULL);\n    g_in_fifo = NULL;\n\n    return 0;\n}\n\n/*****************************************************************************/\n\n/* data in from client ( client -> xrdp -> chansrv ) */\n\nint\nsound_data_in(struct stream *s, int chan_id, int chan_flags, int length,\n              int total_length)\n{\n    int code;\n    int size;\n    int ok_to_free = 1;\n\n    if (!read_entire_packet(s, &g_stream_incoming_packet, chan_flags,\n                            length, total_length))\n    {\n        return 0;\n    }\n\n    in_uint8(g_stream_incoming_packet, code);\n    in_uint8s(g_stream_incoming_packet, 1);\n    in_uint16_le(g_stream_incoming_packet, size);\n\n    switch (code)\n    {\n        case SNDC_WAVECONFIRM:\n            sound_process_wave_confirm(g_stream_incoming_packet, size);\n            break;\n\n        case SNDC_TRAINING:\n            sound_process_training(g_stream_incoming_packet, size);\n            break;\n\n        case SNDC_FORMATS:\n            sound_process_output_formats(g_stream_incoming_packet, size);\n            break;\n\n        case SNDC_REC_NEGOTIATE:\n            sound_process_input_formats(g_stream_incoming_packet, size);\n            break;\n\n        case SNDC_REC_DATA:\n            sound_process_input_data(g_stream_incoming_packet, size);\n            ok_to_free = 0;\n            break;\n\n        default:\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"sound_data_in: unknown code %d size %d\", code, size);\n            break;\n    }\n\n    if (ok_to_free && g_stream_incoming_packet)\n    {\n        xstream_free(g_stream_incoming_packet);\n        g_stream_incoming_packet = NULL;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nsound_get_wait_objs(tbus *objs, int *count, int *timeout)\n{\n    int lcount;\n\n    lcount = *count;\n\n    if (g_audio_l_trans_out != 0)\n    {\n        objs[lcount] = g_audio_l_trans_out->sck;\n        lcount++;\n    }\n\n    if (g_audio_c_trans_out != 0)\n    {\n        objs[lcount] = g_audio_c_trans_out->sck;\n        lcount++;\n    }\n\n    if (g_audio_l_trans_in != 0)\n    {\n        objs[lcount] = g_audio_l_trans_in->sck;\n        lcount++;\n    }\n\n    if (g_audio_c_trans_in != 0)\n    {\n        objs[lcount] = g_audio_c_trans_in->sck;\n        lcount++;\n    }\n\n    *count = lcount;\n    return 0;\n}\n\n/*****************************************************************************/\nint\nsound_check_wait_objs(void)\n{\n    if (g_audio_l_trans_out != 0)\n    {\n        if (trans_check_wait_objs(g_audio_l_trans_out) != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_check_wait_objs: g_audio_l_trans_out returned non-zero\");\n            trans_delete(g_audio_l_trans_out);\n            g_audio_l_trans_out = 0;\n        }\n    }\n\n    if (g_audio_c_trans_out != 0)\n    {\n        if (trans_check_wait_objs(g_audio_c_trans_out) != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_check_wait_objs: g_audio_c_trans_out returned non-zero\");\n            trans_delete(g_audio_c_trans_out);\n            g_audio_c_trans_out = 0;\n            sound_start_sink_listener();\n        }\n    }\n\n    if (g_audio_l_trans_in != 0)\n    {\n        if (trans_check_wait_objs(g_audio_l_trans_in) != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_check_wait_objs: g_audio_l_trans_in returned non-zero\");\n            trans_delete(g_audio_l_trans_in);\n            g_audio_l_trans_in = 0;\n        }\n    }\n\n    if (g_audio_c_trans_in != 0)\n    {\n        if (trans_check_wait_objs(g_audio_c_trans_in) != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_check_wait_objs: g_audio_c_trans_in returned non-zero\");\n            trans_delete(g_audio_c_trans_in);\n            g_audio_c_trans_in = 0;\n            sound_start_source_listener();\n        }\n    }\n\n    return 0;\n}\n\n/******************************************************************************\n **                                                                          **\n **                       Microphone related code                            **\n **                                                                          **\n ******************************************************************************/\n\n/**\n *\n *****************************************************************************/\n\nstatic int\nsound_send_server_input_formats(void)\n{\n#if defined(XRDP_RDPSNDAUDIN)\n    struct stream *s;\n    int bytes;\n    int index;\n    int num_formats;\n    char *size_ptr;\n\n    num_formats = sizeof(g_wave_inp_formats) /\n                  sizeof(g_wave_inp_formats[0]) - 1;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_send_server_input_formats: num_formats %d\", num_formats);\n\n    make_stream(s);\n    init_stream(s, 8182);\n    out_uint16_le(s, SNDC_REC_NEGOTIATE);\n    size_ptr = s->p;\n    out_uint16_le(s, 0);                   /* size, set later */\n    out_uint32_le(s, 0);                   /* unused */\n    out_uint32_le(s, 0);                   /* unused */\n    out_uint16_le(s, num_formats);         /* wNumberOfFormats */\n    out_uint16_le(s, 5);                   /* wVersion */\n\n    /*\n        wFormatTag      2 byte offset 0\n        nChannels       2 byte offset 2\n        nSamplesPerSec  4 byte offset 4\n        nAvgBytesPerSec 4 byte offset 8\n        nBlockAlign     2 byte offset 12\n        wBitsPerSample  2 byte offset 14\n        cbSize          2 byte offset 16\n        data            variable offset 18\n    */\n\n    for (index = 0; index < num_formats; index++)\n    {\n        out_uint16_le(s, g_wave_inp_formats[index]->wFormatTag);\n        out_uint16_le(s, g_wave_inp_formats[index]->nChannels);\n        out_uint32_le(s, g_wave_inp_formats[index]->nSamplesPerSec);\n        out_uint32_le(s, g_wave_inp_formats[index]->nAvgBytesPerSec);\n        out_uint16_le(s, g_wave_inp_formats[index]->nBlockAlign);\n        out_uint16_le(s, g_wave_inp_formats[index]->wBitsPerSample);\n        bytes = g_wave_inp_formats[index]->cbSize;\n        out_uint16_le(s, bytes);\n        if (bytes > 0)\n        {\n            out_uint8p(s, g_wave_inp_formats[index]->data, bytes);\n        }\n    }\n\n    s_mark_end(s);\n    bytes = (int)((s->end - s->data) - 4);\n    size_ptr[0] = bytes;\n    size_ptr[1] = bytes >> 8;\n    bytes = (int)(s->end - s->data);\n    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);\n    free_stream(s);\n#else\n    /* avoid warning */\n    (void)g_wave_inp_formats;\n#endif\n    return 0;\n}\n\n/**\n *\n *****************************************************************************/\n\nstatic int\nsound_process_input_format(int aindex, int wFormatTag, int nChannels,\n                           int nSamplesPerSec, int nAvgBytesPerSec,\n                           int nBlockAlign, int wBitsPerSample,\n                           int cbSize, char *data)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_process_input_format:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"      wFormatTag      %d\", wFormatTag);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"      nChannels       %d\", nChannels);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"      nSamplesPerSec  %d\", nSamplesPerSec);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"      nAvgBytesPerSec %d\", nAvgBytesPerSec);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"      nBlockAlign     %d\", nBlockAlign);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"      wBitsPerSample  %d\", wBitsPerSample);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"      cbSize          %d\", cbSize);\n\n#if 1\n    /* select CD quality audio */\n    if (wFormatTag == g_pcm_inp_44100.wFormatTag &&\n            nChannels == g_pcm_inp_44100.nChannels &&\n            nSamplesPerSec == g_pcm_inp_44100.nSamplesPerSec &&\n            nAvgBytesPerSec == g_pcm_inp_44100.nAvgBytesPerSec &&\n            nBlockAlign == g_pcm_inp_44100.nBlockAlign &&\n            wBitsPerSample == g_pcm_inp_44100.wBitsPerSample)\n    {\n        g_client_input_format_index = aindex;\n        g_server_input_format_index = 0;\n    }\n#else\n    /* select half of CD quality audio */\n    if (wFormatTag == g_pcm_inp_22050.wFormatTag &&\n            nChannels == g_pcm_inp_22050.nChannels &&\n            nSamplesPerSec == g_pcm_inp_22050.nSamplesPerSec &&\n            nAvgBytesPerSec == g_pcm_inp_22050.nAvgBytesPerSec &&\n            nBlockAlign == g_pcm_inp_22050.nBlockAlign &&\n            wBitsPerSample == g_pcm_inp_22050.wBitsPerSample)\n    {\n        g_client_input_format_index = aindex;\n        g_server_input_format_index = 0;\n    }\n#endif\n\n    return 0;\n}\n\n/**\n *\n *****************************************************************************/\n\nstatic int\nsound_process_input_formats(struct stream *s, int size)\n{\n    int num_formats;\n    int index;\n    int wFormatTag;\n    int nChannels;\n    int nSamplesPerSec;\n    int nAvgBytesPerSec;\n    int nBlockAlign;\n    int wBitsPerSample;\n    int cbSize;\n    char *data;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_process_input_formats: size=%d\", size);\n\n    if (g_getenv(\"XRDP_NO_RDPSND_REC\") == NULL)\n    {\n        g_rdpsnd_can_rec = 1;\n    }\n    in_uint8s(s, 8); /* skip 8 bytes */\n    in_uint16_le(s, num_formats);\n    in_uint8s(s, 2); /* skip version */\n\n    if (num_formats > 0)\n    {\n        for (index = 0; index < num_formats; index++)\n        {\n            in_uint16_le(s, wFormatTag);\n            in_uint16_le(s, nChannels);\n            in_uint32_le(s, nSamplesPerSec);\n            in_uint32_le(s, nAvgBytesPerSec);\n            in_uint16_le(s, nBlockAlign);\n            in_uint16_le(s, wBitsPerSample);\n            in_uint16_le(s, cbSize);\n            in_uint8p(s, data, cbSize);\n            sound_process_input_format(index, wFormatTag, nChannels, nSamplesPerSec,\n                                       nAvgBytesPerSec, nBlockAlign, wBitsPerSample,\n                                       cbSize, data);\n        }\n    }\n\n    return 0;\n}\n/**\n *\n *****************************************************************************/\n\nstatic int\nsound_input_start_recording(void)\n{\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_input_start_recording:\");\n\n    /* if there is any data in FIFO, discard it */\n    fifo_clear(g_in_fifo, NULL);\n    g_bytes_in_fifo = 0;\n\n    xstream_new(s, 1024);\n\n    /*\n     * command format\n     *\n     * 02 bytes command SNDC_REC_START\n     * 02 bytes length\n     * 02 bytes data format received earlier\n     */\n\n    out_uint16_le(s, SNDC_REC_START);\n    out_uint16_le(s, 2);\n    out_uint16_le(s, g_client_input_format_index);\n\n    s_mark_end(s);\n    send_channel_data(g_rdpsnd_chan_id, s->data, 6);\n    xstream_free(s);\n\n    return 0;\n}\n\n/**\n *\n *****************************************************************************/\n\nstatic int\nsound_input_stop_recording(void)\n{\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_input_stop_recording:\");\n\n    xstream_new(s, 1024);\n\n    /*\n     * command format\n     *\n     * 02 bytes command SNDC_REC_STOP\n     * 02 bytes length (zero)\n     */\n\n    out_uint16_le(s, SNDC_REC_STOP);\n    out_uint16_le(s, 0);\n\n    s_mark_end(s);\n    send_channel_data(g_rdpsnd_chan_id, s->data, 4);\n    xstream_free(s);\n\n    return 0;\n}\n\n/**\n * Process data: xrdp <- client\n *****************************************************************************/\n\nstatic int\nsound_process_input_data(struct stream *s, int bytes)\n{\n    struct stream *ls;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_process_input_data: bytes %d g_bytes_in_fifo %d\",\n              bytes, g_bytes_in_fifo);\n#if 0 /* no need to cap anymore */\n    /* cap data in fifo */\n    if (g_bytes_in_fifo > 8 * 1024)\n    {\n        return 0;\n    }\n#endif\n    xstream_new(ls, bytes);\n    g_memcpy(ls->data, s->p, bytes);\n    ls->p += bytes;\n    s_mark_end(ls);\n    fifo_add_item(g_in_fifo, (void *) ls);\n    g_bytes_in_fifo += bytes;\n\n    return 0;\n}\n\n/**\n * Got a command from sound_server_source\n *****************************************************************************/\n\nstatic int\nsound_sndsrvr_source_data_in(struct trans *trans)\n{\n    struct stream *ts = NULL;\n    struct stream *s  = NULL;\n\n    tui16    bytes_req   = 0;\n    int      bytes_read  = 0;\n    int      cmd;\n    int      i;\n\n    if (trans == 0)\n    {\n        return 0;\n    }\n\n    if (trans != g_audio_c_trans_in)\n    {\n        return 1;\n    }\n\n    ts = trans_get_in_s(trans);\n    if (trans_force_read(trans, 3))\n    {\n        LOG(LOG_LEVEL_ERROR, \"sound.c: error reading from transport\");\n    }\n\n    ts->p = ts->data + 8;\n    in_uint8(ts, cmd);\n    in_uint16_le(ts, bytes_req);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"sound_sndsrvr_source_data_in: bytes_req %d\", bytes_req);\n\n    xstream_new(s, bytes_req + 2);\n\n    if (cmd == PA_CMD_SEND_DATA)\n    {\n        /* set real len later */\n        out_uint16_le(s, 0);\n\n        while (bytes_read < bytes_req)\n        {\n            if (g_stream_inp == NULL)\n            {\n                g_stream_inp = (struct stream *) fifo_remove_item(g_in_fifo);\n                if (g_stream_inp != NULL)\n                {\n                    g_bytes_in_fifo -= g_stream_inp->size;\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  g_bytes_in_fifo %d\", g_bytes_in_fifo);\n                }\n            }\n\n            if (g_stream_inp == NULL)\n            {\n                /* no more data, send what we have */\n                break;\n            }\n            else\n            {\n                if (g_bytes_in_stream == 0)\n                {\n                    g_bytes_in_stream = g_stream_inp->size;\n                }\n\n                i = bytes_req - bytes_read;\n\n                if (i < g_bytes_in_stream)\n                {\n                    //coverity[COPY_PASTE_ERROR:FALSE]\n                    xstream_copyin(s, &g_stream_inp->data[g_stream_inp->size - g_bytes_in_stream], i);\n                    bytes_read += i;\n                    g_bytes_in_stream -= i;\n                }\n                else\n                {\n                    xstream_copyin(s, &g_stream_inp->data[g_stream_inp->size - g_bytes_in_stream], g_bytes_in_stream);\n                    bytes_read += g_bytes_in_stream;\n                    g_bytes_in_stream = 0;\n                    xstream_free(g_stream_inp);\n                    g_stream_inp = NULL;\n                }\n            }\n        }\n\n        if (bytes_read)\n        {\n            s->data[0] = (char) (bytes_read & 0xff);\n            s->data[1] = (char) ((bytes_read >> 8) & 0xff);\n        }\n\n        s_mark_end(s);\n\n        trans_force_write_s(trans, s);\n    }\n    else if (cmd == PA_CMD_START_REC)\n    {\n        if (g_rdpsnd_can_rec)\n        {\n            sound_input_start_recording();\n        }\n        else\n        {\n            audin_start();\n        }\n    }\n    else if (cmd == PA_CMD_STOP_REC)\n    {\n        if (g_rdpsnd_can_rec)\n        {\n            sound_input_stop_recording();\n        }\n        else\n        {\n            audin_stop();\n        }\n    }\n\n    xstream_free(s);\n\n    return 0;\n}\n\n/**\n * Start a listener for microphone redirection connections\n *****************************************************************************/\nstatic int\nsound_start_source_listener(void)\n{\n    char port[XRDP_SOCKETS_MAXPATH];\n\n    g_audio_l_trans_in = trans_create(TRANS_MODE_UNIX, 128 * 1024, 8192);\n    g_audio_l_trans_in->is_term = g_is_term;\n    g_snprintf(port, sizeof(port), CHANSRV_PORT_IN_STR, g_getuid(),\n               g_display_str);\n    g_audio_l_trans_in->trans_conn_in = sound_sndsrvr_source_conn_in;\n    if (trans_listen(g_audio_l_trans_in, port) != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"trans_listen failed\");\n    }\n    return 0;\n}\n\n/**\n * Start a listener for speaker redirection connections\n *****************************************************************************/\nstatic int\nsound_start_sink_listener(void)\n{\n    char port[XRDP_SOCKETS_MAXPATH];\n\n    g_audio_l_trans_out = trans_create(TRANS_MODE_UNIX, 128 * 1024, 8192);\n    g_audio_l_trans_out->is_term = g_is_term;\n    g_snprintf(port, sizeof(port), CHANSRV_PORT_OUT_STR, g_getuid(),\n               g_display_str);\n    g_audio_l_trans_out->trans_conn_in = sound_sndsrvr_sink_conn_in;\n    if (trans_listen(g_audio_l_trans_out, port) != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"trans_listen failed\");\n    }\n    return 0;\n}\n\n"
  },
  {
    "path": "sesman/chansrv/sound.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2009-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _SOUND_H_\n#define _SOUND_H_\n\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"os_calls.h\"\n#include \"chansrv.h\"\n#include \"trans.h\"\n\n#define SNDC_CLOSE          0x01\n#define SNDC_WAVE           0x02\n#define SNDC_SETVOLUME      0x03\n#define SNDC_SETPITCH       0x04\n#define SNDC_WAVECONFIRM    0x05\n#define SNDC_TRAINING       0x06\n#define SNDC_FORMATS        0x07\n#define SNDC_CRYPTKEY       0x08\n#define SNDC_WAVEENCRYPT    0x09\n#define SNDC_UDPWAVE        0x0A\n#define SNDC_UDPWAVELAST    0x0B\n#define SNDC_QUALITYMODE    0x0C\n\n/* used for sound input (mic) */\n#define SNDC_REC_NEGOTIATE  39\n#define SNDC_REC_START      40\n#define SNDC_REC_STOP       41\n#define SNDC_REC_DATA       42\n#define SNDC_REC_SET_VOLUME 43\n\n/* commands recvd from pulseaudio source */\n#define PA_CMD_START_REC    1\n#define PA_CMD_STOP_REC     2\n#define PA_CMD_SEND_DATA    3\n\nint sound_init(void);\nint sound_deinit(void);\nint sound_get_wait_objs(tbus *objs, int *count, int *timeout);\nint sound_check_wait_objs(void);\n\nint sound_data_in(struct stream *s, int chan_id, int chan_flags,\n                  int length, int total_length);\n\n#endif\n"
  },
  {
    "path": "sesman/chansrv/wave-format-server.txt",
    "content": "\n\nExample wave formats from some servers\n\nsee MMREG.H for defines\n\nWindows 7 SP1\n\nexample wave data sizes coming from server 8820\n\nwFormatTag=1 nChannels=2 nSamplesPerSec=44100 nAvgBytesPerSec=176400 nBlockAlign=4 wBitsPerSample=16 cbSize=0\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=2 nSamplesPerSec=44100 nAvgBytesPerSec=88200 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=2 nSamplesPerSec=44100 nAvgBytesPerSec=88200 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=2 nSamplesPerSec=44100 nAvgBytesPerSec=44359 nBlockAlign=2048 wBitsPerSample=4 cbSize=32\n    0000 f4 07 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n    0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=2 nSamplesPerSec=44100 nAvgBytesPerSec=44251 nBlockAlign=2048 wBitsPerSample=4 cbSize=2\n    0000 f9 07                                           ..\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=44100 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=1 nSamplesPerSec=44100 nAvgBytesPerSec=44100 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=44100 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=1 nSamplesPerSec=44100 nAvgBytesPerSec=44100 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=22311 nBlockAlign=1024 wBitsPerSample=4 cbSize=32\n    0000 f4 03 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n    0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=22201 nBlockAlign=1024 wBitsPerSample=4 cbSize=2\n    0000 f9 03                                           ..\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=1 nSamplesPerSec=44100 nAvgBytesPerSec=22179 nBlockAlign=1024 wBitsPerSample=4 cbSize=32\n    0000 f4 07 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n    0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=1 nSamplesPerSec=44100 nAvgBytesPerSec=22125 nBlockAlign=1024 wBitsPerSample=4 cbSize=2\n    0000 f9 07                                           ..\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=22050 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=22050 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=22050 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=22050 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=16000 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=16000 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=11289 nBlockAlign=512 wBitsPerSample=4 cbSize=32\n    0000 f4 01 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n    0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=11177 nBlockAlign=512 wBitsPerSample=4 cbSize=2\n    0000 f9 01                                           ..\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=11155 nBlockAlign=512 wBitsPerSample=4 cbSize=32\n    0000 f4 03 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n    0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=11100 nBlockAlign=512 wBitsPerSample=4 cbSize=2\n    0000 f9 03                                           ..\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=11025 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=11025 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\nwFormatTag=49 nChannels=1 nSamplesPerSec=44100 nAvgBytesPerSec=8957 nBlockAlign=65 wBitsPerSample=0 cbSize=2\n    0000 40 01                                           @.\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=8192 nBlockAlign=512 wBitsPerSample=4 cbSize=32\n    0000 f4 01 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n    0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=8110 nBlockAlign=512 wBitsPerSample=4 cbSize=2\n    0000 f9 01                                           ..\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=8000 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=8000 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\nwFormatTag=2 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=5644 nBlockAlign=256 wBitsPerSample=4 cbSize=32\n    0000 f4 01 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n    0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\nwFormatTag=17 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=5588 nBlockAlign=256 wBitsPerSample=4 cbSize=2\n    0000 f9 01                                           ..\n\n#define  WAVE_FORMAT_GSM610     0x0031  /*  Microsoft Corporation  */\nwFormatTag=49 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=4478 nBlockAlign=65 wBitsPerSample=0 cbSize=2\n    0000 40 01                                           @.\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=4096 nBlockAlign=256 wBitsPerSample=4 cbSize=32\n    0000 f4 01 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n    0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=4055 nBlockAlign=256 wBitsPerSample=4 cbSize=2\n    0000 f9 01                                           ..\n\n#define  WAVE_FORMAT_GSM610     0x0031  /*  Microsoft Corporation  */\nwFormatTag=49 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=2239 nBlockAlign=65 wBitsPerSample=0 cbSize=2\n    0000 40 01                                           @.\n\n#define  WAVE_FORMAT_GSM610     0x0031  /*  Microsoft Corporation  */\nwFormatTag=49 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=1625 nBlockAlign=65 wBitsPerSample=0 cbSize=2\n    0000 40 01                                           @.\n\n\n\n\nWindows XP SP3\n\nexample wave data sizes coming from server 32512, 16256\n\nwFormatTag=1 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=88200 nBlockAlign=4 wBitsPerSample=16 cbSize=0\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=44100 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=44100 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=22311 nBlockAlign=1024 wBitsPerSample=4 cbSize=32\n0000 f4 03 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=22201 nBlockAlign=1024 wBitsPerSample=4 cbSize=2\n0000 f9 03                                           ..\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=22050 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=22050 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=22050 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=22050 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=16000 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=16000 nBlockAlign=2 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=11289 nBlockAlign=512 wBitsPerSample=4 cbSize=32\n0000 f4 01 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=11177 nBlockAlign=512 wBitsPerSample=4 cbSize=2\n0000 f9 01                                           ..\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=11155 nBlockAlign=512 wBitsPerSample=4 cbSize=32\n0000 f4 03 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=11100 nBlockAlign=512 wBitsPerSample=4 cbSize=2\n0000 f9 03                                           ..\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=11025 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=11025 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=8192 nBlockAlign=512 wBitsPerSample=4 cbSize=32\n0000 f4 01 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=8110 nBlockAlign=512 wBitsPerSample=4 cbSize=2\n0000 f9 01                                           ..\n\n#define  WAVE_FORMAT_ALAW       0x0006  /*  Microsoft Corporation  */\nwFormatTag=6 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=8000 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MULAW      0x0007  /*  Microsoft Corporation  */\nwFormatTag=7 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=8000 nBlockAlign=1 wBitsPerSample=8 cbSize=0\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=7000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 b6 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=16000 nAvgBytesPerSec=7000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 fc 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=6000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 9c 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=16000 nAvgBytesPerSec=6000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 d8 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=5644 nBlockAlign=256 wBitsPerSample=4 cbSize=32\n0000 f4 01 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=5588 nBlockAlign=256 wBitsPerSample=4 cbSize=2\n0000 f9 01                                           ..\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=5000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 82 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=16000 nAvgBytesPerSec=5000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 b4 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_GSM610     0x0031  /*  Microsoft Corporation  */\nwFormatTag=49 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=4478 nBlockAlign=65 wBitsPerSample=0 cbSize=2\n0000 40 01                                           @.\n\n#define  WAVE_FORMAT_ADPCM      0x0002  /*  Microsoft Corporation  */\nwFormatTag=2 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=4096 nBlockAlign=256 wBitsPerSample=4 cbSize=32\n0000 f4 01 07 00 00 01 00 00 00 02 00 ff 00 00 00 00 ................\n0010 c0 00 40 00 f0 00 00 00 cc 01 30 ff 88 01 18 ff ..@.......0.....\n\n#define  WAVE_FORMAT_DVI_ADPCM  0x0011  /*  Intel Corporation  */\nwFormatTag=17 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=4055 nBlockAlign=256 wBitsPerSample=4 cbSize=2\n0000 f9 01                                           ..\n\n?\nwFormatTag=353 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=4005 nBlockAlign=186 wBitsPerSample=16 cbSize=47\n0000 00 04 00 00 01 00 ba 00 00 00 46 36 44 43 39 38 ..........F6DC98\n0010 33 30 2d 42 43 37 39 2d 31 31 64 32 2d 41 39 44 30-BC79-11d2-A9D\n0020 30 2d 30 30 36 30 39 37 39 32 36 30 33 36 00    0-006097926036.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=16000 nAvgBytesPerSec=4000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 90 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=12000 nAvgBytesPerSec=4000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 c0 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=4000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 d0 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=4000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 20 01 01 00 71 05             ...... ...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=4000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 68 00 01 00 71 05             ......h...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=16000 nAvgBytesPerSec=4000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 90 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=12000 nAvgBytesPerSec=3000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 90 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=3000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 9c 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=3000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 d8 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=3000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 4e 00 01 00 71 05             ......N...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=16000 nAvgBytesPerSec=3000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 6c 00 01 00 71 05             ......l...q.\n\n?\nwFormatTag=353 nChannels=1 nSamplesPerSec=22050 nAvgBytesPerSec=2519 nBlockAlign=117 wBitsPerSample=16 cbSize=47\n0000 00 04 00 00 00 00 75 00 00 00 46 36 44 43 39 38 ......u...F6DC98\n0010 33 30 2d 42 43 37 39 2d 31 31 64 32 2d 41 39 44 30-BC79-11d2-A9D\n0020 30 2d 30 30 36 30 39 37 39 32 36 30 33 36 00    0-006097926036.\n\n?\nwFormatTag=353 nChannels=2 nSamplesPerSec=22050 nAvgBytesPerSec=2519 nBlockAlign=117 wBitsPerSample=16 cbSize=47\n0000 00 04 00 00 00 00 75 00 00 00 46 36 44 43 39 38 ......u...F6DC98\n0010 33 30 2d 42 43 37 39 2d 31 31 64 32 2d 41 39 44 30-BC79-11d2-A9D\n0020 30 2d 30 30 36 30 39 37 39 32 36 30 33 36 00    0-006097926036.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=12000 nAvgBytesPerSec=2500 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 f0 00 02 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=2500 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 04 01 02 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=2500 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 68 01 02 00 71 05             ......h...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=16000 nAvgBytesPerSec=2500 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 b4 00 02 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=12000 nAvgBytesPerSec=2500 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 f0 00 02 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=2500 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 04 01 02 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=12000 nAvgBytesPerSec=2250 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 b0 01 04 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=11025 nAvgBytesPerSec=2250 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 d4 01 04 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=2250 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 88 02 04 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=16000 nAvgBytesPerSec=2250 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 44 01 04 00 71 05             ......D...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=12000 nAvgBytesPerSec=2250 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 b0 01 04 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=2250 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 d4 01 04 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_GSM610     0x0031  /*  Microsoft Corporation  */\nwFormatTag=49 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=2239 nBlockAlign=65 wBitsPerSample=0 cbSize=2\n0000 40 01                                           @.\n\n?\nwFormatTag=353 nChannels=1 nSamplesPerSec=16000 nAvgBytesPerSec=2000 nBlockAlign=64 wBitsPerSample=16 cbSize=47\n0000 00 02 00 00 00 00 40 00 00 00 46 36 44 43 39 38 ......@...F6DC98\n0010 33 30 2d 42 43 37 39 2d 31 31 64 32 2d 41 39 44 30-BC79-11d2-A9D\n0020 30 2d 30 30 36 30 39 37 39 32 36 30 33 36 00    0-006097926036.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=16000 nAvgBytesPerSec=2000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 48 00 01 00 71 05             ......H...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=12000 nAvgBytesPerSec=2000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 60 00 01 00 71 05             ......`...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=2000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 68 00 01 00 71 05             ......h...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=2000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 90 00 01 00 71 05             ..........q.\n\n#define  WAVE_FORMAT_GSM610     0x0031  /*  Microsoft Corporation  */\nwFormatTag=49 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=1625 nBlockAlign=65 wBitsPerSample=0 cbSize=2\n0000 40 01                                           @.\n\n?\nwFormatTag=353 nChannels=2 nSamplesPerSec=8000 nAvgBytesPerSec=1500 nBlockAlign=96 wBitsPerSample=16 cbSize=47\n0000 00 02 00 00 00 00 60 00 00 00 46 36 44 43 39 38 ......`...F6DC98\n0010 33 30 2d 42 43 37 39 2d 31 31 64 32 2d 41 39 44 30-BC79-11d2-A9D\n0020 30 2d 30 30 36 30 39 37 39 32 36 30 33 36 00    0-006097926036.\n\n?\nwFormatTag=353 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=1249 nBlockAlign=58 wBitsPerSample=16 cbSize=47\n0000 00 02 00 00 00 00 3a 00 00 00 46 36 44 43 39 38 ......:...F6DC98\n0010 33 30 2d 42 43 37 39 2d 31 31 64 32 2d 41 39 44 30-BC79-11d2-A9D\n0020 30 2d 30 30 36 30 39 37 39 32 36 30 33 36 00    0-006097926036.\n\n#define  WAVE_FORMAT_DSPGROUP_TRUESPEECH        0x0022  /*  DSP Group, Inc  */\nwFormatTag=34 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=1067 nBlockAlign=32 wBitsPerSample=1 cbSize=32\n0000 01 00 f0 00 00 00 00 00 00 00 00 00 00 00 00 00 ................\n0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................\n\n?\nwFormatTag=353 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=1012 nBlockAlign=47 wBitsPerSample=16 cbSize=47\n0000 00 02 00 00 00 00 2f 00 00 00 46 36 44 43 39 38 ....../...F6DC98\n0010 33 30 2d 42 43 37 39 2d 31 31 64 32 2d 41 39 44 30-BC79-11d2-A9D\n0020 30 2d 30 30 36 30 39 37 39 32 36 30 33 36 00    0-006097926036.\n\n?\nwFormatTag=353 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=1000 nBlockAlign=64 wBitsPerSample=16 cbSize=47\n0000 00 02 00 00 00 00 40 00 00 00 46 36 44 43 39 38 ......@...F6DC98\n0010 33 30 2d 42 43 37 39 2d 31 31 64 32 2d 41 39 44 30-BC79-11d2-A9D\n0020 30 2d 30 30 36 30 39 37 39 32 36 30 33 36 00    0-006097926036.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=12000 nAvgBytesPerSec=1000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 30 00 01 00 71 05             ......0...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=11025 nAvgBytesPerSec=1000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 34 00 01 00 71 05             ......4...q.\n\n#define  WAVE_FORMAT_MPEGLAYER3 0x0055  /*  ISO/MPEG Layer3 Format Tag */\nwFormatTag=85 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=1000 nBlockAlign=1 wBitsPerSample=0 cbSize=12\n0000 01 00 02 00 00 00 48 00 01 00 71 05             ......H...q.\n\n?\nwFormatTag=66 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=800 nBlockAlign=24 wBitsPerSample=0 cbSize=10\n0000 02 00 ce 9a 32 f7 a2 ae de ac                   ....2.....\n\n?\nwFormatTag=353 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=750 nBlockAlign=48 wBitsPerSample=16 cbSize=47\n0000 00 02 00 00 00 00 30 00 00 00 46 36 44 43 39 38 ......0...F6DC98\n0010 33 30 2d 42 43 37 39 2d 31 31 64 32 2d 41 39 44 30-BC79-11d2-A9D\n0020 30 2d 30 30 36 30 39 37 39 32 36 30 33 36 00    0-006097926036.\n\n?\nwFormatTag=66 nChannels=1 nSamplesPerSec=8000 nAvgBytesPerSec=666 nBlockAlign=20 wBitsPerSample=0 cbSize=10\n0000 03 00 ce 9a 32 f7 a2 ae de ac                   ....2.....\n\n\n\n//***************************************************************\n// Windows 7 SP1 x64 Server Formats\nWAVE_FORMAT_PCM:\nwFormatTag: 0x0001 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 176400 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 44359 nBlockAlign: 2048 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 44251 nBlockAlign: 2048 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ALAW:\nwFormatTag: 0x0006 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 44100 nBlockAlign: 2 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 22311 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 22201 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 44100 nAvgBytesPerSec: 22179 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 44100 nAvgBytesPerSec: 22125 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 11289 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 11177 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 11155 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 11100 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 44100 nAvgBytesPerSec: 8957 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 8192 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 8110 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 5644 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 5588 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 4478 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 4096 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 4055 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 2239 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 1625 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\n\n//***************************************************************\n// Windows 10 10586 x64 Server Formats\nWAVE_FORMAT_AAC_MS:\nwFormatTag: 0xA106 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 24000 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_AAC_MS:\nwFormatTag: 0xA106 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 20000 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_AAC_MS:\nwFormatTag: 0xA106 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 16000 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_AAC_MS:\nwFormatTag: 0xA106 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 12000 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_PCM:\nwFormatTag: 0x0001 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 176400 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 44359 nBlockAlign: 2048 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 44251 nBlockAlign: 2048 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ALAW:\nwFormatTag: 0x0006 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 44100 nBlockAlign: 2 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 22311 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 22201 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 44100 nAvgBytesPerSec: 22179 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 44100 nAvgBytesPerSec: 22125 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 11289 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 11177 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 11155 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 11100 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 44100 nAvgBytesPerSec: 8957 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 8192 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 8110 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 5644 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 5588 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 4478 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 4096 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 4055 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 2239 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 1625 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\n\n//***************************************************************\n// Windows Server 2016 TP4 x64 Server Formats\nWAVE_FORMAT_AAC_MS:\nwFormatTag: 0xA106 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 24000 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_AAC_MS:\nwFormatTag: 0xA106 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 20000 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_AAC_MS:\nwFormatTag: 0xA106 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 16000 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_AAC_MS:\nwFormatTag: 0xA106 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 12000 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_PCM:\nwFormatTag: 0x0001 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 176400 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 44359 nBlockAlign: 2048 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 44100 nAvgBytesPerSec: 44251 nBlockAlign: 2048 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ALAW:\nwFormatTag: 0x0006 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 44100 nBlockAlign: 2 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 22311 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 22201 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 44100 nAvgBytesPerSec: 22179 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 44100 nAvgBytesPerSec: 22125 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 11289 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 11177 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 11155 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 11100 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 44100 nAvgBytesPerSec: 8957 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 8192 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 8110 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 5644 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 5588 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 4478 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 4096 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 4055 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 2239 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 1625 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\n\n\n\n\n//***************************************************************\n// Windows XP SP3 x86 Server Formats\nWAVE_FORMAT_PCM:\nwFormatTag: 0x0001 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 88200 nBlockAlign: 4 wBitsPerSample: 16 cbSize: 0\n\t\nWAVE_FORMAT_ALAW:\nwFormatTag: 0x0006 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 44100 nBlockAlign: 2 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_MULAW:\nwFormatTag: 0x0007 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 44100 nBlockAlign: 2 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 22311 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 22201 nBlockAlign: 1024 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ALAW:\nwFormatTag: 0x0006 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 22050 nBlockAlign: 2 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_ALAW:\nwFormatTag: 0x0006 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 22050 nBlockAlign: 1 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_MULAW:\nwFormatTag: 0x0007 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 22050 nBlockAlign: 2 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_MULAW:\nwFormatTag: 0x0007 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 22050 nBlockAlign: 1 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_ALAW:\nwFormatTag: 0x0006 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 16000 nBlockAlign: 2 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_MULAW:\nwFormatTag: 0x0007 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 16000 nBlockAlign: 2 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 11289 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 11177 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 11155 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 11100 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ALAW:\nwFormatTag: 0x0006 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 11025 nBlockAlign: 1 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_MULAW:\nwFormatTag: 0x0007 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 11025 nBlockAlign: 1 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 8192 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 8110 nBlockAlign: 512 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_ALAW:\nwFormatTag: 0x0006 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 8000 nBlockAlign: 1 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_MULAW:\nwFormatTag: 0x0007 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 8000 nBlockAlign: 1 wBitsPerSample: 8 cbSize: 0\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 7000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 16000 nAvgBytesPerSec: 7000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 6000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 16000 nAvgBytesPerSec: 6000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 5644 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 5588 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 5000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 16000 nAvgBytesPerSec: 5000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 4478 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_ADPCM:\nwFormatTag: 0x0002 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 4096 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 32\n\t\nWAVE_FORMAT_DVI_ADPCM:\nwFormatTag: 0x0011 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 4055 nBlockAlign: 256 wBitsPerSample: 4 cbSize: 2\n\t\nWAVE_FORMAT_WMAUDIO2:\nwFormatTag: 0x0161 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 4005 nBlockAlign: 186 wBitsPerSample: 16 cbSize: 47\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 16000 nAvgBytesPerSec: 4000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 12000 nAvgBytesPerSec: 4000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 4000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 4000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 4000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 16000 nAvgBytesPerSec: 4000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 12000 nAvgBytesPerSec: 3000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 3000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 3000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 3000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 16000 nAvgBytesPerSec: 3000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_WMAUDIO2:\nwFormatTag: 0x0161 nChannels: 1 nSamplesPerSec: 22050 nAvgBytesPerSec: 2519 nBlockAlign: 117 wBitsPerSample: 16 cbSize: 47\n\t\nWAVE_FORMAT_WMAUDIO2:\nwFormatTag: 0x0161 nChannels: 2 nSamplesPerSec: 22050 nAvgBytesPerSec: 2519 nBlockAlign: 117 wBitsPerSample: 16 cbSize: 47\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 12000 nAvgBytesPerSec: 2500 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 2500 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 2500 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 16000 nAvgBytesPerSec: 2500 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 12000 nAvgBytesPerSec: 2500 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 2500 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 12000 nAvgBytesPerSec: 2250 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 11025 nAvgBytesPerSec: 2250 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 2250 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 16000 nAvgBytesPerSec: 2250 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 12000 nAvgBytesPerSec: 2250 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 2250 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 2239 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_WMAUDIO2:\nwFormatTag: 0x0161 nChannels: 1 nSamplesPerSec: 16000 nAvgBytesPerSec: 2000 nBlockAlign: 64 wBitsPerSample: 16 cbSize: 47\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 16000 nAvgBytesPerSec: 2000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 12000 nAvgBytesPerSec: 2000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 2000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 2000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_GSM610:\nwFormatTag: 0x0031 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 1625 nBlockAlign: 65 wBitsPerSample: 0 cbSize: 2\n\t\nWAVE_FORMAT_WMAUDIO2:\nwFormatTag: 0x0161 nChannels: 2 nSamplesPerSec: 8000 nAvgBytesPerSec: 1500 nBlockAlign: 96 wBitsPerSample: 16 cbSize: 47\n\t\nWAVE_FORMAT_WMAUDIO2:\nwFormatTag: 0x0161 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 1249 nBlockAlign: 58 wBitsPerSample: 16 cbSize: 47\n\t\nWAVE_FORMAT_DSPGROUP_TRUESPEECH\t:\nwFormatTag: 0x0022 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 1067 nBlockAlign: 32 wBitsPerSample: 1 cbSize: 32\n\t\nWAVE_FORMAT_WMAUDIO2:\nwFormatTag: 0x0161 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 1012 nBlockAlign: 47 wBitsPerSample: 16 cbSize: 47\n\t\nWAVE_FORMAT_WMAUDIO2:\nwFormatTag: 0x0161 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 1000 nBlockAlign: 64 wBitsPerSample: 16 cbSize: 47\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 12000 nAvgBytesPerSec: 1000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 11025 nAvgBytesPerSec: 1000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MPEGLAYER3:\nwFormatTag: 0x0055 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 1000 nBlockAlign: 1 wBitsPerSample: 0 cbSize: 12\n\t\nWAVE_FORMAT_MSG723:\nwFormatTag: 0x0042 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 800 nBlockAlign: 24 wBitsPerSample: 0 cbSize: 10\n\t\nWAVE_FORMAT_WMAUDIO2:\nwFormatTag: 0x0161 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 750 nBlockAlign: 48 wBitsPerSample: 16 cbSize: 47\n\t\nWAVE_FORMAT_MSG723:\nwFormatTag: 0x0042 nChannels: 1 nSamplesPerSec: 8000 nAvgBytesPerSec: 666 nBlockAlign: 20 wBitsPerSample: 0 cbSize: 10\n\n"
  },
  {
    "path": "sesman/chansrv/xcommon.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <X11/Xlib.h>\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"os_calls.h\"\n#include \"chansrv.h\"\n#include \"log.h\"\n#include \"clipboard.h\"\n#include \"rail.h\"\n#include \"xcommon.h\"\n\nextern int g_clip_up;                         /* in clipboard.c */\n\nextern int g_rail_up;                         /* in rail.c */\n\nDisplay *g_display = 0;\nint g_x_socket = 0;\ntbus g_x_wait_obj = 0;\nScreen *g_screen = 0;\nint g_screen_num = 0;\nWindow g_root_window = 0;\nAtom g_wm_delete_window_atom = 0;\nAtom g_wm_protocols_atom = 0;\nAtom g_utf8_string = 0;\nAtom g_net_wm_name = 0;\nAtom g_wm_state = 0;\n\nstatic x_server_fatal_cb_type x_server_fatal_handler = 0;\n\n\n/*****************************************************************************/\nstatic int\nxcommon_error_handler(Display *dis, XErrorEvent *xer)\n{\n    char text[256];\n\n    XGetErrorText(dis, xer->error_code, text, 255);\n    LOG_DEVEL(LOG_LEVEL_ERROR, \"X error [%s](%d) opcodes %d/%d \"\n              \"resource 0x%lx\", text, xer->error_code,\n              xer->request_code, xer->minor_code, xer->resourceid);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Allow the caller to be notified on X server failure\n   Specified callback can do any cleanup that needs to be done on exit,\n   like removing temporary files. This is the last function called.\n   Don't worry about memory leaks */\nvoid\nxcommon_set_x_server_fatal_handler(x_server_fatal_cb_type handler)\n{\n    x_server_fatal_handler = handler;\n}\n\n/*****************************************************************************/\n/* The X server had an internal error */\nstatic int\nxcommon_fatal_handler(Display *dis)\n{\n    if (x_server_fatal_handler)\n    {\n        x_server_fatal_handler();\n    }\n    return 0;\n}\n\n/******************************************************************************/\n/* this should be called first */\nint\nxcommon_init(void)\n{\n    if (g_display != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xcommon_init: xcommon_init already called\");\n        return 0;\n    }\n\n    g_display = XOpenDisplay(0);\n\n    if (g_display == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"xcommon_init: error, XOpenDisplay failed\");\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xcommon_init: connected to display ok\");\n\n    /* setting the error handlers can cause problem when shutting down\n       chansrv on some xlibs */\n    XSetErrorHandler(xcommon_error_handler);\n    XSetIOErrorHandler(xcommon_fatal_handler);\n\n    g_x_socket = XConnectionNumber(g_display);\n\n    if (g_x_socket == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"xcommon_init: XConnectionNumber failed\");\n        return 1;\n    }\n\n    g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0);\n    g_screen_num = DefaultScreen(g_display);\n    g_screen = ScreenOfDisplay(g_display, g_screen_num);\n\n    g_root_window = RootWindowOfScreen(g_screen);\n\n    g_wm_delete_window_atom = XInternAtom(g_display, \"WM_DELETE_WINDOW\", 0);\n    g_wm_protocols_atom = XInternAtom(g_display, \"WM_PROTOCOLS\", 0);\n    g_utf8_string = XInternAtom(g_display, \"UTF8_STRING\", 0);\n    g_net_wm_name = XInternAtom(g_display, \"_NET_WM_NAME\", 0);\n    g_wm_state = XInternAtom(g_display, \"WM_STATE\", 0);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error\n   this is called to get any wait objects for the main loop\n   timeout can be nil */\nint\nxcommon_get_wait_objs(tbus *objs, int *count, int *timeout)\n{\n    int lcount;\n\n    if (((!g_clip_up) && (!g_rail_up)) || (objs == 0) || (count == 0))\n    {\n        return 0;\n    }\n    lcount = *count;\n    objs[lcount] = g_x_wait_obj;\n    lcount++;\n    *count = lcount;\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxcommon_check_wait_objs(void)\n{\n    XEvent xevent;\n    int clip_rv;\n    int rail_rv;\n\n    if ((!g_clip_up) && (!g_rail_up))\n    {\n        return 0;\n    }\n    while (XPending(g_display) > 0)\n    {\n        g_memset(&xevent, 0, sizeof(xevent));\n        XNextEvent(g_display, &xevent);\n        clip_rv = clipboard_xevent(&xevent);\n        rail_rv = rail_xevent(&xevent);\n        if ((clip_rv == 1) && (rail_rv == 1))\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xcommon_check_wait_objs unknown xevent type %d\",\n                      xevent.type);\n        }\n    }\n    return 0;\n}\n"
  },
  {
    "path": "sesman/chansrv/xcommon.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if !defined(XCOMMON_H)\n#define XCOMMON_H\n\n#include \"arch.h\"\n#include \"parse.h\"\n\n/* 32 implies long */\n#define FORMAT_TO_BYTES(_format) \\\n    (_format) == 32 ? sizeof(long) : (_format) / 8\n\ntypedef void (*x_server_fatal_cb_type)(void);\n\nint\nxcommon_init(void);\nint\nxcommon_get_wait_objs(tbus *objs, int *count, int *timeout);\nint\nxcommon_check_wait_objs(void);\nvoid\nxcommon_set_x_server_fatal_handler(x_server_fatal_cb_type handler);\n\n#endif\n"
  },
  {
    "path": "sesman/display_utils.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2025\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file display_utils.c\n * @brief Definition of utility calls related to display handling\n * @author Matt Burt\n */\n\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n\n#include \"arch.h\"\n#include \"display_utils.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"sesman.h\"\n#include \"sesman_config.h\"\n#include \"set_int.h\"\n#include \"xrdp_sockets.h\"\n\n/******************************************************************************/\n/**\n *\n * @brief checks if there's a server running on a display\n * @param display the display to check\n * @return 0 if there isn't a display running, nonzero otherwise\n *\n */\nstatic int\nx_server_running_check_ports(int display)\n{\n    char text[256];\n    int x_running;\n    int sck;\n\n    (void)snprintf(text, sizeof(text), X11_UNIX_SOCKET_STR, display);\n    x_running = g_file_exist(text);\n\n    if (!x_running)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Did not find a running X server at %s\", text);\n        (void)snprintf(text, sizeof(text), \"/tmp/.X%d-lock\", display);\n        x_running = g_file_exist(text);\n    }\n\n    if (!x_running) /* check 59xx */\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Did not find a running X server at %s\", text);\n        if ((sck = g_tcp_socket()) != -1)\n        {\n            (void)snprintf(text, sizeof(text), \"59%2.2d\", display);\n            x_running = g_tcp_bind(sck, text);\n            g_tcp_close(sck);\n        }\n    }\n\n    if (!x_running) /* check 60xx */\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Did not find a running X server at %s\", text);\n        if ((sck = g_tcp_socket()) != -1)\n        {\n            (void)snprintf(text, sizeof(text), \"60%2.2d\", display);\n            x_running = g_tcp_bind(sck, text);\n            g_tcp_close(sck);\n        }\n    }\n\n    if (!x_running) /* check 62xx */\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Did not find a running X server at %s\", text);\n        if ((sck = g_tcp_socket()) != -1)\n        {\n            (void)snprintf(text, sizeof(text), \"62%2.2d\", display);\n            x_running = g_tcp_bind(sck, text);\n            g_tcp_close(sck);\n        }\n    }\n\n    if (x_running)\n    {\n        LOG(LOG_LEVEL_INFO, \"Found X server running at %s\", text);\n    }\n\n    return x_running;\n}\n\n/******************************************************************************/\nint\ndisplay_utils_get_free_display(const struct set_int *alloc_displays)\n{\n    int display;\n\n    for (display = g_cfg->sess.x11_display_offset;\n            (unsigned int)display <= g_cfg->sess.max_display_number;\n            ++display)\n    {\n        // Have we already allocated this one?\n        if (!set_int_contains(alloc_displays, display))\n        {\n            if (!x_server_running_check_ports(display))\n            {\n                return display;\n            }\n        }\n    }\n\n    LOG(LOG_LEVEL_ERROR,\n        \"X server -- no display in range (%d to %d) is available\",\n        g_cfg->sess.x11_display_offset,\n        g_cfg->sess.max_display_number);\n\n    return -1;\n}\n"
  },
  {
    "path": "sesman/display_utils.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2025\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file display_utils.h\n * @brief Declaration of utility calls related to display handling\n * @author Matt Burt\n */\n\n\n#ifndef DISPLAY_UTILS_H\n#define DISPLAY_UTILS_H\n\nstruct set_int;\n\n/**\n * @brief Gets a free display number\n *\n * @param alloc_displays Displays already allocated (or being allocated) by sesman\n * @return next available display, or -1 if none.\n */\nint\ndisplay_utils_get_free_display(const struct set_int *alloc_displays);\n\n#endif // DISPLAY_UTILS_H\n"
  },
  {
    "path": "sesman/eicp_process.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file eicp_process.c\n * @brief eicp (executive initialisation control protocol) handler function\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"trans.h\"\n\n#include \"eicp.h\"\n#include \"eicp_process.h\"\n#include \"ercp.h\"\n#include \"os_calls.h\"\n#include \"scp_list.h\"\n#include \"session_list.h\"\n#include \"scp.h\"\n#include \"sesman.h\"\n#include \"sesman_access.h\"\n#include \"sesman_config.h\"\n#include \"string_calls.h\"\n#include \"guid.h\"\n\n/******************************************************************************/\n\nstatic int\nprocess_sys_login_response(struct scp_list_item *sli)\n{\n    int rv;\n    int is_logged_in;\n    uid_t uid;\n    int scp_fd;\n\n    rv = eicp_get_sys_login_response(sli->sesexec_trans, &is_logged_in,\n                                     &uid, &scp_fd);\n    if (rv == 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"Received sys login status for %s : %s\",\n            sli->username,\n            (is_logged_in) ? \"logged in\" : \"not logged in\");\n\n        if (!is_logged_in)\n        {\n            // This shouldn't happen. Close the connection to the\n            // client immediately.\n            sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;\n        }\n        else\n        {\n            /* We've been handed back the client connection */\n            sli->client_trans = scp_init_trans_from_fd(scp_fd,\n                                TRANS_TYPE_SERVER,\n                                sesman_is_term);\n            if (sli->client_trans == NULL)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Can't re-create client connection\");\n                g_file_close(scp_fd);\n                sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;\n            }\n            else\n            {\n                sli->client_trans->trans_data_in = sesman_scp_data_in;\n                sli->client_trans->callback_data = (void *)sli;\n                sli->login_state = E_SLI_LOGIN_SYS;\n                sli->uid = uid;\n                // For system logins, don't allow admin access\n                //sli->is_admin = access_login_mng_allowed(&g_cfg->sec,\n                //                sli->username);\n                sli->is_admin = 0;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nprocess_create_session_response(struct scp_list_item *sli)\n{\n    struct session_item *s_item;\n    const char *display;\n    struct guid guid;\n    enum scp_screate_status status;\n\n    int rv = eicp_get_create_session_response(sli->sesexec_trans,\n             &status, &display, &guid);\n    if (rv == 0)\n    {\n        // Create an entry on the session list for the new session\n        if (status == E_SCP_SCREATE_OK &&\n                (s_item = session_list_new()) == NULL)\n        {\n            status = E_SCP_SCREATE_NO_MEMORY;\n        }\n\n        if (status == E_SCP_SCREATE_OK)\n        {\n            // Further comms from sesexec comes over the ERCP\n            // protocol\n            ercp_trans_from_eicp_trans(sli->sesexec_trans,\n                                       sesman_ercp_data_in,\n                                       (void *)s_item);\n\n            // Move the new ERCP transport over to the session list item,\n            // and initialise enough data so that a connection request\n            // can be serviced.\n            s_item->sesexec_trans = sli->sesexec_trans;\n            s_item->sesexec_pid = sli->sesexec_pid;\n            s_item->guid = guid;\n            s_item->uid = sli->uid;\n            strlcpy(s_item->display, display, sizeof(s_item->display));\n\n            // We don't use the sesexec process again\n            sli->sesexec_trans = NULL;\n            sli->sesexec_pid = 0;\n        }\n        else\n        {\n            guid_clear(&guid);\n            display = \"\";\n        }\n        rv = scp_send_create_session_response(sli->client_trans, status,\n                                              display, &guid);\n        sli->create_session_in_progress = 0;\n        sli->session_x11_display = -1;\n    }\n\n    return rv;\n}\n/******************************************************************************/\nint\neicp_process(struct scp_list_item *sli)\n{\n    enum eicp_msg_code msgno;\n    int rv = 0;\n\n    switch ((msgno = eicp_msg_in_get_msgno(sli->sesexec_trans)))\n    {\n        case E_EICP_SYS_LOGIN_RESPONSE:\n            rv = process_sys_login_response(sli);\n            break;\n\n        case E_EICP_CREATE_SESSION_RESPONSE:\n            rv = process_create_session_response(sli);\n            break;\n\n        default:\n        {\n            char buff[64];\n            eicp_msgno_to_str(msgno, buff, sizeof(buff));\n            LOG(LOG_LEVEL_ERROR, \"Ignored EICP message %s\", buff);\n        }\n    }\n    return rv;\n}\n\n"
  },
  {
    "path": "sesman/eicp_process.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file eicp_process.h\n * @brief eicp (executive initialisation control protocol) handler function\n * @author Matt Burt\n *\n */\n\n#ifndef EICP_PROCESS_H\n#define EICP_PROCESS_H\n\nstruct scp_list_item;\n\n/**\n *\n * @brief Processes an EICP message\n * @param sli the sesman connection\n *\n */\nint\neicp_process(struct scp_list_item *sli);\n\n#endif\n"
  },
  {
    "path": "sesman/ercp_process.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file ercp_process.c\n * @brief ERCP (executive run-time control protocol) handler function\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n\n#include \"trans.h\"\n\n#include \"ercp.h\"\n#include \"ercp_process.h\"\n#include \"session_list.h\"\n#include \"string_calls.h\"\n\n/******************************************************************************/\nstatic int\nprocess_session_announce_event(struct session_item *si)\n{\n    int rv;\n    const char *start_ip_addr;\n    const char *instance_name;\n    const char *display;\n\n    rv = ercp_get_session_announce_event(si->sesexec_trans,\n                                         &display,\n                                         &si->uid,\n                                         &si->type,\n                                         &si->start_width,\n                                         &si->start_height,\n                                         &si->bpp,\n                                         &si->guid,\n                                         &start_ip_addr,\n                                         &si->start_time,\n                                         &instance_name);\n\n    if (rv == 0)\n    {\n        snprintf(si->start_ip_addr, sizeof(si->start_ip_addr),\n                 \"%s\", start_ip_addr);\n        strlcpy(si->display, display, sizeof(si->display));\n        snprintf(si->xrdp_instance_name, sizeof(si->xrdp_instance_name),\n                 \"%s\", instance_name);\n\n        si->state = E_SESSION_RUNNING;\n\n        LOG(LOG_LEVEL_INFO,\n            \"sesman: Session on display %s is now running\", si->display);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic void\nprocess_session_finished_event(struct session_item *si)\n{\n    LOG(LOG_LEVEL_INFO, \"sesman: Session on display %s has finished.\",\n        si->display);\n    // Setting the transport down will remove this connection from the list\n    si->sesexec_trans->status = TRANS_STATUS_DOWN;\n}\n\n/******************************************************************************/\nstatic int\nprocess_client_connect_event(struct session_item *si)\n{\n    int rv;\n    const char *client_ip;\n    const char *client_name;\n    time_t connect_time;\n\n    rv = ercp_get_client_connect_event(si->sesexec_trans,\n                                       &client_ip, &client_name, &connect_time);\n    if (rv == 0)\n    {\n        strlcpy(si->client_ip, client_ip, sizeof(si->client_ip));\n        strlcpy(si->client_name, client_name, sizeof(si->client_name));\n        si->last_connect_disconnect = connect_time;\n        LOG(LOG_LEVEL_INFO,\n            \"sesman: Session on display %s is connected from client '%s'\",\n            si->display, si->client_name);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nprocess_client_disconnect_event(struct session_item *si)\n{\n    int rv;\n    time_t disconnect_time;\n\n    rv = ercp_get_client_disconnect_event(si->sesexec_trans, &disconnect_time);\n    if (rv == 0)\n    {\n        si->client_ip[0] = '\\0';\n        si->client_name[0] = '\\0';\n        si->last_connect_disconnect = disconnect_time;\n        LOG(LOG_LEVEL_INFO,\n            \"sesman: Session on display %s has no client connection\",\n            si->display);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nercp_process(struct session_item *si)\n{\n    enum ercp_msg_code msgno;\n    int rv = 0;\n\n    switch ((msgno = ercp_msg_in_get_msgno(si->sesexec_trans)))\n    {\n        case E_ERCP_SESSION_ANNOUNCE_EVENT:\n            rv = process_session_announce_event(si);\n            break;\n\n        case E_ERCP_SESSION_FINISHED_EVENT:\n            process_session_finished_event(si);\n            break;\n\n        case E_ERCP_CLIENT_CONNECT_EVENT:\n            rv = process_client_connect_event(si);\n            break;\n\n        case E_ERCP_CLIENT_DISCONNECT_EVENT:\n            rv = process_client_disconnect_event(si);\n            break;\n\n        default:\n        {\n            char buff[64];\n            ercp_msgno_to_str(msgno, buff, sizeof(buff));\n            LOG(LOG_LEVEL_ERROR, \"Ignored ERCP message %s\", buff);\n        }\n    }\n    return rv;\n}\n\n"
  },
  {
    "path": "sesman/ercp_process.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file ercp_process.h\n * @brief ERCP (executive run-time control protocol) handler function\n * @author Matt Burt\n *\n */\n\n#ifndef ERCP_PROCESS_H\n#define ERCP_PROCESS_H\n\nstruct session_item;\n\n/**\n *\n * @brief Processes an ERCP message\n *\n */\nint\nercp_process(struct session_item *si);\n\n#endif // ERCP_PROCESS_H\n"
  },
  {
    "path": "sesman/libsesman/Makefile.am",
    "content": "#EXTRA_DIST = \\\n  #xrdp_surface.c\n\nAM_CPPFLAGS = \\\n  -DXRDP_PAMCONF_PATH=\\\"${pamconfdir}\\\" \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SOCKET_ROOT_PATH=\\\"${socketdir}\\\" \\\n  -I$(top_srcdir)/libipm \\\n  -I$(top_srcdir)/common\n#  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n#  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n#  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\"\n\n#AM_CFLAGS = $(OPENSSL_CFLAGS)\n\n#AM_LDFLAGS =\n\n#LIBXRDP_EXTRA_LIBS =\n\n#if XRDP_NEUTRINORDP\n#AM_CPPFLAGS += -DXRDP_NEUTRINORDP\n#LIBXRDP_EXTRA_LIBS += $(FREERDP_LIBS)\n#endif\n\n#if XRDP_RFXCODEC\n#AM_CPPFLAGS += -DXRDP_RFXCODEC\n#endif\n\n#if XRDP_TJPEG\n#AM_CPPFLAGS += -DXRDP_JPEG -DXRDP_TJPEG @TurboJpegIncDir@\n#AM_LDFLAGS += @TurboJpegLibDir@\n#LIBXRDP_EXTRA_LIBS += -lturbojpeg\n#else\n#if XRDP_JPEG\n#AM_CPPFLAGS += -DXRDP_JPEG\n#LIBXRDP_EXTRA_LIBS += -ljpeg\n#endif\n#endif\n\nmodule_LTLIBRARIES = \\\n  libsesman.la\n\n# Possible authentication modules\n# See https://www.gnu.org/software/automake/manual/html_node/Conditional-Sources.html\nEXTRA_libsesman_la_SOURCES = \\\n verify_user.c \\\n verify_user_bsd.c \\\n verify_user_kerberos.c \\\n verify_user_pam.c \\\n verify_user_pam_userpass.c\n\n# Make sure the right authentication module is pulled in\nlibsesman_la_DEPENDENCIES = $(AUTHMOD_OBJ)\n\nlibsesman_la_SOURCES = \\\n  sesman_access.h \\\n  sesman_access.c \\\n  sesman_auth.h \\\n  sesman_config.h \\\n  sesman_config.c \\\n  sesman_clip_restrict.h \\\n  sesman_clip_restrict.c\n\nlibsesman_la_LIBADD = \\\n  $(AUTHMOD_OBJ) \\\n  $(top_builddir)/libipm/libipm.la \\\n  $(top_builddir)/common/libcommon.la \\\n  $(AUTHMOD_LIB)\n"
  },
  {
    "path": "sesman/libsesman/sesman_access.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesman_access.c\n * @brief User access control code\n * @author Simone Fedele\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n\n#include \"arch.h\"\n\n#include \"sesman_access.h\"\n#include \"sesman_config.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n\n/******************************************************************************/\n/**\n * user is root\n *\n * @return 1 if user is UID 0\n */\nstatic int\nuser_is_root(const char *user)\n{\n    int uid = -1;\n    (void)g_getuser_info_by_name(user, &uid, NULL, NULL, NULL, NULL);\n    return (uid == 0);\n}\n\n/******************************************************************************/\nint\naccess_login_allowed(const struct config_security *cfg_sec, const char *user)\n{\n    int ok = 0;\n\n    if (!cfg_sec->allow_root && user_is_root(user))\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"ROOT login attempted, but root login is disabled\");\n    }\n    else\n    {\n        const char *group = cfg_sec->ts_users;\n        const char *param = \"TerminalServerUsers\";\n        int gid = -1;\n\n        if (group == NULL || group[0] == '\\0')\n        {\n            /* Group is not defined. Default access depends on whether\n             * we must have the group or not */\n            if (cfg_sec->ts_always_group_check)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"%s group is not defined. Access denied for %s\",\n                    param, user);\n            }\n            else\n            {\n                LOG(LOG_LEVEL_INFO,\n                    \"%s group is not defined. Access granted for %s\",\n                    param, user);\n                ok = 1;\n            }\n        }\n        else if (g_getgroup_info(group, &gid) != 0)\n        {\n            /* Group is defined but doesn't exist. Default access depends\n             * on whether we must have the group or not */\n            if (cfg_sec->ts_always_group_check)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"%s group %s doesn't exist. Access denied for %s\",\n                    param, group, user);\n            }\n            else\n            {\n                LOG(LOG_LEVEL_INFO,\n                    \"%s group %s doesn't exist. Access granted for %s\",\n                    param, group, user);\n                ok = 1;\n            }\n        }\n        else if (0 != g_check_user_in_group(user, gid, &ok))\n        {\n            LOG(LOG_LEVEL_ERROR, \"Error checking %s group %s. \"\n                \"Access denied for %s\", param, group, user);\n        }\n        else if (!ok)\n        {\n            LOG(LOG_LEVEL_ERROR, \"User %s is not in %s group %s. Access denied\",\n                user, param, group);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_INFO, \"User %s is in %s group %s. Access granted\",\n                user, param, group);\n        }\n    }\n\n    return ok;\n}\n\n/******************************************************************************/\nint\naccess_login_is_admin(const struct config_security *cfg_sec,\n                      const char *user)\n{\n    int ok = 0;\n\n    const char *group = cfg_sec->ts_admins;\n    const char *param = \"TerminalServerAdmins\";\n    int gid = -1;\n\n    if (group == NULL || group[0] == '\\0')\n    {\n        if (cfg_sec->ts_always_group_check)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s group is not defined\", param);\n        }\n    }\n    else if (g_getgroup_info(group, &gid) != 0)\n    {\n        /* Group is defined but doesn't exist */\n        if (cfg_sec->ts_always_group_check)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s group %s doesn't exist.\", param, group);\n        }\n    }\n    else if (0 != g_check_user_in_group(user, gid, &ok))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error checking %s group %s.\", param, group);\n    }\n\n    // Root always has access. Do other checks and logging first\n    if (!ok && user_is_root(user))\n    {\n        ok = 1;\n    }\n\n    if (ok)\n    {\n        LOG(LOG_LEVEL_INFO, \"User %s is in %s group %s\", user, param, group);\n    }\n\n    return ok;\n}\n"
  },
  {
    "path": "sesman/libsesman/sesman_access.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesman_access.h\n * @brief User access control definitions\n * @author Simone Fedele\n *\n */\n\n#ifndef SESMAN_ACCESS_H\n#define SESMAN_ACCESS_H\n\nstruct config_security;\n\n/**\n *\n * @brief Checks if the user is allowed to access the terminal server\n * @param user the user to check\n * @return 0 if access is denied, !=0 if allowed\n *\n */\nint\naccess_login_allowed(const struct config_security *cfg_sec,\n                     const char *user);\n\n/**\n *\n * @brief Checks if the user is allowed to admin the terminal server\n * @param user the user to check\n * @return != 0 if the user can perform administrative tasks\n *\n */\nint\naccess_login_is_admin(const struct config_security *cfg_sec,\n                      const char *user);\n\n#endif\n"
  },
  {
    "path": "sesman/libsesman/sesman_auth.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2012\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesman_auth.h\n * @brief User authentication definitions\n * @author Jay Sorg\n *\n */\n\n#ifndef SESMAN_AUTH_H\n#define SESMAN_AUTH_H\n\n/**\n * Opaque type used to represent an authentication handle\n */\nstruct auth_info;\n#include \"scp_application_types.h\"\n\n/**\n *\n * @brief Validates user's password\n * @param user user's login name\n * @param pass user's password\n * @param client_ip IP address of connecting client (or \"\"/NULL if not known)\n * @param[out] errorcode Error code for the operation. E_SCP_LOGIN_OK on success.\n * @return auth handle on success, NULL on failure\n *\n */\nstruct auth_info *\nauth_userpass(const char *user, const char *pass,\n              const char *client_ip, enum scp_login_status *errorcode);\n\n/**\n *\n * @brief Gets an auth handle for a UDS login\n *\n * @param user User ID\n * @param[out] errorcode Error code for the operation. E_SCP_LOGIN_OK on success.\n *             Can be NULL if this information isn't required.\n * @return auth handle on success, NULL on failure\n *\n */\nstruct auth_info *\nauth_uds(const char *user, enum scp_login_status *errorcode);\n\n/**\n *\n * @brief Starts a session\n * @param auth_info Auth handle created by auth_userpass\n * @param display Display name\n * @return 0 on success, 1 on failure\n *\n * The resources allocated when the session is started are de-allocated\n * by auth_end() - there is no separate way to do this.\n */\nint\nauth_start_session(struct auth_info *auth_info, const char *display);\n\n/**\n *\n * @brief Deallocates an auth handle and releases all resources\n * @param auth_info Auth handle created by auth_userpass\n * @return 0 on success, 1 on failure\n *\n */\nint\nauth_end(struct auth_info *auth_info);\n\n/**\n *\n * @brief Sets up the environment for a session started\n *        with auth_start_session()\n *\n * This call is only effective for PAM-based environments. It must be made\n * after the context has been switched to the logged-in user.\n *\n * @param auth_info Auth handle created by auth_userpass\n * @return 0 on success, 1 on failure\n *\n */\nint\nauth_set_env(struct auth_info *auth_info);\n\n\n#define AUTH_PWD_CHG_OK                0\n#define AUTH_PWD_CHG_CHANGE            1\n#define AUTH_PWD_CHG_CHANGE_MANDATORY  2\n#define AUTH_PWD_CHG_NOT_NOW           3\n#define AUTH_PWD_CHG_ERROR             4\n\n/**\n *\n * @brief WIP - Checks to see if the password for a user needs changing\n *\n * @param user - Username to check\n * @return 0 on success, 1 on failure\n *\n */\nint\nauth_check_pwd_chg(const char *user);\n\n/**\n *\n * @brief WIP - Changes the password for a user\n *\n * @param user Username to check\n * @param newpwd New password for user\n * @return 0 on success, 1 on failure\n *\n */\nint\nauth_change_pwd(const char *user, const char *newpwd);\n\n#endif\n"
  },
  {
    "path": "sesman/libsesman/sesman_clip_restrict.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesman_clip_restrict.c\n * @brief Routine for parsing clip restrict strings\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n\n#include \"arch.h\"\n#include \"sesman_clip_restrict.h\"\n#include \"string_calls.h\"\n\n/*\n  Map clipboard strings into bitmask values.\n*/\nstatic const struct bitmask_string clip_restrict_map[] =\n{\n    { CLIP_RESTRICT_TEXT, \"text\"},\n    { CLIP_RESTRICT_FILE, \"file\"},\n    { CLIP_RESTRICT_IMAGE, \"image\"},\n    { CLIP_RESTRICT_ALL, \"all\"},\n    { CLIP_RESTRICT_NONE, \"none\"},\n    /* Compatibility values */\n    { CLIP_RESTRICT_ALL, \"true\"},\n    { CLIP_RESTRICT_ALL, \"yes\"},\n    { CLIP_RESTRICT_NONE, \"false\"},\n    BITMASK_STRING_END_OF_LIST\n};\n\n/******************************************************************************/\nint\nsesman_clip_restrict_string_to_bitmask(\n    const char *inputstr,\n    char *unrecognised,\n    unsigned int unrecognised_len)\n{\n    return g_str_to_bitmask(inputstr, clip_restrict_map, \",\",\n                            unrecognised, unrecognised_len);\n}\n\n/******************************************************************************/\nint\nsesman_clip_restrict_mask_to_string(\n    int mask,\n    char output[],\n    unsigned int output_len)\n{\n    int rv;\n\n    if (mask == CLIP_RESTRICT_NONE)\n    {\n        rv = snprintf(output, output_len, \"none\");\n    }\n    else if (mask == CLIP_RESTRICT_ALL)\n    {\n        rv = snprintf(output, output_len, \"all\");\n    }\n    else\n    {\n        rv = g_bitmask_to_str(mask, clip_restrict_map, ',', output, output_len);\n    }\n\n    return rv;\n}\n\n"
  },
  {
    "path": "sesman/libsesman/sesman_clip_restrict.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * This file contains the chansrv configuration parameters from sesman.ini\n */\n\n#ifndef SESMAN_CLIP_RESTRICT_H\n#define SESMAN_CLIP_RESTRICT_H\n\n#define CLIP_RESTRICT_NONE 0\n#define CLIP_RESTRICT_TEXT (1<<0)\n#define CLIP_RESTRICT_FILE (1<<1)\n#define CLIP_RESTRICT_IMAGE (1<<2)\n#define CLIP_RESTRICT_ALL 0x7fffffff\n\n/**\n * Converts a sesman clip restrict string to a bitmask\n *\n * @param inputstr Input string\n * @param unrecognised buffer for unrecognised tokens\n * @param unrecognised_len Length of the above\n * @return Bitmask\n *\n * The input is a comma-separated list of tokens as documented in\n * the sesman.ini manpage */\nint\nsesman_clip_restrict_string_to_bitmask(\n    const char *inputstr,\n    char *unrecognised,\n    unsigned int unrecognised_len);\n\n/**\n * Converts a sesman clip restrict bitmask to a string\n *\n * @param mask Input mask\n * @param output buffer for output string\n * @param output_len Length of the above\n * @return Length as for snprintf()\n */\nint\nsesman_clip_restrict_mask_to_string(\n    int mask,\n    char output[],\n    unsigned int output_len);\n\n#endif /* SESMAN_CLIP_RESTRICT_H */\n\n"
  },
  {
    "path": "sesman/libsesman/sesman_config.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file config.c\n * @brief User authentication code\n * @author Simone Fedele @< simo [at] esseemme [dot] org @>\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"sesman_config.h\"\n#include \"sesman_clip_restrict.h\"\n\n#include \"list.h\"\n#include \"file.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n//#include \"chansrv/chansrv_common.h\"\n#include \"scp.h\"\n\n#define SESMAN_CFG_GLOBALS           \"Globals\"\n#define SESMAN_CFG_DEFWM             \"DefaultWindowManager\"\n#define SESMAN_CFG_ADDRESS           \"ListenAddress\"\n#define SESMAN_CFG_PORT              \"ListenPort\"\n#define SESMAN_CFG_ENABLE_USERWM     \"EnableUserWindowManager\"\n#define SESMAN_CFG_USERWM            \"UserWindowManager\"\n#define SESMAN_CFG_AUTH_FILE_PATH    \"AuthFilePath\"\n#define SESMAN_CFG_RECONNECT_SH      \"ReconnectScript\"\n#define SESMAN_CFG_ALWAYS_RUN_RECONNECT \"AlwaysRunReconnect\"\n\n#define SESMAN_CFG_XORG_PARAMS       \"Xorg\"\n#define SESMAN_CFG_VNC_PARAMS        \"Xvnc\"\n\n#define SESMAN_CFG_SESSION_VARIABLES \"SessionVariables\"\n\n/*\n#define SESMAN_CFG_LOGGING           \"Logging\"\n#define SESMAN_CFG_LOG_FILE          \"LogFile\"\n#define SESMAN_CFG_LOG_LEVEL         \"LogLevel\"\n#define SESMAN_CFG_LOG_ENABLE_SYSLOG \"EnableSyslog\"\n#define SESMAN_CFG_LOG_SYSLOG_LEVEL  \"SyslogLevel\"\n*/\n#define SESMAN_CFG_SECURITY                        \"Security\"\n#define SESMAN_CFG_SEC_LOGIN_RETRY                 \"MaxLoginRetry\"\n#define SESMAN_CFG_XAUTH_IN_SYSDIR                 \"XAuthorityInSystemDir\"\n#define SESMAN_CFG_SEC_ALLOW_ROOT                  \"AllowRootLogin\"\n#define SESMAN_CFG_SEC_USR_GROUP                   \"TerminalServerUsers\"\n#define SESMAN_CFG_SEC_ADM_GROUP                   \"TerminalServerAdmins\"\n#define SESMAN_CFG_SEC_ALWAYSGROUPCHECK            \"AlwaysGroupCheck\"\n#define SESMAN_CFG_SEC_RESTRICT_OUTBOUND_CLIPBOARD \"RestrictOutboundClipboard\"\n#define SESMAN_CFG_SEC_RESTRICT_INBOUND_CLIPBOARD  \"RestrictInboundClipboard\"\n#define SESMAN_CFG_SEC_ALLOW_ALTERNATE_SHELL       \"AllowAlternateShell\"\n#define SESMAN_CFG_SEC_PASS_SHELL_AS_ENV           \"PassShellAsEnv\"\n#define SESMAN_CFG_SEC_XORG_NO_NEW_PRIVILEGES      \"XorgNoNewPrivileges\"\n#define SESMAN_CFG_SEC_SESSION_SOCKDIR_GROUP       \"SessionSockdirGroup\"\n\n#define SESMAN_CFG_SESSIONS          \"Sessions\"\n#define SESMAN_CFG_SESS_MAX          \"MaxSessions\"\n#define SESMAN_CFG_SESS_KILL_DISC    \"KillDisconnected\"\n#define SESMAN_CFG_SESS_IDLE_LIMIT   \"IdleTimeLimit\"\n#define SESMAN_CFG_SESS_DISC_LIMIT   \"DisconnectedTimeLimit\"\n#define SESMAN_CFG_SESS_X11DISPLAYOFFSET \"X11DisplayOffset\"\n#define SESMAN_CFG_SESS_MAX_DISPLAY  \"MaxDisplayNumber\"\n#define SESMAN_CFG_SESS_STARTUP_WAIT_TIME \"StartupWaitTime\"\n\n#define SESMAN_CFG_SESS_POLICY_S \"Policy\"\n#define SESMAN_CFG_SESS_POLICY_DFLT_S \"Default\"\n#define SESMAN_CFG_SESS_POLICY_SEP_S \"Separate\"\n\nstatic const struct bitmask_char policy_bits[] =\n{\n    { SESMAN_CFG_SESS_POLICY_U, 'U'  },\n    { SESMAN_CFG_SESS_POLICY_B, 'B'  },\n    { SESMAN_CFG_SESS_POLICY_D, 'D'  },\n    { SESMAN_CFG_SESS_POLICY_I, 'I'  },\n    { SESMAN_CFG_SESS_POLICY_N, 'N'  },\n    BITMASK_CHAR_END_OF_LIST\n};\n\n/***************************************************************************//**\n * Parse a session allocation policy string\n */\nstatic unsigned int\nparse_policy_string(const char *value)\n{\n    unsigned int rv;\n    char unrecognised[16];\n\n    if (0 == g_strcasecmp(value, SESMAN_CFG_SESS_POLICY_DFLT_S))\n    {\n        rv = SESMAN_CFG_SESS_POLICY_DEFAULT;\n    }\n    else if (0 == g_strcasecmp(value, SESMAN_CFG_SESS_POLICY_SEP_S))\n    {\n        rv = SESMAN_CFG_SESS_POLICY_SEPARATE;\n    }\n    else\n    {\n        unrecognised[0] = '\\0';\n        rv = g_charstr_to_bitmask(value, policy_bits, unrecognised,\n                                  sizeof(unrecognised));\n        if (unrecognised[0] != '\\0')\n        {\n            LOG(LOG_LEVEL_WARNING, \"Character(s) '%s' in the session\"\n                \" allocation policy are not recognised\", unrecognised);\n\n            if (g_strchr(unrecognised, 'C') != NULL ||\n                    g_strchr(unrecognised, 'c') != NULL)\n            {\n                /* Change from xrdp v0.9.x */\n                LOG(LOG_LEVEL_WARNING, \"Character 'C' is no longer used\"\n                    \" in session allocation policies - use '%s'\",\n                    SESMAN_CFG_SESS_POLICY_SEP_S);\n            }\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nconfig_output_policy_string(unsigned int value,\n                            char *buff, unsigned int bufflen)\n{\n    int rv = 0;\n    if (bufflen > 0)\n    {\n        if (value & SESMAN_CFG_SESS_POLICY_DEFAULT)\n        {\n            rv = g_snprintf(buff, bufflen, \"Default\");\n        }\n        else if (value & SESMAN_CFG_SESS_POLICY_SEPARATE)\n        {\n            rv = g_snprintf(buff, bufflen, \"Separate\");\n        }\n        else\n        {\n            rv = g_bitmask_to_charstr(value, policy_bits, buff, bufflen, NULL);\n        }\n    }\n\n    return rv;\n}\n\n/***************************************************************************//**\n *\n * @brief Reads sesman [global] configuration section\n * @param file configuration file descriptor\n * @param cf pointer to a config struct\n * @param param_n parameter name list\n * @param param_v parameter value list\n * @return 0 on success, 1 on failure\n *\n */\nstatic int\nconfig_read_globals(int file, struct config_sesman *cf, struct list *param_n,\n                    struct list *param_v)\n{\n    int i;\n\n    list_clear(param_v);\n    list_clear(param_n);\n\n    /* resetting the struct */\n    cf->listen_port[0] = '\\0';\n    cf->enable_user_wm = 0;\n    cf->user_wm = g_strdup(\"\");\n    cf->default_wm = 0;\n    cf->auth_file_path = 0;\n    cf->reconnect_sh = 0;\n    cf->always_run_reconnect = 0;\n\n    file_read_section(file, SESMAN_CFG_GLOBALS, param_n, param_v);\n\n    for (i = 0; i < param_n->count; i++)\n    {\n        const char *param = (const char *)list_get_item(param_n, i);\n        const char *val = (const char *)list_get_item(param_v, i);\n\n        if (0 == g_strcasecmp(param, SESMAN_CFG_DEFWM))\n        {\n            cf->default_wm = g_strdup(val);\n        }\n        else if (0 == g_strcasecmp(param, SESMAN_CFG_USERWM))\n        {\n            g_free(cf->user_wm);\n            cf->user_wm = g_strdup(val);\n        }\n        else if (0 == g_strcasecmp(param, SESMAN_CFG_ENABLE_USERWM))\n        {\n            cf->enable_user_wm = g_text2bool(val);\n        }\n        else if (0 == g_strcasecmp(param, SESMAN_CFG_PORT))\n        {\n            scp_port_to_unix_domain_path(val, cf->listen_port,\n                                         sizeof(cf->listen_port));\n        }\n        else if (0 == g_strcasecmp(param, SESMAN_CFG_AUTH_FILE_PATH))\n        {\n            cf->auth_file_path = g_strdup(val);\n        }\n        else if (g_strcasecmp(param, SESMAN_CFG_RECONNECT_SH) == 0)\n        {\n            cf->reconnect_sh = g_strdup(val);\n        }\n        else if (g_strcasecmp(param, SESMAN_CFG_ALWAYS_RUN_RECONNECT) == 0)\n        {\n            cf->always_run_reconnect = g_text2bool(val);\n        }\n        else if (0 == g_strcasecmp(param, SESMAN_CFG_ADDRESS))\n        {\n            /* Config must be updated for Unix Domain Sockets */\n            LOG(LOG_LEVEL_WARNING, \"Obsolete setting' \" SESMAN_CFG_ADDRESS\n                \"' in [\" SESMAN_CFG_GLOBALS \"] should be removed.\");\n            LOG(LOG_LEVEL_WARNING, \"Review setting' \" SESMAN_CFG_PORT \"' in [\"\n                SESMAN_CFG_GLOBALS \"]\");\n        }\n    }\n\n    /* checking for missing required parameters */\n    if ('\\0' == cf->listen_port[0])\n    {\n        /* Load the default value */\n        scp_port_to_unix_domain_path(NULL, cf->listen_port,\n                                     sizeof(cf->listen_port));\n    }\n\n    if ('\\0' == cf->user_wm[0])\n    {\n        cf->enable_user_wm = 0;\n    }\n\n    if (cf->default_wm == 0 || cf->default_wm[0] == '\\0')\n    {\n        g_free(cf->default_wm);\n        cf->default_wm = g_strdup(\"startwm.sh\");\n    }\n    /* if default_wm doesn't begin with '/', it's a relative path to\n     * XRDP_CFG_PATH */\n    if (cf->default_wm[0] != '/')\n    {\n        /* sizeof operator returns string length including null terminator  */\n        int length = (sizeof(XRDP_CFG_PATH) +\n                      g_strlen(cf->default_wm) + 1); /* '/' */\n        char *buf = (char *)g_malloc(length, 0);\n        g_sprintf(buf, \"%s/%s\", XRDP_CFG_PATH, cf->default_wm);\n        g_free(cf->default_wm);\n        cf->default_wm = buf;\n    }\n\n    if (cf->reconnect_sh == 0 || cf->reconnect_sh[0] == '\\0')\n    {\n        g_free(cf->reconnect_sh);\n        cf->reconnect_sh = g_strdup(\"reconnectwm.sh\");\n    }\n    /* if reconnect_sh doesn't begin with '/', it's a relative path to\n     * XRDP_CFG_PATH */\n    if (cf->reconnect_sh[0] != '/')\n    {\n        /* sizeof operator returns string length including null terminator  */\n        int length = (sizeof(XRDP_CFG_PATH) +\n                      g_strlen(cf->reconnect_sh) + 1); /* '/' */\n        char *buf = (char *)g_malloc(length, 0);\n        g_sprintf(buf, \"%s/%s\", XRDP_CFG_PATH, cf->reconnect_sh);\n        g_free(cf->reconnect_sh);\n        cf->reconnect_sh = buf;\n    }\n\n    return 0;\n}\n\n/***************************************************************************//**\n *\n * @brief Reads sesman [Security] configuration section\n * @param file configuration file descriptor\n * @param sc pointer to a config_security struct\n * @param param_n parameter name list\n * @param param_v parameter value list\n * @return 0 on success, 1 on failure\n *\n */\nstatic int\nconfig_read_security(int file, struct config_security *sc,\n                     struct list *param_n,\n                     struct list *param_v)\n{\n    int i;\n    const char *buf;\n    const char *value;\n\n    list_clear(param_v);\n    list_clear(param_n);\n\n    /* setting defaults */\n    sc->allow_root = 0;\n    sc->login_retry = 3;\n    sc->xauth_in_sysdir = 0;\n    sc->restrict_outbound_clipboard = 0;\n    sc->restrict_inbound_clipboard = 0;\n    sc->allow_alternate_shell = 1;\n    sc->pass_shell_as_env = g_strdup(\"\");\n    sc->xorg_no_new_privileges = 1;\n    sc->ts_users = g_strdup(\"\");\n    sc->ts_admins = g_strdup(\"\");\n    sc->session_sockdir_group = g_strdup(\"\");\n\n    file_read_section(file, SESMAN_CFG_SECURITY, param_n, param_v);\n\n    for (i = 0; i < param_n->count; i++)\n    {\n        buf = (const char *)list_get_item(param_n, i);\n        value = (const char *)list_get_item(param_v, i);\n\n        if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ALLOW_ROOT))\n        {\n            sc->allow_root = g_text2bool(value);\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_LOGIN_RETRY))\n        {\n            sc->login_retry = g_atoi(value);\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_XAUTH_IN_SYSDIR))\n        {\n            sc->xauth_in_sysdir = g_text2bool(value);\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_USR_GROUP))\n        {\n            g_free(sc->ts_users);\n            sc->ts_users = g_strdup(value);\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ADM_GROUP))\n        {\n            g_free(sc->ts_admins);\n            sc->ts_admins = g_strdup(value);\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ALWAYSGROUPCHECK))\n        {\n            sc->ts_always_group_check = g_text2bool(value);\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_RESTRICT_OUTBOUND_CLIPBOARD))\n        {\n            char unrecognised[256];\n            sc->restrict_outbound_clipboard =\n                sesman_clip_restrict_string_to_bitmask(\n                    (const char *)list_get_item(param_v, i),\n                    unrecognised, sizeof(unrecognised));\n            if (unrecognised[0] != '\\0')\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Unrecognised tokens parsing 'RestrictOutboundClipboard' %s\",\n                    unrecognised);\n            }\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_RESTRICT_INBOUND_CLIPBOARD))\n        {\n            char unrecognised[256];\n            sc->restrict_inbound_clipboard =\n                sesman_clip_restrict_string_to_bitmask(\n                    (const char *)list_get_item(param_v, i),\n                    unrecognised, sizeof(unrecognised));\n            if (unrecognised[0] != '\\0')\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Unrecognised tokens parsing 'RestrictInboundClipboard' %s\",\n                    unrecognised);\n            }\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ALLOW_ALTERNATE_SHELL))\n        {\n            sc->allow_alternate_shell =\n                g_text2bool(value);\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_PASS_SHELL_AS_ENV))\n        {\n            g_free(sc->pass_shell_as_env);\n            sc->pass_shell_as_env = g_strdup(value);\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_XORG_NO_NEW_PRIVILEGES))\n        {\n            sc->xorg_no_new_privileges =\n                g_text2bool(value);\n        }\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_SESSION_SOCKDIR_GROUP))\n        {\n            g_free(sc->session_sockdir_group);\n            sc->session_sockdir_group = g_strdup(value);\n        }\n    }\n\n    return 0;\n}\n\n/***************************************************************************//**\n *\n * @brief Reads sesman [Sessions] configuration section\n * @param file configuration file descriptor\n * @param se pointer to a config_sessions struct\n * @param param_n parameter name list\n * @param param_v parameter value list\n * @return 0 on success, 1 on failure\n *\n */\nstatic int\nconfig_read_sessions(int file, struct config_sessions *se, struct list *param_n,\n                     struct list *param_v)\n{\n    int i;\n    const char *buf;\n    const char *value;\n\n    list_clear(param_v);\n    list_clear(param_n);\n\n    /* setting defaults */\n    se->x11_display_offset = 10;\n    // https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml`\n    se->max_display_number = 63;\n    se->max_sessions = 0;\n    se->max_idle_time = 0;\n    se->max_disc_time = 0;\n    se->kill_disconnected = 0;\n    se->policy = SESMAN_CFG_SESS_POLICY_DEFAULT;\n    se->startup_wait_time = 1500;\n\n    file_read_section(file, SESMAN_CFG_SESSIONS, param_n, param_v);\n\n    for (i = 0; i < param_n->count; i++)\n    {\n        buf = (const char *)list_get_item(param_n, i);\n        value = (const char *)list_get_item(param_v, i);\n\n        if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_X11DISPLAYOFFSET))\n        {\n            int x11off = g_atoi(value);\n            if (x11off >= 0)\n            {\n                se->x11_display_offset = x11off;\n            }\n        }\n\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_MAX_DISPLAY))\n        {\n            int mdn = g_atoi(value);\n            if (mdn > 0)\n            {\n                se->max_display_number = mdn;\n            }\n        }\n\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_MAX))\n        {\n            int sm = g_atoi(value);\n            if (sm >= 0)\n            {\n                se->max_sessions = sm;\n            }\n        }\n\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_KILL_DISC))\n        {\n            se->kill_disconnected = g_text2bool(value);\n        }\n\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_IDLE_LIMIT))\n        {\n            se->max_idle_time = g_atoi(value);\n        }\n\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_DISC_LIMIT))\n        {\n            se->max_disc_time = g_atoi(value);\n        }\n\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_POLICY_S))\n        {\n            se->policy = parse_policy_string(value);\n        }\n\n        else if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_STARTUP_WAIT_TIME))\n        {\n            int startup_wait_time = g_atoi(value);\n            if (startup_wait_time > 0 && startup_wait_time <= 15 * 1000)\n            {\n                se->startup_wait_time = startup_wait_time;\n            }\n            else\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Ignoring bad \" SESMAN_CFG_SESS_STARTUP_WAIT_TIME \" value\");\n            }\n        }\n    }\n\n    return 0;\n}\n\n/***************************************************************************//**\n *\n * @brief Reads sesman [Xorg] configuration section\n * @param file configuration file descriptor\n * @param cs pointer to a config_sesman struct\n * @param param_n parameter name list\n * @param param_v parameter value list\n * @return 0 on success, 1 on failure\n *\n */\nstatic int\nconfig_read_xorg_params(int file, struct config_sesman *cs,\n                        struct list *param_n, struct list *param_v)\n{\n    int i;\n\n    list_clear(param_v);\n    list_clear(param_n);\n\n    cs->xorg_params = list_create();\n    cs->xorg_params->auto_free = 1;\n\n    file_read_section(file, SESMAN_CFG_XORG_PARAMS, param_n, param_v);\n\n    for (i = 0; i < param_n->count; i++)\n    {\n        list_add_strdup(cs->xorg_params,\n                        (const char *) list_get_item(param_v, i));\n    }\n\n    return 0;\n}\n\n/***************************************************************************//**\n *\n * @brief Reads sesman [Xvnc] configuration section\n * @param file configuration file descriptor\n * @param cs pointer to a config_sesman struct\n * @param param_n parameter name list\n * @param param_v parameter value list\n * @return 0 on success, 1 on failure\n *\n */\nstatic int\nconfig_read_vnc_params(int file, struct config_sesman *cs, struct list *param_n,\n                       struct list *param_v)\n{\n    int i;\n\n    list_clear(param_v);\n    list_clear(param_n);\n\n    cs->vnc_params = list_create();\n    cs->vnc_params->auto_free = 1;\n\n    file_read_section(file, SESMAN_CFG_VNC_PARAMS, param_n, param_v);\n\n    for (i = 0; i < param_n->count; i++)\n    {\n        list_add_strdup(cs->vnc_params,\n                        (const char *)list_get_item(param_v, i));\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nconfig_read_session_variables(int file, struct config_sesman *cs,\n                              struct list *param_n, struct list *param_v)\n{\n    int i;\n\n    list_clear(param_v);\n    list_clear(param_n);\n\n    cs->env_names = list_create();\n    cs->env_names->auto_free = 1;\n    cs->env_values = list_create();\n    cs->env_values->auto_free = 1;\n\n    file_read_section(file, SESMAN_CFG_SESSION_VARIABLES, param_n, param_v);\n\n    for (i = 0; i < param_n->count; i++)\n    {\n        list_add_strdup(cs->env_names,\n                        (const char *) list_get_item(param_n, i));\n        list_add_strdup(cs->env_values,\n                        (const char *) list_get_item(param_v, i));\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstruct config_sesman *\nconfig_read(const char *sesman_ini)\n{\n    struct config_sesman *cfg;\n    int all_ok = 0;\n\n    if ((cfg = g_new0(struct config_sesman, 1)) != NULL)\n    {\n        if ((cfg->sesman_ini = g_strdup(sesman_ini)) != NULL)\n        {\n            int fd;\n            if ((fd = g_file_open_ro(cfg->sesman_ini)) != -1)\n            {\n                struct list *sec;\n                struct list *param_n;\n                struct list *param_v;\n                sec = list_create();\n                sec->auto_free = 1;\n                file_read_sections(fd, sec);\n                param_n = list_create();\n                param_n->auto_free = 1;\n                param_v = list_create();\n                param_v->auto_free = 1;\n                all_ok = 1;\n\n                /* read global config */\n                config_read_globals(fd, cfg, param_n, param_v);\n\n                /* read Xvnc/Xorg parameter list */\n                config_read_vnc_params(fd, cfg, param_n, param_v);\n                config_read_xorg_params(fd, cfg, param_n, param_v);\n\n                /* read security config */\n                config_read_security(fd, &(cfg->sec), param_n, param_v);\n\n                /* read session config */\n                config_read_sessions(fd, &(cfg->sess), param_n, param_v);\n\n                config_read_session_variables(fd, cfg, param_n, param_v);\n\n                /* cleanup */\n                list_delete(sec);\n                list_delete(param_v);\n                list_delete(param_n);\n                g_file_close(fd);\n            }\n        }\n    }\n\n    if (!all_ok)\n    {\n        config_free(cfg);\n        cfg = NULL;\n    }\n\n    return cfg;\n}\n\n/******************************************************************************/\nvoid\nconfig_dump(struct config_sesman *config)\n{\n    int i;\n    struct config_sessions *se;\n    struct config_security *sc;\n    se = &(config->sess);\n    sc = &(config->sec);\n    char policy_s[64];\n    char restrict_s[64];\n\n    /* Global sesman configuration */\n    g_writeln(\"Filename:                     %s\", config->sesman_ini);\n    g_writeln(\"Global configuration:\");\n    g_writeln(\"    ListenPort:               %s\", config->listen_port);\n    g_writeln(\"    EnableUserWindowManager:  %d\", config->enable_user_wm);\n    g_writeln(\"    UserWindowManager:        %s\", config->user_wm);\n    g_writeln(\"    DefaultWindowManager:     %s\", config->default_wm);\n    g_writeln(\"    ReconnectScript:          %s\", config->reconnect_sh);\n    g_writeln(\"    AlwaysRunReconnect:       %d\", config->always_run_reconnect);\n    g_writeln(\"    AuthFilePath:             %s\",\n              (config->auth_file_path ? config->auth_file_path : \"disabled\"));\n\n    /* Session configuration */\n    config_output_policy_string(se->policy, policy_s, sizeof(policy_s));\n\n    g_writeln(\"Session configuration:\");\n    g_writeln(\"    MaxSessions:              %d\", se->max_sessions);\n    g_writeln(\"    X11DisplayOffset:         %d\", se->x11_display_offset);\n    g_writeln(\"    KillDisconnected:         %d\", se->kill_disconnected);\n    g_writeln(\"    IdleTimeLimit:            %d\", se->max_idle_time);\n    g_writeln(\"    DisconnectedTimeLimit:    %d\", se->max_disc_time);\n    g_writeln(\"    Policy:                   %s\", policy_s);\n    g_writeln(\"    StartupWaitTime:          %u\", se->startup_wait_time);\n\n    /* Security configuration */\n    g_writeln(\"Security configuration:\");\n    g_writeln(\"    AllowRootLogin:            %d\", sc->allow_root);\n    g_writeln(\"    MaxLoginRetry:             %d\", sc->login_retry);\n    g_writeln(\"    XAuthorityInSystemDir:     %d\", sc->xauth_in_sysdir);\n    g_writeln(\"    AlwaysGroupCheck:          %d\", sc->ts_always_group_check);\n    g_writeln(\"    AllowAlternateShell:       %d\", sc->allow_alternate_shell);\n    g_writeln(\"    PassShellAsEnv:            %s\", sc->pass_shell_as_env);\n#ifdef HAVE_SYS_PRCTL_H\n    g_writeln(\"    XorgNoNewPrivileges:       %d\", sc->xorg_no_new_privileges);\n#endif\n    sesman_clip_restrict_mask_to_string(sc->restrict_outbound_clipboard,\n                                        restrict_s, sizeof(restrict_s));\n    g_writeln(\"    RestrictOutboundClipboard: %s\", restrict_s);\n    sesman_clip_restrict_mask_to_string(sc->restrict_inbound_clipboard,\n                                        restrict_s, sizeof(restrict_s));\n\n    g_writeln(\"    RestrictInboundClipboard:  %s\", restrict_s);\n    g_writeln(\"    TSUsersGroup:              %s\", sc->ts_users);\n    g_writeln(\"    TSAdminsGroup:             %s\", sc->ts_admins);\n    g_writeln(\"    SessionSockdirGroup:       %s\", sc->session_sockdir_group);\n\n\n    /* Xorg */\n    if (config->xorg_params->count)\n    {\n        g_writeln(\"Xorg parameters:\");\n    }\n\n    for (i = 0; i < config->xorg_params->count; i++)\n    {\n        g_writeln(\"    Parameter %02d              %s\",\n                  i, (char *) list_get_item(config->xorg_params, i));\n    }\n\n    /* Xvnc */\n    if (config->vnc_params->count)\n    {\n        g_writeln(\"Xvnc parameters:\");\n    }\n\n    for (i = 0; i < config->vnc_params->count; i++)\n    {\n        g_writeln(\"    Parameter %02d              %s\",\n                  i, (char *)list_get_item(config->vnc_params, i));\n    }\n\n    /* SessionVariables */\n    if (config->env_names->count)\n    {\n        g_writeln(\"%s parameters:\", SESMAN_CFG_SESSION_VARIABLES);\n    }\n\n    for (i = 0; i < config->env_names->count; i++)\n    {\n        g_writeln(\"    Parameter %02d              %s=%s\",\n                  i, (char *) list_get_item(config->env_names, i),\n                  (char *) list_get_item(config->env_values, i));\n    }\n}\n\n/******************************************************************************/\nvoid\nconfig_free(struct config_sesman *cs)\n{\n    if (cs != NULL)\n    {\n        g_free(cs->sesman_ini);\n        g_free(cs->default_wm);\n        g_free(cs->user_wm);\n        g_free(cs->reconnect_sh);\n        g_free(cs->auth_file_path);\n        list_delete(cs->vnc_params);\n        list_delete(cs->xorg_params);\n        list_delete(cs->env_names);\n        list_delete(cs->env_values);\n        g_free(cs->sec.pass_shell_as_env);\n        g_free(cs->sec.ts_users);\n        g_free(cs->sec.ts_admins);\n        g_free(cs->sec.session_sockdir_group);\n        g_free(cs);\n    }\n}\n"
  },
  {
    "path": "sesman/libsesman/sesman_config.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesman_config.h\n * @brief User authentication definitions\n * @author Simone Fedele @< simo [at] esseemme [dot] org @>\n *\n */\n\n#ifndef SESMAN_CONFIG_H\n#define SESMAN_CONFIG_H\n\n#include \"arch.h\"\n#include \"list.h\"\n#include \"log.h\"\n\n#include \"xrdp_sockets.h\"\n\nenum SESMAN_CFG_SESS_POLICY_BITS\n{\n    /* If these two are set, they override everything else */\n    SESMAN_CFG_SESS_POLICY_DEFAULT = (1 << 0),\n    SESMAN_CFG_SESS_POLICY_SEPARATE = (1 << 1),\n    /* Configuration bits */\n    SESMAN_CFG_SESS_POLICY_U = (1 << 2),\n    SESMAN_CFG_SESS_POLICY_B = (1 << 3),\n    SESMAN_CFG_SESS_POLICY_D = (1 << 4),\n    SESMAN_CFG_SESS_POLICY_I = (1 << 5),\n    SESMAN_CFG_SESS_POLICY_N = (1 << 6)\n};\n\n/**\n * Name of default sesman.ini file\n */\n#define DEFAULT_SESMAN_INI XRDP_CFG_PATH \"/sesman.ini\"\n\n/**\n *\n * @struct config_security\n * @brief struct that contains sesman access control configuration\n *\n */\nstruct config_security\n{\n    /**\n     * @var allow_root\n     * @brief allow root login on TS\n     */\n    int allow_root;\n    /**\n     * @var login_retry\n     * @brief maximum login attempts\n     */\n    int login_retry;\n    /**\n     * @var x_authority_in_system_dir\n     * @brief Move XAUTHORITY to a system directory\n     */\n    int xauth_in_sysdir;\n\n    /**\n     * @var ts_users\n     * @brief Terminal Server Users group\n     */\n    char *ts_users;\n    /**\n     * @var ts_admins\n     * @brief Terminal Server Administrators group\n     */\n    char *ts_admins;\n    /**\n     * @var ts_always_group_check\n     * @brief if the Groups are not found deny access\n     */\n    int ts_always_group_check;\n    /**\n     * @var restrict_outbound_clipboard\n     * @brief if the clipboard should be enforced restricted. If true only allow client -> server, not vice versa.\n     */\n    int restrict_outbound_clipboard;\n\n    /**\n     * @var restrict_inbound_clipboard\n     * @brief if the clipboard should be enforced restricted. If true only allow server -> client, not vice versa.\n     */\n    int restrict_inbound_clipboard;\n\n    /**\n     * @var allow_alternate_shell\n     * @brief allow an user-supplied alternate shell.\n     * @details 'YES' for all programs allowed, 'NO' for disabling of alternate\n     *          shells.\n     *          If not specified, 'YES' is assumed.\n     */\n    int allow_alternate_shell;\n\n    /**\n     * @var pass_shell_as_env\n     * @brief Passes alternate shells in the environment\n     * @details name of environment variable to receive alternate shell\n     */\n    char *pass_shell_as_env;\n\n    /*\n     * @var xorg_no_new_privileges\n     * @brief if the Xorg X11 server should be started with no_new_privs (Linux only)\n     */\n    int xorg_no_new_privileges;\n\n    /*\n     * @var session_sockdir_group\n     * @brief Group to have read access to the session sockdirs\n     */\n    char *session_sockdir_group;\n};\n\n/**\n *\n * @struct config_sessions\n * @brief struct that contains sesman session handling configuration\n *\n */\nstruct config_sessions\n{\n    /**\n     * @var x11_display_offset\n     * @brief X11 TCP port offset. default value: 10\n     */\n    unsigned int x11_display_offset;\n    /**\n     * @var max_display_number\n     * @brief Highest X11 display number considered for allocation\n     */\n    unsigned int max_display_number;\n    /**\n     * @var max_sessions\n     * @brief maximum number of allowed sessions. 0 for unlimited\n     */\n    unsigned int max_sessions;\n    /**\n     * @var max_idle_time\n     * @brief maximum idle time for each session\n     */\n    int max_idle_time;\n    /**\n     * @var max_disc_time\n     * @brief maximum disconnected time for each session\n     */\n    int max_disc_time;\n    /**\n     * @var kill_disconnected\n     * @brief enables automatic killing of disconnected session\n     */\n    int kill_disconnected;\n    /**\n     * @var policy\n     * @brief session allocation policy\n     */\n    unsigned int policy;\n    /**\n     * @var start wait time\n     * @brief Wait time to make sure a session has started.\n     */\n    unsigned int startup_wait_time;\n};\n\n/**\n *\n * @struct config_sesman\n * @brief struct that contains sesman configuration\n *\n * This struct contains all of sesman configuration parameters<br>\n * Every parameter in [globals] is a member of this struct, other\n * sections options are embedded in this struct as member structures\n *\n */\nstruct config_sesman\n{\n    /**\n     * @var sesman_ini\n     * @brief File that these parameters are read from\n     */\n    char *sesman_ini;\n\n    /**\n     * @var listen_port\n     * @brief Listening port\n     *\n     * This string is used to form the restart directory name, so\n     * can't be the full XRDP_SOCKETS_MAXPATH length.\n     */\n    char listen_port[XRDP_SOCKETS_MAXPATH - 10];\n    /**\n     * @var enable_user_wm\n     * @brief Flag that enables user specific wm\n     */\n    int enable_user_wm;\n    /**\n     * @var default_wm\n     * @brief Default window manager\n     */\n    char *default_wm;\n    /**\n     * @var user_wm\n     * @brief Default window manager.\n     */\n    char *user_wm;\n    /**\n     * @var reconnect_sh\n     * @brief Script executed when reconnected\n     */\n    char *reconnect_sh;\n    /**\n     * @var always_run_reconnect\n     * @brief Do we run the reconnect script on a first connection?\n     */\n    int always_run_reconnect;\n    /**\n     * @var auth_file_path\n     * @brief Auth file path\n     */\n    char *auth_file_path;\n    /**\n     * @var vnc_params\n     * @brief Xvnc additional parameter list\n     */\n    struct list *vnc_params;\n    /**\n     * @var xorg_params\n     * @brief Xorg additional parameter list\n     */\n    struct list *xorg_params;\n    /**\n     * @var log\n     * @brief Log configuration struct\n     */\n    //struct log_config log;\n    /**\n     * @var sec\n     * @brief Security configuration options struct\n     */\n    struct config_security sec;\n    /**\n     * @var sess\n     * @brief Session configuration options struct\n     */\n    struct config_sessions sess;\n\n    /**\n     * @var env_names\n     * @brief environment variable name list\n     */\n    struct list *env_names;\n    /**\n    * @var env_values\n    * @brief environment variable value list\n    */\n    struct list *env_values;\n};\n\n/**\n *\n * @brief Reads sesman configuration\n * @param sesman_ini Name of configuration file to read\n * @return configuration on success, NULL on failure\n *\n * @post pass return value to config_free() to prevent memory leaks\n *\n */\nstruct config_sesman *\nconfig_read(const char *sesman_ini);\n\n/**\n *\n * @brief Dumps configuration\n * @param config pointer to a config_sesman struct\n *\n */\nvoid\nconfig_dump(struct config_sesman *config);\n\n/**\n *\n * @brief Frees configuration allocated by config_read()\n * @param cs pointer to a config_sesman struct (may be NULL)\n *\n */\nvoid\nconfig_free(struct config_sesman *cs);\n\n/**\n * Converts a session allocation Policy value to a strin\n * @param value - Session allocation policy value\n * @param buff - Buffer for result\n * @param bufflen - Length of buffer\n * @return Length of string that would be required without a terminator\n *         to write the whole output (like snprintf())\n */\nint\nconfig_output_policy_string(unsigned int value,\n                            char *buff, unsigned int bufflen);\n\n#endif\n"
  },
  {
    "path": "sesman/libsesman/verify_user.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file verify_user.c\n * @brief Authenticate user using standard unix passwd/shadow system\n * @author Jay Sorg, Simone Fedele\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"sesman_auth.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n#include <stdio.h>\n#include <string.h>\n#include <sys/types.h>\n#include <crypt.h>\n#include <shadow.h>\n#include <pwd.h>\n\n#ifndef SECS_PER_DAY\n#define SECS_PER_DAY (24L*3600L)\n#endif\n\nstatic char *\nauth_crypt_pwd(const char *pwd, const char *pln);\n\nstatic int\nauth_account_disabled(struct spwd *stp);\n\n/*\n * Need a complete type for struct auth_info, even though we're\n * not really using it if this module (UNIX authentication) is selected */\nstruct auth_info\n{\n    char dummy;\n};\n\n/******************************************************************************/\n/* returns non-NULL for success */\nstruct auth_info *\nauth_userpass(const char *user, const char *pass,\n              const char *client_ip, enum scp_login_status *errorcode)\n{\n    const char *encr = NULL;\n    struct passwd *spw;\n\n    /* Need a non-NULL pointer to return to indicate success */\n    static struct auth_info success = {0};\n\n    /* Most likely codepath return from here is 'not authenticated' */\n    enum scp_login_status status = E_SCP_LOGIN_NOT_AUTHENTICATED;\n\n    /* Find the encrypted password */\n    if ((spw = getpwnam(user)) != NULL)\n    {\n        if (g_strncmp(spw->pw_passwd, \"x\", 3) == 0)\n        {\n            struct spwd *stp;\n\n            /* the system is using shadow */\n            if ((stp = getspnam(user)) == NULL)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Can't get shadow entry for account %s\",\n                    user);\n                status = E_SCP_LOGIN_GENERAL_ERROR;\n            }\n            else\n            {\n                if (1 == auth_account_disabled(stp))\n                {\n                    LOG(LOG_LEVEL_INFO, \"account %s is disabled\", user);\n                    status = E_SCP_LOGIN_NOT_AUTHORIZED;\n                }\n                else\n                {\n                    encr = stp->sp_pwdp;\n                }\n            }\n        }\n        else\n        {\n            /* old system with only passwd */\n            encr = spw->pw_passwd;\n        }\n    }\n\n    if (encr != NULL)\n    {\n        const char *epass;\n        if ((epass = crypt(pass, encr)) != NULL &&\n                g_strcmp(encr, epass) == 0)\n        {\n            status = E_SCP_LOGIN_OK;\n        }\n    }\n\n    if (errorcode != NULL)\n    {\n        *errorcode = status;\n    }\n\n    return (status == E_SCP_LOGIN_OK) ? &success : NULL;\n}\n\n/******************************************************************************/\n\nstruct auth_info *\nauth_uds(const char *user, enum scp_login_status *errorcode)\n{\n    struct passwd *spw;\n\n    /* Need a non-NULL pointer to return to indicate success */\n    static struct auth_info success = {0};\n\n    enum scp_login_status status = E_SCP_LOGIN_OK;\n\n    /* Try to check for a disabled account */\n    if ((spw = getpwnam(user)) != NULL)\n    {\n        if (g_strncmp(spw->pw_passwd, \"x\", 3) == 0)\n        {\n            struct spwd *stp;\n\n            /* the system is using shadow */\n            if ((stp = getspnam(user)) == NULL)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Can't get shadow entry for account %s\",\n                    user);\n                status = E_SCP_LOGIN_GENERAL_ERROR;\n            }\n            else\n            {\n                if (1 == auth_account_disabled(stp))\n                {\n                    LOG(LOG_LEVEL_INFO, \"account %s is disabled\", user);\n                    status = E_SCP_LOGIN_NOT_AUTHORIZED;\n                }\n            }\n        }\n    }\n\n    if (errorcode != NULL)\n    {\n        *errorcode = status;\n    }\n\n    return (status == E_SCP_LOGIN_OK) ? &success : NULL;\n}\n\n\n/******************************************************************************/\n/* returns error */\nint\nauth_start_session(struct auth_info *auth_info, const char *display)\n{\n    return 0;\n}\n\n/******************************************************************************/\nint\nauth_end(struct auth_info *auth_info)\n{\n    return 0;\n}\n\n/******************************************************************************/\nint\nauth_set_env(struct auth_info *auth_info)\n{\n    return 0;\n}\n\n/******************************************************************************/\nint\nauth_check_pwd_chg(const char *user)\n{\n    struct passwd *spw;\n    struct spwd *stp;\n    int now;\n    long today;\n\n    spw = getpwnam(user);\n\n    if (spw == 0)\n    {\n        return AUTH_PWD_CHG_ERROR;\n    }\n\n    if (g_strncmp(spw->pw_passwd, \"x\", 3) != 0)\n    {\n        /* old system with only passwd */\n        return AUTH_PWD_CHG_OK;\n    }\n\n    /* the system is using shadow */\n    stp = getspnam(user);\n\n    if (stp == 0)\n    {\n        return AUTH_PWD_CHG_ERROR;\n    }\n\n    /* check if we need a pwd change */\n    now = time(NULL);\n    today = now / SECS_PER_DAY;\n\n    if (stp->sp_expire == -1)\n    {\n        return AUTH_PWD_CHG_OK;\n    }\n\n    if (today >= (stp->sp_lstchg + stp->sp_max - stp->sp_warn))\n    {\n        return AUTH_PWD_CHG_CHANGE;\n    }\n\n    if (today >= (stp->sp_lstchg + stp->sp_max))\n    {\n        return AUTH_PWD_CHG_CHANGE_MANDATORY;\n    }\n\n    if (today < ((stp->sp_lstchg) + (stp->sp_min)))\n    {\n        /* cannot change pwd for now */\n        return AUTH_PWD_CHG_NOT_NOW;\n    }\n\n    return AUTH_PWD_CHG_OK;\n}\n\nint\nauth_change_pwd(const char *user, const char *newpwd)\n{\n    struct passwd *spw;\n    struct spwd *stp;\n    char *newpw;\n    long today;\n\n    FILE *fd;\n\n    if (0 != lckpwdf())\n    {\n        return 1;\n    }\n\n    /* open passwd */\n    spw = getpwnam(user);\n\n    if (spw == 0)\n    {\n        return 1;\n    }\n\n    if (g_strncmp(spw->pw_passwd, \"x\", 3) != 0)\n    {\n        /* old system with only passwd */\n        if ((newpw = auth_crypt_pwd(spw->pw_passwd, newpwd)) == NULL)\n        {\n            ulckpwdf();\n            return 1;\n        }\n\n        spw->pw_passwd = newpw;\n        fd = fopen(\"/etc/passwd\", \"rw\");\n        putpwent(spw, fd);\n    }\n    else\n    {\n        /* the system is using shadow */\n        stp = getspnam(user);\n\n        if (stp == 0)\n        {\n            return 1;\n        }\n\n        /* old system with only passwd */\n        if ((newpw = auth_crypt_pwd(stp->sp_pwdp, newpwd)) == NULL)\n        {\n            ulckpwdf();\n            return 1;\n        }\n\n        stp->sp_pwdp = newpw;\n        today = time(NULL) / SECS_PER_DAY;\n        stp->sp_lstchg = today;\n        stp->sp_expire = today + stp->sp_max + stp->sp_inact;\n        fd = fopen(\"/etc/shadow\", \"rw\");\n        putspent(stp, fd);\n    }\n\n    ulckpwdf();\n    return 0;\n}\n\n/**\n *\n * @brief Password encryption\n * @param pwd Old password\n * @param pln Plaintext new password\n * @return Dynamically allocated new password\n */\n\nstatic char *\nauth_crypt_pwd(const char *pwd, const char *pln)\n{\n    char random[32];\n\n    g_random(random, sizeof(random));\n\n    // crypt_gensalt() is not defined by POSIX, but we have to change\n    // the salt when the password is changed.\n    const char *encr = crypt(pln,\n                             crypt_gensalt(pwd, 0, random, sizeof(random)));\n    return g_strdup(encr);\n}\n\n/**\n *\n * @return 1 if the account is disabled, 0 otherwise\n *\n */\nstatic int\nauth_account_disabled(struct spwd *stp)\n{\n    int today;\n\n    if (0 == stp)\n    {\n        /* if an invalid struct was passed we assume a disabled account */\n        return 1;\n    }\n\n    today = time(NULL) / SECS_PER_DAY;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"last   %ld\", stp->sp_lstchg);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"min    %ld\", stp->sp_min);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"max    %ld\", stp->sp_max);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"inact  %ld\", stp->sp_inact);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"warn   %ld\", stp->sp_warn);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"expire %ld\", stp->sp_expire);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"today  %d\", today);\n\n    if ((stp->sp_expire != -1) && (today >= stp->sp_expire))\n    {\n        return 1;\n    }\n\n    if ((stp->sp_max >= 0) &&\n            (stp->sp_inact >= 0) &&\n            (stp->sp_lstchg > 0) &&\n            (today >= (stp->sp_lstchg + stp->sp_max + stp->sp_inact)))\n    {\n        return 1;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "sesman/libsesman/verify_user_bsd.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2005-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file verify_user_bsd.c\n * @brief Authenticate user using BSD password system\n * @author Renaud Allard\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"sesman_auth.h\"\n\n#define _XOPEN_SOURCE\n#include <stdio.h>\n#include <sys/types.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <time.h>\n#include <limits.h>\n#include <sys/param.h>\n#if defined(OpenBSD)\n#include <login_cap.h>\n#include <bsd_auth.h>\n#else\n/*\n * If OpenBSD isn't defined, add static definitions of OpenBSD-specific\n * functions. This won't work, but will let the compiler on other\n * systems check that all is correctly defined */\nstatic int\nauth_userokay(char *name, char *style, char *type, char *password)\n{\n    fprintf(stderr, \"auth_userokay() not implmented on this platform!\\n\");\n    abort();\n    return 0;\n}\n#endif\n\n\n/*\n * Need a complete type for struct auth_info, even though we're\n * not really using it if this module (BSD authentication) is selected */\nstruct auth_info\n{\n    char dummy;\n};\n\n/******************************************************************************/\n/* returns non-NULL for success */\nstruct auth_info *\nauth_userpass(const char *const_user, const char *const_pass,\n              const char *client_ip, enum scp_login_status *errorcode)\n{\n    /* Need a non-NULL pointer to return to indicate success */\n    static struct auth_info success = {0};\n    enum scp_login_status status;\n\n    // auth_userokay is not const-correct. See usr.sbin/smtpd/smtpd.c in\n    // the OpenBSD source tree for this workaround\n    char user[LOGIN_NAME_MAX];\n    char pass[LINE_MAX];\n    char type[] = \"auth-xrdp\";\n\n    snprintf(user, sizeof(user), \"%s\", const_user);\n    snprintf(pass, sizeof(pass), \"%s\", const_pass);\n\n    if (auth_userokay(user, NULL, type, pass))\n    {\n        status = E_SCP_LOGIN_OK;\n    }\n    else\n    {\n        status = E_SCP_LOGIN_NOT_AUTHENTICATED;\n    }\n\n    if (errorcode != NULL)\n    {\n        *errorcode = status;\n    }\n\n    return (status == E_SCP_LOGIN_OK) ? &success : NULL;\n}\n\n/******************************************************************************/\n/* returns non-NULL for success */\nstruct auth_info *\nauth_uds(const char *user, enum scp_login_status *errorcode)\n{\n    /* Need a non-NULL pointer to return to indicate success */\n    static struct auth_info success = {0};\n\n    if (errorcode != NULL)\n    {\n        *errorcode = E_SCP_LOGIN_OK;\n    }\n\n    return &success;\n}\n\n/******************************************************************************/\n/* returns error */\nint\nauth_start_session(struct auth_info *auth_info, const char *display)\n{\n    return 0;\n}\n\n/******************************************************************************/\nint\nauth_end(struct auth_info *auth_info)\n{\n    return 0;\n}\n\n/******************************************************************************/\nint\nauth_set_env(struct auth_info *auth_info)\n{\n    return 0;\n}\n\n/******************************************************************************/\nint\nauth_check_pwd_chg(const char *user)\n{\n    return 0;\n}\n\nint\nauth_change_pwd(const char *user, const char *newpwd)\n{\n    return 0;\n}\n\nint\nauth_stop_session(struct auth_info *auth_info)\n{\n    return 0;\n}\n"
  },
  {
    "path": "sesman/libsesman/verify_user_kerberos.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file verify_user_kerberos.c\n * @brief Authenticate user using kerberos\n * @author Jay Sorg\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"sesman_auth.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"log.h\"\n\n#include <krb5.h>\n\nstruct auth_info\n{\n    krb5_context ctx;\n    krb5_ccache cc;\n    krb5_principal me;\n};\n\n/******************************************************************************/\n/* Logs a kerberos error code */\nstatic void\nlog_kerberos_failure(krb5_context ctx, krb5_error_code code, const char *where)\n{\n    const char *errstr = krb5_get_error_message(ctx, code);\n    LOG(LOG_LEVEL_ERROR, \"Kerberos call to %s failed [%s]\", where, errstr);\n    krb5_free_error_message(ctx, errstr);\n}\n\n/******************************************************************************/\nint\nauth_end(struct auth_info *auth_info)\n{\n    if (auth_info != NULL)\n    {\n        if (auth_info->me)\n        {\n            krb5_free_principal(auth_info->ctx, auth_info->me);\n        }\n\n        if (auth_info->cc)\n        {\n            krb5_cc_close(auth_info->ctx, auth_info->cc);\n        }\n\n        if (auth_info->ctx)\n        {\n            krb5_free_context(auth_info->ctx);\n        }\n\n        g_memset(auth_info, 0, sizeof(*auth_info));\n        g_free(auth_info);\n    }\n    return 0;\n}\n\n/******************************************************************************/\n/* Checks Kerberos can be used\n *\n * If all is well, an auth_info struct is returned */\nstatic struct auth_info *\nk5_begin(const char *username)\n{\n    int ok = 0;\n    struct auth_info *auth_info = g_new0(struct auth_info, 1);\n    krb5_error_code code;\n\n    if (auth_info == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Out of memory in k5_begin()\");\n    }\n    else if ((code = krb5_init_context(&auth_info->ctx)) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't init Kerberos context\");\n    }\n    /* Determine the credentials cache to use */\n    else if ((code = krb5_cc_default(auth_info->ctx, &auth_info->cc)) != 0)\n    {\n        log_kerberos_failure(auth_info->ctx, code, \"krb5_cc_default\");\n    }\n    /* Parse the username into a full principal */\n    else if ((code = krb5_parse_name(auth_info->ctx,\n                                     username, &auth_info->me)) != 0)\n    {\n        log_kerberos_failure(auth_info->ctx, code, \"krb5_parse_name\");\n    }\n    else\n    {\n        ok = 1;\n    }\n\n    if (!ok)\n    {\n        auth_end(auth_info);\n        auth_info = NULL;\n    }\n\n    return auth_info;\n}\n\n\n/******************************************************************************/\n/* returns boolean */\nstatic enum scp_login_status\nk5_kinit(struct auth_info *auth_info, const char *password)\n{\n    enum scp_login_status status = E_SCP_LOGIN_GENERAL_ERROR;\n    krb5_creds my_creds;\n    krb5_error_code code = 0;\n\n    code = krb5_get_init_creds_password(auth_info->ctx,\n                                        &my_creds, auth_info->me,\n                                        password, NULL, NULL,\n                                        0,\n                                        NULL,\n                                        NULL);\n    if (code != 0)\n    {\n        log_kerberos_failure(auth_info->ctx, code,\n                             \"krb5_get_init_creds_password\");\n        status = E_SCP_LOGIN_NOT_AUTHENTICATED;\n    }\n    else\n    {\n        /*\n         * Try to store the creds in the credentials cache\n         */\n        if ((code = krb5_cc_initialize(auth_info->ctx, auth_info->cc,\n                                       auth_info->me)) != 0)\n        {\n            log_kerberos_failure(auth_info->ctx, code, \"krb5_cc_initialize\");\n        }\n        else if ((code = krb5_cc_store_cred(auth_info->ctx, auth_info->cc,\n                                            &my_creds)) != 0)\n        {\n            log_kerberos_failure(auth_info->ctx, code, \"krb5_cc_store_cred\");\n        }\n        else\n        {\n            status = E_SCP_LOGIN_OK;\n        }\n\n        /* Prevent double-free of the client principal */\n        if (my_creds.client == auth_info->me)\n        {\n            my_creds.client = NULL;\n        }\n\n        krb5_free_cred_contents(auth_info->ctx, &my_creds);\n    }\n\n    return status;\n}\n\n/******************************************************************************/\n/* returns non-NULL for success */\nstruct auth_info *\nauth_userpass(const char *user, const char *pass,\n              const char *client_ip, enum scp_login_status *errorcode)\n{\n    enum scp_login_status status = E_SCP_LOGIN_GENERAL_ERROR;\n    struct auth_info *auth_info = k5_begin(user);\n\n    if (auth_info)\n    {\n        status = k5_kinit(auth_info, pass);\n        if (status != E_SCP_LOGIN_OK)\n        {\n            auth_end(auth_info);\n            auth_info = NULL;\n        }\n    }\n\n    if (errorcode != NULL)\n    {\n        *errorcode = status;\n    }\n\n    return auth_info;\n}\n\n/******************************************************************************/\n/* returns non-NULL for success */\nstruct auth_info *\nauth_uds(const char *user, enum scp_login_status *errorcode)\n{\n    struct auth_info *auth_info = k5_begin(user);\n\n    if (errorcode != NULL)\n    {\n        *errorcode =\n            (auth_info != NULL) ? E_SCP_LOGIN_OK : E_SCP_LOGIN_GENERAL_ERROR;\n    }\n\n    return auth_info;\n}\n\n/******************************************************************************/\n/* returns error */\nint\nauth_start_session(struct auth_info *auth_info, const char *display)\n{\n    return 0;\n}\n\n/******************************************************************************/\nint\nauth_set_env(struct auth_info *auth_info)\n{\n    return 0;\n}\n"
  },
  {
    "path": "sesman/libsesman/verify_user_pam.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file verify_user_pam.c\n * @brief Authenticate user using pam\n * @author Jay Sorg\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n#include \"sesman_auth.h\"\n\n#include <stdio.h>\n#include <security/pam_appl.h>\n\n/* Allows the conversation function to find required items */\nstruct conv_func_data\n{\n    const char *pass;\n};\n\nstruct auth_info\n{\n    int session_opened;\n    int did_setcred;\n    pam_handle_t *ph;\n};\n\n/***************************************************************************//**\n * Returns a string representing a pam_conv message style\n *\n * @param msg_style PAM msg_style (pam_conv(3))\n * @param buff      Buffer for conversion of unrecognised values\n * @param bufflen   Total length of above\n *\n * The buffer described by buff is only written to if required.\n */\nstatic const char *\nmsg_style_to_str(int msg_style, char *buff, unsigned int bufflen)\n{\n    const char *result;\n    switch (msg_style)\n    {\n        case PAM_PROMPT_ECHO_OFF:\n            result = \"PAM_PROMPT_ECHO_OFF\";\n            break;\n\n        case PAM_PROMPT_ECHO_ON:\n            result = \"PAM_PROMPT_ECHO_ON\";\n            break;\n\n        case PAM_ERROR_MSG:\n            result = \"PAM_ERROR_MSG\";\n            break;\n\n        case PAM_TEXT_INFO:\n            result = \"PAM_TEXT_INFO\";\n            break;\n\n        default:\n            g_snprintf(buff, bufflen, \"UNKNOWN_0x%x\", msg_style);\n            result = buff;\n    }\n\n    return result;\n}\n\n/***************************************************************************//**\n * Provides the PAM conversation callback function\n *\n * At present, the main purpose of this function is to supply the\n * user's password to the PAM stack, although some module logging is\n * implemented here.\n *\n * @param[in] num_msg Count of messages in the msg array\n * @param[in] msg Messages from the PAM stack to the application\n * @param[out] resp Message replies from the application to the PAM stack\n * @param[in] appdata_ptr Used to pass in a struct conv_func_data pointer\n *\n * @result PAM_SUCCESS if the messages were all processed successfully.\n *\n * @post If PAM_SUCCESS is returned, resp and its contents are allocated here\n *       and must be freed by the caller\n * @post If PAM_SUCCESS is not returned, resp is not allocated and must not\n *       be not freed by the caller\n *\n * @note See pam_conv(3) for more information\n * @note A basic example conversation function can be found in OSF RFC\n         86.0 (1995)\n */\n\nstatic int\nverify_pam_conv(int num_msg, const struct pam_message **msg,\n                struct pam_response **resp, void *appdata_ptr)\n{\n    int i;\n    struct pam_response *reply = NULL;\n    struct conv_func_data *conv_func_data;\n    char sb[64];\n    int rv = PAM_SUCCESS;\n\n    if (num_msg <= 0 || num_msg > PAM_MAX_NUM_MSG)\n    {\n        rv = PAM_CONV_ERR;\n    }\n    else if ((reply = g_new0(struct pam_response, num_msg)) == NULL)\n    {\n        rv = PAM_BUF_ERR;\n    }\n    else\n    {\n        for (i = 0; i < num_msg && rv == PAM_SUCCESS; i++)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"Handling struct pam_message\"\n                      \" { style = %s, msg = \\\"%s\\\" }\",\n                      msg_style_to_str(msg[i]->msg_style, sb, sizeof (sb)),\n                      msg[i]->msg == NULL ? \"<null>\" : msg[i]->msg);\n\n            switch (msg[i]->msg_style)\n            {\n                case PAM_PROMPT_ECHO_OFF: /* password */\n                    conv_func_data = (struct conv_func_data *) appdata_ptr;\n                    /* Check this function isn't being called\n                     * later than we expected */\n                    if (conv_func_data == NULL || conv_func_data->pass == NULL)\n                    {\n                        LOG(LOG_LEVEL_ERROR,\n                            \"verify_pam_conv: Password unavailable\");\n                        reply[i].resp = g_strdup(\"????\");\n                    }\n                    else\n                    {\n                        reply[i].resp = g_strdup(conv_func_data->pass);\n                    }\n                    break;\n\n                case PAM_ERROR_MSG:\n                    LOG(LOG_LEVEL_ERROR, \"PAM: %s\", msg[i]->msg);\n                    break;\n\n                case PAM_TEXT_INFO:\n                    LOG(LOG_LEVEL_INFO, \"PAM: %s\", msg[i]->msg);\n                    break;\n\n                default:\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Unhandled message in verify_pam_conv\"\n                        \" { style = %s, msg = \\\"%s\\\" }\",\n                        msg_style_to_str(msg[i]->msg_style, sb, sizeof (sb)),\n                        msg[i]->msg == NULL ? \"<null>\" : msg[i]->msg);\n                    rv = PAM_CONV_ERR;\n                }\n            }\n        }\n    }\n\n    if (rv == PAM_SUCCESS)\n    {\n        *resp = reply;\n    }\n    else if (reply != NULL)\n    {\n        for (i = 0; i < num_msg; i++)\n        {\n            if (reply[i].resp != NULL)\n            {\n                g_free(reply[i].resp);\n            }\n        }\n        g_free(reply);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic void\nget_service_name(char *service_name)\n{\n    service_name[0] = 0;\n\n    if (g_file_exist(\"/etc/pam.d/xrdp-sesman\") ||\n#ifdef __LINUX_PAM__\n            /* /usr/lib/pam.d is hardcoded into Linux-PAM */\n            g_file_exist(\"/usr/lib/pam.d/xrdp-sesman\") ||\n#endif\n#ifdef OPENPAM_VERSION\n            /* /usr/local/etc/pam.d is hardcoded into OpenPAM */\n            g_file_exist(\"/usr/local/etc/pam.d/xrdp-sesman\") ||\n#endif\n            g_file_exist(XRDP_PAMCONF_PATH \"/xrdp-sesman\"))\n    {\n        g_strncpy(service_name, \"xrdp-sesman\", 255);\n    }\n    else\n    {\n        g_strncpy(service_name, \"gdm\", 255);\n    }\n}\n\n/******************************************************************************/\n\n/** Performs PAM operations common to login methods\n *\n * @param auth_info Module auth_info structure\n * @param user User name\n * @param pass Password, if needed for authentication.\n * @param client_ip Client IP if known, or NULL\n * @param authentication_required True if user must be authenticated\n *\n * For a UDS connection, the user can be assumed to be authenticated,\n * so in this instance authentication_required can be false.\n *\n * @return Code describing the success of the operation\n */\nstatic enum scp_login_status\ncommon_pam_login(struct auth_info *auth_info,\n                 const char *user,\n                 const char *pass,\n                 const char *client_ip,\n                 int authentication_required)\n{\n    int perror;\n    char service_name[256];\n    struct conv_func_data conv_func_data;\n    struct pam_conv pamc;\n\n    /*\n     * Set up the data required by the conversation function, and the\n     * structure which allows us to pass this to pam_start()\n     */\n    conv_func_data.pass = (authentication_required) ? pass : NULL;\n    pamc.conv = verify_pam_conv;\n    pamc.appdata_ptr = (void *) &conv_func_data;\n\n    get_service_name(service_name);\n    perror = pam_start(service_name, user, &pamc, &(auth_info->ph));\n\n    if (perror != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_start failed: %s\",\n            pam_strerror(auth_info->ph, perror));\n        pam_end(auth_info->ph, perror);\n        return E_SCP_LOGIN_GENERAL_ERROR;\n    }\n\n    if (client_ip != NULL && client_ip[0] != '\\0')\n    {\n        perror = pam_set_item(auth_info->ph, PAM_RHOST, client_ip);\n        if (perror != PAM_SUCCESS)\n        {\n            LOG(LOG_LEVEL_ERROR, \"pam_set_item(PAM_RHOST) failed: %s\",\n                pam_strerror(auth_info->ph, perror));\n        }\n    }\n\n    perror = pam_set_item(auth_info->ph, PAM_TTY, service_name);\n    if (perror != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_set_item(PAM_TTY) failed: %s\",\n            pam_strerror(auth_info->ph, perror));\n    }\n\n    if (authentication_required)\n    {\n        perror = pam_authenticate(auth_info->ph, 0);\n\n        if (perror != PAM_SUCCESS)\n        {\n            LOG(LOG_LEVEL_ERROR, \"pam_authenticate failed: %s\",\n                pam_strerror(auth_info->ph, perror));\n            pam_end(auth_info->ph, perror);\n            return E_SCP_LOGIN_NOT_AUTHENTICATED;\n        }\n    }\n    /* From man page:\n       The pam_acct_mgmt function is used to determine if the users account is\n       valid. It checks for authentication token and account expiration and\n       verifies access restrictions. It is typically called after the user has\n       been authenticated.\n     */\n    perror = pam_acct_mgmt(auth_info->ph, 0);\n\n    if (perror != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_acct_mgmt failed: %s\",\n            pam_strerror(auth_info->ph, perror));\n        pam_end(auth_info->ph, perror);\n        return E_SCP_LOGIN_NOT_AUTHORIZED;\n    }\n\n    /* Set the appdata_ptr passed to the conversation function to\n     * NULL, as the existing value is going out of scope */\n    pamc.appdata_ptr = NULL;\n    perror = pam_set_item(auth_info->ph, PAM_CONV, &pamc);\n    if (perror != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_set_item(PAM_CONV) failed: %s\",\n            pam_strerror(auth_info->ph, perror));\n    }\n\n    return E_SCP_LOGIN_OK;\n}\n\n\n/******************************************************************************/\n/* returns non-NULL for success\n * Detailed error code is in the errorcode variable */\n\nstruct auth_info *\nauth_userpass(const char *user, const char *pass,\n              const char *client_ip, enum scp_login_status *errorcode)\n{\n    struct auth_info *auth_info;\n    enum scp_login_status status;\n\n    auth_info = g_new0(struct auth_info, 1);\n    if (auth_info == NULL)\n    {\n        status = E_SCP_LOGIN_NO_MEMORY;\n    }\n    else\n    {\n        status = common_pam_login(auth_info, user, pass, client_ip, 1);\n\n        if (status != E_SCP_LOGIN_OK)\n        {\n            g_free(auth_info);\n            auth_info = NULL;\n        }\n    }\n\n    if (errorcode != NULL)\n    {\n        *errorcode = status;\n    }\n\n    return auth_info;\n}\n\n/******************************************************************************/\n\nstruct auth_info *\nauth_uds(const char *user, enum scp_login_status *errorcode)\n{\n    struct auth_info *auth_info;\n    enum scp_login_status status;\n\n    auth_info = g_new0(struct auth_info, 1);\n    if (auth_info == NULL)\n    {\n        status = E_SCP_LOGIN_NO_MEMORY;\n    }\n    else\n    {\n        status = common_pam_login(auth_info, user, NULL, NULL, 0);\n\n        if (status != E_SCP_LOGIN_OK)\n        {\n            g_free(auth_info);\n            auth_info = NULL;\n        }\n    }\n\n    if (errorcode != NULL)\n    {\n        *errorcode = status;\n    }\n\n    return auth_info;\n}\n\n/******************************************************************************/\n\n/* returns error */\nstatic int\nauth_start_session_private(struct auth_info *auth_info, const char *display)\n{\n    // For Linux and maybe other systems, pam_systemd needs to know the\n    // session type in order to set the session up correctly\n    const char *session_type;\n    if (g_get_x11_display_from_display_string(display) >= 0)\n    {\n        session_type = \"x11\";\n    }\n    else\n    {\n        session_type = \"wayland\";\n    }\n    g_setenv_log(\"XDG_SESSION_TYPE\", session_type, 1);\n\n    int error = pam_set_item(auth_info->ph, PAM_TTY, display);\n\n    if (error != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_set_item(PAM_TTY) failed: %s\",\n            pam_strerror(auth_info->ph, error));\n        return 1;\n    }\n\n    error = pam_setcred(auth_info->ph, PAM_ESTABLISH_CRED);\n\n    if (error != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_setcred failed: %s\",\n            pam_strerror(auth_info->ph, error));\n        return 1;\n    }\n\n    auth_info->did_setcred = 1;\n    error = pam_open_session(auth_info->ph, 0);\n\n    if (error != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_open_session failed: %s\",\n            pam_strerror(auth_info->ph, error));\n        return 1;\n    }\n\n    auth_info->session_opened = 1;\n    return 0;\n}\n\n/******************************************************************************/\n/**\n * Main routine to start a session\n *\n * Calls the private routine and logs an additional error if the private\n * routine fails\n */\nint\nauth_start_session(struct auth_info *auth_info, const char *display)\n{\n    int result = auth_start_session_private(auth_info, display);\n    if (result != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Can't start PAM session. See PAM logging for more info\");\n    }\n\n    return result;\n}\n\n/******************************************************************************/\n/* returns error */\nstatic int\nauth_stop_session(struct auth_info *auth_info)\n{\n    int rv = 0;\n    int error;\n\n    if (auth_info->session_opened)\n    {\n        error = pam_close_session(auth_info->ph, 0);\n        if (error != PAM_SUCCESS)\n        {\n            LOG(LOG_LEVEL_ERROR, \"pam_close_session failed: %s\",\n                pam_strerror(auth_info->ph, error));\n            rv = 1;\n        }\n        else\n        {\n            auth_info->session_opened = 0;\n        }\n    }\n\n    if (auth_info->did_setcred)\n    {\n        pam_setcred(auth_info->ph, PAM_DELETE_CRED);\n        auth_info->did_setcred = 0;\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/* returns error */\n/* cleanup */\nint\nauth_end(struct auth_info *auth_info)\n{\n    if (auth_info != NULL)\n    {\n        if (auth_info->ph != 0)\n        {\n            auth_stop_session(auth_info);\n\n            pam_end(auth_info->ph, PAM_SUCCESS);\n            auth_info->ph = 0;\n        }\n    }\n\n    g_free(auth_info);\n    return 0;\n}\n\n/******************************************************************************/\n/* returns error */\n/* set any pam env vars */\nint\nauth_set_env(struct auth_info *auth_info)\n{\n    char **pam_envlist;\n    char **pam_env;\n\n    if (auth_info != NULL)\n    {\n        /* export PAM environment */\n        pam_envlist = pam_getenvlist(auth_info->ph);\n\n        if (pam_envlist != NULL)\n        {\n            for (pam_env = pam_envlist; *pam_env != NULL; ++pam_env)\n            {\n                char *str = *pam_env;\n                char *eq_pos = strchr(str, '=');\n\n                if (eq_pos != NULL)\n                {\n                    *eq_pos = '\\0';\n                    g_setenv_log(str, eq_pos + 1, 1);\n                }\n\n                g_free(str);\n            }\n\n            g_free(pam_envlist);\n        }\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "sesman/libsesman/verify_user_pam_userpass.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file verify_user_pam.c\n * @brief Authenticate user using pam\n * @author Jay Sorg\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n#include \"sesman_auth.h\"\n\n#include <security/pam_userpass.h>\n\n#include <stdio.h>\n#include <security/pam_appl.h>\n\n#define SERVICE \"xrdp\"\n\nstruct auth_info\n{\n    pam_userpass_t userpass;\n    int session_opened;\n    int did_setcred;\n    struct pam_conv pamc;\n    pam_handle_t *ph;\n};\n\n/******************************************************************************/\n\n/** Performs PAM operations common to login methods\n *\n * @param auth_info Module auth_info structure\n * @param client_ip Client IP if known, or NULL\n * @param need_pam_authenticate True if user must be authenticated as\n *                              well as authorized\n * @return Code describing the success of the operation\n *\n * The username is assumed to be supplied by the caller in\n * auth_info->userpass.user\n */\nstatic enum scp_login_status\ncommon_pam_login(struct auth_info *auth_info,\n                 const char *client_ip,\n                 int need_pam_authenticate)\n{\n    int perror;\n\n    perror = pam_start(SERVICE, auth_info->userpass.user,\n                       &(auth_info->pamc), &(auth_info->ph));\n\n    if (perror != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_start failed: %s\",\n            pam_strerror(auth_info->ph, perror));\n        pam_end(auth_info->ph, perror);\n        return E_SCP_LOGIN_GENERAL_ERROR;\n    }\n\n    if (client_ip != NULL && client_ip[0] != '\\0')\n    {\n        perror = pam_set_item(auth_info->ph, PAM_RHOST, client_ip);\n        if (perror != PAM_SUCCESS)\n        {\n            LOG(LOG_LEVEL_ERROR, \"pam_set_item(PAM_RHOST) failed: %s\",\n                pam_strerror(auth_info->ph, perror));\n        }\n    }\n\n    perror = pam_set_item(auth_info->ph, PAM_TTY, SERVICE);\n    if (perror != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_set_item(PAM_TTY) failed: %s\",\n            pam_strerror(auth_info->ph, perror));\n    }\n\n    if (need_pam_authenticate)\n    {\n        perror = pam_authenticate(auth_info->ph, 0);\n\n        if (perror != PAM_SUCCESS)\n        {\n            LOG(LOG_LEVEL_ERROR, \"pam_authenticate failed: %s\",\n                pam_strerror(auth_info->ph, perror));\n            pam_end(auth_info->ph, perror);\n            return E_SCP_LOGIN_NOT_AUTHENTICATED;\n        }\n    }\n    /* From man page:\n       The pam_acct_mgmt function is used to determine if the users account is\n       valid. It checks for authentication token and account expiration and\n       verifies access restrictions. It is typically called after the user has\n       been authenticated.\n     */\n    perror = pam_acct_mgmt(auth_info->ph, 0);\n\n    if (perror != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_acct_mgmt failed: %s\",\n            pam_strerror(auth_info->ph, perror));\n        pam_end(auth_info->ph, perror);\n        return E_SCP_LOGIN_NOT_AUTHORIZED;\n    }\n\n    return E_SCP_LOGIN_OK;\n}\n\n\n/******************************************************************************/\n/* returns non-NULL for success\n * Detailed error code is in the errorcode variable */\n\nstruct auth_info *\nauth_userpass(const char *user, const char *pass,\n              const char *client_ip, enum scp_login_status *errorcode)\n{\n    struct auth_info *auth_info;\n    enum scp_login_status status;\n\n    auth_info = g_new0(struct auth_info, 1);\n    if (auth_info == NULL)\n    {\n        status = E_SCP_LOGIN_NO_MEMORY;\n    }\n    else\n    {\n        auth_info->userpass.user = user;\n        auth_info->userpass.pass = pass;\n\n        auth_info->pamc.conv = &pam_userpass_conv;\n        auth_info->pamc.appdata_ptr = &(auth_info->userpass);\n        status = common_pam_login(auth_info, client_ip, 1);\n\n        if (status != E_SCP_LOGIN_OK)\n        {\n            g_free(auth_info);\n            auth_info = NULL;\n        }\n    }\n\n    if (errorcode != NULL)\n    {\n        *errorcode = status;\n    }\n\n    return auth_info;\n}\n\n/******************************************************************************/\n\nstruct auth_info *\nauth_uds(const char *user, enum scp_login_status *errorcode)\n{\n    struct auth_info *auth_info;\n    enum scp_login_status status;\n\n    auth_info = g_new0(struct auth_info, 1);\n    if (auth_info == NULL)\n    {\n        status = E_SCP_LOGIN_NO_MEMORY;\n    }\n    else\n    {\n        auth_info->userpass.user = user;\n        status = common_pam_login(auth_info, NULL, 0);\n\n        if (status != E_SCP_LOGIN_OK)\n        {\n            g_free(auth_info);\n            auth_info = NULL;\n        }\n    }\n\n    if (errorcode != NULL)\n    {\n        *errorcode = status;\n    }\n\n    return auth_info;\n}\n\n/******************************************************************************/\n\n/* returns error */\nstatic int\nauth_start_session_private(struct auth_info *auth_info, const char *display)\n{\n    // For Linux and maybe other systems, pam_systemd needs to know the\n    // session type in order to set the session up correctly\n    const char *session_type;\n    if (g_get_x11_display_from_display_string(display) >= 0)\n    {\n        session_type = \"x11\";\n    }\n    else\n    {\n        session_type = \"wayland\";\n    }\n    g_setenv_log(\"XDG_SESSION_TYPE\", session_type, 1);\n\n    int error = pam_set_item(auth_info->ph, PAM_TTY, display);\n\n    if (error != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_set_item(PAM_TTY) failed: %s\",\n            pam_strerror(auth_info->ph, error));\n        return 1;\n    }\n\n    error = pam_setcred(auth_info->ph, PAM_ESTABLISH_CRED);\n\n    if (error != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_setcred failed: %s\",\n            pam_strerror(auth_info->ph, error));\n        return 1;\n    }\n\n    auth_info->did_setcred = 1;\n    error = pam_open_session(auth_info->ph, 0);\n\n    if (error != PAM_SUCCESS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"pam_open_session failed: %s\",\n            pam_strerror(auth_info->ph, error));\n        return 1;\n    }\n\n    auth_info->session_opened = 1;\n    return 0;\n}\n\n/******************************************************************************/\n/**\n * Main routine to start a session\n *\n * Calls the private routine and logs an additional error if the private\n * routine fails\n */\nint\nauth_start_session(struct auth_info *auth_info, const char *display)\n{\n    int result = auth_start_session_private(auth_info, display);\n    if (result != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Can't start PAM session. See PAM logging for more info\");\n    }\n\n    return result;\n}\n\n/******************************************************************************/\n/* returns error */\nstatic int\nauth_stop_session(struct auth_info *auth_info)\n{\n    int rv = 0;\n    int error;\n\n    if (auth_info->session_opened)\n    {\n        error = pam_close_session(auth_info->ph, 0);\n        if (error != PAM_SUCCESS)\n        {\n            LOG(LOG_LEVEL_ERROR, \"pam_close_session failed: %s\",\n                pam_strerror(auth_info->ph, error));\n            rv = 1;\n        }\n        else\n        {\n            auth_info->session_opened = 0;\n        }\n    }\n\n    if (auth_info->did_setcred)\n    {\n        pam_setcred(auth_info->ph, PAM_DELETE_CRED);\n        auth_info->did_setcred = 0;\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/* returns error */\n/* cleanup */\nint\nauth_end(struct auth_info *auth_info)\n{\n    if (auth_info != NULL)\n    {\n        if (auth_info->ph != 0)\n        {\n            auth_stop_session(auth_info);\n\n            pam_end(auth_info->ph, PAM_SUCCESS);\n            auth_info->ph = 0;\n        }\n    }\n\n    g_free(auth_info);\n    return 0;\n}\n\n/******************************************************************************/\n/* returns error */\n/* set any pam env vars */\nint\nauth_set_env(struct auth_info *auth_info)\n{\n    char **pam_envlist;\n    char **pam_env;\n\n    if (auth_info != NULL)\n    {\n        /* export PAM environment */\n        pam_envlist = pam_getenvlist(auth_info->ph);\n\n        if (pam_envlist != NULL)\n        {\n            for (pam_env = pam_envlist; *pam_env != NULL; ++pam_env)\n            {\n                char *str = *pam_env;\n                char *eq_pos = strchr(str, '=');\n\n                if (eq_pos != NULL)\n                {\n                    *eq_pos = '\\0';\n                    g_setenv_log(str, eq_pos + 1, 1);\n                }\n\n                g_free(str);\n            }\n\n            g_free(pam_envlist);\n        }\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "sesman/lock_uds.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file lock_uds.c\n * @brief Providing a locking facility for Unix Domain Sockets\n * @author Matt Burt\n *\n * It is difficult for a server to determine whether a socket it wishes\n * to listen on is already active or not. The purpose of this module is to\n * provide a locking facility which can be used as a proxy for this.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"log.h\"\n#include \"lock_uds.h\"\n\nstruct lock_uds\n{\n    char *filename; ///<< Name of the lock file\n    int fd; ///<< File descriptor for open file\n    int pid; ///<< PID of process originally taking out lock\n};\n\n/******************************************************************************/\nstruct lock_uds *\nlock_uds(const char *sockname)\n{\n    struct lock_uds *lock = NULL;\n    char *filename = NULL;\n    int fd = -1;\n\n    if (sockname == NULL || sockname[0] != '/')\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"Invalid sockname '%s'\",\n                  (sockname == NULL) ? \"<null>\" : sockname);\n    }\n    else\n    {\n        /* Allocate space for lock filename and result */\n        filename = (char *)g_malloc(g_strlen(sockname) + 1 + 5 + 1, 0);\n        lock = g_new0(struct lock_uds, 1);\n        if (lock == NULL || filename == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s : Out of memory\", __func__);\n        }\n        else\n        {\n            int saved_umask;\n            /* Construct the filename */\n            /* This call is guaranteed to succeed as we know that sockname\n             * contains at least one '/' */\n            char *p = filename;\n            const char *basename = g_strrchr(sockname, '/') + 1;\n            g_memcpy(p, sockname, basename - sockname);\n            p += basename - sockname;\n            *p++ = '.';\n            g_strcpy(p, basename);\n            p += g_strlen(p);\n            *p++ = '.';\n            *p++ = 'l';\n            *p++ = 'o';\n            *p++ = 'c';\n            *p++ = 'k';\n            *p++ = '\\0';\n\n            saved_umask = g_umask_hex(0x77);\n            fd = g_file_open_rw(filename);\n            g_umask_hex(saved_umask);\n            if (fd < 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Unable to create '%s' [%s]\",\n                    filename, g_get_strerror());\n            }\n            else if (g_file_lock(fd, 0, 0) == 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Unable to get lock for '%s' - \"\n                    \"program already running?\", sockname);\n                g_file_close(fd);\n                fd = -1;\n            }\n            else\n            {\n                (void)g_file_set_cloexec(fd, 1);\n            }\n        }\n    }\n\n    if (fd >= 0)\n    {\n        /* Success - finish off */\n        lock->filename = filename;\n        lock->fd = fd;\n        lock->pid = g_getpid();\n    }\n    else\n    {\n        g_free(filename);\n        g_free(lock);\n        lock = NULL;\n    }\n\n    return lock;\n}\n\n/******************************************************************************/\nvoid\nunlock_uds(struct lock_uds *lock)\n{\n    if (lock != NULL)\n    {\n        if (lock->fd >= 0)\n        {\n            g_file_close(lock->fd);\n            lock->fd = -1; // In case of use-after-free\n        }\n\n        /* Only delete the lock file if we are the process which\n         * created it */\n        if (g_getpid() == lock->pid)\n        {\n            g_file_delete(lock->filename);\n        }\n        g_free(lock->filename);\n        lock->filename = NULL;\n        g_free(lock);\n    }\n}\n"
  },
  {
    "path": "sesman/lock_uds.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) 2022 Matt Burt, all xrdp contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file lock_uds.h\n * @brief Providing a locking facility for Unix Domain Sockets\n * @author Matt Burt\n *\n * It is difficult for a server to determine whether a socket it wishes\n * to listen on is already active or not. The purpose of this module is to\n * provide a locking facility which can be used as a proxy for this.\n */\n\n#ifndef LOCK_UDS_H\n#define LOCK_UDS_H\n\nstruct lock_uds;\n\n/**\n * Take out a lock for the specified Unix Domain socket\n * @param sockname Name of socket. Must start with a '/'\n * @return A struct lock_uds instance if the lock was successfully acquired.\n *\n * A NULL return may indicate a lack of memory, or that another\n * process has the lock.\n *\n * A file is created in the same directory as the socket. The name\n * of the file is \".${basename}.lock\", where basename is the base name\n * of the socket. THE file is removed when the lock is relinquished. */\nstruct lock_uds *\nlock_uds(const char *sockname);\n\n/**\n * Relinquish a lock on the specified Unix Domain Socket.\n * @param lock to relinquish\n *\n * If the process which has originally taken out the lock forks, this\n * routine should be called from the child process to prevent the lock\n * inadvertently being passed to the child. */\nvoid\nunlock_uds(struct lock_uds *lock);\n\n#endif // LOCK_UDS_H\n"
  },
  {
    "path": "sesman/notes.txt",
    "content": "************************************************************\n** Notes on the current version of the SCP protocol used  **\n** to communicate with sesman                             **\n**                                                        **\n** This information is for internal documentational use   **\n** only. It may be incomplete. The SCP protocol is        **\n** internal, and may change for even minor releases.      **\n************************************************************\n\nThe SCP protocol is layered on top of libipm, which is in\n../libipm. See ../libipm/scp.h for the interface messages to xrdp-sesman\n"
  },
  {
    "path": "sesman/reconnectwm.sh",
    "content": "#!/bin/sh\n\n# Write procedures here you want to execute on reconnect\n"
  },
  {
    "path": "sesman/scp_list.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file scp_list.h\n * @brief List of SCP connections to sesman (definitions)\n *\n * @author Matt Burt\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n\n#include \"arch.h\"\n#include \"list.h\"\n#include \"os_calls.h\"\n#include \"scp_list.h\"\n#include \"set_int.h\"\n#include \"trans.h\"\n\n#define SCP_LIST_ITEM_IN_USE(sli) \\\n    ( \\\n      (sli) != NULL && \\\n      ( \\\n        ((sli)->client_trans != NULL && (sli)->client_trans->status == TRANS_STATUS_UP) || \\\n        ((sli)->sesexec_trans != NULL && (sli)->sesexec_trans->status == TRANS_STATUS_UP) \\\n      ) \\\n    )\n\nstatic struct list *g_scp_list = NULL;\n\n/**\n * Deletes a scp_list_item, freeing resources\n *\n * After this call, the passed-in pointer is invalid and must not be\n * referenced.\n *\n * Any auth_info struct found in the sesman_con is also deallocated.\n *\n * @param sli struct to de-allocate\n */\nstatic void\nfree_scp_list_item(struct scp_list_item *sli)\n{\n    if (sli != NULL)\n    {\n        trans_delete(sli->client_trans);\n        trans_delete(sli->sesexec_trans);\n        g_free(sli->username);\n        g_free(sli);\n    }\n}\n\n/******************************************************************************/\nint\nscp_list_init(unsigned int list_size)\n{\n    int rv = 1;\n    if (g_scp_list == NULL)\n    {\n        g_scp_list = list_create_sized(list_size);\n    }\n\n    if (g_scp_list == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't allocate SCP list\");\n    }\n    else\n    {\n        g_scp_list->auto_free = 0;\n        rv = 0;\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nvoid\nscp_list_cleanup(void)\n{\n    if (g_scp_list != NULL)\n    {\n        int i;\n        for (i = 0 ; i < g_scp_list->count ; ++i)\n        {\n            struct scp_list_item *p;\n            p = (struct scp_list_item *)list_get_item(g_scp_list, i);\n            free_scp_list_item(p);\n        }\n        list_delete(g_scp_list);\n        g_scp_list = NULL;\n    }\n}\n\n/******************************************************************************/\nunsigned int\nscp_list_get_count(void)\n{\n    return g_scp_list->count;\n}\n\n/******************************************************************************/\nstruct scp_list_item *\nscp_list_item_new(void)\n{\n    struct scp_list_item *result = g_new0(struct scp_list_item, 1);\n    if (result != NULL)\n    {\n        g_snprintf(result->peername, sizeof(result->peername), \"unknown\");\n        result->uid = (uid_t) -1;\n        result->session_x11_display = -1;\n        if (!list_add_item(g_scp_list, (tintptr)result))\n        {\n            g_free(result);\n            result = NULL;\n        }\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nint\nscp_list_set_peername(struct scp_list_item *sli, const char *name)\n{\n    int rv = 1;\n\n    if (sli != NULL && name != NULL)\n    {\n        g_snprintf(sli->peername, sizeof(sli->peername), \"%s\", name);\n        rv = 0;\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nscp_list_get_wait_objs(tbus robjs[], int *robjs_count)\n{\n    int i = 0;\n\n    while (i < g_scp_list->count)\n    {\n        struct scp_list_item *sli;\n        sli = (struct scp_list_item *)list_get_item(g_scp_list, i);\n        int sli_in_use = 0;\n\n        if (sli != NULL)\n        {\n            if (sli->client_trans != NULL &&\n                    sli->client_trans->status == TRANS_STATUS_UP)\n            {\n                robjs[(*robjs_count)++] = sli->client_trans->sck;\n                sli_in_use = 1;\n            }\n\n            if (sli->sesexec_trans != NULL &&\n                    sli->sesexec_trans->status == TRANS_STATUS_UP)\n            {\n                robjs[(*robjs_count)++] = sli->sesexec_trans->sck;\n                sli_in_use = 1;\n            }\n        }\n\n        if (sli_in_use)\n        {\n            ++i;\n        }\n        else\n        {\n            free_scp_list_item(sli);\n            list_remove_item(g_scp_list, i);\n        }\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nint\nscp_list_check_wait_objs(void)\n{\n    int i = 0;\n\n    while (i < g_scp_list->count)\n    {\n        struct scp_list_item *sli;\n        enum scp_list_dispatcher_action action;\n\n        sli = (struct scp_list_item *)list_get_item(g_scp_list, i);\n        action = E_SLD_TERMINATE_SCP_CONN;\n\n        if (SCP_LIST_ITEM_IN_USE(sli))\n        {\n            if (sli->client_trans != NULL &&\n                    sli->client_trans->status == TRANS_STATUS_UP)\n            {\n                if (trans_check_wait_objs(sli->client_trans) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"scp_list_check_wait_objs: \"\n                        \"trans_check_wait_objs(1) failed, removing trans\");\n                    sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;\n                }\n            }\n\n            if (sli->sesexec_trans != NULL &&\n                    sli->sesexec_trans->status == TRANS_STATUS_UP)\n            {\n                if (trans_check_wait_objs(sli->sesexec_trans) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"scp_list_check_wait_objs: \"\n                        \"trans_check_wait_objs(2) failed, removing trans\");\n                    sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;\n                }\n            }\n\n            /* Get any action, and reset the requested one */\n            action = sli->dispatcher_action;\n            sli->dispatcher_action = E_SLD_NONE;\n        }\n\n        switch (action)\n        {\n            case E_SLD_NONE:\n                /* On to the next item on the list */\n                ++i;\n                break;\n\n            case E_SLD_REMOVE_CLIENT_TRANS:\n                trans_delete(sli->client_trans);\n                sli->client_trans = NULL;\n                /* On to the next item on the list */\n                ++i;\n                break;\n            case E_SLD_TERMINATE_SCP_CONN:\n                free_scp_list_item(sli);\n                list_remove_item(g_scp_list, i);\n                break;\n        }\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nvoid\nscp_list_get_create_session_x11_displays(struct set_int *alloc_displays)\n{\n    int i = 0;\n    for (i = 0; i < g_scp_list->count; ++i)\n    {\n        struct scp_list_item *sli;\n\n        sli = (struct scp_list_item *)list_get_item(g_scp_list, i);\n\n        // Only add X11 displays\n        if (SCP_LIST_ITEM_IN_USE(sli) &&\n                sli->create_session_in_progress &&\n                sli->session_x11_display >= 0)\n        {\n            set_int_add(alloc_displays, sli->session_x11_display);\n        }\n    }\n}\n"
  },
  {
    "path": "sesman/scp_list.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file scp_list.h\n * @brief List of SCP connections to sesman (declarations)\n *\n * @author Matt Burt\n *\n */\n\n#ifndef SCP_LIST_H\n#define SCP_LIST_H\n\n#include <sys/types.h>\n\n#include \"xrdp_constants.h\"\n\nstruct set_int;\n\n/**\n * Type describing the login state of an SCP list item\n */\nenum sli_login_state\n{\n    E_SLI_LOGIN_NOT_LOGGED_IN = 0,\n    E_SLI_LOGIN_SYS,\n    E_SLI_LOGIN_UDS\n};\n\n/**\n * Action we require the dispatcher to do for us\n *\n * We can't do some things in an SCP or EICP callback, so we have to\n * ask the dispatcher to do them. For example, we can't delete the\n * client_trans as the callback stack won't be expecting this.\n */\nenum scp_list_dispatcher_action\n{\n    E_SLD_NONE = 0,\n    /**\n     * Remove the client transport as sesexec is\n     * temporarily handling the call.\n     */\n    E_SLD_REMOVE_CLIENT_TRANS,\n    /**\n     * Completely remove the client transport as we won't\n     * be using it again\n     */\n    E_SLD_TERMINATE_SCP_CONN\n};\n\n/**\n * Type for managing sesman connections from SCP clients (xrdp, etc)\n * and any sesexec processes we've created for them.\n */\nstruct scp_list_item\n{\n    struct trans *client_trans; ///< SCP link to sesman client\n    struct trans *sesexec_trans; ///< ECP link to sesexec\n    pid_t sesexec_pid; ///< PID of sesexec (if sesexec is active)\n    char peername[15 + 1]; ///< Name of peer, if known, for logging\n    enum sli_login_state login_state; ///< Login state\n    /**\n     * Any action which a callback requires the dispatcher to\n     * do out of scope of the callback */\n    enum scp_list_dispatcher_action dispatcher_action;\n    uid_t uid; ///< User\n    char *username; ///< Username from UID (at time of logon)\n    char start_ip_addr[MAX_PEER_ADDRSTRLEN];\n    char xrdp_instance_name[MAX_XRDP_INSTANCE_NAMELEN]; ///< Instance name associated with session\n    int is_admin;\n    int create_session_in_progress; ///< Already handling a create_session\n    /// X11 display allocated for session (-1 if N/A)\n    int session_x11_display;\n};\n\n\n/**\n * Initialise the module\n * @param list_size Number of SCP list items allowed\n * @return 0 for success\n *\n * Errors are logged\n */\nint\nscp_list_init(unsigned int list_size);\n\n/**\n * Clean up the module on program exit\n */\nvoid\nscp_list_cleanup(void);\n\n/**\n * Returns the number of items on the SCP list\n * @return Item count\n */\nunsigned int\nscp_list_get_count(void);\n\n/**\n * Allocates a new item on the SCP list\n *\n * @return pointer to new SCP list item or NULL for no memory\n *\n * After allocating the item, you must initialise the sesexec_trans field\n * with a valid transport.\n *\n * The session is removed by scp_list_get_wait_objs() or\n * scp_list_check_wait_objs() when the client\n * transport goes down (or wasn't allocated in the first place).\n */\nstruct scp_list_item *\nscp_list_item_new(void);\n\n/**\n * Set the peername of an SCP list item\n *\n * @param sli SCP list item\n * @param name Name to set\n * @result 0 for success\n */\nint\nscp_list_set_peername(struct scp_list_item *sli, const char *name);\n\n/**\n * @brief Get the wait objs for the SCP list module\n * @param robjs Objects array to update\n * @param robjs_count Elements in robjs (by reference)\n * @return 0 for success\n */\nint\nscp_list_get_wait_objs(tbus robjs[], int *robjs_count);\n\n\n/**\n * @brief Check the wait objs for the SCP list module\n * @return 0 for success\n */\nint\nscp_list_check_wait_objs(void);\n\n/**\n * @brief Get all create-session X11 displays\n *\n * Adds X11 displays allocated to create-session operations to a set\n */\nvoid\nscp_list_get_create_session_x11_displays(struct set_int *alloc_displays);\n\n#endif // SCP_LIST_H\n"
  },
  {
    "path": "sesman/scp_process.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file scp.c\n * @brief scp (sesman control protocol) handler function\n * @author Jay Sorg, Simone Fedele\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"trans.h\"\n#include \"os_calls.h\"\n#include \"eicp.h\"\n#include \"ercp.h\"\n#include \"scp.h\"\n\n#include \"display_utils.h\"\n#include \"scp_process.h\"\n#include \"sesman.h\"\n#include \"sesman_access.h\"\n#include \"sesman_auth.h\"\n#include \"sesman_config.h\"\n#include \"os_calls.h\"\n#include \"set_int.h\"\n#include \"scp_list.h\"\n#include \"session_list.h\"\n#include \"sesexec_control.h\"\n#include \"string_calls.h\"\n#include \"xrdp_sockets.h\"\n\n/******************************************************************************/\n\nstatic int\nprocess_set_peername_request(struct scp_list_item *sli)\n{\n    int rv;\n    const char *peername;\n\n    rv = scp_get_set_peername_request(sli->client_trans, &peername);\n    if (rv == 0)\n    {\n        if (scp_list_set_peername(sli, peername) != 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"Failed to set connection peername from %s to %s\",\n                sli->peername, peername);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nprocess_sys_login_request(struct scp_list_item *sli)\n{\n    int rv;\n    const char *username;\n    const char *password;\n    const char *ip_addr;\n    int send_client_reply = 1;\n\n    rv = scp_get_sys_login_request(sli->client_trans, &username,\n                                   &password, &ip_addr);\n    if (rv == 0)\n    {\n        enum scp_login_status errorcode;\n\n        LOG(LOG_LEVEL_INFO,\n            \"Received system login request from %s for user: %s IP: %s\",\n            sli->peername, username, ip_addr);\n\n        if (sli->login_state != E_SLI_LOGIN_NOT_LOGGED_IN)\n        {\n            errorcode = E_SCP_LOGIN_ALREADY_LOGGED_IN;\n            LOG(LOG_LEVEL_ERROR, \"Connection is already logged in for %s\",\n                sli->username);\n        }\n        else if ((sli->username = g_strdup(username)) == NULL)\n        {\n            errorcode = E_SCP_LOGIN_NO_MEMORY;\n            LOG(LOG_LEVEL_ERROR, \"Memory allocation failure logging in %s\",\n                username);\n        }\n        else\n        {\n            /*\n             * Copy the IP address of the requesting user, anticipating a\n             * successful login. We need this so we can search for a session\n             * with a matching IP address if required.\n             */\n            g_snprintf(sli->start_ip_addr, sizeof(sli->start_ip_addr),\n                       \"%s\", ip_addr);\n\n            /* Create a sesexec process to handle the login\n             *\n             * We won't check for the user being valid here, as this might\n             * lead to information leakage */\n            if (sesexec_start(sli) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"Can't start sesexec to authenticate user\");\n                errorcode = E_SCP_LOGIN_GENERAL_ERROR;\n            }\n            else\n            {\n                int eicp_stat;\n                eicp_stat = eicp_send_sys_login_request(sli->sesexec_trans,\n                                                        username,\n                                                        password,\n                                                        ip_addr,\n                                                        sli->client_trans->sck);\n                if (eicp_stat != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Can't ask sesexec to authenticate user\");\n                    errorcode = E_SCP_LOGIN_GENERAL_ERROR;\n                }\n                else\n                {\n                    /* We've handed over responsibility for the\n                     * SCP communication */\n                    send_client_reply = 0;\n                    sli->dispatcher_action = E_SLD_REMOVE_CLIENT_TRANS;\n                }\n            }\n        }\n\n        if (send_client_reply)\n        {\n            /* We only get here if something has gone\n             * wrong with the handover to sesexec */\n            rv = scp_send_login_response(sli->client_trans, errorcode, 1, -1);\n            sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n\n/**\n * Authenticate and authorize a UDS connection\n *\n * @param sli  Connection to sesman\n * @param uid UID for user\n * @param username Name for user\n * @return Status for the operation\n *\n * @post If E_SCP_LOGIN_OK is returned, sli->username is non-NULL\n */\nstatic enum scp_login_status\nauthenticate_and_authorize_uds_connection(struct scp_list_item *sli,\n        int uid,\n        const char *username)\n{\n    enum scp_login_status status = E_SCP_LOGIN_GENERAL_ERROR;\n    struct auth_info *auth_info = auth_uds(username, &status);\n    if (auth_info != NULL)\n    {\n        if (status != E_SCP_LOGIN_OK)\n        {\n            /* This shouldn't happen */\n            LOG(LOG_LEVEL_ERROR,\n                \"Unexpected status return %d from auth_uds call\",\n                (int)status);\n        }\n        else if (!access_login_allowed(&g_cfg->sec, username))\n        {\n            status = E_SCP_LOGIN_NOT_AUTHORIZED;\n            LOG(LOG_LEVEL_INFO, \"Username okay but group problem for \"\n                \"user: %s\", username);\n        }\n\n        /* If all is well, add info to the sesman connection for later use */\n        if (status == E_SCP_LOGIN_OK)\n        {\n            if ((sli->username = g_strdup(username)) == NULL)\n            {\n                LOG(LOG_LEVEL_ERROR, \"%s : Memory allocation failed\",\n                    __func__);\n                g_free(sli->username);\n                sli->username = NULL;\n                status = E_SCP_LOGIN_NO_MEMORY;\n            }\n            else\n            {\n                sli->login_state = E_SLI_LOGIN_UDS;\n                sli->uid = uid;\n                sli->start_ip_addr[0] = '\\0';\n                sli->is_admin = access_login_is_admin(&g_cfg->sec,\n                                                      sli->username);\n                if (sli->is_admin)\n                {\n                    LOG(LOG_LEVEL_INFO, \"Admin access permitted for user: %s\",\n                        username);\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_INFO, \"Normal access permitted for user: %s\",\n                        username);\n                }\n            }\n        }\n\n        auth_end(auth_info);\n    }\n\n    return status;\n}\n\n/******************************************************************************/\n\nstatic int\nprocess_uds_login_request(struct scp_list_item *sli)\n{\n    enum scp_login_status errorcode;\n    int rv;\n    int uid;\n    int pid;\n    char *username = NULL;\n    int server_closed;\n\n    rv = g_sck_get_peer_cred(sli->client_trans->sck, &pid, &uid, NULL);\n    if (rv != 0)\n    {\n        errorcode = E_SCP_LOGIN_GENERAL_ERROR;\n        LOG(LOG_LEVEL_INFO,\n            \"Unable to get peer credentials for socket %d\",\n            (int)sli->client_trans->sck);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"Received UDS login request from %s for UID: %d from PID: %d\",\n            sli->peername, uid, pid);\n\n        if (sli->login_state != E_SLI_LOGIN_NOT_LOGGED_IN)\n        {\n            errorcode = E_SCP_LOGIN_ALREADY_LOGGED_IN;\n            LOG(LOG_LEVEL_ERROR, \"Connection is already logged in for %s\",\n                sli->username);\n        }\n        else if (g_getuser_info_by_uid(uid, &username,\n                                       NULL, NULL, NULL, NULL) != 0)\n        {\n            errorcode = E_SCP_LOGIN_GENERAL_ERROR;\n            LOG(LOG_LEVEL_ERROR, \"Can't reverse lookup UID %d\", uid);\n        }\n        else\n        {\n            errorcode = authenticate_and_authorize_uds_connection(\n                            sli, uid, username);\n            g_free(username);\n        }\n    }\n\n    if (errorcode == E_SCP_LOGIN_OK)\n    {\n        server_closed = 0;\n    }\n    else\n    {\n        server_closed = 1;\n\n        /* Close the connection after returning from this callback */\n        sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;\n\n        /* Never return the UID if the server is closing */\n        uid = -1;\n    }\n\n    return scp_send_login_response(sli->client_trans, errorcode,\n                                   server_closed, uid);\n}\n\n/******************************************************************************/\n\nstatic void\nlogout_scp_list_item(struct scp_list_item *sli)\n{\n    if (sli->login_state != E_SLI_LOGIN_NOT_LOGGED_IN)\n    {\n        if (sli->sesexec_trans != NULL)\n        {\n            (void)eicp_send_logout_request(sli->sesexec_trans);\n            trans_delete(sli->sesexec_trans);\n            sli->sesexec_trans = NULL;\n        }\n        sli->uid = (uid_t) -1;\n        g_free(sli->username);\n        sli->username = NULL;\n        sli->start_ip_addr[0] = '\\0';\n\n        sli->login_state = E_SLI_LOGIN_NOT_LOGGED_IN;\n    }\n}\n\n/******************************************************************************/\n\nstatic int\nprocess_logout_request(struct scp_list_item *sli)\n{\n    if (sli->login_state != E_SLI_LOGIN_NOT_LOGGED_IN)\n    {\n        LOG(LOG_LEVEL_INFO, \"Logging out %s from sesman\", sli->username);\n        logout_scp_list_item(sli);\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\n/**\n * Create xrdp socket path for the user\n *\n * We do this here rather than in sesexec as we're single-threaded here\n * and so don't have to worry about race conditions\n *\n * Directory is owned by UID of session, but can be accessed by\n * the group specified in the config.\n *\n * Errors are logged so the caller doesn't have to\n */\nstatic int\ncreate_xrdp_socket_path(uid_t uid)\n{\n    // Owner all permissions, group read+execute\n#define RWX_PERMS 0x750\n\n    int rv = 1;\n    const char *sockdir_group = g_cfg->sec.session_sockdir_group;\n    int gid = 0; // Default if no group specified\n\n    char sockdir[XRDP_SOCKETS_MAXPATH];\n    g_snprintf(sockdir, sizeof(sockdir), XRDP_SOCKET_PATH, (int)uid);\n\n    // Create directory permissions RWX_PERMS, if it doesn't exist already\n    // (our os_calls layer doesn't allow us to set the SGID bit here)\n    int old_umask = g_umask_hex(RWX_PERMS ^ 0x777);\n    if (!g_directory_exist(sockdir) && !g_create_dir(sockdir))\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"create_xrdp_socket_path: Can't create %s [%s]\",\n            sockdir, g_get_strerror());\n    }\n    else if (g_chmod_hex(sockdir, RWX_PERMS | 0x2000) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"create_xrdp_socket_path: Can't set SGID bit on %s [%s]\",\n            sockdir, g_get_strerror());\n    }\n    else if (sockdir_group != NULL && sockdir_group[0] != '\\0' &&\n             g_getgroup_info(sockdir_group, &gid) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"create_xrdp_socket_path: Can't get GID of group %s [%s]\",\n            sockdir_group, g_get_strerror());\n    }\n    else if (g_chown(sockdir, uid, gid) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"create_xrdp_socket_path: Can't set owner of %s to %d:%d [%s]\",\n            sockdir, uid, gid, g_get_strerror());\n    }\n    else\n    {\n        rv = 0;\n    }\n    (void)g_umask_hex(old_umask);\n\n    return rv;\n#undef RWX_PERMS\n}\n\n/******************************************************************************/\n/*\n * Gets a free display number\n *\n * We can't use displays either allocated to sessions, or being used to\n * create sessions\n */\nstatic int\nget_free_display(void)\n{\n    int result = -1;\n    struct set_int *alloc_displays;\n\n    alloc_displays = set_int_init(g_cfg->sess.x11_display_offset,\n                                  g_cfg->sess.max_display_number);\n\n    if (alloc_displays != NULL)\n    {\n        // Get all the displays either allocated to sessions, or\n        // potentially assigned to sessions on the SCP list\n        session_list_get_session_x11_displays(alloc_displays);\n        scp_list_get_create_session_x11_displays(alloc_displays);\n\n        // Find a free display, taking the allocated ones into account\n        result = display_utils_get_free_display(alloc_displays);\n\n        set_int_delete(alloc_displays);\n    }\n\n    return result;\n}\n\n/******************************************************************************/\n\nstatic int\nprocess_create_session_request(struct scp_list_item *sli)\n{\n    int rv;\n    /* Client parameters describing new session */\n    enum scp_session_type type;\n    unsigned short width;\n    unsigned short height;\n    unsigned char bpp;\n    const char *shell;\n    const char *directory;\n    const char *instance_name;\n\n    struct guid guid;\n    const char *display;\n    int x11_display = -1;\n    struct session_item *s_item = NULL;\n    int start_sesexec = (sli->sesexec_trans == NULL);\n    int send_client_reply = 1;\n\n    enum scp_screate_status status = E_SCP_SCREATE_OK;\n\n    rv = scp_get_create_session_request(sli->client_trans,\n                                        &type, &width, &height,\n                                        &bpp, &shell, &directory,\n                                        &instance_name);\n\n    if (rv == 0)\n    {\n        if (sli->login_state == E_SLI_LOGIN_NOT_LOGGED_IN)\n        {\n            status = E_SCP_SCREATE_NOT_LOGGED_IN;\n        }\n        else if (sli->create_session_in_progress)\n        {\n            status = E_SCP_SCREATE_IN_PROGRESS;\n        }\n        else\n        {\n            LOG(LOG_LEVEL_INFO,\n                \"Received request from %s to create a session for user %s\",\n                sli->peername, sli->username);\n\n            s_item = session_list_get_bydata(sli->uid, type, width, height,\n                                             bpp, sli->start_ip_addr, instance_name);\n            if (s_item != NULL)\n            {\n                // Found an existing session\n                LOG(LOG_LEVEL_INFO,\n                    \"A suitable session on display %s is already active\",\n                    s_item->display);\n                display = s_item->display;\n                guid = s_item->guid;\n            }\n            // Need to create a new session\n            else if (g_cfg->sess.max_sessions > 0 &&\n                     session_list_get_count() >= g_cfg->sess.max_sessions)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"The maximum number of sessions has been reached\");\n                status = E_SCP_SCREATE_MAX_REACHED;\n            }\n            else if (SCP_SESSION_TYPE_IS_X11(type) &&\n                     (x11_display = get_free_display()) < 0)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"No free X11 display can be found for a new session\");\n                status = E_SCP_SCREATE_NO_DISPLAY;\n            }\n            // Create a socket dir for this user\n            else if (create_xrdp_socket_path(sli->uid) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"Can't create a socket directory for UID %d\",\n                    (int)sli->uid);\n                status = E_SCP_SCREATE_GENERAL_ERROR;\n            }\n            // Create a sesexec process if we don't have one (UDS login)\n            else if (start_sesexec && sesexec_start(sli) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"Can't start sesexec to manage session\");\n                status = E_SCP_SCREATE_GENERAL_ERROR;\n            }\n            else if (start_sesexec &&\n                     eicp_send_uds_login_request(\n                         sli->sesexec_trans, sli->client_trans->sck) != 0)\n            {\n                // Because we started sesexec late, we needed to log it in.\n                // That hasn't gone too well.\n                LOG(LOG_LEVEL_ERROR,\n                    \"Can't set UID for sesexec process\");\n                status = E_SCP_SCREATE_GENERAL_ERROR;\n\n                // Looks like sesexec is broken...\n                trans_delete(sli->sesexec_trans);\n                sli->sesexec_trans = NULL;\n            }\n            else\n            {\n                // Pass the session create request to sesexec\n                LOG(LOG_LEVEL_INFO,\n                    \"Passing session creation request to sesexec\");\n                int eicp_stat;\n                eicp_stat = eicp_send_create_session_request(\n                                sli->sesexec_trans,\n                                x11_display,\n                                type, width, height,\n                                bpp, shell, directory,\n                                instance_name);\n\n                if (eicp_stat != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Can't ask sesexec to create a session\");\n                    status = E_SCP_SCREATE_GENERAL_ERROR;\n                    // Looks like sesexec is broken...\n                    trans_delete(sli->sesexec_trans);\n                    sli->sesexec_trans = NULL;\n                }\n                else\n                {\n                    // We're not sending a reply yet\n                    send_client_reply = 0;\n                    sli->create_session_in_progress = 1;\n                    sli->session_x11_display = x11_display; // Reserve display\n                }\n            }\n        }\n\n        if (send_client_reply)\n        {\n            if (status != E_SCP_SCREATE_OK)\n            {\n                display = \"\";\n                guid_clear(&guid);\n            }\n            rv = scp_send_create_session_response(sli->client_trans,\n                                                  status, display, &guid);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n\nstatic int\nprocess_connect_session_request(struct scp_list_item *sli)\n{\n    int rv;\n    /* Client parameters describing new session */\n    struct guid guid;\n    const char *client_ip;\n    const char *client_name;\n    unsigned int flags;\n    enum scp_sconnect_status status;\n\n    rv = scp_get_connect_session_request(sli->client_trans, &guid,\n                                         &client_ip, &client_name, &flags);\n\n    if (rv == 0)\n    {\n        if (sli->login_state == E_SLI_LOGIN_NOT_LOGGED_IN)\n        {\n            status = E_SCP_SCONNECT_NOT_LOGGED_IN;\n        }\n        else\n        {\n            struct session_item *s_item = session_list_get_byguid(&guid);\n            if (s_item == NULL)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"User %s tried to connect to non-existent session\",\n                    sli->username);\n                status = E_SCP_SCONNECT_NO_SUCH_GUID;\n            }\n            else if (s_item->uid != sli->uid)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"User %s (UID %d) denied access to session for UID %d\",\n                    sli->username, sli->uid, s_item->uid);\n                status = E_SCP_SCONNECT_NO_SUCH_GUID;\n            }\n            else\n            {\n                // Don't log the GUID\n                LOG(LOG_LEVEL_INFO,\n                    \"Forwarding request from %s to connect to a session\",\n                    sli->username);\n                // Pass the session create request to sesexec\n                int ercp_stat;\n                ercp_stat = ercp_send_connect_session_request(\n                                s_item->sesexec_trans,\n                                sli->client_trans->sck,\n                                client_ip,\n                                client_name,\n                                flags);\n\n                if (ercp_stat != 0)\n                {\n                    // The sesexec transport is broken. That's dealt with\n                    // elsewhere.\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Can't ask sesexec to connect to a session\");\n                    status = E_SCP_SCONNECT_GENERAL_ERROR;\n                }\n                else\n                {\n                    status = E_SCP_SCONNECT_OK;\n                }\n            }\n        }\n\n        // Send anything other than a successful connection request\n        // back to the client\n        if (status != E_SCP_SCONNECT_OK)\n        {\n            rv = scp_send_connect_session_response(sli->client_trans,\n                                                   status, -1, -1);\n        }\n    }\n\n    // This call is always the last thing on the SCP connection.\n    logout_scp_list_item(sli); // Remove any sesexec process used for auth\n    sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;\n\n    return rv;\n}\n\n/******************************************************************************/\n\nstatic int\nprocess_list_sessions_request(struct scp_list_item *sli)\n{\n    int rv = 0;\n\n    struct scp_session_info *info = NULL;\n    unsigned int cnt = 0;\n    unsigned int i;\n\n    if (sli->login_state == E_SLI_LOGIN_NOT_LOGGED_IN)\n    {\n        rv = scp_send_list_sessions_response(sli->client_trans,\n                                             E_SCP_LS_NOT_LOGGED_IN,\n                                             NULL);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"Received request from %s to list sessions for user %s\",\n            sli->peername, sli->username);\n\n        if (sli->is_admin)\n        {\n            info = session_list_get_byuid(NULL, &cnt, 0);\n        }\n        else\n        {\n            info = session_list_get_byuid(&sli->uid, &cnt, 0);\n        }\n\n        for (i = 0; rv == 0 && i < cnt; ++i)\n        {\n            rv = scp_send_list_sessions_response(sli->client_trans,\n                                                 E_SCP_LS_SESSION_INFO,\n                                                 &info[i]);\n        }\n        free_session_info_list(info, cnt);\n\n        if (rv == 0)\n        {\n            rv = scp_send_list_sessions_response(sli->client_trans,\n                                                 E_SCP_LS_END_OF_LIST,\n                                                 NULL);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n\nstatic int\nprocess_create_sockdir_request(struct scp_list_item *sli)\n{\n    enum scp_create_sockdir_status status = E_SCP_CS_OTHER_ERROR;\n\n    if (sli->login_state == E_SLI_LOGIN_NOT_LOGGED_IN)\n    {\n        status = E_SCP_CS_NOT_LOGGED_IN;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"Received request from %s to create sockdir for user %s\",\n            sli->peername, sli->username);\n\n        if (create_xrdp_socket_path(sli->uid) == 0)\n        {\n            status = E_SCP_CS_OK;\n        }\n    }\n\n    return scp_send_create_sockdir_response(sli->client_trans, status);\n}\n\n/******************************************************************************/\n\nstatic int\nprocess_close_connection_request(struct scp_list_item *sli)\n{\n    int rv = 0;\n\n    LOG(LOG_LEVEL_INFO, \"Received request to close connection from %s\",\n        sli->peername);\n\n    /* Make sure we're logged out */\n    if (sli->login_state != E_SLI_LOGIN_NOT_LOGGED_IN)\n    {\n        logout_scp_list_item(sli);\n    }\n\n    /* Expecting no more client messages. Close the connection\n     * after returning from this callback */\n    sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;\n    return rv;\n}\n\n/******************************************************************************/\nint\nscp_process(struct scp_list_item *sli)\n{\n    enum scp_msg_code msgno;\n    int rv = 0;\n\n    switch ((msgno = scp_msg_in_get_msgno(sli->client_trans)))\n    {\n        case E_SCP_SET_PEERNAME_REQUEST:\n            rv = process_set_peername_request(sli);\n            break;\n\n        case E_SCP_SYS_LOGIN_REQUEST:\n            rv = process_sys_login_request(sli);\n            break;\n\n        case E_SCP_UDS_LOGIN_REQUEST:\n            rv = process_uds_login_request(sli);\n            break;\n\n        case E_SCP_LOGOUT_REQUEST:\n            rv = process_logout_request(sli);\n            break;\n\n        case E_SCP_CREATE_SESSION_REQUEST:\n            rv = process_create_session_request(sli);\n            break;\n\n        case E_SCP_CONNECT_SESSION_REQUEST:\n            rv = process_connect_session_request(sli);\n            break;\n\n        case E_SCP_LIST_SESSIONS_REQUEST:\n            rv = process_list_sessions_request(sli);\n            break;\n\n        case E_SCP_CREATE_SOCKDIR_REQUEST:\n            rv = process_create_sockdir_request(sli);\n            break;\n\n        case E_SCP_CLOSE_CONNECTION_REQUEST:\n            rv = process_close_connection_request(sli);\n            break;\n\n        default:\n        {\n            char buff[64];\n            scp_msgno_to_str(msgno, buff, sizeof(buff));\n            LOG(LOG_LEVEL_ERROR, \"Ignored SCP message %s\", buff);\n        }\n    }\n    return rv;\n}\n\n"
  },
  {
    "path": "sesman/scp_process.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file scp_process.h\n * @brief scp (sesman control protocol) handler function\n * @author Simone Fedele\n *\n */\n\n#ifndef SCP_PROCESS_H\n#define SCP_PROCESS_H\n\nstruct scp_list_item;\n\n/**\n *\n * @brief Processes an SCP message\n * @param sli the sesman connection\n *\n */\nint\nscp_process(struct scp_list_item *sli);\n\n#endif\n"
  },
  {
    "path": "sesman/sesexec/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_LIBEXEC_PATH=\\\"${libexecdir}/xrdp\\\" \\\n  -DXRDP_SOCKET_ROOT_PATH=\\\"${socketdir}\\\" \\\n  -I$(top_srcdir)/sesman/libsesman \\\n  -I$(top_srcdir)/libipm \\\n  -I$(top_srcdir)/common\n\nSESEXEC_EXTRA_LIBS =\n\nif XRDP_UTMP\n    AM_CPPFLAGS += -DUSE_UTMP\nendif\n\npkglibexec_PROGRAMS = \\\n  xrdp-sesexec\n\nxrdp_sesexec_SOURCES = \\\n  sesexec.c \\\n  sesexec.h \\\n  session.c \\\n  session.h \\\n  ccp_server.c \\\n  ccp_server.h \\\n  eicp_server.c \\\n  eicp_server.h \\\n  ercp_server.c \\\n  ercp_server.h \\\n  env.c \\\n  env.h \\\n  login_info.c \\\n  login_info.h \\\n  sesexec_discover.c \\\n  sesexec_discover.h \\\n  sessionrecord.c \\\n  sessionrecord.h \\\n  xauth.c \\\n  xauth.h \\\n  xwait.c \\\n  xwait.h\n\nxrdp_sesexec_LDFLAGS =\n\nxrdp_sesexec_LDADD = \\\n  $(top_builddir)/sesman/libsesman/libsesman.la \\\n  $(top_builddir)/libipm/libipm.la \\\n  $(top_builddir)/common/libcommon.la \\\n  $(SESEXEC_EXTRA_LIBS)\n"
  },
  {
    "path": "sesman/sesexec/ccp_server.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file eicp_server.c\n * @brief eicp (executive initialisation control protocol) server function\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"trans.h\"\n\n#include \"ccp.h\"\n#include \"ccp_server.h\"\n\n/******************************************************************************/\nint\nccp_server(struct trans *self)\n{\n    int rv = 0;\n    enum ccp_msg_code msgno;\n\n    switch ((msgno = ccp_msg_in_get_msgno(self)))\n    {\n        default:\n        {\n            char buff[64];\n            ccp_msgno_to_str(msgno, buff, sizeof(buff));\n            LOG(LOG_LEVEL_ERROR, \"Ignored CCP message %s\", buff);\n        }\n    }\n    return rv;\n}\n"
  },
  {
    "path": "sesman/sesexec/ccp_server.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file ccp_server.h\n * @brief ccp (connection control protocol) server function\n * @author Matt Burt\n *\n */\n\n#ifndef CCP_SERVER_H\n#define CCP_SERVER_H\n\n/**\n *\n * @brief Processes an CCP message\n * @param self The CCP transport the message is coming in on\n *\n */\nint\nccp_server(struct trans *self);\n\n#endif // CCP_SERVER_H\n"
  },
  {
    "path": "sesman/sesexec/eicp_server.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file eicp_server.c\n * @brief eicp (executive initialisation control protocol) server function\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"trans.h\"\n\n#include \"eicp.h\"\n#include \"eicp_server.h\"\n#include \"login_info.h\"\n#include \"os_calls.h\"\n#include \"ercp.h\"\n#include \"scp.h\"\n#include \"sesexec.h\"\n#include \"sesexec_discover.h\"\n#include \"session.h\"\n\n/******************************************************************************/\nstatic int\nhandle_sys_login_request(struct trans *self)\n{\n    const char *username;\n    const char *password;\n    const char *ip_addr;\n    int scp_fd;\n\n    int rv = eicp_get_sys_login_request(self, &username,\n                                        &password, &ip_addr, &scp_fd);\n    if (rv == 0)\n    {\n        struct trans *scp_trans;\n        scp_trans = scp_init_trans_from_fd(scp_fd, TRANS_TYPE_SERVER,\n                                           sesexec_is_term);\n        if (scp_trans == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't create SCP trans\");\n            g_file_close(scp_fd);\n            rv = 1;\n        }\n        else\n        {\n            if (g_login_info != NULL)\n            {\n                // Shouldn't get here. Prevent a memory leak.\n                LOG(LOG_LEVEL_WARNING,\n                    \"Asked to sys login when a login has already been made\");\n                login_info_free(g_login_info);\n            }\n            g_login_info = login_info_sys_login_user(scp_trans, username,\n                           password, ip_addr);\n\n            if (g_login_info != NULL)\n            {\n                rv = eicp_send_sys_login_response(self, 1,\n                                                  g_login_info->uid, scp_fd);\n            }\n            else\n            {\n                rv = eicp_send_sys_login_response(self, 0, (uid_t) -1, 0);\n            }\n\n            trans_delete(scp_trans); // Closes scp_fd as well\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nhandle_uds_login_request(struct trans *self)\n{\n    int scp_fd;\n\n    int rv = eicp_get_uds_login_request(self, &scp_fd);\n    if (rv == 0)\n    {\n        struct trans *scp_trans;\n        scp_trans = scp_init_trans_from_fd(scp_fd, TRANS_TYPE_SERVER,\n                                           sesexec_is_term);\n        if (scp_trans == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't create SCP trans\");\n            g_file_close(scp_fd);\n            rv = 1;\n        }\n        else\n        {\n            if (g_login_info != NULL)\n            {\n                // Shouldn't get here. Prevent a memory leak.\n                LOG(LOG_LEVEL_WARNING,\n                    \"Asked to UDS login when a login has already been made\");\n                login_info_free(g_login_info);\n            }\n            // The following call logs errors, but these are not\n            // returned to the caller, as the call is expected to succeed.\n            if ((g_login_info = login_info_uds_login_user(scp_trans)) == NULL)\n            {\n                rv = 1;\n            }\n            trans_delete(scp_trans);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nhandle_logout_request(struct trans *self)\n{\n    LOG(LOG_LEVEL_INFO, \"xrdp-sesexec pid %d is now logging out\", g_pid);\n    sesexec_terminate_main_loop(0);\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nhandle_create_session_request(struct trans *self)\n{\n    struct session_parameters sp = {0};\n    int status;\n\n    status = eicp_get_create_session_request(\n                 self, &sp.x11_display,\n                 &sp.type, &sp.width, &sp.height,\n                 &sp.bpp, &sp.shell, &sp.directory,\n                 &sp.instance_name);\n    if (status == 0)\n    {\n        enum scp_screate_status scp_status = E_SCP_SCREATE_OK;\n        const char *display = \"\";\n\n        // Must be logged in to start a session\n        if (g_login_info == NULL)\n        {\n            scp_status = E_SCP_SCREATE_NOT_LOGGED_IN;\n        }\n        else\n        {\n            // Try to create the session\n            sp.guid = guid_new();\n            scp_status = session_start(g_login_info, &sp, &g_session_data);\n            if (scp_status == E_SCP_SCREATE_OK)\n            {\n                display = session_get_display(g_session_data);\n            }\n        }\n\n        // Return the creation status to sesman.\n        status = eicp_send_create_session_response(self, scp_status, display,\n                 &sp.guid);\n        if (status == 0 && scp_status == E_SCP_SCREATE_OK)\n        {\n            // Further comms to sesman is sent over the ERCP protocol\n            ercp_trans_from_eicp_trans(self, sesexec_ercp_data_in, NULL);\n\n            // Announce the session to sesman\n            if ((status = ercp_send_session_announce_event(\n                              self,\n                              display,\n                              g_login_info->uid,\n                              sp.type,\n                              sp.width,\n                              sp.height,\n                              sp.bpp,\n                              &sp.guid,\n                              g_login_info->ip_addr,\n                              session_get_start_time(g_session_data),\n                              sp.instance_name)) != 0)\n            {\n                // We failed to tell sesman about the new session. This\n                // probably means sesman has exited in the time between\n                // asking us to start a session, and our reply. This\n                // could be many seconds, and a new sesman may well\n                // have started.\n                // If we enable the restart functionality at\n                // this point, we have a race condition that could\n                // result in a session which sesman doesn't know\n                // about. The simplest thing to do in this rare situation\n                // is to abort the session - the user can create a\n                // new one\n                LOG(LOG_LEVEL_ERROR,\n                    \"sesman appears to have failed - stopping session\");\n            }\n            else if ((status = sesexec_discover_enable()) != 0)\n            {\n                // Equally regrettable - we can't make the session\n                // discoverable, so we'll stop it.\n                LOG(LOG_LEVEL_ERROR,\n                    \"unable to make session discoverable\"\n                    \" - stopping session\");\n            }\n        }\n    }\n\n    if (status != 0)\n    {\n        // Kill sesexec, and any active session\n        sesexec_terminate_main_loop(status);\n    }\n    return 0;\n}\n\n/******************************************************************************/\nint\neicp_server(struct trans *self)\n{\n    int rv = 0;\n    enum eicp_msg_code msgno;\n\n    switch ((msgno = eicp_msg_in_get_msgno(self)))\n    {\n        case E_EICP_SYS_LOGIN_REQUEST:\n            rv = handle_sys_login_request(self);\n            break;\n\n        case E_EICP_UDS_LOGIN_REQUEST:\n            rv = handle_uds_login_request(self);\n            break;\n\n        case E_EICP_LOGOUT_REQUEST:\n            rv = handle_logout_request(self);\n            break;\n\n        case E_EICP_CREATE_SESSION_REQUEST:\n            rv = handle_create_session_request(self);\n            break;\n\n        default:\n        {\n            char buff[64];\n            eicp_msgno_to_str(msgno, buff, sizeof(buff));\n            LOG(LOG_LEVEL_ERROR, \"Ignored EICP message %s\", buff);\n        }\n    }\n    return rv;\n}\n"
  },
  {
    "path": "sesman/sesexec/eicp_server.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file eicp_server.h\n * @brief eicp (executive initialisation control protocol) server function\n * @author Matt Burt\n *\n */\n\n#ifndef EICP_SERVER_H\n#define EICP_SERVER_H\n\n/**\n *\n * @brief Processes an EICP message\n * @param self The EICP transport the message is coming in on\n *\n */\nint\neicp_server(struct trans *self);\n\n#endif // EICP_SERVER_H\n"
  },
  {
    "path": "sesman/sesexec/env.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file env.c\n * @brief User environment handling code\n * @author Jay Sorg\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <grp.h>\n\n#include \"env.h\"\n#include \"sesman_config.h\"\n#include \"list.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"sesexec.h\"\n#include \"string_calls.h\"\n#include \"xrdp_sockets.h\"\n\n/******************************************************************************/\nint\nenv_set_user(int uid,\n             const struct list *env_names, const struct list *env_values)\n{\n    int error;\n    int pw_gid;\n    int index;\n    char *name;\n    char *value;\n    char *pw_username = NULL;\n    char *pw_shell = NULL;\n    char *pw_dir = NULL;\n    char display[MAX_DISPLAY_NAME_SIZE];\n    char text[256];\n\n    error = g_getuser_info_by_uid(uid, &pw_username, &pw_gid, &pw_shell,\n                                  &pw_dir, 0);\n\n    if (error == 0)\n    {\n        g_rm_temp_dir();\n        g_clearenv();\n#ifdef HAVE_SETUSERCONTEXT\n        error = g_set_allusercontext(uid);\n#else\n        /* Set some of the things setusercontext() handles on other\n         * systems */\n\n        /* Primary group. Note that secondary groups should already\n         * have been set, if we're not using setusercontext() */\n        error = g_setgid(pw_gid);\n\n        if (error == 0)\n        {\n            error = g_setuid(uid);\n        }\n\n        if (error == 0)\n        {\n            g_setenv_log(\"PATH\", \"/sbin:/bin:/usr/bin:/usr/local/bin\", 1);\n        }\n#endif\n        if (error == 0)\n        {\n            g_setenv_log(\"SHELL\", pw_shell, 1);\n            g_setenv_log(\"USER\", pw_username, 1);\n            g_setenv_log(\"LOGNAME\", pw_username, 1);\n            g_snprintf(text, sizeof(text), \"%d\", uid);\n            g_setenv_log(\"UID\", text, 1);\n            g_setenv_log(\"HOME\", pw_dir, 1);\n            g_set_current_dir(pw_dir);\n            // Use our PID as the XRDP_SESSION value\n            g_snprintf(text, sizeof(text), \"%d\", g_pid);\n            g_setenv_log(\"XRDP_SESSION\", text, 1);\n            /* XRDP_SOCKET_PATH is used by\n             * xorgxrdp and the pulseaudio plugin */\n            g_snprintf(text, sizeof(text), XRDP_SOCKET_PATH, uid);\n            g_setenv_log(\"XRDP_SOCKET_PATH\", text, 1);\n\n            // Set the passed-in variables. This may include a DISPLAY,\n            // or WAYLAND_DISPLAY\n            if ((env_names != 0) && (env_values != 0) &&\n                    (env_names->count == env_values->count))\n            {\n                for (index = 0; index < env_names->count; index++)\n                {\n                    name = (char *) list_get_item(env_names, index),\n                    value = (char *) list_get_item(env_values, index),\n                    g_setenv_log(name, value, 1);\n                }\n            }\n\n            if (g_get_display_string(display, sizeof(display)) == 0)\n            {\n                /* pulse sink socket */\n                g_snprintf(text, sizeof(text), CHANSRV_PORT_OUT_BASE_STR,\n                           display);\n                g_setenv_log(\"XRDP_PULSE_SINK_SOCKET\", text, 1);\n                /* pulse source socket */\n                g_snprintf(text, sizeof(text), CHANSRV_PORT_IN_BASE_STR,\n                           display);\n                g_setenv_log(\"XRDP_PULSE_SOURCE_SOCKET\", text, 1);\n\n                // Only set Xauthority for X11\n                if (g_get_x11_display_from_display_string(display) >= 0)\n                {\n                    g_snprintf(text, sizeof(text),\n                               XRDP_SOCKET_PATH \"/Xauthority\", uid);\n                    g_setenv_log(\"XAUTHORITY\", text, 1);\n                }\n            }\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"error getting user info for uid %d\", uid);\n    }\n\n    g_free(pw_username);\n    g_free(pw_dir);\n    g_free(pw_shell);\n\n    return error;\n}\n"
  },
  {
    "path": "sesman/sesexec/env.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file env.h\n * @brief User environment handling code declarations\n * @author Jay Sorg\n *\n */\n\n#ifndef ENV_H\n#define ENV_H\n\n#include \"list.h\"\n\n/**\n *\n * @brief Creates vnc password file\n * @param filename VNC password file name\n * @param password The password to be encrypted\n * @return 0 on success, 1 on error\n *\n */\nint\nenv_check_password_file(const char *filename, const char *password);\n\n/**\n *\n * @brief Sets user environment ($PATH, $HOME, $UID, and others)\n * @param uid user ID\n * @param env_names List of session environment variables to set\n * @param env_values List of session environment values to set\n * @return 0 on success, g_getuser_info() error codes on error\n *\n */\nint\nenv_set_user(int uid,\n             const struct list *env_names, const struct list *env_values);\n\n#endif\n"
  },
  {
    "path": "sesman/sesexec/ercp_server.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file ercp_server.c\n * @brief ercp (executive run-time control protocol) server function\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n\n#include \"login_info.h\"\n#include \"scp.h\"\n#include \"sesexec.h\"\n#include \"os_calls.h\"\n#include \"session.h\"\n#include \"sesman_config.h\"\n#include \"string_calls.h\"\n#include \"trans.h\"\n\n#include \"ercp.h\"\n#include \"ercp_server.h\"\n\n/******************************************************************************/\nstatic enum scp_sconnect_status\nget_session_fds(struct session_data *sd, unsigned int scp_flags,\n                int *display_fd, int *chan_fd)\n{\n    enum scp_sconnect_status result = E_SCP_SCONNECT_OK;\n\n    if ((*display_fd = session_get_display_server_fd(g_login_info, sd)) < 0)\n    {\n        result = E_SCP_SCONNECT_SERVER_FAIL;\n    }\n    else if ((scp_flags & E_SCP_SCONNECT_FLAG_NEED_CHANSRV) == 0)\n    {\n        // Don't need to try to connect to chansrv\n        *chan_fd = -1;\n    }\n    else\n    {\n        // If this fails, it's inconvenient, but not a show-stopper\n        *chan_fd = session_get_chansrv_fd(g_login_info, sd);\n    }\n\n    return result;\n}\n\n/******************************************************************************/\nstatic int\nhandle_connect_session_request(struct trans *self)\n{\n    int scp_fd = -1;\n    unsigned int scp_flags;\n    const char *client_ip;\n    const char *client_name;\n    int rv = ercp_get_connect_session_request(self, &scp_fd, &client_ip,\n             &client_name, &scp_flags);\n    if (rv == 0)\n    {\n        struct trans *scp_trans;\n\n        if ((scp_trans = scp_init_trans_from_fd(scp_fd,\n                                                TRANS_TYPE_SERVER,\n                                                sesexec_is_term)) == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't create SCP trans\");\n            rv = 1;\n        }\n        else\n        {\n            // Ownership of the file descriptor is passed to scp_trans;\n            // don't delete it separately.\n            scp_fd = -1;\n\n            // Now we've got a transport we can send data back to\n            // the SCP client\n            enum scp_sconnect_status scp_status;\n            int display_fd = -1;\n            int chan_fd = -1;\n\n            // Terminate any existing xrdp process to sesexec\n            if (g_ccp_trans != NULL)\n            {\n                sesexec_terminate_connected_xrdp_process(\n                    CCP_CLOSE_DISCONNECTED_BY_OTHERCONNECTION);\n                g_sleep(500);\n            }\n            scp_status = get_session_fds(g_session_data, scp_flags,\n                                         &display_fd, &chan_fd);\n\n            if (scp_status == E_SCP_SCONNECT_OK)\n            {\n                // Tell sesman about the new client connection\n                strlcpy(g_client_ip, client_ip, sizeof(g_client_ip));\n                strlcpy(g_client_name, client_name, sizeof(g_client_name));\n                g_last_connect_disconnect = time(NULL);\n\n                if (g_ecp_trans != NULL)\n                {\n                    (void)ercp_send_client_connect_event(\n                        g_ecp_trans, g_client_ip, g_client_name,\n                        g_last_connect_disconnect);\n\n                }\n            }\n\n            // Pass the session file descriptors to the client\n            rv = scp_send_connect_session_response(scp_trans, scp_status,\n                                                   display_fd, chan_fd);\n\n            if (rv == 0 && scp_status == E_SCP_SCONNECT_OK)\n            {\n                // Variables to pass to the reconnect script\n                const char *vars[] =\n                {\n                    \"XRDP_CLIENT_IP\", g_client_ip,\n                    \"XRDP_CLIENT_NAME\", g_client_name,\n                    NULL // Terminator\n                };\n                // Don't run the reconnect script on the first connect,\n                // unless we're configured to do so.\n                if (session_increment_connect_count(g_session_data) == 0)\n                {\n                    LOG(LOG_LEVEL_INFO, \"User %s has connected to a session\",\n                        g_login_info->username);\n                    if (g_cfg->always_run_reconnect)\n                    {\n                        session_run_reconnect_script(g_login_info,\n                                                     g_session_data, vars);\n                    }\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_INFO, \"User %s has reconnected to a session\",\n                        g_login_info->username);\n                    session_run_reconnect_script(g_login_info,\n                                                 g_session_data, vars);\n                }\n\n                // Convert the SCP transport to a CCP transport, and\n                // record it\n                if (sesexec_set_ccp_trans(scp_trans) == 0)\n                {\n                    scp_trans = NULL; // Prevent transport being deleted.\n                }\n            }\n\n            // Close all our copies of file descriptors, including the\n            // SCP transport if we failed to convert it to a CCP transport\n            if (display_fd >= 0)\n            {\n                g_file_close(display_fd);\n            }\n            if (chan_fd >= 0)\n            {\n                g_file_close(chan_fd);\n            }\n            if (scp_trans != NULL)\n            {\n                trans_delete(scp_trans);\n            }\n        }\n    }\n\n    if (scp_fd >= 0)\n    {\n        g_file_close(scp_fd);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nercp_server(struct trans *self)\n{\n    int rv = 0;\n    enum ercp_msg_code msgno;\n\n    switch ((msgno = ercp_msg_in_get_msgno(self)))\n    {\n        case E_ERCP_CONNECT_SESSION_REQUEST:\n            rv = handle_connect_session_request(self);\n            break;\n\n        default:\n        {\n            char buff[64];\n            ercp_msgno_to_str(msgno, buff, sizeof(buff));\n            LOG(LOG_LEVEL_ERROR, \"Ignored ERCP message %s\", buff);\n        }\n    }\n    return rv;\n}\n"
  },
  {
    "path": "sesman/sesexec/ercp_server.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file ercp_server.h\n * @brief ercp (executive run-time control protocol) server function\n * @author Matt Burt\n *\n */\n\n#ifndef ERCP_SERVER_H\n#define ERCP_SERVER_H\n\n/**\n *\n * @brief Processes an ERCP message\n * @param self The ERCP transport the message is coming in on\n *\n */\nint\nercp_server(struct trans *self);\n\n#endif // ERCP_SERVER_H\n"
  },
  {
    "path": "sesman/sesexec/login_info.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file login_info.c\n * @brief Define functionality associated with user logins for sesexec\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"login_info.h\"\n\n#include \"trans.h\"\n\n#include \"sesman_auth.h\"\n#include \"sesman_access.h\"\n#include \"sesman_config.h\"\n#include \"login_info.h\"\n#include \"os_calls.h\"\n#include \"scp.h\"\n#include \"sesexec.h\"\n#include \"string_calls.h\"\n\n/******************************************************************************/\n/**\n * Logs an authentication failure message\n *\n * @param username Username\n * @param ip_addr IP address, if known\n *\n * The message is intended for use by fail2ban. Make changes with care.\n */\nstatic void\nlog_authfail_message(const char *username, const char *ip_addr)\n{\n    if (ip_addr == NULL || ip_addr[0] == '\\0')\n    {\n        ip_addr = \"unknown\";\n    }\n    LOG(LOG_LEVEL_INFO, \"AUTHFAIL: user=%s ip=%s time=%ld\",\n        username, ip_addr, (long)time(NULL));\n}\n\n/******************************************************************************/\n/**\n * Authenticate and authorize the connection\n *\n * @param supplied_username Name for user\n * @param password Password\n * @param ip_addr Remote IP address\n * @param login_info Structure to fill in for a successful login\n * @return Status for the operation\n *\n * @post If E_SCP_LOGIN_OK is returned, g_login_info is filled in\n *\n */\nstatic enum scp_login_status\nauthenticate_and_authorize_connection(const char *supplied_username,\n                                      const char *password,\n                                      const char *ip_addr,\n                                      struct login_info *login_info)\n{\n    int uid;\n    char *username; // From reverse-looking up the UID\n    enum scp_login_status status;\n    struct auth_info *auth_info;\n\n    if (g_getuser_info_by_name(supplied_username,\n                               &uid, NULL, NULL, NULL, NULL) != 0)\n    {\n        /* we can't get a UID for the user */\n        LOG(LOG_LEVEL_ERROR, \"Can't get UID for user %s\",\n            supplied_username);\n        log_authfail_message(supplied_username, ip_addr);\n        status = E_SCP_LOGIN_NOT_AUTHENTICATED;\n    }\n    else if (g_getuser_info_by_uid(uid,\n                                   &username,\n                                   NULL, NULL, NULL, NULL) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't reverse lookup UID %d\", uid);\n        status = E_SCP_LOGIN_NOT_AUTHENTICATED;\n    }\n    else\n    {\n        if (g_strcmp(username, supplied_username) != 0)\n        {\n            /*\n             * If using a federated naming service (e.g. AD), the username\n             * supplied may not match that name mapped to by the UID. We\n             * will generate a warning in this instance so the user can see\n             * what is being used\n             */\n            LOG(LOG_LEVEL_WARNING,\n                \"Using username %s for the session (from UID %d)\",\n                username, uid);\n        }\n\n        auth_info = auth_userpass(username, password, ip_addr, &status);\n\n        /* Sanity check on result of call */\n        if ((auth_info != NULL && status != E_SCP_LOGIN_OK) ||\n                (auth_info == NULL && status == E_SCP_LOGIN_OK))\n        {\n            LOG(LOG_LEVEL_ERROR, \"Bugcheck; inconsistent auth result. \"\n                \"info = %p, status = %d\", (void *)auth_info, (int)status);\n            status = E_SCP_LOGIN_GENERAL_ERROR;\n            auth_end(auth_info);\n            auth_info = NULL;\n        }\n\n        /* Group access allowed? */\n        if (status == E_SCP_LOGIN_OK &&\n                !access_login_allowed(&g_cfg->sec, username))\n        {\n            LOG(LOG_LEVEL_INFO, \"Username okay but group problem for \"\n                \"user: %s\", username);\n            status = E_SCP_LOGIN_NOT_AUTHORIZED;\n            auth_end(auth_info);\n            auth_info = NULL;\n        }\n\n        switch (status)\n        {\n            case E_SCP_LOGIN_OK:\n            {\n                char *dup_username = g_strdup(username);\n                char *dup_ip_addr = g_strdup(ip_addr);\n\n                if (dup_username == NULL || dup_ip_addr == NULL)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"%s : Memory allocation failed\",\n                        __func__);\n                    g_free(dup_username);\n                    g_free(dup_ip_addr);\n                    status = E_SCP_LOGIN_NO_MEMORY;\n                    auth_end(auth_info);\n                    auth_info = NULL;\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_INFO, \"Access permitted for user: %s\",\n                        username);\n                    login_info->uid = uid;\n                    login_info->username = dup_username;\n                    login_info->ip_addr = dup_ip_addr;\n                    login_info->auth_info = auth_info;\n                }\n            }\n            break;\n\n            case E_SCP_LOGIN_NOT_AUTHENTICATED:\n                log_authfail_message(username, ip_addr);\n                break;\n\n            default:\n                break;\n        }\n\n        g_free(username);\n    }\n    return status;\n}\n\n/******************************************************************************/\nstatic int\nget_scp_client_retry(struct trans *scp_trans,\n                     const char **username, const char **password,\n                     const char **ip_addr)\n{\n    int got_message = 0;\n\n    // Wait for an SCP message\n    enum scp_msg_code msgno;\n\n    scp_msg_in_reset(scp_trans);\n\n    if (scp_msg_in_wait_available(scp_trans) == 0)\n    {\n        msgno = scp_msg_in_get_msgno(scp_trans);\n        switch (msgno)\n        {\n            case E_SCP_SYS_LOGIN_REQUEST:\n                if (scp_get_sys_login_request(scp_trans, username,\n                                              password, ip_addr) == 0)\n                {\n                    got_message = 1;\n                }\n                break;\n\n            case E_SCP_CLOSE_CONNECTION_REQUEST:\n                break;\n\n            default:\n            {\n                char buff[64];\n                scp_msgno_to_str(msgno, buff, sizeof(buff));\n                LOG(LOG_LEVEL_ERROR, \"unexpected message %s from SCP client\",\n                    buff);\n            }\n            break;\n        }\n    }\n\n    return got_message;\n}\n\n/******************************************************************************/\nstruct login_info *\nlogin_info_sys_login_user(struct trans *scp_trans,\n                          const char *username,\n                          const char *password,\n                          const char *ip_addr)\n{\n    struct login_info *result;\n    enum scp_login_status status = E_SCP_LOGIN_GENERAL_ERROR;\n    int server_closed = 0;\n\n    if ((result = g_new0(struct login_info, 1)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Allocation failure logging in user\");\n    }\n    else\n    {\n        int first_time = 1;\n        unsigned int retry_count = g_cfg->sec.login_retry;\n\n        result->uid = (uid_t) -1;\n\n        while (status != E_SCP_LOGIN_OK && !server_closed)\n        {\n            // First time round, we have credentials supplied by the\n            // caller. On subsequent trips, we have to wait for the\n            // SCP client to send us more.\n            if (first_time)\n            {\n                first_time = 0;\n            }\n            else if (!get_scp_client_retry(scp_trans, &username,\n                                           &password, &ip_addr))\n            {\n                status = E_SCP_LOGIN_GENERAL_ERROR;\n                break;\n            }\n\n            status = authenticate_and_authorize_connection(username,\n                     password,\n                     ip_addr,\n                     result);\n\n            if (status != E_SCP_LOGIN_OK)\n            {\n                if (retry_count > 0)\n                {\n                    --retry_count;\n                }\n                else\n                {\n                    server_closed = 1;\n                }\n            }\n\n            if (scp_send_login_response(scp_trans, status,\n                                        server_closed, result->uid) != 0)\n            {\n                status = E_SCP_LOGIN_GENERAL_ERROR;\n                break;\n            }\n        }\n    }\n\n    if (status != E_SCP_LOGIN_OK)\n    {\n        login_info_free(result);\n        result = NULL;\n    }\n\n    return result;\n}\n\n/******************************************************************************/\nstruct login_info *\nlogin_info_uds_login_user(struct trans *scp_trans)\n{\n    struct login_info *result;\n    int uid; // Needed as g_sck_get_peer_cred() doesn't use uid_t\n\n    // Allocate a struct for the result, with the IP address set to \"\"\n    if ((result = g_new0(struct login_info, 1)) == NULL ||\n            (result->ip_addr = g_new0(char, 1)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Allocation failure logging in user\");\n    }\n    else if (g_sck_get_peer_cred(scp_trans->sck, NULL, &uid, NULL) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to get peer credentials for SCP socket\");\n    }\n    else if (g_getuser_info_by_uid(uid, &result->username,\n                                   NULL, NULL, NULL, NULL) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't reverse lookup UID %d\", result->uid);\n    }\n    else if ((result->auth_info = auth_uds(result->username, NULL)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't authorize user %s over UDS\",\n            result->username);\n    }\n    else if (!access_login_allowed(&g_cfg->sec, result->username))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Access denied for user %s by your system admin\",\n            result->username);\n    }\n    else\n    {\n        result->uid = (uid_t)uid;\n        return result;\n    }\n\n    login_info_free(result);\n    return NULL;\n}\n\n\n/******************************************************************************/\nvoid\nlogin_info_free(struct login_info *self)\n{\n    if (self != NULL)\n    {\n        g_free(self->username);\n        g_free(self->ip_addr);\n        if (self->auth_info != NULL)\n        {\n            auth_end(self->auth_info);\n        }\n        g_free(self);\n    }\n}\n"
  },
  {
    "path": "sesman/sesexec/login_info.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file login_info.h\n * @brief Declare functionality associated with user logins for sesexec\n * @author Matt Burt\n *\n */\n\n#ifndef LOGIN_INFO_H\n#define LOGIN_INFO_H\n\n#include <sys/types.h>\n\nstruct trans;\n\n/**\n * Information associated with the logged-in user\n */\nstruct login_info\n{\n    uid_t uid;\n    char *username;\n    char  *ip_addr;\n    struct auth_info *auth_info;\n};\n\n/**\n * @brief Attempt a system login using username/password\n * @param scp_trans SCP transport for talking to the client\n * @param username Username from xrdp\n * @param password Password from xrdp\n * @param ip_addr IP address for xrdp client\n *\n * @result Allocated login_info struct for a successful login\n *\n * This is a wrapper around the dialogue between sesexec and the SCP process\n * which is required to start a session.\n *\n * While this call is in operation, only the scp_trans transport will\n * be checked for messages. Incoming messages on other transports will be\n * ignored. The dialog can also be terminated by a SIGTERM if the SCP\n * transport is configured to allow this.\n *\n * The username in the returned structure may differ from the passed-in\n * username if multiple names map to the same UID. This can happen with\n * federated naming services (e.g. AD, LDAP)\n */\nstruct login_info *\nlogin_info_sys_login_user(struct trans *scp_trans,\n                          const char *username,\n                          const char *password,\n                          const char *ip_addr);\n\n/**\n * @brief Create a login_info structure using UDS credentials\n *\n * This should be a formality, as by the time sesexec tries this, sesman\n * should already have done it.\n *\n * Errors are logged.\n *\n * @param scp_trans SCP transport for talking to the client\n *\n * @result Allocated login_info struct for a successful login\n */\nstruct login_info *\nlogin_info_uds_login_user(struct trans *scp_trans);\n\n/**\n * Free a struct login_info\n */\nvoid\nlogin_info_free(struct login_info *self);\n\n#endif // LOGIN_INFO_H\n"
  },
  {
    "path": "sesman/sesexec/sesexec.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Matt Burt 2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesexec.c\n * @brief Main program file for session executive process\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <ctype.h>\n#include <stdarg.h>\n\n#include \"arch.h\"\n#include \"ccp.h\"\n#include \"ccp_server.h\"\n#include \"eicp.h\"\n#include \"eicp_server.h\"\n#include \"ercp.h\"\n#include \"ercp_server.h\"\n#include \"login_info.h\"\n#include \"sesexec.h\"\n#include \"sesexec_discover.h\"\n#include \"sesman_config.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"session.h\"\n#include \"string_calls.h\"\n#include \"trans.h\"\n#include \"xrdp_sockets.h\"\n\nstruct startup_params\n{\n    const char *sesman_ini;\n};\n\nenum\n{\n    MAX_ROBJS = 32, ///< Maximum number of file objects in use at any one time\n    XRDP_EXIT_TIMEOUT = 2500 ///< Time to wait for xrdp process to exit\n};\n\n/*\n * Program-scope globals\n */\nstruct config_sesman *g_cfg;\nunsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 };\nstruct login_info *g_login_info;\nstruct session_data *g_session_data;\n\ntintptr g_term_event = 0;\ntintptr g_sigchld_event = 0;\npid_t g_pid;\n\nstruct trans *g_ecp_trans;\nstruct trans *g_ccp_trans;\nchar g_client_ip[MAX_PEER_ADDRSTRLEN];\nchar g_client_name[INFO_CLIENT_NAME_BYTES_UTF8];\ntime_t g_last_connect_disconnect;\n\n/*\n * Module-scope globals\n */\nstatic pid_t g_ecp_pid;\nstatic int g_terminate_loop = 0;\nstatic int g_terminate_status = 0;\n\n/*****************************************************************************/\n/**\n * Command line argument parser\n * @param[in] argc number of command line arguments\n * @param[in] argv pointer array of commandline arguments\n * @param[out] startup_params Returned startup parameters\n * @return 0 on success\n */\nstatic int\nprocess_params(int argc, char **argv,\n               struct startup_params *startup_params)\n{\n    int index;\n    const char *option;\n    const char *value;\n\n    startup_params->sesman_ini = DEFAULT_SESMAN_INI;\n\n    index = 1;\n\n    while (index < argc)\n    {\n        option = argv[index];\n\n        if (index + 1 < argc)\n        {\n            value = argv[index + 1];\n        }\n        else\n        {\n            value = \"\";\n        }\n\n        if (g_strcmp(option, \"-c\") == 0)\n        {\n            index++;\n            startup_params->sesman_ini = value;\n        }\n        else /* unknown option */\n        {\n            return index;\n        }\n\n        index++;\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nsesexec_eicp_data_in(struct trans *self)\n{\n    int rv;\n    int available;\n\n    rv = eicp_msg_in_check_available(self, &available);\n\n    if (rv == 0 && available)\n    {\n        if ((rv = eicp_server(self)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s: eicp_server failed\", __func__);\n        }\n        eicp_msg_in_reset(self);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nsesexec_ercp_data_in(struct trans *self)\n{\n    int rv;\n    int available;\n\n    rv = ercp_msg_in_check_available(self, &available);\n\n    if (rv == 0 && available)\n    {\n        if ((rv = ercp_server(self)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s: ercp_server failed\", __func__);\n        }\n        ercp_msg_in_reset(self);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nsesexec_ccp_data_in(struct trans *self)\n{\n    int rv;\n    int available;\n\n    rv = ccp_msg_in_check_available(self, &available);\n\n    if (rv == 0 && available)\n    {\n        if ((rv = ccp_server(self)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s: ccp_server failed\", __func__);\n        }\n        ccp_msg_in_reset(self);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/**\n * Informs the main loop a termination signal has been received\n */\nstatic void\nset_term_event(int sig)\n{\n    /* Don't try to use a wait obj in a child process */\n    if (g_getpid() == g_pid)\n    {\n        g_set_wait_obj(g_term_event);\n    }\n}\n\n/*****************************************************************************/\n/* No-op signal handler.\n */\nstatic void\nsig_no_op(int sig)\n{\n    /* no-op */\n}\n\n/******************************************************************************/\n/**\n * Informs the main loop a child exiting signal has been received\n */\nstatic void\nset_sigchld_event(int sig)\n{\n    /* Don't try to use a wait obj in a child process */\n    if (g_getpid() == g_pid)\n    {\n        g_set_wait_obj(g_sigchld_event);\n    }\n}\n\n/******************************************************************************/\nint\nsesexec_is_term(void)\n{\n    return g_terminate_loop || g_is_wait_obj_set(g_term_event);\n}\n\n/******************************************************************************/\nvoid\nsesexec_terminate_main_loop(int status)\n{\n    // Only take the first request to terminate the loop\n    if (!g_terminate_loop)\n    {\n        g_terminate_loop = 1;\n        g_terminate_status = status;\n    }\n}\n\n/******************************************************************************/\nint\nsesexec_set_ecp_transport(struct trans *t)\n{\n    int rv;\n    int pid;\n    int uid;\n    int gid;\n\n    if (t == NULL)\n    {\n        trans_delete(g_ecp_trans);\n        g_ecp_trans = NULL;\n        g_ecp_pid = 0;\n        rv = 0;\n    }\n    else if (t == g_ecp_trans)\n    {\n        // This would break the memory subsystem!\n        LOG(LOG_LEVEL_ERROR, \"%s: programming error\", __func__);\n        rv = 1;\n    }\n    else if ((rv = g_sck_get_peer_cred(t->sck, &pid, &uid, &gid)) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't get credentials of sesman socket [%s]\",\n            g_get_strerror());\n    }\n    else if (uid != 0 || gid != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"sesman PID %d is running as UID:GID %d:%d\",\n            pid, uid, gid);\n        rv = 1;\n    }\n    else\n    {\n        trans_delete(g_ecp_trans);\n        g_ecp_trans = t;\n        g_ecp_pid = pid;\n        rv = 0;\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nsesexec_is_ecp_active(void)\n{\n    return (g_ecp_trans != NULL &&\n            g_ecp_pid != 0 && g_pid_is_active(g_ecp_pid));\n\n}\n\n/******************************************************************************/\nstatic void\nsesexec_main_loop_cleanup(void)\n{\n    login_info_free(g_login_info);\n\n    /* This session is no longer discoverable */\n    sesexec_discover_disable();\n\n    /* Don't allow sesexec to terminate with an active\n       session, as we can't connect to such a session */\n    if (session_active(g_session_data))\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"Stopping session on xrdp-sesexec exit\");\n        session_send_term(g_session_data, 1);\n    }\n    session_data_free(g_session_data);\n}\n\n/******************************************************************************/\n/**\n * Close the CCP trans unconditionally\n *\n * Use this call if you are certain the other end has gone away\n */\nstatic void\nclose_ccp_trans(void)\n{\n    trans_delete(g_ccp_trans);\n    g_ccp_trans = NULL;\n}\n\n/******************************************************************************/\n/**\n *\n * @brief Starts sesexec main loop\n *\n */\nstatic int\nsesexec_main_loop(void)\n{\n    int error;\n    int robjs_count;\n    intptr_t robjs[MAX_ROBJS];\n\n    g_terminate_loop = 0;\n    g_terminate_status = 0;\n    g_login_info = NULL;\n\n    while (!g_terminate_loop)\n    {\n        robjs_count = 0;\n        robjs[robjs_count++] = g_term_event;\n        robjs[robjs_count++] = g_sigchld_event;\n\n        // ECP transport may be null if sesman has gone away\n        if (g_ecp_trans != NULL)\n        {\n            error = trans_get_wait_objs(g_ecp_trans, robjs, &robjs_count);\n            if (error != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"sesexec_main_loop: \"\n                    \"trans_get_wait_objs(ECP) failed\");\n                sesexec_terminate_main_loop(error);\n                continue;\n            }\n        }\n\n        // CCP transport is set if we have an xrdp connection\n        if (g_ccp_trans != NULL)\n        {\n            error = trans_get_wait_objs(g_ccp_trans, robjs, &robjs_count);\n            if (error != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"sesexec_main_loop: \"\n                    \"trans_get_wait_objs(CCP) failed\");\n                sesexec_terminate_main_loop(error);\n                continue;\n            }\n        }\n\n        // Add any objects from the discover module\n        error = sesexec_discover_get_wait_objs(robjs, &robjs_count, MAX_ROBJS);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"sesexec_main_loop: \"\n                \"sesexec_discover_get_wait_objs() failed\");\n            sesexec_terminate_main_loop(error);\n            continue;\n        }\n\n        if (g_obj_wait(robjs, robjs_count, NULL, 0, -1) != 0)\n        {\n            /* should not get here */\n            LOG(LOG_LEVEL_WARNING, \"sesexec_main_loop: \"\n                \"Unexpected error from g_obj_wait()\");\n            g_sleep(100);\n            continue;\n        }\n\n        if (g_is_wait_obj_set(g_term_event)) /* term */\n        {\n            g_reset_wait_obj(g_term_event);\n            if (session_active(g_session_data))\n            {\n                LOG(LOG_LEVEL_INFO, \"sesexec_main_loop: \"\n                    \"sesexec asked to terminate with active session.\");\n            }\n            else\n            {\n                LOG(LOG_LEVEL_INFO, \"sesexec_main_loop: \"\n                    \"sesexec asked to terminate. \"\n                    \"No session is active\");\n            }\n            sesexec_terminate_main_loop(0);\n            continue;\n        }\n\n        if (g_is_wait_obj_set(g_sigchld_event)) /* SIGCHLD */\n        {\n            g_reset_wait_obj(g_sigchld_event);\n\n            // See whether the session goes from active to inactive\n            // after processing SIGCHLD\n            int session_was_active = session_active(g_session_data);\n            session_process_sigchld_event(g_session_data);\n            if (session_was_active && !session_active(g_session_data))\n            {\n                // We've finished the session. Tell sesman, xrdp and\n                // finish up.\n                if (g_ecp_trans != NULL)\n                {\n                    (void)ercp_send_session_finished_event(g_ecp_trans);\n                }\n\n                sesexec_terminate_connected_xrdp_process(\n                    CCP_CLOSE_LOGOFF_BY_USER);\n\n                session_data_free(g_session_data);\n                g_session_data = NULL;\n                sesexec_terminate_main_loop(0);\n                continue;\n            }\n        }\n\n        if (g_ecp_trans != NULL)\n        {\n            error = trans_check_wait_objs(g_ecp_trans);\n            if (error != 0)\n            {\n                if (g_ecp_trans->status != TRANS_STATUS_UP &&\n                        session_active(g_session_data))\n                {\n                    // sesman has gone away. We have an active session\n                    // to keep track of, so sesman can pick it up when it\n                    // restarts\n                    LOG(LOG_LEVEL_INFO, \"sesexec_main_loop: \"\n                        \"sesman has exited\");\n                    sesexec_set_ecp_transport(NULL);\n                }\n                else\n                {\n                    // A callback has failed, or sesman has gone away and\n                    // we have no active session\n                    LOG(LOG_LEVEL_ERROR, \"sesexec_main_loop: \"\n                        \"trans_check_wait_objs failed for ECP transport\");\n                    sesexec_terminate_main_loop(error);\n                }\n                continue;\n            }\n        }\n\n        if (g_ccp_trans != NULL)\n        {\n            error = trans_check_wait_objs(g_ccp_trans);\n            if (error != 0)\n            {\n                if (g_ccp_trans->status != TRANS_STATUS_UP)\n                {\n                    // xrdp has gone away.\n                    LOG(LOG_LEVEL_INFO, \"sesexec_main_loop: \"\n                        \"xrdp connection has exited (client '%s')\",\n                        g_client_name);\n\n                    g_client_ip[0] = '\\0';\n                    g_client_name[0] = '\\0';\n                    g_last_connect_disconnect = time(NULL);\n\n                    if (g_ecp_trans != NULL)\n                    {\n                        (void)ercp_send_client_disconnect_event(\n                            g_ecp_trans, g_last_connect_disconnect);\n\n                    }\n                    close_ccp_trans();\n                }\n                else\n                {\n                    // A callback has failed. This shouldn't really happen.\n                    // Try to signal a software failure to the xrdp process\n                    LOG(LOG_LEVEL_ERROR, \"sesexec_main_loop: \"\n                        \"trans_check_wait_objs failed for CCP transport\");\n                    sesexec_terminate_connected_xrdp_process(\n                        CCP_CLOSE_SOFTWARE_FAILURE);\n\n                }\n                continue;\n            }\n        }\n\n        error = sesexec_discover_check_wait_objs();\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"sesexec_main_loop: \"\n                \"sesexec_discover_check_wait_objs failed\");\n            sesexec_terminate_main_loop(error);\n            continue;\n        }\n    }\n\n    /* close sesman communications immediately */\n    sesexec_set_ecp_transport(NULL);\n\n    /* We should already have notified xrdp of the reason why we are\n     * closing, in which case this call has no effect */\n    sesexec_terminate_connected_xrdp_process(CCP_CLOSE_SOFTWARE_FAILURE);\n\n    return g_terminate_status;\n}\n\n/******************************************************************************/\nstatic int start_logging(const char *sesman_ini)\n{\n    char text[256];\n    int rv = 1;\n    if (!g_file_exist(sesman_ini))\n    {\n        g_printf(\"Config file %s does not exist\\n\", sesman_ini);\n    }\n    else\n    {\n        enum logReturns log_error;\n        log_error = log_start(sesman_ini, \"xrdp-sesexec\", 0);\n\n        if (log_error != LOG_STARTUP_OK)\n        {\n            switch (log_error)\n            {\n                case LOG_ERROR_MALLOC:\n                    g_writeln(\"error on malloc. cannot start logging. quitting.\");\n                    break;\n                case LOG_ERROR_FILE_OPEN:\n                    g_writeln(\"error opening log file [%s]. quitting.\",\n                              getLogFile(text, sizeof(text) - 1));\n                    break;\n                default:\n                    // Assume sufficient messages have already been generated\n                    break;\n            }\n        }\n        else\n        {\n            rv = 0;\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nget_eicp_fd(char errstr[], unsigned int errstr_size)\n{\n    const char *s =  g_getenv(\"EICP_FD\");\n    const char *p;\n    int fd;\n\n    errstr[0] = '\\0';\n\n    if (s == NULL || s[0] == '\\0')\n    {\n        g_snprintf(errstr, errstr_size,\n                   \"Can't read EICP_FD environment variable\");\n        return -1;\n    }\n\n    for (p = s ; isdigit(*p) ; ++p)\n    {\n        ;\n    }\n\n    if (*p != '\\0')\n    {\n        g_snprintf(errstr, errstr_size, \"EICP_FD has non-digit char '%c'\", *p);\n        return -1;\n    }\n\n    if ((p - s) > 4)\n    {\n        g_snprintf(errstr, errstr_size, \"EICP_FD has too many digits\");\n        return -1;\n    }\n\n    fd = g_atoi(s);\n    if (!g_file_is_open(fd))\n    {\n        g_snprintf(errstr, errstr_size, \"EICP_FD %d is not open\", fd);\n        return -1;\n    }\n\n    return fd;\n}\n\n/******************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    int error = 1;\n    struct startup_params startup_params = {0};\n    int errored_argc;\n    int eicp_fd;\n    char eicp_errstr[128];\n    /*\n     * Check the EICP transport file descriptor is provided and open\n     * before opening any log files, config files, etc. We then open\n     * log files, and log errors at that point */\n    eicp_fd = get_eicp_fd(eicp_errstr, sizeof(eicp_errstr));\n\n    g_init(\"xrdp-sesexec\");\n\n    //g_sleep(15 * 1000);\n    errored_argc = process_params(argc, argv, &startup_params);\n    if (errored_argc > 0)\n    {\n        g_writeln(\"Unknown option: %s\", argv[errored_argc]);\n    }\n    /* starting logging subsystem\n     *\n     * For historic reasons, we share a log file with sesman */\n    else if (start_logging(startup_params.sesman_ini) == 0)\n    {\n        /* reading config\n         *\n         * For historic reasons, we share a config with sesman */\n        if ((g_cfg = config_read(startup_params.sesman_ini)) == NULL)\n        {\n            LOG(LOG_LEVEL_ALWAYS, \"error reading config %s: %s\",\n                startup_params.sesman_ini, g_get_strerror());\n        }\n        else if (eicp_fd < 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s\", eicp_errstr);\n        }\n        else\n        {\n            char text[128];\n            struct trans *t;\n\n            g_pid = g_getpid();\n\n            /* signal handling */\n            g_snprintf(text, sizeof(text), \"xrdp_sesexec_%8.8x_main_term\",\n                       g_pid);\n            g_term_event = g_create_wait_obj(text);\n            g_snprintf(text, sizeof(text), \"xrdp_sesexec_%8.8x_sigchld\",\n                       g_pid);\n            g_sigchld_event = g_create_wait_obj(text);\n\n            // No need to terminate on SIGINT for sesexec. This can\n            // also make it hard to debug sessions.\n            //g_signal_user_interrupt(set_term_event);\n            g_signal_terminate(set_term_event); /* SIGTERM */\n            g_signal_pipe(sig_no_op);          /* SIGPIPE */\n            g_signal_child_stop(set_sigchld_event);\n\n            /* Set up an EICP process handler\n             * Errors are logged by this call if necessary */\n            t = eicp_init_trans_from_fd(eicp_fd,\n                                        TRANS_TYPE_SERVER,\n                                        sesexec_is_term);\n            if (t != NULL && sesexec_set_ecp_transport(t) == 0)\n            {\n                g_ecp_trans->trans_data_in = sesexec_eicp_data_in;\n                g_ecp_trans->callback_data = NULL;\n\n                /* start program main loop */\n                LOG(LOG_LEVEL_INFO, \"starting xrdp-sesexec with pid %d\", g_pid);\n                error = sesexec_main_loop();\n                sesexec_main_loop_cleanup();\n            }\n            g_delete_wait_obj(g_term_event);\n        }\n        config_free(g_cfg);\n        log_end();\n    }\n\n    g_deinit();\n    return error;\n}\n\n/******************************************************************************/\nvoid\nsesexec_terminate_connected_xrdp_process(enum ccp_close_reason_type reason)\n{\n    if (g_ccp_trans != NULL && g_ccp_trans->status == TRANS_STATUS_UP)\n    {\n        // Ask xrdp to exit, specifying the reason to return to\n        // the RDP client (if possible)\n        (void)ccp_send_close_connection_request(g_ccp_trans, reason);\n\n        unsigned int start_ms = g_get_elapsed_ms();\n        while (1)\n        {\n            int robjs_count = 0;\n            intptr_t robjs[MAX_ROBJS];\n\n            // How long have we been waiting for xrdp to exit?\n            unsigned int elapsed = g_get_elapsed_ms() - start_ms;\n            if (elapsed > XRDP_EXIT_TIMEOUT)\n            {\n                // A timeout has occurred\n                LOG(LOG_LEVEL_WARNING,\n                    \"xrdp process failed to exit after %u ms\", elapsed);\n                break;\n            }\n\n            robjs[robjs_count++] = g_term_event;\n            if (trans_get_wait_objs(g_ccp_trans, robjs, &robjs_count) != 0)\n            {\n                // Transport has gone away\n                LOG(LOG_LEVEL_WARNING,\n                    \"xrdp process exited after %u ms\", elapsed);\n                break;\n            }\n            if (g_obj_wait(robjs, robjs_count, NULL, 0,\n                           XRDP_EXIT_TIMEOUT - elapsed) != 0)\n            {\n                /* should not get here */\n                g_sleep(100);\n            }\n            else if (g_is_wait_obj_set(g_term_event))\n            {\n                // Get out as quickly as possible\n                break;\n            }\n            else\n            {\n                // This will cause trans_get_wait_objs() to return a failure\n                // when the end of the data on the socket is reached.\n                (void)trans_check_wait_objs(g_ccp_trans);\n            }\n        }\n    }\n\n    close_ccp_trans();\n}\n\n/******************************************************************************/\nint\nsesexec_set_ccp_trans(struct trans *scp_trans)\n{\n    int rv = 1;\n    pid_t pid;\n\n    if (scp_trans == NULL)\n    {\n        close_ccp_trans();\n        rv = 0;\n    }\n    else if (scp_trans == g_ccp_trans)\n    {\n        // This would break the memory subsystem!\n        LOG(LOG_LEVEL_ERROR, \"%s: programming error\", __func__);\n        rv = 1;\n    }\n    else if ((rv = g_sck_get_peer_cred(scp_trans->sck, &pid, NULL, NULL)) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't get credentials of xrdp socket [%s]\",\n            g_get_strerror());\n    }\n    else\n    {\n        // Convert the transport to a CCP transport\n        ccp_trans_from_scp_trans(scp_trans,\n                                 sesexec_ccp_data_in,\n                                 NULL);\n        trans_delete(g_ccp_trans);\n        g_ccp_trans = scp_trans;\n        rv = 0;\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "sesman/sesexec/sesexec.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesexec.h\n * @brief Main include file\n * @author Jay Sorg\n *\n */\n\n#ifndef SESEXEC_H\n#define SESEXEC_H\n\n#include <sys/types.h>\n\n#include \"ccp_application_types.h\"\n#include \"xrdp_constants.h\"\n\nstruct config_sesman;\nstruct trans;\nstruct login_info;\nstruct session_data;\n\n#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)\n#define USE_BSD_SETLOGIN\n#endif\n\n/* Globals */\n/**\n * Pointer to config data for sesman/sesexec\n */\nextern struct config_sesman *g_cfg;\n\n/**\n * DES key used to obfuscate VNC password files.\n *\n * This key is not documented in RFC6143, but can readily be found by\n * searching VNC sources.\n *\n * You can also find the 'reversed' form \"e84ad660c4721ae0\"\n * on the net, particulary for openssl one-liners to decrypt VNC\n * password files.\n */\nextern unsigned char g_fixedkey[8];\n\n/**\n * Information about the logged-in user\n *\n * This is set when the user successfully passes authentication\n */\nextern struct login_info *g_login_info;\n\n/**\n * Information about the user session (opaque type)\n *\n * Set when the user is succesfully logged in\n */\nextern struct session_data *g_session_data;\n\n/**\n * Program has received a termination event\n */\nextern tintptr g_term_event;\n\n/**\n * Program has received one or more SIGCHLD events\n */\nextern tintptr g_sigchld_event;\n\n/**\n * PID of sesexec process\n *\n * Used to detect when we are running in a form of the original process\n */\nextern pid_t g_pid;\n\n/**\n * EICP/ERCP transport\n *\n * Used to communicate with the sesman process\n *\n * Use sesexec_is_ecp_active() if you need to check sesman is\n * truly there.\n */\nextern struct trans *g_ecp_trans;\n\n/**\n * CCP transport\n *\n * Used to communicate with the currently connected xrdp process\n */\nextern struct trans *g_ccp_trans;\n\n/**\n * Last connected client IP address\n */\nextern char g_client_ip[MAX_PEER_ADDRSTRLEN];\n\n/**\n * Last connected client name\n */\nextern char g_client_name[INFO_CLIENT_NAME_BYTES_UTF8];\n\n/**\n * Last connect / disconnect time\n */\nextern time_t g_last_connect_disconnect;\n\n/**\n * Callback to process incoming ERCP data\n */\nint\nsesexec_ercp_data_in(struct trans *self);\n\n/**\n * Check for termination\n *\n * @return boolean. Set if program has been asked to terminate\n */\nint\nsesexec_is_term(void);\n\n/**\n * Terminate the sesexec main loop\n *\n * @param status Status to return to the OS\n */\nvoid\nsesexec_terminate_main_loop(int status);\n\n/**\n * Sets the ECP (sesman) transport\n *\n * @param t Transport supposedly connected to the ECP protocol\n *          provider (sesman), or NULL to clear the transport\n * @return 0 for success\n *\n * Peer credentials are checked for root:root\n */\nint\nsesexec_set_ecp_transport(struct trans *t);\n\n/**\n * Is the ECP transport still active?\n *\n * @result boolean\n *\n * This is intended to be used as a guard to prevent an active ECP\n * transport being overwritten. Do not use it to check if sesman is\n * active before sending messages, as this introduces a race condition.\n */\nint\nsesexec_is_ecp_active(void);\n\n/**\n * Terminate an active xrdp process\n *\n * @param reason Reason to pass back to the xrdp process (if connected)\n *\n * After this call, g_ccp_trans will be NULL\n */\nvoid\nsesexec_terminate_connected_xrdp_process(enum ccp_close_reason_type reason);\n\n/**\n * Set the CCP transport from an SCP transport\n *\n * This call is intended to be used at the end of a connection\n * event, to record our end of the connection to the xrdp process\n */\nint\nsesexec_set_ccp_trans(struct trans *scp_trans);\n\n#endif // SESEXEC_H\n"
  },
  {
    "path": "sesman/sesexec/sesexec_discover.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesexec_discover.c\n * @brief Declare functionality associated with sesman restart support\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n\n#include \"sesexec_discover.h\"\n#include \"trans.h\"\n#include \"sesexec.h\"\n#include \"session.h\"\n#include \"sesman_config.h\"\n#include \"os_calls.h\"\n#include \"ercp.h\"\n#include \"login_info.h\"\n\n/*\n * Module-scope globals\n */\nstatic struct trans *g_discover_trans = NULL;\n\n/*****************************************************************************/\nstatic int\ndiscover_trans_conn_in(struct trans *trans, struct trans *new_trans)\n{\n    const struct session_parameters *sp;\n    int rv = 0;\n\n    if (trans == NULL || new_trans == NULL || trans != g_discover_trans)\n    {\n        return 1;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"discover_trans_conn_in:\");\n\n    if (sesexec_is_ecp_active())\n    {\n        int pid = 0;\n        (void)g_sck_get_peer_cred(new_trans->sck, &pid, 0, 0);\n\n        LOG(LOG_LEVEL_WARNING,\n            \"Connection attempt to sesexec PID %d from PID %d\"\n            \" while ECP is still active\",\n            g_pid, pid);\n\n        trans_delete(new_trans);\n    }\n    else if ((sp = session_get_parameters(g_session_data)) == NULL)\n    {\n        // If we haven't got session parameters, we shouldn't be here\n        LOG(LOG_LEVEL_ERROR, \"Bugcheck: Can't get active session params\");\n        trans_delete(new_trans);\n        rv = 1;\n    }\n    else\n    {\n        // Reconnect to sesman and tell it about our existing\n        // session\n        ercp_init_trans(new_trans);\n        new_trans->trans_data_in = sesexec_ercp_data_in;\n        new_trans->callback_data = NULL;\n\n        // Note, this call makes further privilege checks that may still\n        // fail.  If they do however, we wish to carry on running. These\n        // failed checks will be logged.\n        if (sesexec_set_ecp_transport(new_trans) == 0)\n        {\n            (void)ercp_send_session_announce_event(\n                new_trans,\n                session_get_display(g_session_data),\n                g_login_info->uid,\n                sp->type,\n                sp->width,\n                sp->height,\n                sp->bpp,\n                &sp->guid,\n                g_login_info->ip_addr,\n                session_get_start_time(g_session_data),\n                sp->instance_name);\n\n            // Tell semsan about the last client connect or disconnect\n            if (g_ccp_trans != NULL)\n            {\n                (void)ercp_send_client_connect_event(new_trans,\n                                                     g_client_ip,\n                                                     g_client_name,\n                                                     g_last_connect_disconnect);\n            }\n            else\n            {\n                (void)ercp_send_client_disconnect_event(new_trans,\n                                                        g_last_connect_disconnect);\n            }\n        }\n    }\n    return rv;\n}\n\n/******************************************************************************/\nint\nsesexec_discover_enable(void)\n{\n    int rv = 1;\n    if (g_session_data == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Cant enable discovery without an active session\");\n    }\n    else if (g_discover_trans != NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Logic error: discovery is already active\");\n    }\n    else if ((g_discover_trans =\n                  trans_create(TRANS_MODE_UNIX, 8192, 8192)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Out of memory enabling discovery\");\n    }\n    else\n    {\n        char discover_port[XRDP_SOCKETS_MAXPATH];\n\n        snprintf(discover_port, sizeof(discover_port), \"%s.r/%s\",\n                 g_cfg->listen_port,\n                 session_get_display(g_session_data));\n        g_discover_trans->is_term = sesexec_is_term;\n        g_discover_trans->trans_conn_in = discover_trans_conn_in;\n        if ((rv = trans_listen(g_discover_trans, discover_port)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Transport error enabling discovery [%s]\",\n                g_get_strerror());\n            trans_delete(g_discover_trans);\n            g_discover_trans = NULL;\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nsesexec_discover_disable(void)\n{\n    trans_delete(g_discover_trans);\n    g_discover_trans = NULL;\n\n    return 0;\n}\n\n/******************************************************************************/\n\nint\nsesexec_discover_get_wait_objs(intptr_t robjs[], int *robjs_count,\n                               int max_count)\n{\n    int rv;\n    if (g_discover_trans == NULL)\n    {\n        rv = 0;\n    }\n    else if (*robjs_count >= max_count)\n    {\n        rv = 1;\n    }\n    else\n    {\n        rv = trans_get_wait_objs(g_discover_trans, robjs, robjs_count);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nsesexec_discover_check_wait_objs(void)\n{\n    return (g_discover_trans == NULL)\n           ? 0\n           : trans_check_wait_objs(g_discover_trans);\n}\n"
  },
  {
    "path": "sesman/sesexec/sesexec_discover.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesexec_discover.h\n * @brief Declare functionality associated with sesman restart support\n * for sesexec\n *\n * @author Matt Burt\n *\n */\n\n#ifndef SESEXEC_DISCOVER_H\n#define SESEXEC_DISCOVER_H\n\n#include <stdint.h>\n\n/**\n * Start the listening object used when sesman restarts\n *\n * @return != 0 for error\n */\nint\nsesexec_discover_enable(void);\n\n/**\n * Stop the listening object used when sesman restarts, and deallocate all\n * module resources.\n *\n * @return != 0 for error\n */\nint\nsesexec_discover_disable(void);\n\n/**\n * Add any file descriptors in use by the module to an array\n *\n * @param robjs Array to add fds to\n * @param[in,out] robjs_count Index where elements are to be added\n * @param max_count Max value of robjs_count\n * @return != 0 for error\n *\n * This function can be called before sesexec_discover_enable(),\n * in which case it does nothing.\n */\nint\nsesexec_discover_get_wait_objs(intptr_t robjs[], int *robjs_count,\n                               int max_count);\n\n\n/**\n * Check any file descriptors in use by the module for actionable events\n * @return != 0 for error\n *\n * This function can be called before sesexec_discover_enable(),\n * in which case it does nothing.\n */\nint\nsesexec_discover_check_wait_objs(void);\n\n#endif // SESEXEC_DISCOVER_H\n"
  },
  {
    "path": "sesman/sesexec/session.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * BSD process grouping by:\n * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland.\n * Copyright (c) 2000-2001 Markus Friedl.\n * Copyright (c) 2011-2015 Koichiro Iwao, Kyushu Institute of Technology.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file session.c\n * @brief Session management code\n * @author Jay Sorg, Simone Fedele\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <stdio.h>\n#include <errno.h>\n\n#include \"arch.h\"\n#include \"session.h\"\n\n#include \"sesman_auth.h\"\n#include \"sesman_config.h\"\n#include \"env.h\"\n#include \"guid.h\"\n#include \"list.h\"\n#include \"log.h\"\n#include \"login_info.h\"\n#include \"os_calls.h\"\n#include \"sesexec.h\"\n#include \"sessionrecord.h\"\n#include \"ssl_calls.h\"\n#include \"string_calls.h\"\n#include \"trans.h\"\n#include \"xauth.h\"\n#include \"xwait.h\"\n#include \"xrdp_sockets.h\"\n\nstruct session_data\n{\n    pid_t x_server; ///< PID of X server\n    pid_t win_mgr; ///< PID of window manager\n    pid_t chansrv; ///< PID of chansrv\n    time_t start_time;\n    unsigned int connect_count;\n    char display[MAX_DISPLAY_NAME_SIZE]; // Set by session_start()\n    struct session_parameters params;\n    // Flexible array member used to store strings in params and ip_addr;\n#ifdef __cplusplus\n    char strings[1];\n#else\n    char strings[];\n#endif\n};\n\n/******************************************************************************/\n/**\n * Create a new session_data structure from a session_parameters object\n *\n * @param sp Session parameters passed to session_start()\n * @return semi-initialised session_data struct\n */\nstatic struct session_data *\nsession_data_new(const struct session_parameters *sp)\n{\n    unsigned int string_length = 0;\n    // What string length do we need?\n    string_length += g_strlen(sp->shell) + 1;\n    string_length += g_strlen(sp->directory) + 1;\n    string_length += g_strlen(sp->instance_name) + 1;\n\n    struct session_data *sd = (struct session_data *)g_malloc(sizeof(*sd) + string_length, 0);\n\n    if (sd == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Out of memory allocating session data struct\");\n    }\n    else\n    {\n        sd->win_mgr = -1;\n        sd->x_server = -1;\n        sd->chansrv = -1;\n        sd->start_time = 0;\n        sd->connect_count = 0;\n\n        /* Copy all the non-string session parameters... */\n        sd->params = *sp;\n\n        /* ...and then the strings */\n        char *memptr = sd->strings;\n\n#define COPY_STRING(dest,src) \\\n    (dest) = memptr; \\\n    strcpy(memptr, src); \\\n    memptr += strlen(memptr) + 1\n\n        COPY_STRING(sd->params.shell, sp->shell);\n        COPY_STRING(sd->params.directory, sp->directory);\n        COPY_STRING(sd->params.instance_name, sp->instance_name);\n\n#undef COPY_STRING\n    }\n\n    return sd;\n}\n\n/******************************************************************************/\nvoid\nsession_data_free(struct session_data *session_data)\n{\n    if (session_data != NULL)\n    {\n#ifdef USE_DEVEL_LOGGING\n        if (session_data->win_mgr > 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING,\n                      \"Freeing session data with valid window manager PID %d\",\n                      session_data->win_mgr);\n        }\n        if (session_data->x_server > 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING,\n                      \"Freeing session data with valid X server PID %d\",\n                      session_data->x_server);\n        }\n        if (session_data->chansrv > 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING,\n                      \"Freeing session data with valid chansrv PID %d\",\n                      session_data->chansrv);\n        }\n#endif\n\n        free(session_data);\n    }\n}\n\n/******************************************************************************/\n/**\n * Creates a string consisting of all parameters that is hosted in the param list\n * @param outstr allocate this buffer before you use this function\n * @param len the allocated len for outstr\n */\nstatic char *\ndumpItemsToString(struct list *self, char *outstr, int len)\n{\n    int index;\n    int totalLen = 0;\n\n    g_memset(outstr, 0, len);\n    if (self->count == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"List is empty\");\n    }\n\n    for (index = 0; index < self->count; index++)\n    {\n        /* +1 = one space*/\n        totalLen = totalLen + g_strlen((char *)list_get_item(self, index)) + 1;\n\n        if (len > totalLen)\n        {\n            g_strcat(outstr, (char *)list_get_item(self, index));\n            g_strcat(outstr, \" \");\n        }\n    }\n\n    return outstr ;\n}\n\n/******************************************************************************/\nstatic void\nstart_chansrv(const struct login_info *login_info,\n              const struct session_data *sd,\n              void *closure /* unused */)\n{\n    struct list *chansrv_params = list_create();\n    const char *exe_path = XRDP_SBIN_PATH \"/xrdp-chansrv\";\n\n    if (chansrv_params != NULL)\n    {\n        chansrv_params->auto_free = 1;\n        if (!list_add_strdup(chansrv_params, exe_path))\n        {\n            list_delete(chansrv_params);\n            chansrv_params = NULL;\n        }\n    }\n\n    if (chansrv_params == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Out of memory starting chansrv\");\n    }\n    else\n    {\n        env_set_user(login_info->uid,\n                     g_cfg->env_names,\n                     g_cfg->env_values);\n\n        LOG_DEVEL_LEAKING_FDS(\"chansrv\", 3, -1);\n\n        /* executing chansrv */\n        g_execvp_list(exe_path, chansrv_params);\n\n        /* should not get here */\n        list_delete(chansrv_params);\n    }\n}\n\n/******************************************************************************/\nstatic void\nstart_window_manager(const struct login_info *login_info,\n                     const struct session_data *sd,\n                     void *closure /* unused */)\n{\n    char text[256];\n    const struct session_parameters *sp = &sd->params;\n\n    env_set_user(login_info->uid,\n                 g_cfg->env_names,\n                 g_cfg->env_values);\n\n    auth_set_env(login_info->auth_info);\n    LOG_DEVEL_LEAKING_FDS(\"window manager\", 3, -1);\n\n    if (sp->directory[0] != '\\0')\n    {\n        if (g_cfg->sec.allow_alternate_shell)\n        {\n            g_set_current_dir(sp->directory);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"Directory change to %s requested, but not \"\n                \"allowed by AllowAlternateShell config value.\",\n                sp->directory);\n        }\n    }\n\n    if (sp->shell[0] != '\\0')\n    {\n        if (g_cfg->sec.allow_alternate_shell)\n        {\n            if (g_cfg->sec.pass_shell_as_env != NULL &&\n                    g_cfg->sec.pass_shell_as_env[0] != '\\0')\n            {\n                // Pass the shell in to the standard startwm scripts\n                // in an environment variable\n                LOG(LOG_LEVEL_INFO,\n                    \"Setting variable '%s' to the specified shell of '%s'\",\n                    g_cfg->sec.pass_shell_as_env,\n                    sp->shell);\n                g_setenv_log(g_cfg->sec.pass_shell_as_env, sp->shell, 1);\n            }\n            else\n            {\n                // Try to execute the shell directly (if permitted)\n                if (g_strchr(sp->shell, ' ') != 0 ||\n                        g_strchr(sp->shell, '\\t') != 0)\n                {\n                    LOG(LOG_LEVEL_INFO,\n                        \"Using user requested window manager on \"\n                        \"display %s with embedded arguments using a shell: %s\",\n                        sd->display, sp->shell);\n                    const char *argv[] = {\"sh\", \"-c\", sp->shell, NULL};\n                    g_execvp(\"/bin/sh\", (char **)argv);\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_INFO,\n                        \"Using user requested window manager on \"\n                        \"display %s %s\", sd->display, sp->shell);\n                    g_execlp3(sp->shell, sp->shell, 0);\n                }\n            }\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"Shell %s requested by user, but not allowed by \"\n                \"AllowAlternateShell config value.\",\n                sp->shell);\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_DEBUG, \"The user session on display %s did \"\n            \"not request a specific window manager\", sd->display);\n    }\n\n    /* try to execute user window manager if enabled */\n    if (g_cfg->enable_user_wm)\n    {\n        g_snprintf(text, sizeof(text), \"%s/%s\",\n                   g_getenv(\"HOME\"), g_cfg->user_wm);\n        if (g_file_exist(text))\n        {\n            LOG(LOG_LEVEL_INFO,\n                \"Using window manager on display %s\"\n                \" from user home directory: %s\", sd->display, text);\n            g_execlp3(text, g_cfg->user_wm, 0);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"The user home directory window manager configuration \"\n                \"is enabled but window manager program does not exist: %s\",\n                text);\n        }\n    }\n\n    LOG(LOG_LEVEL_INFO,\n        \"Using the default window manager on display %s: %s\",\n        sd->display, g_cfg->default_wm);\n    g_execlp3(g_cfg->default_wm, g_cfg->default_wm, 0);\n\n    /* still a problem starting window manager just start xterm */\n    LOG(LOG_LEVEL_WARNING,\n        \"No window manager on display %s started, \"\n        \"so falling back to starting xterm for user debugging\",\n        sd->display);\n    g_execlp3(\"xterm\", \"xterm\", 0);\n\n    /* should not get here */\n    LOG(LOG_LEVEL_ERROR, \"A fatal error has occurred attempting to start \"\n        \"the window manager on display %s, aborting connection\",\n        sd->display);\n}\n\n/******************************************************************************/\nstatic struct list *\nprepare_xorg_xserver_params(const struct session_data *sd,\n                            const char *authfile)\n{\n\n    char screen[32]; /* display number */\n    char text[128];\n    const char *xserver;\n\n    struct list *params = list_create();\n    if (params != NULL)\n    {\n        params->auto_free = 1;\n\n        /*\n         * Make sure Xorg doesn't run setuid root. Root access is not\n         * needed. Xorg can fail when run as root and the user has no\n         * console permissions.\n         */\n        if (g_cfg->sec.xorg_no_new_privileges && g_no_new_privs() != 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"[session start] (display :%d): Failed to disable \"\n                \"setuid on X server: %s\",\n                sd->params.x11_display, g_get_strerror());\n        }\n\n        g_snprintf(screen, sizeof(screen), \":%d\", sd->params.x11_display);\n\n        /* some args are passed via env vars */\n        g_snprintf(text, sizeof(text), \"%d\", sd->params.width);\n        g_setenv_log(\"XRDP_START_WIDTH\", text, 1);\n\n        g_snprintf(text, sizeof(text), \"%d\", sd->params.height);\n        g_setenv_log(\"XRDP_START_HEIGHT\", text, 1);\n\n        g_snprintf(text, sizeof(text), \"%d\", g_cfg->sess.max_idle_time);\n        g_setenv_log(\"XRDP_SESMAN_MAX_IDLE_TIME\", text, 1);\n\n        g_snprintf(text, sizeof(text), \"%d\", g_cfg->sess.max_disc_time);\n        g_setenv_log(\"XRDP_SESMAN_MAX_DISC_TIME\", text, 1);\n\n        g_snprintf(text, sizeof(text), \"%d\", g_cfg->sess.kill_disconnected);\n        g_setenv_log(\"XRDP_SESMAN_KILL_DISCONNECTED\", text, 1);\n\n        g_snprintf(text, sizeof(text), XRDP_X11RDP_BASE_STR, sd->display);\n        g_setenv_log(\"XRDP_X11RDP_SOCKET\", text, 1);\n\n        g_snprintf(text, sizeof(text), XRDP_DISCONNECT_BASE_STR, sd->display);\n        g_setenv_log(\"XRDP_DISCONNECT_SOCKET\", text, 1);\n\n        /* get path of Xorg from config */\n        xserver = (const char *)list_get_item(g_cfg->xorg_params, 0);\n\n        /* these are the must have parameters */\n        list_add_strdup_multi(params,\n                              xserver, screen,\n                              \"-auth\", authfile,\n                              LIST_ADD_STRDUP_TERM);\n\n        /* additional parameters from sesman.ini file */\n        list_append_list_strdup(g_cfg->xorg_params, params, 1);\n    }\n\n    return params;\n}\n\n/******************************************************************************/\n/**\n * Create an Xvnc password file\n *\n * @param x11_display X11 display number\n * @return Name of passwd file, or NULL if no memory.\n *\n * env_set_user() must be called before calling this function\n */\nstatic char *\nget_xvnc_passwd_file_name(int x11_display)\n{\n    char *result = NULL;\n    int len;\n\n    char *pw_username = NULL;\n    char *pw_dir = NULL;\n    char hostname[256];\n    int error;\n\n    /* Get parameters needed for VNC filename */\n    hostname[sizeof(hostname) - 1] = '\\0';\n    g_gethostname(hostname, sizeof(hostname));\n    error = g_getuser_info_by_uid(g_getuid(), &pw_username, 0, 0, &pw_dir, 0);\n\n    if (error != 0 || pw_username == NULL || pw_dir == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't get parameters for XVnc passwd file\");\n    }\n    else\n    {\n        if (0 == g_cfg->auth_file_path)\n        {\n            /* if no auth_file_path is set, then we go for\n             $HOME/.vnc/sesman_passwd-USERNAME@HOSTNAME:DISPLAY */\n            if (!g_directory_exist(\".vnc\"))\n            {\n                if (g_mkdir(\".vnc\") < 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Error creating .vnc directory: %s\",\n                        g_get_strerror());\n                }\n            }\n\n            len = g_snprintf(NULL, 0, \"%s/.vnc/sesman_passwd-%s@%s:%d\",\n                             pw_dir, pw_username, hostname, x11_display);\n            ++len; // Allow for terminator\n\n            result = (char *) g_malloc(len, 1);\n            if (result != NULL)\n            {\n                /* Try legacy names first, remove if found */\n                g_snprintf(result, len,\n                           \"%s/.vnc/sesman_%s_passwd:%d\",\n                           pw_dir, pw_username, x11_display);\n                if (g_file_exist(result))\n                {\n                    LOG(LOG_LEVEL_WARNING, \"Removing old \"\n                        \"password file %s\", result);\n                    g_file_delete(result);\n                }\n                g_snprintf(result, len,\n                           \"%s/.vnc/sesman_%s_passwd\",\n                           pw_dir, pw_username);\n                if (g_file_exist(result))\n                {\n                    LOG(LOG_LEVEL_WARNING, \"Removing insecure \"\n                        \"password file %s\", result);\n                    g_file_delete(result);\n                }\n                g_snprintf(result, len,\n                           \"%s/.vnc/sesman_passwd-%s@%s:%d\",\n                           pw_dir, pw_username, hostname, x11_display);\n            }\n        }\n        else\n        {\n            /* we use auth_file_path as requested */\n            len = g_snprintf(NULL, 0, g_cfg->auth_file_path, pw_username);\n\n            ++len; // Allow for terminator\n            result = (char *) g_malloc(len, 1);\n            if (result != NULL)\n            {\n                g_snprintf(result, len,\n                           g_cfg->auth_file_path, pw_username);\n            }\n        }\n\n        if (result == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Can't allocate memory for Xvnc passwd file name\");\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"pass file: %s\", result);\n        }\n    }\n    g_free(pw_username);\n    g_free(pw_dir);\n\n    return result;\n}\n\n/******************************************************************************/\nstatic int\nset_xvnc_passwd(const char *filename, const char *passwd)\n{\n    char encryptedPasswd[16];\n    char key[24];\n    char passwd_hash[20];\n    char passwd_hash_text[40];\n    int fd;\n    int passwd_bytes;\n    void *des;\n    void *sha1;\n\n    if (filename == NULL)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Cannot write VNC password hash to NULL file\");\n        return 1;\n    }\n\n    /*\n     * If we're in FIPS mode, do not write the GUID to disk after it's\n     * been encrypted with an insecure algorithm.\n     */\n    if (g_fips_mode_enabled())\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't create VNC password file in FIPS mode\");\n        return 1;\n    }\n    /* create password hash from password */\n    passwd_bytes = (passwd == NULL) ? 0 : strlen(passwd);\n    sha1 = ssl_sha1_info_create();\n    ssl_sha1_clear(sha1);\n    ssl_sha1_transform(sha1, \"xrdp_vnc\", 8);\n    ssl_sha1_transform(sha1, passwd, passwd_bytes);\n    ssl_sha1_transform(sha1, passwd, passwd_bytes);\n    ssl_sha1_complete(sha1, passwd_hash);\n    ssl_sha1_info_delete(sha1);\n    g_snprintf(passwd_hash_text, sizeof(passwd_hash_text),\n               \"%2.2x%2.2x%2.2x%2.2x\",\n               (tui8)passwd_hash[0], (tui8)passwd_hash[1],\n               (tui8)passwd_hash[2], (tui8)passwd_hash[3]);\n    passwd = passwd_hash_text;\n\n    /* create file from password */\n    g_memset(encryptedPasswd, 0, sizeof(encryptedPasswd));\n    g_strncpy(encryptedPasswd, passwd, 8);\n    g_memset(key, 0, sizeof(key));\n    g_mirror_memcpy(key, g_fixedkey, 8);\n    des = ssl_des3_encrypt_info_create(key, 0);\n    ssl_des3_encrypt(des, 8, encryptedPasswd, encryptedPasswd);\n    ssl_des3_info_delete(des);\n    fd = g_file_open_ex(filename, 0, 1, 1, 1);\n    if (fd == -1)\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"Cannot write VNC password hash to file %s: %s\",\n            filename, g_get_strerror());\n        return 1;\n    }\n    g_file_write(fd, encryptedPasswd, 8);\n    g_file_close(fd);\n    return 0;\n}\n\n/******************************************************************************/\n/**\n * Prepare a list of parameters for the Xvnc X server\n * @param sd Session data\n * @param authfile XAUTHORITY file\n * @param passwd_file VNC password file, or NULL\n * @param port UDS port to connect to, or NULL\n * @return parameters list\n *\n * One of passwd_file and port must be set\n */\nstatic struct list *\nprepare_xvnc_xserver_params(const struct session_data *sd,\n                            const char *authfile,\n                            const char *passwd_file,\n                            const char *port)\n{\n    char screen[32] = {0}; /* display number */\n    char geometry[32] = {0};\n    char depth[32] = {0};\n    const char *xserver;\n    const struct session_parameters *sp = &sd->params;\n\n    struct list *params = list_create();\n    if (params != NULL)\n    {\n        params->auto_free = 1;\n\n        g_snprintf(screen, sizeof(screen), \":%d\", sp->x11_display);\n        g_snprintf(geometry, sizeof(geometry), \"%dx%d\", sp->width, sp->height);\n        g_snprintf(depth, sizeof(depth), \"%d\", sp->bpp);\n\n        /* get path of Xvnc from config */\n        xserver = (const char *)list_get_item(g_cfg->vnc_params, 0);\n\n        /* these are the must have parameters */\n        list_add_strdup_multi(params,\n                              xserver, screen,\n                              \"-auth\", authfile,\n                              \"-geometry\", geometry,\n                              \"-depth\", depth,\n                              LIST_ADD_STRDUP_TERM);\n\n        if (passwd_file != NULL)\n        {\n            /* RFB authorization */\n            list_add_strdup_multi(params,\n                                  \"-rfbauth\", passwd_file,\n                                  LIST_ADD_STRDUP_TERM);\n        }\n        else if (port != NULL)\n        {\n            /* UDS connection. Authorization is handled by standard socket\n             * permissions, so we do not need to authorize within the\n             * VNC protocol exchange as well */\n            char sock_mode[16];\n\n            /* Convert a standard permissions mask into decimal\n             * for the -rfbunixmode switch argument\n             */\n            g_snprintf(sock_mode, sizeof(sock_mode),\n                       \"%d\", 0660); /* rw-rw---- */\n\n            list_add_strdup_multi(params,\n                                  \"-rfbunixpath\", port,\n                                  \"-rfbunixmode\", sock_mode,\n                                  \"-SecurityTypes\", \"None\",\n                                  LIST_ADD_STRDUP_TERM);\n        }\n\n        /* additional parameters from sesman.ini file */\n        //config_read_xserver_params(SCP_SESSION_TYPE_XVNC,\n        //                           xserver_params);\n        list_append_list_strdup(g_cfg->vnc_params, params, 1);\n    }\n    return params;\n}\n\n/******************************************************************************/\n/* Either execs the X server, or returns */\nstatic void\nstart_x_server(const struct login_info *login_info,\n               const struct session_data *sd,\n               void *closure /* unused */)\n{\n    char authfile[256]; /* The filename for storing xauth information */\n    char execvpparams[2048];\n    char *passwd_file = NULL;\n    struct list *xserver_params = NULL;\n    int unknown_session_type = 0;\n    const struct session_parameters *sp = &sd->params;\n\n    env_set_user(login_info->uid,\n                 g_cfg->env_names,\n                 g_cfg->env_values);\n\n    /* Allocate the passwd_file if required */\n    if (sp->type == SCP_SESSION_TYPE_XVNC &&\n            (passwd_file = get_xvnc_passwd_file_name(sp->x11_display)) == NULL)\n    {\n        /* An error has been logged */\n        return;\n    }\n\n    /* prepare the Xauthority stuff */\n    if (g_getenv(\"XAUTHORITY\") != NULL)\n    {\n        g_snprintf(authfile, sizeof(authfile), \"%s\",\n                   g_getenv(\"XAUTHORITY\"));\n    }\n    else\n    {\n        g_snprintf(authfile, sizeof(authfile), \"%s\", \".Xauthority\");\n    }\n\n    /* Add the entry in XAUTHORITY file or exit if error */\n    if (sp->x11_display >= 0 &&\n            add_xauth_cookie(sp->x11_display, authfile) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Error setting the xauth cookie for display %s in file %s\",\n            sd->display, authfile);\n    }\n    else\n    {\n        switch (sp->type)\n        {\n                char guid_str[GUID_STR_SIZE];\n                char port[256];\n\n            case SCP_SESSION_TYPE_XORG:\n                xserver_params = prepare_xorg_xserver_params(sd, authfile);\n                break;\n\n            case SCP_SESSION_TYPE_XVNC:\n                guid_to_str(&sp->guid, guid_str);\n                set_xvnc_passwd(passwd_file, guid_str);\n                xserver_params = prepare_xvnc_xserver_params(sd, authfile,\n                                 passwd_file, NULL);\n                break;\n\n            case SCP_SESSION_TYPE_XVNC_UDS:\n                g_snprintf(port, sizeof(port), XRDP_X11RDP_STR,\n                           login_info->uid, sd->display);\n                xserver_params = prepare_xvnc_xserver_params(sd, authfile,\n                                 NULL, port);\n                break;\n\n            default:\n                unknown_session_type = 1;\n        }\n\n        if (xserver_params == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Out of memory allocating X server params\");\n        }\n        else if (unknown_session_type)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Unknown session type: %d\",\n                sp->type);\n        }\n        else\n        {\n            /* fire up X server */\n            LOG(LOG_LEVEL_INFO, \"Starting X server on display %s: %s\",\n                sd->display,\n                dumpItemsToString(xserver_params, execvpparams, 2048));\n            LOG_DEVEL_LEAKING_FDS(\"X server\", 3, -1);\n            g_execvp_list((const char *)xserver_params->items[0],\n                          xserver_params);\n        }\n    }\n\n    /* should not get here */\n    g_free(passwd_file);\n    list_delete(xserver_params);\n    LOG(LOG_LEVEL_ERROR, \"A fatal error has occurred attempting \"\n        \"to start the X server on display %s, aborting connection\",\n        sd->display);\n}\n\n/******************************************************************************/\n/*\n * Simple helper process to fork a child and log errors */\nstatic int\nfork_child(\n    void (*runproc)(const struct login_info *,\n                    const struct session_data *,\n                    void *closure),\n    const struct login_info *login_info,\n    const struct session_data *sd,\n    pid_t group_pid,\n    void *closure)\n{\n    int pid = g_fork();\n    if (pid == 0)\n    {\n        /* Child process */\n        if (group_pid >= 0)\n        {\n            (void)g_setpgid(0, group_pid);\n        }\n        runproc(login_info, sd, closure);\n        g_exit(0);\n    }\n\n    if (pid < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Fork failed [%s]\", g_get_strerror());\n    }\n\n    return pid;\n}\n\n/******************************************************************************/\nstatic int\nprocess_startup_wait_time(struct session_data *sd)\n{\n    int rv = 0;\n    int robjs_count;\n    intptr_t robjs[10];\n    unsigned int start = g_get_elapsed_ms();\n\n    LOG(LOG_LEVEL_INFO, \"Waiting for %u ms for session to start\",\n        g_cfg->sess.startup_wait_time);\n    while (1)\n    {\n        unsigned int elapsed = g_get_elapsed_ms() - start;\n        if (elapsed >= g_cfg->sess.startup_wait_time)\n        {\n            break;\n        }\n\n        robjs_count = 0;\n        robjs[robjs_count++] = g_term_event;\n        robjs[robjs_count++] = g_sigchld_event;\n\n        if (g_obj_wait(robjs, robjs_count, NULL, 0,\n                       g_cfg->sess.startup_wait_time - elapsed) != 0)\n        {\n            /* should not get here */\n            LOG(LOG_LEVEL_WARNING, \"process_startup_wait_time: \"\n                \"Unexpected error from g_obj_wait()\");\n            g_sleep(100);\n            continue;\n        }\n\n        if (g_is_wait_obj_set(g_term_event)) /* term */\n        {\n            // Simulate success for now, but leave g_term_event set. The\n            // main loop will also pick up the terminate event and the\n            // session will be closed normally\n            break;\n        }\n\n        if (g_is_wait_obj_set(g_sigchld_event)) /* SIGCHLD */\n        {\n            g_reset_wait_obj(g_sigchld_event);\n            session_process_sigchld_event(sd);\n            if (sd->win_mgr < 0)\n            {\n                // Session has failed in the StartupWaitTime\n                // Wait for the rest of the session to finish\n                rv = 1;\n                session_send_term(sd, 1);\n                break;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic enum scp_screate_status\nsession_start_wrapped(struct login_info *login_info,\n                      const struct session_parameters *s,\n                      struct session_data *sd)\n{\n    int chansrv_pid;\n    int display_pid;\n    int window_manager_pid;\n    enum scp_screate_status status = E_SCP_SCREATE_GENERAL_ERROR;\n\n    /* Set the secondary groups before starting the session to prevent\n     * problems on PAM-based systems (see Linux pam_setcred(3)).\n     * If we have *BSD setusercontext() this is not done here */\n#ifndef HAVE_SETUSERCONTEXT\n    if (g_initgroups(login_info->username) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Failed to initialise secondary groups for %s: %s\",\n            login_info->username, g_get_strerror());\n        return E_SCP_SCREATE_GENERAL_ERROR;\n    }\n#endif\n\n    if (auth_start_session(login_info->auth_info, sd->display) != 0)\n    {\n        // Errors are logged by the auth module, as they are\n        // specific to that module\n        return E_SCP_SCREATE_GENERAL_ERROR;\n    }\n#ifdef USE_BSD_SETLOGIN\n    /**\n     * Create a new session and process group since the 4.4BSD\n     * setlogin() affects the entire process group\n     */\n    if (g_setsid() < 0)\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"[session start] (display %s): setsid failed - pid %d\",\n            sd->display, g_getpid());\n    }\n\n    if (g_setlogin(login_info->username) < 0)\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"[session start] (display %s): setlogin failed for user %s - pid %d\",\n            sd->display, login_info->username, g_getpid());\n    }\n#endif\n\n    /* start the X server in a new process group.\n     *\n     * We group the X server, window manager and chansrv in a single\n     * process group, as it allows signals to be sent to the user session\n     * without affecting sesexec (and vice-versa). This is particularly\n     * important when debugging sesexec as we don't want a SIGINT in\n     * the debugger to be passed to the children */\n    display_pid = fork_child(start_x_server, login_info, sd, 0, NULL);\n    if (display_pid > 0)\n    {\n        enum xwait_status xws;\n        xws = wait_for_xserver(login_info->uid,\n                               g_cfg->env_names,\n                               g_cfg->env_values,\n                               s->x11_display);\n\n        if (xws != XW_STATUS_OK)\n        {\n            switch (xws)\n            {\n                case XW_STATUS_TIMED_OUT:\n                    LOG(LOG_LEVEL_ERROR, \"Timed out waiting for X server\");\n                    break;\n                case XW_STATUS_FAILED_TO_START:\n                    LOG(LOG_LEVEL_ERROR, \"X server failed to start\");\n                    break;\n                default:\n                    LOG(LOG_LEVEL_ERROR,\n                        \"An error occurred waiting for the X server\");\n            }\n            status = E_SCP_SCREATE_X_SERVER_FAIL;\n            /* Kill it anyway in case it did start and we just failed to\n             * pick up on it */\n            g_sigterm(display_pid);\n            g_waitpid(display_pid);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_INFO, \"Display %s is working\", sd->display);\n            LOG(LOG_LEVEL_INFO, \"Starting window manager for display %s\",\n                sd->display);\n\n            window_manager_pid = fork_child(start_window_manager,\n                                            login_info, sd, display_pid, NULL);\n            if (window_manager_pid < 0)\n            {\n                g_sigterm(display_pid);\n                g_waitpid(display_pid);\n            }\n            else\n            {\n                utmp_login(window_manager_pid, sd->display, login_info);\n                LOG(LOG_LEVEL_INFO,\n                    \"Starting the xrdp channel server for display %s\",\n                    sd->display);\n\n                chansrv_pid = fork_child(start_chansrv, login_info,\n                                         sd, display_pid, NULL);\n\n                sd->win_mgr = window_manager_pid;\n                sd->x_server = display_pid;\n                sd->chansrv = chansrv_pid;\n                sd->start_time = time(NULL);\n\n                if (process_startup_wait_time(sd) == 0)\n                {\n                    // Tell the caller we've started\n                    LOG(LOG_LEVEL_INFO,\n                        \"Session in progress on display %s. Waiting until the \"\n                        \"window manager (pid %d) exits to end the session\",\n                        sd->display, window_manager_pid);\n\n                    status = E_SCP_SCREATE_OK;\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Session failed during startup wait time\");\n                    status = E_SCP_SCREATE_SESSION_FAIL;\n                }\n            }\n        }\n    }\n\n    return status;\n}\n\n\n/******************************************************************************/\nenum scp_screate_status\nsession_start(struct login_info *login_info,\n              const struct session_parameters *sp,\n              struct session_data **session_data)\n{\n    enum scp_screate_status status = E_SCP_SCREATE_OK;\n\n    /* Create the session_data struct first */\n    struct session_data *sd = session_data_new(sp);\n    if (sd == NULL)\n    {\n        status = E_SCP_SCREATE_NO_MEMORY;\n    }\n    else\n    {\n        if (sp->x11_display >= 0)\n        {\n            /* Initialise the display name for logging purposes */\n            g_get_display_string_from_x11_display(sp->x11_display,\n                                                  sd->display,\n                                                  MAX_DISPLAY_NAME_SIZE);\n            /* Add the DISPLAY to the list of environment variables we\n             * set for all the sub-processes */\n            char displayname[32];\n            snprintf(displayname, sizeof(displayname), \":%d\",\n                     sp->x11_display);\n\n            if (!list_add_strdup(g_cfg->env_names, \"DISPLAY\") ||\n                    !list_add_strdup(g_cfg->env_values, displayname))\n            {\n                session_data_free(sd);\n                status = E_SCP_SCREATE_NO_MEMORY;\n            }\n        }\n\n        if (status == E_SCP_SCREATE_OK)\n        {\n            status = session_start_wrapped(login_info, sp, sd);\n            if (status == E_SCP_SCREATE_OK)\n            {\n                *session_data = sd;\n            }\n            else\n            {\n                *session_data = NULL;\n                session_data_free(sd);\n            }\n        }\n    }\n\n    return status;\n}\n\n/******************************************************************************/\nstatic int\ncleanup_sockets(struct session_data *sd)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"cleanup_sockets:\");\n\n    char file[XRDP_SOCKETS_MAXPATH];\n    int error = 0;\n\n    int uid = g_login_info->uid;\n\n    g_snprintf(file, sizeof(file), CHANSRV_PORT_OUT_STR, uid, sd->display);\n    if (g_file_exist(file))\n    {\n        LOG(LOG_LEVEL_DEBUG, \"cleanup_sockets: deleting %s\", file);\n        if (g_file_delete(file) == 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"cleanup_sockets: failed to delete %s (%s)\",\n                file, g_get_strerror());\n            error++;\n        }\n    }\n\n    g_snprintf(file, sizeof(file), CHANSRV_PORT_IN_STR, uid, sd->display);\n    if (g_file_exist(file))\n    {\n        LOG(LOG_LEVEL_DEBUG, \"cleanup_sockets: deleting %s\", file);\n        if (g_file_delete(file) == 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"cleanup_sockets: failed to delete %s (%s)\",\n                file, g_get_strerror());\n            error++;\n        }\n    }\n\n    g_snprintf(file, sizeof(file), XRDP_CHANSRV_STR, uid, sd->display);\n    if (g_file_exist(file))\n    {\n        LOG(LOG_LEVEL_DEBUG, \"cleanup_sockets: deleting %s\", file);\n        if (g_file_delete(file) == 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"cleanup_sockets: failed to delete %s (%s)\",\n                file, g_get_strerror());\n            error++;\n        }\n    }\n\n    g_snprintf(file, sizeof(file), CHANSRV_API_STR, uid, sd->display);\n    if (g_file_exist(file))\n    {\n        LOG(LOG_LEVEL_DEBUG, \"cleanup_sockets: deleting %s\", file);\n        if (g_file_delete(file) == 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"cleanup_sockets: failed to delete %s (%s)\",\n                file, g_get_strerror());\n            error++;\n        }\n    }\n\n    /* the following files should be deleted by xorgxrdp\n     * but just in case the deletion failed */\n\n    g_snprintf(file, sizeof(file), XRDP_X11RDP_STR, uid, sd->display);\n    if (g_file_exist(file))\n    {\n        LOG(LOG_LEVEL_DEBUG, \"cleanup_sockets: deleting %s\", file);\n        if (g_file_delete(file) == 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"cleanup_sockets: failed to delete %s (%s)\",\n                file, g_get_strerror());\n            error++;\n        }\n    }\n\n    g_snprintf(file, sizeof(file), XRDP_DISCONNECT_STR, uid, sd->display);\n    if (g_file_exist(file))\n    {\n        LOG(LOG_LEVEL_DEBUG, \"cleanup_sockets: deleting %s\", file);\n        if (g_file_delete(file) == 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"cleanup_sockets: failed to delete %s (%s)\",\n                file, g_get_strerror());\n            error++;\n        }\n    }\n\n    return error;\n}\n\n/******************************************************************************/\nstatic void\nexit_status_to_str(const struct proc_exit_status *e, char buff[], int bufflen)\n{\n    switch (e->reason)\n    {\n        case E_PXR_STATUS_CODE:\n            if (e->val == 0)\n            {\n                g_snprintf(buff, bufflen, \"exit code zero\");\n            }\n            else\n            {\n                g_snprintf(buff, bufflen, \"non-zero exit code %d\", e->val);\n            }\n            break;\n\n        case E_PXR_SIGNAL:\n        {\n            char sigstr[MAXSTRSIGLEN];\n            g_snprintf(buff, bufflen, \"signal %s\",\n                       g_sig2text(e->val, sigstr));\n        }\n        break;\n\n        default:\n            g_snprintf(buff, bufflen, \"an unexpected error\");\n            break;\n    }\n}\n\n/******************************************************************************/\n/**\n * Processes an exited child\n *\n * The PID of the child process is removed from the session_data.\n *\n * @param sd session_data for this session\n * @param pid PID of exited process\n * @param e Exit status of the exited process\n */\nstatic void\nprocess_child_exit(struct session_data *sd,\n                   int pid,\n                   const struct proc_exit_status *e)\n{\n    if (pid == sd->x_server)\n    {\n        LOG(LOG_LEVEL_INFO, \"X server pid %d on display %s finished\",\n            sd->x_server, sd->display);\n        sd->x_server = -1;\n        // No other action - window manager should be going soon\n    }\n    else if (pid == sd->chansrv)\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"xrdp channel server pid %d on display %s finished\",\n            sd->chansrv, sd->display);\n        sd->chansrv = -1;\n    }\n    else if (pid == sd->win_mgr)\n    {\n        int wm_wait_time = time(NULL) - sd->start_time;\n\n        if (e->reason == E_PXR_STATUS_CODE && e->val == 0)\n        {\n            LOG(LOG_LEVEL_INFO,\n                \"Window manager (pid %d, display %s) \"\n                \"finished normally in %d secs\",\n                sd->win_mgr, sd->display, wm_wait_time);\n        }\n        else\n        {\n            char reason[128];\n            exit_status_to_str(e, reason, sizeof(reason));\n\n            LOG(LOG_LEVEL_WARNING, \"Window manager (pid %d, display %s) \"\n                \"exited with %s. This \"\n                \"could indicate a window manager config problem\",\n                sd->win_mgr, sd->display, reason);\n        }\n        if (wm_wait_time < 10)\n        {\n            /* This could be a config issue. Log a significant error */\n            LOG(LOG_LEVEL_WARNING, \"Window manager (pid %d, display %s) \"\n                \"exited quickly (%d secs). This could indicate a window \"\n                \"manager config problem\",\n                sd->win_mgr, sd->display, wm_wait_time);\n        }\n\n        utmp_logout(sd->win_mgr, sd->display, e);\n        sd->win_mgr = -1;\n\n        if (sd->x_server > 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"Terminating X server (pid %d) on display %s\",\n                sd->x_server, sd->display);\n            g_sigterm(sd->x_server);\n        }\n\n        if (sd->chansrv > 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"Terminating the xrdp channel server (pid %d) \"\n                \"on display %s\", sd->chansrv, sd->display);\n            g_sigterm(sd->chansrv);\n        }\n    }\n\n    if (!session_active(sd))\n    {\n        cleanup_sockets(sd);\n    }\n}\n\n/******************************************************************************/\nvoid\nsession_process_sigchld_event(struct session_data *sd)\n{\n    struct proc_exit_status e;\n    int pid;\n\n    // Check for any finished children\n    while ((pid = g_waitchild(&e)) > 0)\n    {\n        process_child_exit(sd, pid, &e);\n    }\n}\n\n/******************************************************************************/\nunsigned int\nsession_active(const struct session_data *sd)\n{\n    return\n        (sd == NULL)\n        ? 0\n        : (sd->win_mgr > 0) + (sd->x_server > 0) + (sd->chansrv > 0);\n}\n\n/******************************************************************************/\ntime_t\nsession_get_start_time(const struct session_data *sd)\n{\n    return (sd == NULL) ? 0 : sd->start_time;\n}\n\n/******************************************************************************/\nunsigned int\nsession_get_connect_count(const struct session_data *sd)\n{\n    return (sd == NULL) ? 0 : sd->connect_count;\n}\n\n/******************************************************************************/\nconst char *\nsession_get_display(const struct session_data *sd)\n{\n    return (sd == NULL) ? \"\" : sd->display;\n}\n\n/******************************************************************************/\nunsigned int\nsession_increment_connect_count(struct session_data *sd)\n{\n    return (sd == NULL) ? 0 : sd->connect_count++;\n}\n\n/******************************************************************************/\nconst struct session_parameters *\nsession_get_parameters(const struct session_data *sd)\n{\n    return (sd == NULL) ? NULL : &sd->params;\n}\n\n/******************************************************************************/\nvoid\nsession_send_term(struct session_data *sd, int wait_for_all)\n{\n    if (sd != NULL)\n    {\n        if (sd->win_mgr > 0)\n        {\n            // Killing the window manager only is appropriate here.\n            // When we process SIGCHLD for the window manager, we\n            // will kill other processes as appropriate\n            g_sigterm(sd->win_mgr);\n        }\n\n        if (wait_for_all)\n        {\n            while (session_active(sd))\n            {\n                /* Don't check SIGTERM - we shouldn't be here long */\n                if (g_obj_wait(&g_sigchld_event, 1, NULL, 0, -1) != 0)\n                {\n                    /* should not get here */\n                    LOG(LOG_LEVEL_WARNING, \"session_send_term: \"\n                        \"Unexpected error from g_obj_wait()\");\n                    g_sleep(100);\n                }\n                else\n                {\n                    g_reset_wait_obj(g_sigchld_event);\n                    session_process_sigchld_event(sd);\n                }\n            }\n        }\n    }\n}\n\n/******************************************************************************/\nstatic void\nstart_reconnect_script(const struct login_info *login_info,\n                       const struct session_data *sd,\n                       void *closure)\n{\n    env_set_user(login_info->uid,\n                 g_cfg->env_names,\n                 g_cfg->env_values);\n\n    auth_set_env(login_info->auth_info);\n\n    if (g_file_exist(g_cfg->reconnect_sh))\n    {\n        /* The 'closure' parameter points to a list of strings\n         * which need to be set in the environment for the reconnect script */\n        if (closure != NULL)\n        {\n            const char **p = (const char **)closure;\n            while (*p != NULL && *(p + 1) != NULL)\n            {\n                (void)g_setenv(*p, *(p + 1), 1);\n                p += 2;\n            }\n        }\n        LOG_DEVEL_LEAKING_FDS(\"reconnect script\", 3, -1);\n\n        LOG(LOG_LEVEL_INFO,\n            \"Starting session reconnection script on display %s: %s\",\n            sd->display, g_cfg->reconnect_sh);\n        g_execlp3(g_cfg->reconnect_sh, g_cfg->reconnect_sh, 0);\n\n        /* should not get here */\n        LOG(LOG_LEVEL_ERROR,\n            \"Error starting session reconnection script on display %s: %s\",\n            sd->display, g_cfg->reconnect_sh);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"Session reconnection script file does not exist: %s\",\n            g_cfg->reconnect_sh);\n    }\n}\n\n/******************************************************************************/\nvoid\nsession_run_reconnect_script(const struct login_info *login_info,\n                             const struct session_data *sd,\n                             const char *vars[])\n{\n    if (fork_child(start_reconnect_script,\n                   login_info, sd, sd->x_server, (void *)vars) < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Failed to fork for session reconnection script\");\n    }\n}\n\n/******************************************************************************/\nint\nsession_get_display_server_fd(const struct login_info *login_info,\n                              const struct session_data *sd)\n{\n    char portname[XRDP_SOCKETS_MAXPATH];\n    const char *localhost = \"localhost\"; // Ignored for TRANS_MODE_UNIX\n    int socket_mode;\n\n    int rv = -1;\n\n    if (sd->x_server <= 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Request to connect to display server %s\"\n            \" which has exited\", sd->display);\n    }\n    else\n    {\n        switch (sd->params.type)\n        {\n            case SCP_SESSION_TYPE_XVNC:\n                socket_mode = TRANS_MODE_TCP;\n                snprintf(portname, sizeof(portname), \"%d\",\n                         5900 + sd->params.x11_display);\n                break;\n\n            case SCP_SESSION_TYPE_XVNC_UDS:\n            case SCP_SESSION_TYPE_XORG:\n                socket_mode = TRANS_MODE_UNIX;\n                snprintf(portname, sizeof(portname), XRDP_X11RDP_STR,\n                         login_info->uid, sd->display);\n\n                break;\n\n            default:\n                LOG(LOG_LEVEL_ERROR, \"Unsupported session type %d for connect\",\n                    sd->params.type);\n                portname[0] = '\\0';\n        }\n\n        if (portname[0] != '\\0')\n        {\n            // Use the transport library to get the fd\n            struct trans *t = trans_create(socket_mode, 8 * 8192, 8192);\n            if (t == NULL)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Out of memory creating transport\");\n            }\n            else if (trans_connect(t, localhost, portname, 3000) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Can't connect to display server %s [%s]\",\n                    sd->display,\n                    g_get_strerror());\n            }\n            else\n            {\n                rv = t->sck;\n                t->sck = -1;\n            }\n            trans_delete(t);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nsession_get_chansrv_fd(const struct login_info *login_info,\n                       const struct session_data *sd)\n{\n    char portname[XRDP_SOCKETS_MAXPATH];\n\n    int rv = -1;\n\n    if (sd->chansrv <= 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Request to connect to chansrv %s\"\n            \" which has exited\", sd->display);\n    }\n    else\n    {\n        snprintf(portname, sizeof(portname),\n                 XRDP_CHANSRV_STR, login_info->uid, sd->display);\n\n        // Use the transport library to get the fd\n        struct trans *t = trans_create(TRANS_MODE_UNIX, 8192, 8192);\n        if (t == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Out of memory creating transport\");\n        }\n        else if (trans_connect(t, NULL, portname, 10 * 1000) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't connect to chansrv %s [%s]\",\n                sd->display,\n                g_get_strerror());\n        }\n        else\n        {\n            rv = t->sck;\n            t->sck = -1;\n        }\n        trans_delete(t);\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "sesman/sesexec/session.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file session.h\n * @brief Session management definitions\n * @author Jay Sorg, Simone Fedele\n *\n */\n\n\n#ifndef SESSION_H\n#define SESSION_H\n\n#include <time.h>\n\n#include \"guid.h\"\n#include \"scp_application_types.h\"\n\nstruct login_info;\nstruct proc_exit_status;\n\n/**\n * Information used to start a session\n */\nstruct session_parameters\n{\n    int x11_display;   // >= 0 for X11 only\n    enum scp_session_type type;\n    unsigned short width;\n    unsigned short height;\n    unsigned char  bpp;\n    struct guid guid;\n    const char *shell;  // Must not be NULL\n    const char *directory;  // Must not be NULL\n    const char *instance_name;  //Must not be NULL\n};\n\n\n/**\n * Data involved in running a session (opaque type)\n *\n * Allocate with session_start() and free with\n * session_data_free() once session_active() returns zero.\n */\nstruct session_data;\n\n/**\n *\n * @brief starts a session\n *\n * @param login_info info for logged in user\n * @param s Session parameters\n * @param[out] session_data Pointer to session data for the session\n *\n * session_data is only set if E_SCP_CREATE_OK is returned\n * @return status\n */\nenum scp_screate_status\nsession_start(struct login_info *login_info,\n              const struct session_parameters *s,\n              struct session_data **session_data);\n\n/**\n * Processes a SIGCHLD event\n *\n * Any pending SIGCHLD events are processed.\n *\n * The PID of a failed child process is removed from the session_data.\n *\n * @param sd session_data for this session\n */\nvoid\nsession_process_sigchld_event(struct session_data *sd);\n\n/**\n * Returns a count of active processes in the session\n *\n * @param sd session_data for this session\n */\nunsigned int\nsession_active(const struct session_data *sd);\n\n/**\n * Returns the start time for an active session\n *\n * @param sd session_data for this session\n * @return session start time\n */\ntime_t\nsession_get_start_time(const struct session_data *sd);\n\n/**\n * Returns the connect count for an active session\n * @param sd session_data for this session\n * @return connect count\n */\nunsigned int\nsession_get_connect_count(const struct session_data *sd);\n\n/**\n * Get a pointer to the session display name\n *\n * @param self session_data object\n * @return session name (\"X11-n\" or \"wayland-n\")\n *\n * A session name is set by a successful call to session_start()\n */\nconst char *\nsession_get_display(const struct session_data *sd);\n\n/**\n * Increment the connect count for an active session\n * @param sd session_data for this session\n * @return Pre-increment value of the connect count\n */\nunsigned int\nsession_increment_connect_count(struct session_data *sd);\n\n/**\n * Returns the parameters used to start the session\n *\n * @param sd session_data for this session\n * @return Pointer to parameters\n *\n * The pointed-to data returned must not be modified in\n * any way.\n */\nconst struct session_parameters *\nsession_get_parameters(const struct session_data *sd);\n\n/***\n * Ask a session to terminate by signalling the window manager\n *\n * @param sd session_data for this session\n * @param wait_for_all != 0 to wait for all processes in the session\n *                     to terminate\n */\nvoid\nsession_send_term(struct session_data *sd, int wait_for_all);\n\n/**\n * Frees a session_data object\n *\n * @param session_data session_data for this session\n *\n * Do not call this until session_active() returns zero, or you\n * lose the ability to track the session PIDs\n */\nvoid\nsession_data_free(struct session_data *session_data);\n\n/**\n * Runs the reconnect script for the session\n * @param login_info Login info for the session\n * @param sd Session data for the session\n * @param vars environment variables for the reconnect script\n *\n * The vars parameter points to an array of strings in pairs. The\n * first string in the pair is the name of an environment variable to\n * set, and the second string is the value\n */\nvoid\nsession_run_reconnect_script(const struct login_info *login_info,\n                             const struct session_data *sd,\n                             const char *vars[]);\n\n/**\n * Connects a file descriptor to the display server\n */\nint\nsession_get_display_server_fd(const struct login_info *login_info,\n                              const struct session_data *sd);\n\n/**\n * Connects a file descriptor to chansrv\n */\nint\nsession_get_chansrv_fd(const struct login_info *login_info,\n                       const struct session_data *sd);\n\n#endif // SESSION_H\n"
  },
  {
    "path": "sesman/sesexec/sessionrecord.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Emmanuel Blindauer 2017\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * str2memcpy() is taken from util-linux/include/strutils.h v2.39 which\n * has the following header:-\n *\n *     No copyright is claimed.  This code is in the public domain; do with\n *     it what you wish.\n */\n\n/**\n *\n * @file sessionrecord.c\n * @brief utmp handling code\n *\n * wtmp/lastlog/btmp is handled by PAM or (on FreeBSD) UTX\n *\n * Idea: Only implement actual utmp, i.e. utmpx for 99%.\n *       See http://80386.nl/unix/utmpx/\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <ctype.h>\n\n#include \"sessionrecord.h\"\n#include \"login_info.h\"\n#include \"log.h\"\n\n// Operational mode of add_xtmp_entry()\n//\n// We can't use USER_PROCESS/DEAD_PROCESS directly, as they\n// won't be available for platforms without USE_UTMP\nenum add_xtmp_mode\n{\n    MODE_LOGIN,\n    MODE_LOGOUT\n};\n\n#ifdef USE_UTMP\n\n#include <sys/time.h>\n#include <string.h>\n#include <unistd.h>\n\n#ifdef HAVE_UTMPX_H\n#include <utmpx.h>\ntypedef struct utmpx _utmp;\n#else\n#include <utmp.h>\ntypedef struct utmp _utmp;\n#endif\n\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n#define XRDP_LINE_FORMAT \"xrdp:%s\"\n// ut_id is a very small field on some platforms, so use a discriminator\n// (e.g. ':' for x11) and a number in hex\n#define XRDP_ID_FORMAT \"%c%x\"\n\n/******************************************************************************/\n/**\n * utmp-specific strncpy() replacement\n *\n * @param dest Destination pointer\n * @param src Source pointer\n * @param n bytes to copy\n *\n * This is like strncpy(), but based on memcpy(), so compilers and static\n * analyzers do not complain when sizeof(destination) is the same as 'n' and\n * result is not terminated by zero.\n *\n *  ONLY use this function to copy string to logs with fixed sizes\n *  (wtmp/utmp. ...)  where string terminator is optional.\n */\nstatic inline void *__attribute__((nonnull (1)))\nstr2memcpy(void *dest, const char *src, size_t n)\n{\n    size_t bytes = strlen(src) + 1;\n\n    if (bytes > n)\n    {\n        bytes = n;\n    }\n\n    memcpy(dest, src, bytes);\n    return dest;\n}\n\n/******************************************************************************/\n/**\n * Set the idbuff string\n *\n * The ut_id field is extremely short (e.g. 4 usable characters on\n * Linux/FreeBSD).\n *\n * @param buff Output buffer, including terminator\n * @param bufflen Length of above\n * @param display Display string for the session\n */\nstatic void\nset_idbuff_str(char buff[], unsigned int bufflen, const char *display)\n{\n    unsigned int display_num = 0;\n    char discriminator;\n\n    // X11 display?\n    int x11_display = g_get_x11_display_from_display_string(display);\n    if (x11_display >= 0)\n    {\n        discriminator = ':';\n        display_num = (unsigned int)x11_display;\n    }\n    else\n    {\n        discriminator = 'W';\n        /* Look for the first digit in the string */\n        while (*display != '\\0' && !isdigit(*display))\n        {\n            ++display;\n        }\n        /* convert consecutive digits to a number */\n        display_num = 0;\n        while (*display != '\\0' && isdigit(*display))\n        {\n            display_num = (display_num * 10) + (*display - '0');\n            ++display;\n        }\n    }\n    display_num = MIN(display_num, 0xfff);\n    g_snprintf(buff, bufflen, XRDP_ID_FORMAT, discriminator, display_num);\n}\n\n/******************************************************************************/\n/**\n * Prepare the utmp struct and write it.\n *\n * @param pid PID of session manager\n * @param display Display number of session\n * @param login_info Login info (NULL for MODE_LOGOUT)\n * @param mode see enum add_xtmp_mode\n * @param e Exit status (NULL unless MODE_LOGOUT)\n */\n\nstatic void\nadd_xtmp_entry(int pid, const char *display,\n               const struct login_info *login_info,\n               enum add_xtmp_mode mode, const struct proc_exit_status *e)\n{\n    _utmp ut;\n    /* For some string fields, use a formatting buffer one character larger\n     * than the eventual destination. This lets us use normal string\n     * functions to create the strings, and the terminator can then\n     * be omitted (if necessary) when filling in 'ut' */\n    char idbuff[sizeof(ut.ut_id) + 1];\n    char linebuff[sizeof(ut.ut_line) + 1];\n\n    struct timeval tv;\n\n    g_memset(&ut, 0, sizeof(ut));\n    set_idbuff_str(idbuff, sizeof(idbuff), display);\n    g_snprintf(linebuff, sizeof(linebuff), XRDP_LINE_FORMAT, display);\n    gettimeofday(&tv, NULL);\n\n    ut.ut_type = (mode == MODE_LOGIN) ? USER_PROCESS : DEAD_PROCESS;\n    ut.ut_pid = pid;\n    str2memcpy(ut.ut_id, idbuff, sizeof(ut.ut_id));\n\n    // Linux utmp(5) suggests ut_line, ut_time, ut_user, and ut_host\n    // are not set for a DEAD_PROCESS\n    if (ut.ut_type != DEAD_PROCESS)\n    {\n        ut.ut_tv.tv_sec = tv.tv_sec;\n        ut.ut_tv.tv_usec = tv.tv_usec;\n        str2memcpy(ut.ut_line, linebuff, sizeof(ut.ut_line));\n        if (login_info != NULL)\n        {\n            str2memcpy(ut.ut_user, login_info->username, sizeof(ut.ut_user));\n#ifdef HAVE_UTMPX_UT_HOST\n            str2memcpy(ut.ut_host, login_info->ip_addr, sizeof(ut.ut_host));\n#endif\n        }\n    }\n\n#ifdef HAVE_UTMPX_UT_EXIT\n    if (e != NULL && e->reason == E_PXR_STATUS_CODE)\n    {\n        ut.ut_exit.e_exit = e->val;\n    }\n    else if (e != NULL && e->reason == E_PXR_SIGNAL)\n    {\n        ut.ut_exit.e_termination = e->val;\n    }\n#endif\n\n    /* update the utmp file */\n    /* open utmp */\n    setutxent();\n    /* add the computed entry */\n    pututxline(&ut);\n    /* closes utmp */\n    endutxent();\n\n}\n#else // USE_UTMP\nstatic void\nadd_xtmp_entry(int pid, const char *display,\n               const struct login_info *login_info,\n               short state, const struct proc_exit_status *e)\n{\n}\n#endif\n\n\n/******************************************************************************/\nvoid\nutmp_login(int pid, const char *display,\n           const struct login_info *login_info)\n{\n    log_message(LOG_LEVEL_DEBUG,\n                \"adding login info for utmp: %d - %s - %s - %s\",\n                pid, display, login_info->username, login_info->ip_addr);\n\n    add_xtmp_entry(pid, display, login_info, MODE_LOGIN, NULL);\n}\n\n/******************************************************************************/\nvoid\nutmp_logout(int pid, const char *display,\n            const struct proc_exit_status *exit_status)\n{\n\n    log_message(LOG_LEVEL_DEBUG, \"adding logout info for utmp: %d - %s\",\n                pid, display);\n\n    add_xtmp_entry(pid, display, NULL, MODE_LOGOUT, exit_status);\n}\n"
  },
  {
    "path": "sesman/sesexec/sessionrecord.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Emmanuel Blindauer 2017\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sessionrecord.h\n * @brief utmp handling code\n *\n */\n\n#ifndef SESSIONRECORD_H\n#define SESSIONRECORD_H\n\nstruct login_info;\nstruct proc_exit_status;\n\n/**\n * @brief Record login in utmp\n *\n * @param pid PID of window manager\n * @param display Display description\n * @param login_info Information about logged in user\n */\nvoid\nutmp_login(int pid, const char *display,\n           const struct login_info *login_info);\n\n/**\n * @brief Record logout in utmp\n *\n * @param pid PID of window manager\n * @param display Display description\n * @param exit_status Exit status of process\n */\nvoid\nutmp_logout(int pid, const char *display,\n            const struct proc_exit_status *exit_status);\n\n#endif\n"
  },
  {
    "path": "sesman/sesexec/xauth.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Emmanuel Blindauer 2016\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file xauth.c\n * @brief XAUTHORITY handling code\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include \"xauth.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n\n/******************************************************************************/\nint\nadd_xauth_cookie(int display, const char *file)\n{\n    FILE *dp;\n    char cookie_str[33];\n    char cookie_bin[16];\n    char xauth_str[256];\n    int ret;\n\n    g_random(cookie_bin, 16);\n    g_bytes_to_hexstr(cookie_bin, 16, cookie_str, 33);\n\n    g_sprintf(xauth_str, \"xauth -q -f %s add :%d . %s\",\n              file, display, cookie_str);\n\n    dp = popen(xauth_str, \"r\");\n    if (dp == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unable to launch xauth\");\n        return 1;\n    }\n\n    ret = pclose(dp);\n    if (ret < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"An error occurred while running xauth\");\n        return 1;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "sesman/sesexec/xauth.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Emmanuel Blindauer 2016\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file xauth.c\n * @brief XAUTHORITY handling code\n *\n */\n\n#ifndef XAUTH_H\n#define XAUTH_H\n\n/**\n *\n * @brief create the XAUTHORITY file for the user according to the display and the cookie\n *        xauth uses XAUTHORITY if defined, ~/.Xauthority otherwise\n * @param display The session display\n * @param file If not NULL, write the authorization in the file instead of default location\n * @return 0 if adding the cookie is ok\n */\n\nint\nadd_xauth_cookie(int display, const char *file);\n\n#endif\n"
  },
  {
    "path": "sesman/sesexec/xwait.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"env.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"xwait.h\"\n\n#include <stdio.h>\n#include <string.h>\n\n/******************************************************************************/\nstatic void\nlog_waitforx_messages(FILE *dp)\n{\n    char buffer[256];\n    while (fgets(buffer, sizeof(buffer), dp))\n    {\n        const char *msg = buffer;\n        enum logLevels level = LOG_LEVEL_ERROR;\n\n        g_strtrim(buffer, 2);\n\n        // Has the message got a class at the start?\n        if (strlen(buffer) > 3 && buffer[0] == '<' && buffer[2] == '>')\n        {\n            switch (buffer[1])\n            {\n                case 'D':\n                    level = LOG_LEVEL_DEBUG;\n                    break;\n                case 'I':\n                    level = LOG_LEVEL_INFO;\n                    break;\n                case 'W':\n                    level = LOG_LEVEL_WARNING;\n                    break;\n                default:\n                    level = LOG_LEVEL_ERROR;\n                    break;\n            }\n            msg = buffer + 3;\n        }\n\n        if (strlen(msg) > 0)\n        {\n            LOG(level, \"waitforx: %s\", msg);\n        }\n    }\n}\n\n/******************************************************************************/\n/**\n * Contruct the command to run to check the X server\n */\nstatic struct list *\nmake_xwait_command(int display)\n{\n    const char exe[] = XRDP_LIBEXEC_PATH \"/waitforx\";\n    char displaystr[64];\n\n    struct list *cmd = list_create();\n    if (cmd != NULL)\n    {\n        cmd->auto_free = 1;\n        g_snprintf(displaystr, sizeof(displaystr), \":%d\", display);\n\n        if (!list_add_strdup_multi(cmd, exe, \"-d\", displaystr,\n                                   LIST_ADD_STRDUP_TERM))\n        {\n            list_delete(cmd);\n            cmd = NULL;\n        }\n    }\n\n    return cmd;\n}\n\n/******************************************************************************/\nenum xwait_status\nwait_for_xserver(uid_t uid,\n                 struct list *env_names,\n                 struct list *env_values,\n                 int display)\n{\n    enum xwait_status rv = XW_STATUS_MISC_ERROR;\n    int fd[2] = {-1, -1};\n    struct list *cmd = make_xwait_command(display);\n\n\n    // Construct the command to execute to check the display\n    if (cmd == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't create xwait command list - no mem\");\n    }\n    else if (g_pipe(fd) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't create pipe : %s\", g_get_strerror());\n    }\n    else\n    {\n        pid_t pid = g_fork();\n        if (pid < 0)\n        {\n            // Error already logged\n        }\n        else if (pid == 0)\n        {\n            /* Child process */\n\n            /* Send stdout and stderr up the pipe */\n            g_file_close(fd[0]);\n            g_file_duplicate_on(fd[1], 1);\n            g_file_duplicate_on(fd[1], 2);\n\n            /* Move to the user context... */\n            env_set_user(uid,\n                         env_names,\n                         env_values);\n\n            /* ...and run the program */\n            g_execvp_list((const char *)cmd->items[0], cmd);\n            LOG(LOG_LEVEL_ERROR, \"Can't run %s - %s\",\n                (const char *)cmd->items[0], g_get_strerror());\n            g_exit(rv);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"Waiting for X server to start on display :%d\",\n                display);\n\n            g_file_close(fd[1]);\n            fd[1] = -1;\n            FILE *dp = fdopen(fd[0], \"r\");\n            if (dp == NULL)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Unable to launch waitforx\");\n            }\n            else\n            {\n                struct proc_exit_status e;\n\n                fd[0] = -1; // File descriptor closed by fclose()\n                log_waitforx_messages(dp);\n                fclose(dp);\n                e = g_waitpid_status(pid);\n                switch (e.reason)\n                {\n                    case E_PXR_STATUS_CODE:\n                        rv = (enum xwait_status)e.val;\n                        break;\n\n                    case E_PXR_SIGNAL:\n                    {\n                        char sigstr[MAXSTRSIGLEN];\n                        LOG(LOG_LEVEL_ERROR,\n                            \"waitforx failed with unexpected signal %s\",\n                            g_sig2text(e.val, sigstr));\n                    }\n                    break;\n\n                    default:\n                        LOG(LOG_LEVEL_ERROR,\n                            \"waitforx failed with unknown reason\");\n                }\n            }\n        }\n        if (fd[0] >= 0)\n        {\n            g_file_close(fd[0]);\n        }\n\n        if (fd[1] >= 0)\n        {\n            g_file_close(fd[1]);\n        }\n    }\n\n    list_delete(cmd);\n\n    return rv;\n}\n"
  },
  {
    "path": "sesman/sesexec/xwait.h",
    "content": "#ifndef XWAIT_H\n#define XWAIT_H\n\n#include <sys/types.h>\n\nenum xwait_status\n{\n    XW_STATUS_OK = 0,\n    XW_STATUS_MISC_ERROR,\n    XW_STATUS_TIMED_OUT,\n    XW_STATUS_FAILED_TO_START\n};\n\n/**\n *\n * @brief waits for X to start\n * @param uid User to run program under\n * @param env_names Environment to set for user (names)\n * @param env_values Environment to set for user (values)\n * @param display number\n * @return status\n *\n */\nenum xwait_status\nwait_for_xserver(uid_t uid,\n                 struct list *env_names,\n                 struct list *env_values,\n                 int display);\n#endif\n"
  },
  {
    "path": "sesman/sesexec_control.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) 2023 Matt Burt\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesexec_control.c\n * @brief Start/stop session executive process\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"sesman_config.h\"\n#include \"eicp.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"scp_list.h\"\n#include \"string_calls.h\"\n#include \"sesexec_control.h\"\n#include \"sesman.h\"\n#include \"trans.h\"\n#include \"xrdp_sockets.h\"\n\n#define SESEXEC_SHORTNAME \"xrdp-sesexec\"\n#define SESEXEC_LONGNAME XRDP_LIBEXEC_PATH \"/\" SESEXEC_SHORTNAME\n\n// Some platforms using setsid() benefit from sesexec being\n// forked again, so the UNIX session can be created cleanly\n// See FreeBSD bug\n//     ports/157282: effective login name is not set by xrdp-sesman\n//     https://www.freebsd.org/cgi/query-pr.cgi?pr=157282\n\n#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)\n#define USE_BSD_SETLOGIN 1\n#endif\n\n/*****************************************************************************/\n/**\n * Adds entries to the args list for running sesexec\n *\n * @param args Argument list\n * @return 0 for memory allocation failure, 1 for success\n */\nstatic int\ncreate_exec_args_add_entries(struct list *args)\n{\n    if (!list_add_strdup(args, SESEXEC_SHORTNAME))\n    {\n        return 0;\n    }\n\n    if (g_strcmp(g_cfg->sesman_ini, DEFAULT_SESMAN_INI) != 0)\n    {\n        if (!list_add_strdup_multi(args, \"-c\", g_cfg->sesman_ini,\n                                   LIST_ADD_STRDUP_TERM))\n        {\n            return 0;\n        }\n    }\n\n    return 1;\n}\n\n/*****************************************************************************/\n/**\n * Create an args list for sesexec\n * @return NULL if memory could not be allocated\n *\n * The result must be freed with list_delete() after use\n */\nstatic struct list *\ncreate_exec_args(void)\n{\n    struct list *result = list_create();\n    if (result != NULL)\n    {\n        result->auto_free = 1;\n        if (!create_exec_args_add_entries(result))\n        {\n            list_delete(result);\n            result = NULL;\n        }\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nint\nsesexec_start(struct scp_list_item *sli)\n{\n    // Local socket pair used to set up the EICP channel for sesexec\n    // We also use the socket pair to communicate the PID of sesexec back\n    // to sesman. Technically we only need this if USE_BSD_SETLOGIN\n    // is set, but removing this variable complicates the code so\n    // much it isn't worth it.\n    int sck[2] = {-1, -1};\n    int rv = -1;\n    int size;\n    const char *exe = SESEXEC_LONGNAME;\n    struct list *args = NULL;\n\n    if (!g_executable_exist(exe))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't execute %s\", exe);\n    }\n    else if ((args = create_exec_args()) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Out of memory running sesexec\");\n    }\n    else if (g_sck_local_socketpair(sck) < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't create sesexec EICP socket [%s]\",\n            g_get_strerror());\n    }\n    else\n    {\n        int pid = g_fork();\n        if (pid == -1)\n        {\n            // Error already logged\n            g_file_close(sck[0]);\n            g_file_close(sck[1]);\n        }\n        else if (pid == 0)\n        {\n            /* Sesexec process */\n            g_file_close(sck[0]);\n\n#if USE_BSD_SETLOGIN\n            if (g_fork() != 0)\n            {\n                g_exit(0);\n            }\n#endif\n            // Send our pid back to sesman\n            pid = g_getpid();\n            size = g_file_write(sck[1], (const char *)&pid, sizeof(pid));\n\n            if (size != sizeof(pid))\n            {\n                LOG(LOG_LEVEL_ERROR, \"Can't write to PID socket [%s]\",\n                    g_get_strerror());\n            }\n            else\n            {\n                /* Put the number of the file descriptor in EICP_FD\n                 * in the environment */\n                char buff[64];\n                g_snprintf(buff, sizeof(buff), \"%d\", sck[1]);\n                g_setenv_log(\"EICP_FD\", buff, 1);\n\n                /* [Development] Log all file descriptors not marked cloexec\n                 * other than stdin, stdout, stderr, and the EICP fd in sck[1].\n                 */\n                if (sck[1] < 3)\n                {\n                    // EICP fd has overwritten one of the standard descriptors\n                    LOG_DEVEL_LEAKING_FDS(\"xrdp-sesexec\", 3, -1);\n                }\n                else\n                {\n                    LOG_DEVEL_LEAKING_FDS(\"xrdp-sesexec\", 3, sck[1]);\n                    LOG_DEVEL_LEAKING_FDS(\"xrdp-sesexec\", sck[1] + 1, -1);\n                }\n\n                g_execvp_list(exe, args);\n\n                // Shouldn't get here. Errors are logged if we do.\n            }\n            g_exit(1);\n        }\n        else\n        {\n            g_file_close(sck[1]);\n\n            // Get the PID from the child (or the grancdchild)\n            int size = g_file_read(sck[0], (char *)&pid, sizeof(pid));\n\n            if (size != sizeof(pid))\n            {\n                LOG(LOG_LEVEL_ERROR, \"Can't read PID of sesexec process [%s]\",\n                    g_get_strerror());\n                g_file_close(sck[0]);\n            }\n            else\n            {\n                struct trans *t = eicp_init_trans_from_fd(sck[0],\n                                  TRANS_TYPE_CLIENT,\n                                  sesman_is_term);\n                if (t == NULL)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Can't create sesexec transport [%s]\",\n                        g_get_strerror());\n                    g_file_close(sck[0]);\n                }\n                else\n                {\n                    t->trans_data_in = sesman_eicp_data_in;\n                    t->callback_data = (void *)sli;\n                    sli->sesexec_trans = t;\n                    sli->sesexec_pid = pid;\n                    rv = 0;\n                }\n            }\n        }\n    }\n\n    list_delete(args);\n    return rv;\n}\n"
  },
  {
    "path": "sesman/sesexec_control.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) 2023 Matt Burt\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesexec_control.h\n * @brief Start/stop session executive process\n * @author Matt Burt\n *\n */\n\n\n#ifndef SESEXEC_H\n#define SESEXEC_H\n\n#include <sys/types.h>\n\nstruct trans;\nstruct scp_list_item;\n\n/**\n * Start a session executive\n * @param sli SCP list item to allocate EICP transport to\n * @result 0 for success\n *\n * If non-zero is returned, all errors have been logged.\n * If zero is returned, the sesexec_trans and sesexec_pid fields of\n * the SCP_list_item have been initialised.\n */\n\nint\nsesexec_start(struct scp_list_item *sli);\n\n#endif // SESEXEC_H\n"
  },
  {
    "path": "sesman/sesman.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesman.c\n * @brief Main program file\n * @author Jay Sorg\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdarg.h>\n\n#include \"arch.h\"\n#include \"sesman.h\"\n\n#include \"sesman_auth.h\"\n#include \"sesman_config.h\"\n#include \"eicp.h\"\n#include \"eicp_process.h\"\n#include \"ercp.h\"\n#include \"ercp_process.h\"\n#include \"scp_list.h\"\n#include \"session_list.h\"\n#include \"lock_uds.h\"\n#include \"os_calls.h\"\n#include \"scp.h\"\n#include \"scp_process.h\"\n#include \"sesexec_control.h\"\n#include \"sesman_restart.h\"\n#include \"sig.h\"\n#include \"string_calls.h\"\n#include \"trans.h\"\n#include \"xrdp_configure_options.h\"\n#include \"xrdp_sockets.h\"\n\n/**\n * Maximum number of SCP list items\n */\n#define MAX_SCP_LIST_ITEMS 16\n\n/**\n * Define the mode of operation of the program\n */\nenum sesman_mode\n{\n    SSM_NORMAL = 0,\n    SSM_KILL_DAEMON,\n    SSM_RELOAD_DAEMON\n};\n\nstruct sesman_startup_params\n{\n    const char *sesman_ini;\n    enum sesman_mode mode;\n    int no_daemon;\n    int help;\n    int version;\n    int dump_config;\n};\n\nstruct config_sesman *g_cfg;\ntintptr g_term_event = 0;\nstatic tintptr g_sigchld_event = 0;\nstatic tintptr g_reload_event = 0;\n\nstatic struct trans *g_list_trans;\n\n/* Variables used to lock g_list_trans */\nstatic struct lock_uds *g_list_trans_lock;\n\nstatic int g_pid;\n\n/*****************************************************************************/\n/**\n * @brief looks for a case-insensitive match of a string in a list\n * @param candidate  String to match\n * @param ... NULL-terminated list of strings to compare the candidate with\n * @return !=0 if the candidate is found in the list\n */\nstatic int nocase_matches(const char *candidate, ...)\n{\n    va_list vl;\n    const char *member;\n    int result = 0;\n\n    va_start(vl, candidate);\n    while ((member = va_arg(vl, const char *)) != NULL)\n    {\n        if (g_strcasecmp(candidate, member) == 0)\n        {\n            result = 1;\n            break;\n        }\n    }\n\n    va_end(vl);\n    return result;\n}\n\n/*****************************************************************************/\n/**\n *\n * @brief  Command line argument parser\n * @param[in] argc number of command line arguments\n * @param[in] argv pointer array of commandline arguments\n * @param[out] startup_params Returned startup parameters\n * @return 0 on success, n on nth argument is unknown\n *\n */\nstatic int\nsesman_process_params(int argc, char **argv,\n                      struct sesman_startup_params *startup_params)\n{\n    int index;\n    const char *option;\n    const char *value;\n\n    startup_params->mode = SSM_NORMAL;\n\n    index = 1;\n\n    while (index < argc)\n    {\n        option = argv[index];\n\n        if (index + 1 < argc)\n        {\n            value = argv[index + 1];\n        }\n        else\n        {\n            value = \"\";\n        }\n\n        if (nocase_matches(option, \"-help\", \"--help\", \"-h\", (const char *)0))\n        {\n            startup_params->help = 1;\n        }\n        else if (nocase_matches(option, \"-kill\", \"--kill\", \"-k\",\n                                (const char *)0))\n        {\n            startup_params->mode = SSM_KILL_DAEMON;\n        }\n        else if (nocase_matches(option, \"-reload\", \"--reload\", \"-r\", (const char *)0))\n        {\n            startup_params->mode = SSM_RELOAD_DAEMON;\n        }\n        else if (nocase_matches(option, \"-nodaemon\", \"--nodaemon\", \"-n\",\n                                \"-nd\", \"--nd\", \"-ns\", \"--ns\", (const char *)0))\n        {\n            startup_params->no_daemon = 1;\n        }\n        else if (nocase_matches(option, \"-v\", \"--version\", (const char *)0))\n        {\n            startup_params->version = 1;\n        }\n        else if (nocase_matches(option, \"--dump-config\", (const char *)0))\n        {\n            startup_params->dump_config = 1;\n        }\n        else if (nocase_matches(option, \"-c\", \"--config\", (const char *)0))\n        {\n            index++;\n            startup_params->sesman_ini = value;\n        }\n        else /* unknown option */\n        {\n            return index;\n        }\n\n        index++;\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int sesman_listen_test(struct config_sesman *cfg)\n{\n    int status = sesman_create_listening_transport(cfg);\n    sesman_delete_listening_transport();\n    return status;\n}\n\n/******************************************************************************/\n/**\n * Close all file descriptors used by sesman.\n *\n * This is generally used after forking, to make sure the\n * file descriptors used by the main process are not disturbed\n *\n * This call will also :-\n * - release all trans objects held by sesman\n * - Delete sesman wait objects\n * - Call sesman_delete_listening_transport()\n */\nstatic int\nsesman_close_all(void)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"sesman_close_all:\");\n\n    scp_list_cleanup();\n    session_list_cleanup();\n\n    g_delete_wait_obj(g_reload_event);\n    g_delete_wait_obj(g_sigchld_event);\n    g_delete_wait_obj(g_term_event);\n\n    sesman_delete_listening_transport();\n\n    return 0;\n}\n\n/******************************************************************************/\nint\nsesman_scp_data_in(struct trans *self)\n{\n    int rv;\n    int available;\n\n    rv = scp_msg_in_check_available(self, &available);\n\n    if (rv == 0 && available)\n    {\n        struct scp_list_item *sli;\n        sli = (struct scp_list_item *)self->callback_data;\n\n        if ((rv = scp_process(sli)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"sesman_data_in: scp_process_msg failed\");\n        }\n        scp_msg_in_reset(self);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nsesman_listen_conn_in(struct trans *self, struct trans *new_self)\n{\n    struct scp_list_item *sli;\n    if (scp_list_get_count() >= MAX_SCP_LIST_ITEMS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"sesman_listen_conn_in: error, too many \"\n            \"connections, rejecting\");\n        trans_delete(new_self);\n    }\n    else if ((sli = scp_list_item_new()) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"sesman_data_in: No memory to allocate \"\n            \"new connection\");\n        trans_delete(new_self);\n    }\n    else if (scp_init_trans(new_self) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"sesman_data_in: Can't init SCP connection\");\n        trans_delete(new_self);\n    }\n    else\n    {\n        new_self->callback_data = (void *)sli;\n        new_self->trans_data_in = sesman_scp_data_in;\n        sli->client_trans = new_self;\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nint\nsesman_eicp_data_in(struct trans *self)\n{\n    int rv;\n    int available;\n\n    rv = eicp_msg_in_check_available(self, &available);\n\n    if (rv == 0 && available)\n    {\n        struct scp_list_item *sli;\n        sli = (struct scp_list_item *)self->callback_data;\n        if ((rv = eicp_process(sli)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"sesman_eicp_data_in: eicp_process_msg failed\");\n        }\n        eicp_msg_in_reset(self);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nsesman_ercp_data_in(struct trans *self)\n{\n    int rv;\n    int available;\n\n    rv = ercp_msg_in_check_available(self, &available);\n\n    if (rv == 0 && available)\n    {\n        struct session_item *si = (struct session_item *)self->callback_data;\n        if ((rv = ercp_process(si)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"sesman_ercp_data_in: ercp_process_msg failed\");\n        }\n        ercp_msg_in_reset(self);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/**\n * Informs the main loop a termination signal has been received\n */\nstatic void\nset_term_event(int sig)\n{\n    /* Don't try to use a wait obj in a child process */\n    if (g_getpid() == g_pid)\n    {\n        g_set_wait_obj(g_term_event);\n    }\n}\n\n/*****************************************************************************/\n/* No-op signal handler.\n */\nstatic void\nsig_no_op(int sig)\n{\n    /* no-op */\n}\n\n/******************************************************************************/\n/**\n * Catch a SIGCHLD and ignore the main loop\n *\n * In theory we could use waitpid() in the signal handler, but that\n * would prevent us adding any logging\n */\nstatic void\nset_sigchld_event(int sig)\n{\n    /* Don't try to use a wait obj in a child process */\n    if (g_getpid() == g_pid)\n    {\n        g_set_wait_obj(g_sigchld_event);\n    }\n}\n\n/******************************************************************************/\n/**\n * Informs the main loop a SIGHUP has been received\n */\nstatic void\nset_reload_event(int sig)\n{\n    /* Don't try to use a wait obj in a child process */\n    if (g_getpid() == g_pid)\n    {\n        g_set_wait_obj(g_reload_event);\n    }\n}\n\n/******************************************************************************/\nvoid\nsesman_delete_listening_transport(void)\n{\n    if (g_getpid() == g_pid)\n    {\n        trans_delete(g_list_trans);\n    }\n    else\n    {\n        trans_delete_from_child(g_list_trans);\n    }\n    g_list_trans = NULL;\n\n    unlock_uds(g_list_trans_lock); // Won't unlock anything for a child process\n    g_list_trans_lock = NULL;\n}\n\n/******************************************************************************/\nint\nsesman_create_listening_transport(const struct config_sesman *cfg)\n{\n    int rv = 1;\n    g_list_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);\n    if (g_list_trans == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s: trans_create failed\", __func__);\n    }\n    else if ((g_list_trans_lock = lock_uds(cfg->listen_port)) != NULL)\n    {\n        /* Make sure the file is always created with the correct\n         * permissions, if it's not there */\n        int entry_umask = g_umask_hex(0x666);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"%s: port %s\", __func__, cfg->listen_port);\n        rv = trans_listen_address(g_list_trans, cfg->listen_port, NULL);\n        if (rv != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s: trans_listen_address failed\", __func__);\n        }\n        else if (g_chown(cfg->listen_port, g_getuid(), g_getuid()) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Can't set ownership of '%s' [%s]\",\n                cfg->listen_port, g_get_strerror());\n        }\n        else if ((rv = g_chmod_hex(cfg->listen_port, 0x666)) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"%s: Can't set permissions on '%s' [%s]\",\n                __func__, cfg->listen_port, g_get_strerror());\n        }\n        else\n        {\n            g_list_trans->trans_conn_in = sesman_listen_conn_in;\n        }\n        g_umask_hex(entry_umask);\n    }\n\n    if (rv != 0)\n    {\n        sesman_delete_listening_transport();\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nsesman_is_term(void)\n{\n    return g_is_wait_obj_set(g_term_event);\n}\n\n/******************************************************************************/\n/**\n *\n * @brief Starts sesman main loop\n *\n */\nstatic int\nsesman_main_loop(void)\n{\n    int error;\n    int robjs_count;\n    intptr_t robjs[1024];\n\n    if (sesman_create_listening_transport(g_cfg) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"sesman_main_loop: sesman_create_listening_transport failed\");\n        return 1;\n    }\n    LOG(LOG_LEVEL_INFO, \"Sesman now listening on %s\", g_cfg->listen_port);\n\n    error = 0;\n    while (!error)\n    {\n        robjs_count = 0;\n        robjs[robjs_count++] = g_term_event;\n        robjs[robjs_count++] = g_sigchld_event;\n        robjs[robjs_count++] = g_reload_event;\n\n        if (g_list_trans != NULL)\n        {\n            /* g_list_trans might be NULL on a reconfigure if sesman\n             * is unable to listen again */\n            error = trans_get_wait_objs(g_list_trans, robjs, &robjs_count);\n            if (error != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"sesman_main_loop: \"\n                    \"trans_get_wait_objs failed\");\n                break;\n            }\n        }\n\n        error = scp_list_get_wait_objs(robjs, &robjs_count);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"sesman_main_loop: \"\n                \"scp_list_get_wait_objs failed\");\n            break;\n        }\n\n        error = session_list_get_wait_objs(robjs, &robjs_count);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"sesman_main_loop: \"\n                \"session_list_get_wait_objs failed\");\n            break;\n        }\n\n        if (g_obj_wait(robjs, robjs_count, NULL, 0, -1) != 0)\n        {\n            /* should not get here */\n            LOG(LOG_LEVEL_WARNING, \"sesman_main_loop: \"\n                \"Unexpected error from g_obj_wait()\");\n            g_sleep(100);\n        }\n\n        if (g_is_wait_obj_set(g_term_event)) /* term */\n        {\n            LOG(LOG_LEVEL_INFO, \"sesman_main_loop: \"\n                \"sesman asked to terminate\");\n            break;\n        }\n\n        if (g_is_wait_obj_set(g_sigchld_event)) /* term */\n        {\n            g_reset_wait_obj(g_sigchld_event);\n            // Prevent any zombies from hanging around\n            while (g_waitchild(NULL) > 0)\n            {\n                ;\n            }\n        }\n\n        if (g_is_wait_obj_set(g_reload_event)) /* We're asked to reload */\n        {\n            g_reset_wait_obj(g_reload_event);\n            sig_sesman_reload_cfg();\n        }\n\n        if (g_list_trans != NULL)\n        {\n            error = trans_check_wait_objs(g_list_trans);\n            if (error != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"sesman_main_loop: \"\n                    \"trans_check_wait_objs failed\");\n                break;\n            }\n        }\n\n        error = scp_list_check_wait_objs();\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"sesman_main_loop: \"\n                \"scp_list_check_wait_objs failed\");\n            break;\n        }\n\n        error = session_list_check_wait_objs();\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"sesman_main_loop: \"\n                \"session_list_check_wait_objs failed\");\n            break;\n        }\n    }\n\n    return error;\n}\n\n/*****************************************************************************/\nstatic void\nprint_version(void)\n{\n    g_writeln(\"xrdp-sesman %s\", PACKAGE_VERSION);\n    g_writeln(\"  The xrdp session manager\");\n    g_writeln(\"  Copyright (C) 2004-%d Jay Sorg, \"\n              \"Neutrino Labs, and all contributors.\",\n              VERSION_YEAR);\n    g_writeln(\"  See https://github.com/neutrinolabs/xrdp for more information.\");\n    g_writeln(\"%s\", \"\");\n\n#if defined(XRDP_CONFIGURE_OPTIONS)\n    g_writeln(\"  Configure options:\");\n    g_writeln(\"%s\", XRDP_CONFIGURE_OPTIONS);\n#endif\n}\n\n/******************************************************************************/\nstatic void\nprint_help(void)\n{\n    g_printf(\"Usage: xrdp-sesman [options]\\n\");\n    g_printf(\"   -k, --kill        shut down xrdp-sesman\\n\");\n    g_printf(\"   -r, --reload      reload xrdp-sesman\\n\");\n    g_printf(\"   -h, --help        show help\\n\");\n    g_printf(\"   -v, --version     show version\\n\");\n    g_printf(\"   -n, --nodaemon    don't fork into background\\n\");\n    g_printf(\"   -c, --config      specify new path to sesman.ini\\n\");\n    g_printf(\"       --dump-config display config on stdout on startup\\n\");\n    g_deinit();\n}\n\n/******************************************************************************/\n/**\n * Reads the PID file\n */\nstatic int\nread_pid_file(const char *pid_file, int *pid)\n{\n    int rv = 1;\n    int fd;\n\n    /* check if sesman is running */\n    if (!g_file_exist(pid_file))\n    {\n        g_printf(\"sesman is not running (pid file not found - %s)\\n\", pid_file);\n    }\n    else if ((fd = g_file_open_ro(pid_file)) < 0)\n    {\n        g_printf(\"error opening pid file[%s]: %s\\n\", pid_file, g_get_strerror());\n    }\n    else\n    {\n        char pid_s[32] = {0};\n        int error = g_file_read(fd, pid_s, sizeof(pid_s) - 1);\n        g_file_close(fd);\n\n        if (error < 0)\n        {\n            g_printf(\"error reading pid file: %s\\n\", g_get_strerror());\n        }\n        else\n        {\n            *pid = g_atoi(pid_s);\n            rv = 0;\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/** Creates the socket path for sesman and session sockets\n*/\nstatic int\ncreate_xrdp_socket_root_path(void)\n{\n    int uid = g_getuid();\n    int gid = g_getgid();\n\n    /* Create the path using 0755 permissions */\n    int old_umask = g_umask_hex(0x22);\n    (void)g_create_path(XRDP_SOCKET_ROOT_PATH\"/\");\n    (void)g_umask_hex(old_umask);\n\n    /* Check the ownership and permissions on the last path element\n     * are as expected */\n    if (g_chown(XRDP_SOCKET_ROOT_PATH, uid, gid) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"create_xrdp_socket_root_path: Can't set owner of %s to %d:%d\",\n            XRDP_SOCKET_ROOT_PATH, uid, gid);\n        return 1;\n    }\n\n    if (g_chmod_hex(XRDP_SOCKET_ROOT_PATH, 0x755) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"create_xrdp_socket_root_path: Can't set perms of %s to 0x755\",\n            XRDP_SOCKET_ROOT_PATH);\n        return 1;\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    int error;\n    enum logReturns log_error;\n    char text[256];\n    char pid_file[256];\n    struct sesman_startup_params startup_params = {0};\n    int errored_argc;\n    int daemon;\n\n    g_init(\"xrdp-sesman\");\n    g_snprintf(pid_file, 255, \"%s/xrdp-sesman.pid\", XRDP_PID_PATH);\n\n    startup_params.sesman_ini = DEFAULT_SESMAN_INI;\n\n    errored_argc = sesman_process_params(argc, argv, &startup_params);\n    if (errored_argc > 0)\n    {\n        print_version();\n        g_writeln(\"%s\", \"\");\n        print_help();\n        g_writeln(\"%s\", \"\");\n\n        g_writeln(\"Unknown option: %s\", argv[errored_argc]);\n        g_deinit();\n        g_exit(1);\n    }\n\n    if (startup_params.help)\n    {\n        print_help();\n        g_exit(0);\n    }\n\n    if (startup_params.version)\n    {\n        print_version();\n        g_exit(0);\n    }\n\n\n    if (startup_params.mode == SSM_KILL_DAEMON)\n    {\n        int pid;\n        int error = 1;\n        if (read_pid_file(pid_file, &pid) == 0)\n        {\n            if (g_sigterm(pid) != 0)\n            {\n                g_printf(\"error killing sesman: %s\\n\", g_get_strerror());\n            }\n            else\n            {\n                /* File is no longer required */\n                g_file_delete(pid_file);\n                error = 0;\n            }\n        }\n        g_deinit();\n        g_exit(error);\n    }\n\n    if (startup_params.mode == SSM_RELOAD_DAEMON)\n    {\n        int pid;\n        int error = 1;\n        if (read_pid_file(pid_file, &pid) == 0)\n        {\n            if (g_sighup(pid) != 0)\n            {\n                g_printf(\"error reloading sesman: %s\\n\", g_get_strerror());\n            }\n            else\n            {\n                error = 0;\n            }\n        }\n        g_deinit();\n        g_exit(error);\n    }\n\n    if (g_file_exist(pid_file))\n    {\n        g_printf(\"xrdp-sesman is already running.\\n\");\n        g_printf(\"if it's not running, try removing \");\n        g_printf(\"%s\", pid_file);\n        g_printf(\"\\n\");\n        g_deinit();\n        g_exit(1);\n    }\n\n    /* starting logging subsystem */\n    if (!g_file_exist(startup_params.sesman_ini))\n    {\n        g_printf(\"Config file %s does not exist\\n\", startup_params.sesman_ini);\n        g_deinit();\n        g_exit(1);\n    }\n    log_error = log_start(\n                    startup_params.sesman_ini, \"xrdp-sesman\",\n                    (startup_params.dump_config) ? LOG_START_DUMP_CONFIG : 0);\n\n    if (log_error != LOG_STARTUP_OK)\n    {\n        switch (log_error)\n        {\n            case LOG_ERROR_MALLOC:\n                g_writeln(\"error on malloc. cannot start logging. quitting.\");\n                break;\n            case LOG_ERROR_FILE_OPEN:\n                g_writeln(\"error opening log file [%s]. quitting.\",\n                          getLogFile(text, 255));\n                break;\n            default:\n                // Assume sufficient messages have already been generated\n                break;\n        }\n\n        g_deinit();\n        g_exit(1);\n    }\n\n    /* reading config */\n    if ((g_cfg = config_read(startup_params.sesman_ini)) == NULL)\n    {\n        LOG(LOG_LEVEL_ALWAYS, \"error reading config %s: %s\",\n            startup_params.sesman_ini, g_get_strerror());\n        log_end();\n        g_deinit();\n        g_exit(1);\n    }\n\n    if (startup_params.dump_config)\n    {\n        config_dump(g_cfg);\n    }\n\n    LOG(LOG_LEVEL_TRACE, \"config loaded in %s at %s:%d\", __func__, __FILE__, __LINE__);\n    LOG(LOG_LEVEL_TRACE, \"    sesman_ini        = %s\", g_cfg->sesman_ini);\n    LOG(LOG_LEVEL_TRACE, \"    listen_port       = %s\", g_cfg->listen_port);\n    LOG(LOG_LEVEL_TRACE, \"    enable_user_wm    = %d\", g_cfg->enable_user_wm);\n    LOG(LOG_LEVEL_TRACE, \"    default_wm        = %s\", g_cfg->default_wm);\n    LOG(LOG_LEVEL_TRACE, \"    user_wm           = %s\", g_cfg->user_wm);\n    LOG(LOG_LEVEL_TRACE, \"    reconnect_sh      = %s\", g_cfg->reconnect_sh);\n    LOG(LOG_LEVEL_TRACE, \"    auth_file_path    = %s\", g_cfg->auth_file_path);\n\n    daemon = !startup_params.no_daemon;\n    if (daemon)\n    {\n        /* not to spit on the console, shut up stdout/stderr before anything's logged */\n        g_file_close(0);\n        g_file_close(1);\n        g_file_close(2);\n\n        if (g_file_open_rw(\"/dev/null\") < 0)\n        {\n        }\n\n        if (g_file_open_rw(\"/dev/null\") < 0)\n        {\n        }\n\n        if (g_file_open_rw(\"/dev/null\") < 0)\n        {\n        }\n    }\n\n    /* Create the socket directory before we try to listen (or\n     * test-listen), so there's somewhere for the default socket to live */\n    if (create_xrdp_socket_root_path() != 0)\n    {\n        config_free(g_cfg);\n        log_end();\n        g_deinit();\n        g_exit(1);\n    }\n\n    if (daemon)\n    {\n        /* start of daemonizing code */\n        if (sesman_listen_test(g_cfg) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Failed to start xrdp-sesman daemon, \"\n                \"possibly address already in use.\");\n            config_free(g_cfg);\n            log_end();\n            g_deinit();\n            g_exit(1);\n        }\n\n        if (0 != g_fork())\n        {\n            config_free(g_cfg);\n            log_end();\n            g_deinit();\n            g_exit(0);\n        }\n\n    }\n\n    /* Now we've forked (if necessary), we can get the program PID */\n    g_pid = g_getpid();\n\n    /* signal handling */\n    g_snprintf(text, 255, \"xrdp_sesman_%8.8x_main_term\", g_pid);\n    g_term_event = g_create_wait_obj(text);\n    g_snprintf(text, 255, \"xrdp_sesman_%8.8x_sigchld\", g_pid);\n    g_sigchld_event = g_create_wait_obj(text);\n    g_snprintf(text, 255, \"xrdp_sesman_%8.8x_reload\", g_pid);\n    g_reload_event = g_create_wait_obj(text);\n\n    g_signal_user_interrupt(set_term_event); /* SIGINT  */\n    g_signal_terminate(set_term_event); /* SIGTERM */\n    g_signal_pipe(sig_no_op);          /* SIGPIPE */\n    g_signal_child_stop(set_sigchld_event); /* SIGCHLD */\n    g_signal_hang_up(set_reload_event); /* SIGHUP  */\n\n    if (daemon)\n    {\n        /* writing pid file */\n        char pid_s[32];\n        int fd = g_file_open_rw(pid_file);\n\n        if (-1 == fd)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"error opening pid file[%s]: %s\",\n                pid_file, g_get_strerror());\n            log_end();\n            config_free(g_cfg);\n            g_deinit();\n            g_exit(1);\n        }\n\n        g_sprintf(pid_s, \"%d\", g_pid);\n        g_file_write(fd, pid_s, g_strlen(pid_s));\n        g_file_close(fd);\n    }\n\n    /* start program main loop */\n    LOG(LOG_LEVEL_INFO,\n        \"starting xrdp-sesman with pid %d\", g_pid);\n\n    /* make sure the X11_UNIX_SOCKET_DIRECTORY exists */\n    if (!g_directory_exist(X11_UNIX_SOCKET_DIRECTORY))\n    {\n        if (!g_create_dir(X11_UNIX_SOCKET_DIRECTORY))\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"sesman.c: error creating dir \" X11_UNIX_SOCKET_DIRECTORY);\n        }\n        if (g_chmod_hex(X11_UNIX_SOCKET_DIRECTORY, 0x1777) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"sesman.c: can't set permissions on \"\n                X11_UNIX_SOCKET_DIRECTORY \"[%s]\", g_get_strerror());\n        }\n    }\n\n    if ((error = scp_list_init(MAX_SCP_LIST_ITEMS)) == 0 &&\n            (error = session_list_init()) == 0 &&\n            (error = sesman_restart_discover_sessions()) == 0)\n    {\n        error = sesman_main_loop();\n    }\n\n    /* clean up PID file on exit */\n    if (daemon)\n    {\n        g_file_delete(pid_file);\n    }\n\n    sesman_close_all();\n\n    log_end();\n\n    config_free(g_cfg);\n    g_deinit();\n    g_exit(error);\n    return 0;\n}\n"
  },
  {
    "path": "sesman/sesman.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesman.h\n * @brief Main include file\n * @author Jay Sorg\n *\n */\n\n#ifndef SESMAN_H\n#define SESMAN_H\n\nstruct config_sesman;\nstruct trans;\n\n/* Globals */\nextern struct config_sesman *g_cfg;\nextern tintptr g_term_event;\n\n/*\n * Remove the listening transport\n *\n * Needed if reloading the config and the listener has changed\n */\nvoid\nsesman_delete_listening_transport(void);\n\n/*\n * Create the listening socket transport\n *\n * @return 0 for success\n */\nint\nsesman_create_listening_transport(const struct config_sesman *cfg);\n\n/**\n * Callback to process incoming SCP data\n */\nint\nsesman_scp_data_in(struct trans *self);\n\n/**\n * Callback to process incoming EICP data\n */\nint\nsesman_eicp_data_in(struct trans *self);\n\n/**\n * Callback to process incoming ERCP data\n */\nint\nsesman_ercp_data_in(struct trans *self);\n\n/*\n * Check for termination\n */\nint\nsesman_is_term(void);\n\n#endif\n"
  },
  {
    "path": "sesman/sesman.ini.in",
    "content": ";; See `man 5 sesman.ini` for details\n\n[Globals]\n; listening port\n#ListenPort=sesman.socket\nEnableUserWindowManager=true\n; Give in relative path to user's home directory\nUserWindowManager=startwm.sh\n; Give in full path or relative path to @sesmansysconfdir@\nDefaultWindowManager=startwm.sh\n; Give in full path or relative path to @sesmansysconfdir@\nReconnectScript=reconnectwm.sh\n; Set this to 'yes' if you wish to reconnect script to be run on\n; the first connection to a session. Normally the script is\n; only run on reconnections.\n#AlwaysRunReconnect=no\n\n[Security]\nAllowRootLogin=true\nMaxLoginRetry=4\nXAuthorityInSystemDir=no\nTerminalServerUsers=tsusers\nTerminalServerAdmins=tsadmins\n; When AlwaysGroupCheck=false access will be permitted\n; if the group TerminalServerUsers is not defined, and the\n; non-existence of TerminalServerAdmins will not be reported\nAlwaysGroupCheck=false\n; When RestrictOutboundClipboard=all clipboard from the\n; server is not pushed to the client.\n; In addition, you can control text/file/image transfer restrictions\n; respectively. It also accepts comma separated list such as text,file,image.\n; To keep compatibility, some aliases are also available:\n;   true: an alias of all\n;   false: an alias of none\n;   yes: an alias of all\nRestrictOutboundClipboard=none\n; When RestrictInboundClipboard=all clipboard from the\n; client is not pushed to the server.\n; In addition, you can control text/file/image transfer restrictions\n; respectively. It also accepts comma separated list such as text,file,image.\n; To keep compatibility, some aliases are also available:\n;   true: an alias of all\n;   false: an alias of none\n;   yes: an alias of all\nRestrictInboundClipboard=none\n; Set to 'no' to prevent users from logging in with alternate shells\n#AllowAlternateShell=true\n; Normally, alternate shells (if permitted) are executed directly, as\n; specified.\n; If this is set, alternate shells are not actioned directly, but\n; passed in to the default window manager in the specified environment\n; variable. This allows the system manager more control over exactly\n; what alternate shells are permitted.\n; This will override any setting of the same environment variable\n; in the [SessionVariables] section.\n#PassShellAsEnv=XRDP_ALTERNATE_SHELL\n; On Linux systems, the Xorg X11 server is normally invoked using\n; no_new_privs to avoid problems if the executable is suid. This may,\n; however, interfere with the use of security modules such as AppArmor.\n; Leave this unset unless you need to disable it.\n#XorgNoNewPrivileges=true\n; Specify the group which is to have read access to the directory where\n; local sockets for the session are created.\n; This should take one of the following values:-\n; 1) For normal operation with sesman, set this to 'root' for\n;    maximum security\n; 2) If you are using xrdp to connect to VNC sessions with X server\n;    sockets or chansrv sockets in the local sockets dir, set this to\n;    the runtime_group in xrdp.ini. If you do not do this, xrdp will not\n;    be able to connect to your sessions.\nSessionSockdirGroup=root\n#SessionSockdirGroup=xrdp\n\n\n[Sessions]\n;; X11DisplayOffset - x11 display number offset\n; Type: integer\n; Default: 10\nX11DisplayOffset=10\n\n;; MaxSessions - maximum number of connections to an xrdp server\n; Type: integer\n; Default: 0\nMaxSessions=50\n\n;; MaxDisplayNumer - maximum number considered for an X display\n; Type: integer\n; Default: 63\n;\n; IANA only allocates TCP ports up to 6063 for X servers. If you are not\n; allowing TCP connections to your X servers you may safely increase this\n; number.\n#MaxDisplayNumber=63\n\n;; KillDisconnected - kill disconnected sessions\n; Type: boolean\n; Default: false\n; if 1, true, or yes, every session will be killed within DisconnectedTimeLimit\n; seconds after the user disconnects\nKillDisconnected=false\n\n;; DisconnectedTimeLimit (seconds) - wait before kill disconnected sessions\n; Type: integer\n; Default: 0\n; if KillDisconnected is set to false, this value is ignored\nDisconnectedTimeLimit=0\n\n;; IdleTimeLimit (seconds) - wait before disconnect idle sessions\n; Type: integer\n; Default: 0\n; Set to 0 to disable idle disconnection.\nIdleTimeLimit=0\n\n;; Policy - session allocation policy\n;\n;  Type: enum [ \"Default\" | \"Separate\" | Combination from {UBDI} ]\n;  \"Default\"    Currently same as \"UB\"\n;  \"Separate\"   All sessions are separate. Sessions can never be rejoined,\n;               and will need to be cleaned up manually, or automatically\n;               by setting other sesman options.\n;\n;   Combination options:-\n;      U        Sessions are separated per user\n;      B        Sessions are separated by bits-per-pixel\n;      D        Sessions are separated by initial display size\n;      I        Sessions are separated by IP address\n;      N        Sessions are separated by xrdp instance name\n;\n;   The options U and B are always active, and cannot be de-selected.\n;\n;   The \"\" in the text above are for readability. Do not include them in\n;   the string\nPolicy=Default\n\n;; Startup wait time\n; Milliseconds to wait to ensure the session has started\nStartupWaitTime=1500\n\n[Logging]\n; Note: Log levels can be any of: core, error, warning, info, debug, or trace\nLogFile=xrdp-sesman.log\nLogLevel=INFO\nEnableSyslog=true\n#SyslogLevel=INFO\n#EnableConsole=false\n#ConsoleLevel=INFO\n#EnableProcessId=false\n\n[LoggingPerLogger]\n; Note: per logger configuration is only used if xrdp is built with\n; --enable-devel-logging\n#sesman.c=INFO\n#main()=INFO\n\n;\n; Session definitions - startup command-line parameters for each session type\n;\n\n[Xorg]\n; Specify the path of non-suid Xorg executable. It might differ depending\n; on your distribution and version. Find out the appropriate path for your\n; environment. The typical path is known as follows:\n;\n; Fedora 26 or later          :  param=/usr/libexec/Xorg\n; Alma/Rocky Linux 8 or later :  param=/usr/libexec/Xorg\n; Debian 9 or later           :  param=/usr/lib/xorg/Xorg\n; Ubuntu 16.04 or later       :  param=/usr/lib/xorg/Xorg\n; Arch Linux                  :  param=/usr/lib/Xorg\n; FreeBSD (from 2022Q4)       :  param=/usr/local/libexec/Xorg\n;\nparam=Xorg\n; Leave the rest parameters as-is unless you understand what will happen.\nparam=-config\nparam=xrdp/xorg.conf\n;param=xrdp/xorg_nvidia.conf\n;param=xrdp/xorg_nvidia_grid.conf\nparam=-noreset\nparam=-nolisten\nparam=tcp\n; Logging levels are 4 for debug and 5 for trace. Uncomment and\n; edit these lines to get debugging info in the xorgxrdp log file\n#param=-logverbose\n#param=5\nparam=-logfile\nparam=.xorgxrdp.%s.log\n\n[Xvnc]\nparam=Xvnc\nparam=-bs\nparam=-nolisten\nparam=tcp\nparam=-localhost\nparam=-dpi\nparam=96\n\n[Chansrv]\n; drive redirection\n; See sesman.ini(5) for the format of this parameter\n#FuseMountName=/run/user/%u/thinclient_drives\n#FuseMountName=/media/thinclient_drives/%U/thinclient_drives\nFuseMountName=thinclient_drives\n#FuseMountNameColonCharReplacement=\n; this value allows only the user to access their own mapped drives.\n; Make this more permissive (e.g. 022) if required.\nFileUmask=077\n; Can be used to disable FUSE functionality - see sesman.ini(5)\n#EnableFuseMount=false\n; Can be used to enable direct I/O to FUSE open file calls. This is useful\n; when open file handles need to immediately see changes made on the client\n; side. There is a performance hit, so use with caution.\n#FuseDirectIO=true\n; Uncomment this line only if you are using GNOME 3 versions 3.29.92\n; and up, and you wish to cut-paste files between Nautilus and Windows. Do\n; not use this setting for GNOME 4, or other file managers\n#UseNautilus3FlistFormat=true\n; Uncomment this line if your file manager erroneously reports\n; 'No free space' when trying to copy any files to remote drives.\n#FuseRootReportMaxFree=true\n; sound redirection\n; workaround for Microsoft mstsc.exe to suppress noise.\n; SoundNumSilentFramesAAC | SoundNumSilentFramesMP3 silent frames are sent before SNDC_CLOSE is sent.\n; during SoundMsecDoNotSend mS after SNDC_CLOSE is sent, sound data is not send.\n; depending on the environment, it might be necessary to increase values.\n; Defaults: SoundNumSilentFramesAAC=4, SoundNumSilentFramesMP3=2, SoundMsecDoNotSend=1000\n; If set to 0, this workaround is not applied.\n#SoundNumSilentFramesAAC=4\n#SoundNumSilentFramesMP3=2\n#SoundMsecDoNotSend=1000\n\n[ChansrvLogging]\n; Note: one log file is created per display and the LogFile config value\n; is ignored. The channel server log file names follow the naming convention:\n; xrdp-chansrv.${DISPLAY}.log\n;\n; Note: Log levels can be any of: core, error, warning, info, debug, or trace\nLogLevel=INFO\nEnableSyslog=true\n#SyslogLevel=INFO\n#EnableConsole=false\n#ConsoleLevel=INFO\n#EnableProcessId=false\n; Log file path\n; Set this to move the log file away from its default location. You may want\n; to do this for (e.g.) NFS-mounted home directories\n; See sesman.ini(5) for the format of this parameter\n#LogFilePath=/run/user/%u/xrdp\n\n[ChansrvLoggingPerLogger]\n; Note: per logger configuration is only used if xrdp is built with\n; --enable-devel-logging\n#chansrv.c=INFO\n#main()=INFO\n\n[SessionVariables]\nPULSE_SCRIPT=@sesmansysconfdir@/pulse/default.pa\n;XRDP_USE_ACCEL_ASSIST=1\n;XRDP_NVIDIA_GRID=1\n"
  },
  {
    "path": "sesman/sesman_restart.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Matt Burt 2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesman_restart.c\n * @brief Sesman restart definitions\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <stdio.h>\n\n#include \"os_calls.h\"\n#include \"sesman.h\"\n#include \"sesman_config.h\"\n#include \"session_list.h\"\n\n#include \"ercp.h\"\n\n#include \"sesman_restart.h\"\n#include \"xrdp_sockets.h\"\n\n// Result of calling init_restart_directory()\nenum init_restart_dir_status\n{\n    E_RESTART_DIR_CREATED_OK,     ///< All good. Dir created\n    E_RESTART_DIR_ALREADY_EXISTS, ///< All good. Dir already existed\n    E_RESTART_DIR_ERROR           ///< Not good\n};\n\nenum\n{\n    MAX_DISCOVERY_WAIT_TIME = 5000  // Milli-seconds\n};\n\n/******************************************************************************/\nstatic enum init_restart_dir_status\ninit_restart_directory(const char *restart_dir)\n{\n    enum init_restart_dir_status rv;\n\n    if (g_directory_exist(restart_dir))\n    {\n        rv = E_RESTART_DIR_ALREADY_EXISTS;\n    }\n    else\n    {\n        // Create the restart directory for the next run\n        if (g_mkdir(restart_dir) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't create restart directory %s [%s]\",\n                restart_dir, g_get_strerror());\n            rv = E_RESTART_DIR_ERROR;\n        }\n        else\n        {\n            rv = E_RESTART_DIR_CREATED_OK;\n        }\n    }\n\n    if (rv != E_RESTART_DIR_ERROR)\n    {\n        // Always set the permissions on the restart directory, whether\n        // or not we created it\n        if (g_chown(restart_dir, g_getuid(), g_getuid()) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't set ownership of '%s' [%s]\",\n                restart_dir, g_get_strerror());\n            rv = E_RESTART_DIR_ERROR;\n        }\n        else if (g_chmod_hex(restart_dir, 0x700) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't set permissions on '%s' [%s]\",\n                restart_dir, g_get_strerror());\n            rv = E_RESTART_DIR_ERROR;\n        }\n    }\n    return rv;\n}\n\n/******************************************************************************/\n/**\n * Attempts to add a sesexec Unix Domain Socket to the process_list\n * @param filename Name of UDS\n * @return Boolean for success\n *\n * The credentials of the process on the other end are checked.\n * We don't take the max session limit into account when adding sessions here,\n * as this could result in orphaned sessions.\n */\nstatic int\nadd_sesexec_fd_to_session_list(const char *filename)\n{\n    int status = 0;\n    struct trans *t = NULL;\n\n    // Check filename is a socket\n    if (g_socket_exist(filename))\n    {\n        // Try to connect to the session\n        if ((t = ercp_connect(filename, sesman_is_term)) != NULL)\n        {\n            int sesexec_pid;\n            int sesexec_uid;\n            int sesexec_gid;\n\n            // Find the credentials of the sesexec process on the other end\n            if (g_sck_get_peer_cred(t->sck, &sesexec_pid,\n                                    &sesexec_uid, &sesexec_gid) == 0)\n            {\n                // Don't talk to unprivileged processes. It's a big concern\n                // if we find one.\n                if (sesexec_uid != 0 || sesexec_gid != 0)\n                {\n                    LOG(LOG_LEVEL_ALWAYS,\n                        \"Unexpected sesexec owner %d:%d\"\n                        \" for PID %d listening on %s\",\n                        sesexec_uid, sesexec_gid, sesexec_pid, filename);\n                }\n                else\n                {\n                    struct session_item *s_item;\n                    if ((s_item = session_list_new()) != NULL)\n                    {\n                        // Finalise the session for I/O\n                        t->trans_data_in = sesman_ercp_data_in;\n                        t->callback_data = (void *)s_item;\n\n                        // Complete the session fields for the\n                        // E_SESSION_STARTING state\n                        s_item->sesexec_trans = t;\n                        s_item->sesexec_pid = sesexec_pid;\n                        s_item->display[0] = '\\0';\n\n                        // Tell the caller we've added one\n                        status = 1;\n                    }\n                }\n            }\n        }\n    }\n\n    // Clean up an unused transport\n    if (status == 0)\n    {\n        trans_delete(t);\n    }\n\n    return 1;\n}\n\n/******************************************************************************/\nstatic int\ndiscover_sessions(const char *restart_dir)\n{\n    int rv = 0;\n    struct list *dirnames = g_readdir(restart_dir);\n    unsigned int start_time = g_get_elapsed_ms();\n    unsigned int session_count;\n    unsigned int elapsed;\n    int robjs_count;\n    intptr_t robjs[1024];\n    int timeout;\n\n    if (dirnames == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Can't read restart directory to discover sessions [%s]\",\n            g_get_strerror());\n    }\n    else\n    {\n        // Iterate over the restart directory, and add any sesexec\n        // processes we discover to the session list, in\n        // E_SESSION_STARTING state.\n        char filename[XRDP_SOCKETS_MAXPATH];\n        int i;\n\n        for (i = 0 ; i < dirnames->count; ++i)\n        {\n            g_snprintf(filename, sizeof(filename),  \"%s/%s\",\n                       restart_dir, (const char *)dirnames->items[i]);\n\n            (void)add_sesexec_fd_to_session_list(filename);\n        }\n\n        list_delete(dirnames);\n        dirnames = NULL;\n    }\n\n    // Process session list messages until either all sessions have\n    // started (or failed), or we hit a timeout.\n    while (1)\n    {\n        session_count = session_list_get_count_by_state(E_SESSION_STARTING);\n        elapsed = (g_get_elapsed_ms() - start_time);\n        if (session_count == 0 || elapsed >= MAX_DISCOVERY_WAIT_TIME)\n        {\n            break;\n        }\n\n        robjs_count = 0;\n        robjs[robjs_count++] = g_term_event;\n        (void)session_list_get_wait_objs(robjs, &robjs_count);\n\n        timeout = MAX_DISCOVERY_WAIT_TIME - elapsed; // > 0\n        if (g_obj_wait(robjs, robjs_count, NULL, 0, timeout) != 0)\n        {\n            /* should not get here */\n            g_sleep(100);\n            continue;\n        }\n\n        if (g_is_wait_obj_set(g_term_event)) /* term */\n        {\n            LOG(LOG_LEVEL_INFO, \"discover_sessions: sesman asked to terminate\");\n            rv = 1;\n            break;\n        }\n\n        (void)session_list_check_wait_objs();\n    }\n\n    if (rv == 0)\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"Session discovery took %d secs and loaded %u sessions\",\n            elapsed, session_list_get_count_by_state(E_SESSION_RUNNING));\n\n        if (session_count > 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"%u sessions have not responded at end of discovery\",\n                session_count);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nsesman_restart_discover_sessions(void)\n{\n    int rv = 1;\n    // The restart directory contains Unix Domain sockets, so can't\n    // exceed XRDP_SOCKETS_MAXPATH in length\n    char restart_dir[XRDP_SOCKETS_MAXPATH];\n\n    // sizeof(g_cfg->listen_port) is guaranteed to be smaller than\n    // XRDP_SOCKETS_MAXPATH\n    g_snprintf(restart_dir, sizeof(restart_dir),\n               \"%s.r\", g_cfg->listen_port);\n    switch (init_restart_directory(restart_dir))\n    {\n        case E_RESTART_DIR_CREATED_OK:\n            // Nothing to discover\n            rv = 0;\n            break;\n\n        case E_RESTART_DIR_ALREADY_EXISTS:\n            // Look for sessions from previous run\n            rv = discover_sessions(restart_dir);\n            break;\n\n        default:\n            ;\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "sesman/sesman_restart.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Matt Burt 2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesman_restart.h\n * @brief Sesman restart declarations\n * @author Matt Burt\n *\n */\n\n\n#ifndef SESMAN_RESTART_H\n#define SESMAN_RESTART_H\n\n/**\n * Discover sessions from a previous sesman run\n * @return 0 for success\n *\n * Errors are logged\n */\nint\nsesman_restart_discover_sessions(void);\n\n#endif // SESMAN_RESTART_H\n"
  },
  {
    "path": "sesman/session_list.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * BSD process grouping by:\n * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland.\n * Copyright (c) 2000-2001 Markus Friedl.\n * Copyright (c) 2011-2015 Koichiro Iwao, Kyushu Institute of Technology.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file session_list.c\n * @brief Session list management code\n * @author Jay Sorg, Simone Fedele\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"arch.h\"\n#include \"session_list.h\"\n#include \"trans.h\"\n\n#include \"sesman_config.h\"\n#include \"list.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"sesman.h\"\n#include \"set_int.h\"\n#include \"string_calls.h\"\n#include \"xrdp_sockets.h\"\n\nstatic struct list *g_session_list = NULL;\n\n#define SESSION_IN_USE(si) \\\n    ((si) != NULL && \\\n     (si)->sesexec_trans != NULL && \\\n     (si)->sesexec_trans->status == TRANS_STATUS_UP)\n\n/******************************************************************************/\nint\nsession_list_init(void)\n{\n    int rv = 0;\n    if (g_session_list == NULL)\n    {\n        g_session_list = list_create_sized(g_cfg->sess.max_sessions);\n        if (g_session_list == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't allocate session list\");\n            rv = 1;\n        }\n        else\n        {\n            g_session_list->auto_free = 0;\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/**\n * Frees resources allocated to a session_item\n *\n * @param si Session item\n *\n * @note Any pointer to this item on g_session_list will be invalid\n *       after this call.\n */\nstatic void\nfree_session(struct session_item *si)\n{\n    if (si != NULL)\n    {\n        if (si->sesexec_trans != NULL)\n        {\n            trans_delete(si->sesexec_trans);\n        }\n        g_free(si);\n    }\n}\n\n/******************************************************************************/\nvoid\nsession_list_cleanup(void)\n{\n    if (g_session_list != NULL)\n    {\n        int i;\n        for (i = 0 ; i < g_session_list->count ; ++i)\n        {\n            struct session_item *si;\n            si = (struct session_item *)list_get_item(g_session_list, i);\n            free_session(si);\n        }\n        list_delete(g_session_list);\n        g_session_list = NULL;\n    }\n}\n\n/******************************************************************************/\nunsigned int\nsession_list_get_count(void)\n{\n    return (g_session_list == NULL) ? 0 : g_session_list->count;\n}\n\n/******************************************************************************/\nunsigned int\nsession_list_get_count_by_state(enum session_state state)\n{\n    unsigned int result = 0;\n    int i;\n    for (i = 0 ; i < g_session_list->count ; ++i)\n    {\n        struct session_item *si;\n        si = (struct session_item *)list_get_item(g_session_list, i);\n        if (si->state == state)\n        {\n            ++result;\n        }\n    }\n    return result;\n}\n\n/******************************************************************************/\nstruct session_item *\nsession_list_new(void)\n{\n    struct session_item *result = g_new0(struct session_item, 1);\n    if (result != NULL)\n    {\n        result->state = E_SESSION_STARTING;\n        if (!list_add_item(g_session_list, (tintptr)result))\n        {\n            g_free(result);\n            result = NULL;\n        }\n    }\n\n    return result;\n}\n\n/******************************************************************************/\nvoid\nsession_list_get_session_x11_displays(struct set_int *alloc_displays)\n{\n    int count = (g_session_list == NULL) ? 0 : g_session_list->count;\n\n    int i = 0;\n    for (i = 0 ; i < count ; ++i)\n    {\n        struct session_item *si;\n        si = (struct session_item *)list_get_item(g_session_list, i);\n\n        if (SESSION_IN_USE(si) && SCP_SESSION_TYPE_IS_X11(si->type))\n        {\n            int display = g_get_x11_display_from_display_string(si->display);\n            if (display >= 0)\n            {\n                set_int_add(alloc_displays, display);\n            }\n        }\n    }\n}\n\n/******************************************************************************/\nstruct session_item *\nsession_list_get_bydata(uid_t uid,\n                        enum scp_session_type type,\n                        unsigned short width,\n                        unsigned short height,\n                        unsigned char  bpp,\n                        const char *ip_addr,\n                        const char *instance_name)\n{\n    char policy_str[64];\n    int policy = g_cfg->sess.policy;\n    int i;\n\n    if (ip_addr == NULL)\n    {\n        ip_addr = \"\";\n    }\n\n    if (instance_name == NULL)\n    {\n        instance_name = \"\";\n    }\n\n    if ((policy & SESMAN_CFG_SESS_POLICY_DEFAULT) != 0)\n    {\n        /* Before xrdp v0.9.14, the default\n         * session policy varied by type. If this is needed again\n         * in the future, here is the place to add it */\n        policy = SESMAN_CFG_SESS_POLICY_U | SESMAN_CFG_SESS_POLICY_B;\n    }\n\n    config_output_policy_string(policy, policy_str, sizeof(policy_str));\n\n    LOG(LOG_LEVEL_DEBUG,\n        \"%s: search policy=%s type=%s U=%d B=%d D=(%dx%d) I=%s P=%s\",\n        __func__,\n        policy_str, SCP_SESSION_TYPE_TO_STR(type),\n        uid, bpp, width, height,\n        ip_addr, instance_name);\n\n    /* 'Separate' policy never matches */\n    if (policy & SESMAN_CFG_SESS_POLICY_SEPARATE)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"%s: No matches possible\", __func__);\n        return NULL;\n    }\n\n    for (i = 0 ; i < g_session_list->count ; ++i)\n    {\n        struct session_item *si;\n        si = (struct session_item *)list_get_item(g_session_list, i);\n        if (!SESSION_IN_USE(si))\n        {\n            continue;\n        }\n\n        LOG(LOG_LEVEL_DEBUG,\n            \"%s: try %p type=%s U=%d B=%d D=(%dx%d) I=%s N=%s\",\n            __func__,\n            si,\n            SCP_SESSION_TYPE_TO_STR(si->type),\n            si->uid, si->bpp,\n            si->start_width, si->start_height,\n            si->start_ip_addr, si->xrdp_instance_name);\n\n        if (si->type != type)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"%s: Type doesn't match\", __func__);\n            continue;\n        }\n\n        if ((policy & SESMAN_CFG_SESS_POLICY_U) && uid != si->uid)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"%s: UID doesn't match for 'U' policy\", __func__);\n            continue;\n        }\n\n        if ((policy & SESMAN_CFG_SESS_POLICY_B) && si->bpp != bpp)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"%s: bpp doesn't match for 'B' policy\", __func__);\n            continue;\n        }\n\n        if ((policy & SESMAN_CFG_SESS_POLICY_D) &&\n                (si->start_width != width ||\n                 si->start_height != height))\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"%s: Dimensions don't match for 'D' policy\", __func__);\n            continue;\n        }\n\n        if ((policy & SESMAN_CFG_SESS_POLICY_I) &&\n                g_strcmp(si->start_ip_addr, ip_addr) != 0)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"%s: IPs don't match for 'I' policy\", __func__);\n            continue;\n        }\n\n        if ((policy & SESMAN_CFG_SESS_POLICY_N) &&\n                g_strcmp(si->xrdp_instance_name, instance_name) != 0)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"%s: Instance names don't match for 'N' policy\", __func__);\n            continue;\n        }\n\n        LOG(LOG_LEVEL_DEBUG,\n            \"%s: Got match, display=%s\", __func__, si->display);\n        return si;\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"%s: No matches found\", __func__);\n    return NULL;\n}\n\n/******************************************************************************/\nstruct scp_session_info *\nsession_list_get_byuid(const uid_t *uid, unsigned int *cnt, unsigned int flags)\n{\n    int i;\n    struct scp_session_info *sess;\n    int count;\n    int index;\n\n    count = 0;\n\n    if (uid != NULL)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"searching for session by UID: %d\", (int)*uid);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_DEBUG, \"searching for all sessions\");\n    }\n\n    for (i = 0 ; i < g_session_list->count ; ++i)\n    {\n        const struct session_item *si;\n        si = (const struct session_item *)list_get_item(g_session_list, i);\n        if (SESSION_IN_USE(si) && (uid == NULL || *uid == si->uid))\n        {\n            count++;\n        }\n    }\n\n    if (count == 0)\n    {\n        (*cnt) = 0;\n        return 0;\n    }\n\n    /* malloc() an array of disconnected sessions */\n    sess = g_new0(struct scp_session_info, count);\n\n    if (sess == 0)\n    {\n        (*cnt) = 0;\n        return 0;\n    }\n\n    index = 0;\n    for (i = 0 ; i < g_session_list->count ; ++i)\n    {\n        const struct session_item *si;\n        si = (const struct session_item *)list_get_item(g_session_list, i);\n\n        if (SESSION_IN_USE(si) && (uid == NULL || *uid == si->uid))\n        {\n            sess[index].sid = si->sesexec_pid;\n            sess[index].display = g_strdup(si->display);\n            sess[index].type = si->type;\n            sess[index].height = si->start_height;\n            sess[index].width = si->start_width;\n            sess[index].bpp = si->bpp;\n            sess[index].start_time = si->start_time;\n            sess[index].uid = si->uid;\n            sess[index].start_ip_addr = g_strdup(si->start_ip_addr);\n            sess[index].client_ip = g_strdup(si->client_ip);\n            sess[index].client_name = g_strdup(si->client_name);\n            sess[index].last_connect_disconnect = si->last_connect_disconnect;\n            sess[index].xrdp_instance_name = g_strdup(si->xrdp_instance_name);\n\n            /* Check for string allocation failures */\n            if (sess[index].display == NULL ||\n                    sess[index].start_ip_addr == NULL ||\n                    sess[index].client_ip == NULL ||\n                    sess[index].client_name == NULL ||\n                    sess[index].xrdp_instance_name == NULL)\n            {\n                free_session_info_list(sess, *cnt);\n                (*cnt) = 0;\n                return 0;\n            }\n            index++;\n        }\n    }\n\n    (*cnt) = count;\n    return sess;\n}\n\n/******************************************************************************/\nstruct session_item *\nsession_list_get_byguid(const struct guid *guid)\n{\n    int i;\n\n    for (i = 0 ; i < g_session_list->count ; ++i)\n    {\n        struct session_item *si;\n        si = (struct session_item *)list_get_item(g_session_list, i);\n        if (SESSION_IN_USE(si) && GUID_ARE_EQUAL(guid, &si->guid))\n        {\n            return si;\n        }\n    }\n\n    return NULL;\n}\n\n/******************************************************************************/\nvoid\nfree_session_info_list(struct scp_session_info *sesslist, unsigned int cnt)\n{\n    if (sesslist != NULL && cnt > 0)\n    {\n        unsigned int i;\n        for (i = 0 ; i < cnt ; ++i)\n        {\n            g_free(sesslist[i].display);\n            g_free(sesslist[i].start_ip_addr);\n            g_free(sesslist[i].client_ip);\n            g_free(sesslist[i].client_name);\n            g_free(sesslist[i].xrdp_instance_name);\n        }\n    }\n\n    g_free(sesslist);\n}\n\n/******************************************************************************/\nint\nsession_list_get_wait_objs(tbus robjs[], int *robjs_count)\n{\n    int i;\n\n    for (i = 0 ; i < g_session_list->count; ++i)\n    {\n        const struct session_item *si;\n        si = (const struct session_item *)list_get_item(g_session_list, i);\n        if (SESSION_IN_USE(si))\n        {\n            robjs[(*robjs_count)++] = si->sesexec_trans->sck;\n        }\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nint\nsession_list_check_wait_objs(void)\n{\n    int i = 0;\n\n    while (i < g_session_list->count)\n    {\n        struct session_item *si;\n        si = (struct session_item *)list_get_item(g_session_list, i);\n        if (SESSION_IN_USE(si))\n        {\n            if (trans_check_wait_objs(si->sesexec_trans) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"sesman_check_wait_objs: \"\n                    \"trans_check_wait_objs failed, removing trans\");\n                si->sesexec_trans->status = TRANS_STATUS_DOWN;\n            }\n        }\n\n        if (SESSION_IN_USE(si))\n        {\n            ++i;\n        }\n        else\n        {\n            free_session(si);\n            list_remove_item(g_session_list, i);\n        }\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "sesman/session_list.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file session_list.h\n * @brief Session list management definitions\n * @author Jay Sorg, Simone Fedele\n *\n */\n\n\n#ifndef SESSION_LIST_H\n#define SESSION_LIST_H\n\n#include <sys/types.h>\n\n#include \"guid.h\"\n#include \"scp_application_types.h\"\n#include \"xrdp_constants.h\"\n\nstruct set_int;\n\nenum session_state\n{\n    /**\n     * Session definition is little more than a sesexec process. We're\n     * waiting for more details of the session from sesexec */\n    E_SESSION_STARTING,\n    /** Session is fully active */\n    E_SESSION_RUNNING\n};\n\n/**\n * Object describing a session\n *\n * Unless otherwide noted, fields are only valid if\n * the status is E_SESSION_RUNNING\n */\nstruct session_item\n{\n    enum session_state state;\n    struct trans *sesexec_trans; // trans for sesexec process. Always valid.\n    pid_t sesexec_pid; // pid for sesexec process. Always valid\n    /**\n     * May be valid if known when the session is starting, otherwise \"\" */\n    char display[MAX_DISPLAY_NAME_SIZE];\n    uid_t uid;\n    enum scp_session_type type;\n    unsigned short start_width;\n    unsigned short start_height;\n    unsigned char bpp;\n    struct guid guid;\n    char start_ip_addr[MAX_PEER_ADDRSTRLEN];\n    time_t start_time;\n    char client_ip[MAX_PEER_ADDRSTRLEN];\n    char client_name[INFO_CLIENT_NAME_BYTES_UTF8];\n    time_t last_connect_disconnect;\n    char xrdp_instance_name[MAX_XRDP_INSTANCE_NAMELEN];\n    /* allow a tag to be specified to distinguish sessions */\n};\n\n/**\n * Initialise the module\n * @return 0 for success\n *\n * Errors are logged\n */\nint\nsession_list_init(void);\n\n/**\n * Clean up the module on program exit\n */\nvoid\nsession_list_cleanup(void);\n\n/**\n * Returns the number of sessions currently active\n * @return Session count\n */\nunsigned int\nsession_list_get_count(void);\n\n/**\n * @brief Get the number of sessions in a particular state\n * @param state to count\n * @return session count\n */\nunsigned int\nsession_list_get_count_by_state(enum session_state state);\n\n/**\n * Allocates a new session on the list\n *\n * state will be E_SESSION_STARTING. Other data must be filled in by\n * the caller as appropriate.\n *\n * @return pointer to new session object or NULL for no memory\n *\n * After allocating the session, you must initialise the sesexec_trans field\n * with a valid transport.\n *\n * The session is removed by session_check_wait_objs() when the transport\n * goes down (or wasn't allocated in the first place).\n */\nstruct session_item *\nsession_list_new(void);\n\n/**\n * @brief Get all session displays\n *\n * Adds X11 displays allocated to sessions to a set\n */\nvoid\nsession_list_get_session_x11_displays(struct set_int *alloc_displays);\n\n/**\n *\n * @brief finds a session matching the supplied parameters\n * @return session data or 0\n *\n */\nstruct session_item *\nsession_list_get_bydata(uid_t uid,\n                        enum scp_session_type type,\n                        unsigned short width,\n                        unsigned short height,\n                        unsigned char  bpp,\n                        const char *ip_addr,\n                        const char *instance_name);\n\n/**\n * @brief retrieves session descriptions\n * @param uid the UID for the descriptions by reference, or NULL for\n *            all UIDs\n * @param[out] cnt The number of sessions returned\n * @param flags Future expansion\n * @return A block of session descriptions\n *\n * Pass the return result to free_session_info_list() after use\n *\n */\nstruct scp_session_info *\nsession_list_get_byuid(const uid_t *uid, unsigned int *cnt, unsigned int flags);\n\n/**\n * @brief retrieves a session by GUID\n * @param guid GUID of session\n * @return Pointer to session, or NULL.\n *\n * The caller is responsible for checking the client has\n * permissions to access the session.\n */\nstruct session_item *\nsession_list_get_byguid(const struct guid *guid);\n\n/**\n *\n * @brief Frees the result of session_get_byuser()\n * @param sesslist Resuit of session_get_byuser()\n * @param cnt  Number of entries in sess\n */\nvoid\nfree_session_info_list(struct scp_session_info *sesslist, unsigned int cnt);\n\n/**\n * @brief Get the wait objs for the session list module\n * @param robjs Objects array to update\n * @param robjs_count Elements in robjs (by reference)\n * @return 0 for success\n */\nint\nsession_list_get_wait_objs(tbus robjs[], int *robjs_count);\n\n\n/**\n * @brief Check the wait objs for the session list module\n * @return 0 for success\n */\nint\nsession_list_check_wait_objs(void);\n\n#endif // SESSION_LIST_H\n"
  },
  {
    "path": "sesman/sig.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sig.c\n * @brief signal handling functions\n * @author Jay Sorg, Simone Fedele\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"sig.h\"\n\n#include \"sesman_config.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"sesman.h\"\n#include \"session_list.h\"\n#include \"string_calls.h\"\n\n/******************************************************************************/\nvoid\nsig_sesman_reload_cfg(void)\n{\n    int error;\n    struct config_sesman *cfg;\n\n    LOG(LOG_LEVEL_INFO, \"receiving SIGHUP\");\n\n    if ((cfg = config_read(g_cfg->sesman_ini)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error reading config - keeping old cfg\");\n        return;\n    }\n\n    /* Deal with significant config changes */\n    if (g_strcmp(g_cfg->listen_port, cfg->listen_port) != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"sesman listen port changed to %s\",\n            cfg->listen_port);\n        LOG(LOG_LEVEL_WARNING,\n            \"Restarting sesman will now lose active sessions\");\n\n        /* We have to delete the old port before listening to the new one\n         * in case they overlap in scope */\n        sesman_delete_listening_transport();\n        if (sesman_create_listening_transport(cfg) == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"Sesman now listening on %s\",\n                g_cfg->listen_port);\n        }\n    }\n\n    /* free old config data */\n    config_free(g_cfg);\n\n    /* replace old config with newly read one */\n    g_cfg = cfg;\n\n    /* Restart logging subsystem */\n    error = log_start(g_cfg->sesman_ini, \"xrdp-sesman\", LOG_START_RESTART);\n\n    if (error != LOG_STARTUP_OK)\n    {\n        char buf[256];\n\n        switch (error)\n        {\n            case LOG_ERROR_MALLOC:\n                g_printf(\"error on malloc. cannot restart logging. log stops here, sorry.\\n\");\n                break;\n            case LOG_ERROR_FILE_OPEN:\n                g_printf(\"error reopening log file [%s]. log stops here, sorry.\\n\", getLogFile(buf, 255));\n                break;\n        }\n    }\n\n    LOG(LOG_LEVEL_INFO, \"configuration reloaded, log subsystem restarted\");\n}\n"
  },
  {
    "path": "sesman/sig.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sig.h\n * @brief Signal handling function declarations\n * @author Jay Sorg, Simone Fedele\n *\n */\n\n#ifndef SIG_H\n#define SIG_H\n\n/**\n *\n * @brief SIGHUP handling code\n *\n */\nvoid\nsig_sesman_reload_cfg(void);\n\n#endif\n"
  },
  {
    "path": "sesman/startwm.sh",
    "content": "#!/usr/bin/env bash\n#\n# This script is an example. You might need to edit this script\n# depending on your distro if it doesn't work for you.\n#\n# Uncomment the following line for debug:\n# exec xterm\n\n\n# Execution sequence for interactive login shell - pseudocode\n#\n# IF /etc/profile is readable THEN\n#     execute /etc/profile\n# END IF\n# IF ~/.bash_profile is readable THEN\n#     execute ~/.bash_profile\n# ELSE\n#     IF ~/.bash_login is readable THEN\n#         execute ~/.bash_login\n#     ELSE\n#         IF ~/.profile is readable THEN\n#             execute ~/.profile\n#         END IF\n#     END IF\n# END IF\npre_start()\n{\n  if [ -r /etc/profile ]; then\n    . /etc/profile\n  fi\n  if [ -r ~/.bash_profile ]; then\n    . ~/.bash_profile\n  else\n    if [ -r ~/.bash_login ]; then\n      . ~/.bash_login\n    else\n      if [ -r ~/.profile ]; then\n        . ~/.profile\n      fi\n    fi\n  fi\n  return 0\n}\n\n# When logging out from the interactive shell, the execution sequence is:\n#\n# IF ~/.bash_logout exists THEN\n#     execute ~/.bash_logout\n# END IF\npost_start()\n{\n  if [ -r ~/.bash_logout ]; then\n    . ~/.bash_logout\n  fi\n  return 0\n}\n\nget_xdg_session_startupcmd()\n{\n  # If DESKTOP_SESSION is set and valid then the STARTUP command will be taken from there\n  # GDM exports environment variables XDG_CURRENT_DESKTOP and XDG_SESSION_DESKTOP.\n  # This follows it.\n  if [ -n \"$1\" ] && [ -d /usr/share/xsessions ] \\\n    && [ -f \"/usr/share/xsessions/$1.desktop\" ]; then\n    STARTUP=$(grep ^Exec= \"/usr/share/xsessions/$1.desktop\")\n    STARTUP=${STARTUP#Exec=*}\n    XDG_CURRENT_DESKTOP=$(grep ^DesktopNames= \"/usr/share/xsessions/$1.desktop\")\n    XDG_CURRENT_DESKTOP=${XDG_CURRENT_DESKTOP#DesktopNames=*}\n    XDG_CURRENT_DESKTOP=${XDG_CURRENT_DESKTOP//;/:}\n    export XDG_CURRENT_DESKTOP\n    export XDG_SESSION_DESKTOP=\"$DESKTOP_SESSION\"\n  fi\n}\n\n#start the window manager\nwm_start()\n{\n  if [ -r /etc/default/locale ]; then\n    . /etc/default/locale\n    export LANG LANGUAGE\n  fi\n\n  # debian\n  if [ -r /etc/X11/Xsession ]; then\n    pre_start\n\n    # if you want to start preferred desktop environment,\n    # add following line,\n    #  [ -n \"$XRDP_SESSION\" ] && export DESKTOP_SESSION=<your preferred desktop>\n    # in either of following file.\n    # 1. ~/.profile\n    # 2. create a file (any_filename.sh is OK) in /etc/profile.d\n    # <your preferred desktop> shall be one of \"ls -1 /usr/share/xsessions/|cut -d. -f1\"\n    # e.g.  [ -n \"$XRDP_SESSION\" ] && export DESKTOP_SESSION=ubuntu\n\n    # Alternatively, set \"PassShellAsEnv=DESKTOP_SESSION\" in sesman.ini, which\n    # lets the user specify the required session directly.\n\n    # STARTUP is the default startup command.\n    # if $1 is empty and STARTUP was not set\n    # /etc/X11/Xsession.d/50x11-common_determine-startup will fallback to\n    # x-session-manager\n    if [ -z \"$STARTUP\" ] && [ -n \"$DESKTOP_SESSION\" ]; then\n      get_xdg_session_startupcmd \"$DESKTOP_SESSION\"\n    fi\n\n    . /etc/X11/Xsession\n    post_start\n    exit 0\n  fi\n\n  # alpine\n  # Don't use /etc/X11/xinit/Xsession - it doesn't work\n  if [ -f /etc/alpine-release ]; then\n    if [ -f /etc/X11/xinit/xinitrc ]; then\n        pre_start\n        /etc/X11/xinit/xinitrc\n        post_start\n    else\n        echo \"** xinit package isn't installed\" >&2\n        exit 1\n    fi\n  fi\n\n  # el\n  if [ -r /etc/X11/xinit/Xsession ]; then\n    pre_start\n    . /etc/X11/xinit/Xsession\n    post_start\n    exit 0\n  fi\n\n  # suse\n  if [ -r /etc/X11/xdm/Xsession ]; then\n    # since the following script run a user login shell,\n    # do not execute the pseudo login shell scripts\n    . /etc/X11/xdm/Xsession\n    exit 0\n  elif [ -r /usr/etc/X11/xdm/Xsession ]; then\n    . /usr/etc/X11/xdm/Xsession\n    exit 0\n  fi\n\n  pre_start\n  xterm\n  post_start\n}\n\n#. /etc/environment\n#export PATH=$PATH\n#export LANG=$LANG\n\n# change PATH to be what your environment needs usually what is in\n# /etc/environment\n#PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games\"\n#export PATH=$PATH\n\n# for PATH and LANG from /etc/environment\n# pam will auto process the environment file if /etc/pam.d/xrdp-sesman\n# includes\n# auth       required     pam_env.so readenv=1\n\nwm_start\n\nexit 1\n"
  },
  {
    "path": "sesman/tools/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SOCKET_ROOT_PATH=\\\"${socketdir}\\\" \\\n  -I$(top_srcdir)/sesman/libsesman \\\n  -I$(top_srcdir)/common \\\n  -I$(top_srcdir)/libipm\n\nAM_CFLAGS = $(X_CFLAGS)\n\nbin_PROGRAMS = \\\n  xrdp-sesrun \\\n  xrdp-sesadmin \\\n  xrdp-dis\n\nnoinst_PROGRAMS = \\\n  xrdp-authtest \\\n  xrdp-xcon\n\nxrdp_sesrun_SOURCES = \\\n  sesrun.c\n\nxrdp_sesadmin_SOURCES = \\\n  sesadmin.c\n\nxrdp_dis_SOURCES = \\\n  dis.c\n\nxrdp_dis_LDADD = \\\n  $(top_builddir)/common/libcommon.la\n\nxrdp_xcon_SOURCES = \\\n  xcon.c\n\nxrdp_authtest_SOURCES = \\\n  authtest.c\n\nxrdp_sesrun_LDADD = \\\n  $(top_builddir)/sesman/libsesman/libsesman.la \\\n  $(top_builddir)/common/libcommon.la \\\n  $(top_builddir)/libipm/libipm.la\n\nxrdp_sesadmin_LDADD = \\\n  $(top_builddir)/sesman/libsesman/libsesman.la \\\n  $(top_builddir)/common/libcommon.la \\\n  $(top_builddir)/libipm/libipm.la\n\nxrdp_xcon_LDFLAGS = \\\n  $(X_LIBS)\n\nxrdp_xcon_LDADD = \\\n  $(X_PRE_LIBS) -lX11 $(X_EXTRA_LIBS)\n\nxrdp_authtest_LDADD = \\\n  $(top_builddir)/sesman/libsesman/libsesman.la \\\n  $(top_builddir)/common/libcommon.la \\\n  $(top_builddir)/libipm/libipm.la \\\n  $(AUTHMOD_LIB)\n"
  },
  {
    "path": "sesman/tools/authmod.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file authmod.c\n *\n * @brief Pull in the configured authentication module\n *\n * Configured auth module is referenced by the macro define\n * XRDP_AUTHMOD_SRC, defined by the configure system\n *\n * @author Matt Burt\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include XRDP_AUTHMOD_SRC\n"
  },
  {
    "path": "sesman/tools/authtest.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file authtest.c\n * @brief An utility to test the compiled-in authentication module\n * @author Matt Burt\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <unistd.h>\n\n#include \"log.h\"\n#include \"sesman_auth.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n// cppcheck doesn't always set this macro to something in double-quotes\n#if defined(__cppcheck__)\n#undef PACKAGE_VERSION\n#endif\n\n#if !defined(PACKAGE_VERSION)\n#define PACKAGE_VERSION \"???\"\n#endif\n\n#ifndef MAX_PASSWORD_LEN\n#   define MAX_PASSWORD_LEN 512\n#endif\n\n/**\n * Parameters needed to call the auth module\n */\nstruct authmod_params\n{\n    const char *username;\n    char password[MAX_PASSWORD_LEN + 1];\n    const char *command;\n    int start_session;\n};\n\n\n/**************************************************************************//**\n * Prints a brief summary of options and defaults\n */\nstatic void\nusage(void)\n{\n    g_printf(\"xrdp auth module tester v\" PACKAGE_VERSION \"\\n\");\n    g_printf(\"\\n\"\n             \"Calls functions in the compiled-in auth module, so that the\\n\"\n             \"module can be checked simply for functionality, memory leaks,\\n\"\n             \"etc.\\n\\n\"\n             \"This is a DEVELOPER-ONLY tool\\n\");\n    g_printf(\"\\nusage:\\n\");\n    g_printf(\"authtest [options] [username]\\n\\n\");\n    g_printf(\"options:\\n\");\n    g_printf(\"    -p <password>\\n\"\n             \"    -F <file-descriptor>  Read password from this file descriptor\\n\"\n             \"    -c <command>          Start a session and run the\\n\"\n             \"                          specified non-interactive command\\n\"\n             \"                          in it\\n\");\n    g_printf(\"\\nIf username is omitted, the current user is used, and.\\n\"\n             \"a UDS login is attempted\\n\"\n             \"If username is provided, password is needed.\\n\"\n             \"    Password is prompted for if -p or -F are not specified\\n\");\n}\n\n\n/**************************************************************************//**\n * Read a password from a file descriptor\n *\n * @param fd_str string representing file descriptor\n * @param amp Authmod parameter structure for resulting password\n * @return !=0 for success\n */\nstatic int\nread_password_from_fd(const char *fd_str, struct authmod_params *amp)\n{\n    int result = 0;\n    int s = g_file_read(atoi(fd_str), amp->password,\n                        sizeof (amp->password) - 1);\n    if (s < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't read password from fd %s - %s\",\n            fd_str, g_get_strerror());\n        amp->password[0] = '\\0';\n    }\n    else\n    {\n        amp->password[s] = '\\0';\n        if (s > 0 && amp->password[s - 1] == '\\n')\n        {\n            amp->password[s - 1] = '\\0';\n        }\n        result = 1;\n    }\n    return result;\n}\n\n/**************************************************************************//**\n * Parses the program args\n *\n * @param argc Passed to main\n * @param argv Passed to main\n * @param amp Authmod parameter structure for resulting values\n * @return !=0 for success\n */\nstatic int\nparse_program_args(int argc, char *argv[], struct authmod_params *amp)\n{\n    int params_ok = 1;\n    int opt;\n    bool_t password_set = 0;\n\n    amp->username = NULL;\n    amp->password[0] = '\\0';\n    amp->start_session = 0;\n    amp->command = NULL;\n\n    while ((opt = getopt(argc, argv, \"c:p:F:\")) != -1)\n    {\n        switch (opt)\n        {\n            case 'c':\n                if (amp->command)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"Ignoring multiple '%c' options\",\n                        (char)opt);\n                }\n                else\n                {\n                    amp->command = optarg;\n                }\n                break;\n\n            case 'p':\n                if (password_set)\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"Ignoring option '%c' - password already set \",\n                        (char)opt);\n                }\n                else\n                {\n                    g_strncpy(amp->password, optarg, sizeof(amp->password) - 1);\n                    password_set = 1;\n                }\n                break;\n\n            case 'F':\n                if (password_set)\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"Ignoring option '%c' - password already set \",\n                        (char)opt);\n                }\n                else\n                {\n                    if (read_password_from_fd(optarg, amp))\n                    {\n                        password_set = 1;\n                    }\n                    else\n                    {\n                        params_ok = 0;\n                    }\n                }\n                break;\n\n            default:\n                LOG(LOG_LEVEL_ERROR, \"Unrecognised switch '%c'\", (char)opt);\n                params_ok = 0;\n        }\n    }\n\n    if (argc == optind)\n    {\n        // No username was specified\n        if (password_set)\n        {\n            LOG(LOG_LEVEL_WARNING, \"No username - ignoring specified password\");\n            amp->password[0] = '\\0';\n        }\n        amp->username = NULL;\n    }\n    else if ((argc - optind) > 1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unexpected arguments after username\");\n        params_ok = 0;\n    }\n    else\n    {\n        amp->username = argv[optind];\n        if (!password_set)\n        {\n            const char *p = getpass(\"Password: \");\n            if (p == NULL)\n            {\n                params_ok = 0;\n            }\n            else\n            {\n                g_snprintf(amp->password, sizeof(amp->password), \"%s\", p);\n            }\n        }\n    }\n\n    return params_ok;\n}\n\n/******************************************************************************/\n/**\n * Gets the current username for a UDS login\n *\n * Result must be freed after use.\n */\nstatic char *\nget_username()\n{\n    int uid = g_getuid();\n    char *this_user;\n    int status;\n\n    status = g_getuser_info_by_uid(uid, &this_user, NULL, NULL, NULL, NULL);\n    if (status != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't map UID %d to a username\", uid);\n        this_user = NULL;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO, \"Mapped current UID %d to \\\"%s\\\"\",\n            uid, this_user);\n    }\n\n    return this_user;\n}\n\n/******************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    struct log_config *logging;\n    int rv = 0;\n    char *this_user = NULL;\n    struct authmod_params amp;\n\n    logging = log_config_init_for_console(LOG_LEVEL_DEBUG,\n                                          g_getenv(\"AUTHTEST_LOG_LEVEL\"));\n    log_start_from_param(logging);\n    log_config_free(logging);\n\n    if (!parse_program_args(argc, argv, &amp))\n    {\n        usage();\n        rv = 1;\n    }\n    else if (amp.username == NULL && (this_user = get_username()) == NULL)\n    {\n        rv = 1;\n    }\n    else\n    {\n        struct auth_info *auth_info;\n        enum scp_login_status errorcode;\n        char errstr[64];\n\n        if (amp.username == NULL)\n        {\n            auth_info = auth_uds(this_user, &errorcode);\n        }\n        else\n        {\n            auth_info = auth_userpass(amp.username, amp.password,\n                                      NULL, &errorcode);\n        }\n        scp_login_status_to_str(errorcode, errstr, sizeof(errstr));\n        LOG(LOG_LEVEL_INFO,\n            \"auth_userpass() returned %s, errorcode=%d [%s]\",\n            (auth_info == NULL) ? \"NULL\" : \"non-NULL\",\n            (int)errorcode, errstr);\n\n        rv = (int)errorcode;\n        if (auth_info && rv == 0 && amp.command != NULL)\n        {\n            const char *display = \"xrdp-test10\";\n            rv = auth_start_session(auth_info, display);\n            LOG(LOG_LEVEL_INFO, \"auth_start_session(,%s) returned %d\",\n                display, rv);\n            if (rv == 0)\n            {\n                rv = g_system(amp.command);\n                LOG(LOG_LEVEL_INFO, \"command \\\"%s\\\" returned %d\",\n                    amp.command, rv);\n            }\n        }\n        if (auth_info != NULL)\n        {\n            int rv2 = auth_end(auth_info);\n            LOG(LOG_LEVEL_INFO, \"auth_end() returned %d\", rv2);\n            rv = (rv == 0) ? rv2 : rv;\n        }\n    }\n\n    g_free(this_user);\n    log_end();\n\n    return rv;\n}\n"
  },
  {
    "path": "sesman/tools/dis.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <sys/socket.h>\n#include <sys/un.h>\n#include <errno.h>\n\n#include \"xrdp_constants.h\"\n#include \"xrdp_sockets.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\nint main(int argc, char **argv)\n{\n    int sck;\n    char disstr[MAX_DISPLAY_NAME_SIZE];\n    struct sockaddr_un sa;\n    size_t len;\n\n    if (argc != 1)\n    {\n        printf(\"xrdp disconnect utility\\n\");\n        printf(\"run with no parameters to disconnect you xrdp session\\n\");\n        return 0;\n    }\n\n    if (g_get_display_string(disstr, sizeof(disstr)) < 0)\n    {\n        printf(\"Can't find the display from the environment\\n\");\n        return 1;\n    }\n\n    memset(&sa, 0, sizeof(sa));\n    sa.sun_family = AF_UNIX;\n    g_sprintf(sa.sun_path, XRDP_DISCONNECT_STR, g_getuid(), disstr);\n\n    if (access(sa.sun_path, F_OK) != 0)\n    {\n        printf(\"not in an xrdp session\\n\");\n        return 1;\n    }\n\n    if ((sck = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0)\n    {\n        printf(\"socket open error\\n\");\n        return 1;\n    }\n\n    len = sizeof(sa);\n\n    if (sendto(sck, \"sig\", 4, 0, (struct sockaddr *)&sa, len) > 0)\n    {\n        printf(\"message sent ok\\n\");\n    }\n    else\n    {\n        printf(\"message send failed: %s\\n\", strerror(errno));\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "sesman/tools/sesadmin.c",
    "content": "/*\n * sesadmin.c - an sesman administration tool\n * (c) 2008 Simone Fedele\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"trans.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n#include \"scp.h\"\n#include \"scp_sync.h\"\n\n#include <stdio.h>\n#include <unistd.h>\n\n\nchar cmnd[257];\nchar port[257];\n\nstatic int cmndList(struct trans *t);\nstatic int cmndKill(struct trans *t);\nstatic void cmndHelp(void);\n\n\nint main(int argc, char **argv)\n{\n    struct trans *t;\n    //int end;\n    int idx;\n    //int sel;\n    struct log_config *logging;\n    int rv = 1;\n\n    cmnd[0] = '\\0';\n    port[0] = '\\0';\n\n    logging = log_config_init_for_console(LOG_LEVEL_INFO, NULL);\n    log_start_from_param(logging);\n    log_config_free(logging);\n\n    for (idx = 0; idx < argc; idx++)\n    {\n        if (0 == g_strncmp(argv[idx], \"-u=\", 3))\n        {\n            g_printf(\"** Ignoring unused argument '-u'\");\n        }\n        else if (0 == g_strncmp(argv[idx], \"-p=\", 3))\n        {\n            g_printf(\"** Ignoring unused argument '-p'\");\n        }\n        else if (0 == g_strncmp(argv[idx], \"-i=\", 3))\n        {\n            g_strncpy(port, (argv[idx]) + 3, 256);\n        }\n        else if (0 == g_strncmp(argv[idx], \"-c=\", 3))\n        {\n            g_strncpy(cmnd, (argv[idx]) + 3, 256);\n        }\n    }\n\n    if (0 == g_strncmp(cmnd, \"\", 1))\n    {\n        cmndHelp();\n        return 0;\n    }\n\n    t = scp_connect(port, \"xrdp-sesadmin\", NULL);\n\n    if (t == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"scp_connect() error\");\n    }\n    else\n    {\n        /* Log in as the current user */\n        rv = scp_sync_uds_login_request(t);\n    }\n\n    if (rv == 0)\n    {\n        if (0 == g_strncmp(cmnd, \"list\", 5))\n        {\n            rv = cmndList(t);\n        }\n        else if (0 == g_strncmp(cmnd, \"kill:\", 5))\n        {\n            rv = cmndKill(t);\n        }\n    }\n\n    if (rv == 0)\n    {\n        rv = scp_send_close_connection_request(t);\n    }\n    trans_delete(t);\n    log_end();\n\n    return rv;\n}\n\nstatic void\ncmndHelp(void)\n{\n    fprintf(stderr, \"sesadmin - a console sesman administration tool\\n\");\n    fprintf(stderr, \"syntax: sesadmin [] COMMAND [OPTIONS]\\n\\n\");\n    fprintf(stderr, \"-i=<port>    : sesman port (can be defaulted)\\n\");\n    fprintf(stderr, \"-c=<command> : command to execute on the server [MANDATORY]\\n\");\n    fprintf(stderr, \"               it can be one of those:\\n\");\n    fprintf(stderr, \"               list\\n\");\n    fprintf(stderr, \"               kill:<sid>\\n\");\n}\n\nstatic void\nprint_session(const struct scp_session_info *s)\n{\n    char *username;\n    const char *uptr;\n    // Don't need to check error return explicitly - can check username\n    // against NULL\n    (void)g_getuser_info_by_uid(s->uid, &username, NULL, NULL, NULL, NULL);\n    uptr = (username == NULL) ? \"<unknown>\" : username;\n\n    printf(\"Session ID: %d\\n\", s->sid);\n    printf(\"\\tDisplay: %s\\n\", s->display);\n    printf(\"\\tUser: %s\\n\", uptr);\n    printf(\"\\tSession type: %s\\n\", SCP_SESSION_TYPE_TO_STR(s->type));\n    printf(\"\\tScreen size: %dx%d, color depth %d\\n\",\n           s->width, s->height, s->bpp);\n    printf(\"\\tStarted: %s\", ctime(&s->start_time));\n    if (s->start_ip_addr[0] != '\\0')\n    {\n        printf(\"\\tStart IP address: %s\\n\", s->start_ip_addr);\n    }\n    if (s->client_ip[0] != '\\0' && s->client_name[0] != '\\0')\n    {\n        printf(\"\\tConnection state: connected\\n\");\n        printf(\"\\tConnected client IP: %s\\n\", s->client_ip);\n        printf(\"\\tConnected client name: %s\\n\", s->client_name);\n        printf(\"\\tConnection start time: %s\",\n               ctime(&s->last_connect_disconnect));\n    }\n    else\n    {\n        printf(\"\\tConnection state: disconnected\\n\");\n        printf(\"\\tConnection end time: %s\",\n               (s->last_connect_disconnect == 0) ? \"-\\n\" :\n               ctime(&s->last_connect_disconnect));\n    }\n    if (s->xrdp_instance_name[0] != '\\0')\n    {\n        printf(\"\\txrdp instance name: %s\\n\", s->xrdp_instance_name);\n    }\n    g_free(username);\n}\n\nstatic int\ncmndList(struct trans *t)\n{\n    int rv = 1;\n    struct list *sessions = scp_sync_list_sessions_request(t);\n    if (sessions != NULL)\n    {\n        if (sessions->count == 0)\n        {\n            printf(\"No sessions.\\n\");\n        }\n        else\n        {\n            int i;\n            for (i = 0 ; i < sessions->count; ++i)\n            {\n                print_session((struct scp_session_info *)sessions->items[i]);\n            }\n        }\n        (void)scp_send_close_connection_request(t);\n        list_delete(sessions);\n    }\n\n    return rv;\n}\n\nstatic int\ncmndKill(struct trans *t)\n{\n    fprintf(stderr, \"not yet implemented\\n\");\n    return 1;\n}\n"
  },
  {
    "path": "sesman/tools/sesrun.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file sesrun.c\n * @brief An utility to start a session\n * @author Jay Sorg, Simone Fedele\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <unistd.h>\n#include <limits.h>\n#include <ctype.h>\n\n#include \"parse.h\"\n#include \"trans.h\"\n#include \"os_calls.h\"\n#include \"sesman_config.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n#include \"guid.h\"\n\n#include \"scp.h\"\n#include \"scp_sync.h\"\n\n// cppcheck doesn't always set this macro to something in double-quotes\n#if defined(__cppcheck__)\n#undef PACKAGE_VERSION\n#endif\n\n#if !defined(PACKAGE_VERSION)\n#define PACKAGE_VERSION \"???\"\n#endif\n\n#ifndef MAX_PASSWORD_LEN\n#   define MAX_PASSWORD_LEN 512\n#endif\n\n#ifndef DEFAULT_WIDTH\n#   define DEFAULT_WIDTH 1280\n#endif\n\n#ifndef DEFAULT_HEIGHT\n#   define DEFAULT_HEIGHT 1024\n#endif\n\n/* Default setting used by Windows 10 mstsc.exe */\n#ifndef DEFAULT_BPP\n#   define DEFAULT_BPP 32\n#endif\n\n#ifndef DEFAULT_SESSION_TYPE\n#   define DEFAULT_SESSION_TYPE \"Xorg\"\n#endif\n\n/**\n * Maps session type strings session type codes\n */\nstatic struct\n{\n    const char *name;\n    enum scp_session_type type;\n} type_map[] =\n{\n    { \"Xvnc\", SCP_SESSION_TYPE_XVNC},\n    { \"Xvnc-UDS\", SCP_SESSION_TYPE_XVNC_UDS},\n    { \"Xorg\", SCP_SESSION_TYPE_XORG},\n    { NULL, (enum scp_session_type) - 1}\n};\n\n/**\n * Parameters needed for a session\n */\nstruct session_params\n{\n    int width;\n    int height;\n    int bpp;\n    enum scp_session_type session_type;\n\n    const char *directory;\n    const char *shell;\n    const char *ip_addr;\n\n    const char *username;\n    const char *instance_name;\n    char password[MAX_PASSWORD_LEN + 1];\n};\n\n/**************************************************************************//**\n * Maps a string to a session type value\n *\n * @param t session type string\n * @param[out] value session type value\n * @return 0 for success or != 0 if not found\n */\nstatic\nint string_to_session_type(const char *t, enum scp_session_type *value)\n{\n    unsigned int i;\n    for (i = 0 ; type_map[i].name != NULL; ++i)\n    {\n        if (g_strcasecmp(type_map[i].name, t) == 0)\n        {\n            *value = type_map[i].type;\n            return 0;\n        }\n    }\n\n    return 1;\n}\n\n/**************************************************************************//**\n * Returns a list of supported session types\n *\n * Caller supplies a buffer. Buffer handling and buffer overflow detection are\n * the same as snprint()\n *\n * @param buff area for result\n * @param bufflen Size of result\n * @return number of characters for the output string\n */\nstatic\nunsigned int get_session_type_list(char *buff, unsigned int bufflen)\n{\n    unsigned int i;\n    unsigned int ret = 0;\n    const char *sep = \"\";\n\n    for (i = 0 ; type_map[i].name != NULL; ++i)\n    {\n        if (ret < bufflen)\n        {\n            ret += g_snprintf(buff + ret, bufflen - ret,\n                              \"%s%s\", sep, type_map[i].name);\n            sep = \", \";\n        }\n    }\n\n    return ret;\n}\n\n/**************************************************************************//**\n * Prints a brief summary of options and defaults\n */\nstatic void\nusage(void)\n{\n    char sesstype_list[64];\n\n    (void)get_session_type_list(sesstype_list, sizeof(sesstype_list));\n\n    g_printf(\"xrdp session starter v\" PACKAGE_VERSION \"\\n\");\n    g_printf(\"\\nusage:\\n\");\n    g_printf(\"sesrun --help\\n\"\n             \"\\nor\\n\"\n             \"sesrun [options] [username]\\n\\n\");\n    g_printf(\"options:\\n\");\n    g_printf(\"    -g <geometry>         Default:%dx%d\\n\",\n             DEFAULT_WIDTH, DEFAULT_HEIGHT);\n    g_printf(\"    -b <bits-per-pixel>   Default:%d\\n\", DEFAULT_BPP);\n    g_printf(\"    -t <type>             Default:%s\\n\", DEFAULT_SESSION_TYPE);\n    g_printf(\"    -D <directory>        Default: $HOME\\n\"\n             \"    -S <shell>            Default: Defined window manager\\n\"\n             \"    -N <instance-name>    Default: Empty\\n\"\n             \"    -p <password>         TESTING ONLY - DO NOT USE IN PRODUCTION\\n\"\n             \"    -F <file-descriptor>  Read password from this file descriptor\\n\"\n             \"    -c <sesman_ini>       Alternative sesman.ini file\\n\");\n    g_printf(\"\\nSupported types are %s\\n\",\n             sesstype_list);\n    g_printf(\"\\nIf username is omitted, the current user is used.\\n\"\n             \"If username is provided, password is needed.\\n\"\n             \"    Password is prompted for if -p or -F are not specified\\n\");\n    g_printf(\"\\nThe instance name is used to associate the session with an xrdp\\n\"\n             \"\\ndaemon tagged with that particular name.\\n\");\n}\n\n\n/**************************************************************************//**\n * Parses a string <width>x<height>\n *\n * @param geom_str Input string\n * @param sp Session parameter structure for resulting width and height\n * @return !=0 for success\n */\nstatic int\nparse_geometry_string(const char *geom_str, struct session_params *sp)\n{\n    int result = 0;\n    unsigned int sep_count = 0; /* Count of 'x' separators */\n    unsigned int other_count = 0; /* Count of non-digits and non separators */\n    const char *sepp = NULL; /* Pointer to the 'x' */\n    const char *p = geom_str;\n\n    while (*p != '\\0')\n    {\n        if (!isdigit(*p))\n        {\n            if (*p == 'x' || *p == 'X')\n            {\n                ++sep_count;\n                sepp = p;\n            }\n            else\n            {\n                ++other_count;\n            }\n        }\n        ++p;\n    }\n\n    if (sep_count != 1 || other_count > 0 ||\n            sepp == geom_str ||  /* Separator at start of string */\n            sepp == (p - 1) )    /* Separator at end of string */\n    {\n        LOG(LOG_LEVEL_ERROR, \"Invalid geometry string '%s'\", geom_str);\n    }\n    else\n    {\n        sp->width = atoi(geom_str);\n        sp->height = atoi(sepp + 1);\n        result = 1;\n    }\n\n    return result;\n}\n\n\n/**************************************************************************//**\n * Read a password from a file descriptor\n *\n * @param fd_str string representing file descriptor\n * @param sp Session parameter structure for resulting password\n * @return !=0 for success\n */\nstatic int\nread_password_from_fd(const char *fd_str, struct session_params *sp)\n{\n    int result = 0;\n    int s = g_file_read(atoi(fd_str), sp->password, sizeof (sp->password) - 1);\n    if (s < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't read password from fd %s - %s\",\n            fd_str, g_get_strerror());\n        sp->password[0] = '\\0';\n    }\n    else\n    {\n        sp->password[s] = '\\0';\n        if (s > 0 && sp->password[s - 1] == '\\n')\n        {\n            sp->password[s - 1] = '\\0';\n        }\n        result = 1;\n    }\n    return result;\n}\n\n/**************************************************************************//**\n * Parses the program args\n *\n * @param argc Passed to main\n * @param argv Passed to main\n * @param sp Session parameter structure for resulting values\n * @param sesman_ini Pointer to an alternative config file if one is specified\n * @return !=0 for success\n */\nstatic int\nparse_program_args(int argc, char *argv[], struct session_params *sp,\n                   const char **sesman_ini)\n{\n    int params_ok = 1;\n    int opt;\n    bool_t password_set = 0;\n\n    sp->width = DEFAULT_WIDTH;\n    sp->height = DEFAULT_HEIGHT;\n    sp->bpp = DEFAULT_BPP;\n    (void)string_to_session_type(DEFAULT_SESSION_TYPE, &sp->session_type);\n\n    sp->directory = \"\";\n    sp->shell = \"\";\n    sp->ip_addr = \"\";\n    sp->instance_name = \"\";\n\n    sp->username = NULL;\n    sp->password[0] = '\\0';\n\n    while ((opt = getopt(argc, argv, \"g:b:s:t:D:S:p:F:c:N:\")) != -1)\n    {\n        switch (opt)\n        {\n            case 'g':\n                if (!parse_geometry_string(optarg, sp))\n                {\n                    params_ok = 0;\n                }\n                break;\n\n            case 'b':\n                sp->bpp = atoi(optarg);\n                break;\n\n            case 't':\n                if (string_to_session_type(optarg, &sp->session_type) != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Unrecognised session type '%s'\",\n                        optarg);\n                    params_ok = 0;\n                }\n                break;\n\n            case 'D':\n                sp->directory = optarg;\n                break;\n\n            case 'S':\n                sp->shell = optarg;\n                break;\n\n            case 'p':\n                if (password_set)\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"Ignoring option '%c' - password already set \",\n                        (char)opt);\n                }\n                else\n                {\n                    g_strncpy(sp->password, optarg, sizeof(sp->password) - 1);\n                    password_set = 1;\n                }\n                break;\n\n            case 'F':\n                if (password_set)\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"Ignoring option '%c' - password already set \",\n                        (char)opt);\n                }\n                else\n                {\n                    if (read_password_from_fd(optarg, sp))\n                    {\n                        password_set = 1;\n                    }\n                    else\n                    {\n                        params_ok = 0;\n                    }\n                }\n                break;\n\n            case 'N':\n                sp->instance_name = optarg;\n                break;\n\n            case 'c':\n                *sesman_ini = optarg;\n                break;\n\n            default:\n                LOG(LOG_LEVEL_ERROR, \"Unrecognised switch '%c'\", (char)opt);\n                params_ok = 0;\n        }\n    }\n\n    if (argc == optind)\n    {\n        // No username was specified\n        if (password_set)\n        {\n            LOG(LOG_LEVEL_WARNING, \"No username - ignoring specified password\");\n            sp->password[0] = '\\0';\n        }\n        sp->username = NULL;\n    }\n    else if ((argc - optind) > 1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Unexpected arguments after username\");\n        params_ok = 0;\n    }\n    else if (params_ok)\n    {\n        // A username is specified\n        sp->username = argv[optind];\n        if (!password_set)\n        {\n            const char *p = getpass(\"Password: \");\n            if (p == NULL)\n            {\n                params_ok = 0;\n            }\n            else\n            {\n                g_snprintf(sp->password, sizeof(sp->password), \"%s\", p);\n            }\n        }\n    }\n\n    return params_ok;\n}\n\n/**************************************************************************//**\n * Sends an SCP login request\n *\n * A sys login request (i.e. username / password) is used if a username\n * is specified. Otherwise we use a uds login request for the current user.\n *\n * @param t SCP connection\n * @param sp Data for request\n */\nstatic int\nsend_login_request(struct trans *t, const struct session_params *sp)\n{\n    int rv;\n    LOG(LOG_LEVEL_DEBUG, \"ip_addr:\\\"%s\\\"\", sp->ip_addr);\n    if (sp->username != NULL)\n    {\n        /* Only log the password in development builds */\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"password:\\\"%s\\\"\", sp->password);\n\n        rv = scp_send_sys_login_request(t, sp->username,\n                                        sp->password, sp->ip_addr);\n    }\n    else\n    {\n        rv = scp_send_uds_login_request(t);\n    }\n\n    return rv;\n}\n\n/**************************************************************************//**\n * Receives an SCP login response\n *\n * @param t SCP transport to receive reply on\n * @param[out] server_closed != 0 if server has gone away\n * @return 0 for successful authentication\n */\nstatic int\nhandle_login_response(struct trans *t, int *server_closed)\n{\n    enum scp_login_status login_result;\n\n    int rv = scp_sync_wait_specific(t, E_SCP_LOGIN_RESPONSE);\n    if (rv != 0)\n    {\n        *server_closed = 1;\n    }\n    else\n    {\n        rv = scp_get_login_response(t, &login_result, server_closed, NULL);\n        if (rv == 0)\n        {\n            if (login_result != E_SCP_LOGIN_OK)\n            {\n                char msg[256];\n                scp_login_status_to_str(login_result, msg, sizeof(msg));\n                g_printf(\"Login failed; %s\\n\", msg);\n                rv = 1;\n            }\n        }\n        scp_msg_in_reset(t); // Done with this message\n    }\n\n    return rv;\n}\n\n\n/**************************************************************************//**\n * Sends an SCP create session request\n *\n * @param t SCP connection\n * @param sp Data for request\n */\nstatic int\nsend_create_session_request(struct trans *t, const struct session_params *sp)\n{\n    LOG(LOG_LEVEL_DEBUG,\n        \"width:%d  height:%d  bpp:%d  code:%d\\n\"\n        \"directory:\\\"%s\\\" shell:\\\"%s\\\" instance_name:\\\"%s\\\"\",\n        sp->width, sp->height, sp->bpp, sp->session_type,\n        sp->directory, sp->shell, sp->instance_name);\n\n    return scp_send_create_session_request(\n               t, sp->session_type,\n               sp->width, sp->height, sp->bpp, sp->shell,\n               sp->directory, sp->instance_name);\n}\n\n/**************************************************************************//**\n * Receives an SCP create session response\n *\n * @param t SCP transport to receive reply on\n * @return 0 for success\n */\nstatic int\nhandle_create_session_response(struct trans *t)\n{\n    enum scp_screate_status status;\n    const char *display;\n    struct guid guid;\n\n    int rv = scp_sync_wait_specific(t, E_SCP_CREATE_SESSION_RESPONSE);\n    if (rv == 0)\n    {\n        rv = scp_get_create_session_response(t, &status,\n                                             &display, &guid);\n\n        if (rv == 0)\n        {\n            if (status != E_SCP_SCREATE_OK)\n            {\n                char msg[256];\n                scp_screate_status_to_str(status, msg, sizeof(msg));\n                g_printf(\"Connection failed; %s\\n\", msg);\n                rv = 1;\n            }\n            else\n            {\n                char guid_str[GUID_STR_SIZE];\n                g_printf(\"ok display=%s GUID=%s\\n\",\n                         display,\n                         guid_to_str(&guid, guid_str));\n            }\n        }\n        scp_msg_in_reset(t); // Done with this message\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    const char *sesman_ini = XRDP_CFG_PATH \"/sesman.ini\";\n    struct config_sesman *cfg = NULL;\n\n    struct trans *t = NULL;\n    struct session_params sp;\n\n    struct log_config *logging;\n    int rv = 1;\n\n    logging = log_config_init_for_console(LOG_LEVEL_WARNING,\n                                          g_getenv(\"SESRUN_LOG_LEVEL\"));\n    log_start_from_param(logging);\n    log_config_free(logging);\n\n    if (argc == 2 && g_strcmp(argv[1], \"--help\") == 0)\n    {\n        usage();\n        rv = 0;\n    }\n    else if (!parse_program_args(argc, argv, &sp, &sesman_ini))\n    {\n        usage();\n    }\n    else if ((cfg = config_read(sesman_ini)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"error reading config file %s : %s\",\n            sesman_ini, g_get_strerror());\n    }\n    else if (!(t = scp_connect(cfg->listen_port, \"xrdp-sesrun\", NULL)))\n    {\n        LOG(LOG_LEVEL_ERROR, \"connect error - %s\", g_get_strerror());\n    }\n    else\n    {\n        int server_closed = 0;\n        while (!server_closed)\n        {\n            rv = send_login_request(t, &sp);\n            if (rv != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Error sending login request to sesman\");\n                break;\n            }\n\n            rv = handle_login_response(t, &server_closed);\n            if (rv == 0)\n            {\n                break; /* Successful authentication */\n            }\n            if (!server_closed)\n            {\n                const char *p = getpass(\"Password: \");\n                if (p == NULL)\n                {\n                    break;\n                }\n                g_snprintf(sp.password, sizeof(sp.password), \"%s\", p);\n            }\n        }\n\n        if (rv == 0)\n        {\n            if ((rv = send_create_session_request(t, &sp)) == 0)\n            {\n                rv = handle_create_session_response(t);\n                (void)scp_send_close_connection_request(t);\n            }\n        }\n        trans_delete(t);\n    }\n\n    g_memset(sp.password, '\\0', sizeof(sp.password));\n    config_free(cfg);\n    log_end();\n\n    return rv;\n}\n"
  },
  {
    "path": "sesman/tools/xcon.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <errno.h>\n#include <poll.h>\n#include <X11/Xlib.h>\n#include <sys/select.h>\n\nDisplay *g_display = 0;\nint g_x_socket = 0;\n\nint main(int argc, char **argv)\n{\n    int i1;\n    XEvent xevent;\n\n    g_display = XOpenDisplay(0);\n\n    if (g_display == 0)\n    {\n        printf(\"XOpenDisplay failed\\n\");\n        return 0;\n    }\n\n    g_x_socket = XConnectionNumber(g_display);\n\n    while (1)\n    {\n        struct pollfd pollfd;\n        pollfd.fd = g_x_socket;\n        pollfd.events = POLLIN;\n        pollfd.revents = 0;\n        do\n        {\n            i1 = poll(&pollfd, 1, -1);\n        }\n        while (i1 < 0 && errno == EINTR);\n\n        if (i1 < 0)\n        {\n            break;\n        }\n\n        XNextEvent(g_display, &xevent);\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "tests/Makefile.am",
    "content": "\nEXTRA_DIST = \\\n  readme.txt\n\nSUBDIRS = \\\n  common \\\n  libipm \\\n  libxrdp \\\n  memtest \\\n  xrdp\n"
  },
  {
    "path": "tests/common/Makefile.am",
    "content": "\nAM_CPPFLAGS = \\\n  -I$(top_builddir) \\\n  -I$(top_srcdir)/common\n\nLOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \\\n                  $(top_srcdir)/tap-driver.sh\n\nPACKAGE_STRING = \"libcommon\"\n\nTESTS = test_common\ncheck_PROGRAMS = test_common\n\ntest_common_SOURCES = \\\n    test_common.h \\\n    test_common_main.c \\\n    test_fifo_calls.c \\\n    test_list_calls.c \\\n    test_list16_calls.c \\\n    test_parse.c \\\n    test_set_int.c \\\n    test_string_calls.c \\\n    test_string_calls_unicode.c \\\n    test_os_calls.c \\\n    test_os_calls_signals.c \\\n    test_ssl_calls.c \\\n    test_base64.c \\\n    test_guid.c \\\n    test_scancode.c \\\n    test_timers.c\n\ntest_common_CFLAGS = \\\n    @CHECK_CFLAGS@ \\\n    -D TOP_SRCDIR=\\\"$(top_srcdir)\\\"\n\ntest_common_LDADD = \\\n    $(top_builddir)/common/libcommon.la \\\n    @CHECK_LIBS@\n"
  },
  {
    "path": "tests/common/test_base64.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"base64.h\"\n\n#include \"test_common.h\"\n/*\n* These are the example test strings in RFC4648(10)\n*/\nstatic const char *rfc4648_ex1_text = \"\";\nstatic const char *rfc4648_ex1_b64 = \"\";\nstatic const char *rfc4648_ex2_text = \"f\";\nstatic const char *rfc4648_ex2_b64 = \"Zg==\";\nstatic const char *rfc4648_ex3_text = \"fo\";\nstatic const char *rfc4648_ex3_b64 = \"Zm8=\";\nstatic const char *rfc4648_ex4_text = \"foo\";\nstatic const char *rfc4648_ex4_b64 = \"Zm9v\";\nstatic const char *rfc4648_ex5_text = \"foob\";\nstatic const char *rfc4648_ex5_b64 = \"Zm9vYg==\";\nstatic const char *rfc4648_ex6_text = \"fooba\";\nstatic const char *rfc4648_ex6_b64 = \"Zm9vYmE=\";\nstatic const char *rfc4648_ex7_text = \"foobar\";\nstatic const char *rfc4648_ex7_b64 = \"Zm9vYmFy\";\n\n/* Every single valid base64 character, except padding */\nstatic const char *all_b64 =\n    \"ABCDEFGHIJKL\"\n    \"MNOPQRSTUVWX\"\n    \"YZabcdefghij\"\n    \"klmnopqrstuv\"\n    \"wxyz01234567\"\n    \"89+/\";\n\n/* What we should get as binary if we decode this */\nstatic const char all_b64_decoded[] =\n{\n    '\\x00', '\\x10', '\\x83', '\\x10', '\\x51', '\\x87', '\\x20', '\\x92', '\\x8b',\n    '\\x30', '\\xd3', '\\x8f', '\\x41', '\\x14', '\\x93', '\\x51', '\\x55', '\\x97',\n    '\\x61', '\\x96', '\\x9b', '\\x71', '\\xd7', '\\x9f', '\\x82', '\\x18', '\\xa3',\n    '\\x92', '\\x59', '\\xa7', '\\xa2', '\\x9a', '\\xab', '\\xb2', '\\xdb', '\\xaf',\n    '\\xc3', '\\x1c', '\\xb3', '\\xd3', '\\x5d', '\\xb7', '\\xe3', '\\x9e', '\\xbb',\n    '\\xf3', '\\xdf', '\\xbf'\n};\n\nstatic void\ntest_rfc4648_to_b64(const char *plaintext, size_t len, const char *b64)\n{\n    char buff[256];\n    size_t result;\n\n    result = base64_encode(plaintext, len, buff, sizeof(buff));\n    ck_assert_int_eq(result, len);\n    ck_assert_str_eq(buff, b64);\n\n}\n\n/* Text-only encoder wrapper */\nstatic void\ntest_rfc4648_to_b64_text(const char *plaintext, const char *b64)\n{\n    test_rfc4648_to_b64(plaintext, g_strlen(plaintext), b64);\n}\n\n/* Text-only decoder wrapper for valid base64 */\nstatic void\ntest_rfc4648_from_b64_text(const char *b64, const char *text)\n{\n    char buff[256];\n    size_t actual_len;\n    int result;\n\n    result = base64_decode(b64, buff, sizeof(buff), &actual_len);\n    ck_assert_int_eq(result, 0);\n    ck_assert_int_lt(actual_len, sizeof(buff));\n    buff[actual_len] = '\\0';\n    ck_assert_str_eq(buff, text);\n}\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex1_to)\n{\n    test_rfc4648_to_b64_text(rfc4648_ex1_text, rfc4648_ex1_b64);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex1_from)\n{\n    test_rfc4648_from_b64_text(rfc4648_ex1_b64, rfc4648_ex1_text);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex2_to)\n{\n    test_rfc4648_to_b64_text(rfc4648_ex2_text, rfc4648_ex2_b64);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex2_from)\n{\n    test_rfc4648_from_b64_text(rfc4648_ex2_b64, rfc4648_ex2_text);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex3_to)\n{\n    test_rfc4648_to_b64_text(rfc4648_ex3_text, rfc4648_ex3_b64);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex3_from)\n{\n    test_rfc4648_from_b64_text(rfc4648_ex3_b64, rfc4648_ex3_text);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex4_to)\n{\n    test_rfc4648_to_b64_text(rfc4648_ex4_text, rfc4648_ex4_b64);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex4_from)\n{\n    test_rfc4648_from_b64_text(rfc4648_ex4_b64, rfc4648_ex4_text);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex5_to)\n{\n    test_rfc4648_to_b64_text(rfc4648_ex5_text, rfc4648_ex5_b64);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex5_from)\n{\n    test_rfc4648_from_b64_text(rfc4648_ex5_b64, rfc4648_ex5_text);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex6_to)\n{\n    test_rfc4648_to_b64_text(rfc4648_ex6_text, rfc4648_ex6_b64);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex6_from)\n{\n    test_rfc4648_from_b64_text(rfc4648_ex6_b64, rfc4648_ex6_text);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex7_to)\n{\n    test_rfc4648_to_b64_text(rfc4648_ex7_text, rfc4648_ex7_b64);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_rfc4648_ex7_from)\n{\n    test_rfc4648_from_b64_text(rfc4648_ex7_b64, rfc4648_ex7_text);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_all_valid_from)\n{\n    char buff[256];\n    size_t actual_len;\n    int result;\n    char *str_result;\n    char *str_expected;\n\n    result = base64_decode(all_b64, buff, sizeof(buff), &actual_len);\n    ck_assert_int_eq(result, 0);\n    ck_assert_int_eq(actual_len, sizeof(all_b64_decoded));\n    str_result = bin_to_hex(buff, actual_len);\n    str_expected = bin_to_hex(all_b64_decoded, sizeof(all_b64_decoded));\n    ck_assert_str_eq(str_result, str_expected);\n    free(str_result);\n    free(str_expected);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_all_valid_to)\n{\n    char buff[256];\n    size_t result;\n\n    result = base64_encode(all_b64_decoded, sizeof(all_b64_decoded),\n                           buff, sizeof(buff));\n    ck_assert_int_eq(result, sizeof(all_b64_decoded));\n    ck_assert_str_eq(buff, all_b64);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_all_invalid)\n{\n    char buff[256];\n    size_t actual_len;\n    char valid[256] = {0};\n    char encoded[5] = { \"T0sh\" }; /* Decodes to 'OK!' */\n    int result;\n\n    /* Make a note of all the valid b64 characters */\n    unsigned int i = 0;\n    unsigned char c;\n    while ((c = all_b64[i]) != '\\0')\n    {\n        valid[c] = 1;\n        ++i;\n    }\n\n    /* Check the decoder's working on a simple string...*/\n    result = base64_decode(encoded, buff, sizeof(buff), &actual_len);\n    ck_assert_int_eq(result, 0);\n    ck_assert_int_eq(actual_len, 3);\n    buff[actual_len] = '\\0';\n    ck_assert_str_eq(buff, \"OK!\");\n\n    /* Now replace the 1st character with all invalid characters in turn,\n     * and check they're rejected */\n    for (i = 0 ; i < 256; ++i)\n    {\n        if (i != '\\0' && !valid[i]) /* Don't try the string terminator char! */\n        {\n            encoded[0] = i;\n            result = base64_decode(encoded, buff, sizeof(buff), &actual_len);\n            if (result == 0)\n            {\n                ck_abort_msg(\"Character 0x%02x was not rejected\", i);\n            }\n        }\n    }\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_small_buffer_encode)\n{\n    char buff[10 * 4 + 1]; /* Enough space for 10 quanta */\n\n    size_t result;\n\n    result = base64_encode(all_b64_decoded, sizeof(all_b64_decoded),\n                           buff, sizeof(buff));\n    /* Should have read 10 lots of 24 bits from the input */\n    ck_assert_int_eq(result, 10 * 3);\n    ck_assert_str_eq(buff, \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn\");\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_small_buffer_decode)\n{\n    char buff[10]; /* Enough space for 10 chars */\n\n    size_t actual_len;\n    int result;\n    char *str_result;\n    char *str_expected;\n\n    result = base64_decode(all_b64, buff, sizeof(buff), &actual_len);\n    ck_assert_int_eq(result, 0);\n    ck_assert_int_eq(actual_len, sizeof(all_b64_decoded));\n    str_result = bin_to_hex(buff, sizeof(buff));\n    str_expected = bin_to_hex(all_b64_decoded, sizeof(buff));\n    ck_assert_str_eq(str_result, str_expected);\n    free(str_result);\n    free(str_expected);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_add_pad_one)\n{\n    /* Check that a missing trailing '=' is added when decoding */\n    test_rfc4648_from_b64_text(\"Zm8\", \"fo\"); /* RFC4648 example 3 */\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_add_pad_two)\n{\n    /* Check that two missing trailing '=' chars are added when decoding */\n    test_rfc4648_from_b64_text(\"Zg\", \"f\"); /* RFC4648 example 2 */\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_bad_pad)\n{\n    char buff[16];\n    size_t actual_len;\n\n    /* Check all bad quanta with padding chars */\n    static const char *bad_pad[] =\n    {\n        \"=AAA\",\n        \"A=AA\",\n        \"AA=A\",\n        \"==AA\",\n        \"=A=A\",\n        \"=AA=\",\n        \"A==A\",\n        \"A=A=\",\n        \"===A\",\n        \"A===\",\n        NULL\n    };\n    const char **p;\n\n    for (p = bad_pad ; *p != NULL ; ++p)\n    {\n        int result = base64_decode(*p, buff, sizeof(buff), &actual_len);\n        if (result == 0)\n        {\n            ck_abort_msg(\"Padding '%s' was not rejected\", *p);\n        }\n    }\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_b64_concat_pad)\n{\n    const char *src =\n        \"VGVzdA==\"  /* Test */\n        \"IA==\"      /* <space> */\n        \"Y29uY2F0ZW5hdGVk\" /* concatenated */\n        \"IA==\"      /* <space> */\n        \"cGFkZGluZw==\"; /*padding */\n    const char *expected = \"Test concatenated padding\";\n    char buff[64];\n    size_t actual_len;\n    int result;\n\n    result = base64_decode(src, buff, sizeof(buff), &actual_len);\n    ck_assert_int_eq(result, 0);\n    ck_assert_int_eq(actual_len, g_strlen(expected));\n    buff[actual_len] = '\\0';\n    ck_assert_str_eq(buff, expected);\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_base64(void)\n{\n    Suite *s;\n    TCase *tc_b64;\n\n    s = suite_create(\"base64\");\n\n    tc_b64 = tcase_create(\"base64\");\n    suite_add_tcase(s, tc_b64);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex1_to);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex1_from);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex2_to);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex2_from);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex3_to);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex3_from);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex4_to);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex4_from);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex5_to);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex5_from);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex6_to);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex6_from);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex7_to);\n    tcase_add_test(tc_b64, test_b64_rfc4648_ex7_from);\n    tcase_add_test(tc_b64, test_b64_all_valid_from);\n    tcase_add_test(tc_b64, test_b64_all_valid_to);\n    tcase_add_test(tc_b64, test_b64_all_invalid);\n    tcase_add_test(tc_b64, test_b64_small_buffer_encode);\n    tcase_add_test(tc_b64, test_b64_small_buffer_decode);\n    tcase_add_test(tc_b64, test_b64_add_pad_one);\n    tcase_add_test(tc_b64, test_b64_add_pad_two);\n    tcase_add_test(tc_b64, test_b64_bad_pad);\n    tcase_add_test(tc_b64, test_b64_concat_pad);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_common.h",
    "content": "\n#ifndef TEST_COMMON_H\n#define TEST_COMMON_H\n\n#include <check.h>\n\nchar *\nbin_to_hex(const char *input, int length);\n\nSuite *make_suite_test_fifo(void);\nSuite *make_suite_test_list(void);\nSuite *make_suite_test_list16(void);\nSuite *make_suite_test_parse(void);\nSuite *make_suite_test_set_int(void);\nSuite *make_suite_test_string(void);\nSuite *make_suite_test_string_unicode(void);\nSuite *make_suite_test_os_calls(void);\nSuite *make_suite_test_ssl_calls(void);\nSuite *make_suite_test_base64(void);\nSuite *make_suite_test_guid(void);\nSuite *make_suite_test_scancode(void);\nSuite *make_suite_test_timers(void);\n\nTCase *make_tcase_test_os_calls_signals(void);\n\nvoid os_calls_signals_init(void);\nvoid os_calls_signals_deinit(void);\n\n#endif /* TEST_COMMON_H */\n"
  },
  {
    "path": "tests/common/test_common_main.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n\n#include \"log.h\"\n#include \"ssl_calls.h\"\n\n#include \"test_common.h\"\n\n/**\n * Converts a binary buffer to a hexadecimal representation\n *\n * Result must be free'd after use\n */\nchar *\nbin_to_hex(const char *input, int length)\n{\n    int i;\n    char *result = (char *)malloc(length * 2 + 1);\n    if (result != NULL)\n    {\n        char *p = result;\n        const char *hexdigit = \"0123456789abcdef\";\n        for (i = 0 ; i < length ; ++i)\n        {\n            int c = input[i];\n            if (c < 0)\n            {\n                c += 256;\n            }\n            *p++ = hexdigit[ c / 16];\n            *p++ = hexdigit[ c % 16];\n        }\n        *p = '\\0';\n    }\n\n    return result;\n}\n\nint main (void)\n{\n    int number_failed;\n    SRunner *sr;\n\n    sr = srunner_create (make_suite_test_fifo());\n    srunner_add_suite(sr, make_suite_test_list());\n    srunner_add_suite(sr, make_suite_test_list16());\n    srunner_add_suite(sr, make_suite_test_parse());\n    srunner_add_suite(sr, make_suite_test_set_int());\n    srunner_add_suite(sr, make_suite_test_string());\n    srunner_add_suite(sr, make_suite_test_string_unicode());\n    srunner_add_suite(sr, make_suite_test_os_calls());\n    srunner_add_suite(sr, make_suite_test_ssl_calls());\n    srunner_add_suite(sr, make_suite_test_base64());\n    srunner_add_suite(sr, make_suite_test_guid());\n    srunner_add_suite(sr, make_suite_test_scancode());\n    srunner_add_suite(sr, make_suite_test_timers());\n\n    srunner_set_tap(sr, \"-\");\n    /*\n     * Set up console logging */\n    struct log_config *lc = log_config_init_for_console(LOG_LEVEL_INFO, NULL);\n    log_start_from_param(lc);\n    log_config_free(lc);\n    /* Disable stdout buffering, as this can confuse the error\n     * reporting when running in libcheck fork mode */\n    setvbuf(stdout, NULL, _IONBF, 0);\n\n    /* Initialise modules */\n    ssl_init();\n    os_calls_signals_init();\n\n    srunner_run_all (sr, CK_ENV);\n    number_failed = srunner_ntests_failed(sr);\n    srunner_free(sr);\n\n    ssl_finish();\n    os_calls_signals_deinit();\n\n    log_end();\n    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\n}\n"
  },
  {
    "path": "tests/common/test_fifo_calls.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"fifo.h\"\n\n#include \"os_calls.h\"\n#include \"test_common.h\"\n#include \"string_calls.h\"\n\nstatic const char *strings[] =\n{\n    \"one\",\n    \"two\",\n    \"three\",\n    \"four\",\n    \"five\",\n    \"six\",\n    \"seven\",\n    \"eight\",\n    \"nine\",\n    \"ten\",\n    \"eleven\",\n    \"twelve\",\n    NULL\n};\n\n#define LARGE_TEST_SIZE 10000\n\n/******************************************************************************/\n/* Item destructor function for fifo tests involving allocated strings */\nstatic void\nstring_item_destructor(void *item, void *closure)\n{\n    free(item);\n\n    if (closure != NULL)\n    {\n        /* Count the free operation */\n        int *c = (int *)closure;\n        ++(*c);\n    }\n}\n/******************************************************************************/\n\nSTART_TEST(test_fifo__null)\n{\n    struct fifo *f = NULL;\n    void *vp;\n    int status;\n\n    // These calls should not crash!\n    fifo_delete(f, NULL);\n    fifo_clear(f, NULL);\n\n    status = fifo_add_item(f, NULL);\n    ck_assert_int_eq(status, 0);\n\n    vp = fifo_remove_item(f);\n    ck_assert_ptr_eq(vp, NULL);\n\n    status = fifo_is_empty(f);\n    ck_assert_int_eq(status, 1);\n}\n\nEND_TEST\n\nSTART_TEST(test_fifo__simple)\n{\n    struct fifo *f = fifo_create(NULL);\n    ck_assert_ptr_ne(f, NULL);\n\n    int empty = fifo_is_empty(f);\n    ck_assert_int_eq(empty, 1);\n\n    // Check we can't add NULL to the fifo\n    int success = fifo_add_item(f, NULL);\n    ck_assert_int_eq(success, 0);\n\n    // Check we can't remove anything from an empty fifo\n    void *vp = fifo_remove_item(f);\n    ck_assert_ptr_eq(vp, NULL);\n\n    // Add some static strings to the FIFO\n    const char **s;\n    unsigned int n = 0;\n    for (s = &strings[0] ; *s != NULL; ++s)\n    {\n        fifo_add_item(f, (void *)*s);\n        ++n;\n    }\n\n    empty = fifo_is_empty(f);\n    ck_assert_int_eq(empty, 0);\n\n    unsigned int i;\n    for (i = 0 ; i < n ; ++i)\n    {\n        const char *p = (const char *)fifo_remove_item(f);\n        ck_assert_ptr_eq(p, strings[i]);\n    }\n\n    empty = fifo_is_empty(f);\n    ck_assert_int_eq(empty, 1);\n\n    fifo_delete(f, NULL);\n}\nEND_TEST\n\n\nSTART_TEST(test_fifo__strdup)\n{\n    struct fifo *f = fifo_create(string_item_destructor);\n    ck_assert_ptr_ne(f, NULL);\n\n    // Add some dynamically allocated strings to the FIFO\n    const char **s;\n    unsigned int n = 0;\n    for (s = &strings[0] ; *s != NULL; ++s)\n    {\n        int ok = fifo_add_item(f, (void *)strdup(*s));\n        ck_assert_int_eq(ok, 1);\n        ++n;\n    }\n\n    // Delete the fifo, freeing the allocated strings. Check free() is called\n    // the expected number of times.\n    int c = 0;\n    fifo_delete(f, &c);\n    ck_assert_int_eq(c, n);\n}\nEND_TEST\n\nSTART_TEST(test_fifo__large_test_1)\n{\n    struct fifo *f = fifo_create(string_item_destructor);\n    ck_assert_ptr_ne(f, NULL);\n\n    // Fill the fifo with dynamically allocated strings\n    int i;\n    for (i = 0; i < LARGE_TEST_SIZE; ++i)\n    {\n        int ok = fifo_add_item(f, (void *)strdup(\"test item\"));\n        ck_assert_int_eq(ok, 1);\n    }\n\n    // Clear the fifo, checking free is called the expected number of times\n    int c = 0;\n    fifo_clear(f, &c);\n    ck_assert_int_eq(c, LARGE_TEST_SIZE);\n\n    int empty = fifo_is_empty(f);\n    ck_assert_int_eq(empty, 1);\n\n    // Finally delete the fifo, checking free is not called this time\n    c = 0;\n    fifo_delete(f, &c);\n    ck_assert_int_eq(c, 0);\n}\nEND_TEST\n\nSTART_TEST(test_fifo__large_test_2)\n{\n    char buff[64];\n\n    struct fifo *f = fifo_create(string_item_destructor);\n    ck_assert_ptr_ne(f, NULL);\n\n    // Fill the fifo with dynamically allocated strings\n    int i;\n    for (i = 0; i < LARGE_TEST_SIZE; ++i)\n    {\n        g_snprintf(buff, sizeof(buff), \"%d\", i);\n        int ok = fifo_add_item(f, (void *)strdup(buff));\n        ck_assert_int_eq(ok, 1);\n    }\n\n    // Extract all the strings from the fifo, making sure they're\n    // as expected\n    for (i = 0; i < LARGE_TEST_SIZE; ++i)\n    {\n        g_snprintf(buff, sizeof(buff), \"%d\", i);\n        char *s = fifo_remove_item(f);\n        ck_assert_ptr_ne(s, NULL);\n        ck_assert_str_eq(s, buff);\n        free(s);\n    }\n\n    int empty = fifo_is_empty(f);\n    ck_assert_int_eq(empty, 1);\n\n    int c = 0;\n    fifo_delete(f, &c);\n    ck_assert_int_eq(c, 0);\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_fifo(void)\n{\n    Suite *s;\n    TCase *tc_simple;\n\n    s = suite_create(\"Fifo\");\n\n    tc_simple = tcase_create(\"simple\");\n    suite_add_tcase(s, tc_simple);\n    tcase_add_test(tc_simple, test_fifo__null);\n    tcase_add_test(tc_simple, test_fifo__simple);\n    tcase_add_test(tc_simple, test_fifo__strdup);\n    tcase_add_test(tc_simple, test_fifo__large_test_1);\n    tcase_add_test(tc_simple, test_fifo__large_test_2);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_guid.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"guid.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"os_calls.h\"\n\n#include \"test_common.h\"\n\n/******************************************************************************/\n\nSTART_TEST(test_guid_to_str_remotefx)\n{\n    /* setup */\n    char dest[GUID_STR_SIZE];\n    struct guid guid;\n    g_memcpy(guid.g, XR_CODEC_GUID_REMOTEFX, GUID_SIZE);\n\n    /* test */\n    guid_to_str(&guid, dest);\n\n    /* verify */\n    ck_assert_str_eq(dest, \"76772F12-BD72-4463-AFB3-B73C9C6F7886\");\n}\nEND_TEST\n\nSTART_TEST(test_guid_to_str_nscodec)\n{\n\n    /* setup */\n    char dest[GUID_STR_SIZE];\n    struct guid guid;\n    g_memcpy(guid.g, XR_CODEC_GUID_NSCODEC, GUID_SIZE);\n\n    /* test */\n    guid_to_str(&guid, dest);\n\n    /* verify */\n    ck_assert_str_eq(dest, \"CA8D1BB9-000F-154F-589F-AE2D1A87E2D6\");\n}\nEND_TEST\n\nSTART_TEST(test_guid_to_str_ignore)\n{\n    /* setup */\n    char dest[GUID_STR_SIZE];\n    struct guid guid;\n    g_memcpy(guid.g, XR_CODEC_GUID_IGNORE, GUID_SIZE);\n\n    /* test */\n    guid_to_str(&guid, dest);\n\n    /* verify */\n    ck_assert_str_eq(dest, \"0C4351A6-3535-42AE-910C-CDFCE5760B58\");\n}\nEND_TEST\n\nSTART_TEST(test_guid_to_str_random)\n{\n    /* setup */\n    char dest[GUID_STR_SIZE];\n    struct guid guid;\n    unsigned int i;\n    for (i = 0 ; i < 100; ++i)\n    {\n        guid = guid_new();\n        /* test */\n        guid_to_str(&guid, dest);\n\n        /* Check all the '-' signs are in the right places */\n        ck_assert_int_eq(dest[8], '-');\n        ck_assert_int_eq(dest[13], '-');\n        ck_assert_int_eq(dest[18], '-');\n        ck_assert_int_eq(dest[23], '-');\n\n        /* Check the variant is RFC4122 */\n        char c = dest[18 + 1]; /* char after 3rd dash */\n        if (c != '8' && c != '9' && c != 'A' && c != 'B')\n        {\n            ck_abort_msg(\"Generated UUID is not RFC4122 compliant\");\n        }\n\n        /* Check the version is 'randomly generated' */\n        c = dest[13 + 1]; /* char after 2nd dash */\n        if (c != '4')\n        {\n            ck_abort_msg(\"Generated UUID is not RFC4122 randomly-generated\");\n        }\n\n    }\n}\nEND_TEST\n\n/******************************************************************************/\n\nSuite *\nmake_suite_test_guid(void)\n{\n    Suite *s;\n    TCase *tc_guid;\n\n    s = suite_create(\"GUID\");\n\n    tc_guid = tcase_create(\"guid_to_str\");\n    suite_add_tcase(s, tc_guid);\n    tcase_add_test(tc_guid, test_guid_to_str_remotefx);\n    tcase_add_test(tc_guid, test_guid_to_str_nscodec);\n    tcase_add_test(tc_guid, test_guid_to_str_ignore);\n    tcase_add_test(tc_guid, test_guid_to_str_random);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_list16_calls.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"list16.h\"\n\n#include \"os_calls.h\"\n#include \"test_common.h\"\n#include \"string_calls.h\"\n\n#define TEST_LIST16_SIZE 1000\n\nSTART_TEST(test_list16__simple)\n{\n    struct list16 *lst = list16_create();\n    int i;\n    tui16 val;\n    int res;\n    for (i = 0 ; i < TEST_LIST16_SIZE ; ++i)\n    {\n        res = list16_add_item(lst, (tui16)i);\n        ck_assert_int_ne(res, 0);\n    }\n\n    ck_assert_int_eq(lst->count, TEST_LIST16_SIZE);\n    for (i = 0 ; i < TEST_LIST16_SIZE ; ++i)\n    {\n        ck_assert_int_eq(lst->items[i], (tui16)i);\n        // Also check get method\n        val = list16_get_item(lst, i);\n        ck_assert_int_eq(val, (tui16)i);\n    }\n\n    /* Out-of-bounds test */\n    val = list16_get_item(lst, TEST_LIST16_SIZE);\n    ck_assert_int_eq(val, 0);\n\n    i = list16_index_of(lst, 50);\n    ck_assert_int_eq(i, 50);\n\n    list16_remove_item(lst, 10);\n    ck_assert_int_eq(lst->count, TEST_LIST16_SIZE - 1);\n    /* Check values before the deleted item */\n    for (i = 0; i < 10; ++i)\n    {\n        val = list16_get_item(lst, i);\n        ck_assert_int_eq(val, (tui16)i);\n    }\n    /* Check values after the deleted item */\n    for (i = 10; i < lst->count; ++i)\n    {\n        val = list16_get_item(lst, i);\n        ck_assert_int_eq(val, (tui16)(i + 1));\n    }\n\n    list16_insert_item(lst, 10, 10);\n    ck_assert_int_eq(lst->count, TEST_LIST16_SIZE);\n    /* Re-check all values */\n    for (i = 0; i < lst->count; ++i)\n    {\n        val = list16_get_item(lst, i);\n        ck_assert_int_eq(val, (tui16)i);\n    }\n\n    list16_insert_item(lst, 0, 99);\n    ck_assert_int_eq(lst->count, TEST_LIST16_SIZE + 1);\n    val = list16_get_item(lst, 10);\n    ck_assert_int_eq(val, 9);\n\n    list16_clear(lst);\n    ck_assert_int_eq(lst->count, 0);\n    list16_delete(lst);\n}\nEND_TEST\n\n/* Tests stack calls work as expected. Run under valgrind to check memory */\nSTART_TEST(test_list16__stack)\n{\n    int i;\n    int res;\n    struct list16 lst;\n\n    list16_init(&lst);\n    ck_assert_int_eq(lst.count, 0);\n    list16_deinit(&lst);\n    list16_deinit(&lst); // Shouldn't happen, but could result in double-free\n\n    list16_init(&lst);\n    for (i = 0 ; i < TEST_LIST16_SIZE ; ++i)\n    {\n        res = list16_add_item(&lst, (tui16)i);\n        ck_assert_int_ne(res, 0);\n    }\n    ck_assert_int_eq(lst.count, TEST_LIST16_SIZE);\n    list16_deinit(&lst);\n}\n\n/******************************************************************************/\nSuite *\nmake_suite_test_list16(void)\n{\n    Suite *s;\n    TCase *tc_simple;\n\n    s = suite_create(\"List16\");\n\n    tc_simple = tcase_create(\"simple\");\n    suite_add_tcase(s, tc_simple);\n    tcase_add_test(tc_simple, test_list16__simple);\n    tcase_add_test(tc_simple, test_list16__stack);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_list_calls.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"list.h\"\n\n#include \"os_calls.h\"\n#include \"test_common.h\"\n#include \"string_calls.h\"\n\n#define TEST_LIST_SIZE 1000\n\nSTART_TEST(test_list__simple)\n{\n    struct list *lst = list_create();\n    int i;\n    int val;\n    for (i = 0 ; i < TEST_LIST_SIZE ; ++i)\n    {\n        list_add_item(lst, i);\n    }\n\n    ck_assert_int_eq(lst->count, TEST_LIST_SIZE);\n    for (i = 0 ; i < TEST_LIST_SIZE ; ++i)\n    {\n        ck_assert_int_eq(lst->items[i], i);\n        // Also check get method\n        val = list_get_item(lst, i);\n        ck_assert_int_eq(val, i);\n    }\n\n    i = list_index_of(lst, 50);\n    ck_assert_int_eq(i, 50);\n\n    list_remove_item(lst, 10);\n    ck_assert_int_eq(lst->count, TEST_LIST_SIZE - 1);\n    val = list_get_item(lst, 10);\n    ck_assert_int_eq(val, 11);\n\n    list_insert_item(lst, 10, 10);\n    ck_assert_int_eq(lst->count, TEST_LIST_SIZE);\n    val = list_get_item(lst, 10);\n    ck_assert_int_eq(val, 10);\n\n    list_insert_item(lst, 0, 99);\n    ck_assert_int_eq(lst->count, TEST_LIST_SIZE + 1);\n    val = list_get_item(lst, 10);\n    ck_assert_int_eq(val, 9);\n\n    list_clear(lst);\n    ck_assert_int_eq(lst->count, 0);\n    list_delete(lst);\n}\nEND_TEST\n\n// This needs to be run through valgrind to truly check all memory is\n// being de-allocated\nSTART_TEST(test_list__simple_auto_free)\n{\n    struct list *lst = list_create();\n    lst->auto_free = 1;\n\n    int i;\n    for (i = 0 ; i < TEST_LIST_SIZE ; ++i)\n    {\n        char strval[64];\n        g_snprintf(strval, sizeof(strval), \"%d\", i);\n        // Odds, use list_add_item/strdup, evens use list_add_strdup\n        if ((i % 2) != 0)\n        {\n            list_add_item(lst, (tintptr)g_strdup(strval));\n        }\n        else\n        {\n            list_add_strdup(lst, strval);\n        }\n    }\n\n    list_remove_item(lst, 0);\n    list_remove_item(lst, 0);\n    list_remove_item(lst, 0);\n    list_remove_item(lst, 0);\n    list_remove_item(lst, 0);\n    ck_assert_int_eq(lst->count, TEST_LIST_SIZE - 5);\n    list_delete(lst);\n}\nEND_TEST\n\nSTART_TEST(test_list__simple_append_list)\n{\n    int i;\n    struct list *src = list_create();\n    struct list *dst = list_create();\n    src->auto_free = 0;\n    dst->auto_free = 1;\n\n    list_add_item(src, (tintptr)\"6\");\n    list_add_item(src, (tintptr)\"7\");\n    list_add_item(src, (tintptr)\"8\");\n    list_add_item(src, (tintptr)\"9\");\n    list_add_item(src, (tintptr)\"10\");\n    list_add_item(src, (tintptr)\"11\");\n\n    list_add_item(dst, (tintptr)g_strdup(\"0\"));\n    list_add_item(dst, (tintptr)g_strdup(\"1\"));\n    list_add_item(dst, (tintptr)g_strdup(\"2\"));\n    list_add_item(dst, (tintptr)g_strdup(\"3\"));\n    list_add_item(dst, (tintptr)g_strdup(\"4\"));\n    list_add_item(dst, (tintptr)g_strdup(\"5\"));\n\n    list_append_list_strdup(src, dst, 0);\n\n    ck_assert_int_eq(dst->count, 12);\n\n    for (i = 0 ; i < dst->count; ++i)\n    {\n        int val = g_atoi((const char *)list_get_item(dst, i));\n        ck_assert_int_eq(val, i);\n    }\n\n    list_delete(src);\n    list_clear(dst);  // Exercises auto_free code paths in list.c\n    list_delete(dst);\n}\nEND_TEST\n\nSTART_TEST(test_list__simple_strdup_multi)\n{\n    int i;\n    struct list *lst = list_create();\n    lst->auto_free = 1;\n\n    list_add_strdup_multi(lst,\n                          \"0\", \"1\", \"2\", \"3\", \"4\", \"5\",\n                          \"6\", \"7\", \"8\", \"9\", \"10\", \"11\",\n                          LIST_ADD_STRDUP_TERM);\n\n    ck_assert_int_eq(lst->count, 12);\n\n    for (i = 0 ; i < lst->count; ++i)\n    {\n        int val = g_atoi((const char *)list_get_item(lst, i));\n        ck_assert_int_eq(val, i);\n    }\n\n    list_delete(lst);\n}\nEND_TEST\n\nSTART_TEST(test_list__append_fragment)\n{\n    struct list *l = list_create();\n    l->auto_free = 1;\n\n    const char *test_string = \"split this\";\n\n    int fragment_ret = split_string_append_fragment(&test_string,\n                       test_string + 5, l);\n    ck_assert_int_eq(fragment_ret, 1);\n    ck_assert_str_eq((const char *)l->items[0], \"split\");\n\n    fragment_ret = split_string_append_fragment(&test_string,\n                   test_string + 1000, l);\n    ck_assert_int_eq(fragment_ret, 1);\n    ck_assert_str_eq((const char *)l->items[1], \"this\");\n\n    list_delete(l);\n}\nEND_TEST\n\nSTART_TEST(test_list__split_string_into_list)\n{\n    struct list *l = split_string_into_list(\"The fat cat sat on my hat.\", ' ');\n\n    ck_assert_int_eq(l->count, 7);\n    ck_assert_str_eq((const char *)l->items[0], \"The\");\n    ck_assert_str_eq((const char *)l->items[1], \"fat\");\n    ck_assert_str_eq((const char *)l->items[2], \"cat\");\n    ck_assert_str_eq((const char *)l->items[3], \"sat\");\n    ck_assert_str_eq((const char *)l->items[4], \"on\");\n    ck_assert_str_eq((const char *)l->items[5], \"my\");\n    ck_assert_str_eq((const char *)l->items[6], \"hat.\");\n\n    list_delete(l);\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_list(void)\n{\n    Suite *s;\n    TCase *tc_simple;\n\n    s = suite_create(\"List\");\n\n    tc_simple = tcase_create(\"simple\");\n    suite_add_tcase(s, tc_simple);\n    tcase_add_test(tc_simple, test_list__simple);\n    tcase_add_test(tc_simple, test_list__simple_auto_free);\n    tcase_add_test(tc_simple, test_list__simple_append_list);\n    tcase_add_test(tc_simple, test_list__simple_strdup_multi);\n    tcase_add_test(tc_simple, test_list__append_fragment);\n    tcase_add_test(tc_simple, test_list__split_string_into_list);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_os_calls.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <stdlib.h>\n#include <sys/time.h>\n#include <sys/resource.h>\n#include <poll.h>\n#include <errno.h>\n\n#include \"os_calls.h\"\n#include \"list.h\"\n\n#include \"test_common.h\"\n\n#ifndef TOP_SRCDIR\n#define TOP_SRCDIR \".\"\n#endif\n\n// File for testing ro/rw opens\n#define RO_RW_FILE \"./test_ro_rw\"\n\n// Directory for testing files\n#define TEST_READDIR \"./test_readdir\"\n\n/******************************************************************************/\n/***\n * Gets the number of open file descriptors for the current process */\nstatic unsigned int\nget_open_fd_count(void)\n{\n    unsigned int i;\n    unsigned int rv;\n\n    // What's the max number of file descriptors?\n    struct rlimit nofile;\n    if (getrlimit(RLIMIT_NOFILE, &nofile) < 0)\n    {\n        const char *errstr = g_get_strerror();\n        ck_abort_msg(\"Can't create socketpair [%s]\", errstr);\n    }\n\n    struct pollfd *fds =\n        (struct pollfd *)g_malloc(sizeof(struct pollfd) * nofile.rlim_cur, 0);\n    ck_assert_ptr_nonnull(fds);\n\n    for (i = 0 ; i < nofile.rlim_cur; ++i)\n    {\n        fds[i].fd = i;\n        fds[i].events = 0;\n        fds[i].revents = 0;\n    }\n\n    if (poll(fds, nofile.rlim_cur, 0) < 0)\n    {\n        const char *errstr = g_get_strerror();\n        ck_abort_msg(\"Can't poll fds [%s]\", errstr);\n    }\n\n    rv = nofile.rlim_cur;\n    for (i = 0 ; i < nofile.rlim_cur; ++i)\n    {\n        if (fds[i].revents == POLLNVAL)\n        {\n            --rv;\n        }\n    }\n\n    g_free(fds);\n\n    return rv;\n}\n\n/******************************************************************************/\nSTART_TEST(test_g_file_get_size__returns_file_size)\n{\n    unsigned long long size;\n\n    size = g_file_get_size(TOP_SRCDIR \"/xrdp/xrdp256.bmp\");\n    ck_assert_int_eq(size, 49278);\n\n\n    size = g_file_get_size(TOP_SRCDIR \"/xrdp/ad256.bmp\");\n    ck_assert_int_eq(size, 19766);\n\n}\nEND_TEST\n\nSTART_TEST(test_g_file_get_size__1GiB)\n{\n    const char *file = \"./file_1GiB.dat\";\n    unsigned int block_size = 4096;\n    unsigned int block_count = 262144;\n    /* C90 5.2.4.2.1 guarantees long long is at least 64 bits */\n    const long long expected_size =\n        (long long)block_size * block_count;\n    long long size;\n    int system_rv;\n\n    char cmd[256];\n\n    /* Create a sparse file of the expected size with one block of data\n     * at the end */\n    g_snprintf(cmd, sizeof(cmd),\n               \"dd if=/dev/zero of=%s bs=%u seek=%u count=1\",\n               file,\n               block_size,\n               block_count - 1);\n\n    system_rv = system(cmd);\n    size = g_file_get_size(file);\n    g_file_delete(file);\n    ck_assert_int_eq(system_rv, 0);\n    ck_assert_int_eq(size, expected_size);\n}\nEND_TEST\n\nSTART_TEST(test_g_file_get_size__just_less_than_2GiB)\n{\n    const char *file = \"./file_2GiB.dat\";\n    unsigned int block_size = 4096;\n    unsigned int block_count = 524287; /* 4096 * 52428__8__ = 2GiB */\n    /* C90 5.2.4.2.1 guarantees long long is at least 64 bits */\n    const long long expected_size =\n        (long long)block_size * block_count;\n    long long size;\n    int system_rv;\n\n    char cmd[256];\n\n    /* Create a sparse file of the expected size with one block of data\n     * at the end */\n    g_snprintf(cmd, sizeof(cmd),\n               \"dd if=/dev/zero of=%s bs=%u seek=%u count=1\",\n               file,\n               block_size,\n               block_count - 1);\n\n    system_rv = system(cmd);\n    size = g_file_get_size(file);\n    g_file_delete(file);\n    ck_assert_int_eq(system_rv, 0);\n    ck_assert_int_eq(size, expected_size);\n}\nEND_TEST\n\n/* skip these tests until g_file_get_size() supports large files*/\n#if 0\nSTART_TEST(test_g_file_get_size__2GiB)\n{\n    const char *file = \"./file_2GiB.dat\";\n    unsigned int block_size = 4096;\n    unsigned int block_count = 524288;\n    /* C90 5.2.4.2.1 guarantees long long is at least 64 bits */\n    const long long expected_size =\n        (long long)block_size * block_count;\n    long long size;\n    int system_rv;\n\n    char cmd[256];\n\n    /* Create a sparse file of the expected size with one block of data\n     * at the end */\n    g_snprintf(cmd, sizeof(cmd),\n               \"dd if=/dev/zero of=%s bs=%u seek=%u count=1\",\n               file,\n               block_size,\n               block_count - 1);\n\n    system_rv = system(cmd);\n    size = g_file_get_size(file);\n    g_file_delete(file);\n    ck_assert_int_eq(system_rv, 0);\n    ck_assert_int_eq(size, expected_size);\n}\nEND_TEST\n\nSTART_TEST(test_g_file_get_size__5GiB)\n{\n    const char *file = \"./file_5GiB.dat\";\n    unsigned int block_size = 4096;\n    unsigned int block_count = 1310720;\n    /* C90 5.2.4.2.1 guarantees long long is at least 64 bits */\n    const long long expected_size =\n        (long long)block_size * block_count;\n    long long size;\n    int system_rv;\n\n    char cmd[256];\n\n    /* Create a sparse file of the expected size with one block of data\n     * at the end */\n    g_snprintf(cmd, sizeof(cmd),\n               \"dd if=/dev/zero of=%s bs=%u seek=%u count=1\",\n               file,\n               block_size,\n               block_count - 1);\n\n    system_rv = system(cmd);\n    size = g_file_get_size(file);\n    g_file_delete(file);\n    ck_assert_int_eq(system_rv, 0);\n    ck_assert_int_eq(size, expected_size);\n}\nEND_TEST\n#endif\n\n/******************************************************************************/\n/* Test we can write to a file which is opened for write */\nSTART_TEST(test_g_file_rw)\n{\n    const char data[] = \"File data\\n\";\n\n    int fd = g_file_open_rw(RO_RW_FILE);\n    ck_assert(fd >= 0);\n\n    int status = g_file_write(fd, data, sizeof(data) - 1);\n    g_file_close(fd);\n\n    // Assume no signals have occurred\n    ck_assert_int_eq(status, sizeof(data) - 1);\n\n    // Leave file in place for test_g_file_ro\n}\nEND_TEST\n\n/******************************************************************************/\n/* Test we can't write to a file which is opened read only */\nSTART_TEST(test_g_file_ro)\n{\n    const char data[] = \"File data\\n\";\n\n    int fd = g_file_open_ro(RO_RW_FILE);\n    ck_assert(fd >= 0);\n\n    int status = g_file_write(fd, data, sizeof(data) - 1);\n    g_file_close(fd);\n\n    // Write must fail\n    ck_assert_int_lt(status, 0);\n\n    // Tidy-up (not checked)\n    g_file_delete(RO_RW_FILE);\n}\nEND_TEST\n\n/******************************************************************************/\n/* Just test we can set and clear the flag. We don't test its operation */\nSTART_TEST(test_g_file_cloexec)\n{\n    int flag;\n    int devzerofd = g_file_open_ro(\"/dev/zero\");\n    ck_assert(devzerofd >= 0);\n\n    (void)g_file_set_cloexec(devzerofd, 1);\n    flag = g_file_get_cloexec(devzerofd);\n    ck_assert(flag != 0);\n\n    (void)g_file_set_cloexec(devzerofd, 0);\n    flag = g_file_get_cloexec(devzerofd);\n    ck_assert(flag == 0);\n\n    g_file_close(devzerofd);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_g_file_get_open_fds)\n{\n    int fd_count = get_open_fd_count();\n    int i;\n\n    struct list *start_list = g_get_open_fds(0, -1);\n    ck_assert_ptr_ne(start_list, NULL);\n    ck_assert_int_eq(start_list->count, fd_count);\n\n    // Open another file\n    int devzerofd = g_file_open_ro(\"/dev/zero\");\n    ck_assert(devzerofd >= 0);\n\n    // Have we now got one more open file?\n    struct list *open_list = g_get_open_fds(0, -1);\n    ck_assert_ptr_ne(open_list, NULL);\n    ck_assert_int_eq(open_list->count, fd_count + 1);\n\n    // Check the new file is not in the start list, but is in the open list\n    ck_assert_int_lt(list_index_of(start_list, devzerofd), 0);\n    ck_assert_int_ge(list_index_of(open_list, devzerofd), 0);\n\n    g_file_close(devzerofd);\n\n    struct list *finish_list = g_get_open_fds(0, -1);\n    ck_assert_ptr_ne(finish_list, NULL);\n\n    // start list same as finish list?\n    ck_assert_int_eq(finish_list->count, fd_count);\n\n    for (i = 0 ; i < start_list->count; ++i)\n    {\n        ck_assert_int_eq((int)finish_list->items[i],\n                         (int)start_list->items[i]);\n    }\n\n    list_delete(start_list);\n    list_delete(open_list);\n    list_delete(finish_list);\n}\nEND_TEST\n\n\n/******************************************************************************/\nSTART_TEST(test_g_file_is_open)\n{\n    int devzerofd = g_file_open_ro(\"/dev/zero\");\n    ck_assert(devzerofd >= 0);\n\n    // Check open file comes up as open\n    ck_assert_int_ne(g_file_is_open(devzerofd), 0);\n\n    g_file_close(devzerofd);\n\n    // Check the now-closed file no longer registers as open\n    ck_assert_int_eq(g_file_is_open(devzerofd), 0);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_g_sck_fd_passing)\n{\n    int sck[2];\n    char buff[16];\n    int istatus;\n    unsigned int fdcount;\n\n    int devzerofd = g_file_open_ro(\"/dev/zero\");\n    ck_assert(devzerofd >= 0);\n\n    if (g_sck_local_socketpair(sck) != 0)\n    {\n        const char *errstr = g_get_strerror();\n        g_file_close(devzerofd);\n        ck_abort_msg(\"Can't create socketpair [%s]\", errstr);\n    }\n\n    // Pass the fd for /dev/zero to sck[0]...\n    istatus = g_sck_send_fd_set(sck[0], \"?\", 1, &devzerofd, 1);\n    if (istatus != 1)\n    {\n        const char *errstr = g_get_strerror();\n        g_file_close(devzerofd);\n        g_file_close(sck[0]);\n        g_file_close(sck[1]);\n        ck_abort_msg(\"Can't send fd set [%s]\", errstr);\n    }\n\n    // We can now close the fd for /dev/zero, as it's \"in flight\"\n    g_file_close(devzerofd);\n    devzerofd = -1;\n\n    // Read the fd for /dev/zero from sck[1]\n    fdcount = -1;\n    istatus = g_sck_recv_fd_set(sck[1], buff, sizeof(buff),\n                                &devzerofd, 1, &fdcount);\n    if (istatus != 1)\n    {\n        const char *errstr = g_get_strerror();\n        g_file_close(sck[0]);\n        g_file_close(sck[1]);\n        ck_abort_msg(\"Can't receive fd set [%s]\", errstr);\n    }\n\n    // Don't need the socket pair any more\n    g_file_close(sck[0]);\n    g_file_close(sck[1]);\n\n    // We should have got 1 fd back, and received a data byte of '?'\n    if (fdcount != 1)\n    {\n        g_file_close(devzerofd);\n        ck_abort_msg(\"Should have 1 fd, got %u\", fdcount);\n    }\n\n    if (buff[0] != '?')\n    {\n        g_file_close(devzerofd);\n        ck_abort_msg(\"Should have received '?' in buffer\");\n    }\n\n    // Does the fd for /dev/zero work?\n    istatus = g_file_read(devzerofd, buff, 1);\n    if (istatus != 1)\n    {\n        const char *errstr = g_get_strerror();\n        g_file_close(devzerofd);\n        ck_abort_msg(\"Can't read from /dev/zero fd %d [%s]\", devzerofd, errstr);\n    }\n\n    g_file_close(devzerofd);\n\n    ck_assert_int_eq(buff[0], '\\0');\n}\nEND_TEST\n\nSTART_TEST(test_g_sck_fd_overflow)\n{\n    int sck[2];\n    char buff[16];\n    int istatus;\n    unsigned int fdcount;\n    int devzerofd[2];\n\n    // Count the number of file descriptors for the process\n    unsigned int base_fd_count = get_open_fd_count();\n    unsigned int proc_fd_count;\n\n    // Open a couple of file descriptors to /dev/zero\n    devzerofd[0] = g_file_open_ro(\"/dev/zero\");\n    devzerofd[1] = g_file_open_ro(\"/dev/zero\");\n    ck_assert(devzerofd[0] >= 0);\n    ck_assert(devzerofd[1] >= 0);\n    proc_fd_count = get_open_fd_count();\n    ck_assert_int_eq(proc_fd_count, base_fd_count + 2);\n\n    if (g_sck_local_socketpair(sck) != 0)\n    {\n        const char *errstr = g_get_strerror();\n        g_file_close(devzerofd[0]);\n        g_file_close(devzerofd[1]);\n        ck_abort_msg(\"Can't create socketpair [%s]\", errstr);\n    }\n    proc_fd_count = get_open_fd_count();\n    ck_assert_int_eq(proc_fd_count, base_fd_count + 4);\n\n    // Pass the /dev/zero fds to sck[0]...\n    istatus = g_sck_send_fd_set(sck[0], \"?\", 1, devzerofd, 2);\n    if (istatus != 1)\n    {\n        const char *errstr = g_get_strerror();\n        g_file_close(devzerofd[0]);\n        g_file_close(devzerofd[1]);\n        g_file_close(sck[0]);\n        g_file_close(sck[1]);\n        ck_abort_msg(\"Can't send fd set [%s]\", errstr);\n    }\n\n    // We can now close fds for /dev/zero, as  they are \"in flight\"\n    g_file_close(devzerofd[0]);\n    g_file_close(devzerofd[1]);\n    devzerofd[0] = -1;\n    devzerofd[1] = -1;\n    proc_fd_count = get_open_fd_count();\n    ck_assert_int_eq(proc_fd_count, base_fd_count + 2);\n\n    // Read one fd for /dev/zero from sck[1]\n    fdcount = -1;\n    istatus = g_sck_recv_fd_set(sck[1], buff, sizeof(buff),\n                                &devzerofd[0], 1, &fdcount);\n    if (istatus != 1)\n    {\n        const char *errstr = g_get_strerror();\n        g_file_close(sck[0]);\n        g_file_close(sck[1]);\n        ck_abort_msg(\"Can't receive fd set [%s]\", errstr);\n    }\n\n    // We should now have just ONE more file descriptor\n    proc_fd_count = get_open_fd_count();\n    ck_assert_int_eq(proc_fd_count, base_fd_count + 3);\n\n    // Don't need the socket pair any more\n    g_file_close(sck[0]);\n    g_file_close(sck[1]);\n    proc_fd_count = get_open_fd_count();\n    ck_assert_int_eq(proc_fd_count, base_fd_count + 1);\n\n    // Does the fd for /dev/zero work?\n    istatus = g_file_read(devzerofd[0], buff, 1);\n    if (istatus != 1)\n    {\n        const char *errstr = g_get_strerror();\n        g_file_close(devzerofd[0]);\n        ck_abort_msg(\"Can't read from /dev/zero fd %d [%s]\",\n                     devzerofd[0], errstr);\n    }\n    ck_assert_int_eq(buff[0], '\\0');\n\n    g_file_close(devzerofd[0]);\n    proc_fd_count = get_open_fd_count();\n    ck_assert_int_eq(proc_fd_count, base_fd_count);\n}\nEND_TEST\n\n/******************************************************************************/\nstatic int qsort_func_strlist(const void *a, const void *b)\n{\n    return strcmp(*(const char **)a, *(const char **)b);\n}\n\nSTART_TEST(test_g_readdir)\n{\n    int status;\n    const char *entries[] = { \"one\", \"two\", \"three\", \"four\", \"five\", 0};\n    unsigned int count = 0;\n    const char **name;\n\n    // Don't check results of create dir, as we may be re-running this\n    // after a fail\n    (void)g_mkdir(TEST_READDIR);\n    // This should work though\n    status = g_set_current_dir(TEST_READDIR);\n    ck_assert_int_eq(status, 0);\n\n    // Create some files in the directory\n    for (name = entries; *name != NULL; ++name, ++count)\n    {\n        int fd = g_file_open_rw(*name);\n        ck_assert(fd >= 0);\n        g_file_close(fd);\n    }\n\n    // Can we read them, and are there the expected number?\n    struct list *dentries = g_readdir(\".\");\n    ck_assert_ptr_ne(dentries, NULL);\n    ck_assert_ptr_ne(dentries, NULL);\n    ck_assert_int_eq(dentries->count, count);\n\n    // Sort both lists according to the current locale\n    qsort(entries, count, sizeof(entries[0]), qsort_func_strlist);\n    qsort(dentries->items, count, sizeof(dentries->items[0]),\n          qsort_func_strlist);\n\n    // Check both lists are identical\n    int i;\n    for (i = 0 ; i < count; ++i)\n    {\n        ck_assert_str_eq(entries[i], (const char *)dentries->items[i]);\n    }\n\n    // Clean up\n    list_delete(dentries);\n    for (i = 0 ; i < count ; ++i)\n    {\n        g_file_delete(entries[i]);\n    }\n    g_set_current_dir(\"..\");\n    status = g_remove_dir(TEST_READDIR); // Returns a boolean(?)\n    ck_assert_int_ne(status, 0);\n\n\n}\nEND_TEST\n\nSTART_TEST(test_g_readdir_not_dir)\n{\n    struct list *dentries = g_readdir(\"NoSuchDirectory\");\n    ck_assert_ptr_eq(dentries, 0);\n    ck_assert_int_eq(errno, ENOENT);\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_os_calls(void)\n{\n    Suite *s;\n    TCase *tc_os_calls;\n\n    s = suite_create(\"OS-Calls\");\n\n    tc_os_calls = tcase_create(\"oscalls-file\");\n    suite_add_tcase(s, tc_os_calls);\n    tcase_add_test(tc_os_calls, test_g_file_get_size__returns_file_size);\n    tcase_add_test(tc_os_calls, test_g_file_get_size__1GiB);\n    tcase_add_test(tc_os_calls, test_g_file_get_size__just_less_than_2GiB);\n#if 0\n    tcase_add_test(tc_os_calls, test_g_file_get_size__2GiB);\n    tcase_add_test(tc_os_calls, test_g_file_get_size__5GiB);\n#endif\n    tcase_add_test(tc_os_calls, test_g_file_rw);\n    tcase_add_test(tc_os_calls, test_g_file_ro); // Must follow test_g_file_rw\n    tcase_add_test(tc_os_calls, test_g_file_cloexec);\n    tcase_add_test(tc_os_calls, test_g_file_get_open_fds);\n    tcase_add_test(tc_os_calls, test_g_file_is_open);\n    tcase_add_test(tc_os_calls, test_g_sck_fd_passing);\n    tcase_add_test(tc_os_calls, test_g_sck_fd_overflow);\n    tcase_add_test(tc_os_calls, test_g_readdir);\n    tcase_add_test(tc_os_calls, test_g_readdir_not_dir);\n\n    // Add other test cases in other files\n    suite_add_tcase(s, make_tcase_test_os_calls_signals());\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_os_calls_signals.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <signal.h>\n\n#include \"os_calls.h\"\n\n#include \"test_common.h\"\n\nstatic tintptr g_wobj1 = 0;\n\n/******************************************************************************/\nvoid\nos_calls_signals_init(void)\n{\n    g_wobj1 = g_create_wait_obj(\"\");\n}\n\n/******************************************************************************/\nvoid\nos_calls_signals_deinit(void)\n{\n    g_delete_wait_obj(g_wobj1);\n    g_wobj1 = 0;\n}\n\n/******************************************************************************/\n/**\n * Set the global wait object g_wobj1\n */\nstatic void\nset_wobj1(int signum)\n{\n    g_set_wait_obj(g_wobj1);\n}\n\n/******************************************************************************/\n/**\n * Sends a number of signals to the process and checks they are all delivered\n *\n * @param sig Signal number\n * @param count Number of signals to send\n *\n * The caller is expected to establish a signal handler before this call\n * which sets the global g_wobj1 on signal delivery */\n\nstatic\nvoid send_multiple_signals(int sig, unsigned int count)\n{\n    while (count-- > 0)\n    {\n        g_reset_wait_obj(g_wobj1);\n        ck_assert_int_eq(g_is_wait_obj_set(g_wobj1), 0);\n        // Expect the signal to be delivered synchronously\n        raise(sig);\n        ck_assert_int_ne(g_is_wait_obj_set(g_wobj1), 0);\n    }\n}\n\n/******************************************************************************/\nSTART_TEST(test_g_set_alarm)\n{\n    g_reset_wait_obj(g_wobj1);\n    ck_assert_int_eq(g_is_wait_obj_set(g_wobj1), 0);\n\n    g_set_alarm(set_wobj1, 1);\n\n    g_obj_wait(&g_wobj1, 1, NULL, 0, 2000);\n\n    ck_assert_int_ne(g_is_wait_obj_set(g_wobj1), 0);\n\n    // Clean up\n    g_set_alarm(NULL, 0);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_g_signal_child_stop_1)\n{\n    struct proc_exit_status e;\n\n    g_reset_wait_obj(g_wobj1);\n    ck_assert_int_eq(g_is_wait_obj_set(g_wobj1), 0);\n\n    g_signal_child_stop(set_wobj1);\n\n    int pid = g_fork();\n\n    if (pid == 0)\n    {\n        g_exit(45);\n    }\n    ck_assert_int_ne(pid, 0);\n    g_obj_wait(&g_wobj1, 1, NULL, 0, 2000);\n    ck_assert_int_ne(g_is_wait_obj_set(g_wobj1), 0);\n\n    e = g_waitpid_status(pid);\n\n    ck_assert_int_eq(e.reason, E_PXR_STATUS_CODE);\n    ck_assert_int_eq(e.val, 45);\n\n    // Try another one to make sure the signal handler is still in place.\n    // This one can generate a signal\n    g_reset_wait_obj(g_wobj1);\n\n    pid = g_fork();\n    if (pid == 0)\n    {\n        // Before raising the signal, change directory to a non-writeable\n        // one to avoid generating a corefile.\n        g_set_current_dir(\"/\");\n        raise(SIGUSR2);\n    }\n    ck_assert_int_ne(pid, 0);\n    g_obj_wait(&g_wobj1, 1, NULL, 0, 2000);\n    ck_assert_int_ne(g_is_wait_obj_set(g_wobj1), 0);\n\n    e = g_waitpid_status(pid);\n\n    ck_assert_int_eq(e.reason, E_PXR_SIGNAL);\n    ck_assert_int_eq(e.val, SIGUSR2);\n\n    // Clean up\n    g_signal_child_stop(NULL);\n}\nEND_TEST\n\n/******************************************************************************/\n/* Checks that multiple children finishing do not interrupt\n * g_waitpid_status() */\nSTART_TEST(test_g_signal_child_stop_2)\n{\n#define CHILD_COUNT 20\n    int pids[CHILD_COUNT];\n    unsigned int i;\n\n    struct proc_exit_status e;\n\n    g_reset_wait_obj(g_wobj1);\n    ck_assert_int_eq(g_is_wait_obj_set(g_wobj1), 0);\n\n    g_signal_child_stop(set_wobj1);\n\n    for (i = 0 ; i < CHILD_COUNT; ++i)\n    {\n        int pid = g_fork();\n        if (pid == 0)\n        {\n            g_sleep((i + 1) * 100);\n            g_exit(i + 1);\n        }\n        ck_assert_int_ne(pid, 0);\n        pids[i] = pid;\n    }\n    g_obj_wait(&g_wobj1, 1, NULL, 0, 2000);\n    ck_assert_int_ne(g_is_wait_obj_set(g_wobj1), 0);\n\n    for (i = 0 ; i < CHILD_COUNT; ++i)\n    {\n        e = g_waitpid_status(pids[i]);\n        ck_assert_int_eq(e.reason, E_PXR_STATUS_CODE);\n        ck_assert_int_eq(e.val, (i + 1));\n    }\n\n    // Clean up\n    g_signal_child_stop(NULL);\n#undef CHILD_COUNT\n}\nEND_TEST\n\n\n/******************************************************************************/\nSTART_TEST(test_g_signal_segfault)\n{\n    g_signal_segfault(set_wobj1);\n\n    // Only one signal can be received in this way. After handling\n    // the signal the handler should be automatically reset.\n    send_multiple_signals(SIGSEGV, 1);\n\n    g_signal_segfault(NULL);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_g_signal_hang_up)\n{\n    g_signal_hang_up(set_wobj1);\n\n    send_multiple_signals(SIGHUP, 5);\n\n    g_signal_hang_up(NULL);\n}\n\n/******************************************************************************/\nSTART_TEST(test_g_signal_user_interrupt)\n{\n    g_signal_user_interrupt(set_wobj1);\n\n    send_multiple_signals(SIGINT, 5);\n\n    g_signal_user_interrupt(NULL);\n}\n\n/******************************************************************************/\nSTART_TEST(test_g_signal_terminate)\n{\n    g_signal_terminate(set_wobj1);\n\n    send_multiple_signals(SIGTERM, 5);\n\n    g_signal_terminate(NULL);\n}\n\n/******************************************************************************/\nSTART_TEST(test_g_signal_pipe)\n{\n    g_signal_pipe(set_wobj1);\n\n    send_multiple_signals(SIGPIPE, 5);\n\n    g_signal_pipe(NULL);\n}\n\n/******************************************************************************/\nSTART_TEST(test_g_signal_usr1)\n{\n    g_signal_usr1(set_wobj1);\n\n    send_multiple_signals(SIGUSR1, 5);\n\n    g_signal_usr1(NULL);\n}\n\n/******************************************************************************/\nSTART_TEST(test_waitpid_not_interrupted_by_sig)\n{\n    /* Start a child which waits 3 seconds and exits */\n    int child_pid = g_fork();\n    if (child_pid == 0)\n    {\n        g_sleep(3000);\n        g_exit(42);\n    }\n\n    /* Set an alarm for 1 second's time */\n    g_reset_wait_obj(g_wobj1);\n    g_set_alarm(set_wobj1, 1);\n\n    struct proc_exit_status e = g_waitpid_status(child_pid);\n    // We should have had the alarm...\n    ck_assert_int_ne(g_is_wait_obj_set(g_wobj1), 0);\n\n    // ..and got the status of the child\n    ck_assert_int_eq(e.reason, E_PXR_STATUS_CODE);\n    ck_assert_int_eq(e.val, 42);\n\n    // Clean up\n    g_set_alarm(NULL, 0);\n}\n\n/******************************************************************************/\nTCase *\nmake_tcase_test_os_calls_signals(void)\n{\n    TCase *tc = tcase_create(\"oscalls-signals\");\n\n    tcase_add_test(tc, test_g_set_alarm);\n    tcase_add_test(tc, test_g_signal_child_stop_1);\n    tcase_add_test(tc, test_g_signal_child_stop_2);\n    tcase_add_test(tc, test_g_signal_segfault);\n    tcase_add_test(tc, test_g_signal_hang_up);\n    tcase_add_test(tc, test_g_signal_user_interrupt);\n    tcase_add_test(tc, test_g_signal_terminate);\n    tcase_add_test(tc, test_g_signal_pipe);\n    tcase_add_test(tc, test_g_signal_usr1);\n    tcase_add_test(tc, test_waitpid_not_interrupted_by_sig);\n\n    return tc;\n}\n"
  },
  {
    "path": "tests/common/test_parse.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"parse.h\"\n\n#include \"test_common.h\"\n\n#define ELEMENTS(x) (sizeof(x) / sizeof(x[0]))\n\nstatic const char\nutf8_simple_test_with_emoji[] =\n    \"Simple Test.\"\n    \"\\xf0\\x9f\\x98\\xa5\"; // U+1F625 Disappointed But Relieved Face\n\nstatic const char16_t\nutf16_simple_test_with_emoji[] =\n{\n    'S', 'i', 'm', 'p', 'l', 'e', ' ', 'T', 'e', 's', 't', '.',\n    0xd83d, 0xde25, // U+1F625\n    0 // terminator\n};\n\n/******************************************************************************/\nSTART_TEST(test_out_utf8_as_utf16_le)\n{\n    struct stream *s;\n    make_stream(s);\n    init_stream(s, 8192);\n    out_utf8_as_utf16_le(s, utf8_simple_test_with_emoji,\n                         sizeof(utf8_simple_test_with_emoji)); // Include term\n    s_mark_end(s);\n\n    // Rewind the stream\n    s->p = s->data;\n    unsigned int i;\n\n    for (i = 0; i < ELEMENTS(utf16_simple_test_with_emoji); ++i)\n    {\n        char16_t val;\n        in_uint16_le(s, val);\n        if (val != utf16_simple_test_with_emoji[i])\n        {\n            ck_abort_msg(\"test_out_utf8_as_utf16_le: \"\n                         \"Index %u expected %x, got %x\",\n                         i, utf16_simple_test_with_emoji[i], val);\n        }\n    }\n\n    ck_assert_int_eq(s_check_end(s), 1);\n\n    free_stream(s);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_in_utf16_le_fixed_as_utf8)\n{\n    struct stream *s;\n    make_stream(s);\n    init_stream(s, 8192);\n\n    // Write the stream without a terminator\n    unsigned int i;\n    for (i = 0; i < ELEMENTS(utf16_simple_test_with_emoji) - 1; ++i)\n    {\n        out_uint16_le(s, utf16_simple_test_with_emoji[i]);\n    }\n    s_mark_end(s);\n\n    // Rewind the stream\n    s->p = s->data;\n\n    char buff[256];\n    unsigned int len;\n\n    // Check the length call\n    len = in_utf16_le_fixed_as_utf8_length(s, i);\n    ck_assert_int_eq(len, sizeof(utf8_simple_test_with_emoji));\n\n    // Now read the string, checking for the same length\n    unsigned int read_len;\n    read_len = in_utf16_le_fixed_as_utf8(s, i, buff, sizeof(buff));\n    ck_assert_int_eq(len, read_len);\n\n    // Should be at the end of the buffer\n    ck_assert_int_eq(s_check_end(s), 1);\n\n    // Check the contents are as expected\n    int cmp = memcmp(buff, utf8_simple_test_with_emoji,\n                     sizeof(utf8_simple_test_with_emoji));\n    ck_assert_int_eq(cmp, 0);\n\n    free_stream(s);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_in_utf16_le_terminated_as_utf8)\n{\n    struct stream *s;\n    make_stream(s);\n    init_stream(s, 8192);\n\n    // Write the stream with the terminator\n    unsigned int i;\n    for (i = 0; i < ELEMENTS(utf16_simple_test_with_emoji); ++i)\n    {\n        out_uint16_le(s, utf16_simple_test_with_emoji[i]);\n    }\n    s_mark_end(s);\n\n    // Rewind the stream\n    s->p = s->data;\n\n    char buff[256];\n    unsigned int len;\n\n    // Check the length call\n    len = in_utf16_le_terminated_as_utf8_length(s);\n    ck_assert_int_eq(len, sizeof(utf8_simple_test_with_emoji));\n\n    // Now read the string, checking for the same length\n    unsigned int read_len;\n    read_len = in_utf16_le_terminated_as_utf8(s, buff, sizeof(buff));\n    ck_assert_int_eq(len, read_len);\n\n    // Should be at the end of the buffer\n    ck_assert_int_eq(s_check_end(s), 1);\n\n    // Check the contents are as expected\n    int cmp = memcmp(buff, utf8_simple_test_with_emoji,\n                     sizeof(utf8_simple_test_with_emoji));\n    ck_assert_int_eq(cmp, 0);\n\n    free_stream(s);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_in_utf16_le_significant_chars)\n{\n    struct stream *s;\n    make_stream(s);\n    init_stream(s, 8192);\n\n    const struct\n    {\n        struct\n        {\n            char16_t high; // Set to 0 for a single UTF-16 word\n            char16_t low;\n        } pair;\n        char32_t expected;\n    } tests[] =\n    {\n        // Single high surrogates are bad\n        { { 0, 0xd800 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xdbff }, UCS_REPLACEMENT_CHARACTER },\n        // Single low surrogates are bad\n        { { 0, 0xdc00 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xdfff }, UCS_REPLACEMENT_CHARACTER },\n        // Values before and after surrogate range\n        { { 0, 0xd7ff }, 0xd7ff },\n        { { 0, 0xe000 }, 0xe000 },\n        // First and last non-surrogate pair values (don't use\n        // 0xfffe and 0xffff for this test as they are non-characters,\n        // and 0xfffd is the replacement character)\n        { { 0, 0 }, 0 },\n        { { 0, 0xfffc }, 0xfffc },\n        { { 0, 0xfffd }, UCS_REPLACEMENT_CHARACTER },\n        // First and last surrogate pair values (don't use\n        // 0x10fffe and 0x10ffff for this test as they are non-characters)\n        { { 0xd800, 0xdc00 }, 0x10000 },\n        { { 0xdbff, 0xdffd }, 0x10fffd },\n        // End-of-plane non-characters (BMP) and the characters before them\n        { { 0xd83f, 0xdffd }, 0x1fffd },\n        { { 0xd83f, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+1FFFE\n        { { 0xd83f, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+1FFFF\n        { { 0xd87f, 0xdffd }, 0x2fffd },\n        { { 0xd87f, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+2FFFE\n        { { 0xd87f, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+2FFFF\n        { { 0xd8bf, 0xdffd }, 0x3fffd },\n        { { 0xd8bf, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+3FFFE\n        { { 0xd8bf, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+3FFFF\n        { { 0xd8ff, 0xdffd }, 0x4fffd },\n        { { 0xd8ff, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+4FFFE\n        { { 0xd8ff, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+4FFFF\n        { { 0xd93f, 0xdffd }, 0x5fffd },\n        { { 0xd93f, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+5FFFE\n        { { 0xd93f, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+5FFFF\n        { { 0xd97f, 0xdffd }, 0x6fffd },\n        { { 0xd97f, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+6FFFE\n        { { 0xd97f, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+6FFFF\n        { { 0xd9bf, 0xdffd }, 0x7fffd },\n        { { 0xd9bf, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+7FFFE\n        { { 0xd9bf, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+7FFFF\n        { { 0xd9ff, 0xdffd }, 0x8fffd },\n        { { 0xd9ff, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+8FFFE\n        { { 0xd9ff, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+8FFFF\n        { { 0xda3f, 0xdffd }, 0x9fffd },\n        { { 0xda3f, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+9FFFE\n        { { 0xda3f, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+9FFFF\n        { { 0xda7f, 0xdffd }, 0xafffd },\n        { { 0xda7f, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+AFFFE\n        { { 0xda7f, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+AFFFF\n        { { 0xdabf, 0xdffd }, 0xbfffd },\n        { { 0xdabf, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+BFFFE\n        { { 0xdabf, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+BFFFF\n        { { 0xdaff, 0xdffd }, 0xcfffd },\n        { { 0xdaff, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+CFFFE\n        { { 0xdaff, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+CFFFF\n        { { 0xdb3f, 0xdffd }, 0xdfffd },\n        { { 0xdb3f, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+DFFFE\n        { { 0xdb3f, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+DFFFF\n        { { 0xdb7f, 0xdffd }, 0xefffd },\n        { { 0xdb7f, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+EFFFE\n        { { 0xdb7f, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+EFFFF\n        { { 0xdbbf, 0xdffd }, 0xffffd },\n        { { 0xdbbf, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+FFFFE\n        { { 0xdbbf, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+FFFFF\n        { { 0xdbff, 0xdffd }, 0x10fffd },\n        { { 0xdbff, 0xdffe }, UCS_REPLACEMENT_CHARACTER }, // U+10FFFE\n        { { 0xdbff, 0xdfff }, UCS_REPLACEMENT_CHARACTER }, // U+10FFFF\n        // Non-characters in \"Arabic Presentation Forms-A\"\n        { { 0, 0xfdd0 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdd1 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdd2 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdd3 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdd4 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdd5 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdd6 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdd7 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdd8 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdd9 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdda }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfddb }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfddc }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfddd }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdde }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfddf }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde0 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde1 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde2 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde3 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde4 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde5 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde6 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde7 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde8 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfde9 }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdea }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdeb }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdec }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfded }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdee }, UCS_REPLACEMENT_CHARACTER },\n        { { 0, 0xfdef }, UCS_REPLACEMENT_CHARACTER }\n    };\n\n    unsigned int i;\n    for (i = 0; i < ELEMENTS(tests); ++i)\n    {\n        char buff[256];\n        unsigned int word_count;\n        init_stream(s, 8192);\n\n        word_count = 0;\n        if (tests[i].pair.high != 0)\n        {\n            out_uint16_le(s, tests[i].pair.high);\n            ++word_count;\n        }\n        out_uint16_le(s, tests[i].pair.low);\n        ++word_count;\n        s_mark_end(s);\n\n        // Rewind the stream\n        s->p = s->data;\n\n        // Read in one UTF-16 LE character as UTF-32\n        in_utf16_le_fixed_as_utf8(s, word_count, buff, sizeof(buff));\n        const char *p = buff;\n        char32_t c32 = utf8_get_next_char(&p, NULL);\n\n        if (c32 != tests[i].expected)\n        {\n            ck_abort_msg(\"test_in_utf16_le_significant_chars: \"\n                         \"Index %u for {%x, %x}, expected %x, got %x\",\n                         i,  tests[i].pair.high, tests[i].pair.low,\n                         tests[i].expected, c32);\n        }\n    }\n\n    free_stream(s);\n}\nEND_TEST\n\n/******************************************************************************/\n\nSuite *\nmake_suite_test_parse(void)\n{\n    Suite *s;\n    TCase *tc_unicode;\n\n    s = suite_create(\"Parse\");\n\n    tc_unicode = tcase_create(\"Unicode\");\n    suite_add_tcase(s, tc_unicode);\n    tcase_add_test(tc_unicode, test_out_utf8_as_utf16_le);\n    tcase_add_test(tc_unicode, test_in_utf16_le_fixed_as_utf8);\n    tcase_add_test(tc_unicode, test_in_utf16_le_terminated_as_utf8);\n    tcase_add_test(tc_unicode, test_in_utf16_le_significant_chars);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_scancode.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"scancode.h\"\n\n#include \"test_common.h\"\n\n// Max supported scancode value\n#define MAX_SUPPORTED_SCANCODE 0x2ff\n\n// Checks conversions to-and-from scancode indexes\nSTART_TEST(test_scancode__scancode_to_index)\n{\n    int i;\n    // In the range 0x00 - 0x7f, scancodes are the same as indexes\n    for (i = 0x0; i <= 0x7f; ++i)\n    {\n        ck_assert_int_eq(scancode_to_index(i), i);\n        ck_assert_int_eq(scancode_from_index(i), i);\n    }\n\n    // Scancodes from 0x80 - 0xff are not supported\n    for (i = 0x80; i <= 0xff; ++i)\n    {\n        ck_assert_int_eq(scancode_to_index(i), -1);\n    }\n\n    // 0x100 - 0x177 map to 0x80 - 0xf7\n    for (i = 0x100; i <= 0x177; ++i)\n    {\n        ck_assert_int_eq(scancode_to_index(i), i - 0x80);\n        ck_assert_int_eq(scancode_from_index(i - 0x80), i);\n    }\n\n    // Scancodes from 0x178 - 0x1ff are not supported\n    for (i = 0x178; i <= 0x1ff; ++i)\n    {\n        ck_assert_int_eq(scancode_to_index(i), -1);\n    }\n\n    // In the range 0x200 up, only SCANCODE_PAUSE_KEY is\n    // supported\n    ck_assert_int_ge(SCANCODE_PAUSE_KEY, 0x200);\n    ck_assert_int_le(SCANCODE_PAUSE_KEY, MAX_SUPPORTED_SCANCODE);\n    for (i = 0x200; i <= MAX_SUPPORTED_SCANCODE; ++i)\n    {\n        if (i == SCANCODE_PAUSE_KEY)\n        {\n            ck_assert_int_eq(scancode_to_index(i), SCANCODE_INDEX_PAUSE_KEY);\n            ck_assert_int_eq(scancode_from_index(SCANCODE_INDEX_PAUSE_KEY), i);\n        }\n        else\n        {\n            ck_assert_int_eq(scancode_to_index(i), -1);\n        }\n    }\n}\n\n// Checks all returned evdev scancodes are mapped to a keycode\nSTART_TEST(test_scancode__keycode_sets)\n{\n    ck_assert_int_eq(scancode_set_keycode_set(NULL), 1);\n    ck_assert_int_eq(scancode_set_keycode_set(\"\"), 1);\n    ck_assert_int_eq(scancode_set_keycode_set(\"evdev\"), 0);\n    ck_assert_int_eq(scancode_set_keycode_set(\"evdev+aliases(qwerty)\"), 0);\n    ck_assert_int_eq(scancode_set_keycode_set(\"base\"), 0);\n    ck_assert_int_eq(scancode_set_keycode_set(\"xfree86\"), 0);\n    ck_assert_int_eq(scancode_set_keycode_set(\"xfree86+aliases(qwerty)\"), 0);\n}\nEND_TEST\n\n// Checks all returned evdev scancodes are mapped to a keycode\nSTART_TEST(test_scancode__evdev_all_values_returned)\n{\n    unsigned int iter;\n    unsigned int scancode;\n\n    ck_assert_int_eq(scancode_set_keycode_set(\"evdev\"), 0);\n\n    iter = 0;\n    while ((scancode = scancode_get_next(&iter)) != 0)\n    {\n        ck_assert_int_ge(scancode, 0);\n        ck_assert_int_le(scancode, MAX_SUPPORTED_SCANCODE);\n        unsigned short keycode = scancode_to_x11_keycode(scancode);\n        ck_assert_int_ne(keycode, 0);\n    }\n}\nEND_TEST\n\n// Checks all invalid evdev scancodes return 0\nSTART_TEST(test_scancode__evdev_bad_values_mapped_to_0)\n{\n    // Store valid scancodes which are between 0 and MAX_SUPPORTED_SCANCODE\n    char valid[MAX_SUPPORTED_SCANCODE + 1] = {0};\n    unsigned int iter;\n    unsigned int scancode;\n\n    ck_assert_int_eq(scancode_set_keycode_set(\"evdev\"), 0);\n\n    iter = 0;\n    while ((scancode = scancode_get_next(&iter)) != 0)\n    {\n        ck_assert_int_ge(scancode, 0);\n        ck_assert_int_le(scancode, MAX_SUPPORTED_SCANCODE);\n        valid[scancode] = 1;\n    }\n\n    for (scancode = 0 ; scancode <= MAX_SUPPORTED_SCANCODE; ++scancode)\n    {\n        if (!valid[scancode])\n        {\n            ck_assert_int_eq(scancode_to_x11_keycode(scancode), 0);\n        }\n    }\n}\nEND_TEST\n\n// Checks all returned base scancodes are mapped to a keycode\nSTART_TEST(test_scancode__base_all_values_returned)\n{\n    unsigned int iter;\n    unsigned int scancode;\n\n    ck_assert_int_eq(scancode_set_keycode_set(\"base\"), 0);\n\n    iter = 0;\n    while ((scancode = scancode_get_next(&iter)) != 0)\n    {\n        ck_assert_int_ge(scancode, 0);\n        ck_assert_int_le(scancode, MAX_SUPPORTED_SCANCODE);\n        unsigned short keycode = scancode_to_x11_keycode(scancode);\n        ck_assert_int_ne(keycode, 0);\n    }\n}\nEND_TEST\n\n// Checks all invalid base scancodes return 0\nSTART_TEST(test_scancode__base_bad_values_mapped_to_0)\n{\n    // Store valid scancodes which are between 0 and MAX_SUPPORTED_SCANCODE\n    char valid[MAX_SUPPORTED_SCANCODE + 1] = {0};\n    unsigned int iter;\n    unsigned int scancode;\n\n    ck_assert_int_eq(scancode_set_keycode_set(\"base\"), 0);\n\n    iter = 0;\n    while ((scancode = scancode_get_next(&iter)) != 0)\n    {\n        ck_assert_int_ge(scancode, 0);\n        ck_assert_int_le(scancode, MAX_SUPPORTED_SCANCODE);\n        valid[scancode] = 1;\n    }\n\n    for (scancode = 0 ; scancode <= MAX_SUPPORTED_SCANCODE; ++scancode)\n    {\n        if (!valid[scancode])\n        {\n            ck_assert_int_eq(scancode_to_x11_keycode(scancode), 0);\n        }\n    }\n}\nEND_TEST\n\n/******************************************************************************/\n\nSuite *\nmake_suite_test_scancode(void)\n{\n    Suite *s;\n    TCase *tc;\n\n    s = suite_create(\"Scancode\");\n\n    tc = tcase_create(\"scancode\");\n    suite_add_tcase(s, tc);\n    tcase_add_test(tc, test_scancode__scancode_to_index);\n    tcase_add_test(tc, test_scancode__keycode_sets);\n    tcase_add_test(tc, test_scancode__evdev_all_values_returned);\n    tcase_add_test(tc, test_scancode__evdev_bad_values_mapped_to_0);\n    tcase_add_test(tc, test_scancode__base_all_values_returned);\n    tcase_add_test(tc, test_scancode__base_bad_values_mapped_to_0);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_set_int.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <limits.h>\n\n#include \"set_int.h\"\n\n#include \"test_common.h\"\n\nSTART_TEST(test_basic__bad_args)\n{\n    struct set_int *set = set_int_init(10, 1);\n    ck_assert_ptr_eq(set, NULL);\n\n    // Check for no segfaults with a NULL set\n    set_int_add(set, 10);\n    set_int_remove(set, 10);\n    ck_assert_int_eq(set_int_contains(set, 10), 0);\n    set_int_add_all(set);\n    set_int_remove_all(set);\n\n    int val = 0;\n    ck_assert_int_eq(set_int_get_next(set, &val), 0);\n\n    set_int_delete(set);\n}\nEND_TEST\n\nSTART_TEST(test_basic__one_to_ten)\n{\n    int i;\n\n    struct set_int *set = set_int_init(1, 10);\n    ck_assert_ptr_ne(set, NULL);\n\n    set_int_add(set, 0);  // out-of-range\n    for (i = 1 ; i <= 5; ++i)\n    {\n        set_int_add(set, i);\n    }\n    set_int_add(set, 11); // out-of-range\n\n    ck_assert_int_eq(set_int_contains(set, 0), 0);\n    ck_assert_int_eq(set_int_contains(set, 1), 1);\n    ck_assert_int_eq(set_int_contains(set, 2), 1);\n    ck_assert_int_eq(set_int_contains(set, 3), 1);\n    ck_assert_int_eq(set_int_contains(set, 4), 1);\n    ck_assert_int_eq(set_int_contains(set, 5), 1);\n    ck_assert_int_eq(set_int_contains(set, 6), 0);\n    ck_assert_int_eq(set_int_contains(set, 7), 0);\n    ck_assert_int_eq(set_int_contains(set, 8), 0);\n    ck_assert_int_eq(set_int_contains(set, 9), 0);\n    ck_assert_int_eq(set_int_contains(set, 10), 0);\n    ck_assert_int_eq(set_int_contains(set, 11), 0);\n\n    set_int_delete(set);\n}\nEND_TEST\n\nSTART_TEST(test_basic__add_remove_all)\n{\n    struct set_int *set = set_int_init(1, 10);\n    ck_assert_ptr_ne(set, NULL);\n\n    set_int_add(set, 0);  // out-of-range\n    set_int_add_all(set);\n    set_int_add(set, 11); // out-of-range\n\n    ck_assert_int_eq(set_int_contains(set, 0), 0);\n    ck_assert_int_eq(set_int_contains(set, 1), 1);\n    ck_assert_int_eq(set_int_contains(set, 2), 1);\n    ck_assert_int_eq(set_int_contains(set, 3), 1);\n    ck_assert_int_eq(set_int_contains(set, 4), 1);\n    ck_assert_int_eq(set_int_contains(set, 5), 1);\n    ck_assert_int_eq(set_int_contains(set, 6), 1);\n    ck_assert_int_eq(set_int_contains(set, 7), 1);\n    ck_assert_int_eq(set_int_contains(set, 8), 1);\n    ck_assert_int_eq(set_int_contains(set, 9), 1);\n    ck_assert_int_eq(set_int_contains(set, 10), 1);\n    ck_assert_int_eq(set_int_contains(set, 11), 0);\n\n    set_int_remove_all(set);\n    ck_assert_int_eq(set_int_contains(set, 1), 0);\n    ck_assert_int_eq(set_int_contains(set, 2), 0);\n    ck_assert_int_eq(set_int_contains(set, 3), 0);\n    ck_assert_int_eq(set_int_contains(set, 4), 0);\n    ck_assert_int_eq(set_int_contains(set, 5), 0);\n    ck_assert_int_eq(set_int_contains(set, 6), 0);\n    ck_assert_int_eq(set_int_contains(set, 7), 0);\n    ck_assert_int_eq(set_int_contains(set, 8), 0);\n    ck_assert_int_eq(set_int_contains(set, 9), 0);\n    ck_assert_int_eq(set_int_contains(set, 10), 0);\n\n    set_int_delete(set);\n}\nEND_TEST\n\nSTART_TEST(test_basic__single_element)\n{\n#define VAL -1000\n\n    struct set_int *set = set_int_init(VAL, VAL);\n    ck_assert_ptr_ne(set, NULL);\n\n    set_int_add(set, VAL - 1);  // out-of-range\n    set_int_add(set, VAL);\n    set_int_add(set, VAL + 1);  // out-of-range\n\n    ck_assert_int_eq(set_int_contains(set, VAL - 1), 0);\n    ck_assert_int_eq(set_int_contains(set, VAL), 1);\n    ck_assert_int_eq(set_int_contains(set, VAL + 1), 0);\n\n    set_int_add_all(set);\n    ck_assert_int_eq(set_int_contains(set, VAL - 1), 0);\n    ck_assert_int_eq(set_int_contains(set, VAL), 1);\n    ck_assert_int_eq(set_int_contains(set, VAL + 1), 0);\n\n    set_int_remove(set, VAL);\n    ck_assert_int_eq(set_int_contains(set, VAL), 0);\n\n    set_int_delete(set);\n#undef VAL\n}\nEND_TEST\n\nSTART_TEST(test_basic__get_next)\n{\n    int i;\n    struct set_int *set = set_int_init(0, 1000);\n    ck_assert_ptr_ne(set, NULL);\n\n    for (i = 1 ; i <= 10; ++i)\n    {\n        set_int_add(set, i);\n    }\n\n    set_int_add(set, 500);\n\n    int val = INT_MIN;\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 1);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 2);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 3);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 4);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 5);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 6);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 7);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 8);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 9);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 10);\n    ck_assert_int_eq(set_int_get_next(set, &val), 1);\n    ck_assert_int_eq(val, 500);\n    ck_assert_int_eq(set_int_get_next(set, &val), 0);\n\n    set_int_delete(set);\n}\nEND_TEST\n\n/******************************************************************************/\n\nSuite *\nmake_suite_test_set_int(void)\n{\n    Suite *s;\n    TCase *tc_basic;\n\n    s = suite_create(\"SetInt\");\n\n    tc_basic = tcase_create(\"basic\");\n    suite_add_tcase(s, tc_basic);\n    tcase_add_test(tc_basic, test_basic__bad_args);\n    tcase_add_test(tc_basic, test_basic__one_to_ten);\n    tcase_add_test(tc_basic, test_basic__add_remove_all);\n    tcase_add_test(tc_basic, test_basic__single_element);\n    tcase_add_test(tc_basic, test_basic__get_next);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_ssl_calls.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"ssl_calls.h\"\n\n#include \"test_common.h\"\n\n/* Time to allow RSA-based test suites to run on older, slower platforms\n *\n * These platforms are most often seen on build farms (e.g. Debian CI) */\n#define RSA_BASED_TEST_SUITE_TIMEOUT 60\n\nSTART_TEST(test_rc4_enc_ok)\n{\n    const char *key = \"16_byte_key-----\";\n    char text[] = \"xrdp-test-suite-rc4-encryption\";\n    char *result;\n\n    void *info = ssl_rc4_info_create();\n    ssl_rc4_set_key(info, key, g_strlen(key));\n    ssl_rc4_crypt(info, text, sizeof(text) - 1);\n    ssl_rc4_info_delete(info);\n    result = bin_to_hex(text, sizeof(text) - 1);\n    ck_assert(result != NULL);\n    /* Result should be the same as\n     * echo -n '<text>' | \\\n     *     openssl rc4 -K <hex-key> -e [-provider legacy] | \\\n     *     xxd -g0\n     *\n     * where <hex-key> is the string above in hexadecimal */\n    ck_assert_str_eq(result, \"c080f175b2d85802dbf1042f07180ddc4be1d9bd4a44158f0aebf11c961b\");\n    g_free(result);\n}\nEND_TEST\n\nSTART_TEST(test_rc4_enc_tv0_ok)\n{\n    /*\n     * This is one of the 5 original RC4 test vectors posted in response to\n     * the 'RC4 Algorithm revealed' sci.crypt usenet posting */\n    unsigned char key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};\n    unsigned char text[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};\n    const char *expected = \"75b7878099e0c596\";\n    char *result;\n\n    void *info = ssl_rc4_info_create();\n    ssl_rc4_set_key(info, (char *)key, sizeof(key));\n    ssl_rc4_crypt(info, (char *)text, sizeof(text));\n    ssl_rc4_info_delete(info);\n\n    result = bin_to_hex((char *)text, sizeof(text));\n    ck_assert(result != NULL);\n    ck_assert_str_eq(result, expected);\n    g_free(result);\n}\nEND_TEST\n\nSTART_TEST(test_rc4_enc_tv1_ok)\n{\n    /*\n     * This is one of the 5 original RC4 test vectors posted in response to\n     * the 'RC4 Algorithm revealed' sci.crypt usenet posting */\n    unsigned char key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};\n    unsigned char text[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};\n    const char *expected = \"7494c2e7104b0879\";\n    char *result;\n\n    void *info = ssl_rc4_info_create();\n    ssl_rc4_set_key(info, (char *)key, sizeof(key));\n    ssl_rc4_crypt(info, (char *)text, sizeof(text));\n    ssl_rc4_info_delete(info);\n\n    result = bin_to_hex((char *)text, sizeof(text));\n    ck_assert(result != NULL);\n    ck_assert_str_eq(result, expected);\n    g_free(result);\n}\nEND_TEST\n\nSTART_TEST(test_rc4_enc_tv2_ok)\n{\n    /*\n     * This is one of the 5 original RC4 test vectors posted in response to\n     * the 'RC4 Algorithm revealed' sci.crypt usenet posting */\n    unsigned char key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};\n    unsigned char text[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};\n    const char *expected = \"de188941a3375d3a\";\n    char *result;\n\n    void *info = ssl_rc4_info_create();\n    ssl_rc4_set_key(info, (char *)key, sizeof(key));\n    ssl_rc4_crypt(info, (char *)text, sizeof(text));\n    ssl_rc4_info_delete(info);\n\n    result = bin_to_hex((char *)text, sizeof(text));\n    ck_assert(result != NULL);\n    ck_assert_str_eq(result, expected);\n    g_free(result);\n}\nEND_TEST\n\nSTART_TEST(test_rc4_enc_tv3_ok)\n{\n    /*\n     * This is one of the 5 original RC4 test vectors posted in response to\n     * the 'RC4 Algorithm revealed' sci.crypt usenet posting */\n    unsigned char key[] = {0xef, 0x01, 0x23, 0x45};\n    unsigned char text[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};\n    const char *expected = \"d6a141a7ec3c38dfbd61\";\n    char *result;\n\n    void *info = ssl_rc4_info_create();\n    ssl_rc4_set_key(info, (char *)key, sizeof(key));\n    ssl_rc4_crypt(info, (char *)text, sizeof(text));\n    ssl_rc4_info_delete(info);\n\n    result = bin_to_hex((char *)text, sizeof(text));\n    ck_assert(result != NULL);\n    ck_assert_str_eq(result, expected);\n    g_free(result);\n}\nEND_TEST\n\nSTART_TEST(test_rc4_enc_tv4_ok)\n{\n    /*\n     * This is one of the 5 original RC4 test vectors posted in response to\n     * the 'RC4 Algorithm revealed' sci.crypt usenet posting */\n    unsigned char key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};\n    unsigned char text[] =\n    {\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n        0x01, 0x01\n    };\n    const char *expected =\n        \"7595c3e6114a09780c4ad452338e1ffd9a1be9498f813d76533449b6778dca\"\n        \"d8c78a8d2ba9ac66085d0e53d59c26c2d1c490c1ebbe0ce66d1b6b1b13b6\"\n        \"b919b847c25a91447a95e75e4ef16779cde8bf0a95850e32af9689444fd3\"\n        \"77108f98fdcbd4e726567500990bcc7e0ca3c4aaa304a387d20f3b8fbbcd\"\n        \"42a1bd311d7a4303dda5ab078896ae80c18b0af66dff319616eb784e495a\"\n        \"d2ce90d7f772a81747b65f62093b1e0db9e5ba532fafec47508323e67132\"\n        \"7df9444432cb7367cec82f5d44c0d00b67d650a075cd4b70dedd77eb9b10\"\n        \"231b6b5b741347396d62897421d43df9b42e446e358e9c11a9b2184ecbef\"\n        \"0cd8e7a877ef968f1390ec9b3d35a5585cb009290e2fcde7b5ec66d9084b\"\n        \"e44055a619d9dd7fc3166f9487f7cb272912426445998514c15d53a18c86\"\n        \"4ce3a2b7555793988126520eacf2e3066e230c91bee4dd5304f5fd0405b3\"\n        \"5bd99c73135d3d9bc335ee049ef69b3867bf2d7bd1eaa595d8bfc0066ff8\"\n        \"d31509eb0c6caa006c807a623ef84c3d33c195d23ee320c40de0558157c8\"\n        \"22d4b8c569d849aed59d4e0fd7f379586b4b7ff684ed6a189f7486d49b9c\"\n        \"4bad9ba24b96abf924372c8a8fffb10d55354900a77a3db5f205e1b99fcd\"\n        \"8660863a159ad4abe40fa48934163ddde542a6585540fd683cbfd8c00f12\"\n        \"129a284deacc4cdefe58be7137541c047126c8d49e2755ab181ab7e940b0c0\";\n\n    char *result;\n\n    void *info = ssl_rc4_info_create();\n    ssl_rc4_set_key(info, (char *)key, sizeof(key));\n    ssl_rc4_crypt(info, (char *)text, sizeof(text));\n    ssl_rc4_info_delete(info);\n\n    result = bin_to_hex((char *)text, sizeof(text));\n    ck_assert(result != NULL);\n    ck_assert_str_eq(result, expected);\n    g_free(result);\n}\nEND_TEST\n\nSTART_TEST(test_sha1_hash_ok)\n{\n    const char *hash_string = \"xrdp-test-suite-sha1-hash\";\n    char digest[20];\n    char *result1;\n    char *result2;\n\n    void *info = ssl_sha1_info_create();\n    ssl_sha1_clear(info);\n    ssl_sha1_transform(info, hash_string, g_strlen(hash_string));\n    ssl_sha1_complete(info, digest);\n    result1 = bin_to_hex(digest, sizeof(digest));\n    ck_assert(result1 != NULL);\n    /* Check result with echo -n '<hash_string>' | sha1sum */\n    ck_assert_str_eq(result1, \"3ea0ae84e97e6262c7cfe79ccd7ad2094c06885d\");\n\n    /* Check a clear has the desired effect */\n    ssl_sha1_clear(info);\n    ssl_sha1_transform(info, hash_string, g_strlen(hash_string));\n    ssl_sha1_complete(info, digest);\n    result2 = bin_to_hex(digest, sizeof(digest));\n    ck_assert(result2 != NULL);\n    ck_assert_str_eq(result1, result2);\n\n    ssl_sha1_info_delete(info);\n    g_free(result1);\n    g_free(result2);\n}\nEND_TEST\n\nSTART_TEST(test_md5_hash_ok)\n{\n    const char *hash_string = \"xrdp-test-suite-md5-hash\";\n    char digest[16];\n    char *result1;\n    char *result2;\n\n    void *info = ssl_md5_info_create();\n\n    ssl_md5_clear(info);\n    ssl_md5_transform(info, hash_string, g_strlen(hash_string));\n    ssl_md5_complete(info, digest);\n    result1 = bin_to_hex(digest, sizeof(digest));\n    ck_assert(result1 != NULL);\n    /* Check result with echo -n '<hash_string>' | md5sum */\n    ck_assert_str_eq(result1, \"ddc599dc7ec62b8f78760b071704c007\");\n\n    /* Check a clear has the desired effect */\n    ssl_md5_clear(info);\n    ssl_md5_transform(info, hash_string, g_strlen(hash_string));\n    ssl_md5_complete(info, digest);\n    result2 = bin_to_hex(digest, sizeof(digest));\n    ck_assert(result2 != NULL);\n    ck_assert_str_eq(result1, result2);\n\n    ssl_md5_info_delete(info);\n    g_free(result1);\n    g_free(result2);\n}\nEND_TEST\n\nSTART_TEST(test_des3_enc_ok)\n{\n    const char *key = \"24_byte_key-------------\";\n    char plaintext[] = \"xrdp-test-suite-des3-encryption-must-be-multiple-of-8-chars-long--------\";\n    char ciphertext[sizeof(plaintext) - 1]; /* No terminator needed */\n    char plaintext2[sizeof(plaintext)];\n\n    char *result;\n\n    void *info = ssl_des3_encrypt_info_create(key, 0);\n    ssl_des3_encrypt(info, sizeof(plaintext) - 1, plaintext, ciphertext);\n    ssl_des3_info_delete(info);\n    result = bin_to_hex(ciphertext, sizeof(ciphertext));\n    ck_assert(result != NULL);\n    /* Result should be the same as\n     * echo -n '<text>' | \\\n     *     openssl des3 -iv 0000000000000000 -K <hex-key> -e -nopad | \\\n     *     od -t x1\n     *\n     * where <hex-key> is the string above in hexadecimal */\n    ck_assert_str_eq(result,\n                     \"856d70861827365e188781616e4f9dcc3009b2c5dc7785edcbc05fa825a4ea5e10b23735c0e971ca20f895f455b8845418963af6dd8e649719790eed6cbcee0fb97b743c60e32e8b\");\n    g_free(result);\n\n    /* Let's go back again */\n    info = ssl_des3_decrypt_info_create(key, 0);\n    ssl_des3_decrypt(info, sizeof(ciphertext), ciphertext, plaintext2);\n    ssl_des3_info_delete(info);\n    plaintext2[sizeof(plaintext2) - 1] = '\\0';\n\n    ck_assert_str_eq(plaintext, plaintext2);\n}\nEND_TEST\n\nSTART_TEST(test_hmac_sha1_dgst_ok)\n{\n    const char *key = \"20_byte_key---------\";\n    const char *hash_string = \"xrdp-test-suite-hmac-sha1-dgst\";\n    char hmac[20];\n\n    char *result;\n\n    void *info = ssl_hmac_info_create();\n    ssl_hmac_sha1_init(info, key, g_strlen(key));\n    ssl_hmac_transform(info, hash_string, g_strlen(hash_string));\n    ssl_hmac_complete(info, hmac, sizeof(hmac));\n    ssl_hmac_info_delete(info);\n    result = bin_to_hex(hmac, sizeof(hmac));\n    ck_assert(result != NULL);\n    /* Result should be the same as\n     * echo -n '<text>' | openssl dgst -sha1 -hmac '<key>'\n     *\n     * or:-\n     *\n     * echo -n '<text>' | openssl mac -digest sha1 -macopt key:'<key>' hmac\n     */\n    ck_assert_str_eq(result, \"af8c04e609e9f3cba53ad7815b60160dc69a9936\");\n    g_free(result);\n\n}\nEND_TEST\n\nSTART_TEST(test_gen_key_xrdp1)\n{\n#define RSA_TEST_BITS 2048\n    char modulus[RSA_TEST_BITS / 8] = {0};\n    char private_key[RSA_TEST_BITS / 8] = {0};\n    unsigned char exponent[4] =\n    {\n        0x01, 0x00, 0x01, 0x00 /* 65537 in little-endian format */\n    };\n\n    /*\n     * We can't do much here because of the nature of the call, but we can\n     * at least check it completes without error */\n    int error;\n    error = ssl_gen_key_xrdp1(RSA_TEST_BITS,\n                              (const char *)exponent, sizeof(exponent),\n                              modulus, sizeof(modulus),\n                              private_key, sizeof(private_key));\n    ck_assert(error == 0);\n\n    /* Both the modulus and the privatekey should be odd */\n    ck_assert((modulus[0] & 1) == 1);\n    ck_assert((private_key[0] & 1) == 1);\n#undef RSA_TEST_BITS\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_ssl_calls(void)\n{\n    Suite *s;\n    TCase *tc;\n\n    s = suite_create(\"SSL-Calls\");\n\n    tc = tcase_create(\"ssl_calls_rc4\");\n    suite_add_tcase(s, tc);\n    tcase_add_test(tc, test_rc4_enc_ok);\n    tcase_add_test(tc, test_rc4_enc_tv0_ok);\n    tcase_add_test(tc, test_rc4_enc_tv1_ok);\n    tcase_add_test(tc, test_rc4_enc_tv2_ok);\n    tcase_add_test(tc, test_rc4_enc_tv3_ok);\n    tcase_add_test(tc, test_rc4_enc_tv4_ok);\n\n    tc = tcase_create(\"ssl_calls_sha1\");\n    suite_add_tcase(s, tc);\n    tcase_add_test(tc, test_sha1_hash_ok);\n\n    tc = tcase_create(\"ssl_calls_md5\");\n    suite_add_tcase(s, tc);\n    tcase_add_test(tc, test_md5_hash_ok);\n\n    tc = tcase_create(\"ssl_calls_des3\");\n    suite_add_tcase(s, tc);\n    tcase_add_test(tc, test_des3_enc_ok);\n\n    tc = tcase_create(\"ssl_calls_hmac_sha1\");\n    suite_add_tcase(s, tc);\n    tcase_add_test(tc, test_hmac_sha1_dgst_ok);\n\n    tc = tcase_create(\"ssl_calls_rsa_key\");\n    suite_add_tcase(s, tc);\n    tcase_set_timeout(tc, RSA_BASED_TEST_SUITE_TIMEOUT);\n    tcase_add_test(tc, test_gen_key_xrdp1);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_string_calls.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <limits.h>\n#include <signal.h>\n\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"ms-rdpbcgr.h\"\n\n#include \"test_common.h\"\n\n#define RESULT_LEN 1024\n\n/* Universal character names need a C99 compiler */\n#if __STDC_VERSION__ >= 199901L\n#   define CJK_UNIFIED_IDEOGRAPH_5E78 \"\\u5e78\"\n#   define CJK_UNIFIED_IDEOGRAPH_798F \"\\u798f\"\n#   define CJK_UNIFIED_IDEOGRAPH_5B89 \"\\u5b89\"\n#   define CJK_UNIFIED_IDEOGRAPH_5EB7 \"\\u5eb7\"\n#else\n// Assume we're using UTF-8\n#   define CJK_UNIFIED_IDEOGRAPH_5E78 \"\\xe5\\xb9\\xb8\"\n#   define CJK_UNIFIED_IDEOGRAPH_798F \"\\xe7\\xa6\\x8f\"\n#   define CJK_UNIFIED_IDEOGRAPH_5B89 \"\\xe5\\xae\\x89\"\n#   define CJK_UNIFIED_IDEOGRAPH_5EB7 \"\\xe5\\xba\\xb7\"\n#endif\n\n#define HAPPINESS_AND_WELL_BEING  \\\n    CJK_UNIFIED_IDEOGRAPH_5E78 CJK_UNIFIED_IDEOGRAPH_798F \\\n    CJK_UNIFIED_IDEOGRAPH_5B89 CJK_UNIFIED_IDEOGRAPH_5EB7\n\nSTART_TEST(test_strnjoin__when_src_is_null__returns_empty_string)\n{\n    /* setup */\n\n    const char **src = NULL;\n    char result[RESULT_LEN];\n    result[0] = '\\0';\n\n    /* test */\n\n    g_strnjoin(result, RESULT_LEN, \" \", src, 0);\n\n    /* verify */\n\n    ck_assert_str_eq(result, \"\");\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_src_has_null_item__returns_joined_string)\n{\n    /* setup */\n\n    const char *test_value = \"test_value\";\n    const char *src[] = { test_value, NULL };\n    char result[RESULT_LEN];\n    result[0] = '\\0';\n\n    /* test */\n\n    g_strnjoin(result, RESULT_LEN, \" \", src, 2);\n\n    /* verify */\n\n    ck_assert_str_eq(result, \"test_value \");\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_src_has_one_item__returns_copied_source_string)\n{\n    /* setup */\n\n    const char *expected_value = \"test_value\";\n    const char *src[] = { expected_value };\n    char result[RESULT_LEN];\n    result[0] = '\\0';\n\n    /* test */\n\n    g_strnjoin(result, RESULT_LEN, \" \", src, 1);\n\n    /* verify */\n\n    ck_assert_str_eq(result, expected_value);\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_src_has_two_items__returns_joined_string)\n{\n    /* setup */\n\n    const char *test_value = \"test_value\";\n    const char *src[] = { test_value, test_value };\n    char result[RESULT_LEN];\n    result[0] = '\\0';\n\n    /* test */\n\n    g_strnjoin(result, RESULT_LEN, \" \", src, 2);\n\n    /* verify */\n\n    ck_assert_str_eq(result, \"test_value test_value\");\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_joiner_is_empty_string__returns_joined_string)\n{\n    /* setup */\n\n    const char *test_value = \"test_value\";\n    const char *src[] = { test_value, test_value };\n    char result[RESULT_LEN];\n    result[0] = '\\0';\n\n    /* test */\n\n    g_strnjoin(result, RESULT_LEN, \"\", src, 2);\n\n    /* verify */\n\n    ck_assert_str_eq(result, \"test_valuetest_value\");\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_joiner_is_NULL__returns_joined_string)\n{\n    /* setup */\n\n    const char *test_value = \"test_value\";\n    const char *src[] = { test_value, test_value };\n    char result[RESULT_LEN];\n    result[0] = '\\0';\n\n    /* test */\n\n    g_strnjoin(result, RESULT_LEN, NULL, src, 2);\n\n    /* verify */\n\n    ck_assert_str_eq(result, \"test_valuetest_value\");\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_destination_is_NULL__returns_NULL)\n{\n    /* setup */\n\n    const char *test_value = \"test_value\";\n    const char *src[] = { test_value };\n    char *result = NULL;\n\n    /* test */\n\n    g_strnjoin(result, 0, \" \", src, 1);\n\n    /* verify */\n\n    ck_assert_ptr_eq(result, NULL);\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_destination_is_shorter_than_src__returns_partial_src_string)\n{\n    /* setup */\n\n    const char *test_value = \"test_value\";\n    const char *src[] = { test_value };\n    char result[5];\n    result[0] = '\\0';\n\n    /* test */\n\n    g_strnjoin(result, 5, \" \", src, 1);\n\n    /* verify */\n\n    ck_assert_str_eq(result, \"test\");\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_destination_is_shorter_than_src_plus_joiner__returns_partial_joined_string)\n{\n    /* setup */\n\n    const char *test_value = \"test_value\";\n    const char *src[] = { test_value, test_value};\n    char result[16];\n    result[0] = '\\0';\n\n    /* test */\n\n    g_strnjoin(result, 16, \" joiner \", src, 2);\n\n    /* verify */\n\n    ck_assert_str_eq(result, \"test_value join\");\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_destination_has_contents__returns_joined_string_with_content_overwritten)\n{\n    /* setup */\n\n    const char *test_value = \"test_value\";\n    const char *src[] = { test_value, test_value};\n    char result[RESULT_LEN] = \"1234567890\";\n\n    /* test */\n\n    g_strnjoin(result, RESULT_LEN, \" \", src, 2);\n\n    /* verify */\n\n    ck_assert_str_eq(result, \"test_value test_value\");\n}\nEND_TEST\n\nSTART_TEST(test_strnjoin__when_always__then_doesnt_write_beyond_end_of_destination)\n{\n    /* setup */\n\n    const char *src[] = { \"a\", \"b\", \"c\"};\n    char result[5 + 1 + 1]; /* a-b-c + term null + guard value */\n\n    /* test */\n\n    result[6] = '\\x7f';\n    g_strnjoin(result, 5 + 1, \"-\", src, 3);\n\n    /* verify */\n\n    ck_assert_int_eq(result[6], '\\x7f');\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_bm2str__no_bits_defined)\n{\n    int rv;\n    char buff[64];\n\n    static const struct bitmask_string bits[] =\n    {\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    rv = g_bitmask_to_str(0xffff, bits, ',', buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"0xffff\");\n    ck_assert_int_eq(rv, 6);\n}\nEND_TEST\n\nSTART_TEST(test_bm2str__all_bits_defined)\n{\n    int rv;\n    char buff[64];\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        {1 << 6, \"BIT_6\"},\n        {1 << 7, \"BIT_7\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 6 | 1 << 7;\n\n    rv = g_bitmask_to_str(bitmask, bits, '|', buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"BIT_0|BIT_1|BIT_6|BIT_7\");\n    ck_assert_int_eq(rv, (6 * 4) - 1);\n}\nEND_TEST\n\nSTART_TEST(test_bm2str__some_bits_undefined)\n{\n    int rv;\n    char buff[64];\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        {1 << 6, \"BIT_6\"},\n        {1 << 7, \"BIT_7\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 16;\n\n    rv = g_bitmask_to_str(bitmask, bits, ':', buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"BIT_0:BIT_1:0x10000\");\n    ck_assert_int_eq(rv, (6 * 2) + 7);\n}\nEND_TEST\n\nSTART_TEST(test_bm2str__overflow_all_bits_defined)\n{\n    int rv;\n    char buff[10];\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        {1 << 6, \"BIT_6\"},\n        {1 << 7, \"BIT_7\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 6 | 1 << 7;\n\n    rv = g_bitmask_to_str(bitmask, bits, '+', buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"BIT_0+BIT\");\n    ck_assert_int_eq(rv, (4 * 6) - 1);\n}\nEND_TEST\n\nSTART_TEST(test_bm2str__overflow_some_bits_undefined)\n{\n    int rv;\n    char buff[16];\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        {1 << 6, \"BIT_6\"},\n        {1 << 7, \"BIT_7\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 16;\n\n    rv = g_bitmask_to_str(bitmask, bits, '#', buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"BIT_0#BIT_1#0x1\");\n    ck_assert_int_eq(rv, (6 * 2) + 7);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__null_string)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    rv = g_str_to_bitmask(NULL, bits, \",\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__empty_string)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    rv = g_str_to_bitmask(\"\", bits, \",\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__null_bitdefs)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    rv = g_str_to_bitmask(\"BIT_0\", NULL, \",\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__null_delim)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    rv = g_str_to_bitmask(\"BIT_0\", bits, NULL, buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__null_buffer)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    rv = g_str_to_bitmask(\"BIT_0\", bits, \",\", NULL, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"dummy\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__zero_buffer)\n{\n    int rv;\n    char buff[1];\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    rv = g_str_to_bitmask(\"BIT_0\", bits, \",\", buff, 0);\n\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__zero_mask)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {0,      \"ZERO MASK\"}, /* mask 0 should not be detected as end of list */\n        {1 << 0, \"BIT_0\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0;\n    rv = g_str_to_bitmask(\"BIT_0\", bits, \",\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__all_defined)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1;\n    rv = g_str_to_bitmask(\"BIT_0,BIT_1\", bits, \",\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__no_defined)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 0;\n    rv = g_str_to_bitmask(\"BIT_2,BIT_3\", bits, \",\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"BIT_2,BIT_3\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__some_defined)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        {1 << 2, \"BIT_2\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 1;\n    rv = g_str_to_bitmask(\"a,BIT_1,b\", bits, \",\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"a,b\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__trim_space)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        {1 << 2, \"BIT_2\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 2;\n    rv = g_str_to_bitmask(\"BIT_0 , BIT_1 , BIT_2\", bits, \",\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__overflow_undefined)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        {1 << 2, \"BIT_2\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 1;\n    rv = g_str_to_bitmask(\"123456789,BIT_1,abcdef\", bits, \",\", buff, sizeof(buff));\n\n    /* abcdef is not filled */\n    ck_assert_str_eq(buff, \"123456789\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__delim_slash)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        {1 << 2, \"BIT_2\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 2;\n    rv = g_str_to_bitmask(\"BIT_0/BIT_1/BIT_2\", bits, \"/\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__no_delim)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    rv = g_str_to_bitmask(\"BIT_0,BIT_1\", bits, \"\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"BIT_0,BIT_1\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__multiple_delim)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        {1 << 2, \"BIT_2\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 2;\n    rv = g_str_to_bitmask(\"BIT_0/BIT_1,BIT_2\", bits, \",/\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__first_delim_is_semicolon)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        {1 << 1, \"BIT_1\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 1;\n    rv = g_str_to_bitmask(\"a;b;BIT_1;c\", bits, \";,\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"a;b;c\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_str2bm__empty_token)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_string bits[] =\n    {\n        {1 << 0, \"BIT_0\"},\n        BITMASK_STRING_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0;\n    rv = g_str_to_bitmask(\",BIT_0, ,\", bits, \",\", buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_bm2char__no_bits_defined)\n{\n    int rv;\n    char buff[64];\n    int rest;\n\n    static const struct bitmask_char bits[] =\n    {\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    rv = g_bitmask_to_charstr(0xffff, bits, buff, sizeof(buff), &rest);\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, 0);\n    ck_assert_int_eq(rest, 0xffff);\n}\nEND_TEST\n\nSTART_TEST(test_bm2char__all_bits_defined)\n{\n    int rv;\n    char buff[64];\n    int rest;\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        {1 << 1, 'B'},\n        {1 << 6, 'C'},\n        {1 << 7, 'D'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 6 | 1 << 7;\n\n    rv = g_bitmask_to_charstr(bitmask, bits, buff, sizeof(buff), &rest);\n\n    ck_assert_str_eq(buff, \"ABCD\");\n    ck_assert_int_eq(rv, 4);\n    ck_assert_int_eq(rest, 0);\n}\nEND_TEST\n\nSTART_TEST(test_bm2char__some_bits_undefined)\n{\n    int rv;\n    char buff[64];\n    int rest;\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        {1 << 1, 'B'},\n        {1 << 6, 'C'},\n        {1 << 7, 'D'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 16;\n\n    rv = g_bitmask_to_charstr(bitmask, bits, buff, sizeof(buff), &rest);\n\n    ck_assert_str_eq(buff, \"AB\");\n    ck_assert_int_eq(rv, 2);\n    ck_assert_int_eq(rest, (1 << 16));\n}\nEND_TEST\n\nSTART_TEST(test_bm2char__overflow_all_bits_defined)\n{\n    int rv;\n    char buff[3];\n    int rest;\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        {1 << 1, 'B'},\n        {1 << 6, 'C'},\n        {1 << 7, 'D'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 6 | 1 << 7;\n\n    rv = g_bitmask_to_charstr(bitmask, bits, buff, sizeof(buff), &rest);\n\n    ck_assert_str_eq(buff, \"AB\");\n    ck_assert_int_eq(rv, 4);\n    ck_assert_int_eq(rest, 0);\n}\nEND_TEST\n\nSTART_TEST(test_bm2char__overflow_some_bits_undefined)\n{\n    int rv;\n    char buff[2];\n    int rest;\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        {1 << 1, 'B'},\n        {1 << 6, 'C'},\n        {1 << 7, 'D'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 16;\n\n    rv = g_bitmask_to_charstr(bitmask, bits, buff, sizeof(buff), &rest);\n\n    ck_assert_str_eq(buff, \"A\");\n    ck_assert_int_eq(rv, 2);\n    ck_assert_int_eq(rest, (1 << 16));\n}\nEND_TEST\n\nSTART_TEST(test_bm2char__null_rest_param)\n{\n    int rv;\n    char buff[10];\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        {1 << 1, 'B'},\n        {1 << 6, 'C'},\n        {1 << 7, 'D'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1 | 1 << 16;\n\n    rv = g_bitmask_to_charstr(bitmask, bits, buff, sizeof(buff), NULL);\n\n    ck_assert_str_eq(buff, \"AB\");\n    ck_assert_int_eq(rv, 2);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_char2bm__null_string)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    rv = g_charstr_to_bitmask(NULL, bits, buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_char2bm__empty_string)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    rv = g_charstr_to_bitmask(\"\", bits, buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_char2bm__null_bitdefs)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    rv = g_charstr_to_bitmask(\"A\", NULL, buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_char2bm__null_buffer)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    rv = g_charstr_to_bitmask(\"B\", bits, NULL, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"dummy\");\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_char2bm__zero_buffer)\n{\n    int rv;\n    char buff[1];\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    rv = g_charstr_to_bitmask(\"B\", bits, buff, 0);\n\n    ck_assert_int_eq(rv, 0);\n}\nEND_TEST\n\nSTART_TEST(test_char2bm__zero_mask)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_char bits[] =\n    {\n        {0,      'A'}, /* mask 0 should not be detected as end of list */\n        {1 << 0, 'B'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0;\n    rv = g_charstr_to_bitmask(\"B\", bits, buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_char2bm__all_defined)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        {1 << 1, 'B'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 1 << 0 | 1 << 1;\n    rv = g_charstr_to_bitmask(\"AB\", bits, buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_char2bm__no_defined)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        {1 << 1, 'B'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 0;\n    rv = g_charstr_to_bitmask(\"CD\", bits, buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"CD\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_char2bm__some_defined)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        {1 << 1, 'B'},\n        {1 << 2, 'C'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 1 << 1;\n    rv = g_charstr_to_bitmask(\"0B1\", bits, buff, sizeof(buff));\n\n    ck_assert_str_eq(buff, \"01\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\nSTART_TEST(test_char2bm__overflow_undefined)\n{\n    int rv;\n    char buff[16] = { 'd', 'u', 'm', 'm', 'y' };\n\n    static const struct bitmask_char bits[] =\n    {\n        {1 << 0, 'A'},\n        {1 << 1, 'B'},\n        {1 << 2, 'C'},\n        BITMASK_CHAR_END_OF_LIST\n    };\n\n    int bitmask = 1 << 1;\n    rv = g_charstr_to_bitmask(\"123456789Bvwxyz\", bits, buff, 10);\n\n    /* vwxyz is not filled */\n    ck_assert_str_eq(buff, \"123456789\");\n    ck_assert_int_eq(rv, bitmask);\n}\nEND_TEST\n\n/******************************************************************************/\n\nSTART_TEST(test_strtrim__trim_left)\n{\n    /* setup */\n    char output[] = \"\\t\\t    \\tDone is better than perfect.\\t\\t    \\n\\n\";\n\n    /* test */\n    g_strtrim(output, 1);\n\n    /* verify */\n    ck_assert_str_eq(output, \"Done is better than perfect.\\t\\t    \\n\\n\");\n}\nEND_TEST\n\nSTART_TEST(test_strtrim__trim_right)\n{\n    /* setup */\n    char output[] = \"\\t\\t    \\tDone is better than perfect.\\t\\t    \\n\\n\";\n\n    /* test */\n    g_strtrim(output, 2);\n\n    /* verify */\n    ck_assert_str_eq(output, \"\\t\\t    \\tDone is better than perfect.\");\n}\nEND_TEST\n\nSTART_TEST(test_strtrim__trim_both)\n{\n    /* setup */\n    char output[] = \"\\t\\t    \\tDone is better than perfect.\\t\\t    \\n\\n\";\n\n    /* test */\n    g_strtrim(output, 3);\n\n    /* verify */\n    ck_assert_str_eq(output, \"Done is better than perfect.\");\n}\nEND_TEST\n\nSTART_TEST(test_strtrim__trim_through)\n{\n    /* setup */\n    char output[] = \"\\t\\t    \\tDone is better than perfect.\\t\\t    \\n\\n\";\n\n    /* test */\n    g_strtrim(output, 4);\n\n    /* verify */\n    ck_assert_str_eq(output, \"Doneisbetterthanperfect.\");\n}\nEND_TEST\n\nSTART_TEST(test_strtrim__chinese_chars)\n{\n    /* setup */\n    char output[] = \"\\t\\t    \\t\" HAPPINESS_AND_WELL_BEING \"\\t\\t    \\n\\n\";\n\n    /* test */\n    g_strtrim(output, 4);\n\n    /* verify */\n    ck_assert_str_eq(output, HAPPINESS_AND_WELL_BEING);\n}\nEND_TEST\n\n/******************************************************************************/\n\nSTART_TEST(test_sigs__common)\n{\n    char name[MAXSTRSIGLEN];\n    char *res;\n\n    // Check some common POSIX signals\n    res = g_sig2text(SIGHUP, name);\n    ck_assert_ptr_eq(res, name);\n    ck_assert_str_eq(res, \"SIGHUP\");\n\n    res = g_sig2text(SIGCHLD, name);\n    ck_assert_ptr_eq(res, name);\n    ck_assert_str_eq(res, \"SIGCHLD\");\n\n    res = g_sig2text(SIGXFSZ, name);\n    ck_assert_ptr_eq(res, name);\n    ck_assert_str_eq(res, \"SIGXFSZ\");\n\n    res = g_sig2text(SIGRTMIN, name);\n    ck_assert_ptr_eq(res, name);\n    ck_assert_str_eq(res, \"SIGRTMIN\");\n\n    res = g_sig2text(SIGRTMIN + 2, name);\n    ck_assert_ptr_eq(res, name);\n    ck_assert_str_eq(res, \"SIGRTMIN+2\");\n\n    res = g_sig2text(SIGRTMAX, name);\n    ck_assert_ptr_eq(res, name);\n    ck_assert_str_eq(res, \"SIGRTMAX\");\n\n    // Should be invalid\n    res = g_sig2text(0, name);\n    ck_assert_ptr_eq(res, name);\n    ck_assert_str_eq(res, \"SIG#0\");\n\n    res = g_sig2text(65535, name);\n    ck_assert_ptr_eq(res, name);\n    ck_assert_str_eq(res, \"SIG#65535\");\n\n\n    // POSIX defines signals as ints, but insists they are positive. So\n    // we ought to trest we get sane behaviour for -ve numbers\n    res = g_sig2text(-1, name);\n    ck_assert_ptr_eq(res, name);\n    ck_assert_str_eq(res, \"SIG#-1\");\n}\nEND_TEST\n\nSTART_TEST(test_sigs__bigint)\n{\n    char name[MAXSTRSIGLEN];\n    char name2[1024];\n\n    // Check that big integers aren't being truncated by the definition\n    // of MAXSTRSIGLEN\n    int i = INT_MAX;\n\n    g_sig2text(i, name);\n    g_snprintf(name2, sizeof(name2), \"SIG#%d\", i);\n    ck_assert_str_eq(name, name2);\n\n    i = INT_MIN;\n    g_sig2text(i, name);\n    g_snprintf(name2, sizeof(name2), \"SIG#%d\", i);\n    ck_assert_str_eq(name, name2);\n}\nEND_TEST\n\n/******************************************************************************/\n\nSTART_TEST(test_htoi__all)\n{\n    // Invalid 1st character\n    ck_assert_int_eq(g_htoi(\"\"), 0);\n    ck_assert_int_eq(g_htoi(\"z\"), 0);\n    // Test border conditions (assumes ASCII) */\n    ck_assert_int_eq(g_htoi(\"99/\"), 0x99); /* '/' = one-before '0' */\n    ck_assert_int_eq(g_htoi(\"99:\"), 0x99); /* '/' = one-after '9' */\n    ck_assert_int_eq(g_htoi(\"99@\"), 0x99); /* '#' = one-before 'A' */\n    ck_assert_int_eq(g_htoi(\"99G\"), 0x99); /* 'G' = one-after 'F' */\n    ck_assert_int_eq(g_htoi(\"99`\"), 0x99); /* '`' = one-before 'a' */\n    ck_assert_int_eq(g_htoi(\"99g\"), 0x99); /* 'g' = one-after 'f' */\n\n    // Test all valid characters and shifting is OK */\n    ck_assert_int_eq(g_htoi(\"01234567\"), 0x01234567);\n    ck_assert_int_eq(g_htoi(\"8ABCDEFa\"), 0x8ABCDEFa);\n    ck_assert_int_eq(g_htoi(\"bcdef\"), 0xbcdef);\n}\nEND_TEST\n\n/******************************************************************************/\n\nSuite *\nmake_suite_test_string(void)\n{\n    Suite *s;\n    TCase *tc_strnjoin;\n    TCase *tc_bm2str;\n    TCase *tc_str2bm;\n    TCase *tc_bm2char;\n    TCase *tc_char2bm;\n    TCase *tc_strtrim;\n    TCase *tc_sigs;\n    TCase *tc_htoi;\n\n    s = suite_create(\"String\");\n\n    tc_strnjoin = tcase_create(\"strnjoin\");\n    suite_add_tcase(s, tc_strnjoin);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_src_is_null__returns_empty_string);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_src_has_null_item__returns_joined_string);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_src_has_one_item__returns_copied_source_string);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_src_has_two_items__returns_joined_string);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_joiner_is_empty_string__returns_joined_string);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_joiner_is_NULL__returns_joined_string);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_destination_is_NULL__returns_NULL);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_destination_is_shorter_than_src__returns_partial_src_string);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_destination_is_shorter_than_src_plus_joiner__returns_partial_joined_string);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_destination_has_contents__returns_joined_string_with_content_overwritten);\n    tcase_add_test(tc_strnjoin, test_strnjoin__when_always__then_doesnt_write_beyond_end_of_destination);\n\n    tc_bm2str = tcase_create(\"bm2str\");\n    suite_add_tcase(s, tc_bm2str);\n    tcase_add_test(tc_bm2str, test_bm2str__no_bits_defined);\n    tcase_add_test(tc_bm2str, test_bm2str__all_bits_defined);\n    tcase_add_test(tc_bm2str, test_bm2str__some_bits_undefined);\n    tcase_add_test(tc_bm2str, test_bm2str__overflow_all_bits_defined);\n    tcase_add_test(tc_bm2str, test_bm2str__overflow_some_bits_undefined);\n    tc_str2bm = tcase_create(\"str2bm\");\n    suite_add_tcase(s, tc_str2bm);\n    tcase_add_test(tc_str2bm, test_str2bm__null_string);\n    tcase_add_test(tc_str2bm, test_str2bm__empty_string);\n    tcase_add_test(tc_str2bm, test_str2bm__null_bitdefs);\n    tcase_add_test(tc_str2bm, test_str2bm__null_delim);\n    tcase_add_test(tc_str2bm, test_str2bm__null_buffer);\n    tcase_add_test(tc_str2bm, test_str2bm__zero_buffer);\n    tcase_add_test(tc_str2bm, test_str2bm__zero_mask);\n    tcase_add_test(tc_str2bm, test_str2bm__all_defined);\n    tcase_add_test(tc_str2bm, test_str2bm__no_defined);\n    tcase_add_test(tc_str2bm, test_str2bm__some_defined);\n    tcase_add_test(tc_str2bm, test_str2bm__trim_space);\n    tcase_add_test(tc_str2bm, test_str2bm__overflow_undefined);\n    tcase_add_test(tc_str2bm, test_str2bm__no_delim);\n    tcase_add_test(tc_str2bm, test_str2bm__delim_slash);\n    tcase_add_test(tc_str2bm, test_str2bm__multiple_delim);\n    tcase_add_test(tc_str2bm, test_str2bm__first_delim_is_semicolon);\n    tcase_add_test(tc_str2bm, test_str2bm__empty_token);\n\n    tc_bm2char = tcase_create(\"bm2char\");\n    suite_add_tcase(s, tc_bm2char);\n    tcase_add_test(tc_bm2char, test_bm2char__no_bits_defined);\n    tcase_add_test(tc_bm2char, test_bm2char__all_bits_defined);\n    tcase_add_test(tc_bm2char, test_bm2char__some_bits_undefined);\n    tcase_add_test(tc_bm2char, test_bm2char__overflow_all_bits_defined);\n    tcase_add_test(tc_bm2char, test_bm2char__overflow_some_bits_undefined);\n    tcase_add_test(tc_bm2char, test_bm2char__null_rest_param);\n    tc_char2bm = tcase_create(\"char2bm\");\n    suite_add_tcase(s, tc_char2bm);\n    tcase_add_test(tc_char2bm, test_char2bm__null_string);\n    tcase_add_test(tc_char2bm, test_char2bm__empty_string);\n    tcase_add_test(tc_char2bm, test_char2bm__null_bitdefs);\n    tcase_add_test(tc_char2bm, test_char2bm__null_buffer);\n    tcase_add_test(tc_char2bm, test_char2bm__zero_buffer);\n    tcase_add_test(tc_char2bm, test_char2bm__zero_mask);\n    tcase_add_test(tc_char2bm, test_char2bm__all_defined);\n    tcase_add_test(tc_char2bm, test_char2bm__no_defined);\n    tcase_add_test(tc_char2bm, test_char2bm__some_defined);\n    tcase_add_test(tc_char2bm, test_char2bm__overflow_undefined);\n\n    tc_strtrim = tcase_create(\"strtrim\");\n    suite_add_tcase(s, tc_strtrim);\n    tcase_add_test(tc_strtrim, test_strtrim__trim_left);\n    tcase_add_test(tc_strtrim, test_strtrim__trim_right);\n    tcase_add_test(tc_strtrim, test_strtrim__trim_both);\n    tcase_add_test(tc_strtrim, test_strtrim__trim_through);\n    tcase_add_test(tc_strtrim, test_strtrim__chinese_chars);\n\n    tc_sigs = tcase_create(\"signals\");\n    suite_add_tcase(s, tc_sigs);\n    tcase_add_test(tc_sigs, test_sigs__common);\n    tcase_add_test(tc_sigs, test_sigs__bigint);\n\n    tc_htoi = tcase_create(\"g_htoi\");\n    suite_add_tcase(s, tc_htoi);\n    tcase_add_test(tc_htoi, test_htoi__all);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_string_calls_unicode.c",
    "content": "/*\n * The UTF-8 decoder tests are based on the UTF-8 decoder capability\n * and stress test\" 2015-08-26 by Markus Kuhn. A copy of that file\n * named \"UTF-8-test.txt\" should be in the source directory for this file */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"string_calls.h\"\n\n#include \"test_common.h\"\n\n// Abbreviate UCS_REPLACEMENT_CHARACTER for utf8_decode_sub_test arrays\n#define URC UCS_REPLACEMENT_CHARACTER\n\nstruct utf8_decode_sub_test\n{\n    const char *testref;\n    const char *utf8str;\n    // This array will contain 0 values after the initialised part\n    const char32_t expected[65];\n};\n\n// Abbreviate UCS_REPLACEMENT_CHARACTER for utf8_encode_sub_test arrays\n#define E_URC { 0xef, 0xbf, 0xbd }\n\nstruct utf8_encode_sub_test\n{\n    const char *testref;\n    char32_t c32;\n    unsigned int expected_len;\n    char expected_str[MAXLEN_UTF8_CHAR];\n};\n\n// Used as the simple test in UTF-8-test.txt\nstatic const char greek_kosme[] =\n    \"\\xce\\xba\" // GREEK SMALL LETTER KAPPA\n    \"\\xe1\\xbd\\xb9\" // GREEK SMALL LETTER OMICRON WITH OXIA\n    \"\\xcf\\x83\" // GREEK SMALL LETTER SIGMA\n    \"\\xce\\xbc\" // GREEK SMALL LETTER MU\n    \"\\xce\\xb5\"; // GREEK SMALL LETTER EPSILON\n\n// See Issue #2603\nstatic const char simple_test_with_emoji[] =\n    \"Simple Test.\"\n    \"\\xf0\\x9f\\x98\\xa5\"; // U+1F625 Disappointed But Relieved Face\n\n/******************************************************************************/\n/**\n * Function to decode a UTF-8 string and check the expected result\n *\n * @param st Pointer to the sub-test to run\n */\nstatic void\nrun_utf8_decode_sub_test(const struct utf8_decode_sub_test *st)\n{\n    char32_t c;\n    const char *p = st->utf8str;\n    unsigned int index = 0;\n\n    do\n    {\n        c = utf8_get_next_char(&p, NULL);\n\n        if (c != st->expected[index])\n        {\n            ck_abort_msg(\"Sub-test section %s Index %u expected %x, got %x\",\n                         st->testref,\n                         index, st->expected[index], c);\n        }\n        ++index;\n    }\n    while (c != 0);\n}\n\n/******************************************************************************/\n/**\n * Function to run an array of decode sub-tests\n *\n * @param st Pointer to the first sub-test to run\n */\nstatic void\nrun_decode_sub_test_array(const struct utf8_decode_sub_test *st)\n{\n    while (st->utf8str != NULL)\n    {\n        run_utf8_decode_sub_test(st++);\n    }\n}\n\n/******************************************************************************/\n/**\n * Function to encode a UTF-8 value and check the expected result\n *\n * @param st Pointer to the sub-test to run\n */\nstatic void\nrun_utf8_encode_sub_test(const struct utf8_encode_sub_test *st)\n{\n    char actual_str[MAXLEN_UTF8_CHAR];\n    unsigned int index;\n    unsigned int actual_len = utf_char32_to_utf8(st->c32, actual_str);\n\n    if (actual_len != st->expected_len)\n    {\n        ck_abort_msg(\"Sub-test %s Expected length of %u, got %u\",\n                     st->testref,\n                     st->expected_len, actual_len);\n    }\n\n    for (index = 0 ; index < actual_len; ++index)\n    {\n        if (actual_str[index] != st->expected_str[index])\n        {\n            ck_abort_msg(\"Sub-test %s Character %u, expected %02x got %02x\",\n                         st->testref, index,\n                         (int)(unsigned char)st->expected_str[index],\n                         (int)(unsigned char)actual_str[index]);\n        }\n    }\n}\n\n/******************************************************************************/\n/**\n * Function to run an array of encode sub-tests\n *\n * @param st Pointer to the first sub-test to run\n */\nstatic void\nrun_encode_sub_test_array(const struct utf8_encode_sub_test *st)\n{\n    while (st->expected_len > 0)\n    {\n        run_utf8_encode_sub_test(st++);\n    }\n}\n\n\n/******************************************************************************/\nSTART_TEST(test_get_next_char__section_1)\n{\n    const struct utf8_decode_sub_test st =\n    {\n        \"1\",\n        greek_kosme,\n        {\n            0x03ba, // GREEK SMALL LETTER KAPPA\n            0x1f79, // GREEK SMALL LETTER OMICRON WITH OXIA\n            0x03c3, // GREEK SMALL LETTER SIGMA\n            0x03bc, // GREEK SMALL LETTER MU\n            0x03b5  // GREEK SMALL LETTER EPSILON\n        }\n    };\n\n    run_utf8_decode_sub_test(&st);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_get_next_char__section_2)\n{\n    const struct utf8_decode_sub_test tests[] =\n    {\n        // 2.1  First possible sequence of a certain length\n        //\n        // (2.1.1 Is tested separately)\n        { \"2.1.2\", \"\\xc2\\x80\", { 0x80 } },\n        { \"2.1.3\", \"\\xe0\\xa0\\x80\", { 0x800 } },\n        { \"2.1.4\", \"\\xf0\\x90\\x80\\x80\", { 0x10000 } },\n        { \"2.1.5\", \"\\xf8\\x88\\x80\\x80\\x80\", { URC } },\n        { \"2.1.6\", \"\\xfc\\x84\\x80\\x80\\x80\\x80\", { URC } },\n\n        // 2.2  Last possible sequence of a certain length\n        { \"2.2.1\", \"\\x7f\", { 0x7f } },\n        { \"2.2.2\", \"\\xdf\\xbf\", { 0x7ff } },\n        // Use U+0000FFFC instead of U+0000FFFF as our decoder\n        // treats non-characters as an input error\n        { \"2.2.3\", \"\\xef\\xbf\\xbc\", { 0xfffc } },\n        // U+001FFFFF is out-of-range\n        { \"2.2.4\", \"\\xf7\\xbf\\xbf\\xbf\", { URC } },\n        { \"2.2.5\", \"\\xfb\\xbf\\xbf\\xbf\\xbf\", { URC } },\n        { \"2.2.6\", \"\\xfd\\xbf\\xbf\\xbf\\xbf\\xbf\", { URC } },\n\n        // 2.3  Other boundary conditions\n        { \"2.3.1\", \"\\xed\\x9f\\xbf\", { 0xd7ff } },\n        { \"2.3.2\", \"\\xee\\x80\\x80\", { 0xe000 } },\n        { \"2.3.3\", \"\\xef\\xbf\\xbd\", { 0xfffd } },\n        // Don't use U+10FFFF (non-character)\n        { \"2.3.4\", \"\\xf4\\x8f\\xbf\\xbd\", { 0x10fffd } },\n        { \"2.3.5\", \"\\xf4\\x90\\x80\\x80\", { URC } },\n        // Terminator\n        { 0 }\n    };\n\n    // 2.1.1 is a '\\0' which we use to terminate our strings. Test\n    // it separately\n    {\n        const char *p = \"\";\n\n        ck_assert_int_eq(utf8_get_next_char(&p, NULL), 0);\n    }\n\n    // Do the rest of the section 2 tests\n    run_decode_sub_test_array(tests);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_get_next_char__section_3)\n{\n    const struct utf8_decode_sub_test tests[] =\n    {\n        // 3.1  Unexpected continuation bytes\n        //\n        // Each unexpected continuation byte should be separately\n        // signalled as a malformed sequence of its own.\n        { \"3.1.1\", \"\\x80\", { URC } },\n        { \"3.1.2\", \"\\xbf\", { URC } },\n        { \"3.1.3\", \"\\x80\\xbf\", { URC, URC } },\n        { \"3.1.4\", \"\\x80\\xbf\\x80\", { URC, URC, URC } },\n        { \"3.1.5\", \"\\x80\\xbf\\x80\\xbf\", { URC, URC, URC, URC } },\n        { \"3.1.6\", \"\\x80\\xbf\\x80\\xbf\\x80\", { URC, URC, URC, URC, URC } },\n        {\n            \"3.1.7\",\n            \"\\x80\\xbf\\x80\\xbf\\x80\\xbf\",\n            { URC, URC, URC, URC, URC, URC }\n        },\n        {\n            \"3.1.8\",\n            \"\\x80\\xbf\\x80\\xbf\\x80\\xbf\\x80\",\n            { URC, URC, URC, URC, URC, URC, URC }\n        },\n        {\n            \"3.1.9\",\n            \"\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d\\x8e\\x8f\"\n            \"\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b\\x9c\\x9d\\x9e\\x9f\"\n            \"\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9\\xaa\\xab\\xac\\xad\\xae\\xaf\"\n            \"\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\",\n            {\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC\n            }\n        },\n\n        // 3.2  Lonely start characters\n        {\n            \"3.2.1\",\n            \"\\xc0 \\xc1 \\xc2 \\xc3 \\xc4 \\xc5 \\xc6 \\xc7 \"\n            \"\\xc8 \\xc9 \\xca \\xcb \\xcc \\xcd \\xce \\xcf \"\n            \"\\xd0 \\xd1 \\xd2 \\xd3 \\xd4 \\xd5 \\xd6 \\xd7 \"\n            \"\\xd8 \\xd9 \\xda \\xdb \\xdc \\xdd \\xde \\xdf \",\n            {\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' '\n            }\n        },\n        {\n            \"3.2.2\",\n            \"\\xe0 \\xe1 \\xe2 \\xe3 \\xe4 \\xe5 \\xe6 \\xe7 \"\n            \"\\xe8 \\xe9 \\xea \\xeb \\xec \\xed \\xee \\xef \",\n            {\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' '\n            }\n        },\n        {\n            \"3.2.3\",\n            \"\\xf0 \\xf1 \\xf2 \\xf3 \\xf4 \\xf5 \\xf6 \\xf7 \",\n            {\n                URC, ' ', URC, ' ', URC, ' ', URC, ' ',\n                URC, ' ', URC, ' ', URC, ' ', URC, ' '\n            }\n        },\n        {\n            \"3.2.4\",\n            \"\\xf8 \\xf9 \\xfa \\xfb \",\n            {\n                URC, ' ', URC, ' ', URC, ' ', URC, ' '\n            }\n        },\n        {\n            \"3.2.5\", \"\\xfc \\xfd \", { URC, ' ', URC, ' ' }\n        },\n\n        // 3.3  Sequences with last continuation byte missing\n        //\n        // From  UTF-8-test.txt:-\n        //     All bytes of an incomplete sequence should be signalled as\n        //     a single malformed sequence, i.e., you should see only a\n        //     single replacement character in each of the next 10 tests.\n        { \"3.3.1\", \"\\xc0\", { URC } },\n        { \"3.3.2\", \"\\xe0\\x80\", { URC } },\n        { \"3.3.3\", \"\\xf0\\x80\\x80\", { URC } },\n        { \"3.3.4\", \"\\xf8\\x80\\x80\\x80\", { URC } },\n        { \"3.3.5\", \"\\xfc\\x80\\x80\\x80\\x80\", { URC } },\n\n        { \"3.3.6\", \"\\xdf\", { URC } },\n        { \"3.3.7\", \"\\xef\\xbf\", { URC } },\n        { \"3.3.8\", \"\\xf7\\xbf\\xbf\", { URC} },\n        { \"3.3.9\", \"\\xfb\\xbf\\xbf\\xbf\", { URC } },\n        { \"3.3.10\", \"\\xfd\\xbf\\xbf\\xbf\\xbf\", { URC } },\n\n        // 3.4  Concatenation of incomplete sequences\n        {\n            \"3,4\",\n            \"\\xc0\"\n            \"\\xe0\\x80\"\n            \"\\xf0\\x80\\x80\"\n            \"\\xf8\\x80\\x80\\x80\"\n            \"\\xfc\\x80\\x80\\x80\\x80\"\n            \"\\xdf\"\n            \"\\xef\\xbf\"\n            \"\\xf7\\xbf\\xbf\"\n            \"\\xfb\\xbf\\xbf\\xbf\"\n            \"\\xfd\\xbf\\xbf\\xbf\\xbf\",\n            {\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC\n            }\n        },\n\n        // 3.5  Impossible bytes\n        { \"3.5.1\", \"\\xfe\", { URC } },\n        { \"3.5.2\", \"\\xff\", { URC } },\n        { \"3.5.3\", \"\\xfe\\xfe\\xff\\xff\", { URC, URC, URC, URC } },\n        // Terminator\n        { 0 }\n    };\n\n    run_decode_sub_test_array(tests);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_get_next_char__section_4)\n{\n    const struct utf8_decode_sub_test tests[] =\n    {\n        // 4.1  Examples of an overlong ASCII character\n        //\n        // With a safe UTF-8 decoder, all of the following five\n        // overlong representations of the ASCII character slash (\"/\")\n        // should be rejected like a malformed UTF-8 sequence, for\n        // instance by substituting it with a replacement character. If\n        // you see a slash below, you do not have a safe UTF-8 decoder!\n        { \"4.1.1\", \"\\xc0\\xaf\", { URC } },\n        { \"4.1.2\", \"\\xe0\\x80\\xaf\", { URC } },\n        { \"4.1.3\", \"\\xf0\\x80\\x80\\xaf\", { URC } },\n        { \"4.1.4\", \"\\xf8\\x80\\x80\\x80\\xaf\", { URC } },\n        { \"4.1.5\", \"\\xfc\\x80\\x80\\x80\\x80\\xaf\", { URC } },\n\n        // 4.2  Maximum overlong sequences\n\n        // Below you see the highest Unicode value that is still resulting\n        // in an overlong sequence if represented with the given number of\n        // bytes. This is a boundary test for safe UTF-8 decoders. All\n        // five characters should be rejected like malformed UTF-8\n        // sequences.\n        { \"4.2.1\", \"\\xc1\\xbf\", { URC } },\n        { \"4.2.2\", \"\\xe0\\x9f\\xbf\", { URC } },\n        { \"4.2.3\", \"\\xf0\\x8f\\xbf\\xbf\", { URC } },\n        { \"4.2.4\", \"\\xf8\\x87\\xbf\\xbf\\xbf\", { URC } },\n        { \"4.2.5\", \"\\xfc\\x83\\xbf\\xbf\\xbf\\xbf\", { URC } },\n\n        // 4.3  Overlong representation of the NUL character\n\n        // The following five sequences should also be rejected like\n        // malformed UTF-8 sequences and should not be treated like the\n        // ASCII NUL character.\n        { \"4.3.1\", \"\\xc0\\x80\", { URC } },\n        { \"4.3.2\", \"\\xe0\\x80\\x80\", { URC } },\n        { \"4.3.3\", \"\\xf0\\x80\\x80\\x80\", { URC } },\n        { \"4.3.4\", \"\\xf8\\x80\\x80\\x80\\x80\", { URC } },\n        { \"4.3.5\", \"\\xfc\\x80\\x80\\x80\\x80\\x80\", { URC } },\n\n        // Terminator\n        { 0 }\n    };\n\n    run_decode_sub_test_array(tests);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_get_next_char__section_5)\n{\n    const struct utf8_decode_sub_test tests[] =\n    {\n        // 5  Illegal code positions\n\n        // The following UTF-8 sequences should be rejected like\n        // malformed sequences, because they never represent valid\n        // ISO 10646 characters and a UTF-8 decoder that accepts them\n        // might introduce security problems comparable to overlong\n        // UTF-8 sequences.\n\n        // 5.1 Single UTF-16 surrogates\n        { \"5.1.1\", \"\\xed\\xa0\\x80\", { URC } },\n        { \"5.1.2\", \"\\xed\\xad\\xbf\", { URC } },\n        { \"5.1.3\", \"\\xed\\xae\\x80\", { URC } },\n        { \"5.1.4\", \"\\xed\\xaf\\xbf\", { URC } },\n        { \"5.1.5\", \"\\xed\\xb0\\x80\", { URC } },\n        { \"5.1.6\", \"\\xed\\xbe\\x80\", { URC } },\n        { \"5.1.7\", \"\\xed\\xbf\\xbf\", { URC } },\n\n        // 5.2 Paired UTF-16 surrogates\n        { \"5.2.1\", \"\\xed\\xa0\\x80\\xed\\xb0\\x80\", { URC, URC } },\n        { \"5.2.2\", \"\\xed\\xa0\\x80\\xed\\xbf\\xbf\", { URC, URC } },\n        { \"5.2.3\", \"\\xed\\xad\\xbf\\xed\\xb0\\x80\", { URC, URC } },\n        { \"5.2.4\", \"\\xed\\xad\\xbf\\xed\\xbf\\xbf\", { URC, URC } },\n        { \"5.2.5\", \"\\xed\\xae\\x80\\xed\\xb0\\x80\", { URC, URC } },\n        { \"5.2.6\", \"\\xed\\xae\\x80\\xed\\xbf\\xbf\", { URC, URC } },\n        { \"5.2.7\", \"\\xed\\xaf\\xbf\\xed\\xb0\\x80\", { URC, URC } },\n        { \"5.2.8\", \"\\xed\\xaf\\xbf\\xed\\xbf\\xbf\", { URC, URC } },\n\n        // 5.3 Noncharacter code positions\n\n        // The following \"noncharacters\" are \"reserved for internal\n        // use\" by applications, and according to older versions of\n        // the Unicode Standard \"should never be interchanged\". Unicode\n        // Corrigendum #9 dropped the latter restriction. Nevertheless,\n        // their presence in incoming UTF-8 data can remain a potential\n        // security risk, depending on what use is made of these codes\n        // subsequently. Examples of such internal use:\n        //\n        //  - Some file APIs with 16-bit characters may use the integer\n        //    value -1 = U+FFFF to signal an end-of-file (EOF) or error\n        //    condition.\n        //\n        //  - In some UTF-16 receivers, code point U+FFFE might trigger\n        //    a byte-swap operation (to convert between UTF-16LE and\n        //    UTF-16BE).\n        // With such internal use of noncharacters, it may be desirable\n        // and safer to block those code points in UTF-8 decoders, as\n        // they should never occur legitimately in incoming UTF-8 data,\n        // and could trigger unsafe behaviour in subsequent processing.\n\n        // Particularly problematic noncharacters in 16-bit applications:\n        { \"5.3.1\", \"\\xef\\xbf\\xbe\", { URC } },\n        { \"5.3.2\", \"\\xef\\xbf\\xbf\", { URC } },\n\n        // Other noncharacters:\n        {\n            \"5.3.3\",\n            // Non-characters in \"Arabic Presentation Forms-A\" (BMP)\n            \"\\xef\\xb7\\x90\" \"\\xef\\xb7\\x91\" \"\\xef\\xb7\\x92\" \"\\xef\\xb7\\x93\"\n            \"\\xef\\xb7\\x94\" \"\\xef\\xb7\\x95\" \"\\xef\\xb7\\x96\" \"\\xef\\xb7\\x97\"\n            \"\\xef\\xb7\\x98\" \"\\xef\\xb7\\x99\" \"\\xef\\xb7\\x9a\" \"\\xef\\xb7\\x9b\"\n            \"\\xef\\xb7\\x9c\" \"\\xef\\xb7\\x9d\" \"\\xef\\xb7\\x9e\" \"\\xef\\xb7\\x9f\"\n            \"\\xef\\xb7\\xa0\" \"\\xef\\xb7\\xa1\" \"\\xef\\xb7\\xa2\" \"\\xef\\xb7\\xa3\"\n            \"\\xef\\xb7\\xa4\" \"\\xef\\xb7\\xa5\" \"\\xef\\xb7\\xa6\" \"\\xef\\xb7\\xa7\"\n            \"\\xef\\xb7\\xa8\" \"\\xef\\xb7\\xa9\" \"\\xef\\xb7\\xaa\" \"\\xef\\xb7\\xab\"\n            \"\\xef\\xb7\\xac\" \"\\xef\\xb7\\xad\" \"\\xef\\xb7\\xae\" \"\\xef\\xb7\\xaf\",\n            {\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC\n            }\n        },\n\n        {\n            \"5.3.4\",\n            \"\\xf0\\x9f\\xbf\\xbe\" \"\\xf0\\x9f\\xbf\\xbf\" // U+0001FFFE U+0001FFFF\n            \"\\xf0\\xaf\\xbf\\xbe\" \"\\xf0\\xaf\\xbf\\xbf\" // U+0002FFFE U+0002FFFF\n            \"\\xf0\\xbf\\xbf\\xbe\" \"\\xf0\\xbf\\xbf\\xbf\" // U+0003FFFE U+0003FFFF\n            \"\\xf1\\x8f\\xbf\\xbe\" \"\\xf1\\x8f\\xbf\\xbf\" // U+0004FFFE U+0004FFFF\n            \"\\xf1\\x9f\\xbf\\xbe\" \"\\xf1\\x9f\\xbf\\xbf\" // U+0005FFFE U+0005FFFF\n            \"\\xf1\\xaf\\xbf\\xbe\" \"\\xf1\\xaf\\xbf\\xbf\" // U+0006FFFE U+0006FFFF\n            \"\\xf1\\xbf\\xbf\\xbe\" \"\\xf1\\xbf\\xbf\\xbf\" // U+0007FFFE U+0007FFFF\n            \"\\xf2\\x8f\\xbf\\xbe\" \"\\xf2\\x8f\\xbf\\xbf\" // U+0008FFFE U+0008FFFF\n            \"\\xf2\\x9f\\xbf\\xbe\" \"\\xf2\\x9f\\xbf\\xbf\" // U+0009FFFE U+0009FFFF\n            \"\\xf2\\xaf\\xbf\\xbe\" \"\\xf2\\xaf\\xbf\\xbf\" // U+000AFFFE U+000AFFFF\n            \"\\xf2\\xbf\\xbf\\xbe\" \"\\xf2\\xbf\\xbf\\xbf\" // U+000BFFFE U+000BFFFF\n            \"\\xf3\\x8f\\xbf\\xbe\" \"\\xf3\\x8f\\xbf\\xbf\" // U+000CFFFE U+000CFFFF\n            \"\\xf3\\x9f\\xbf\\xbe\" \"\\xf3\\x9f\\xbf\\xbf\" // U+000DFFFE U+000DFFFF\n            \"\\xf3\\xaf\\xbf\\xbe\" \"\\xf3\\xaf\\xbf\\xbf\" // U+000EFFFE U+000EFFFF\n            \"\\xf3\\xbf\\xbf\\xbe\" \"\\xf3\\xbf\\xbf\\xbf\" // U+000FFFFE U+000FFFFF\n            \"\\xf4\\x8f\\xbf\\xbe\" \"\\xf4\\x8f\\xbf\\xbf\",// U+0010FFFE U+0010FFFF\n            {\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC,\n                URC, URC, URC, URC, URC, URC, URC, URC\n            }\n        },\n\n        // Last line of UTF8-test.txt\n        { \"TheEnd\", \"THE END\\n\", { 'T', 'H', 'E', ' ', 'E', 'N', 'D', '\\n'} },\n\n        // Terminator\n        { 0 }\n\n    };\n\n    run_decode_sub_test_array(tests);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_utf_char32_to_utf8)\n{\n    const struct utf8_encode_sub_test tests[] =\n    {\n\n        // E2.1  First possible sequence of a certain length\n        //\n        { \"E2.1.1\", 0, 1, { 0 } },\n        { \"E2.1.2\", 0x80, 2, { 0xc2, 0x80 } },\n        { \"E2.1.3\", 0x800, 3, { 0xe0, 0xa0, 0x80 } },\n        { \"E2.1.4\", 0x10000, 4, { 0xf0, 0x90, 0x80, 0x80 } },\n\n        // E2.2  Last possible sequence of a certain length\n        { \"E2.2.1\", 0x7f, 1, { 0x7f } },\n        { \"E2.2.2\", 0x7ff, 2, { 0xdf, 0xbf } },\n        { \"E2.2.3\", 0xfffc, 3, { 0xef, 0xbf, 0xbc } }, // See 2.1.3 above\n        { \"E2.2.4\", 0x1FFFFF, 3, E_URC }, // out-of-range\n\n        // E2.3  Other boundary conditions\n        { \"E2.3.1\", 0xd7ff, 3, { 0xed, 0x9f, 0xbf } },\n        { \"E2.3.2\", 0xe000, 3, { 0xee, 0x80, 0x80 } },\n        { \"E2.3.3\", 0xfffd, 3, { 0xef, 0xbf, 0xbd } },\n        { \"E2.3.4\", 0x10fffd, 4, { 0xf4, 0x8f, 0xbf, 0xbd } }, // See 2.3.4 above\n        // E2.3.5 - not tested\n\n        // E5.1 Single UTF-16 surrogates\n        { \"E5.1.1\", 0xd800, 3, E_URC },\n        { \"E5.1.2\", 0xdb7f, 3, E_URC },\n        { \"E5.1.3\", 0xdb80, 3, E_URC },\n        { \"E5.1.4\", 0xdbff, 3, E_URC },\n        { \"E5.1.5\", 0xdc00, 3, E_URC },\n        { \"E5.1.6\", 0xdf80, 3, E_URC },\n        { \"E5.1.7\", 0xdfff, 3, E_URC },\n\n        // E5.3 Non-character code positions\n        { \"E5.3.3(0)\", 0xfdd0, 3, E_URC },\n        { \"E5.3.3(1)\", 0xfdd1, 3, E_URC },\n        { \"E5.3.3(2)\", 0xfdd2, 3, E_URC },\n        { \"E5.3.3(3)\", 0xfdd3, 3, E_URC },\n        { \"E5.3.3(4)\", 0xfdd4, 3, E_URC },\n        { \"E5.3.3(5)\", 0xfdd5, 3, E_URC },\n        { \"E5.3.3(6)\", 0xfdd6, 3, E_URC },\n        { \"E5.3.3(7)\", 0xfdd7, 3, E_URC },\n        { \"E5.3.3(8)\", 0xfdd8, 3, E_URC },\n        { \"E5.3.3(9)\", 0xfdd9, 3, E_URC },\n        { \"E5.3.3(10)\", 0xfdda, 3, E_URC },\n        { \"E5.3.3(11)\", 0xfddb, 3, E_URC },\n        { \"E5.3.3(12)\", 0xfddc, 3, E_URC },\n        { \"E5.3.3(13)\", 0xfddd, 3, E_URC },\n        { \"E5.3.3(14)\", 0xfdde, 3, E_URC },\n        { \"E5.3.3(15)\", 0xfddf, 3, E_URC },\n        { \"E5.3.3(16)\", 0xfde0, 3, E_URC },\n        { \"E5.3.3(17)\", 0xfde1, 3, E_URC },\n        { \"E5.3.3(18)\", 0xfde2, 3, E_URC },\n        { \"E5.3.3(19)\", 0xfde3, 3, E_URC },\n        { \"E5.3.3(20)\", 0xfde4, 3, E_URC },\n        { \"E5.3.3(21)\", 0xfde5, 3, E_URC },\n        { \"E5.3.3(22)\", 0xfde6, 3, E_URC },\n        { \"E5.3.3(23)\", 0xfde7, 3, E_URC },\n        { \"E5.3.3(24)\", 0xfde8, 3, E_URC },\n        { \"E5.3.3(25)\", 0xfde9, 3, E_URC },\n        { \"E5.3.3(26)\", 0xfdea, 3, E_URC },\n        { \"E5.3.3(27)\", 0xfdeb, 3, E_URC },\n        { \"E5.3.3(28)\", 0xfdec, 3, E_URC },\n        { \"E5.3.3(29)\", 0xfded, 3, E_URC },\n        { \"E5.3.3(30)\", 0xfdee, 3, E_URC },\n        { \"E5.3.3(31)\", 0xfdef, 3, E_URC },\n        { \"E5.3.4(0)\", 0x1fffe, 3, E_URC },\n        { \"E5.3.4(1)\", 0x1ffff, 3, E_URC },\n        { \"E5.3.4(2)\", 0x2fffe, 3, E_URC },\n        { \"E5.3.4(3)\", 0x2ffff, 3, E_URC },\n        { \"E5.3.4(4)\", 0x3fffe, 3, E_URC },\n        { \"E5.3.4(5)\", 0x3ffff, 3, E_URC },\n        { \"E5.3.4(6)\", 0x4fffe, 3, E_URC },\n        { \"E5.3.4(7)\", 0x4ffff, 3, E_URC },\n        { \"E5.3.4(8)\", 0x5fffe, 3, E_URC },\n        { \"E5.3.4(9)\", 0x5ffff, 3, E_URC },\n        { \"E5.3.4(10)\", 0x6fffe, 3, E_URC },\n        { \"E5.3.4(11)\", 0x6ffff, 3, E_URC },\n        { \"E5.3.4(12)\", 0x7fffe, 3, E_URC },\n        { \"E5.3.4(13)\", 0x7ffff, 3, E_URC },\n        { \"E5.3.4(14)\", 0x8fffe, 3, E_URC },\n        { \"E5.3.4(15)\", 0x8ffff, 3, E_URC },\n        { \"E5.3.4(16)\", 0x9fffe, 3, E_URC },\n        { \"E5.3.4(17)\", 0x9ffff, 3, E_URC },\n        { \"E5.3.4(18)\", 0xafffe, 3, E_URC },\n        { \"E5.3.4(19)\", 0xaffff, 3, E_URC },\n        { \"E5.3.4(20)\", 0xbfffe, 3, E_URC },\n        { \"E5.3.4(21)\", 0xbffff, 3, E_URC },\n        { \"E5.3.4(22)\", 0xcfffe, 3, E_URC },\n        { \"E5.3.4(23)\", 0xcffff, 3, E_URC },\n        { \"E5.3.4(24)\", 0xdfffe, 3, E_URC },\n        { \"E5.3.4(25)\", 0xdffff, 3, E_URC },\n        { \"E5.3.4(26)\", 0xefffe, 3, E_URC },\n        { \"E5.3.4(27)\", 0xeffff, 3, E_URC },\n        { \"E5.3.4(28)\", 0xffffe, 3, E_URC },\n        { \"E5.3.4(29)\", 0xfffff, 3, E_URC },\n        { \"E5.3.4(30)\", 0x10fffe, 3, E_URC },\n        { \"E5.3.4(31)\", 0x10ffff, 3, E_URC },\n        { \"E5.99.0\", 'T', 1, { 'T' } },\n        { \"E5.99.1\", 'H', 1, { 'H' } },\n        { \"E5.99.2\", 'E', 1, { 'E' } },\n        { \"E5.99.3\", ' ', 1, { ' ' } },\n        { \"E5.99.4\", 'E', 1, { 'E' } },\n        { \"E5.99.5\", 'N', 1, { 'N' } },\n        { \"E5.99.6\", 'D', 1, { 'D' } },\n\n        // Terminator\n        { 0 }\n    };\n\n    run_encode_sub_test_array(tests);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_utf8_char_count)\n{\n    // Check function can cope with NULL argument\n    ck_assert_int_eq(utf8_char_count(NULL), 0);\n\n    unsigned int kosme_strlen = strlen(greek_kosme);\n    unsigned int kosme_len = utf8_char_count(greek_kosme);\n\n    // All characters map to two bytes except for the 'omicrom with oxia'\n    // which maps to three\n    ck_assert_int_eq(kosme_strlen, 2 + 3 + 2 + 2 + 2);\n    ck_assert_int_eq(kosme_len, 5);\n\n    unsigned int simple_test_strlen = strlen(simple_test_with_emoji);\n    unsigned int simple_test_len = utf8_char_count(simple_test_with_emoji);\n\n    ck_assert_int_eq(simple_test_strlen,\n                     (1 + 1 + 1 + 1 + 1 + 1 ) + // Simple\n                     1 +\n                     (1 + 1 + 1 + 1 ) + // Test\n                     1 +\n                     4);               // emoji\n    // The emoji is 4 bytes - all others are 1\n    ck_assert_int_eq(simple_test_len, simple_test_strlen - 3);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_utf8_as_utf16_word_count)\n{\n    unsigned int kosme_count =\n        utf8_as_utf16_word_count(greek_kosme, strlen(greek_kosme));\n\n    ck_assert_int_eq(kosme_count, 5); // All characters in BMP\n\n    unsigned int simple_test_count =\n        utf8_as_utf16_word_count(simple_test_with_emoji,\n                                 strlen(simple_test_with_emoji));\n\n    ck_assert_int_eq(simple_test_count,\n                     (1 + 1 + 1 + 1 + 1 + 1 ) + // Simple\n                     1 +\n                     (1 + 1 + 1 + 1 ) + // Test\n                     1 +\n                     2); // emoji\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_utf8_add_char_at)\n{\n#define TEST_SIZE sizeof(simple_test_with_emoji)\n\n    // Type pairing a string position with a Unicode char\n    struct pos_to_char_map\n    {\n        unsigned int pos;\n        char32_t c32;\n    };\n\n    // Buffer for constructing the string\n    char buff[TEST_SIZE];\n\n    // A pseudo-random map of the characters in simple_test_with_emoji\n    const struct pos_to_char_map map[] =\n    {\n        { 0, 'l' },\n        { 0, 'S' },\n        { 1, 'i' },\n        { 2, 'm' },\n        { 4, 0x1f625 },\n        { 4, '.' },\n        { 4, 'e' },\n        { 5, 'T' },\n        { 3, 'p' },\n        { 7, 't' },\n        { 7, 'e' },\n        { 8, 's' },\n        { 6, ' ' },\n        { 0 }\n    };\n\n    buff[0] = '\\0';\n\n    // Construct the string in a pseudo-random fashion\n\n    const struct pos_to_char_map *p;\n    for (p = map; p->c32 != 0 ; ++p)\n    {\n        if (!utf8_add_char_at(buff, TEST_SIZE, p->c32, p->pos))\n        {\n            ck_abort_msg(\"test_utf8_add_char_at: \"\n                         \"Can't insert char %x at pos %u\",\n                         p->c32,\n                         p->pos);\n        }\n    }\n\n    // Should have reached the buffer size by now\n    ck_assert_int_eq(strlen(buff), TEST_SIZE - 1);\n\n    // Check the string is what we expect\n    ck_assert_int_eq(strcmp(buff, simple_test_with_emoji), 0);\n\n    // Try to insert another character\n    if (utf8_add_char_at(buff, TEST_SIZE, ' ', 0))\n    {\n        ck_abort_msg(\"test_utf8_add_char_at: \"\n                     \"Insert succeeded but should have failed\");\n    }\n\n#undef TEST_SIZE\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_utf8_remove_char_at)\n{\n#define TEST_SIZE sizeof(simple_test_with_emoji)\n    // Type pairing a string position with a Unicode char\n    struct pos_to_char_map\n    {\n        unsigned int pos;\n        char32_t c32;\n    };\n\n    // Buffer for deconstructing the string\n    char buff[TEST_SIZE];\n\n    // A pseudo-random map of the characters in simple_test_with_emoji\n    const struct pos_to_char_map map[] =\n    {\n        { 2, 'm' },\n        { 7, 'e' },\n        { 5, ' ' },\n        { 1, 'i' },\n        { 2, 'l' },\n        { 3, 'T' },\n        { 6, 0x1f625 },\n        { 2, 'e' },\n        { 3, 't' },\n        { 3, '.' },\n        { 2, 's' },\n        { 1, 'p' },\n        { 0, 'S' },\n        { 0 }\n    };\n\n    char32_t c32;\n\n    strcpy(buff, simple_test_with_emoji);\n\n    // Deconstruct the string in a pseudo-random fashion\n    const struct pos_to_char_map *p;\n    for (p = map; p->c32 != 0 ; ++p)\n    {\n        c32 = utf8_remove_char_at(buff, p->pos);\n        if (c32 != p->c32)\n        {\n            ck_abort_msg(\"test_utf8_remove_char_at: \"\n                         \"remove char at pos %u was %x, expected %x\",\n                         p->pos, c32, p->c32);\n        }\n    }\n\n    // Should have emptied the buffer by now\n    ck_assert_int_eq(buff[0], '\\0');\n\n    // Try to remove other characters\n    c32 = utf8_remove_char_at(buff, 0);\n    ck_assert_int_eq(c32, 0);\n    c32 = utf8_remove_char_at(buff, 99);\n    ck_assert_int_eq(c32, 0);\n    ck_assert_int_eq(buff[0], '\\0');\n\n#undef TEST_SIZE\n}\nEND_TEST\n\n/******************************************************************************/\n\nSuite *\nmake_suite_test_string_unicode(void)\n{\n    Suite *s;\n    TCase *tc_unicode;\n\n    s = suite_create(\"String\");\n\n    tc_unicode = tcase_create(\"Unicode\");\n    suite_add_tcase(s, tc_unicode);\n    tcase_add_test(tc_unicode, test_get_next_char__section_1);\n    tcase_add_test(tc_unicode, test_get_next_char__section_2);\n    tcase_add_test(tc_unicode, test_get_next_char__section_3);\n    tcase_add_test(tc_unicode, test_get_next_char__section_4);\n    tcase_add_test(tc_unicode, test_get_next_char__section_5);\n    tcase_add_test(tc_unicode, test_utf_char32_to_utf8);\n    tcase_add_test(tc_unicode, test_utf8_char_count);\n    tcase_add_test(tc_unicode, test_utf8_as_utf16_word_count);\n    tcase_add_test(tc_unicode, test_utf8_add_char_at);\n    tcase_add_test(tc_unicode, test_utf8_remove_char_at);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/common/test_timers.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <limits.h>\n#include \"os_calls.h\"\n#include \"timers.h\"\n\n#include \"test_common.h\"\n\n/******************************************************************************/\nSTART_TEST(test_timers__null_timer)\n{\n    unsigned int now = g_get_elapsed_ms();\n    struct timers_oneshot *timer = NULL;\n    int v = timers_oneshot_get_remaining(timer, now);\n    ck_assert_int_eq(v, -1);\n\n    // Check any value of 'v' is not changed with a NULL timer\n    timers_oneshot_update_poll(timer, now, &v);\n    ck_assert_int_eq(v, -1);\n\n    v = 0;\n    timers_oneshot_update_poll(timer, now, &v);\n    ck_assert_int_eq(v, 0);\n\n    v = INT_MAX;\n    timers_oneshot_update_poll(timer, now, &v);\n    ck_assert_int_eq(v, INT_MAX);\n}\nEND_TEST\n\n/******************************************************************************/\nSTART_TEST(test_timers__two_secs)\n{\n#define TOLERANCE 25    // Percent\n#define HALF_WAIT 1000   // A second\n    struct timers_oneshot *timer = timers_oneshot_init(2 * HALF_WAIT);\n    ck_assert_ptr_ne(timer, NULL);\n\n    // Wait for half the total period and check the elapsed timer is\n    // within limits\n    g_sleep(HALF_WAIT);\n    int remaining = timers_oneshot_get_remaining(timer, g_get_elapsed_ms());\n\n    ck_assert_int_ge(remaining, HALF_WAIT - (HALF_WAIT * TOLERANCE / 100));\n    ck_assert_int_le(remaining, HALF_WAIT + (HALF_WAIT * TOLERANCE / 100));\n\n    // Wait for the rest of the period and check the timer is zero (or near it)\n    g_sleep(remaining);\n    unsigned int now = g_get_elapsed_ms();\n    int v = timers_oneshot_get_remaining(timer, now);\n    ck_assert_int_ge(v, 0);\n    ck_assert_int_le(v, 1);\n\n    // Check the timer is zero in the future\n    v = timers_oneshot_get_remaining(timer, now + 1000); // Second\n    ck_assert_int_eq(v, 0);\n    v = timers_oneshot_get_remaining(timer, now + 3600 * 1000); // Hour\n    ck_assert_int_eq(v, 0);\n    v = timers_oneshot_get_remaining(timer, now + 86400 * 1000); // Day\n    ck_assert_int_eq(v, 0);\n    v = timers_oneshot_get_remaining(timer, now + 7 * 86400 * 1000); // Week\n    ck_assert_int_eq(v, 0);\n\n    free(timer);\n#undef TOLERANCE\n#undef HALF_WAIT\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_timers(void)\n{\n    Suite *s;\n    TCase *tc_timers;\n\n    s = suite_create(\"timers\");\n\n    tc_timers = tcase_create(\"timers\");\n    suite_add_tcase(s, tc_timers);\n    tcase_add_test(tc_timers, test_timers__null_timer);\n    tcase_add_test(tc_timers, test_timers__two_secs);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/libipm/Makefile.am",
    "content": "\nAM_CPPFLAGS = \\\n  -I$(top_builddir) \\\n  -I$(top_srcdir)/libipm \\\n  -I$(top_srcdir)/common\n\nLOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \\\n                  $(top_srcdir)/tap-driver.sh\n\nPACKAGE_STRING = \"libipm\"\n\nTESTS = test_libipm\ncheck_PROGRAMS = test_libipm\n\ntest_libipm_SOURCES = \\\n    test_libipm_main.c \\\n    test_libipm.h \\\n    test_libipm_send_calls.c \\\n    test_libipm_recv_calls.c\n\ntest_libipm_CFLAGS = \\\n    @CHECK_CFLAGS@ \\\n    -D TOP_SRCDIR=\\\"$(top_srcdir)\\\"\n\ntest_libipm_LDADD = \\\n    $(top_builddir)/libipm/libipm.la \\\n    $(top_builddir)/common/libcommon.la \\\n    @CHECK_LIBS@\n"
  },
  {
    "path": "tests/libipm/test_libipm.h",
    "content": "\n#ifndef TEST_LIBIPM__H\n#define TEST_LIBIPM__H\n\n#include <check.h>\n\n/* Private libipm stuff. This is duplicated here, so if the libipm\n * value change, tests will fail! */\nenum\n{\n    LIBIPM_VERSION = 2,\n    LIBIPM_HEADER_SIZE = 12,\n    LIBIPM_MAX_MESSAGE_SIZE = 8192,\n    LIBIPM_MAX_FD_PER_MSG = 8,\n    LIBIPM_MAX_PAYLOAD_SIZE = LIBIPM_MAX_MESSAGE_SIZE - LIBIPM_HEADER_SIZE\n};\n\n/* Globals */\nextern struct trans *g_t_out;   /* Channel for outputting libipm messages */\nextern struct trans *g_t_in;    /* Channel for inputting libipm messages */\nextern struct trans *g_t_vanilla; /* Non-SCP channel */\nextern int g_fd;                /* An open file descriptor (/dev/zero) */\n\nextern const char *g_supported_types;  /* All recognised type codes */\nextern const char *g_unimplemented_types; /* recognised, unimplemented codes */\n\n#define TEST_MESSAGE_NO 66\n/* Test message with no string translation */\n#define TEST_MESSAGE_NO_STRING_NO 67\n\n/**\n * Compares two binary blocks\n *\n * @param actual_data Actual data\n * @param actual_len Actual length\n * @param expected_data Expected data\n * @aram expected_len Expected data length\n *\n * Differences are raised using ck_* calls\n */\nvoid\ncheck_binary_data_eq(const void *actual_data,\n                     unsigned int actual_len,\n                     const void *expected_data,\n                     unsigned int expected_len);\n\n/**\n * Check the file descriptor specified is working as /dev/zero\n *\n * If it isn't, an exception is raised using ck_* calls\n */\nvoid\ncheck_fd_is_dev_zero(int fd);\n\n/**\n * Looks for the specified string in the specified stream\n * @param s Stream to search\n * @param str Null-terminated string to look for\n * @return != 0 if string found in the buffer\n *\n * The whole buffer is searched for the string. not just the\n * used bit.\n */\nint\ndoes_stream_contain_string(const struct stream *s, const char *str);\n\n/**\n * Returns the number of open file descriptors in the process */\nunsigned int\nget_open_fd_count(void);\n\nSuite *make_suite_test_libipm_send_calls(void);\nSuite *make_suite_test_libipm_recv_calls(void);\n\n#endif /* TEST_LIBIPM__H */\n"
  },
  {
    "path": "tests/libipm/test_libipm_main.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <sys/resource.h>\n#include <poll.h>\n\n#include \"log.h\"\n#include \"libipm.h\"\n#include \"trans.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\n#include \"test_libipm.h\"\n\nstruct trans *g_t_out = NULL;\nstruct trans *g_t_in = NULL;\nstruct trans *g_t_vanilla = NULL;\nint g_fd = -1;\n\nconst char *g_supported_types = \"ybnqiuxtsdhogB\";\nconst char *g_unimplemented_types = \"dog\";\n\n/******************************************************************************/\nstatic const char *\nmsgno_to_str(unsigned short msgno)\n{\n    return (msgno == TEST_MESSAGE_NO) ? \"TEST_MESSAGE_NO\" : NULL;\n}\n\n/******************************************************************************/\nstatic void\nsuite_test_libipm_calls_start(void)\n{\n    int sck[2];\n    struct trans *t1 = NULL;\n    struct trans *t2 = NULL;\n    struct trans *t3 = NULL;\n    int fd = -1;\n    int success = 0;\n\n    if ((t1 = trans_create(TRANS_MODE_UNIX, 128, 128)) == NULL)\n    {\n        const char *errstr = g_get_strerror();\n        LOG(LOG_LEVEL_ERROR, \"Can't create test transport 1 [%s]\", errstr);\n    }\n    else if ((t2 = trans_create(TRANS_MODE_UNIX, 128, 128)) == NULL)\n    {\n        const char *errstr = g_get_strerror();\n        LOG(LOG_LEVEL_ERROR, \"Can't create test transport 2 [%s]\", errstr);\n    }\n    else if ((t3 = trans_create(TRANS_MODE_UNIX, 128, 128)) == NULL)\n    {\n        const char *errstr = g_get_strerror();\n        LOG(LOG_LEVEL_ERROR, \"Can't create test transport 3 [%s]\", errstr);\n    }\n    else if ((fd = g_file_open_rw(\"/dev/zero\")) < 0)\n    {\n        const char *errstr = g_get_strerror();\n        LOG(LOG_LEVEL_ERROR, \"Can't open /dev/zero [%s]\", errstr);\n    }\n    else if (g_sck_local_socketpair(sck) < 0)\n    {\n        const char *errstr = g_get_strerror();\n        LOG(LOG_LEVEL_ERROR, \"Can't create test sockets [%s]\", errstr);\n    }\n    else\n    {\n        enum libipm_status init1;\n        enum libipm_status init2;\n\n        t1->sck = sck[0];\n        t1->type1 = TRANS_TYPE_CLIENT;\n        t1->status = TRANS_STATUS_UP;\n\n        t2->sck = sck[1];\n        t2->type1 = TRANS_TYPE_SERVER;\n        t2->status = TRANS_STATUS_UP;\n\n        init1 = libipm_init_trans(t1, LIBIPM_FAC_TEST, msgno_to_str);\n        init2 = libipm_init_trans(t2, LIBIPM_FAC_TEST, msgno_to_str);\n        if (init1 != E_LI_SUCCESS || init2 != E_LI_SUCCESS)\n        {\n            LOG(LOG_LEVEL_ERROR, \"libipm_init_trans() call failed\");\n        }\n        else\n        {\n            success = 1;\n        }\n    }\n\n    if (success)\n    {\n        g_t_out = t1;\n        g_t_in = t2;\n        g_t_vanilla = t3;\n        g_fd = fd;\n    }\n    else\n    {\n        trans_delete(t1);\n        trans_delete(t2);\n        trans_delete(t3);\n        if (fd >= 0)\n        {\n            g_file_close(fd);\n        }\n    }\n}\n\n/******************************************************************************/\nstatic void\nsuite_test_libipm_calls_end(void)\n{\n    trans_delete(g_t_out);\n    trans_delete(g_t_in);\n    trans_delete(g_t_vanilla);\n}\n\n/******************************************************************************/\nvoid\ncheck_binary_data_eq(const void *actual_data,\n                     unsigned int actual_len,\n                     const void *expected_data,\n                     unsigned int expected_len)\n{\n    const unsigned char *cp_expected = (const unsigned char *)expected_data;\n    const unsigned char *cp_expected_end =\n        (const unsigned char *)expected_data + expected_len;\n    const unsigned char *cp_actual = (const unsigned char *)actual_data;\n\n    if (expected_len != actual_len)\n    {\n        ck_abort_msg(\"Differing lengths. Expected %u, got %u\",\n                     expected_len, actual_len);\n    }\n\n    while (cp_expected < cp_expected_end)\n    {\n        if (*cp_expected != *cp_actual)\n        {\n            int byte_pos = cp_expected - (const unsigned char *)expected_data;\n            ck_abort_msg(\"Byte position %d. Expected %02x, got %02x\",\n                         byte_pos, *cp_expected, *cp_actual);\n        }\n        ++cp_expected;\n        ++cp_actual;\n    }\n}\n\n/******************************************************************************/\nvoid\ncheck_fd_is_dev_zero(int fd)\n{\n    char buff[1] = { '\\001' };\n    int status;\n    status = g_file_read(fd, buff, sizeof(buff));\n    ck_assert_int_eq(status, 1);\n    ck_assert_int_eq(buff[0], '\\0');\n\n    status = g_file_write(fd, buff, sizeof(buff));\n    ck_assert_int_eq(status, 1);\n}\n\n/******************************************************************************/\n\nint\ndoes_stream_contain_string(const struct stream *s, const char *str)\n{\n    int len = g_strlen(str);\n    int i;\n    if (len > 0 && len <= s->size)\n    {\n        for (i = 0 ; i <= s->size - len; ++i)\n        {\n            /* This is not a sophisticated string search. We use a\n             * single character test to avoid a function call for\n             * every comparison */\n            if (str[0] == s->data[i] && g_memcmp(str, &s->data[i], len) == 0)\n            {\n                return 1;\n            }\n        }\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nunsigned int\nget_open_fd_count(void)\n{\n    unsigned int i;\n    unsigned int rv;\n\n    // What's the max number of file descriptors?\n    struct rlimit nofile;\n    if (getrlimit(RLIMIT_NOFILE, &nofile) < 0)\n    {\n        const char *errstr = g_get_strerror();\n        ck_abort_msg(\"Can't create socketpair [%s]\", errstr);\n    }\n\n    struct pollfd *fds =\n        (struct pollfd *)g_malloc(sizeof(struct pollfd) * nofile.rlim_cur, 0);\n    ck_assert_ptr_nonnull(fds);\n\n    for (i = 0 ; i < nofile.rlim_cur; ++i)\n    {\n        fds[i].fd = i;\n        fds[i].events = 0;\n        fds[i].revents = 0;\n    }\n\n    if (poll(fds, nofile.rlim_cur, 0) < 0)\n    {\n        const char *errstr = g_get_strerror();\n        ck_abort_msg(\"Can't poll fds [%s]\", errstr);\n    }\n\n    rv = nofile.rlim_cur;\n    for (i = 0 ; i < nofile.rlim_cur; ++i)\n    {\n        if (fds[i].revents == POLLNVAL)\n        {\n            --rv;\n        }\n    }\n\n    g_free(fds);\n\n    return rv;\n}\n\n/******************************************************************************/\nint main (void)\n{\n    int number_failed;\n    SRunner *sr;\n\n    sr = srunner_create (make_suite_test_libipm_send_calls());\n    srunner_add_suite (sr, make_suite_test_libipm_recv_calls());\n\n    srunner_set_tap(sr, \"-\");\n    /*\n     * Set up console logging */\n    struct log_config *lc = log_config_init_for_console(LOG_LEVEL_INFO, NULL);\n    log_start_from_param(lc);\n    log_config_free(lc);\n    /* Disable stdout buffering, as this can confuse the error\n     * reporting when running in libcheck fork mode */\n    setvbuf(stdout, NULL, _IONBF, 0);\n\n    /* Initialise modules */\n    suite_test_libipm_calls_start();\n\n    srunner_run_all (sr, CK_ENV);\n    number_failed = srunner_ntests_failed(sr);\n    srunner_free(sr);\n\n    suite_test_libipm_calls_end();\n\n    log_end();\n    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\n}\n"
  },
  {
    "path": "tests/libipm/test_libipm_recv_calls.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <unistd.h>\n\n#include \"libipm.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"trans.h\"\n\n#include \"test_libipm.h\"\n\n/* Random(ish) values for test_libipm_send_recv_all_test */\n#define TEST_y_VALUE 89\n#define TEST_b_VALUE 1\n#define TEST_n_VALUE -143\n#define TEST_q_VALUE 329\n#define TEST_i_VALUE -150000\n#define TEST_u_VALUE 150000\n#define TEST_x_VALUE -4500000000L\n#define TEST_t_VALUE 8500000000L\n#define TEST_s_VALUE \"libipm recv test\"\n#define TEST_B_VALUE  'b', 'y', 'B', 'Y', '8', '2', '/'\n\n/**\n * Type for fields in the message header\n *\n * The type value is the offset of the field within the header\n */\nenum header_field\n{\n    HDR_IPM_VER = 0,\n    HDR_MSG_LEN = 2,\n    HDR_FACILITY = 4,\n    HDR_MSGNO = 6,\n    HDR_RESERVED = 8\n};\n\n/**\n * Gets a message header field value */\nstatic unsigned int\nget_header_field(struct stream *s, enum header_field field)\n{\n    unsigned int res;\n    char *saved_p = s->p;\n    s->p = s->data + (unsigned short)field;\n    if (field == HDR_RESERVED)\n    {\n        in_uint32_le(s, res);\n    }\n    else\n    {\n        in_uint16_le(s, res);\n    }\n\n    s->p = saved_p;\n\n    return res;\n}\n\n/**\n * Sets a message header field value */\nstatic void\nset_header_field(struct stream *s, enum header_field field, unsigned int val)\n{\n    char *saved_p = s->p;\n    s->p = s->data + (unsigned short)field;\n    if (field == HDR_RESERVED)\n    {\n        out_uint32_le(s, val);\n    }\n    else\n    {\n        out_uint16_le(s, val);\n    }\n\n    s->p = saved_p;\n}\n\n/**\n * Flushes input on a non-blocking socket\n *\n * Returns number of bytes read\n */\nstatic unsigned int\nflush_socket(int sck)\n{\n    char buff[1024];\n    unsigned int result = 0;\n    int status;\n    while (1)\n    {\n        status = g_sck_recv(g_t_in->sck, buff, sizeof(buff), 0);\n        if (status < 0)\n        {\n            break;\n        }\n        result += status;\n    }\n\n    return result;\n}\n\n/**\n * Waits for an expected incoming message */\nstatic void\ncheck_for_incoming_message(unsigned short expected_msgno)\n{\n    enum libipm_status status;\n    unsigned short msgno;\n\n    /* Get the message at the other end */\n    libipm_msg_in_reset(g_t_in);\n    status = libipm_msg_in_wait_available(g_t_in);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    msgno = libipm_msg_in_get_msgno(g_t_in);\n    ck_assert_int_eq(msgno, expected_msgno);\n}\n\n/**\n * Test for input truncated by a number of bytes\n *\n * This call assumes the output buffer contains a message of a single\n * type that has already been successfully sent and checked.\n *\n * The send size is truncated, and the message is sent again. This\n * lets us check the input parser won't accept a type for which\n * there is insufficient data.\n */\nstatic void\ntest_truncated_input_type(char typechar, void *valueptr,\n                          int truncate_value,\n                          enum libipm_status expected_status)\n\n{\n    const char format[] = {typechar, '\\0'};\n    enum libipm_status status;\n    int istatus;\n    unsigned int msg_size;\n\n    /* The same message is still in the buffer.\n     *\n     * reduce the payload length by the truncate value...*/\n    msg_size = get_header_field(g_t_out->out_s, HDR_MSG_LEN);\n    set_header_field(g_t_out->out_s, HDR_MSG_LEN, msg_size - truncate_value);\n\n    /* ...and re-send it */\n    istatus = trans_force_write(g_t_out);\n    ck_assert_int_eq(istatus, 0);\n\n    /* Catch the message at the other end */\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    switch (typechar)\n    {\n        case 'B':\n            /* For this type, the descriptor is critical to read\n             * the value */\n            status = libipm_msg_in_parse(g_t_in, format,\n                                         (struct fsb_type *)valueptr);\n            break;\n        default:\n            /* For other types, the value shouldn't be needed, as\n             * it's only written to if the parse is successful */\n            status = libipm_msg_in_parse(g_t_in, format,\n                                         (struct fsb_type *)NULL);\n            break;\n    }\n    ck_assert_int_eq(status, expected_status);\n\n    /* There should be 'truncate_value' extra octets left on the input\n    * socket which wasn't read when we shrunk the header */\n    istatus = flush_socket(g_t_in->sck);\n    ck_assert_int_eq(istatus, truncate_value);\n\n    /* Put the message size back to its original value, for further tests */\n    set_header_field(g_t_out->out_s, HDR_MSG_LEN, msg_size);\n}\n\n/**\n * Test for bad header values\n *\n * This call assumes the output buffer contains a message containing\n * a single 'u' type that has already been send and checked\n *\n * The specified header field is overwritten, and the message is\n * sent. On the receive side we check for a 'bad header' error, and\n * then put everything back to its starting place.\n */\nstatic void\ntest_bad_header_value(enum header_field field, unsigned int test_val)\n{\n    unsigned int old_val;\n    enum libipm_status status;\n    int istatus;\n\n    /* The same message is still in the buffer.\n     *\n     * Save the field value we are going to change, and replace it */\n    old_val = get_header_field(g_t_out->out_s, field);\n    set_header_field(g_t_out->out_s, field, test_val);\n\n    /* re-send the message */\n    istatus = trans_force_write(g_t_out);\n    ck_assert_int_eq(istatus, 0);\n\n    /* Catch the message at the other end. The error is\n     * reported when we wait for the incoming message */\n    libipm_msg_in_reset(g_t_in);\n    status = libipm_msg_in_wait_available(g_t_in);\n    ck_assert_int_eq(status, E_LI_BAD_HEADER);\n\n    /* There should be 5 extra octets ('u' + 32-bit value) left on the input\n    * socket which wasn't read when we broke the header */\n    istatus = flush_socket(g_t_in->sck);\n    ck_assert_int_eq(istatus, 1 + sizeof(uint32_t));\n\n    /* Put the message size back to its original value, for further tests */\n    set_header_field(g_t_out->out_s, field, old_val);\n}\n\n/***************************************************************************//**\n * As the 'append all' test, but data is sent across a link, demarshalled,\n * and validated */\nSTART_TEST(test_libipm_send_recv_all_test)\n{\n    ck_assert_ptr_ne(g_t_out, NULL);\n    ck_assert_ptr_ne(g_t_in, NULL);\n\n    static char bin_out[] = { TEST_B_VALUE };\n    struct libipm_fsb binary_desc = { (void *)bin_out, sizeof(bin_out) };\n    enum libipm_status status;\n\n    /* variables for received values */\n    uint8_t y;\n    int b;\n    int16_t n;\n    uint16_t q;\n    int32_t i;\n    uint32_t u;\n    int64_t x;\n    uint64_t t;\n    char *s;\n    int h = -1;\n    char B[sizeof(bin_out)];\n    char c;\n\n    /* The message is small enough to fit in the socket buffer */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO,\n                 \"ybnqiuxtshB\",\n                 TEST_y_VALUE,\n                 TEST_b_VALUE,\n                 TEST_n_VALUE,\n                 TEST_q_VALUE,\n                 TEST_i_VALUE,\n                 TEST_u_VALUE,\n                 TEST_x_VALUE,\n                 TEST_t_VALUE,\n                 TEST_s_VALUE,\n                 g_fd,\n                 &binary_desc);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    /* Catch the message at the other end */\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Re-use our descriptor for the receive operation */\n    binary_desc.data = (void *)&B;\n    binary_desc.datalen = sizeof(B);\n\n    status = libipm_msg_in_parse(\n                 g_t_in,\n                 \"ybnqiuxtshB\",\n                 &y, &b, &n, &q, &i, &u, &x, &t, &s, &h, &binary_desc);\n\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(y, TEST_y_VALUE);\n    ck_assert_int_eq(b, TEST_b_VALUE);\n    ck_assert_int_eq(n, TEST_n_VALUE);\n    ck_assert_int_eq(q, TEST_q_VALUE);\n    ck_assert_int_eq(i, TEST_i_VALUE);\n    ck_assert_int_eq(u, TEST_u_VALUE);\n    ck_assert_int_eq(x, TEST_x_VALUE);\n    ck_assert_int_eq(t, TEST_t_VALUE);\n    check_binary_data_eq(TEST_s_VALUE, sizeof(TEST_s_VALUE) - 1,\n                         s, g_strlen(s));\n    /* The file descriptor should not be -1, neither should it be\n     * the value we sent. It should also point to /dev/zero */\n    ck_assert_int_ne(h, -1);\n    ck_assert_int_ne(h, g_fd);\n    check_fd_is_dev_zero(h);\n    g_file_close(h);\n\n    check_binary_data_eq(bin_out, sizeof(bin_out), B, sizeof(B));\n\n    /* Check we're at the end of the message */\n    c = libipm_msg_in_peek_type(g_t_in);\n    ck_assert_int_eq(c, '\\0');\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 'y'\n */\nSTART_TEST(test_libipm_receive_y_type)\n{\n    enum libipm_status status;\n    uint8_t y;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"y\", TEST_y_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"y\", &y);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(y, TEST_y_VALUE);\n\n    test_truncated_input_type('y', &y, 1, E_LI_BUFFER_OVERFLOW);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 'b'\n */\nSTART_TEST(test_libipm_receive_b_type)\n{\n    enum libipm_status status;\n    int b;\n    int istatus;\n    char c;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"b\", TEST_b_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"b\", &b);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(b, TEST_b_VALUE);\n\n    test_truncated_input_type('b', &b, 1, E_LI_BUFFER_OVERFLOW);\n\n    /* Resend and re-catch the message */\n    istatus = trans_force_write(g_t_out);\n    ck_assert_int_eq(istatus, 0);\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Modify the message to contain a '2' for the boolean */\n    c = libipm_msg_in_peek_type(g_t_in);\n    ck_assert_int_eq(c, 'b'); /* Next type should be a 'b' */\n    c = *(g_t_in->in_s->p + 1); /* This should be the test value */\n    ck_assert_int_eq(c, TEST_b_VALUE); /* Check it */\n    *(g_t_in->in_s->p + 1) = 2;\n    status = libipm_msg_in_parse( g_t_in, \"b\", &b);\n    ck_assert_int_eq(status, E_LI_BAD_VALUE);\n\n    /* Resend and re-catch the message */\n    istatus = trans_force_write(g_t_out);\n    ck_assert_int_eq(istatus, 0);\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Modify the message to contain a '-1' for the boolean */\n    *(g_t_in->in_s->p + 1) = (char) -1;\n    status = libipm_msg_in_parse( g_t_in, \"b\", &b);\n    ck_assert_int_eq(status, E_LI_BAD_VALUE);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 'n'\n */\nSTART_TEST(test_libipm_receive_n_type)\n{\n    enum libipm_status status;\n    int16_t n;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"n\", TEST_n_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"n\", &n);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(n, TEST_n_VALUE);\n\n    test_truncated_input_type('n', &n, 1, E_LI_BUFFER_OVERFLOW);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 'q'\n */\nSTART_TEST(test_libipm_receive_q_type)\n{\n    enum libipm_status status;\n    uint16_t q;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"q\", TEST_q_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"q\", &q);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(q, TEST_q_VALUE);\n\n    test_truncated_input_type('q', &q, 1, E_LI_BUFFER_OVERFLOW);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 'i'\n */\nSTART_TEST(test_libipm_receive_i_type)\n{\n    enum libipm_status status;\n    int32_t i;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"i\", TEST_i_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"i\", &i);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(i, TEST_i_VALUE);\n\n    test_truncated_input_type('i', &i, 1, E_LI_BUFFER_OVERFLOW);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 'u'\n */\nSTART_TEST(test_libipm_receive_u_type)\n{\n    enum libipm_status status;\n    uint32_t u;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"u\", TEST_u_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"u\", &u);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(u, TEST_u_VALUE);\n\n    test_truncated_input_type('u', &u, 1, E_LI_BUFFER_OVERFLOW);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 'x'\n */\nSTART_TEST(test_libipm_receive_x_type)\n{\n    enum libipm_status status;\n    int64_t x;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"x\", TEST_x_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"x\", &x);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(x, TEST_x_VALUE);\n\n    test_truncated_input_type('x', &x, 1, E_LI_BUFFER_OVERFLOW);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 't'\n */\nSTART_TEST(test_libipm_receive_t_type)\n{\n    enum libipm_status status;\n    uint64_t t;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"t\", TEST_t_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"t\", &t);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(t, TEST_t_VALUE);\n\n    test_truncated_input_type('t', &t, 1, E_LI_BUFFER_OVERFLOW);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 's'\n */\nSTART_TEST(test_libipm_receive_s_type)\n{\n    enum libipm_status status;\n    char *s;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"s\", TEST_s_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"s\", &s);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    check_binary_data_eq(TEST_s_VALUE, sizeof(TEST_s_VALUE) - 1,\n                         s, g_strlen(s));\n\n    /* This effectively tests that unterminated strings are not\n     * passed back to the user */\n    test_truncated_input_type('s', &s, 1, E_LI_BAD_VALUE);\n}\nEND_TEST\n\n\n/***************************************************************************//**\n * Checks various receive errors for 'h'\n */\nSTART_TEST(test_libipm_receive_h_type)\n{\n    enum libipm_status status;\n    int istatus;\n    unsigned int i;\n    int fd_count;\n\n    /* Get the number of open file descriptors */\n    int base_fd_count = get_open_fd_count();\n    ck_assert_int_gt(base_fd_count, 0);\n\n    /* Send the max number of copies of the /dev/zero\n     * file descriptor */\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, NULL);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    for (i = 0 ; i < LIBIPM_MAX_FD_PER_MSG; ++i)\n    {\n        status = libipm_msg_out_append(g_t_out, \"h\", g_fd);\n        ck_assert_int_eq(status, E_LI_SUCCESS);\n    }\n    libipm_msg_out_mark_end(g_t_out);\n    istatus = trans_force_write(g_t_out);\n    ck_assert_int_eq(istatus, 0);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the number of file descriptors has gone up as expected */\n    fd_count = get_open_fd_count();\n    ck_assert_int_eq(fd_count, base_fd_count + LIBIPM_MAX_FD_PER_MSG);\n\n    /* Check half the descriptors work */\n    for (i = 0 ; i < LIBIPM_MAX_FD_PER_MSG / 2; ++i)\n    {\n        int h = -1;\n        status = libipm_msg_in_parse(g_t_in, \"h\", &h);\n        ck_assert_int_eq(status, E_LI_SUCCESS);\n        check_fd_is_dev_zero(h);\n        g_file_close(h);\n    }\n\n    /* Close the message without reading the other descriptors */\n    libipm_msg_in_reset(g_t_in);\n\n    /* Check all the file descriptors we received have been closed */\n    fd_count = get_open_fd_count();\n    ck_assert_int_eq(fd_count, base_fd_count);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various receive errors for 'B'\n */\nSTART_TEST(test_libipm_receive_B_type)\n{\n    enum libipm_status status;\n    static char bin_out[] = { TEST_B_VALUE };\n    char bin_in[sizeof(bin_out)];\n\n    struct libipm_fsb binary_desc = { (void *)bin_out, sizeof(bin_out) };\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"B\", &binary_desc);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    binary_desc.data = (void *)bin_in;\n    binary_desc.datalen = sizeof(bin_in);\n\n    status = libipm_msg_in_parse( g_t_in, \"B\", &binary_desc);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    check_binary_data_eq(bin_out, sizeof(bin_out),\n                         bin_in, sizeof(bin_in));\n\n    /* Check a truncated binary object is rejected */\n    test_truncated_input_type('B', &binary_desc, 1, E_LI_BUFFER_OVERFLOW);\n\n    /* Check a binary object without a complete length field is rejected */\n    test_truncated_input_type('B', &binary_desc, sizeof(bin_out) + 1,\n                              E_LI_BUFFER_OVERFLOW);\n\n    /* Check a binary object with a mismatching FSB length field is rejected */\n    --binary_desc.datalen;\n    test_truncated_input_type('B', &binary_desc, 0, E_LI_BAD_VALUE);\n    ++binary_desc.datalen;\n\n    /* Check a binary object with a null FSB data field is rejected */\n    binary_desc.data = NULL;\n    test_truncated_input_type('B', &binary_desc, 0, E_LI_PROGRAM_ERROR);\n    test_truncated_input_type('B', NULL, 0, E_LI_PROGRAM_ERROR);\n}\nEND_TEST\n\n\n/***************************************************************************//**\n * Checks for a message with a completely missing type\n */\nSTART_TEST(test_libipm_receive_no_type)\n{\n    enum libipm_status status;\n    uint32_t u;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"u\", TEST_u_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"u\", &u);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(u, TEST_u_VALUE);\n\n    /* Completely remove the type flag and the value from the message */\n    test_truncated_input_type('u', &u, sizeof(uint32_t) + 1,\n                              E_LI_BUFFER_OVERFLOW);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks for a message with an unexpected type\n */\nSTART_TEST(test_libipm_receive_unexpected_type)\n{\n    enum libipm_status status;\n    int istatus;\n    uint32_t u;\n    int32_t i;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"u\", TEST_u_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"u\", &u);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(u, TEST_u_VALUE);\n\n    /* Resend and re-catch the message */\n    istatus = trans_force_write(g_t_out);\n    ck_assert_int_eq(istatus, 0);\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Try parsing with a type mismatch */\n    status = libipm_msg_in_parse( g_t_in, \"i\", &i);\n    ck_assert_int_eq(status, E_LI_UNEXPECTED_TYPE);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks for a message with an unsupported type\n */\nSTART_TEST(test_libipm_receive_unsupported_type)\n{\n    enum libipm_status status;\n    int istatus;\n    uint32_t u;\n    char c;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"u\", TEST_u_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"u\", &u);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(u, TEST_u_VALUE);\n\n    /* Resend and re-catch the message */\n    istatus = trans_force_write(g_t_out);\n    ck_assert_int_eq(istatus, 0);\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Modify the message to contain an unsupported type */\n    c = libipm_msg_in_peek_type(g_t_in);\n    ck_assert_int_eq(c, 'u'); /* Next type should be a 'u' */\n    *g_t_in->in_s->p = 'A'; /* unsupported type */\n    c = libipm_msg_in_peek_type(g_t_in);\n    ck_assert_int_eq(c, '?'); /* peek should say this is an error */\n    /* Parse it anyway */\n    status = libipm_msg_in_parse( g_t_in, \"A\", (const char *)0);\n    ck_assert_int_eq(status, E_LI_UNSUPPORTED_TYPE);\n}\nEND_TEST\n\n\n/***************************************************************************//**\n * Checks for a message with an unimplemented type\n */\nSTART_TEST(test_libipm_receive_unimplemented_type)\n{\n    enum libipm_status status;\n    int istatus;\n    uint32_t u;\n    char c;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO_STRING_NO, \"u\", TEST_u_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO_STRING_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"u\", &u);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(u, TEST_u_VALUE);\n\n    /* Resend and re-catch the message */\n    istatus = trans_force_write(g_t_out);\n    ck_assert_int_eq(istatus, 0);\n    check_for_incoming_message(TEST_MESSAGE_NO_STRING_NO);\n\n    /* Try parsing with an unimplemented type.\n     * To do this we need to modify the type marker in the input stream */\n    c = libipm_msg_in_peek_type(g_t_in);\n    ck_assert_int_eq(c, 'u'); /* Next type should be a 'u' */\n    *g_t_in->in_s->p = 'd'; /* reserved type */\n    c = libipm_msg_in_peek_type(g_t_in);\n    ck_assert_int_eq(c, 'd');\n    status = libipm_msg_in_parse( g_t_in, \"d\", (const char *)0);\n    ck_assert_int_eq(status, E_LI_UNIMPLEMENTED_TYPE);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks for bad header values\n */\nSTART_TEST(test_libipm_receive_bad_header)\n{\n    enum libipm_status status;\n    uint32_t u;\n    unsigned short hdr_ipm_ver;\n    unsigned short hdr_facility;\n    unsigned int i;\n\n    /* First, a simple send... */\n    status = libipm_msg_out_simple_send(\n                 g_t_out, TEST_MESSAGE_NO, \"u\", TEST_u_VALUE);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    /* Check the value */\n    status = libipm_msg_in_parse( g_t_in, \"u\", &u);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n    ck_assert_int_eq(u, TEST_u_VALUE);\n\n    /* Save existing header values */\n    hdr_ipm_ver = get_header_field(g_t_out->out_s, HDR_IPM_VER);\n    hdr_facility = get_header_field(g_t_out->out_s, HDR_FACILITY);\n\n    test_bad_header_value(HDR_IPM_VER, hdr_ipm_ver + 1);\n    test_bad_header_value(HDR_FACILITY, hdr_facility - 1);\n    test_bad_header_value(HDR_RESERVED, 0xff);\n    test_bad_header_value(HDR_MSG_LEN, LIBIPM_MAX_MESSAGE_SIZE + 1);\n    test_bad_header_value(HDR_MSG_LEN, 0xffff);\n    for (i = 0 ; i < LIBIPM_HEADER_SIZE; ++i)\n    {\n        test_bad_header_value(HDR_MSG_LEN, i);\n    }\n}\nEND_TEST\n\n\n/***************************************************************************//**\n * Checks message erase works as expected\n */\nSTART_TEST(test_libipm_receive_msg_erase)\n{\n    enum libipm_status status;\n    int istatus;\n    const char *username = \"username\";\n    const char *password = \"password\";\n\n    /* Send a message containing sensitive information */\n    status = libipm_msg_out_simple_send(g_t_out, TEST_MESSAGE_NO, \"ss\",\n                                        username, password);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    check_for_incoming_message(TEST_MESSAGE_NO);\n    libipm_set_flags(g_t_in, LIBIPM_E_MSG_IN_ERASE_AFTER_USE);\n\n    ck_assert_int_ne(does_stream_contain_string(g_t_in->in_s, password), 0);\n    libipm_msg_in_reset(g_t_in);\n    ck_assert_msg(does_stream_contain_string(g_t_in->in_s, password) == 0,\n                  \"Auto buffer reset on input not working\");\n\n    /* The flag should be reset automatically */\n    /* Resend and re-catch the message */\n    istatus = trans_force_write(g_t_out);\n    ck_assert_int_eq(istatus, 0);\n    check_for_incoming_message(TEST_MESSAGE_NO);\n\n    ck_assert_int_ne(does_stream_contain_string(g_t_in->in_s, password), 0);\n    libipm_msg_in_reset(g_t_in);\n    ck_assert_msg(does_stream_contain_string(g_t_in->in_s, password) != 0,\n                  \"LIBIPM_E_MSG_IN_ERASE_AFTER_USE not automatically cleared\");\n}\nEND_TEST\n/***************************************************************************//**\n * Exercises codepaths that shouldn't be called (programming errors)\n */\nSTART_TEST(test_libipm_receive_programming_errors)\n{\n    enum libipm_status status;\n    int available;\n    int32_t dummy;\n\n    status = libipm_msg_in_wait_available(g_t_vanilla);\n    ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);\n\n    status = libipm_msg_in_check_available(g_t_vanilla, &available);\n    ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);\n\n    status = libipm_msg_in_parse(g_t_vanilla, \"i\", &dummy);\n    ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);\n\n    libipm_msg_in_reset(g_t_vanilla); /* No status to check */\n\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_libipm_recv_calls(void)\n{\n    Suite *s;\n    TCase *tc;\n\n    s = suite_create(\"libipm_recv\");\n\n    tc = tcase_create(\"libipm_recv\");\n    suite_add_tcase(s, tc);\n    tcase_add_test(tc, test_libipm_send_recv_all_test);\n    tcase_add_test(tc, test_libipm_receive_y_type);\n    tcase_add_test(tc, test_libipm_receive_b_type);\n    tcase_add_test(tc, test_libipm_receive_n_type);\n    tcase_add_test(tc, test_libipm_receive_q_type);\n    tcase_add_test(tc, test_libipm_receive_i_type);\n    tcase_add_test(tc, test_libipm_receive_u_type);\n    tcase_add_test(tc, test_libipm_receive_x_type);\n    tcase_add_test(tc, test_libipm_receive_t_type);\n    tcase_add_test(tc, test_libipm_receive_s_type);\n    tcase_add_test(tc, test_libipm_receive_h_type);\n    tcase_add_test(tc, test_libipm_receive_B_type);\n    tcase_add_test(tc, test_libipm_receive_no_type);\n    tcase_add_test(tc, test_libipm_receive_unexpected_type);\n    tcase_add_test(tc, test_libipm_receive_unsupported_type);\n    tcase_add_test(tc, test_libipm_receive_unimplemented_type);\n    tcase_add_test(tc, test_libipm_receive_bad_header);\n    tcase_add_test(tc, test_libipm_receive_msg_erase);\n    tcase_add_test(tc, test_libipm_receive_programming_errors);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/libipm/test_libipm_send_calls.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <unistd.h>\n#include <ctype.h>\n\n#include \"libipm.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"trans.h\"\n\n#include \"test_libipm.h\"\n\n/* Random(ish) values for test_libipm_append_all_test */\n#define ALL_TEST_y_VALUE 45\n#define ALL_TEST_b_VALUE 0\n#define ALL_TEST_n_VALUE -14\n#define ALL_TEST_q_VALUE 327\n#define ALL_TEST_i_VALUE -100000\n#define ALL_TEST_u_VALUE 100000\n#define ALL_TEST_x_VALUE -4000000000L\n#define ALL_TEST_t_VALUE 8000000000L\n#define ALL_TEST_s_VALUE \\\n    'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\\0'\n#define ALL_TEST_B_VALUE  'a', 'z', 'A', 'Z', '0', '9', '#'\n\n/* This macro generates two unsigned char values, separated by a comma,\n * representing a 2's complement little-endian 16-bit integer */\n#define BITS16_LE(x) ((x) & 0xff), (((unsigned int)(x) >> 8) & 0xff)\n\n/* This macro generates four unsigned char values, separated by a comma,\n * representing a 2's complement little-endian 32-bit integer */\n#define BITS32_LE(x) BITS16_LE((x) & 0xffff), \\\n    BITS16_LE(((unsigned int)(x) >> 16) & 0xffff)\n\n/* This macro generates eight unsigned char values, separated by a comma,\n * representing a 2's complement little-endian 64-bit integer */\n#define BITS64_LE(x) BITS32_LE((uint64_t)(x) & 0xffffffff), \\\n    BITS32_LE(((uint64_t)(x) >> 32) & 0xffffffff)\n\n/* Expected buffer contents for test_libipm_append_all_test */\nstatic const unsigned char all_test_expected_buff[] =\n{\n    BITS16_LE(LIBIPM_VERSION),\n    BITS16_LE(74),  /* Header : message length */\n    BITS16_LE(LIBIPM_FAC_TEST),\n    BITS16_LE(TEST_MESSAGE_NO),\n    BITS32_LE(0),\n    /* ------------------- */\n    'y', ALL_TEST_y_VALUE,\n    'b', ALL_TEST_b_VALUE,\n    'n', BITS16_LE(ALL_TEST_n_VALUE),\n    'q', BITS16_LE(ALL_TEST_q_VALUE),\n    'i', BITS32_LE(ALL_TEST_i_VALUE),\n    'u', BITS32_LE(ALL_TEST_u_VALUE),\n    'x', BITS64_LE(ALL_TEST_x_VALUE),\n    't', BITS64_LE(ALL_TEST_t_VALUE),\n    /* String + terminator */\n    's', ALL_TEST_s_VALUE,\n    'h', /* No buffer value is needed for 'h' */\n    /* Fixed size block */\n    'B', BITS16_LE(7) /* length */, ALL_TEST_B_VALUE\n};\n\n/* Type used to map small test values (i.e. simple types that fit in an int)\n * to expected status codes if we try to output them for a given type */\nstruct int_test_value\n{\n    int value;\n    enum libipm_status expected_status;\n};\n\n/***************************************************************************//**\n * Compares the data in a stream against an expected data block\n *\n * @param s Stream to check\n * @param expdata Expected data\n * @aram explen Expected data len\n */\nstatic void\ncheck_stream_data_eq(const struct stream *s,\n                     const unsigned char *expected_data,\n                     unsigned int expected_len)\n{\n    check_binary_data_eq((unsigned char *)s->data,\n                         (unsigned int)(s->end - s->data),\n                         expected_data,\n                         expected_len);\n}\n\n\n/***************************************************************************//**\n * Value checks for small types (i.e. those that fit in an 'int' */\nstatic void\ntest_small_type_values(char typechar,\n                       const struct int_test_value v[], unsigned int count)\n{\n    unsigned int i;\n    enum libipm_status status;\n    const char format[] = { typechar, '\\0'};\n\n    for (i = 0 ; i < count; ++i)\n    {\n        status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO,\n                                     format, v[i].value);\n        if (status != v[i].expected_status)\n        {\n            ck_abort_msg(\"Test value %d. Expected status %d, got %d\",\n                         v[i].value, v[i].expected_status, status);\n        }\n    }\n}\n\n/***************************************************************************//**\n * Checks we can add a simple type right at the end of a buffer, but that\n * a buffer overflow is also detected if there's not enough space.\n */\nstatic void\ntest_append_at_end_of_message(char typechar, unsigned int wire_size)\n{\n    char padding[LIBIPM_MAX_PAYLOAD_SIZE] = {0};\n    struct libipm_fsb desc;\n    enum libipm_status status;\n    const char format[] = {'B', typechar, '\\0'};\n\n    /* Construct a descriptor for a binary object that fills most of\n     * the output buffer, leaving just enough space for our type at the end.\n     * Three bytes are needed for the binary descriptor overhead */\n    desc.data = padding;\n    desc.datalen = LIBIPM_MAX_PAYLOAD_SIZE - 3 - wire_size;\n\n    /* Check we're OK at the end of the buffer... */\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, format, &desc, 0);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    /* ..but if the value would overflow the end of the packet it's an error */\n    ++desc.datalen;\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, format, &desc, 0);\n    ck_assert_int_eq(status, E_LI_BUFFER_OVERFLOW);\n}\n\n/***************************************************************************//**\n * Appends all data types to a transport, and checks the binary data in\n * the output stream is as expected */\nSTART_TEST(test_libipm_append_all_test)\n{\n    ck_assert_ptr_ne(g_t_out, NULL);\n\n    static char string[] = { ALL_TEST_s_VALUE };\n    static char binary[] = { ALL_TEST_B_VALUE };\n    struct libipm_fsb binary_desc = { (void *)binary, sizeof(binary) };\n    enum libipm_status status;\n\n    status = libipm_msg_out_init(\n                 g_t_out, TEST_MESSAGE_NO,\n                 \"ybnqiuxtshB\",\n                 ALL_TEST_y_VALUE,\n                 ALL_TEST_b_VALUE,\n                 ALL_TEST_n_VALUE,\n                 ALL_TEST_q_VALUE,\n                 ALL_TEST_i_VALUE,\n                 ALL_TEST_u_VALUE,\n                 ALL_TEST_x_VALUE,\n                 ALL_TEST_t_VALUE,\n                 string,\n                 g_fd,\n                 &binary_desc);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    libipm_msg_out_mark_end(g_t_out);\n\n    check_stream_data_eq(\n        g_t_out->out_s,\n        all_test_expected_buff, sizeof(all_test_expected_buff));\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 'y'\n */\nSTART_TEST(test_libipm_send_y_type)\n{\n    static const struct int_test_value test_values[] =\n    {\n        {0, E_LI_SUCCESS},\n        {255, E_LI_SUCCESS},\n        {-1, E_LI_BAD_VALUE},\n        {256, E_LI_BAD_VALUE},\n        {63336, E_LI_BAD_VALUE},\n        {2147483647, E_LI_BAD_VALUE}\n    };\n\n    test_small_type_values('y', test_values,\n                           sizeof(test_values) / sizeof(test_values[0]));\n\n    test_append_at_end_of_message('y', 2);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 'b'\n */\nSTART_TEST(test_libipm_send_b_type)\n{\n    static const struct int_test_value test_values[] =\n    {\n        {0, E_LI_SUCCESS},\n        {1, E_LI_SUCCESS},\n        {2, E_LI_BAD_VALUE},\n        {-1, E_LI_BAD_VALUE},\n        {256, E_LI_BAD_VALUE}\n    };\n\n    test_small_type_values('b', test_values,\n                           sizeof(test_values) / sizeof(test_values[0]));\n\n    test_append_at_end_of_message('b', 2);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 'n'\n */\nSTART_TEST(test_libipm_send_n_type)\n{\n    static const struct int_test_value test_values[] =\n    {\n        {-32768, E_LI_SUCCESS},\n        {32767, E_LI_SUCCESS},\n        {-32769, E_LI_BAD_VALUE},\n        {32768, E_LI_BAD_VALUE},\n        {2147483647, E_LI_BAD_VALUE}\n    };\n\n    test_small_type_values('n', test_values,\n                           sizeof(test_values) / sizeof(test_values[0]));\n\n    test_append_at_end_of_message('n', 3);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 'q'\n */\nSTART_TEST(test_libipm_send_q_type)\n{\n    static const struct int_test_value test_values[] =\n    {\n        {0, E_LI_SUCCESS},\n        {65535, E_LI_SUCCESS},\n        {-1, E_LI_BAD_VALUE},\n        {65536, E_LI_BAD_VALUE},\n        {2147483647, E_LI_BAD_VALUE}\n    };\n\n    test_small_type_values('q', test_values,\n                           sizeof(test_values) / sizeof(test_values[0]));\n\n    test_append_at_end_of_message('q', 3);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 'i'\n */\nSTART_TEST(test_libipm_send_i_type)\n{\n#if SIZEOF_INT > 4\n    static const struct int_test_value test_values[] =\n    {\n        {-2147483648, E_LI_SUCCESS},\n        {2147483647, E_LI_SUCCESS},\n        {-2147483649, E_LI_BAD_VALUE},\n        {2147483648, E_LI_BAD_VALUE},\n    };\n\n    test_small_type_values('i', test_values,\n                           sizeof(test_values) / sizeof(test_values[0]));\n#endif\n    test_append_at_end_of_message('i', 5);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 'u'\n */\nSTART_TEST(test_libipm_send_u_type)\n{\n#if SIZEOF_INT > 4\n    static const struct int_test_value test_values[] =\n    {\n        {0, E_LI_SUCCESS},\n        {4294967296, E_LI_SUCCESS},\n        {-1, E_LI_BAD_VALUE},\n        {4294967297, E_LI_BAD_VALUE},\n    };\n\n    test_small_type_values('u', test_values,\n                           sizeof(test_values) / sizeof(test_values[0]));\n#endif\n    test_append_at_end_of_message('u', 5);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 'x'\n */\nSTART_TEST(test_libipm_send_x_type)\n{\n    test_append_at_end_of_message('x', 9);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 't'\n */\nSTART_TEST(test_libipm_send_t_type)\n{\n    test_append_at_end_of_message('t', 9);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 's'\n */\nSTART_TEST(test_libipm_send_s_type)\n{\n    enum libipm_status status;\n\n    /* The maximum string length would be LIBIPM_MAX_PAYLOAD_SIZE-2, as we\n     * need one char for the 's' type marker, and another for the string\n     * terminator */\n\n    /* Construct a string one character too long to fit in the buffer */\n    char str[LIBIPM_MAX_PAYLOAD_SIZE];\n\n    g_memset(str, 'A', sizeof(str));\n    str[sizeof(str) - 1] = '\\0';\n\n    /* A write should overflow... */\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, \"s\", str);\n    ck_assert_int_eq(status, E_LI_BUFFER_OVERFLOW);\n\n    /* .. but a string one character shorter should be OK */\n    str[sizeof(str) - 2] = '\\0';\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, \"s\", str);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    /* Check passing a NULL string doesn't crash the program */\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO,\n                                 \"s\", (const char *)0);\n    ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 'h'\n */\nSTART_TEST(test_libipm_send_h_type)\n{\n    enum libipm_status status;\n    unsigned int i;\n\n    test_append_at_end_of_message('h', 1);\n\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, NULL);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    for (i = 0 ; i < LIBIPM_MAX_FD_PER_MSG; ++i)\n    {\n        status = libipm_msg_out_append(g_t_out, \"h\", g_fd);\n        ck_assert_int_eq(status, E_LI_SUCCESS);\n    }\n\n    status = libipm_msg_out_append(g_t_out, \"h\", 1);\n    ck_assert_int_eq(status, E_LI_TOO_MANY_FDS);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks various send errors for 'B'\n */\nSTART_TEST(test_libipm_send_B_type)\n{\n    enum libipm_status status;\n    char bin[LIBIPM_MAX_PAYLOAD_SIZE] = {0};\n    struct libipm_fsb desc;\n\n    /* The maximum binary block length would be LIBIPM_MAX_PAYLOAD_SIZE - 3,\n     * as we need one char for the 'B' type marker, and two for the length\n     *\n     * Construct a descriptor for a binary object that completely fills\n     * the output buffer */\n    desc.data = bin;\n    desc.datalen = LIBIPM_MAX_PAYLOAD_SIZE - 3;\n\n    /* Check it fits in the buffer... */\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, \"B\", &desc);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    /* ..but one byte bigger, and it won't fit */\n    ++desc.datalen;\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, \"B\", &desc);\n    ck_assert_int_eq(status, E_LI_BUFFER_OVERFLOW);\n    --desc.datalen;\n\n    /* Check NULL pointers don't crash the library */\n    desc.data = NULL;\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, \"B\", &desc);\n    ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, \"B\",\n                                 (const struct libipm_fsb *)0);\n    ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks send errors for unsupported and unimplemented types\n */\nSTART_TEST(test_libipm_send_bad_types)\n{\n    enum libipm_status status;\n    enum libipm_status expected_status;\n    char format[2] = {0};\n    char c;\n\n    for (c = 0x1; c < 0x7f; ++c)\n    {\n        if (!isprint(c))\n        {\n            continue;\n        }\n\n        if (g_strchr(g_supported_types, c) == NULL)\n        {\n            expected_status = E_LI_UNSUPPORTED_TYPE;\n        }\n        else if (g_strchr(g_unimplemented_types, c) != NULL)\n        {\n            expected_status = E_LI_UNIMPLEMENTED_TYPE;\n        }\n        else\n        {\n            continue;\n        }\n\n        format[0] = c;\n        status = libipm_msg_out_init(g_t_out,\n                                     TEST_MESSAGE_NO_STRING_NO,\n                                     format, (const char *)0);\n        if (status != expected_status)\n        {\n            ck_abort_msg(\"Output char '%c'. Expected status %d, got %d\",\n                         c, expected_status, status);\n        }\n    }\n}\nEND_TEST\n\n/***************************************************************************//**\n * Checks message erase works as expected\n *\n * Also calls libipm_msg_out_append() which isn't exercised anywhere else\n */\nSTART_TEST(test_libipm_send_msg_erase)\n{\n    enum libipm_status status;\n    const char *username = \"username\";\n    const char *password = \"password\";\n\n    status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, NULL);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    status = libipm_msg_out_append(g_t_out, \"ss\", username, password);\n    ck_assert_int_eq(status, E_LI_SUCCESS);\n\n    ck_assert_int_ne(does_stream_contain_string(g_t_out->out_s, password), 0);\n    libipm_msg_out_erase(g_t_out);\n    ck_assert_int_eq(does_stream_contain_string(g_t_out->out_s, password), 0);\n}\nEND_TEST\n\n/***************************************************************************//**\n * Exercises codepaths that shouldn't be called (programming errors)\n */\nSTART_TEST(test_libipm_send_programming_errors)\n{\n    enum libipm_status status;\n\n    status = libipm_msg_out_init(g_t_vanilla, TEST_MESSAGE_NO, NULL);\n    ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);\n\n    status = libipm_msg_out_append(g_t_vanilla, \"i\", 0);\n    ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);\n\n    libipm_msg_out_mark_end(g_t_vanilla); /* No status to check */\n\n    status = libipm_msg_out_simple_send(g_t_vanilla, TEST_MESSAGE_NO, \"i\", 0);\n    ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);\n\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_libipm_send_calls(void)\n{\n    Suite *s;\n    TCase *tc;\n\n    s = suite_create(\"libipm_send\");\n\n    tc = tcase_create(\"libipm_send\");\n    suite_add_tcase(s, tc);\n    tcase_add_test(tc, test_libipm_append_all_test);\n    tcase_add_test(tc, test_libipm_send_y_type);\n    tcase_add_test(tc, test_libipm_send_b_type);\n    tcase_add_test(tc, test_libipm_send_n_type);\n    tcase_add_test(tc, test_libipm_send_q_type);\n    tcase_add_test(tc, test_libipm_send_i_type);\n    tcase_add_test(tc, test_libipm_send_u_type);\n    tcase_add_test(tc, test_libipm_send_x_type);\n    tcase_add_test(tc, test_libipm_send_t_type);\n    tcase_add_test(tc, test_libipm_send_s_type);\n    tcase_add_test(tc, test_libipm_send_h_type);\n    tcase_add_test(tc, test_libipm_send_B_type);\n    tcase_add_test(tc, test_libipm_send_y_type);\n    tcase_add_test(tc, test_libipm_send_bad_types);\n    tcase_add_test(tc, test_libipm_send_msg_erase);\n    tcase_add_test(tc, test_libipm_send_programming_errors);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/libxrdp/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n  -I$(top_builddir) \\\n  -I$(top_srcdir)/libxrdp \\\n  -I$(top_srcdir)/common\n\nLOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \\\n                  $(top_srcdir)/tap-driver.sh\n\nPACKAGE_STRING = \"libxrdp\"\n\nTESTS = test_libxrdp\ncheck_PROGRAMS = test_libxrdp\n\ntest_libxrdp_SOURCES = \\\n    test_libxrdp.h \\\n    test_libxrdp_main.c \\\n    test_libxrdp_process_monitor_stream.c \\\n    test_xrdp_sec_process_mcs_data_monitors.c\n\ntest_libxrdp_CFLAGS = \\\n    @CHECK_CFLAGS@\n\ntest_libxrdp_LDADD = \\\n    $(top_builddir)/common/libcommon.la \\\n    $(top_builddir)/libxrdp/libxrdp.la \\\n    @CHECK_LIBS@\n"
  },
  {
    "path": "tests/libxrdp/test_libxrdp.h",
    "content": "#ifndef TEST_LIBXRDP_H\n#define TEST_LIBXRDP_H\n\n#include <check.h>\n\nSuite *make_suite_test_xrdp_sec_process_mcs_data_monitors(void);\nSuite *make_suite_test_monitor_processing(void);\n\n#endif /* TEST_LIBXRDP_H */\n"
  },
  {
    "path": "tests/libxrdp/test_libxrdp_main.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include \"log.h\"\n#include \"test_libxrdp.h\"\n\nint main (void)\n{\n    int number_failed;\n    SRunner *sr;\n\n    sr = srunner_create(make_suite_test_xrdp_sec_process_mcs_data_monitors());\n    srunner_add_suite(sr, make_suite_test_monitor_processing());\n\n    srunner_set_tap(sr, \"-\");\n\n    /*\n     * Set up console logging */\n    struct log_config *lc = log_config_init_for_console(LOG_LEVEL_INFO, NULL);\n    log_start_from_param(lc);\n    log_config_free(lc);\n    /* Disable stdout buffering, as this can confuse the error\n     * reporting when running in libcheck fork mode */\n    setvbuf(stdout, NULL, _IONBF, 0);\n\n    srunner_run_all (sr, CK_ENV);\n    number_failed = srunner_ntests_failed(sr);\n    srunner_free(sr);\n    log_end();\n    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\n}\n"
  },
  {
    "path": "tests/libxrdp/test_libxrdp_process_monitor_stream.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"libxrdp.h\"\n#include \"os_calls.h\"\n\n#include \"test_libxrdp.h\"\n\nSTART_TEST(test_libxrdp_process_monitor_stream__when_description_is_null__fail)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 4);\n\n    //Dummy data.\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    int error = libxrdp_process_monitor_stream(s, NULL, 1);\n    ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR);\n\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_libxrdp_process_monitor_stream__when_stream_is_too_small__fail)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 2);\n\n    //Dummy data.\n    out_uint16_le(s, 0);\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    struct display_size_description *description =\n        (struct display_size_description *)\n        g_malloc(sizeof(struct display_size_description), 1);\n\n    int error = libxrdp_process_monitor_stream(s, description, 1);\n    ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR);\n\n    free(description);\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_libxrdp_process_monitor_stream__when_monitor_count_is_greater_than_sixteen__fail)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 4);\n\n    //Dummy data.\n    out_uint32_le(s, 17);\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    struct display_size_description *description =\n        (struct display_size_description *)\n        g_malloc(sizeof(struct display_size_description), 1);\n\n    int error = libxrdp_process_monitor_stream(s, description, 1);\n    ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR_TOO_MANY_MONITORS);\n\n    free(description);\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_libxrdp_process_monitor_stream__with_single_monitor_happy_path)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 44);\n\n    out_uint32_le(s, 1); //monitorCount\n\n    // Pretend we have a 4k monitor\n    out_uint32_le(s, TS_MONITOR_PRIMARY); //flags\n    out_uint32_le(s, 0); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, 3840); //monitor width\n    out_uint32_le(s, 2160); //monitor height\n    out_uint32_le(s, 2000); //physical width\n    out_uint32_le(s, 2000); //physical height\n    out_uint32_le(s, 0); //orientation\n    out_uint32_le(s, 100); //desktop scale factor\n    out_uint32_le(s, 100); //device scale factor\n\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    struct display_size_description *description =\n        (struct display_size_description *)\n        g_malloc(sizeof(struct display_size_description), 1);\n\n    int error = libxrdp_process_monitor_stream(s, description, 1);\n\n    //Verify function call passed.\n    ck_assert_int_eq(error, 0);\n\n    ck_assert_int_eq(description->monitorCount, 1);\n\n    // Verify normal monitor\n    ck_assert_int_eq(description->minfo[0].left, 0);\n    ck_assert_int_eq(description->minfo[0].top, 0);\n    ck_assert_int_eq(description->minfo[0].right, 3839);\n    ck_assert_int_eq(description->minfo[0].bottom, 2159);\n    ck_assert_int_eq(description->minfo[0].physical_width, 2000);\n    ck_assert_int_eq(description->minfo[0].physical_height, 2000);\n    ck_assert_int_eq(description->minfo[0].orientation, 0);\n    ck_assert_int_eq(description->minfo[0].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[0].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[0].is_primary, 1);\n\n    // Verify normalized monitor\n    ck_assert_int_eq(description->minfo_wm[0].left, 0);\n    ck_assert_int_eq(description->minfo_wm[0].top, 0);\n    ck_assert_int_eq(description->minfo_wm[0].right, 3839);\n    ck_assert_int_eq(description->minfo_wm[0].bottom, 2159);\n    ck_assert_int_eq(description->minfo_wm[0].physical_width, 2000);\n    ck_assert_int_eq(description->minfo_wm[0].physical_height, 2000);\n    ck_assert_int_eq(description->minfo_wm[0].orientation, 0);\n    ck_assert_int_eq(description->minfo_wm[0].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[0].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[0].is_primary, 1);\n\n    // Verify geometry (+1 greater than )\n    ck_assert_int_eq(description->session_width, 3840);\n    ck_assert_int_eq(description->session_height, 2160);\n\n    free(description);\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_libxrdp_process_monitor_stream__with_sextuple_monitor_happy_path)\n{\n#define MONITOR_WIDTH 3840\n#define MONITOR_HEIGHT 2160\n\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 8192);\n\n    out_uint32_le(s, 6); //monitorCount\n\n    // 4k monitor at position (0, 0)\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, 0); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, MONITOR_WIDTH); //monitor width\n    out_uint32_le(s, MONITOR_HEIGHT); //monitor height\n    out_uint32_le(s, 9); //physical width\n    out_uint32_le(s, 9); //physical height\n    out_uint32_le(s, -10); //orientation\n    out_uint32_le(s, -100); //desktop scale factor\n    out_uint32_le(s, 600); //device scale factor\n\n    // 4k monitor at position (1, 0)\n    out_uint32_le(s, TS_MONITOR_PRIMARY); //flags\n    out_uint32_le(s, MONITOR_WIDTH); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, MONITOR_WIDTH); //monitor width\n    out_uint32_le(s, MONITOR_HEIGHT); //monitor height\n    out_uint32_le(s, 5); //physical width\n    out_uint32_le(s, 11000); //physical height\n    out_uint32_le(s, 10); //orientation (Expect to be reset to 0)\n    out_uint32_le(s, 360); //desktop scale factor\n    out_uint32_le(s, 720); //device scale factor\n\n    // 4k monitor at position (2, 0)\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, (2 * MONITOR_WIDTH)); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, MONITOR_WIDTH); //monitor width\n    out_uint32_le(s, MONITOR_HEIGHT); //monitor height\n    out_uint32_le(s, 1000); //physical width\n    out_uint32_le(s, 1000); //physical height\n    out_uint32_le(s, 5000); //orientation\n    out_uint32_le(s, 80); //desktop scale factor\n    out_uint32_le(s, 140); //device scale factor\n\n    // 4k monitor at position (0, 1)\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, 0); //monitor left\n    out_uint32_le(s, MONITOR_HEIGHT); //monitor top\n    out_uint32_le(s, MONITOR_WIDTH); //monitor width\n    out_uint32_le(s, MONITOR_HEIGHT); //monitor height\n    out_uint32_le(s, 1000); //physical width\n    out_uint32_le(s, 1000); //physical height\n    out_uint32_le(s, 91); //orientation\n    out_uint32_le(s, 180); //desktop scale factor\n    out_uint32_le(s, 100); //device scale factor\n\n    // 4k monitor at position (1, 1)\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, MONITOR_WIDTH); //monitor left\n    out_uint32_le(s, MONITOR_HEIGHT); //monitor top\n    out_uint32_le(s, MONITOR_WIDTH); //monitor width\n    out_uint32_le(s, MONITOR_HEIGHT); //monitor height\n    out_uint32_le(s, 1000); //physical width\n    out_uint32_le(s, 1000); //physical height\n    out_uint32_le(s, 0); //orientation\n    out_uint32_le(s, 20); //desktop scale factor\n    out_uint32_le(s, 50); //device scale factor\n\n    // 4k monitor at position (2, 1)\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, (2 * MONITOR_WIDTH)); //monitor left\n    out_uint32_le(s, MONITOR_HEIGHT); //monitor top\n    out_uint32_le(s, MONITOR_WIDTH); //monitor width\n    out_uint32_le(s, MONITOR_HEIGHT); //monitor height\n    out_uint32_le(s, 1000); //physical width\n    out_uint32_le(s, 1000); //physical height\n    out_uint32_le(s, 0); //orientation\n    out_uint32_le(s, 300); //desktop scale factor\n    out_uint32_le(s, 400); //device scale factor\n\n    s_mark_end(s);\n    // Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    struct display_size_description *description =\n        (struct display_size_description *)\n        g_malloc(sizeof(struct display_size_description), 1);\n\n    int error = libxrdp_process_monitor_stream(s, description, 1);\n\n    //Verify function call passed.\n    ck_assert_int_eq(error, 0);\n\n    ck_assert_int_eq(description->monitorCount, 6);\n\n    /*************************************************\n     * Verify standard monitors\n     *************************************************/\n    ck_assert_int_eq(description->minfo[0].left, 0);\n    ck_assert_int_eq(description->minfo[0].top, 0);\n    ck_assert_int_eq(description->minfo[0].right, MONITOR_WIDTH - 1);\n    ck_assert_int_eq(description->minfo[0].bottom, MONITOR_HEIGHT - 1);\n    ck_assert_int_eq(description->minfo[0].physical_width, 0);\n    ck_assert_int_eq(description->minfo[0].physical_height, 0);\n    ck_assert_int_eq(description->minfo[0].orientation, 0);\n    ck_assert_int_eq(description->minfo[0].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[0].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[0].is_primary, 0);\n\n    ck_assert_int_eq(description->minfo[1].left, MONITOR_WIDTH);\n    ck_assert_int_eq(description->minfo[1].top, 0);\n    ck_assert_int_eq(description->minfo[1].right, (2 * MONITOR_WIDTH - 1));\n    ck_assert_int_eq(description->minfo[1].bottom, MONITOR_HEIGHT - 1);\n    ck_assert_int_eq(description->minfo[1].physical_width, 0);\n    ck_assert_int_eq(description->minfo[1].physical_height, 0);\n    ck_assert_int_eq(description->minfo[1].orientation, 0);\n    ck_assert_int_eq(description->minfo[1].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[1].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[1].is_primary, 1);\n\n    ck_assert_int_eq(description->minfo[2].left, (2 * MONITOR_WIDTH));\n    ck_assert_int_eq(description->minfo[2].top, 0);\n    ck_assert_int_eq(description->minfo[2].right, (3 * MONITOR_WIDTH - 1));\n    ck_assert_int_eq(description->minfo[2].bottom, MONITOR_HEIGHT - 1);\n    ck_assert_int_eq(description->minfo[2].physical_width, 1000);\n    ck_assert_int_eq(description->minfo[2].physical_height, 1000);\n    ck_assert_int_eq(description->minfo[2].orientation, 0);\n    ck_assert_int_eq(description->minfo[2].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[2].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[2].is_primary, 0);\n\n    ck_assert_int_eq(description->minfo[3].left, 0);\n    ck_assert_int_eq(description->minfo[3].top, MONITOR_HEIGHT);\n    ck_assert_int_eq(description->minfo[3].right, MONITOR_WIDTH - 1);\n    ck_assert_int_eq(description->minfo[3].bottom, (2 * MONITOR_HEIGHT - 1));\n    ck_assert_int_eq(description->minfo[3].physical_width, 1000);\n    ck_assert_int_eq(description->minfo[3].physical_height, 1000);\n    ck_assert_int_eq(description->minfo[3].orientation, 0);\n    ck_assert_int_eq(description->minfo[3].desktop_scale_factor, 180);\n    ck_assert_int_eq(description->minfo[3].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[3].is_primary, 0);\n\n    ck_assert_int_eq(description->minfo[4].left, MONITOR_WIDTH);\n    ck_assert_int_eq(description->minfo[4].top, MONITOR_HEIGHT);\n    ck_assert_int_eq(description->minfo[4].right, (2 * MONITOR_WIDTH - 1));\n    ck_assert_int_eq(description->minfo[4].bottom, (2 * MONITOR_HEIGHT - 1));\n    ck_assert_int_eq(description->minfo[4].physical_width, 1000);\n    ck_assert_int_eq(description->minfo[4].physical_height, 1000);\n    ck_assert_int_eq(description->minfo[4].orientation, 0);\n    ck_assert_int_eq(description->minfo[4].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[4].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[4].is_primary, 0);\n\n    ck_assert_int_eq(description->minfo[5].left, (2 * MONITOR_WIDTH));\n    ck_assert_int_eq(description->minfo[5].top, MONITOR_HEIGHT);\n    ck_assert_int_eq(description->minfo[5].right, (3 * MONITOR_WIDTH - 1));\n    ck_assert_int_eq(description->minfo[5].bottom, (2 * MONITOR_HEIGHT - 1));\n    ck_assert_int_eq(description->minfo[5].physical_width, 1000);\n    ck_assert_int_eq(description->minfo[5].physical_height, 1000);\n    ck_assert_int_eq(description->minfo[5].orientation, 0);\n    ck_assert_int_eq(description->minfo[5].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[5].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo[5].is_primary, 0);\n\n    /*************************************************\n     * Verify normalized monitors\n     *************************************************/\n    ck_assert_int_eq(description->minfo_wm[0].left, 0);\n    ck_assert_int_eq(description->minfo_wm[0].top, 0);\n    ck_assert_int_eq(description->minfo_wm[0].right, MONITOR_WIDTH - 1);\n    ck_assert_int_eq(description->minfo_wm[0].bottom, MONITOR_HEIGHT - 1);\n    ck_assert_int_eq(description->minfo_wm[0].physical_width, 0);\n    ck_assert_int_eq(description->minfo_wm[0].physical_height, 0);\n    ck_assert_int_eq(description->minfo_wm[0].orientation, 0);\n    ck_assert_int_eq(description->minfo_wm[0].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[0].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[0].is_primary, 0);\n\n    ck_assert_int_eq(description->minfo_wm[1].left, MONITOR_WIDTH);\n    ck_assert_int_eq(description->minfo_wm[1].top, 0);\n    ck_assert_int_eq(description->minfo_wm[1].right, (2 * MONITOR_WIDTH - 1));\n    ck_assert_int_eq(description->minfo_wm[1].bottom, MONITOR_HEIGHT - 1);\n    ck_assert_int_eq(description->minfo_wm[1].physical_width, 0);\n    ck_assert_int_eq(description->minfo_wm[1].physical_height, 0);\n    ck_assert_int_eq(description->minfo_wm[1].orientation, 0);\n    ck_assert_int_eq(description->minfo_wm[1].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[1].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[1].is_primary, 1);\n\n    ck_assert_int_eq(description->minfo_wm[2].left, (2 * MONITOR_WIDTH));\n    ck_assert_int_eq(description->minfo_wm[2].top, 0);\n    ck_assert_int_eq(description->minfo_wm[2].right, (3 * MONITOR_WIDTH - 1));\n    ck_assert_int_eq(description->minfo_wm[2].bottom, MONITOR_HEIGHT - 1);\n    ck_assert_int_eq(description->minfo_wm[2].physical_width, 1000);\n    ck_assert_int_eq(description->minfo_wm[2].physical_height, 1000);\n    ck_assert_int_eq(description->minfo_wm[2].orientation, 0);\n    ck_assert_int_eq(description->minfo_wm[2].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[2].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[2].is_primary, 0);\n\n    ck_assert_int_eq(description->minfo_wm[3].left, 0);\n    ck_assert_int_eq(description->minfo_wm[3].top, MONITOR_HEIGHT);\n    ck_assert_int_eq(description->minfo_wm[3].right, MONITOR_WIDTH - 1);\n    ck_assert_int_eq(description->minfo_wm[3].bottom, (2 * MONITOR_HEIGHT - 1));\n    ck_assert_int_eq(description->minfo_wm[3].physical_width, 1000);\n    ck_assert_int_eq(description->minfo_wm[3].physical_height, 1000);\n    ck_assert_int_eq(description->minfo_wm[3].orientation, 0);\n    ck_assert_int_eq(description->minfo_wm[3].desktop_scale_factor, 180);\n    ck_assert_int_eq(description->minfo_wm[3].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[3].is_primary, 0);\n\n    ck_assert_int_eq(description->minfo_wm[4].left, MONITOR_WIDTH);\n    ck_assert_int_eq(description->minfo_wm[4].top, MONITOR_HEIGHT);\n    ck_assert_int_eq(description->minfo_wm[4].right, (2 * MONITOR_WIDTH - 1));\n    ck_assert_int_eq(description->minfo_wm[4].bottom, (2 * MONITOR_HEIGHT - 1));\n    ck_assert_int_eq(description->minfo_wm[4].physical_width, 1000);\n    ck_assert_int_eq(description->minfo_wm[4].physical_height, 1000);\n    ck_assert_int_eq(description->minfo_wm[4].orientation, 0);\n    ck_assert_int_eq(description->minfo_wm[4].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[4].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[4].is_primary, 0);\n\n    ck_assert_int_eq(description->minfo_wm[5].left, (2 * MONITOR_WIDTH));\n    ck_assert_int_eq(description->minfo_wm[5].top, MONITOR_HEIGHT);\n    ck_assert_int_eq(description->minfo_wm[5].right, (3 * MONITOR_WIDTH - 1));\n    ck_assert_int_eq(description->minfo_wm[5].bottom, (2 * MONITOR_HEIGHT - 1));\n    ck_assert_int_eq(description->minfo_wm[5].physical_width, 1000);\n    ck_assert_int_eq(description->minfo_wm[5].physical_height, 1000);\n    ck_assert_int_eq(description->minfo_wm[5].orientation, 0);\n    ck_assert_int_eq(description->minfo_wm[5].desktop_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[5].device_scale_factor, 100);\n    ck_assert_int_eq(description->minfo_wm[5].is_primary, 0);\n\n    // Verify geometry\n    ck_assert_int_eq(description->session_width, (3 * MONITOR_WIDTH));\n    ck_assert_int_eq(description->session_height, (2 * MONITOR_HEIGHT));\n\n    free(description);\n    free_stream(s);\n#undef MONITOR_WIDTH\n#undef MONITOR_HEIGHT\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_monitor_processing(void)\n{\n    Suite *s;\n    TCase *tc_process_monitors;\n\n    s = suite_create(\"test_libxrdp_process_monitor_stream\");\n\n    tc_process_monitors = tcase_create(\"libxrdp_process_monitor_stream\");\n    tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__when_description_is_null__fail);\n    tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__when_stream_is_too_small__fail);\n    tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__when_monitor_count_is_greater_than_sixteen__fail);\n    tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__with_single_monitor_happy_path);\n    tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__with_sextuple_monitor_happy_path);\n\n    suite_add_tcase(s, tc_process_monitors);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/libxrdp/test_xrdp_sec_process_mcs_data_monitors.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"libxrdp.h\"\n#include \"os_calls.h\"\n\n#include \"test_libxrdp.h\"\n\nstruct xrdp_sec *sec_layer;\nstruct xrdp_rdp *rdp_layer;\nstruct xrdp_session *session;\n\nstatic void setup(void)\n{\n    rdp_layer = (struct xrdp_rdp *)g_malloc(sizeof(struct xrdp_rdp), 1);\n    session = (struct xrdp_session *)g_malloc(sizeof(struct xrdp_session), 1);\n    session->rdp = rdp_layer;\n    session->client_info = &(((struct xrdp_rdp *)session->rdp)->client_info);\n    session->client_info->multimon = 1;\n    sec_layer = (struct xrdp_sec *) g_malloc(sizeof(struct xrdp_sec), 1);\n    sec_layer->rdp_layer = rdp_layer;\n}\n\nstatic void teardown(void)\n{\n    g_free(sec_layer);\n    g_free(session);\n    g_free(rdp_layer);\n}\n\nSTART_TEST(test_xrdp_sec_process_mcs_data_monitors__when_flags_is_not_zero__fail)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 8);\n\n    out_uint32_le(s, 1);\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    int error = xrdp_sec_process_mcs_data_monitors(sec_layer, s);\n    ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR);\n\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_xrdp_sec_process_mcs_data_monitors__when_monitor_count_is_greater_than_sixteen__fail)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 8);\n\n    out_uint32_le(s, 0);\n    out_uint32_le(s, 17);\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    int error = xrdp_sec_process_mcs_data_monitors(sec_layer, s);\n    ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR_TOO_MANY_MONITORS);\n\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_xrdp_sec_process_mcs_data_monitors__with_single_monitor_happy_path)\n{\n    struct xrdp_client_info *client_info = &(rdp_layer->client_info);\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 28);\n\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, 1); //monitorCount\n\n    // Pretend we have a 4k monitor\n    out_uint32_le(s, 0); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, 3840); //monitor right\n    out_uint32_le(s, 2160); //monitor bottom\n    out_uint32_le(s, 1); //is primary\n\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    //Verify function call passed.\n    int error = xrdp_sec_process_mcs_data_monitors(sec_layer, s);\n    ck_assert_int_eq(error, 0);\n\n    ck_assert_int_eq(client_info->display_sizes.monitorCount, 1);\n\n    // Verify normal monitor\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].left, 0);\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].top, 0);\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].right, 3840);\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].bottom, 2160);\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].is_primary, 1);\n\n    // Verify normalized monitor\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].left, 0);\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].top, 0);\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].right, 3840);\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].bottom, 2160);\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].is_primary, 1);\n\n    // Verify geometry (+1 greater than )\n    ck_assert_int_eq(client_info->display_sizes.session_width, 3841);\n    ck_assert_int_eq(client_info->display_sizes.session_height, 2161);\n\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_xrdp_sec_process_mcs_data_monitors__when_no_primary_monitor_is_specified_one_is_selected)\n{\n    struct xrdp_client_info *client_info = &(rdp_layer->client_info);\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 28);\n\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, 1); //monitorCount\n\n    // Pretend we have a 4k monitor\n    out_uint32_le(s, 0); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, 3840); //monitor right\n    out_uint32_le(s, 2160); //monitor bottom\n    out_uint32_le(s, 0); //is primary\n\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    //Verify function call passed.\n    int error = xrdp_sec_process_mcs_data_monitors(sec_layer, s);\n    ck_assert_int_eq(error, 0);\n\n    ck_assert_int_eq(client_info->display_sizes.monitorCount, 1);\n\n    // Verify normal monitor\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].left, 0);\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].top, 0);\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].right, 3840);\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].bottom, 2160);\n    ck_assert_int_eq(client_info->display_sizes.minfo[0].is_primary, 1);\n\n    // Verify normalized monitor\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].left, 0);\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].top, 0);\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].right, 3840);\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].bottom, 2160);\n    ck_assert_int_eq(client_info->display_sizes.minfo_wm[0].is_primary, 1);\n\n    // Verify geometry (+1 greater than )\n    ck_assert_int_eq(client_info->display_sizes.session_width, 3841);\n    ck_assert_int_eq(client_info->display_sizes.session_height, 2161);\n\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_width_is_too_large)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 28);\n\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, 1); //monitorCount\n\n    // Pretend we have a 4k monitor\n    out_uint32_le(s, 0); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, 33000); //monitor right\n    out_uint32_le(s, 2160); //monitor bottom\n    out_uint32_le(s, 1); //is primary\n\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    //Verify function call passed.\n    int error = xrdp_sec_process_mcs_data_monitors(sec_layer, s);\n    ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR_INVALID_DESKTOP);\n\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_width_is_too_small)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 28);\n\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, 1); //monitorCount\n\n    // Pretend we have a 4k monitor\n    out_uint32_le(s, 0); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, 100); //monitor right\n    out_uint32_le(s, 2160); //monitor bottom\n    out_uint32_le(s, 1); //is primary\n\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    //Verify function call passed.\n    int error = xrdp_sec_process_mcs_data_monitors(sec_layer, s);\n    ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR_INVALID_DESKTOP);\n\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_height_is_too_large)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 28);\n\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, 1); //monitorCount\n\n    // Pretend we have a 4k monitor\n    out_uint32_le(s, 0); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, 3840); //monitor right\n    out_uint32_le(s, 33000); //monitor bottom\n    out_uint32_le(s, 1); //is primary\n\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    //Verify function call passed.\n    int error = xrdp_sec_process_mcs_data_monitors(sec_layer, s);\n    ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR_INVALID_DESKTOP);\n\n    free_stream(s);\n}\nEND_TEST\n\nSTART_TEST(test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_height_is_too_small)\n{\n    struct stream *s = (struct stream *)NULL;\n    make_stream(s);\n    init_stream(s, 28);\n\n    out_uint32_le(s, 0); //flags\n    out_uint32_le(s, 1); //monitorCount\n\n    // Pretend we have a 4k monitor\n    out_uint32_le(s, 0); //monitor left\n    out_uint32_le(s, 0); //monitor top\n    out_uint32_le(s, 3840); //monitor right\n    out_uint32_le(s, 100); //monitor bottom\n    out_uint32_le(s, 1); //is primary\n\n    s_mark_end(s);\n    //Reset the read counter of the stream so the processing function handles it properly.\n    s->p = s->data;\n\n    //Verify function call passed.\n    int error = xrdp_sec_process_mcs_data_monitors(sec_layer, s);\n    ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR_INVALID_DESKTOP);\n\n    free_stream(s);\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_xrdp_sec_process_mcs_data_monitors(void)\n{\n    Suite *s;\n    TCase *tc_process_monitors;\n\n    s = suite_create(\"test_xrdp_sec_process_mcs_data_monitors\");\n\n    tc_process_monitors = tcase_create(\"xrdp_sec_process_mcs_data_monitors\");\n    tcase_add_checked_fixture(tc_process_monitors, setup, teardown);\n    tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_flags_is_not_zero__fail);\n    tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_monitor_count_is_greater_than_sixteen__fail);\n    tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__with_single_monitor_happy_path);\n    tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_no_primary_monitor_is_specified_one_is_selected);\n    tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_width_is_too_large);\n    tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_width_is_too_small);\n    tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_height_is_too_large);\n    tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_height_is_too_small);\n\n    suite_add_tcase(s, tc_process_monitors);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/memtest/Makefile.am",
    "content": "\nAM_CPPFLAGS = \\\n  -I$(top_srcdir)/common\n\nPACKAGE_STRING = \"memtest\"\n\ncheck_PROGRAMS = \\\n  memtest\n\nmemtest_SOURCES = \\\n  libmem.h \\\n  libmem.c \\\n  memtest.c\n\nmemtest_LDADD = \\\n  $(top_builddir)/common/libcommon.la\n\nTESTS = \\\n  memtest\n"
  },
  {
    "path": "tests/memtest/libmem.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"libmem.h\"\n#include \"log.h\"\n#include \"os_calls.h\"\n\n#define ALIGN_BY 32\n#define ALIGN_BY_M1 (ALIGN_BY - 1)\n#define ALIGN(_in) (((_in) + ALIGN_BY_M1) & (~ALIGN_BY_M1))\n\n\nstruct mem_item\n{\n    unsigned int addr;\n    int bytes;\n    struct mem_item *next;\n    struct mem_item *prev;\n};\n\nstruct mem_info\n{\n    unsigned int addr;\n    int bytes;\n    int flags;\n    struct mem_item *free_head;\n    struct mem_item *free_tail;\n    struct mem_item *used_head;\n    struct mem_item *used_tail;\n    int total_bytes;\n};\n\n/*****************************************************************************/\nstatic int\nlibmem_free_mem_item(struct mem_info *self, struct mem_item *mi)\n{\n    if (self == 0 || mi == 0)\n    {\n        return 0;\n    }\n    if (mi->prev != 0)\n    {\n        mi->prev->next = mi->next;\n    }\n    if (mi->next != 0)\n    {\n        mi->next->prev = mi->prev;\n    }\n    if (mi == self->free_head)\n    {\n        self->free_head = mi->next;\n    }\n    if (mi == self->free_tail)\n    {\n        self->free_tail = mi->prev;\n    }\n    if (mi == self->used_head)\n    {\n        self->used_head = mi->next;\n    }\n    if (mi == self->used_tail)\n    {\n        self->used_tail = mi->prev;\n    }\n    free(mi);\n    return 0;\n}\n\n/*****************************************************************************/\nvoid *\nlibmem_init(unsigned int addr, int bytes)\n{\n    struct mem_info *self;\n    struct mem_item *mi;\n\n    self = (struct mem_info *)g_malloc_nofail(sizeof(struct mem_info));\n    memset(self, 0, sizeof(struct mem_info));\n    self->addr = addr;\n    self->bytes = bytes;\n    //self->flags = 1;\n    mi = (struct mem_item *)g_malloc_nofail(sizeof(struct mem_item));\n    memset(mi, 0, sizeof(struct mem_item));\n    mi->addr = addr;\n    mi->bytes = bytes;\n    self->free_head = mi;\n    self->free_tail = mi;\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nlibmem_deinit(void *aself)\n{\n    struct mem_info *self;\n\n    self = (struct mem_info *)aself;\n    if (self == 0)\n    {\n        return;\n    }\n    while (self->free_head != 0)\n    {\n        libmem_free_mem_item(self, self->free_head);\n    }\n    while (self->used_head != 0)\n    {\n        libmem_free_mem_item(self, self->used_head);\n    }\n    free(self);\n}\n\n/****************************************************************************/\nstatic int\nlibmem_add_used_item(struct mem_info *self, unsigned int addr, int bytes)\n{\n    struct mem_item *mi;\n    struct mem_item *new_mi;\n    int added;\n\n    if (self == 0 || addr == 0)\n    {\n        return 1;\n    }\n    if (self->used_head == 0)\n    {\n        /* add first item */\n        new_mi = (struct mem_item *)g_malloc_nofail(sizeof(struct mem_item));\n        memset(new_mi, 0, sizeof(struct mem_item));\n        new_mi->addr = addr;\n        new_mi->bytes = bytes;\n        self->used_head = new_mi;\n        self->used_tail = new_mi;\n        return 0;\n    }\n    added = 0;\n    mi = self->used_head;\n    while (mi != 0)\n    {\n        if (mi->addr > addr)\n        {\n            /* add before */\n            new_mi = (struct mem_item *)g_malloc_nofail(sizeof(struct mem_item));\n            memset(new_mi, 0, sizeof(struct mem_item));\n            new_mi->addr = addr;\n            new_mi->bytes = bytes;\n            new_mi->prev = mi->prev;\n            new_mi->next = mi;\n            if (mi->prev != 0)\n            {\n                mi->prev->next = new_mi;\n            }\n            mi->prev = new_mi;\n            if (self->used_head == mi)\n            {\n                self->used_head = new_mi;\n            }\n            added = 1;\n            break;\n        }\n        mi = mi->next;\n    }\n    if (!added)\n    {\n        /* add last */\n        new_mi = (struct mem_item *)g_malloc_nofail(sizeof(struct mem_item));\n        memset(new_mi, 0, sizeof(struct mem_item));\n        new_mi->addr = addr;\n        new_mi->bytes = bytes;\n        self->used_tail->next = new_mi;\n        new_mi->prev = self->used_tail;\n        self->used_tail = new_mi;\n    }\n    return 0;\n}\n\n/****************************************************************************/\nstatic int\nlibmem_add_free_item(struct mem_info *self, unsigned int addr, int bytes)\n{\n    struct mem_item *mi;\n    struct mem_item *new_mi;\n    int added;\n\n    if (self == 0 || addr == 0)\n    {\n        return 1;\n    }\n    if (self->free_head == 0)\n    {\n        /* add first item */\n        new_mi = (struct mem_item *)g_malloc_nofail(sizeof(struct mem_item));\n        memset(new_mi, 0, sizeof(struct mem_item));\n        new_mi->addr = addr;\n        new_mi->bytes = bytes;\n        self->free_head = new_mi;\n        self->free_tail = new_mi;\n        return 0;\n    }\n    added = 0;\n    mi = self->free_head;\n    while (mi != 0)\n    {\n        if (mi->addr > addr)\n        {\n            if (mi->prev != 0)\n            {\n                if (mi->prev->addr + mi->prev->bytes == addr)\n                {\n                    /* don't need to add, just make prev bigger */\n                    mi->prev->bytes += bytes;\n                    if (mi->prev->addr + mi->prev->bytes == mi->addr)\n                    {\n                        /* here we can remove one */\n                        mi->prev->bytes += mi->bytes;\n                        libmem_free_mem_item(self, mi);\n                    }\n                    return 0;\n                }\n            }\n            if (addr + bytes == mi->addr)\n            {\n                /* don't need to add here either */\n                mi->addr = addr;\n                mi->bytes += bytes;\n                return 0;\n            }\n            /* add before */\n            new_mi = (struct mem_item *)g_malloc_nofail(sizeof(struct mem_item));\n            memset(new_mi, 0, sizeof(struct mem_item));\n            new_mi->addr = addr;\n            new_mi->bytes = bytes;\n            new_mi->prev = mi->prev;\n            new_mi->next = mi;\n            if (mi->prev != 0)\n            {\n                mi->prev->next = new_mi;\n            }\n            mi->prev = new_mi;\n            if (self->free_head == mi)\n            {\n                self->free_head = new_mi;\n            }\n            added = 1;\n            break;\n        }\n        mi = mi->next;\n    }\n    if (!added)\n    {\n        /* add last */\n        new_mi = (struct mem_item *)g_malloc_nofail(sizeof(struct mem_item));\n        memset(new_mi, 0, sizeof(struct mem_item));\n        new_mi->addr = addr;\n        new_mi->bytes = bytes;\n        self->free_tail->next = new_mi;\n        new_mi->prev = self->free_tail;\n        self->free_tail = new_mi;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nlibmem_print(struct mem_info *self)\n{\n    struct mem_item *mi;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"libmem_print:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  used_head %p\", self->used_head);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  used_tail %p\", self->used_tail);\n    mi = self->used_head;\n    if (mi != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  used list\");\n        while (mi != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"    ptr %p prev %p next %p addr 0x%8.8x bytes %d\",\n                      mi, mi->prev, mi->next, mi->addr, mi->bytes);\n            mi = mi->next;\n        }\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  free_head %p\", self->free_head);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  free_tail %p\", self->free_tail);\n    mi = self->free_head;\n    if (mi != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  free list\");\n        while (mi != 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"    ptr %p prev %p next %p addr 0x%8.8x bytes %d\",\n                      mi, mi->prev, mi->next, mi->addr, mi->bytes);\n            mi = mi->next;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nunsigned int\nlibmem_alloc(void *obj, int bytes)\n{\n    struct mem_info *self;\n    struct mem_item *mi;\n    unsigned int addr;\n\n    if (bytes < 1)\n    {\n        return 0;\n    }\n    bytes = ALIGN(bytes);\n    self = (struct mem_info *)obj;\n    addr = 0;\n    mi = self->free_head;\n    while (mi != 0)\n    {\n        if (bytes <= mi->bytes)\n        {\n            addr = mi->addr;\n            mi->bytes -= bytes;\n            mi->addr += bytes;\n            if (mi->bytes < 1)\n            {\n                libmem_free_mem_item(self, mi);\n            }\n            break;\n        }\n        mi = mi->next;\n    }\n    if (addr != 0)\n    {\n        self->total_bytes += bytes;\n        libmem_add_used_item(self, addr, bytes);\n        if (self->flags & 1)\n        {\n            libmem_print(self);\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"libmem_alloc: error\");\n    }\n    return addr;\n}\n\n/*****************************************************************************/\nint\nlibmem_free(void *obj, unsigned int addr)\n{\n    struct mem_info *self;\n    struct mem_item *mi;\n\n    if (addr == 0)\n    {\n        return 0;\n    }\n    self = (struct mem_info *)obj;\n    mi = self->used_tail;\n    while (mi != 0)\n    {\n        if (mi->addr == addr)\n        {\n            self->total_bytes -= mi->bytes;\n            libmem_add_free_item(self, mi->addr, mi->bytes);\n            libmem_free_mem_item(self, mi);\n            if (self->flags & 1)\n            {\n                libmem_print(self);\n            }\n            return 0;\n        }\n        mi = mi->prev;\n    }\n    LOG_DEVEL(LOG_LEVEL_ERROR, \"libmem_free: error\");\n    return 1;\n}\n\n/*****************************************************************************/\nint\nlibmem_set_flags(void *obj, int flags)\n{\n    struct mem_info *self;\n\n    self = (struct mem_info *)obj;\n    self->flags |= flags;\n    return 0;\n}\n\n/*****************************************************************************/\nint\nlibmem_clear_flags(void *obj, int flags)\n{\n    struct mem_info *self;\n\n    self = (struct mem_info *)obj;\n    self->flags &= ~flags;\n    return 0;\n}\n\n/*****************************************************************************/\nint\nlibmem_get_alloced_bytes(void *obj)\n{\n    struct mem_info *self;\n\n    self = (struct mem_info *)obj;\n    return self->total_bytes;\n}\n"
  },
  {
    "path": "tests/memtest/libmem.h",
    "content": "\n#ifndef _LIBMEM_C\n#define _LIBMEM_C\n\nvoid *\nlibmem_init(unsigned int addr, int bytes);\nvoid\nlibmem_deinit(void *aself);\nunsigned int\nlibmem_alloc(void *obj, int bytes);\nint\nlibmem_free(void *obj, unsigned int addr);\nint\nlibmem_set_flags(void *obj, int flags);\nint\nlibmem_clear_flags(void *obj, int flags);\nint\nlibmem_get_alloced_bytes(void *obj);\n\n#endif\n"
  },
  {
    "path": "tests/memtest/memtest.c",
    "content": "\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n\n#include \"libmem.h\"\n#include \"log.h\"\n\nint main(int argc, char **argv)\n{\n    void *obj;\n    unsigned int addr1;\n    unsigned int addr2;\n    unsigned int addr3;\n    unsigned int addr4;\n    unsigned int addr5;\n    int index;\n    int rd;\n    struct log_config *config;\n\n    config = log_config_init_for_console(LOG_LEVEL_DEBUG, NULL);\n    log_start_from_param(config);\n    log_config_free(config);\n    /* Disable stdout buffering, as this can confuse the error\n     * reporting when running in libcheck fork mode */\n    setvbuf(stdout, NULL, _IONBF, 0);\n\n    srand(time(0));\n    obj = libmem_init(0x80000000, 64 * 1024 * 1024);\n    for (index = 0; index < 256; index++)\n    {\n        rd = rand() & 0xffff;\n        printf(\"1 rd %d\\n\", rd);\n        addr1 = libmem_alloc(obj, rd);\n        rd = rand() & 0xffff;\n        printf(\"2 rd %d\\n\", rd);\n        addr2 = libmem_alloc(obj, rd);\n        rd = rand() & 0xffff;\n        printf(\"3 rd %d\\n\", rd);\n        addr3 = libmem_alloc(obj, rd);\n        rd = rand() & 0xffff;\n        printf(\"4 rd %d\\n\", rd);\n        addr4 = libmem_alloc(obj, rd);\n        addr5 = libmem_alloc(obj, rd);\n        libmem_free(obj, addr1);\n        printf(\"5\\n\");\n        addr1 = libmem_alloc(obj, 64);\n        printf(\"6\\n\");\n        libmem_free(obj, addr3);\n        printf(\"7\\n\");\n        addr3 = libmem_alloc(obj, 64 * 1024);\n        libmem_free(obj, addr5);\n        addr5 = libmem_alloc(obj, 64 * 1024);\n        printf(\"8\\n\");\n        libmem_free(obj, addr1);\n        printf(\"9\\n\");\n        libmem_free(obj, addr2);\n        printf(\"10\\n\");\n        libmem_free(obj, addr3);\n        libmem_free(obj, addr4);\n        if (index == 255)\n        {\n            libmem_set_flags(obj, 1);\n        }\n        libmem_free(obj, addr5);\n    }\n    libmem_deinit(obj);\n    log_end();\n    return 0;\n}\n"
  },
  {
    "path": "tests/readme.txt",
    "content": "\nthis directory contains different tests\n\n"
  },
  {
    "path": "tests/xrdp/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n  -DXRDP_TOP_SRCDIR=\\\"$(top_srcdir)\\\" \\\n  -I$(top_builddir) \\\n  -I$(top_srcdir)/xrdp \\\n  -I$(top_srcdir)/libxrdp \\\n  -I$(top_srcdir)/common \\\n  -I$(top_srcdir)/third_party/tomlc99 \\\n  $(IMLIB2_CFLAGS)\n\nLOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \\\n                  $(top_srcdir)/tap-driver.sh\n\nPACKAGE_STRING=\"XRDP daemon\"\n\nEXTRA_DIST = \\\n  test_4bit.bmp \\\n  test_8bit.bmp \\\n  test_24bit.bmp \\\n  test_not4_4bit.bmp \\\n  test_not4_8bit.bmp \\\n  test_not4_24bit.bmp \\\n  test1.jpg \\\n  test_alpha_blend.png \\\n  gfx/gfx.toml \\\n  gfx/gfx_codec_h264_only.toml \\\n  gfx/gfx_codec_h264_preferred.toml \\\n  gfx/gfx_codec_order_undefined.toml \\\n  gfx/gfx_codec_rfx_only.toml \\\n  gfx/gfx_codec_rfx_preferred_odd.toml \\\n  gfx/gfx_codec_rfx_preferred.toml \\\n  gfx/gfx_h264_encoder_invalid.toml \\\n  gfx/gfx_h264_encoder_openh264.toml \\\n  gfx/gfx_h264_encoder_undefined.toml \\\n  gfx/gfx_h264_encoder_x264.toml \\\n  gfx/gfx_missing_h264.toml\n\nTESTS = test_xrdp\ncheck_PROGRAMS = test_xrdp\n\ntest_xrdp_SOURCES = \\\n    test_xrdp.h \\\n    test_xrdp_main.c \\\n    test_xrdp_egfx.c \\\n    test_xrdp_keymap.c \\\n    test_xrdp_region.c \\\n    test_tconfig.c \\\n    test_bitmap_load.c\n\ntest_xrdp_CFLAGS = \\\n    -D IMAGEDIR=\\\"$(srcdir)\\\" \\\n    @CHECK_CFLAGS@ \\\n    @CMOCKA_CFLAGS@\n\ntest_xrdp_LDFLAGS = -Wl,--wrap=pixman_region_extents, \\\n    -Wl,--wrap=pixman_region_not_empty\n\ntest_xrdp_LDADD = \\\n    $(top_builddir)/xrdp/xrdp_bitmap_load.o \\\n    $(top_builddir)/xrdp/xrdp_bitmap_common.o \\\n    $(top_builddir)/xrdp/funcs.o \\\n    $(top_builddir)/libxrdp/libxrdp.la \\\n    $(top_builddir)/xrdp/lang.o \\\n    $(top_builddir)/xrdp/xrdp_mm.o \\\n    $(top_builddir)/xrdp/xrdp_mm_ccp.o \\\n    $(top_builddir)/xrdp/xrdp_wm.o \\\n    $(top_builddir)/xrdp/xrdp_font.o \\\n    $(top_builddir)/xrdp/xrdp_egfx.o \\\n    $(top_builddir)/xrdp/xrdp_cache.o \\\n    $(top_builddir)/xrdp/xrdp_region.o \\\n    $(top_builddir)/xrdp/xrdp_listen.o \\\n    $(top_builddir)/xrdp/xrdp_bitmap.o \\\n    $(top_builddir)/xrdp/xrdp_painter.o \\\n    $(top_builddir)/xrdp/xrdp_encoder.o \\\n    $(top_builddir)/xrdp/xrdp_process.o \\\n    $(top_builddir)/xrdp/xrdp_login_wnd.o \\\n    $(top_builddir)/xrdp/xrdp_tconfig.o \\\n    $(top_builddir)/xrdp/xrdp_main_utils.o \\\n    $(top_builddir)/libpainter/src/libpainter.la \\\n    $(top_builddir)/librfxcodec/src/librfxencode.la \\\n    $(top_builddir)/libipm/libipm.la \\\n    $(top_builddir)/common/libcommon.la \\\n    $(top_builddir)/third_party/tomlc99/libtoml.la \\\n    $(PIXMAN_LIBS) \\\n    $(IMLIB2_LIBS) \\\n    @CHECK_LIBS@ \\\n    @CMOCKA_LIBS@\n\nif XRDP_X264\nAM_CPPFLAGS += -DXRDP_X264 $(XRDP_X264_CFLAGS)\ntest_xrdp_LDADD += \\\n    $(top_builddir)/xrdp/xrdp_encoder_x264.o \\\n    $(XRDP_X264_LIBS)\nendif\n\nif XRDP_OPENH264\nAM_CPPFLAGS += -DXRDP_X264 $(XRDP_OPENH264_CFLAGS)\ntest_xrdp_LDADD += \\\n    $(top_builddir)/xrdp/xrdp_encoder_openh264.o \\\n    $(XRDP_OPENH264_LIBS)\nendif\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx.toml",
    "content": "[codec]\norder = [ \"H.264\", \"RFX\" ]\n\n# Specify a preferred H.264 encoder, \"x264\" or \"OpenH264\".\n# This parameter takes effect only when more than one encoder is\n# enabled at compile time. If only one encoder is enabled, the encoder\n# will be used regardless the value of this parameter.\nh264_encoder = \"OpenH264\"\n\n#\n# Configurations for x264\n#\n[x264.default]\n# NOTE: x264 specifies bitrate in unit of kbps.\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 60\nfps_den = 1\n\n[x264.lan]\n# inherits default\n\n[x264.wan]\nvbv_max_bitrate = 15_000\nvbv_buffer_size = 1_500\n\n[x264.broadband_high]\npreset = \"superfast\"\nvbv_max_bitrate = 8_000\nvbv_buffer_Size = 800\n\n[x264.satellite]\npreset = \"superfast\"\nvbv_max_bitrate = 5_000\nvbv_buffer_size = 500\n\n[x264.broadband_low]\npreset = \"veryfast\"\nvbv_max_bitrate = 1_600\nvbv_buffer_size = 66\n\n[x264.modem]\npreset = \"fast\"\nvbv_max_bitrate = 1_200\nvbv_buffer_size = 50\n\n#\n# Configurations for OpenH264\n#\n[OpenH264.default]\n# NOTE: OpenH264 specifies bitrate in unit of bps, not kbps.\nEnableFrameSkip = false\nTargetBitrate = 20_000_000\nMaxBitrate =    0          # unspecified\nMaxFrameRate = 60.0\n\n[OpenH264.lan]\n# inherits default\n\n[OpenH264.wan]\nTargetBitrate = 10_000_000\nMaxBitrate =    12_000_000\n\n[OpenH264.broadband_high]\nEnableFrameSkip = true\nTargetBitrate = 8_000_000\nMaxBitrate =   10_000_000\n\n[OpenH264.satellite]\nEnableFrameSkip = true\nTargetBitrate = 4_000_000\nMaxBitrate =    6_000_000\n\n[OpenH264.broadband_low]\nEnableFrameSkip = true\nTargetBitrate = 1_600_000\nMaxBitrate =    1_800_000\n\n[OpenH264.modem]\nEnableFrameSkip = true\nTargetBitrate =   600_000\nMaxBitrate =    1_200_000\n\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_codec_h264_only.toml",
    "content": "[codec]\norder = [ \"H.264\" ]\n\n[x264.default]\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 24\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n[x264.wan]\n[x264.broadband_high]\n[x264.satellite]\n[x264.broadband_low]\n[x264.modem]\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_codec_h264_preferred.toml",
    "content": "[codec]\norder = [ \"H.264\", \"RFX\" ]\n\n[x264.default]\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 24\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n[x264.wan]\n[x264.broadband_high]\n[x264.satellite]\n[x264.broadband_low]\n[x264.modem]\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_codec_order_undefined.toml",
    "content": "[codec]\norder = [ ]\n\n[x264.default]\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 24\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n[x264.wan]\n[x264.broadband_high]\n[x264.satellite]\n[x264.broadband_low]\n[x264.modem]\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_codec_rfx_only.toml",
    "content": "[codec]\norder = [ \"RFX\" ]\n\n[x264.default]\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 24\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n[x264.wan]\n[x264.broadband_high]\n[x264.satellite]\n[x264.broadband_low]\n[x264.modem]\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_codec_rfx_preferred.toml",
    "content": "[codec]\norder = [ \"RFX\", \"H.264\" ]\n\n[x264.default]\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 24\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n[x264.wan]\n[x264.broadband_high]\n[x264.satellite]\n[x264.broadband_low]\n[x264.modem]\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_codec_rfx_preferred_odd.toml",
    "content": "[codec]\norder = [ \"RFX\", \"H.264\", \"RFX\" ]\n\n[x264.default]\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 24\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n[x264.wan]\n[x264.broadband_high]\n[x264.satellite]\n[x264.broadband_low]\n[x264.modem]\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_h264_encoder_invalid.toml",
    "content": "[codec]\norder = [ \"H.264\", \"RFX\" ]\n\n# Specify a preferred H.264 encoder, \"x264\" or \"OpenH264\".\n# This parameter takes effect only when more than one encoder is\n# enabled at compile time. If only one encoder is enabled, the encoder\n# will be used regardless the value of this parameter.\nh264_encoder = \"FreeH264\"\n\n#\n# Configurations for x264\n#\n[x264.default]\n# NOTE: x264 specifies bitrate in unit of kbps.\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 60\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n# inherits default\n\n[x264.wan]\nvbv_max_bitrate = 15_000\nvbv_buffer_size = 1_500\n\n[x264.broadband_high]\npreset = \"superfast\"\nvbv_max_bitrate = 8_000\nvbv_buffer_Size = 800\n\n[x264.satellite]\npreset = \"superfast\"\nvbv_max_bitrate = 5_000\nvbv_buffer_size = 500\n\n[x264.broadband_low]\npreset = \"veryfast\"\nvbv_max_bitrate = 1_600\nvbv_buffer_size = 66\n\n[x264.modem]\npreset = \"fast\"\nvbv_max_bitrate = 1_200\nvbv_buffer_size = 50\n\n#\n# Configurations for OpenH264\n#\n[OpenH264.default]\n# NOTE: OpenH264 specifies bitrate in unit of bps, not kbps.\nEnableFrameSkip = false\nTargetBitrate = 20_000_000\nMaxBitrate =    0          # unspecified\nMaxFrameRate = 60.0\n\n[OpenH264.lan]\n# inherits default\n\n[OpenH264.wan]\nTargetBitrate = 10_000_000\nMaxBitrate =    12_000_000\n\n[OpenH264.broadband_high]\nEnableFrameSkip = true\nTargetBitrate = 8_000_000\nMaxBitrate =   10_000_000\n\n[OpenH264.satellite]\nEnableFrameSkip = true\nTargetBitrate = 4_000_000\nMaxBitrate =    6_000_000\n\n[OpenH264.broadband_low]\nEnableFrameSkip = true\nTargetBitrate = 1_600_000\nMaxBitrate =    1_800_000\n\n[OpenH264.modem]\nEnableFrameSkip = true\nTargetBitrate =   600_000\nMaxBitrate =    1_200_000\n\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_h264_encoder_openh264.toml",
    "content": "[codec]\norder = [ \"H.264\", \"RFX\" ]\n\n# Specify a preferred H.264 encoder, \"x264\" or \"OpenH264\".\n# This parameter takes effect only when more than one encoder is\n# enabled at compile time. If only one encoder is enabled, the encoder\n# will be used regardless the value of this parameter.\nh264_encoder = \"OpenH264\"\n\n#\n# Configurations for x264\n#\n[x264.default]\n# NOTE: x264 specifies bitrate in unit of kbps.\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 60\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n# inherits default\n\n[x264.wan]\nvbv_max_bitrate = 15_000\nvbv_buffer_size = 1_500\n\n[x264.broadband_high]\npreset = \"superfast\"\nvbv_max_bitrate = 8_000\nvbv_buffer_Size = 800\n\n[x264.satellite]\npreset = \"superfast\"\nvbv_max_bitrate = 5_000\nvbv_buffer_size = 500\n\n[x264.broadband_low]\npreset = \"veryfast\"\nvbv_max_bitrate = 1_600\nvbv_buffer_size = 66\n\n[x264.modem]\npreset = \"fast\"\nvbv_max_bitrate = 1_200\nvbv_buffer_size = 50\n\n#\n# Configurations for OpenH264\n#\n[OpenH264.default]\n# NOTE: OpenH264 specifies bitrate in unit of bps, not kbps.\nEnableFrameSkip = false\nTargetBitrate = 20_000_000\nMaxBitrate =    0          # unspecified\nMaxFrameRate = 60.0\n\n[OpenH264.lan]\n# inherits default\n\n[OpenH264.wan]\nTargetBitrate = 10_000_000\nMaxBitrate =    12_000_000\n\n[OpenH264.broadband_high]\nEnableFrameSkip = true\nTargetBitrate = 8_000_000\nMaxBitrate =   10_000_000\n\n[OpenH264.satellite]\nEnableFrameSkip = true\nTargetBitrate = 4_000_000\nMaxBitrate =    6_000_000\n\n[OpenH264.broadband_low]\nEnableFrameSkip = true\nTargetBitrate = 1_600_000\nMaxBitrate =    1_800_000\n\n[OpenH264.modem]\nEnableFrameSkip = true\nTargetBitrate =   600_000\nMaxBitrate =    1_200_000\n\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_h264_encoder_undefined.toml",
    "content": "[codec]\norder = [ \"H.264\", \"RFX\" ]\n\n# Specify a preferred H.264 encoder, \"x264\" or \"OpenH264\".\n# This parameter takes effect only when more than one encoder is\n# enabled at compile time. If only one encoder is enabled, the encoder\n# will be used regardless the value of this parameter.\n#h264_encoder = \"OpenH264\"\n\n#\n# Configurations for x264\n#\n[x264.default]\n# NOTE: x264 specifies bitrate in unit of kbps.\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 60\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n# inherits default\n\n[x264.wan]\nvbv_max_bitrate = 15_000\nvbv_buffer_size = 1_500\n\n[x264.broadband_high]\npreset = \"superfast\"\nvbv_max_bitrate = 8_000\nvbv_buffer_Size = 800\n\n[x264.satellite]\npreset = \"superfast\"\nvbv_max_bitrate = 5_000\nvbv_buffer_size = 500\n\n[x264.broadband_low]\npreset = \"veryfast\"\nvbv_max_bitrate = 1_600\nvbv_buffer_size = 66\n\n[x264.modem]\npreset = \"fast\"\nvbv_max_bitrate = 1_200\nvbv_buffer_size = 50\n\n#\n# Configurations for OpenH264\n#\n[OpenH264.default]\n# NOTE: OpenH264 specifies bitrate in unit of bps, not kbps.\nEnableFrameSkip = false\nTargetBitrate = 20_000_000\nMaxBitrate =    0          # unspecified\nMaxFrameRate = 60.0\n\n[OpenH264.lan]\n# inherits default\n\n[OpenH264.wan]\nTargetBitrate = 10_000_000\nMaxBitrate =    12_000_000\n\n[OpenH264.broadband_high]\nEnableFrameSkip = true\nTargetBitrate = 8_000_000\nMaxBitrate =   10_000_000\n\n[OpenH264.satellite]\nEnableFrameSkip = true\nTargetBitrate = 4_000_000\nMaxBitrate =    6_000_000\n\n[OpenH264.broadband_low]\nEnableFrameSkip = true\nTargetBitrate = 1_600_000\nMaxBitrate =    1_800_000\n\n[OpenH264.modem]\nEnableFrameSkip = true\nTargetBitrate =   600_000\nMaxBitrate =    1_200_000\n\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_h264_encoder_x264.toml",
    "content": "[codec]\norder = [ \"H.264\", \"RFX\" ]\n\n# Specify a preferred H.264 encoder, \"x264\" or \"OpenH264\".\n# This parameter takes effect only when more than one encoder is\n# enabled at compile time. If only one encoder is enabled, the encoder\n# will be used regardless the value of this parameter.\nh264_encoder = \"x264\"\n\n#\n# Configurations for x264\n#\n[x264.default]\n# NOTE: x264 specifies bitrate in unit of kbps.\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 60\nfps_den = 1\nthreads = 1\n\n[x264.lan]\n# inherits default\n\n[x264.wan]\nvbv_max_bitrate = 15_000\nvbv_buffer_size = 1_500\n\n[x264.broadband_high]\npreset = \"superfast\"\nvbv_max_bitrate = 8_000\nvbv_buffer_Size = 800\n\n[x264.satellite]\npreset = \"superfast\"\nvbv_max_bitrate = 5_000\nvbv_buffer_size = 500\n\n[x264.broadband_low]\npreset = \"veryfast\"\nvbv_max_bitrate = 1_600\nvbv_buffer_size = 66\n\n[x264.modem]\npreset = \"fast\"\nvbv_max_bitrate = 1_200\nvbv_buffer_size = 50\n\n#\n# Configurations for OpenH264\n#\n[OpenH264.default]\n# NOTE: OpenH264 specifies bitrate in unit of bps, not kbps.\nEnableFrameSkip = false\nTargetBitrate = 20_000_000\nMaxBitrate =    0          # unspecified\nMaxFrameRate = 60.0\n\n[OpenH264.lan]\n# inherits default\n\n[OpenH264.wan]\nTargetBitrate = 10_000_000\nMaxBitrate =    12_000_000\n\n[OpenH264.broadband_high]\nEnableFrameSkip = true\nTargetBitrate = 8_000_000\nMaxBitrate =   10_000_000\n\n[OpenH264.satellite]\nEnableFrameSkip = true\nTargetBitrate = 4_000_000\nMaxBitrate =    6_000_000\n\n[OpenH264.broadband_low]\nEnableFrameSkip = true\nTargetBitrate = 1_600_000\nMaxBitrate =    1_800_000\n\n[OpenH264.modem]\nEnableFrameSkip = true\nTargetBitrate =   600_000\nMaxBitrate =    1_200_000\n\n"
  },
  {
    "path": "tests/xrdp/gfx/gfx_missing_h264.toml",
    "content": "[codec]\norder = [ \"H.264\", \"RFX\" ]\n\n[x264.lan]\n[x264.wan]\n[x264.broadband_high]\n[x264.satellite]\n[x264.broadband_low]\n[x264.modem]\n"
  },
  {
    "path": "tests/xrdp/test_bitmap_load.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"xrdp.h\"\n\n#include \"test_xrdp.h\"\n\n/* Where the image files are located */\n#ifndef IMAGEDIR\n#define IMAGEDIR \".\"\n#endif\n\n/* Handy color definitions. These are variables so they are displayed\n * in assert messages if tests fail */\nstatic int RED = COLOR24RGB(255, 0, 0);\nstatic int GREEN = COLOR24RGB(0, 255, 0);\nstatic int BLUE = COLOR24RGB(0, 0, 255);\nstatic int WHITE = COLOR24RGB(255, 255, 255);\n\n/* Virtual desktop maxima and minima [MS-RDPBCGR] 2.2.1.3.6 */\n#define MAX_VDESKTOP_WIDTH 32766\n#define MAX_VDESKTOP_HEIGHT 32766\n#define MIN_VDESKTOP_WIDTH 200\n#define MIN_VDESKTOP_HEIGHT 200\n\n/* Characteristics of the test bitmap(s) */\n#define TEST_BM_WIDTH 256\n#define TEST_BM_HEIGHT 256\n\n#define TEST_NOT4_BM_WIDTH 62\n#define TEST_NOT4_BM_HEIGHT 62\n\n#define TEST_BM_TOP_LEFT_PIXEL RED\n#define TEST_BM_TOP_RIGHT_PIXEL GREEN\n#define TEST_BM_BOTTOM_LEFT_PIXEL BLUE\n#define TEST_BM_BOTTOM_RIGHT_PIXEL WHITE\n\n/*\n * Scaling bitmaps properly will introduce color changes with dithering.\n * Also some filetypes use compression, and these do not represent colors\n * perfectly.\n *\n * This is the Pythagorean distance we allow between two colors for them to\n * be considered close enough to each other */\n#define MAX_SIMILAR_COLOR_DISTANCE 3\n\n/* Time to allow some large bitmap test suites to run on slower platforms */\n#define LARGE_BM_TEST_SUITE_TIMEOUT 10\n\nstatic void setup(void)\n{\n}\n\nstatic void teardown(void)\n{\n}\n\n/* Tests an error is returned for a non-existent file */\nSTART_TEST(test_bitmap_load__with_invalid_image__fail)\n{\n    struct xrdp_wm *wm = NULL;\n    int result;\n\n    struct xrdp_bitmap *bm = xrdp_bitmap_create(4, 4, 32, WND_TYPE_IMAGE, wm);\n\n    ck_assert_ptr_ne(bm, NULL);\n\n    result = xrdp_bitmap_load(bm, \"/dev/null\", NULL, 0, XBLT_NONE, 0, 0);\n\n    ck_assert_int_ne(result, 0);\n\n    xrdp_bitmap_delete(bm);\n}\nEND_TEST\n\n/* Checks a particular pixmap value is expected */\nstatic void\ncheck_pixel(struct xrdp_bitmap *bm, int i, int j, int expected)\n{\n    int pixel = xrdp_bitmap_get_pixel(bm, i, j);\n    if (pixel != expected)\n    {\n        ck_abort_msg(\"Pixmap (%d,%d) expected 0x%06x, got 0x%06x\",\n                     i, j, expected, pixel);\n    }\n}\n\n/* Calculates whether two colors are close enough to be considered the same */\nstatic void\ncheck_is_close_color(struct xrdp_bitmap *bm, int i, int j, int expected)\n{\n    int pixel = xrdp_bitmap_get_pixel(bm, i, j);\n    int r1;\n    int g1;\n    int b1;\n    int r2;\n    int g2;\n    int b2;\n    int variance;\n\n    SPLITCOLOR32(r1, g1, b1, pixel);\n    SPLITCOLOR32(r2, g2, b2, expected);\n\n    variance = ((r1 - r2) * (r1 - r2) +\n                (g1 - g2) * (g1 - g2) +\n                (b1 - b2) * (b1 - b2));\n\n    if (variance > MAX_SIMILAR_COLOR_DISTANCE * MAX_SIMILAR_COLOR_DISTANCE)\n    {\n        ck_abort_msg(\"Pixmap (%d,%d) expected 0x%06x, got 0x%06x\"\n                     \" which exceeds distance of %d\",\n                     i, j, expected, pixel, MAX_SIMILAR_COLOR_DISTANCE);\n    }\n}\n\n/* Check we can load images of various depths with various transforms */\nstatic void\nload_and_transform_img(const char *name,\n                       enum xrdp_bitmap_load_transform transform,\n                       int twidth, int theight)\n{\n    struct xrdp_wm *wm = NULL;\n    int result;\n\n    int width;\n    int height;\n\n    char full_name[256];\n\n    struct xrdp_bitmap *bm = xrdp_bitmap_create(4, 4, 32, WND_TYPE_IMAGE, wm);\n\n    ck_assert_ptr_ne(bm, NULL);\n\n    g_snprintf(full_name, sizeof(full_name), IMAGEDIR \"/%s\", name);\n    result = xrdp_bitmap_load(bm, full_name, NULL, HCOLOR(bm->bpp, WHITE),\n                              transform, twidth, theight);\n\n    ck_assert_int_eq(result, 0);\n\n    /* Bitmap right size? */\n    if (transform == XBLT_NONE)\n    {\n        width = TEST_BM_WIDTH;\n        height = TEST_BM_HEIGHT;\n        ck_assert_int_eq(bm->width, TEST_BM_WIDTH);\n        ck_assert_int_eq(bm->height, TEST_BM_HEIGHT);\n    }\n    else\n    {\n        width = twidth;\n        height = theight;\n        ck_assert_int_eq(bm->width, twidth);\n        ck_assert_int_eq(bm->height, theight);\n    }\n\n    /* Corners OK?  Allow for dithering */\n    check_is_close_color(bm, 0, 0, TEST_BM_TOP_LEFT_PIXEL);\n    check_is_close_color(bm, width - 1, 0, TEST_BM_TOP_RIGHT_PIXEL);\n    check_is_close_color(bm, 0, height - 1, TEST_BM_BOTTOM_LEFT_PIXEL);\n    check_is_close_color(bm, width - 1, height - 1, TEST_BM_BOTTOM_RIGHT_PIXEL);\n\n    xrdp_bitmap_delete(bm);\n}\n\n/* Check we can load bitmaps that aren't a multiple of 4 pixels wide */\nstatic void\nload_not4_img(const char *name)\n{\n    struct xrdp_wm *wm = NULL;\n    int result;\n\n    const int width = TEST_NOT4_BM_WIDTH;\n    const int height = TEST_NOT4_BM_HEIGHT;\n\n    char full_name[256];\n    int i;\n    int j;\n\n    struct xrdp_bitmap *bm = xrdp_bitmap_create(4, 4, 32, WND_TYPE_IMAGE, wm);\n\n    ck_assert_ptr_ne(bm, NULL);\n\n    g_snprintf(full_name, sizeof(full_name), IMAGEDIR \"/%s\", name);\n    result = xrdp_bitmap_load(bm, full_name, NULL, HCOLOR(bm->bpp, WHITE),\n                              XBLT_NONE, 0, 0);\n\n    ck_assert_int_eq(result, 0);\n\n    /* Bitmap right size? */\n    ck_assert_int_eq(bm->width, TEST_NOT4_BM_WIDTH);\n    ck_assert_int_eq(bm->height, TEST_NOT4_BM_HEIGHT);\n\n    /* Check all data */\n    for (i = 0 ; i < width / 2 ; ++i)\n    {\n        for (j = 0 ; j < height / 2 ; ++j)\n        {\n            check_pixel(bm, i, j, TEST_BM_TOP_LEFT_PIXEL);\n            check_pixel(bm, i + width / 2, j, TEST_BM_TOP_RIGHT_PIXEL);\n            check_pixel(bm, i, j + height / 2, TEST_BM_BOTTOM_LEFT_PIXEL);\n            check_pixel(bm, i + width / 2, j + height / 2,\n                        TEST_BM_BOTTOM_RIGHT_PIXEL);\n        }\n    }\n\n    xrdp_bitmap_delete(bm);\n}\n\nSTART_TEST(test_bitmap_load__4_bit__ok)\n{\n    load_and_transform_img(\"test_4bit.bmp\", XBLT_NONE, 0, 0);\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__8_bit__ok)\n{\n    load_and_transform_img(\"test_8bit.bmp\", XBLT_NONE, 0, 0);\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__24_bit__ok)\n{\n    load_and_transform_img(\"test_24bit.bmp\", XBLT_NONE, 0, 0);\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__max_width_zoom__ok)\n{\n    load_and_transform_img(\"test_24bit.bmp\",\n                           XBLT_ZOOM, MAX_VDESKTOP_WIDTH, MIN_VDESKTOP_HEIGHT);\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__max_height_zoom__ok)\n{\n    load_and_transform_img(\"test_24bit.bmp\",\n                           XBLT_ZOOM, MIN_VDESKTOP_WIDTH, MAX_VDESKTOP_HEIGHT);\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__min_zoom__ok)\n{\n    load_and_transform_img(\"test_24bit.bmp\",\n                           XBLT_ZOOM, MIN_VDESKTOP_WIDTH, MIN_VDESKTOP_HEIGHT);\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__max_width_scale__ok)\n{\n    load_and_transform_img(\"test_24bit.bmp\",\n                           XBLT_SCALE, MAX_VDESKTOP_WIDTH, MIN_VDESKTOP_HEIGHT);\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__max_height_scale__ok)\n{\n    load_and_transform_img(\"test_24bit.bmp\",\n                           XBLT_SCALE, MIN_VDESKTOP_WIDTH, MAX_VDESKTOP_HEIGHT);\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__min_scale__ok)\n{\n    load_and_transform_img(\"test_24bit.bmp\",\n                           XBLT_SCALE, MIN_VDESKTOP_WIDTH, MIN_VDESKTOP_HEIGHT);\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__not_4_pixels_wide_4_bit__ok)\n{\n    load_not4_img(\"test_not4_4bit.bmp\");\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__not_4_pixels_wide_8_bit__ok)\n{\n    load_not4_img(\"test_not4_8bit.bmp\");\n}\nEND_TEST\n\nSTART_TEST(test_bitmap_load__not_4_pixels_wide_24_bit__ok)\n{\n    load_not4_img(\"test_not4_24bit.bmp\");\n}\nEND_TEST\n\n#ifdef USE_IMLIB2\nSTART_TEST(test_png_load__blend_ok)\n{\n    load_and_transform_img(\"test_alpha_blend.png\", XBLT_NONE, 0, 0);\n}\nEND_TEST\n\nSTART_TEST(test_jpg_load__ok)\n{\n    load_and_transform_img(\"test1.jpg\", XBLT_NONE, 0, 0);\n}\nEND_TEST\n#endif\n\n/******************************************************************************/\nSuite *\nmake_suite_test_bitmap_load(void)\n{\n    Suite *s;\n    TCase *tc;\n\n    s = suite_create(\"BitmapLoad\");\n\n    tc = tcase_create(\"xrdp_bitmap_load_basic\");\n    suite_add_tcase(s, tc);\n    tcase_add_checked_fixture(tc, setup, teardown);\n    tcase_add_test(tc, test_bitmap_load__with_invalid_image__fail);\n    tcase_add_test(tc, test_bitmap_load__4_bit__ok);\n    tcase_add_test(tc, test_bitmap_load__8_bit__ok);\n    tcase_add_test(tc, test_bitmap_load__24_bit__ok);\n\n    tc = tcase_create(\"xrdp_bitmap_load_zoom\");\n    suite_add_tcase(s, tc);\n    tcase_add_checked_fixture(tc, setup, teardown);\n    tcase_set_timeout(tc, LARGE_BM_TEST_SUITE_TIMEOUT);\n    tcase_add_test(tc, test_bitmap_load__max_width_zoom__ok);\n    tcase_add_test(tc, test_bitmap_load__max_height_zoom__ok);\n    tcase_add_test(tc, test_bitmap_load__min_zoom__ok);\n\n    tc = tcase_create(\"xrdp_bitmap_load_scale\");\n    suite_add_tcase(s, tc);\n    tcase_add_checked_fixture(tc, setup, teardown);\n    tcase_set_timeout(tc, LARGE_BM_TEST_SUITE_TIMEOUT);\n    tcase_add_test(tc, test_bitmap_load__max_width_scale__ok);\n    tcase_add_test(tc, test_bitmap_load__max_height_scale__ok);\n    tcase_add_test(tc, test_bitmap_load__min_scale__ok);\n\n    tc = tcase_create(\"xrdp_bitmap_load_not_mod_4\");\n    suite_add_tcase(s, tc);\n    tcase_add_checked_fixture(tc, setup, teardown);\n    tcase_add_test(tc, test_bitmap_load__not_4_pixels_wide_4_bit__ok);\n    tcase_add_test(tc, test_bitmap_load__not_4_pixels_wide_8_bit__ok);\n    tcase_add_test(tc, test_bitmap_load__not_4_pixels_wide_24_bit__ok);\n\n\n#ifdef USE_IMLIB2\n    tc = tcase_create(\"xrdp_other_load\");\n    suite_add_tcase(s, tc);\n    tcase_add_checked_fixture(tc, setup, teardown);\n    tcase_add_test(tc, test_png_load__blend_ok);\n    tcase_add_test(tc, test_jpg_load__ok);\n#endif\n\n    return s;\n}\n"
  },
  {
    "path": "tests/xrdp/test_tconfig.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"xrdp_tconfig.h\"\n#include \"test_xrdp.h\"\n#include \"xrdp.h\"\n\n#define GFXCONF_STUBDIR XRDP_TOP_SRCDIR \"/tests/xrdp/gfx/\"\n\nSTART_TEST(test_tconfig_gfx_always_success)\n{\n    ck_assert_int_eq(1, 1);\n}\nEND_TEST\n\nSTART_TEST(test_tconfig_gfx_h264_oh264)\n{\n    struct xrdp_tconfig_gfx gfxconfig;\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_h264_encoder_openh264.toml\", &gfxconfig);\n\n    /* H.264 encoder is OpenH264 */\n    ck_assert_int_eq(gfxconfig.h264_encoder, XTC_H264_OPENH264);\n}\n\nSTART_TEST(test_tconfig_gfx_h264_x264)\n{\n    struct xrdp_tconfig_gfx gfxconfig;\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_h264_encoder_x264.toml\", &gfxconfig);\n\n    /* H.264 encoder is x264 */\n    ck_assert_int_eq(gfxconfig.h264_encoder, XTC_H264_X264);\n}\n\nSTART_TEST(test_tconfig_gfx_h264_undefined)\n{\n    struct xrdp_tconfig_gfx gfxconfig;\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_h264_encoder_undefined.toml\", &gfxconfig);\n\n    /* H.264 encoder is x264 if undefined */\n    ck_assert_int_eq(gfxconfig.h264_encoder, XTC_H264_X264);\n}\n\nSTART_TEST(test_tconfig_gfx_h264_invalid)\n{\n    struct xrdp_tconfig_gfx gfxconfig;\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_h264_encoder_invalid.toml\", &gfxconfig);\n\n    /* H.264 encoder is x264 if invalid, unknown encoder specified */\n    ck_assert_int_eq(gfxconfig.h264_encoder, XTC_H264_X264);\n}\n\nSTART_TEST(test_tconfig_gfx_oh264_load_basic)\n{\n    struct xrdp_tconfig_gfx gfxconfig;\n    int rv = tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx.toml\", &gfxconfig);\n\n    ck_assert_int_eq(rv, 0);\n\n    /* default */\n    ck_assert_int_eq(gfxconfig.openh264_param[0].EnableFrameSkip, 0);\n    ck_assert_int_eq(gfxconfig.openh264_param[0].TargetBitrate, 20000000);\n    ck_assert_int_eq(gfxconfig.openh264_param[0].MaxBitrate, 0);\n    ck_assert_float_eq(gfxconfig.openh264_param[0].MaxFrameRate, 60.0);\n}\n\nSTART_TEST(test_tconfig_gfx_x264_load_basic)\n{\n    struct xrdp_tconfig_gfx gfxconfig;\n    int rv = tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx.toml\", &gfxconfig);\n\n    ck_assert_int_eq(rv, 0);\n\n    /* default */\n    ck_assert_str_eq(gfxconfig.x264_param[0].preset, \"ultrafast\");\n    ck_assert_str_eq(gfxconfig.x264_param[0].tune, \"zerolatency\");\n    ck_assert_str_eq(gfxconfig.x264_param[0].profile, \"main\");\n    ck_assert_int_eq(gfxconfig.x264_param[0].vbv_max_bitrate, 0);\n    ck_assert_int_eq(gfxconfig.x264_param[0].vbv_buffer_size, 0);\n    ck_assert_int_eq(gfxconfig.x264_param[0].fps_num, 60);\n    ck_assert_int_eq(gfxconfig.x264_param[0].fps_den, 1);\n\n}\nEND_TEST\n\nSTART_TEST(test_tconfig_gfx_codec_order)\n{\n    struct xrdp_tconfig_gfx gfxconfig;\n\n    /* H264 earlier */\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_codec_h264_preferred.toml\", &gfxconfig);\n    ck_assert_int_eq(gfxconfig.codec.codec_count, 2);\n    ck_assert_int_eq(gfxconfig.codec.codecs[0], XTC_H264);\n    ck_assert_int_eq(gfxconfig.codec.codecs[1], XTC_RFX);\n\n    /* H264 only */\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_codec_h264_only.toml\", &gfxconfig);\n    ck_assert_int_eq(gfxconfig.codec.codec_count, 1);\n    ck_assert_int_eq(gfxconfig.codec.codecs[0], XTC_H264);\n\n    /* RFX earlier */\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_codec_rfx_preferred.toml\", &gfxconfig);\n    ck_assert_int_eq(gfxconfig.codec.codec_count, 2);\n    ck_assert_int_eq(gfxconfig.codec.codecs[0], XTC_RFX);\n    ck_assert_int_eq(gfxconfig.codec.codecs[1], XTC_H264);\n\n    /* RFX appears twice like: RFX, H264, RFX */\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_codec_rfx_preferred_odd.toml\", &gfxconfig);\n    ck_assert_int_eq(gfxconfig.codec.codec_count, 2);\n    ck_assert_int_eq(gfxconfig.codec.codecs[0], XTC_RFX);\n    ck_assert_int_eq(gfxconfig.codec.codecs[1], XTC_H264);\n\n    /* RFX only */\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_codec_rfx_only.toml\", &gfxconfig);\n    ck_assert_int_eq(gfxconfig.codec.codec_count, 1);\n    ck_assert_int_eq(gfxconfig.codec.codecs[0], XTC_RFX);\n\n    /* H264 is preferred if order undefined */\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_codec_order_undefined.toml\", &gfxconfig);\n    ck_assert_int_eq(gfxconfig.codec.codec_count, 2);\n    ck_assert_int_eq(gfxconfig.codec.codecs[0], XTC_H264);\n    ck_assert_int_eq(gfxconfig.codec.codecs[1], XTC_RFX);\n}\nEND_TEST\n\nSTART_TEST(test_tconfig_gfx_missing_file)\n{\n    struct xrdp_tconfig_gfx gfxconfig;\n\n    /* Check RFX config is returned if the file doesn't exist */\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/no_such_file.toml\", &gfxconfig);\n    ck_assert_int_eq(gfxconfig.codec.codec_count, 1);\n    ck_assert_int_eq(gfxconfig.codec.codecs[0], XTC_RFX);\n}\nEND_TEST\n\nSTART_TEST(test_tconfig_gfx_missing_h264)\n{\n    struct xrdp_tconfig_gfx gfxconfig;\n\n    /* Check RFX config only is returned if H.264 parameters are missing */\n    tconfig_load_gfx(GFXCONF_STUBDIR \"/gfx_missing_h264.toml\", &gfxconfig);\n    ck_assert_int_eq(gfxconfig.codec.codec_count, 1);\n    ck_assert_int_eq(gfxconfig.codec.codecs[0], XTC_RFX);\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_tconfig_load_gfx(void)\n{\n    Suite *s;\n    TCase *tc_tconfig_load_gfx;\n\n    s = suite_create(\"GfxLoad\");\n\n    tc_tconfig_load_gfx = tcase_create(\"xrdp_tconfig_load_gfx\");\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_always_success);\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_x264_load_basic);\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_codec_order);\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_missing_file);\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_missing_h264);\n\n    /* OpenH264 */\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_oh264_load_basic);\n\n    /* H.264 encoder */\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_h264_oh264);\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_h264_x264);\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_h264_undefined);\n    tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_h264_invalid);\n\n    suite_add_tcase(s, tc_tconfig_load_gfx);\n\n    return s;\n}\n"
  },
  {
    "path": "tests/xrdp/test_xrdp.h",
    "content": "#ifndef TEST_XRDP_H\n#define TEST_XRDP_H\n\n#include <check.h>\n\nSuite *make_suite_test_bitmap_load(void);\nSuite *make_suite_test_keymap_load(void);\nSuite *make_suite_egfx_base_functions(void);\nSuite *make_suite_region(void);\nSuite *make_suite_tconfig_load_gfx(void);\n\n#endif /* TEST_XRDP_H */\n"
  },
  {
    "path": "tests/xrdp/test_xrdp_egfx.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2021\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Test driver for XRDP routines\n *\n * If you want to run this driver under valgrind to check for memory leaks,\n * use the following command line:-\n *\n * CK_FORK=no valgrind --leak-check=full --show-leak-kinds=all \\\n *     .libs/test_xrdp\n *\n * without the 'CK_FORK=no', memory still allocated by the test driver will\n * be logged\n */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"log.h\"\n#include \"os_calls.h\"\n#include <stdlib.h>\n#include \"xrdp_egfx.h\"\n#include \"test_xrdp.h\"\n\nSTART_TEST(test_xrdp_egfx_send_create_surface__happy_path)\n{\n    struct xrdp_egfx_bulk *bulk = g_new0(struct xrdp_egfx_bulk, 1);\n\n    const int surface_id = 0xFF;\n    const int width = 640;\n    const int height = 480;\n    const int pixel_format = 32;\n\n    struct stream *s = xrdp_egfx_create_surface(\n                           bulk, surface_id, width, height, pixel_format);\n    s->p = s->data;\n\n    unsigned char descriptor;\n    in_uint8(s, descriptor);\n    ck_assert_int_eq(0xE0, descriptor);\n\n    free_stream(s);\n    g_free(bulk);\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_egfx_base_functions(void)\n{\n    Suite *s;\n    TCase *tc_process_monitors;\n\n    s = suite_create(\"test_xrdp_egfx_base_functions\");\n\n    tc_process_monitors = tcase_create(\"xrdp_egfx_base_functions\");\n    tcase_add_test(tc_process_monitors,\n                   test_xrdp_egfx_send_create_surface__happy_path);\n\n    suite_add_tcase(s, tc_process_monitors);\n\n    return s;\n}\n\n"
  },
  {
    "path": "tests/xrdp/test_xrdp_keymap.c",
    "content": "#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include <X11/X.h> // For NoSymbol\n#include <X11/keysym.h>\n\n#include \"test_xrdp.h\"\n\n#include \"xrdp.h\"\n\nSTART_TEST(test_keymap_load__basic_load)\n{\n    struct xrdp_keymap km;\n    const struct xrdp_key_info  *ki;\n\n    // Set the memory area to non-zero values\n    memset(&km, 0x7f, sizeof(km));\n\n    // Japanese qwerty layout (see https://kbdlayout.info/kbdjpn)\n    // for OADG 109A\n    //\n    // The Kanji shift-state is not supported by the file format\n    km_load_file(XRDP_TOP_SRCDIR \"/instfiles/km-00000411.toml\", &km);\n\n    ki = &km.keys_noshift[0x59]; // Unmapped scancode\n    ck_assert_int_eq(ki->sym, NoSymbol);\n    ck_assert_int_eq(ki->chr, 0);\n\n    /* qwerty */\n    ki = &km.keys_noshift[0x10];\n    ck_assert_int_eq(ki->sym, XK_q);\n    ck_assert_int_eq(ki->chr, 'q');\n    ki = &km.keys_noshift[0x11];\n    ck_assert_int_eq(ki->sym, XK_w);\n    ck_assert_int_eq(ki->chr, 'w');\n    ki = &km.keys_noshift[0x12];\n    ck_assert_int_eq(ki->sym, XK_e);\n    ck_assert_int_eq(ki->chr, 'e');\n    ki = &km.keys_noshift[0x13];\n    ck_assert_int_eq(ki->sym, XK_r);\n    ck_assert_int_eq(ki->chr, 'r');\n    ki = &km.keys_noshift[0x14];\n    ck_assert_int_eq(ki->sym, XK_t);\n    ck_assert_int_eq(ki->chr, 't');\n    ki = &km.keys_noshift[0x15];\n    ck_assert_int_eq(ki->sym, XK_y);\n    ck_assert_int_eq(ki->chr, 'y');\n\n    /* QWERTY */\n    ki = &km.keys_shift[0x10];\n    ck_assert_int_eq(ki->sym, XK_Q);\n    ck_assert_int_eq(ki->chr, 'Q');\n    ki = &km.keys_shift[0x11];\n    ck_assert_int_eq(ki->sym, XK_W);\n    ck_assert_int_eq(ki->chr, 'W');\n    ki = &km.keys_shift[0x12];\n    ck_assert_int_eq(ki->sym, XK_E);\n    ck_assert_int_eq(ki->chr, 'E');\n    ki = &km.keys_shift[0x13];\n    ck_assert_int_eq(ki->sym, XK_R);\n    ck_assert_int_eq(ki->chr, 'R');\n    ki = &km.keys_shift[0x14];\n    ck_assert_int_eq(ki->sym, XK_T);\n    ck_assert_int_eq(ki->chr, 'T');\n    ki = &km.keys_shift[0x15];\n    ck_assert_int_eq(ki->sym, XK_Y);\n    ck_assert_int_eq(ki->chr, 'Y');\n\n    /* right-shift and 4 keys to left */\n    ki = &km.keys_noshift[0x33]; // OEM Comma\n    ck_assert_int_eq(ki->sym, XK_comma);\n    ck_assert_int_eq(ki->chr, ',');\n    ki = &km.keys_noshift[0x34]; // OEM Period\n    ck_assert_int_eq(ki->sym, XK_period);\n    ck_assert_int_eq(ki->chr, '.');\n    ki = &km.keys_noshift[0x35]; // OEM 2\n    ck_assert_int_eq(ki->sym, XK_slash);\n    ck_assert_int_eq(ki->chr, '/');\n    ki = &km.keys_noshift[0x73]; // ABNT C\n    ck_assert_int_eq(ki->sym, XK_backslash);\n    ck_assert_int_eq(ki->chr, '\\\\');\n    ki = &km.keys_noshift[0x36]; // Right shift\n    ck_assert_int_eq(ki->sym, XK_Shift_R);\n    ck_assert_int_eq(ki->chr, 0);\n}\nEND_TEST\n\n/******************************************************************************/\nSuite *\nmake_suite_test_keymap_load(void)\n{\n    Suite *s;\n    TCase *tc_keymap_load;\n\n    s = suite_create(\"KeymapLoad\");\n\n    tc_keymap_load = tcase_create(\"xrdp_keymap_load\");\n    tcase_add_test(tc_keymap_load, test_keymap_load__basic_load);\n\n    suite_add_tcase(s, tc_keymap_load);\n    return s;\n}\n"
  },
  {
    "path": "tests/xrdp/test_xrdp_main.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2021\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Test driver for XRDP routines\n *\n * If you want to run this driver under valgrind to check for memory leaks,\n * use the following command line:-\n *\n * CK_FORK=no valgrind --leak-check=full --show-leak-kinds=all \\\n *     .libs/test_xrdp\n *\n * without the 'CK_FORK=no', memory still allocated by the test driver will\n * be logged\n */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"log.h\"\n#include \"os_calls.h\"\n#include <stdio.h>\n#include <stdlib.h>\n\n#include \"test_xrdp.h\"\n\nint main (void)\n{\n    int number_failed;\n    SRunner *sr;\n    struct log_config *logging;\n\n    /* Configure the logging sub-system so that functions can use\n     * the log functions as appropriate */\n    logging = log_config_init_for_console(LOG_LEVEL_INFO,\n                                          g_getenv(\"TEST_LOG_LEVEL\"));\n    log_start_from_param(logging);\n    log_config_free(logging);\n    /* Disable stdout buffering, as this can confuse the error\n     * reporting when running in libcheck fork mode */\n    setvbuf(stdout, NULL, _IONBF, 0);\n\n    sr = srunner_create (make_suite_test_bitmap_load());\n    srunner_add_suite(sr, make_suite_test_keymap_load());\n    srunner_add_suite(sr, make_suite_egfx_base_functions());\n    srunner_add_suite(sr, make_suite_region());\n    srunner_add_suite(sr, make_suite_tconfig_load_gfx());\n\n    srunner_set_tap(sr, \"-\");\n    srunner_run_all (sr, CK_ENV);\n    number_failed = srunner_ntests_failed(sr);\n    srunner_free(sr);\n\n    log_end();\n\n    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\n}\n"
  },
  {
    "path": "tests/xrdp/test_xrdp_region.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg, Christopher Pitstick 2004-2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Test driver for XRDP routines\n *\n * If you want to run this driver under valgrind to check for memory leaks,\n * use the following command line:-\n *\n * CK_FORK=no valgrind --leak-check=full --show-leak-kinds=all \\\n *     .libs/test_xrdp\n *\n * without the 'CK_FORK=no', memory still allocated by the test driver will\n * be logged\n */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"log.h\"\n#include \"os_calls.h\"\n#include <stdlib.h>\n\n#if defined(XRDP_PIXMAN)\n#include <pixman.h>\n#else\n#include \"pixman-region.h\"\n#endif\n\n#include \"test_xrdp.h\"\n#include \"xrdp.h\"\n#include <stdarg.h>\n#include <stddef.h>\n#include <stdint.h>\n#include <setjmp.h>\n#ifdef __cplusplus\n#error \"cmocka is not supported with C++\"\n#else\n#include <cmocka.h>\n#endif\n\n#define UNUSED(x) (void)(x)\n\n// Mock functions\nstatic pixman_box16_t test_box =\n{\n    0, 0, 100, 100\n};\n\n// cmocka requires this to be externally linkable\nextern pixman_box16_t *__wrap_pixman_region_extents(pixman_region16_t *region);\npixman_box16_t *__wrap_pixman_region_extents(pixman_region16_t *region)\n{\n    check_expected_ptr(region);\n    return mock_ptr_type(pixman_box16_t *);\n}\n\nstatic void test_xrdp_region_get_bounds__negligent_path(void **state)\n{\n    struct xrdp_region *region = g_new0(struct xrdp_region, 1);\n    struct xrdp_rect *rect = g_new0(struct xrdp_rect, 1);\n\n    // Cmocka boilerplate\n    UNUSED(state);\n    expect_any(__wrap_pixman_region_extents, region);\n    will_return(__wrap_pixman_region_extents, NULL);\n\n    const int ret = xrdp_region_get_bounds(region, rect);\n\n    assert_int_equal(1, ret);\n\n    g_free(region);\n    g_free(rect);\n}\n\nstatic void test_xrdp_region_get_bounds__happy_path(void **state)\n{\n    struct xrdp_region *region = g_new0(struct xrdp_region, 1);\n    struct xrdp_rect *rect = g_new0(struct xrdp_rect, 1);\n\n    // Cmocka boilerplate\n    UNUSED(state);\n    expect_any(__wrap_pixman_region_extents, region);\n    will_return(__wrap_pixman_region_extents, &test_box);\n\n    const int ret = xrdp_region_get_bounds(region, rect);\n\n    assert_int_equal(0, ret);\n    assert_int_equal(0, rect->top);\n    assert_int_equal(0, rect->left);\n    assert_int_equal(100, rect->bottom);\n    assert_int_equal(100, rect->right);\n\n    g_free(region);\n    g_free(rect);\n}\n\n// cmocka requires this to be externally linkable\nextern pixman_bool_t __wrap_pixman_region_not_empty(pixman_region16_t *region);\npixman_bool_t __wrap_pixman_region_not_empty(pixman_region16_t *region)\n{\n    check_expected_ptr(region);\n    return mock_type(pixman_bool_t);\n}\n\nstatic void test_xrdp_region_not_empty__happy_path(void **state)\n{\n    struct xrdp_region *region = g_new0(struct xrdp_region, 1);\n\n    // Cmocka boilerplate\n    UNUSED(state);\n    expect_any(__wrap_pixman_region_not_empty, region);\n    will_return(__wrap_pixman_region_not_empty, (pixman_bool_t)0);\n\n    const int ret = xrdp_region_not_empty(region);\n\n    assert_int_equal(0, ret);\n\n    g_free(region);\n}\n\nSTART_TEST(execute_suite)\n{\n    const struct CMUnitTest tests[] =\n    {\n        cmocka_unit_test(test_xrdp_region_get_bounds__negligent_path),\n        cmocka_unit_test(test_xrdp_region_get_bounds__happy_path),\n        cmocka_unit_test(test_xrdp_region_not_empty__happy_path)\n    };\n\n    ck_assert_int_eq(cmocka_run_group_tests(tests, NULL, NULL), 0);\n}\nEND_TEST\n\n/******************************************************************************/\n/*\nFor an example of how to use cmocka, see the following:\nhttps://gitlab.com/cmocka/cmocka/-/blob/master/example/mock/uptime/test_uptime.c\n*/\nSuite *\nmake_suite_region(void)\n{\n    Suite *s;\n    TCase *tc_region;\n\n    s = suite_create(\"test_xrdp_region\");\n\n    tc_region = tcase_create(\"test_xrdp_region\");\n    tcase_add_test(tc_region, execute_suite);\n\n    suite_add_tcase(s, tc_region);\n\n    return s;\n}\n"
  },
  {
    "path": "third_party/COPYING-THIRD-PARTY",
    "content": "-- tomlc99: TOML C library\n\nMIT License\n\nCopyright (c) CK Tan\nhttps://github.com/cktan/tomlc99\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n--------------------------------------------------------------------------------\n"
  },
  {
    "path": "third_party/Makefile.am",
    "content": "EXTRA_DIST = \\\n             copying_third_party.h \\\n             COPYING-THIRD-PARTY \\\n             Makefile.copying \\\n             README.md\n"
  },
  {
    "path": "third_party/Makefile.copying",
    "content": "\ncopying: copying_third_party.h\n\ncopying_third_party.h:\n\tbin2c copying_third_party < COPYING-THIRD-PARTY > copying_third_party.h\n\nclean:\n\trm -f copying_third_party.h\n"
  },
  {
    "path": "third_party/README.md",
    "content": "# Third-Party Software Components\n\nUnder this directory, third-party software/libraries developed independently\nof xrdp are imported as git submodules or subtree.  Each third-party software\nis subject to its own software license.\n\nSee [COPYING-THIRD-PARTY](third_party/COPYING-THIRD-PARTY) for full license\nstatement of all third-party components.\n\n```\nthird_party\n└── tomlc99 ······ TOML C library (MIT License)\n```\n\n## Developer's Note\n\nIn order to show all license terms in xrdp, follow the steps below after\nadding new third-party libraries.\n\n1. Install [adobe/bin2c](https://github.com/adobe/bin2c) to your development\n   environment\n2. Write all third-party license terms to `COPYING-THIRD-PARTY`\n3. Run `make -f Makefile.copying` to generate `copying_third_party.h`\n4. Commit generated `copying_third_party.h`\n"
  },
  {
    "path": "third_party/copying_third_party.h",
    "content": "#include <stdlib.h>\nconst char copying_third_party[] = \"\\\n-- tomlc99: TOML C library\\n\\\n\\n\\\nMIT License\\n\\\n\\n\\\nCopyright (c) CK Tan\\n\\\nhttps://github.com/cktan/tomlc99\\n\\\n\\n\\\nPermission is hereby granted, free of charge, to any person obtaining a copy\\n\\\nof this software and associated documentation files (the \\\"Software\\\"), to deal\\n\\\nin the Software without restriction, including without limitation the rights\\n\\\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\\n\\\ncopies of the Software, and to permit persons to whom the Software is\\n\\\nfurnished to do so, subject to the following conditions:\\n\\\n\\n\\\nThe above copyright notice and this permission notice shall be included in all\\n\\\ncopies or substantial portions of the Software.\\n\\\n\\n\\\nTHE SOFTWARE IS PROVIDED \\\"AS IS\\\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\\n\\\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\\n\\\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\\n\\\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\\n\\\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\\n\\\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\\n\\\nSOFTWARE.\\n\\\n\\n\\\n--------------------------------------------------------------------------------\\n\\\n\";\nconst size_t copying_third_party_len = sizeof(copying_third_party) - 1;\n"
  },
  {
    "path": "third_party/tomlc99/.editorconfig",
    "content": "root = true\n\n[*]\nend_of_line = lf\ninsert_final_newline = false\ntrim_trailing_whitespace = true\n\n[*.{c,h}]\nindent_style = space\nindent_size = 2\n\n[Makefile]\nindent_style = tab\nindent_size = 4\n"
  },
  {
    "path": "third_party/tomlc99/.gitignore",
    "content": "*~\n\n# Object files\n*.o\n*.ko\n*.obj\n*.elf\n\n# Precompiled Headers\n*.gch\n*.pch\n\n# Libraries\n*.lib\n*.a\n*.la\n*.lo\n\n# Shared objects (inc. Windows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n*.i*86\n*.x86_64\n*.hex\ntoml_cat\ntoml_json\ntoml_sample\n\n# Debug files\n*.dSYM/\n*.su\n"
  },
  {
    "path": "third_party/tomlc99/LICENSE",
    "content": "MIT License\n\nCopyright (c) CK Tan\nhttps://github.com/cktan/tomlc99\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "third_party/tomlc99/Makefile.am",
    "content": "EXTRA_DIST = \\\n    toml.c \\\n    toml.h \\\n    LICENSE\n\n# See src/Makefile\n# '-x c' forces gcc to be used if we are using g++ for CI testing\nAM_CFLAGS = -x c -std=c99 -std=c99 -Wall -Wextra -fpic\n\nmodule_LTLIBRARIES  = libtoml.la\n\nlibtoml_la_SOURCES = toml.c toml.h\n\nlibtoml_la_LDFLAGS = -version-info 1:0\n\ninclude_headers = toml.h\n\n"
  },
  {
    "path": "third_party/tomlc99/README.md",
    "content": "# tomlc99\n\n> **Note: there is a newer version of this library available at [tomlc17](https://github.com/cktan/tomlc17).**\n\nTOML in c99; v1.0 compliant.\n\nIf you are looking for a C++ library, you might try this wrapper: [https://github.com/cktan/tomlcpp](https://github.com/cktan/tomlcpp).\n\n* Compatible with [TOML v1.0.0](https://toml.io/en/v1.0.0).\n* Tested with multiple test suites, including\n[toml-lang/toml-test](https://github.com/toml-lang/toml-test) and\n[iarna/toml-spec-tests](https://github.com/iarna/toml-spec-tests).\n* Provides very simple and intuitive interface.\n\n\n## Usage\n\nPlease see the `toml.h` file for details. The following is a simple example that\nparses this config file:\n\n```toml\n[server]\n\thost = \"www.example.com\"\n\tport = [ 8080, 8181, 8282 ]\n```\n\nThese are the usual steps for getting values from a file:\n\n1. Parse the TOML file.\n2. Traverse and locate a table in TOML.\n3. Extract values from the table.\n4. Free up allocated memory.\n\nBelow is an example of parsing the values from the example table.\n\n```c\n#include <stdio.h>\n#include <string.h>\n#include <errno.h>\n#include <stdlib.h>\n#include \"toml.h\"\n\nstatic void error(const char* msg, const char* msg1)\n{\n    fprintf(stderr, \"ERROR: %s%s\\n\", msg, msg1?msg1:\"\");\n    exit(1);\n}\n\n\nint main()\n{\n    FILE* fp;\n    char errbuf[200];\n\n    // 1. Read and parse toml file\n    fp = fopen(\"sample.toml\", \"r\");\n    if (!fp) {\n        error(\"cannot open sample.toml - \", strerror(errno));\n    }\n\n    toml_table_t* conf = toml_parse_file(fp, errbuf, sizeof(errbuf));\n    fclose(fp);\n\n    if (!conf) {\n        error(\"cannot parse - \", errbuf);\n    }\n\n    // 2. Traverse to a table.\n    toml_table_t* server = toml_table_in(conf, \"server\");\n    if (!server) {\n        error(\"missing [server]\", \"\");\n    }\n\n    // 3. Extract values\n    toml_datum_t host = toml_string_in(server, \"host\");\n    if (!host.ok) {\n        error(\"cannot read server.host\", \"\");\n    }\n\n    toml_array_t* portarray = toml_array_in(server, \"port\");\n    if (!portarray) {\n        error(\"cannot read server.port\", \"\");\n    }\n\n    printf(\"host: %s\\n\", host.u.s);\n    printf(\"port: \");\n    for (int i = 0; ; i++) {\n        toml_datum_t port = toml_int_at(portarray, i);\n        if (!port.ok) break;\n        printf(\"%d \", (int)port.u.i);\n    }\n    printf(\"\\n\");\n\n    // 4. Free memory\n    free(host.u.s);\n    toml_free(conf);\n    return 0;\n}\n```\n\n#### Accessing Table Content\n\nTOML tables are dictionaries where lookups are done using string keys. In\ngeneral, all access functions on tables are named `toml_*_in(...)`.\n\nIn the normal case, you know the key and its content type, and retrievals can be done\nusing one of these functions:\n```c\ntoml_string_in(tab, key);\ntoml_bool_in(tab, key);\ntoml_int_in(tab, key);\ntoml_double_in(tab, key);\ntoml_timestamp_in(tab, key);\ntoml_table_in(tab, key);\ntoml_array_in(tab, key);\n```\n\nYou can also interrogate the keys in a table using an integer index:\n```c\ntoml_table_t* tab = toml_parse_file(...);\nfor (int i = 0; ; i++) {\n    const char* key = toml_key_in(tab, i);\n    if (!key) break;\n    printf(\"key %d: %s\\n\", i, key);\n}\n```\n\n#### Accessing Array Content\n\nTOML arrays can be deref-ed using integer indices. In general, all access methods on arrays are named `toml_*_at()`.\n\nTo obtain the size of an array:\n```c\nint size = toml_array_nelem(arr);\n```\n\nTo obtain the content of an array, use a valid index and call one of these functions:\n```c\ntoml_string_at(arr, idx);\ntoml_bool_at(arr, idx);\ntoml_int_at(arr, idx);\ntoml_double_at(arr, idx);\ntoml_timestamp_at(arr, idx);\ntoml_table_at(arr, idx);\ntoml_array_at(arr, idx);\n```\n\n#### toml_datum_t\n\nSome `toml_*_at` and `toml_*_in` functions return a toml_datum_t\nstructure. The `ok` flag in the structure indicates if the function\ncall was successful. If so, you may proceed to read the value\ncorresponding to the type of the content.\n\nFor example:\n```\ntoml_datum_t host = toml_string_in(tab, \"host\");\nif (host.ok) {\n\tprintf(\"host: %s\\n\", host.u.s);\n\tfree(host.u.s);   /* FREE applies to string and timestamp types only */\n}\n```\n\n** IMPORTANT: if the accessed value is a string or a timestamp, you must call `free(datum.u.s)` or `free(datum.u.ts)` respectively after usage. **\n\n## Building and installing\n\nA normal *make* suffices. You can also simply include the\n`toml.c` and `toml.h` files in your project.\n\nInvoking `make install` will install the header and library files into\n/usr/local/{include,lib}.\n\nAlternatively, specify `make install prefix=/a/file/path` to install into\n/a/file/path/{include,lib}.\n\n## Testing\n\nTo test against the standard test set provided by toml-lang/toml-test:\n\n```sh\n% make\n% cd test1\n% bash build.sh   # do this once\n% bash run.sh     # this will run the test suite\n```\n\n\nTo test against the standard test set provided by iarna/toml:\n\n```sh\n% make\n% cd test2\n% bash build.sh   # do this once\n% bash run.sh     # this will run the test suite\n```\n"
  },
  {
    "path": "third_party/tomlc99/libtoml.pc.sample",
    "content": "prefix=/usr/local\nexec_prefix=${prefix}\nlibdir=${exec_prefix}/lib\nincludedir=${prefix}/include\n\nName: libtoml\nURL: https://github.com/cktan/tomlc99/\nDescription: TOML C library in c99.\nVersion: v1.0\nLibs: -L${libdir} -ltoml\nCflags: -I${includedir}\n"
  },
  {
    "path": "third_party/tomlc99/sample.toml",
    "content": "[server]\n    host = \"example.com\"\n    port = [ 8080, 8181, 8282 ]\n"
  },
  {
    "path": "third_party/tomlc99/stdex/.gitignore",
    "content": "/*.out\n"
  },
  {
    "path": "third_party/tomlc99/stdex/RUN.sh",
    "content": "rm -f *.out\nfor i in *.toml; do\n   echo -n $i\n   ../toml_cat $i >& $i.out\n   if [ -f $i.res ]; then\n      if $(diff $i.out $i.res >& /dev/null); then\n        echo \" [OK]\"\n      else\n\techo \" [FAILED]\"\n      fi\n   else\n      echo \" [?????]\"\n   fi\n \ndone\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arr1.toml",
    "content": "integers = [ 1, 2, 3 ]\ncolors = [ \"red\", \"yellow\", \"green\" ]\nnested_arrays_of_ints = [ [ 1, 2 ], [3, 4, 5] ]\nnested_mixed_array = [ [ 1, 2 ], [\"a\", \"b\", \"c\"] ]\nstring_array = [ \"all\", 'strings', \"\"\"are the same\"\"\", '''type''' ]\n\n# Mixed-type arrays are allowed\nnumbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]\ncontributors = [\n  \"Foo Bar <foo@example.com>\",\n  { name = \"Baz Qux\", email = \"bazqux@example.com\", url = \"https://example.com/bazqux\" }\n]\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arr1.toml.res",
    "content": "{\n  integers = [\n    1,\n    2,\n    3,\n  ],\n  colors = [\n    \"red\",\n    \"yellow\",\n    \"green\",\n  ],\n  nested_arrays_of_ints = [\n    [\n      1,\n      2,\n    ],\n    [\n      3,\n      4,\n      5,\n    ],\n  ],\n  nested_mixed_array = [\n    [\n      1,\n      2,\n    ],\n    [\n      \"a\",\n      \"b\",\n      \"c\",\n    ],\n  ],\n  string_array = [\n    \"all\",\n    \"strings\",\n    \"are the same\",\n    \"type\",\n  ],\n  numbers = [\n    0.100000,\n    0.200000,\n    0.500000,\n    1,\n    2,\n    5,\n  ],\n  contributors = [\n    \"Foo Bar <foo@example.com>\",\n    {\n      name = \"Baz Qux\",\n      email = \"bazqux@example.com\",\n      url = \"https://example.com/bazqux\",\n    },\n  ],\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arr2.toml",
    "content": "integers2 = [\n  1, 2, 3\n]\n\nintegers3 = [\n  1,\n  2, # this is ok\n]\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arr2.toml.res",
    "content": "{\n  integers2 = [\n    1,\n    2,\n    3,\n  ],\n  integers3 = [\n    1,\n    2,\n  ],\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab1.toml",
    "content": "[[products]]\nname = \"Hammer\"\nsku = 738594937\n\n[[products]]  # empty table within the array\n\n[[products]]\nname = \"Nail\"\nsku = 284758393\n\ncolor = \"gray\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab1.toml.res",
    "content": "{\n  products = [\n    {\n      name = \"Hammer\",\n      sku = 738594937,\n    },\n    {\n    },\n    {\n      name = \"Nail\",\n      sku = 284758393,\n      color = \"gray\",\n    },\n  ],\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab2.toml",
    "content": "[[fruits]]\nname = \"apple\"\n\n[fruits.physical]  # subtable\ncolor = \"red\"\nshape = \"round\"\n\n[[fruits.varieties]]  # nested array of tables\nname = \"red delicious\"\n\n[[fruits.varieties]]\nname = \"granny smith\"\n\n\n[[fruits]]\nname = \"banana\"\n\n[[fruits.varieties]]\nname = \"plantain\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab2.toml.res",
    "content": "{\n  fruits = [\n    {\n      name = \"apple\",\n      varieties = [\n        {\n          name = \"red delicious\",\n        },\n        {\n          name = \"granny smith\",\n        },\n      ],\n      physical = {\n        color = \"red\",\n        shape = \"round\",\n      },\n    },\n    {\n      name = \"banana\",\n      varieties = [\n        {\n          name = \"plantain\",\n        },\n      ],\n    },\n  ],\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab3.toml",
    "content": "# INVALID TOML DOC\n[fruit.physical]  # subtable, but to which parent element should it belong?\ncolor = \"red\"\nshape = \"round\"\n\n[[fruit]]  # parser must throw an error upon discovering that \"fruit\" is\n           # an array rather than a table\nname = \"apple\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab3.toml.res",
    "content": "ERROR: line 6: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab4.toml",
    "content": "# INVALID TOML DOC\nfruits = []\n\n[[fruits]] # Not allowed\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab4.toml.res",
    "content": "ERROR: line 4: array mismatch\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab5.toml",
    "content": "# INVALID TOML DOC\n[[fruits]]\nname = \"apple\"\n\n[[fruits.varieties]]\nname = \"red delicious\"\n\n# INVALID: This table conflicts with the previous array of tables\n[fruits.varieties]\nname = \"granny smith\"\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab5.toml.res",
    "content": "ERROR: line 9: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab6.toml",
    "content": "# INVALID TOML DOC\n[[fruits]]\nname = \"apple\"\n\n[[fruits.varieties]]\nname = \"red delicious\"\n\n[fruits.physical]\ncolor = \"red\"\nshape = \"round\"\n\n# INVALID: This array of tables conflicts with the previous table\n[[fruits.physical]]\ncolor = \"green\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab6.toml.res",
    "content": "ERROR: line 13: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab7.toml",
    "content": "points = [ { x = 1, y = 2, z = 3 },\n           { x = 7, y = 8, z = 9 },\n           { x = 2, y = 4, z = 8 } ]\n"
  },
  {
    "path": "third_party/tomlc99/stdex/arrtab7.toml.res",
    "content": "{\n  points = [\n    {\n      x = 1,\n      y = 2,\n      z = 3,\n    },\n    {\n      x = 7,\n      y = 8,\n      z = 9,\n    },\n    {\n      x = 2,\n      y = 4,\n      z = 8,\n    },\n  ],\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/bool1.toml",
    "content": "bool1 = true\nbool2 = false\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/bool1.toml.res",
    "content": "{\n  bool1 = true,\n  bool2 = false,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/comment.toml",
    "content": "# This is a full-line comment\nkey = \"value\"  # This is a comment at the end of a line\nanother = \"# This is not a comment\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/comment.toml.res",
    "content": "{\n  key = \"value\",\n  another = \"# This is not a comment\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float1.toml",
    "content": "# fractional\nflt1 = +1.0\nflt2 = 3.1415\nflt3 = -0.01\n\n# exponent\nflt4 = 5e+22\nflt5 = 1e06\nflt6 = -2E-2\n\n# both\nflt7 = 6.626e-34\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float1.toml.res",
    "content": "{\n  flt1 = 1.000000,\n  flt2 = 3.141500,\n  flt3 = -0.010000,\n  flt4 = 49999999999999995805696.000000,\n  flt5 = 1000000.000000,\n  flt6 = -0.020000,\n  flt7 = 0.000000,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float2.toml",
    "content": "invalid_float_1 = .7\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float2.toml.res",
    "content": "{\nERROR: unable to decode value in table\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float3.toml",
    "content": "invalid_float_2 = 7.\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float3.toml.res",
    "content": "{\nERROR: unable to decode value in table\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float4.toml",
    "content": "invalid_float_3 = 3.e+20\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float4.toml.res",
    "content": "{\nERROR: unable to decode value in table\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float5.toml",
    "content": "flt8 = 224_617.445_991_228\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float5.toml.res",
    "content": "{\n  flt8 = 224617.445991,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float6.toml",
    "content": "# infinity\nsf1 = inf  # positive infinity\nsf2 = +inf # positive infinity\nsf3 = -inf # negative infinity\n\n# not a number\nsf4 = nan  # actual sNaN/qNaN encoding is implementation-specific\nsf5 = +nan # same as `nan`\nsf6 = -nan # valid, actual encoding is implementation-specific\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/float6.toml.res",
    "content": "{\n  sf1 = inf,\n  sf2 = inf,\n  sf3 = -inf,\n  sf4 = nan,\n  sf5 = nan,\n  sf6 = nan,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/inlinetab1.toml",
    "content": "name = { first = \"Tom\", last = \"Preston-Werner\" }\npoint = { x = 1, y = 2 }\nanimal = { type.name = \"pug\" }\n"
  },
  {
    "path": "third_party/tomlc99/stdex/inlinetab1.toml.res",
    "content": "{\n  name = {\n    first = \"Tom\",\n    last = \"Preston-Werner\",\n  },\n  point = {\n    x = 1,\n    y = 2,\n  },\n  animal = {\n    type = {\n      name = \"pug\",\n    },\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/inlinetab2.toml",
    "content": "[product]\ntype = { name = \"Nail\" }\ntype.edible = false  # INVALID\n"
  },
  {
    "path": "third_party/tomlc99/stdex/inlinetab2.toml.res",
    "content": "ERROR: line 3: cannot insert new entry into existing table\n"
  },
  {
    "path": "third_party/tomlc99/stdex/inlinetab3.toml",
    "content": "[product]\ntype.name = \"Nail\"\ntype = { edible = false }  # INVALID\n"
  },
  {
    "path": "third_party/tomlc99/stdex/inlinetab3.toml.res",
    "content": "ERROR: line 3: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/int0.toml",
    "content": "int1 = +99\nint2 = 42\nint3 = 0\nint4 = -17\nint5 = 1_000\nint6 = 5_349_221\nint7 = 53_49_221  # Indian number system grouping\nint8 = 1_2_3_4_5  # VALID but discouraged\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/int0.toml.res",
    "content": "{\n  int1 = 99,\n  int2 = 42,\n  int3 = 0,\n  int4 = -17,\n  int5 = 1000,\n  int6 = 5349221,\n  int7 = 5349221,\n  int8 = 12345,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/int1.toml",
    "content": "# hexadecimal with prefix `0x`\nhex1 = 0xDEADBEEF\nhex2 = 0xdeadbeef\nhex3 = 0xdead_beef\n\n# octal with prefix `0o`\noct1 = 0o01234567\noct2 = 0o755 # useful for Unix file permissions\n\n# binary with prefix `0b`\nbin1 = 0b11010110\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/int1.toml.res",
    "content": "{\n  hex1 = 3735928559,\n  hex2 = 3735928559,\n  hex3 = 3735928559,\n  oct1 = 342391,\n  oct2 = 493,\n  bin1 = 214,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys00.toml",
    "content": "key = \"value\"\nbare_key = \"value\"\nbare-key = \"value\"\n1234 = \"value\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys00.toml.res",
    "content": "{\n  key = \"value\",\n  bare_key = \"value\",\n  bare-key = \"value\",\n  1234 = \"value\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys01.toml",
    "content": "\"127.0.0.1\" = \"value\"\n\"character encoding\" = \"value\"\n\"ʎǝʞ\" = \"value\"\n'key2' = \"value\"\n'quoted \"value\"' = \"value\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys01.toml.res",
    "content": "{\n  127.0.0.1 = \"value\",\n  character encoding = \"value\",\n  ʎǝʞ = \"value\",\n  key2 = \"value\",\n  quoted \"value\" = \"value\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys02.toml",
    "content": "= \"no key name\"  # INVALID\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys02.toml.res",
    "content": "ERROR: line 1: syntax error\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys03.toml",
    "content": "\"\" = \"blank\"     # VALID but discouraged\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys03.toml.res",
    "content": "{\n   = \"blank\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys04.toml",
    "content": "name = \"Orange\"\nphysical.color = \"orange\"\nphysical.shape = \"round\"\nsite.\"google.com\" = true\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys04.toml.res",
    "content": "{\n  name = \"Orange\",\n  physical = {\n    color = \"orange\",\n    shape = \"round\",\n  },\n  site = {\n    google.com = true,\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys05.toml",
    "content": "fruit.name = \"banana\"     # this is best practice\nfruit. color = \"yellow\"    # same as fruit.color\nfruit . flavor = \"banana\"   # same as fruit.flavor\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys05.toml.res",
    "content": "{\n  fruit = {\n    name = \"banana\",\n    color = \"yellow\",\n    flavor = \"banana\",\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys06.toml",
    "content": "# DO NOT DO THIS\nname = \"Tom\"\nname = \"Pradyun\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys06.toml.res",
    "content": "ERROR: line 3: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys07.toml",
    "content": "# THIS WILL NOT WORK\nspelling = \"favorite\"\n\"spelling\" = \"favourite\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys07.toml.res",
    "content": "ERROR: line 3: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys08.toml",
    "content": "# This makes the key \"fruit\" into a table.\nfruit.apple.smooth = true\n\n# So then you can add to the table \"fruit\" like so:\nfruit.orange = 2\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys08.toml.res",
    "content": "{\n  fruit = {\n    orange = 2,\n    apple = {\n      smooth = true,\n    },\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys09.toml",
    "content": "# THE FOLLOWING IS INVALID\n\n# This defines the value of fruit.apple to be an integer.\nfruit.apple = 1\n\n# But then this treats fruit.apple like it's a table.\n# You can't turn an integer into a table.\nfruit.apple.smooth = true\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys09.toml.res",
    "content": "ERROR: line 8: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys10.toml",
    "content": "# VALID BUT DISCOURAGED\n\napple.type = \"fruit\"\norange.type = \"fruit\"\n\napple.skin = \"thin\"\norange.skin = \"thick\"\n\napple.color = \"red\"\norange.color = \"orange\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys10.toml.res",
    "content": "{\n  apple = {\n    type = \"fruit\",\n    skin = \"thin\",\n    color = \"red\",\n  },\n  orange = {\n    type = \"fruit\",\n    skin = \"thick\",\n    color = \"orange\",\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys11.toml",
    "content": "# RECOMMENDED\n\napple.type = \"fruit\"\napple.skin = \"thin\"\napple.color = \"red\"\n\norange.type = \"fruit\"\norange.skin = \"thick\"\norange.color = \"orange\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys11.toml.res",
    "content": "{\n  apple = {\n    type = \"fruit\",\n    skin = \"thin\",\n    color = \"red\",\n  },\n  orange = {\n    type = \"fruit\",\n    skin = \"thick\",\n    color = \"orange\",\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys12.toml",
    "content": "3.14159 = \"pi\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/keys12.toml.res",
    "content": "{\n  3 = {\n    14159 = \"pi\",\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/kvpair0.toml",
    "content": "key = \"value\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/kvpair0.toml.res",
    "content": "{\n  key = \"value\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/kvpair1.toml",
    "content": "key = # INVALID\n"
  },
  {
    "path": "third_party/tomlc99/stdex/kvpair1.toml.res",
    "content": "ERROR: line 1: syntax error\n"
  },
  {
    "path": "third_party/tomlc99/stdex/kvpair2.toml",
    "content": "first = \"Tom\" last = \"Preston-Werner\" # INVALID\n"
  },
  {
    "path": "third_party/tomlc99/stdex/kvpair2.toml.res",
    "content": "ERROR: line 1: extra chars after value\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string0.toml",
    "content": "str = \"I'm a string. \\\"You can quote me\\\". Name\\tJos\\u00E9\\nLocation\\tSF.\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string0.toml.res",
    "content": "{\n  str = \"I'm a string. \\\"You can quote me\\\". Name\\tJos\\0xc3\\0xa9\\nLocation\\tSF.\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string1.toml",
    "content": "str1 = \"\"\"\nRoses are red\nViolets are blue\"\"\"\n\n# On a Unix system, the above multi-line string will most likely be the same as:\nstr2 = \"Roses are red\\nViolets are blue\"\n\n# On a Windows system, it will most likely be equivalent to:\nstr3 = \"Roses are red\\r\\nViolets are blue\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string1.toml.res",
    "content": "{\n  str1 = \"Roses are red\\nViolets are blue\",\n  str2 = \"Roses are red\\nViolets are blue\",\n  str3 = \"Roses are red\\r\\nViolets are blue\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string3.toml",
    "content": "# The following strings are byte-for-byte equivalent:\nstr1 = \"The quick brown fox jumps over the lazy dog.\"\n\nstr2 = \"\"\"\nThe quick brown \\\n\n\n  fox jumps over \\\n    the lazy dog.\"\"\"\n\nstr3 = \"\"\"\\\n       The quick brown \\\n       fox jumps over \\\n       the lazy dog.\\\n       \"\"\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string3.toml.res",
    "content": "{\n  str1 = \"The quick brown fox jumps over the lazy dog.\",\n  str2 = \"The quick brown fox jumps over the lazy dog.\",\n  str3 = \"The quick brown fox jumps over the lazy dog.\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string4.toml",
    "content": "str4 = \"\"\"Here are two quotation marks: \"\". Simple enough.\"\"\"\n# str5 = \"\"\"Here are three quotation marks: \"\"\".\"\"\"  # INVALID\nstr5 = \"\"\"Here are three quotation marks: \"\"\\\".\"\"\"\nstr6 = \"\"\"Here are fifteen quotation marks: \"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\".\"\"\"\n\n# \"This,\" she said, \"is just a pointless statement.\"\nstr7 = \"\"\"\"This,\" she said, \"is just a pointless statement.\"\"\"\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string4.toml.res",
    "content": "{\n  str4 = \"Here are two quotation marks: \\\"\\\". Simple enough.\",\n  str5 = \"Here are three quotation marks: \\\"\\\"\\\".\",\n  str6 = \"Here are fifteen quotation marks: \\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\".\",\n  str7 = \"\\\"This,\\\" she said, \\\"is just a pointless statement.\\\"\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string5.toml",
    "content": "# What you see is what you get.\nwinpath  = 'C:\\Users\\nodejs\\templates'\nwinpath2 = '\\\\ServerX\\admin$\\system32\\'\nquoted   = 'Tom \"Dubs\" Preston-Werner'\nregex    = '<\\i\\c*\\s*>'\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string5.toml.res",
    "content": "{\n  winpath = \"C:\\\\Users\\\\nodejs\\\\templates\",\n  winpath2 = \"\\\\\\\\ServerX\\\\admin$\\\\system32\\\\\",\n  quoted = \"Tom \\\"Dubs\\\" Preston-Werner\",\n  regex = \"<\\\\i\\\\c*\\\\s*>\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string6.toml",
    "content": "regex2 = '''I [dw]on't need \\d{2} apples'''\nlines  = '''\nThe first newline is\ntrimmed in raw strings.\n   All other whitespace\n   is preserved.\n'''\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string6.toml.res",
    "content": "{\n  regex2 = \"I [dw]on't need \\\\d{2} apples\",\n  lines = \"The first newline is\\ntrimmed in raw strings.\\n   All other whitespace\\n   is preserved.\\n\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string7.toml",
    "content": "quot15 = '''Here are fifteen quotation marks: \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"'''\n\n# 'That,' she said, 'is still pointless.'\nstr = ''''That,' she said, 'is still pointless.''''\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string7.toml.res",
    "content": "{\n  quot15 = \"Here are fifteen quotation marks: \\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\",\n  str = \"'That,' she said, 'is still pointless.'\",\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string8.toml",
    "content": "# apos15 = '''Here are fifteen apostrophes: ''''''''''''''''''  # INVALID\napos15 = \"Here are fifteen apostrophes: '''''''''''''''\"\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/string8.toml.res",
    "content": "ERROR: line 2: triple-s-quote inside string lit\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab01.toml",
    "content": "[table-1]\nkey1 = \"some string\"\nkey2 = 123\n\n[table-2]\nkey1 = \"another string\"\nkey2 = 456\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab01.toml.res",
    "content": "{\n  table-1 = {\n    key1 = \"some string\",\n    key2 = 123,\n  },\n  table-2 = {\n    key1 = \"another string\",\n    key2 = 456,\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab02.toml",
    "content": "[dog.\"tater.man\"]\ntype.name = \"pug\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab02.toml.res",
    "content": "{\n  dog = {\n    tater.man = {\n      type = {\n        name = \"pug\",\n      },\n    },\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab03.toml",
    "content": "[a.b.c]            # this is best practice\n[ d.e.f ]          # same as [d.e.f]\n[ g .  h  . i ]    # same as [g.h.i]\n[ j . \"ʞ\" . 'l' ]  # same as [j.\"ʞ\".'l']\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab03.toml.res",
    "content": "{\n  a = {\n    b = {\n      c = {\n      },\n    },\n  },\n  d = {\n    e = {\n      f = {\n      },\n    },\n  },\n  g = {\n    h = {\n      i = {\n      },\n    },\n  },\n  j = {\n    ʞ = {\n      l = {\n      },\n    },\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab04.toml",
    "content": "# [x] you\n# [x.y] don't\n# [x.y.z] need these\n[x.y.z.w] # for this to work\n\n[x] # defining a super-table afterward is ok\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab04.toml.res",
    "content": "{\n  x = {\n    y = {\n      z = {\n        w = {\n        },\n      },\n    },\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab05.toml",
    "content": "# DO NOT DO THIS\n\n[fruit]\napple = \"red\"\n\n[fruit]\norange = \"orange\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab05.toml.res",
    "content": "ERROR: line 6: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab06.toml",
    "content": "# DO NOT DO THIS EITHER\n\n[fruit]\napple = \"red\"\n\n[fruit.apple]\ntexture = \"smooth\"\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab06.toml.res",
    "content": "ERROR: line 6: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab07.toml",
    "content": "# VALID BUT DISCOURAGED\n[fruit.apple]\n[animal]\n[fruit.orange]\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab07.toml.res",
    "content": "{\n  fruit = {\n    apple = {\n    },\n    orange = {\n    },\n  },\n  animal = {\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab08.toml",
    "content": "# Top-level table begins.\nname = \"Fido\"\nbreed = \"pug\"\n\n# Top-level table ends.\n[owner]\nname = \"Regina Dogman\"\nmember_since = 1999-08-04\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab08.toml.res",
    "content": "{\n  name = \"Fido\",\n  breed = \"pug\",\n  owner = {\n    name = \"Regina Dogman\",\n    member_since = 1999-08-04,\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab09.toml",
    "content": "fruit.apple.color = \"red\"\n# Defines a table named fruit\n# Defines a table named fruit.apple\n\nfruit.apple.taste.sweet = true\n# Defines a table named fruit.apple.taste\n# fruit and fruit.apple were already created\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab09.toml.res",
    "content": "{\n  fruit = {\n    apple = {\n      color = \"red\",\n      taste = {\n        sweet = true,\n      },\n    },\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab10.toml",
    "content": "[fruit]\napple.color = \"red\"\napple.taste.sweet = true\n\n[fruit.apple]  # INVALID\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab10.toml.res",
    "content": "ERROR: line 5: key exists\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab11.toml",
    "content": "[fruit]\napple.color = \"red\"\napple.taste.sweet = true\n\n# [fruit.apple]  # INVALID\n# [fruit.apple.taste]  # INVALID\n\n[fruit.apple.texture]  # you can add sub-tables\nsmooth = true\n"
  },
  {
    "path": "third_party/tomlc99/stdex/tab11.toml.res",
    "content": "{\n  fruit = {\n    apple = {\n      color = \"red\",\n      taste = {\n        sweet = true,\n      },\n      texture = {\n        smooth = true,\n      },\n    },\n  },\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts1.toml",
    "content": "odt1 = 1979-05-27T07:32:00Z\nodt2 = 1979-05-27T00:32:00-07:00\nodt3 = 1979-05-27T00:32:00.999999-07:00\nodt4 = 1979-05-27T00:32:00.01-07:00\n\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts1.toml.res",
    "content": "{\n  odt1 = 1979-05-27T07:32:00Z,\n  odt2 = 1979-05-27T00:32:00-07:00,\n  odt3 = 1979-05-27T00:32:00.999-07:00,\n  odt4 = 1979-05-27T00:32:00.010-07:00,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts2.toml",
    "content": "odt4 = 1979-05-27 07:32:00Z\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts2.toml.res",
    "content": "{\n  odt4 = 1979-05-27T07:32:00Z,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts3.toml",
    "content": "ldt1 = 1979-05-27T07:32:00\nldt2 = 1979-05-27T00:32:00.999999\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts3.toml.res",
    "content": "{\n  ldt1 = 1979-05-27T07:32:00,\n  ldt2 = 1979-05-27T00:32:00.999,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts4.toml",
    "content": "ld1 = 1979-05-27\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts4.toml.res",
    "content": "{\n  ld1 = 1979-05-27,\n}\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts5.toml",
    "content": "lt1 = 07:32:00\nlt2 = 00:32:00.999999\n"
  },
  {
    "path": "third_party/tomlc99/stdex/ts5.toml.res",
    "content": "{\n  lt1 = 07:32:00,\n  lt2 = 00:32:00.999,\n}\n"
  },
  {
    "path": "third_party/tomlc99/test1/.gitignore",
    "content": "/goworkspace\n/toml-test\n/toml-test-decoder\n"
  },
  {
    "path": "third_party/tomlc99/test1/README.md",
    "content": "How to run the tests\n===\n\n```\n% bash build.sh\n% bash run.sh\nTest: array-mixed-types-arrays-and-ints (invalid)\n\nExpected an error, but no error was reported.\n-------------------------------------------------------------------------------\nTest: array-mixed-types-ints-and-floats (invalid)\n\nExpected an error, but no error was reported.\n-------------------------------------------------------------------------------\nTest: array-mixed-types-strings-and-ints (invalid)\n\nExpected an error, but no error was reported.\n\n129 passed, 3 failed\n```\n\nNote: toml version 1.0 allows mixed types in arrays.\n"
  },
  {
    "path": "third_party/tomlc99/test1/build.sh",
    "content": "#!/usr/bin/env bash\n\nDIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\n\nexport GOBIN=$DIR\ngo install github.com/toml-lang/toml-test/cmd/toml-test@latest # install test suite"
  },
  {
    "path": "third_party/tomlc99/test1/extra/array_of_tables.toml",
    "content": "x = [ {'a'= 1}, {'a'= 2} ]\n"
  },
  {
    "path": "third_party/tomlc99/test1/extra/inline_array.toml",
    "content": "x = [1,2,3]\n"
  },
  {
    "path": "third_party/tomlc99/test1/extra/inline_table.toml",
    "content": "x = {'a'= 1, 'b'= 2 }\n"
  },
  {
    "path": "third_party/tomlc99/test1/run.sh",
    "content": "#!/usr/bin/env bash\n\nDIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\n\n$DIR/toml-test $DIR/../toml_json\n"
  },
  {
    "path": "third_party/tomlc99/test2/.gitignore",
    "content": "/toml-spec-tests"
  },
  {
    "path": "third_party/tomlc99/test2/Note.txt",
    "content": "Note that we utilize the 'jq' command to normalize json files for comparison. Depending the\nverson of jq on your system, some tests may generate error that looks like this:\n\n   parse error: Exceeds depth limit for parsing at line 1\n\nThis is an error in 'jq', and it does not indicate that the tests themselves fail.\n"
  },
  {
    "path": "third_party/tomlc99/test2/build.sh",
    "content": "#!/usr/bin/env bash\n\nset -e\n\nDIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\n\n[ -d toml-spec-tests ] || git clone https://github.com/cktan/toml-spec-tests.git\n"
  },
  {
    "path": "third_party/tomlc99/test2/run.sh",
    "content": "#!/usr/bin/env bash\n\nif ! (which jq >& /dev/null); then\n    echo \"ERROR: please install the 'jq' utility\"\n    exit 1\nfi\n\n#\n#  POSITIVE tests\n#\nfor i in toml-spec-tests/values/*.toml; do\n    fname=\"$i\"\n    ext=\"${fname##*.}\"\n    fname=\"${fname%.*}\"\n    echo -n $fname ' '\n    res='[OK]'\n    if (../toml_json $fname.toml >& $fname.json.out); then\n        jq -S . $fname.json.out > t.json\n\tmv t.json $fname.json.out\n\tif [ -f $fname.json ]; then\n\t    if ! (diff $fname.json $fname.json.out >& /dev/null); then\n\t        res='[FAILED]'\n\t    else\n\t\trm -f $fname.json.out\n\t    fi\n\telse\n\t    res='[??]'\n\tfi\n    fi\n    echo ... $res\ndone\n\n\n#\n#  NEGATIVE tests\n#\nfor i in toml-spec-tests/errors/*.toml; do\n    echo -n $i ' '\n    res='[OK]'\n    if (../toml_json $i >& $i.json.out); then\n\tres='[FAILED]'\n    fi\n    echo ... $res\ndone\n"
  },
  {
    "path": "third_party/tomlc99/toml.c",
    "content": "/*\n\n  MIT License\n\n  Copyright (c) CK Tan\n  https://github.com/cktan/tomlc99\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n\n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n  SOFTWARE.\n\n*/\n#define _POSIX_C_SOURCE 200809L\n#include \"toml.h\"\n#include <assert.h>\n#include <ctype.h>\n#include <errno.h>\n#include <stdbool.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nstatic void *(*ppmalloc)(size_t) = malloc;\nstatic void (*ppfree)(void *) = free;\n\nvoid toml_set_memutil(void *(*xxmalloc)(size_t), void (*xxfree)(void *)) {\n  if (xxmalloc)\n    ppmalloc = xxmalloc;\n  if (xxfree)\n    ppfree = xxfree;\n}\n\n#define ALIGN8(sz) (((sz) + 7) & ~7)\n#define MALLOC(a) ppmalloc(a)\n#define FREE(a) ppfree(a)\n\n#define malloc(x) error - forbidden - use MALLOC instead\n#define free(x) error - forbidden - use FREE instead\n#define calloc(x, y) error - forbidden - use CALLOC instead\n\nstatic void *CALLOC(size_t nmemb, size_t sz) {\n  int nb = ALIGN8(sz) * nmemb;\n  void *p = MALLOC(nb);\n  if (p) {\n    memset(p, 0, nb);\n  }\n  return p;\n}\n\n// some old platforms define strdup macro -- drop it.\n#undef strdup\n#define strdup(x) error - forbidden - use STRDUP instead\n\nstatic char *STRDUP(const char *s) {\n  int len = strlen(s);\n  char *p = MALLOC(len + 1);\n  if (p) {\n    memcpy(p, s, len);\n    p[len] = 0;\n  }\n  return p;\n}\n\n// some old platforms define strndup macro -- drop it.\n#undef strndup\n#define strndup(x) error - forbiden - use STRNDUP instead\n\nstatic char *STRNDUP(const char *s, size_t n) {\n  size_t len = strnlen(s, n);\n  char *p = MALLOC(len + 1);\n  if (p) {\n    memcpy(p, s, len);\n    p[len] = 0;\n  }\n  return p;\n}\n\n/**\n * Convert a char in utf8 into UCS, and store it in *ret.\n * Return #bytes consumed or -1 on failure.\n */\nint toml_utf8_to_ucs(const char *orig, int len, int64_t *ret) {\n  const unsigned char *buf = (const unsigned char *)orig;\n  unsigned i = *buf++;\n  int64_t v;\n\n  /* 0x00000000 - 0x0000007F:\n     0xxxxxxx\n  */\n  if (0 == (i >> 7)) {\n    if (len < 1)\n      return -1;\n    v = i;\n    return *ret = v, 1;\n  }\n  /* 0x00000080 - 0x000007FF:\n     110xxxxx 10xxxxxx\n  */\n  if (0x6 == (i >> 5)) {\n    if (len < 2)\n      return -1;\n    v = i & 0x1f;\n    for (int j = 0; j < 1; j++) {\n      i = *buf++;\n      if (0x2 != (i >> 6))\n        return -1;\n      v = (v << 6) | (i & 0x3f);\n    }\n    return *ret = v, (const char *)buf - orig;\n  }\n\n  /* 0x00000800 - 0x0000FFFF:\n     1110xxxx 10xxxxxx 10xxxxxx\n  */\n  if (0xE == (i >> 4)) {\n    if (len < 3)\n      return -1;\n    v = i & 0x0F;\n    for (int j = 0; j < 2; j++) {\n      i = *buf++;\n      if (0x2 != (i >> 6))\n        return -1;\n      v = (v << 6) | (i & 0x3f);\n    }\n    return *ret = v, (const char *)buf - orig;\n  }\n\n  /* 0x00010000 - 0x001FFFFF:\n     11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n  */\n  if (0x1E == (i >> 3)) {\n    if (len < 4)\n      return -1;\n    v = i & 0x07;\n    for (int j = 0; j < 3; j++) {\n      i = *buf++;\n      if (0x2 != (i >> 6))\n        return -1;\n      v = (v << 6) | (i & 0x3f);\n    }\n    return *ret = v, (const char *)buf - orig;\n  }\n\n  /* 0x00200000 - 0x03FFFFFF:\n     111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx\n  */\n  if (0x3E == (i >> 2)) {\n    if (len < 5)\n      return -1;\n    v = i & 0x03;\n    for (int j = 0; j < 4; j++) {\n      i = *buf++;\n      if (0x2 != (i >> 6))\n        return -1;\n      v = (v << 6) | (i & 0x3f);\n    }\n    return *ret = v, (const char *)buf - orig;\n  }\n\n  /* 0x04000000 - 0x7FFFFFFF:\n     1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx\n  */\n  if (0x7e == (i >> 1)) {\n    if (len < 6)\n      return -1;\n    v = i & 0x01;\n    for (int j = 0; j < 5; j++) {\n      i = *buf++;\n      if (0x2 != (i >> 6))\n        return -1;\n      v = (v << 6) | (i & 0x3f);\n    }\n    return *ret = v, (const char *)buf - orig;\n  }\n  return -1;\n}\n\n/**\n *\tConvert a UCS char to utf8 code, and return it in buf.\n *\tReturn #bytes used in buf to encode the char, or\n *\t-1 on error.\n */\nint toml_ucs_to_utf8(int64_t code, char buf[6]) {\n  /* http://stackoverflow.com/questions/6240055/manually-converting-unicode-codepoints-into-utf-8-and-utf-16\n   */\n  /* The UCS code values 0xd800–0xdfff (UTF-16 surrogates) as well\n   * as 0xfffe and 0xffff (UCS noncharacters) should not appear in\n   * conforming UTF-8 streams.\n   */\n  if (0xd800 <= code && code <= 0xdfff)\n    return -1;\n  if (0xfffe <= code && code <= 0xffff)\n    return -1;\n\n  /* 0x00000000 - 0x0000007F:\n     0xxxxxxx\n  */\n  if (code < 0)\n    return -1;\n  if (code <= 0x7F) {\n    buf[0] = (unsigned char)code;\n    return 1;\n  }\n\n  /* 0x00000080 - 0x000007FF:\n     110xxxxx 10xxxxxx\n  */\n  if (code <= 0x000007FF) {\n    buf[0] = (unsigned char)(0xc0 | (code >> 6));\n    buf[1] = (unsigned char)(0x80 | (code & 0x3f));\n    return 2;\n  }\n\n  /* 0x00000800 - 0x0000FFFF:\n     1110xxxx 10xxxxxx 10xxxxxx\n  */\n  if (code <= 0x0000FFFF) {\n    buf[0] = (unsigned char)(0xe0 | (code >> 12));\n    buf[1] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));\n    buf[2] = (unsigned char)(0x80 | (code & 0x3f));\n    return 3;\n  }\n\n  /* 0x00010000 - 0x001FFFFF:\n     11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n  */\n  if (code <= 0x001FFFFF) {\n    buf[0] = (unsigned char)(0xf0 | (code >> 18));\n    buf[1] = (unsigned char)(0x80 | ((code >> 12) & 0x3f));\n    buf[2] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));\n    buf[3] = (unsigned char)(0x80 | (code & 0x3f));\n    return 4;\n  }\n\n  /* 0x00200000 - 0x03FFFFFF:\n     111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx\n  */\n  if (code <= 0x03FFFFFF) {\n    buf[0] = (unsigned char)(0xf8 | (code >> 24));\n    buf[1] = (unsigned char)(0x80 | ((code >> 18) & 0x3f));\n    buf[2] = (unsigned char)(0x80 | ((code >> 12) & 0x3f));\n    buf[3] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));\n    buf[4] = (unsigned char)(0x80 | (code & 0x3f));\n    return 5;\n  }\n\n  /* 0x04000000 - 0x7FFFFFFF:\n     1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx\n  */\n  if (code <= 0x7FFFFFFF) {\n    buf[0] = (unsigned char)(0xfc | (code >> 30));\n    buf[1] = (unsigned char)(0x80 | ((code >> 24) & 0x3f));\n    buf[2] = (unsigned char)(0x80 | ((code >> 18) & 0x3f));\n    buf[3] = (unsigned char)(0x80 | ((code >> 12) & 0x3f));\n    buf[4] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));\n    buf[5] = (unsigned char)(0x80 | (code & 0x3f));\n    return 6;\n  }\n\n  return -1;\n}\n\n/*\n *\tTOML has 3 data structures: value, array, table.\n *\tEach of them can have identification key.\n */\ntypedef struct toml_keyval_t toml_keyval_t;\nstruct toml_keyval_t {\n  const char *key; /* key to this value */\n  const char *val; /* the raw value */\n};\n\ntypedef struct toml_arritem_t toml_arritem_t;\nstruct toml_arritem_t {\n  int valtype; /* for value kind: 'i'nt, 'd'ouble, 'b'ool, 's'tring, 't'ime,\n                  'D'ate, 'T'imestamp */\n  char *val;\n  toml_array_t *arr;\n  toml_table_t *tab;\n};\n\nstruct toml_array_t {\n  const char *key; /* key to this array */\n  int kind;        /* element kind: 'v'alue, 'a'rray, or 't'able, 'm'ixed */\n  int type;        /* for value kind: 'i'nt, 'd'ouble, 'b'ool, 's'tring, 't'ime,\n                      'D'ate, 'T'imestamp, 'm'ixed */\n\n  int nitem; /* number of elements */\n  toml_arritem_t *item;\n};\n\nstruct toml_table_t {\n  const char *key; /* key to this table */\n  bool implicit;   /* table was created implicitly */\n  bool readonly;   /* no more modification allowed */\n\n  /* key-values in the table */\n  int nkval;\n  toml_keyval_t **kval;\n\n  /* arrays in the table */\n  int narr;\n  toml_array_t **arr;\n\n  /* tables in the table */\n  int ntab;\n  toml_table_t **tab;\n};\n\nstatic inline void xfree(const void *x) {\n  if (x)\n    FREE((void *)(intptr_t)x);\n}\n\nenum tokentype_t {\n  INVALID,\n  DOT,\n  COMMA,\n  EQUAL,\n  LBRACE,\n  RBRACE,\n  NEWLINE,\n  LBRACKET,\n  RBRACKET,\n  STRING,\n};\ntypedef enum tokentype_t tokentype_t;\n\ntypedef struct token_t token_t;\nstruct token_t {\n  tokentype_t tok;\n  int lineno;\n  char *ptr; /* points into context->start */\n  int len;\n  int eof;\n};\n\ntypedef struct context_t context_t;\nstruct context_t {\n  char *start;\n  char *stop;\n  char *errbuf;\n  int errbufsz;\n\n  token_t tok;\n  toml_table_t *root;\n  toml_table_t *curtab;\n\n  struct {\n    int top;\n    char *key[10];\n    token_t tok[10];\n  } tpath;\n};\n\n#define STRINGIFY(x) #x\n#define TOSTRING(x) STRINGIFY(x)\n#define FLINE __FILE__ \":\" TOSTRING(__LINE__)\n\nstatic int next_token(context_t *ctx, int dotisspecial);\n\n/*\n  Error reporting. Call when an error is detected. Always return -1.\n*/\nstatic int e_outofmemory(context_t *ctx, const char *fline) {\n  snprintf(ctx->errbuf, ctx->errbufsz, \"ERROR: out of memory (%s)\", fline);\n  return -1;\n}\n\nstatic int e_internal(context_t *ctx, const char *fline) {\n  snprintf(ctx->errbuf, ctx->errbufsz, \"internal error (%s)\", fline);\n  return -1;\n}\n\nstatic int e_syntax(context_t *ctx, int lineno, const char *msg) {\n  snprintf(ctx->errbuf, ctx->errbufsz, \"line %d: %s\", lineno, msg);\n  return -1;\n}\n\nstatic int e_badkey(context_t *ctx, int lineno) {\n  snprintf(ctx->errbuf, ctx->errbufsz, \"line %d: bad key\", lineno);\n  return -1;\n}\n\nstatic int e_keyexists(context_t *ctx, int lineno) {\n  snprintf(ctx->errbuf, ctx->errbufsz, \"line %d: key exists\", lineno);\n  return -1;\n}\n\nstatic int e_forbid(context_t *ctx, int lineno, const char *msg) {\n  snprintf(ctx->errbuf, ctx->errbufsz, \"line %d: %s\", lineno, msg);\n  return -1;\n}\n\nstatic void *expand(void *p, int sz, int newsz) {\n  void *s = MALLOC(newsz);\n  if (!s)\n    return 0;\n\n  if (p) {\n    memcpy(s, p, sz);\n    FREE(p);\n  }\n  return s;\n}\n\nstatic void **expand_ptrarr(void **p, int n) {\n  void **s = MALLOC((n + 1) * sizeof(void *));\n  if (!s)\n    return 0;\n\n  s[n] = 0;\n  if (p) {\n    memcpy(s, p, n * sizeof(void *));\n    FREE(p);\n  }\n  return s;\n}\n\nstatic toml_arritem_t *expand_arritem(toml_arritem_t *p, int n) {\n  toml_arritem_t *pp = expand(p, n * sizeof(*p), (n + 1) * sizeof(*p));\n  if (!pp)\n    return 0;\n\n  memset(&pp[n], 0, sizeof(pp[n]));\n  return pp;\n}\n\nstatic char *norm_lit_str(const char *src, int srclen, int multiline,\n                          char *errbuf, int errbufsz) {\n  char *dst = 0; /* will write to dst[] and return it */\n  int max = 0;   /* max size of dst[] */\n  int off = 0;   /* cur offset in dst[] */\n  const char *sp = src;\n  const char *sq = src + srclen;\n  int ch;\n\n  /* scan forward on src */\n  for (;;) {\n    if (off >= max - 10) { /* have some slack for misc stuff */\n      int newmax = max + 50;\n      char *x = expand(dst, max, newmax);\n      if (!x) {\n        xfree(dst);\n        snprintf(errbuf, errbufsz, \"out of memory\");\n        return 0;\n      }\n      dst = x;\n      max = newmax;\n    }\n\n    /* finished? */\n    if (sp >= sq)\n      break;\n\n    ch = *sp++;\n    /* control characters other than tab is not allowed */\n    if ((0 <= ch && ch <= 0x08) || (0x0a <= ch && ch <= 0x1f) || (ch == 0x7f)) {\n      if (!(multiline && (ch == '\\r' || ch == '\\n'))) {\n        xfree(dst);\n        snprintf(errbuf, errbufsz, \"invalid char U+%04x\", ch);\n        return 0;\n      }\n    }\n\n    // a plain copy suffice\n    dst[off++] = ch;\n  }\n\n  dst[off++] = 0;\n  return dst;\n}\n\n/*\n * Convert src to raw unescaped utf-8 string.\n * Returns NULL if error with errmsg in errbuf.\n */\nstatic char *norm_basic_str(const char *src, int srclen, int multiline,\n                            char *errbuf, int errbufsz) {\n  char *dst = 0; /* will write to dst[] and return it */\n  int max = 0;   /* max size of dst[] */\n  int off = 0;   /* cur offset in dst[] */\n  const char *sp = src;\n  const char *sq = src + srclen;\n  int ch;\n\n  /* scan forward on src */\n  for (;;) {\n    if (off >= max - 10) { /* have some slack for misc stuff */\n      int newmax = max + 50;\n      char *x = expand(dst, max, newmax);\n      if (!x) {\n        xfree(dst);\n        snprintf(errbuf, errbufsz, \"out of memory\");\n        return 0;\n      }\n      dst = x;\n      max = newmax;\n    }\n\n    /* finished? */\n    if (sp >= sq)\n      break;\n\n    ch = *sp++;\n    if (ch != '\\\\') {\n      /* these chars must be escaped: U+0000 to U+0008, U+000A to U+001F, U+007F\n       */\n      if ((0 <= ch && ch <= 0x08) || (0x0a <= ch && ch <= 0x1f) ||\n          (ch == 0x7f)) {\n        if (!(multiline && (ch == '\\r' || ch == '\\n'))) {\n          xfree(dst);\n          snprintf(errbuf, errbufsz, \"invalid char U+%04x\", ch);\n          return 0;\n        }\n      }\n\n      // a plain copy suffice\n      dst[off++] = ch;\n      continue;\n    }\n\n    /* ch was backslash. we expect the escape char. */\n    if (sp >= sq) {\n      snprintf(errbuf, errbufsz, \"last backslash is invalid\");\n      xfree(dst);\n      return 0;\n    }\n\n    /* for multi-line, we want to kill line-ending-backslash ... */\n    if (multiline) {\n\n      // if there is only whitespace after the backslash ...\n      if (sp[strspn(sp, \" \\t\\r\")] == '\\n') {\n        /* skip all the following whitespaces */\n        sp += strspn(sp, \" \\t\\r\\n\");\n        continue;\n      }\n    }\n\n    /* get the escaped char */\n    ch = *sp++;\n    switch (ch) {\n    case 'u':\n    case 'U': {\n      int64_t ucs = 0;\n      int nhex = (ch == 'u' ? 4 : 8);\n      for (int i = 0; i < nhex; i++) {\n        if (sp >= sq) {\n          snprintf(errbuf, errbufsz, \"\\\\%c expects %d hex chars\", ch, nhex);\n          xfree(dst);\n          return 0;\n        }\n        ch = *sp++;\n        int v = ('0' <= ch && ch <= '9')\n                    ? ch - '0'\n                    : (('A' <= ch && ch <= 'F') ? ch - 'A' + 10 : -1);\n        if (-1 == v) {\n          snprintf(errbuf, errbufsz, \"invalid hex chars for \\\\u or \\\\U\");\n          xfree(dst);\n          return 0;\n        }\n        ucs = ucs * 16 + v;\n      }\n      int n = toml_ucs_to_utf8(ucs, &dst[off]);\n      if (-1 == n) {\n        snprintf(errbuf, errbufsz, \"illegal ucs code in \\\\u or \\\\U\");\n        xfree(dst);\n        return 0;\n      }\n      off += n;\n    }\n      continue;\n\n    case 'b':\n      ch = '\\b';\n      break;\n    case 't':\n      ch = '\\t';\n      break;\n    case 'n':\n      ch = '\\n';\n      break;\n    case 'f':\n      ch = '\\f';\n      break;\n    case 'r':\n      ch = '\\r';\n      break;\n    case '\"':\n      ch = '\"';\n      break;\n    case '\\\\':\n      ch = '\\\\';\n      break;\n    default:\n      snprintf(errbuf, errbufsz, \"illegal escape char \\\\%c\", ch);\n      xfree(dst);\n      return 0;\n    }\n\n    dst[off++] = ch;\n  }\n\n  // Cap with NUL and return it.\n  dst[off++] = 0;\n  return dst;\n}\n\n/* Normalize a key. Convert all special chars to raw unescaped utf-8 chars. */\nstatic char *normalize_key(context_t *ctx, token_t strtok) {\n  const char *sp = strtok.ptr;\n  const char *sq = strtok.ptr + strtok.len;\n  int lineno = strtok.lineno;\n  char *ret;\n  int ch = *sp;\n  char ebuf[80];\n\n  /* handle quoted string */\n  if (ch == '\\'' || ch == '\\\"') {\n    /* if ''' or \"\"\", take 3 chars off front and back. Else, take 1 char off. */\n    int multiline = 0;\n    if (sp[1] == ch && sp[2] == ch) {\n      sp += 3, sq -= 3;\n      multiline = 1;\n    } else\n      sp++, sq--;\n\n    if (ch == '\\'') {\n      /* for single quote, take it verbatim. */\n      if (!(ret = STRNDUP(sp, sq - sp))) {\n        e_outofmemory(ctx, FLINE);\n        return 0;\n      }\n    } else {\n      /* for double quote, we need to normalize */\n      ret = norm_basic_str(sp, sq - sp, multiline, ebuf, sizeof(ebuf));\n      if (!ret) {\n        e_syntax(ctx, lineno, ebuf);\n        return 0;\n      }\n    }\n\n    /* newlines are not allowed in keys */\n    if (strchr(ret, '\\n')) {\n      xfree(ret);\n      e_badkey(ctx, lineno);\n      return 0;\n    }\n    return ret;\n  }\n\n  /* for bare-key allow only this regex: [A-Za-z0-9_-]+ */\n  const char *xp;\n  for (xp = sp; xp != sq; xp++) {\n    int k = *xp;\n    if (isalnum(k))\n      continue;\n    if (k == '_' || k == '-')\n      continue;\n    e_badkey(ctx, lineno);\n    return 0;\n  }\n\n  /* dup and return it */\n  if (!(ret = STRNDUP(sp, sq - sp))) {\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  return ret;\n}\n\n/*\n * Look up key in tab. Return 0 if not found, or\n * 'v'alue, 'a'rray or 't'able depending on the element.\n */\nstatic int check_key(toml_table_t *tab, const char *key,\n                     toml_keyval_t **ret_val, toml_array_t **ret_arr,\n                     toml_table_t **ret_tab) {\n  int i;\n  void *dummy;\n\n  if (!ret_tab)\n    ret_tab = (toml_table_t **)&dummy;\n  if (!ret_arr)\n    ret_arr = (toml_array_t **)&dummy;\n  if (!ret_val)\n    ret_val = (toml_keyval_t **)&dummy;\n\n  *ret_tab = 0;\n  *ret_arr = 0;\n  *ret_val = 0;\n\n  for (i = 0; i < tab->nkval; i++) {\n    if (0 == strcmp(key, tab->kval[i]->key)) {\n      *ret_val = tab->kval[i];\n      return 'v';\n    }\n  }\n  for (i = 0; i < tab->narr; i++) {\n    if (0 == strcmp(key, tab->arr[i]->key)) {\n      *ret_arr = tab->arr[i];\n      return 'a';\n    }\n  }\n  for (i = 0; i < tab->ntab; i++) {\n    if (0 == strcmp(key, tab->tab[i]->key)) {\n      *ret_tab = tab->tab[i];\n      return 't';\n    }\n  }\n  return 0;\n}\n\nstatic int key_kind(toml_table_t *tab, const char *key) {\n  return check_key(tab, key, 0, 0, 0);\n}\n\n/* Create a keyval in the table.\n */\nstatic toml_keyval_t *create_keyval_in_table(context_t *ctx, toml_table_t *tab,\n                                             token_t keytok) {\n  /* first, normalize the key to be used for lookup.\n   * remember to free it if we error out.\n   */\n  char *newkey = normalize_key(ctx, keytok);\n  if (!newkey)\n    return 0;\n\n  /* if key exists: error out. */\n  toml_keyval_t *dest = 0;\n  if (key_kind(tab, newkey)) {\n    xfree(newkey);\n    e_keyexists(ctx, keytok.lineno);\n    return 0;\n  }\n\n  /* make a new entry */\n  int n = tab->nkval;\n  toml_keyval_t **base;\n  if (0 == (base = (toml_keyval_t **)expand_ptrarr((void **)tab->kval, n))) {\n    xfree(newkey);\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  tab->kval = base;\n\n  if (0 == (base[n] = (toml_keyval_t *)CALLOC(1, sizeof(*base[n])))) {\n    xfree(newkey);\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  dest = tab->kval[tab->nkval++];\n\n  /* save the key in the new value struct */\n  dest->key = newkey;\n  return dest;\n}\n\n/* Create a table in the table.\n */\nstatic toml_table_t *create_keytable_in_table(context_t *ctx, toml_table_t *tab,\n                                              token_t keytok) {\n  /* first, normalize the key to be used for lookup.\n   * remember to free it if we error out.\n   */\n  char *newkey = normalize_key(ctx, keytok);\n  if (!newkey)\n    return 0;\n\n  /* if key exists: error out */\n  toml_table_t *dest = 0;\n  if (check_key(tab, newkey, 0, 0, &dest)) {\n    xfree(newkey); /* don't need this anymore */\n\n    /* special case: if table exists, but was created implicitly ... */\n    if (dest && dest->implicit) {\n      /* we make it explicit now, and simply return it. */\n      dest->implicit = false;\n      return dest;\n    }\n    e_keyexists(ctx, keytok.lineno);\n    return 0;\n  }\n\n  /* create a new table entry */\n  int n = tab->ntab;\n  toml_table_t **base;\n  if (0 == (base = (toml_table_t **)expand_ptrarr((void **)tab->tab, n))) {\n    xfree(newkey);\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  tab->tab = base;\n\n  if (0 == (base[n] = (toml_table_t *)CALLOC(1, sizeof(*base[n])))) {\n    xfree(newkey);\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  dest = tab->tab[tab->ntab++];\n\n  /* save the key in the new table struct */\n  dest->key = newkey;\n  return dest;\n}\n\n/* Create an array in the table.\n */\nstatic toml_array_t *create_keyarray_in_table(context_t *ctx, toml_table_t *tab,\n                                              token_t keytok, char kind) {\n  /* first, normalize the key to be used for lookup.\n   * remember to free it if we error out.\n   */\n  char *newkey = normalize_key(ctx, keytok);\n  if (!newkey)\n    return 0;\n\n  /* if key exists: error out */\n  if (key_kind(tab, newkey)) {\n    xfree(newkey); /* don't need this anymore */\n    e_keyexists(ctx, keytok.lineno);\n    return 0;\n  }\n\n  /* make a new array entry */\n  int n = tab->narr;\n  toml_array_t **base;\n  if (0 == (base = (toml_array_t **)expand_ptrarr((void **)tab->arr, n))) {\n    xfree(newkey);\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  tab->arr = base;\n\n  if (0 == (base[n] = (toml_array_t *)CALLOC(1, sizeof(*base[n])))) {\n    xfree(newkey);\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  toml_array_t *dest = tab->arr[tab->narr++];\n\n  /* save the key in the new array struct */\n  dest->key = newkey;\n  dest->kind = kind;\n  return dest;\n}\n\nstatic toml_arritem_t *create_value_in_array(context_t *ctx,\n                                             toml_array_t *parent) {\n  const int n = parent->nitem;\n  toml_arritem_t *base = expand_arritem(parent->item, n);\n  if (!base) {\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  parent->item = base;\n  parent->nitem++;\n  return &parent->item[n];\n}\n\n/* Create an array in an array\n */\nstatic toml_array_t *create_array_in_array(context_t *ctx,\n                                           toml_array_t *parent) {\n  const int n = parent->nitem;\n  toml_arritem_t *base = expand_arritem(parent->item, n);\n  if (!base) {\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  toml_array_t *ret = (toml_array_t *)CALLOC(1, sizeof(toml_array_t));\n  if (!ret) {\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  base[n].arr = ret;\n  parent->item = base;\n  parent->nitem++;\n  return ret;\n}\n\n/* Create a table in an array\n */\nstatic toml_table_t *create_table_in_array(context_t *ctx,\n                                           toml_array_t *parent) {\n  int n = parent->nitem;\n  toml_arritem_t *base = expand_arritem(parent->item, n);\n  if (!base) {\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  toml_table_t *ret = (toml_table_t *)CALLOC(1, sizeof(toml_table_t));\n  if (!ret) {\n    e_outofmemory(ctx, FLINE);\n    return 0;\n  }\n  base[n].tab = ret;\n  parent->item = base;\n  parent->nitem++;\n  return ret;\n}\n\nstatic int skip_newlines(context_t *ctx, int isdotspecial) {\n  while (ctx->tok.tok == NEWLINE) {\n    if (next_token(ctx, isdotspecial))\n      return -1;\n    if (ctx->tok.eof)\n      break;\n  }\n  return 0;\n}\n\nstatic int parse_keyval(context_t *ctx, toml_table_t *tab);\n\nstatic inline int eat_token(context_t *ctx, tokentype_t typ, int isdotspecial,\n                            const char *fline) {\n  if (ctx->tok.tok != typ)\n    return e_internal(ctx, fline);\n\n  if (next_token(ctx, isdotspecial))\n    return -1;\n\n  return 0;\n}\n\n/* We are at '{ ... }'.\n * Parse the table.\n */\nstatic int parse_inline_table(context_t *ctx, toml_table_t *tab) {\n  if (eat_token(ctx, LBRACE, 1, FLINE))\n    return -1;\n\n  for (;;) {\n    if (ctx->tok.tok == NEWLINE)\n      return e_syntax(ctx, ctx->tok.lineno,\n                      \"newline not allowed in inline table\");\n\n    /* until } */\n    if (ctx->tok.tok == RBRACE)\n      break;\n\n    if (ctx->tok.tok != STRING)\n      return e_syntax(ctx, ctx->tok.lineno, \"expect a string\");\n\n    if (parse_keyval(ctx, tab))\n      return -1;\n\n    if (ctx->tok.tok == NEWLINE)\n      return e_syntax(ctx, ctx->tok.lineno,\n                      \"newline not allowed in inline table\");\n\n    /* on comma, continue to scan for next keyval */\n    if (ctx->tok.tok == COMMA) {\n      if (eat_token(ctx, COMMA, 1, FLINE))\n        return -1;\n      continue;\n    }\n    break;\n  }\n\n  if (eat_token(ctx, RBRACE, 1, FLINE))\n    return -1;\n\n  tab->readonly = 1;\n\n  return 0;\n}\n\nstatic int valtype(const char *val) {\n  toml_timestamp_t ts;\n  if (*val == '\\'' || *val == '\"')\n    return 's';\n  if (0 == toml_rtob(val, 0))\n    return 'b';\n  if (0 == toml_rtoi(val, 0))\n    return 'i';\n  if (0 == toml_rtod(val, 0))\n    return 'd';\n  if (0 == toml_rtots(val, &ts)) {\n    if (ts.year && ts.hour)\n      return 'T'; /* timestamp */\n    if (ts.year)\n      return 'D'; /* date */\n    return 't';   /* time */\n  }\n  return 'u'; /* unknown */\n}\n\n/* We are at '[...]' */\nstatic int parse_array(context_t *ctx, toml_array_t *arr) {\n  if (eat_token(ctx, LBRACKET, 0, FLINE))\n    return -1;\n\n  for (;;) {\n    if (skip_newlines(ctx, 0))\n      return -1;\n\n    /* until ] */\n    if (ctx->tok.tok == RBRACKET)\n      break;\n\n    switch (ctx->tok.tok) {\n    case STRING: {\n      /* set array kind if this will be the first entry */\n      if (arr->kind == 0)\n        arr->kind = 'v';\n      else if (arr->kind != 'v')\n        arr->kind = 'm';\n\n      char *val = ctx->tok.ptr;\n      int vlen = ctx->tok.len;\n\n      /* make a new value in array */\n      toml_arritem_t *newval = create_value_in_array(ctx, arr);\n      if (!newval)\n        return e_outofmemory(ctx, FLINE);\n\n      if (!(newval->val = STRNDUP(val, vlen)))\n        return e_outofmemory(ctx, FLINE);\n\n      newval->valtype = valtype(newval->val);\n\n      /* set array type if this is the first entry */\n      if (arr->nitem == 1)\n        arr->type = newval->valtype;\n      else if (arr->type != newval->valtype)\n        arr->type = 'm'; /* mixed */\n\n      if (eat_token(ctx, STRING, 0, FLINE))\n        return -1;\n      break;\n    }\n\n    case LBRACKET: { /* [ [array], [array] ... ] */\n      /* set the array kind if this will be the first entry */\n      if (arr->kind == 0)\n        arr->kind = 'a';\n      else if (arr->kind != 'a')\n        arr->kind = 'm';\n\n      toml_array_t *subarr = create_array_in_array(ctx, arr);\n      if (!subarr)\n        return -1;\n      if (parse_array(ctx, subarr))\n        return -1;\n      break;\n    }\n\n    case LBRACE: { /* [ {table}, {table} ... ] */\n      /* set the array kind if this will be the first entry */\n      if (arr->kind == 0)\n        arr->kind = 't';\n      else if (arr->kind != 't')\n        arr->kind = 'm';\n\n      toml_table_t *subtab = create_table_in_array(ctx, arr);\n      if (!subtab)\n        return -1;\n      if (parse_inline_table(ctx, subtab))\n        return -1;\n      break;\n    }\n\n    default:\n      return e_syntax(ctx, ctx->tok.lineno, \"syntax error\");\n    }\n\n    if (skip_newlines(ctx, 0))\n      return -1;\n\n    /* on comma, continue to scan for next element */\n    if (ctx->tok.tok == COMMA) {\n      if (eat_token(ctx, COMMA, 0, FLINE))\n        return -1;\n      continue;\n    }\n    break;\n  }\n\n  if (eat_token(ctx, RBRACKET, 1, FLINE))\n    return -1;\n  return 0;\n}\n\n/* handle lines like these:\n   key = \"value\"\n   key = [ array ]\n   key = { table }\n*/\nstatic int parse_keyval(context_t *ctx, toml_table_t *tab) {\n  if (tab->readonly) {\n    return e_forbid(ctx, ctx->tok.lineno,\n                    \"cannot insert new entry into existing table\");\n  }\n\n  token_t key = ctx->tok;\n  if (eat_token(ctx, STRING, 1, FLINE))\n    return -1;\n\n  if (ctx->tok.tok == DOT) {\n    /* handle inline dotted key.\n       e.g.\n       physical.color = \"orange\"\n       physical.shape = \"round\"\n    */\n    toml_table_t *subtab = 0;\n    {\n      char *subtabstr = normalize_key(ctx, key);\n      if (!subtabstr)\n        return -1;\n\n      subtab = toml_table_in(tab, subtabstr);\n      xfree(subtabstr);\n    }\n    if (!subtab) {\n      subtab = create_keytable_in_table(ctx, tab, key);\n      if (!subtab)\n        return -1;\n    }\n    if (next_token(ctx, 1))\n      return -1;\n    if (parse_keyval(ctx, subtab))\n      return -1;\n    return 0;\n  }\n\n  if (ctx->tok.tok != EQUAL) {\n    return e_syntax(ctx, ctx->tok.lineno, \"missing =\");\n  }\n\n  if (next_token(ctx, 0))\n    return -1;\n\n  switch (ctx->tok.tok) {\n  case STRING: { /* key = \"value\" */\n    toml_keyval_t *keyval = create_keyval_in_table(ctx, tab, key);\n    if (!keyval)\n      return -1;\n    token_t val = ctx->tok;\n\n    assert(keyval->val == 0);\n    if (!(keyval->val = STRNDUP(val.ptr, val.len)))\n      return e_outofmemory(ctx, FLINE);\n\n    if (next_token(ctx, 1))\n      return -1;\n\n    return 0;\n  }\n\n  case LBRACKET: { /* key = [ array ] */\n    toml_array_t *arr = create_keyarray_in_table(ctx, tab, key, 0);\n    if (!arr)\n      return -1;\n    if (parse_array(ctx, arr))\n      return -1;\n    return 0;\n  }\n\n  case LBRACE: { /* key = { table } */\n    toml_table_t *nxttab = create_keytable_in_table(ctx, tab, key);\n    if (!nxttab)\n      return -1;\n    if (parse_inline_table(ctx, nxttab))\n      return -1;\n    return 0;\n  }\n\n  default:\n    return e_syntax(ctx, ctx->tok.lineno, \"syntax error\");\n  }\n  return 0;\n}\n\ntypedef struct tabpath_t tabpath_t;\nstruct tabpath_t {\n  int cnt;\n  token_t key[10];\n};\n\n/* at [x.y.z] or [[x.y.z]]\n * Scan forward and fill tabpath until it enters ] or ]]\n * There will be at least one entry on return.\n */\nstatic int fill_tabpath(context_t *ctx) {\n  int lineno = ctx->tok.lineno;\n  int i;\n\n  /* clear tpath */\n  for (i = 0; i < ctx->tpath.top; i++) {\n    char **p = &ctx->tpath.key[i];\n    xfree(*p);\n    *p = 0;\n  }\n  ctx->tpath.top = 0;\n\n  for (;;) {\n    if (ctx->tpath.top >= 10)\n      return e_syntax(ctx, lineno,\n                      \"table path is too deep; max allowed is 10.\");\n\n    if (ctx->tok.tok != STRING)\n      return e_syntax(ctx, lineno, \"invalid or missing key\");\n\n    char *key = normalize_key(ctx, ctx->tok);\n    if (!key)\n      return -1;\n    ctx->tpath.tok[ctx->tpath.top] = ctx->tok;\n    ctx->tpath.key[ctx->tpath.top] = key;\n    ctx->tpath.top++;\n\n    if (next_token(ctx, 1))\n      return -1;\n\n    if (ctx->tok.tok == RBRACKET)\n      break;\n\n    if (ctx->tok.tok != DOT)\n      return e_syntax(ctx, lineno, \"invalid key\");\n\n    if (next_token(ctx, 1))\n      return -1;\n  }\n\n  if (ctx->tpath.top <= 0)\n    return e_syntax(ctx, lineno, \"empty table selector\");\n\n  return 0;\n}\n\n/* Walk tabpath from the root, and create new tables on the way.\n * Sets ctx->curtab to the final table.\n */\nstatic int walk_tabpath(context_t *ctx) {\n  /* start from root */\n  toml_table_t *curtab = ctx->root;\n\n  for (int i = 0; i < ctx->tpath.top; i++) {\n    const char *key = ctx->tpath.key[i];\n\n    toml_keyval_t *nextval = 0;\n    toml_array_t *nextarr = 0;\n    toml_table_t *nexttab = 0;\n    switch (check_key(curtab, key, &nextval, &nextarr, &nexttab)) {\n    case 't':\n      /* found a table. nexttab is where we will go next. */\n      break;\n\n    case 'a':\n      /* found an array. nexttab is the last table in the array. */\n      if (nextarr->kind != 't')\n        return e_internal(ctx, FLINE);\n\n      if (nextarr->nitem == 0)\n        return e_internal(ctx, FLINE);\n\n      nexttab = nextarr->item[nextarr->nitem - 1].tab;\n      break;\n\n    case 'v':\n      return e_keyexists(ctx, ctx->tpath.tok[i].lineno);\n\n    default: { /* Not found. Let's create an implicit table. */\n      int n = curtab->ntab;\n      toml_table_t **base =\n          (toml_table_t **)expand_ptrarr((void **)curtab->tab, n);\n      if (0 == base)\n        return e_outofmemory(ctx, FLINE);\n\n      curtab->tab = base;\n\n      if (0 == (base[n] = (toml_table_t *)CALLOC(1, sizeof(*base[n]))))\n        return e_outofmemory(ctx, FLINE);\n\n      if (0 == (base[n]->key = STRDUP(key)))\n        return e_outofmemory(ctx, FLINE);\n\n      nexttab = curtab->tab[curtab->ntab++];\n\n      /* tabs created by walk_tabpath are considered implicit */\n      nexttab->implicit = true;\n    } break;\n    }\n\n    /* switch to next tab */\n    curtab = nexttab;\n  }\n\n  /* save it */\n  ctx->curtab = curtab;\n\n  return 0;\n}\n\n/* handle lines like [x.y.z] or [[x.y.z]] */\nstatic int parse_select(context_t *ctx) {\n  assert(ctx->tok.tok == LBRACKET);\n\n  /* true if [[ */\n  int llb = (ctx->tok.ptr + 1 < ctx->stop && ctx->tok.ptr[1] == '[');\n  /* need to detect '[[' on our own because next_token() will skip whitespace,\n     and '[ [' would be taken as '[[', which is wrong. */\n\n  /* eat [ or [[ */\n  if (eat_token(ctx, LBRACKET, 1, FLINE))\n    return -1;\n  if (llb) {\n    assert(ctx->tok.tok == LBRACKET);\n    if (eat_token(ctx, LBRACKET, 1, FLINE))\n      return -1;\n  }\n\n  if (fill_tabpath(ctx))\n    return -1;\n\n  /* For [x.y.z] or [[x.y.z]], remove z from tpath.\n   */\n  token_t z = ctx->tpath.tok[ctx->tpath.top - 1];\n  xfree(ctx->tpath.key[ctx->tpath.top - 1]);\n  ctx->tpath.top--;\n\n  /* set up ctx->curtab */\n  if (walk_tabpath(ctx))\n    return -1;\n\n  if (!llb) {\n    /* [x.y.z] -> create z = {} in x.y */\n    toml_table_t *curtab = create_keytable_in_table(ctx, ctx->curtab, z);\n    if (!curtab)\n      return -1;\n    ctx->curtab = curtab;\n  } else {\n    /* [[x.y.z]] -> create z = [] in x.y */\n    toml_array_t *arr = 0;\n    {\n      char *zstr = normalize_key(ctx, z);\n      if (!zstr)\n        return -1;\n      arr = toml_array_in(ctx->curtab, zstr);\n      xfree(zstr);\n    }\n    if (!arr) {\n      arr = create_keyarray_in_table(ctx, ctx->curtab, z, 't');\n      if (!arr)\n        return -1;\n    }\n    if (arr->kind != 't')\n      return e_syntax(ctx, z.lineno, \"array mismatch\");\n\n    /* add to z[] */\n    toml_table_t *dest;\n    {\n      toml_table_t *t = create_table_in_array(ctx, arr);\n      if (!t)\n        return -1;\n\n      if (0 == (t->key = STRDUP(\"__anon__\")))\n        return e_outofmemory(ctx, FLINE);\n\n      dest = t;\n    }\n\n    ctx->curtab = dest;\n  }\n\n  if (ctx->tok.tok != RBRACKET) {\n    return e_syntax(ctx, ctx->tok.lineno, \"expects ]\");\n  }\n  if (llb) {\n    if (!(ctx->tok.ptr + 1 < ctx->stop && ctx->tok.ptr[1] == ']')) {\n      return e_syntax(ctx, ctx->tok.lineno, \"expects ]]\");\n    }\n    if (eat_token(ctx, RBRACKET, 1, FLINE))\n      return -1;\n  }\n\n  if (eat_token(ctx, RBRACKET, 1, FLINE))\n    return -1;\n\n  if (ctx->tok.tok != NEWLINE)\n    return e_syntax(ctx, ctx->tok.lineno, \"extra chars after ] or ]]\");\n\n  return 0;\n}\n\ntoml_table_t *toml_parse(char *conf, char *errbuf, int errbufsz) {\n  context_t ctx;\n\n  // clear errbuf\n  if (errbufsz <= 0)\n    errbufsz = 0;\n  if (errbufsz > 0)\n    errbuf[0] = 0;\n\n  // init context\n  memset(&ctx, 0, sizeof(ctx));\n  ctx.start = conf;\n  ctx.stop = ctx.start + strlen(conf);\n  ctx.errbuf = errbuf;\n  ctx.errbufsz = errbufsz;\n\n  // start with an artificial newline of length 0\n  ctx.tok.tok = NEWLINE;\n  ctx.tok.lineno = 1;\n  ctx.tok.ptr = conf;\n  ctx.tok.len = 0;\n\n  // make a root table\n  if (0 == (ctx.root = CALLOC(1, sizeof(*ctx.root)))) {\n    e_outofmemory(&ctx, FLINE);\n    // Do not goto fail, root table not set up yet\n    return 0;\n  }\n\n  // set root as default table\n  ctx.curtab = ctx.root;\n\n  /* Scan forward until EOF */\n  for (token_t tok = ctx.tok; !tok.eof; tok = ctx.tok) {\n    switch (tok.tok) {\n\n    case NEWLINE:\n      if (next_token(&ctx, 1))\n        goto fail;\n      break;\n\n    case STRING:\n      if (parse_keyval(&ctx, ctx.curtab))\n        goto fail;\n\n      if (ctx.tok.tok != NEWLINE) {\n        e_syntax(&ctx, ctx.tok.lineno, \"extra chars after value\");\n        goto fail;\n      }\n\n      if (eat_token(&ctx, NEWLINE, 1, FLINE))\n        goto fail;\n      break;\n\n    case LBRACKET: /* [ x.y.z ] or [[ x.y.z ]] */\n      if (parse_select(&ctx))\n        goto fail;\n      break;\n\n    default:\n      e_syntax(&ctx, tok.lineno, \"syntax error\");\n      goto fail;\n    }\n  }\n\n  /* success */\n  for (int i = 0; i < ctx.tpath.top; i++)\n    xfree(ctx.tpath.key[i]);\n  return ctx.root;\n\nfail:\n  // Something bad has happened. Free resources and return error.\n  for (int i = 0; i < ctx.tpath.top; i++)\n    xfree(ctx.tpath.key[i]);\n  toml_free(ctx.root);\n  return 0;\n}\n\ntoml_table_t *toml_parse_file(FILE *fp, char *errbuf, int errbufsz) {\n  int bufsz = 0;\n  char *buf = 0;\n  int off = 0;\n\n  /* read from fp into buf */\n  while (!feof(fp)) {\n\n    if (off == bufsz) {\n      int xsz = bufsz + 1000;\n      char *x = expand(buf, bufsz, xsz);\n      if (!x) {\n        snprintf(errbuf, errbufsz, \"out of memory\");\n        xfree(buf);\n        return 0;\n      }\n      buf = x;\n      bufsz = xsz;\n    }\n\n    errno = 0;\n    int n = fread(buf + off, 1, bufsz - off, fp);\n    if (ferror(fp)) {\n      snprintf(errbuf, errbufsz, \"%s\",\n               errno ? strerror(errno) : \"Error reading file\");\n      xfree(buf);\n      return 0;\n    }\n    off += n;\n  }\n\n  /* tag on a NUL to cap the string */\n  if (off == bufsz) {\n    int xsz = bufsz + 1;\n    char *x = expand(buf, bufsz, xsz);\n    if (!x) {\n      snprintf(errbuf, errbufsz, \"out of memory\");\n      xfree(buf);\n      return 0;\n    }\n    buf = x;\n    bufsz = xsz;\n  }\n  buf[off] = 0;\n\n  /* parse it, cleanup and finish */\n  toml_table_t *ret = toml_parse(buf, errbuf, errbufsz);\n  xfree(buf);\n  return ret;\n}\n\nstatic void xfree_kval(toml_keyval_t *p) {\n  if (!p)\n    return;\n  xfree(p->key);\n  xfree(p->val);\n  xfree(p);\n}\n\nstatic void xfree_tab(toml_table_t *p);\n\nstatic void xfree_arr(toml_array_t *p) {\n  if (!p)\n    return;\n\n  xfree(p->key);\n  const int n = p->nitem;\n  for (int i = 0; i < n; i++) {\n    toml_arritem_t *a = &p->item[i];\n    if (a->val)\n      xfree(a->val);\n    else if (a->arr)\n      xfree_arr(a->arr);\n    else if (a->tab)\n      xfree_tab(a->tab);\n  }\n  xfree(p->item);\n  xfree(p);\n}\n\nstatic void xfree_tab(toml_table_t *p) {\n  int i;\n\n  if (!p)\n    return;\n\n  xfree(p->key);\n\n  for (i = 0; i < p->nkval; i++)\n    xfree_kval(p->kval[i]);\n  xfree(p->kval);\n\n  for (i = 0; i < p->narr; i++)\n    xfree_arr(p->arr[i]);\n  xfree(p->arr);\n\n  for (i = 0; i < p->ntab; i++)\n    xfree_tab(p->tab[i]);\n  xfree(p->tab);\n\n  xfree(p);\n}\n\nvoid toml_free(toml_table_t *tab) { xfree_tab(tab); }\n\nstatic void set_token(context_t *ctx, tokentype_t tok, int lineno, char *ptr,\n                      int len) {\n  token_t t;\n  t.tok = tok;\n  t.lineno = lineno;\n  t.ptr = ptr;\n  t.len = len;\n  t.eof = 0;\n  ctx->tok = t;\n}\n\nstatic void set_eof(context_t *ctx, int lineno) {\n  set_token(ctx, NEWLINE, lineno, ctx->stop, 0);\n  ctx->tok.eof = 1;\n}\n\n/* Scan p for n digits compositing entirely of [0-9] */\nstatic int scan_digits(const char *p, int n) {\n  int ret = 0;\n  for (; n > 0 && isdigit(*p); n--, p++) {\n    ret = 10 * ret + (*p - '0');\n  }\n  return n ? -1 : ret;\n}\n\nstatic int scan_date(const char *p, int *YY, int *MM, int *DD) {\n  int year, month, day;\n  year = scan_digits(p, 4);\n  month = (year >= 0 && p[4] == '-') ? scan_digits(p + 5, 2) : -1;\n  day = (month >= 0 && p[7] == '-') ? scan_digits(p + 8, 2) : -1;\n  if (YY)\n    *YY = year;\n  if (MM)\n    *MM = month;\n  if (DD)\n    *DD = day;\n  return (year >= 0 && month >= 0 && day >= 0) ? 0 : -1;\n}\n\nstatic int scan_time(const char *p, int *hh, int *mm, int *ss) {\n  int hour, minute, second;\n  hour = scan_digits(p, 2);\n  minute = (hour >= 0 && p[2] == ':') ? scan_digits(p + 3, 2) : -1;\n  second = (minute >= 0 && p[5] == ':') ? scan_digits(p + 6, 2) : -1;\n  if (hh)\n    *hh = hour;\n  if (mm)\n    *mm = minute;\n  if (ss)\n    *ss = second;\n  return (hour >= 0 && minute >= 0 && second >= 0) ? 0 : -1;\n}\n\nstatic int scan_string(context_t *ctx, char *p, int lineno, int dotisspecial) {\n  char *orig = p;\n  if (0 == strncmp(p, \"'''\", 3)) {\n    char *q = p + 3;\n\n    while (1) {\n      q = strstr(q, \"'''\");\n      if (0 == q) {\n        return e_syntax(ctx, lineno, \"unterminated triple-s-quote\");\n      }\n      while (q[3] == '\\'')\n        q++;\n      break;\n    }\n\n    set_token(ctx, STRING, lineno, orig, q + 3 - orig);\n    return 0;\n  }\n\n  if (0 == strncmp(p, \"\\\"\\\"\\\"\", 3)) {\n    char *q = p + 3;\n\n    while (1) {\n      q = strstr(q, \"\\\"\\\"\\\"\");\n      if (0 == q) {\n        return e_syntax(ctx, lineno, \"unterminated triple-d-quote\");\n      }\n      if (q[-1] == '\\\\') {\n        q++;\n        continue;\n      }\n      while (q[3] == '\\\"')\n        q++;\n      break;\n    }\n\n    // the string is [p+3, q-1]\n\n    int hexreq = 0; /* #hex required */\n    int escape = 0;\n    for (p += 3; p < q; p++) {\n      if (escape) {\n        escape = 0;\n        if (strchr(\"btnfr\\\"\\\\\", *p))\n          continue;\n        if (*p == 'u') {\n          hexreq = 4;\n          continue;\n        }\n        if (*p == 'U') {\n          hexreq = 8;\n          continue;\n        }\n        if (p[strspn(p, \" \\t\\r\")] == '\\n')\n          continue; /* allow for line ending backslash */\n        return e_syntax(ctx, lineno, \"bad escape char\");\n      }\n      if (hexreq) {\n        hexreq--;\n        if (strchr(\"0123456789ABCDEF\", *p))\n          continue;\n        return e_syntax(ctx, lineno, \"expect hex char\");\n      }\n      if (*p == '\\\\') {\n        escape = 1;\n        continue;\n      }\n    }\n    if (escape)\n      return e_syntax(ctx, lineno, \"expect an escape char\");\n    if (hexreq)\n      return e_syntax(ctx, lineno, \"expected more hex char\");\n\n    set_token(ctx, STRING, lineno, orig, q + 3 - orig);\n    return 0;\n  }\n\n  if ('\\'' == *p) {\n    for (p++; *p && *p != '\\n' && *p != '\\''; p++)\n      ;\n    if (*p != '\\'') {\n      return e_syntax(ctx, lineno, \"unterminated s-quote\");\n    }\n\n    set_token(ctx, STRING, lineno, orig, p + 1 - orig);\n    return 0;\n  }\n\n  if ('\\\"' == *p) {\n    int hexreq = 0; /* #hex required */\n    int escape = 0;\n    for (p++; *p; p++) {\n      if (escape) {\n        escape = 0;\n        if (strchr(\"btnfr\\\"\\\\\", *p))\n          continue;\n        if (*p == 'u') {\n          hexreq = 4;\n          continue;\n        }\n        if (*p == 'U') {\n          hexreq = 8;\n          continue;\n        }\n        return e_syntax(ctx, lineno, \"bad escape char\");\n      }\n      if (hexreq) {\n        hexreq--;\n        if (strchr(\"0123456789ABCDEF\", *p))\n          continue;\n        return e_syntax(ctx, lineno, \"expect hex char\");\n      }\n      if (*p == '\\\\') {\n        escape = 1;\n        continue;\n      }\n      if (*p == '\\'') {\n        if (p[1] == '\\'' && p[2] == '\\'') {\n          return e_syntax(ctx, lineno, \"triple-s-quote inside string lit\");\n        }\n        continue;\n      }\n      if (*p == '\\n')\n        break;\n      if (*p == '\"')\n        break;\n    }\n    if (*p != '\"') {\n      return e_syntax(ctx, lineno, \"unterminated quote\");\n    }\n\n    set_token(ctx, STRING, lineno, orig, p + 1 - orig);\n    return 0;\n  }\n\n  /* check for timestamp without quotes */\n  if (0 == scan_date(p, 0, 0, 0) || 0 == scan_time(p, 0, 0, 0)) {\n    // forward thru the timestamp\n    p += strspn(p, \"0123456789.:+-Tt Zz\");\n    // squeeze out any spaces at end of string\n    for (; p[-1] == ' '; p--)\n      ;\n    // tokenize\n    set_token(ctx, STRING, lineno, orig, p - orig);\n    return 0;\n  }\n\n  /* literals */\n  for (; *p && *p != '\\n'; p++) {\n    int ch = *p;\n    if (ch == '.' && dotisspecial)\n      break;\n    if ('A' <= ch && ch <= 'Z')\n      continue;\n    if ('a' <= ch && ch <= 'z')\n      continue;\n    if (strchr(\"0123456789+-_.\", ch))\n      continue;\n    break;\n  }\n\n  set_token(ctx, STRING, lineno, orig, p - orig);\n  return 0;\n}\n\nstatic int next_token(context_t *ctx, int dotisspecial) {\n  int lineno = ctx->tok.lineno;\n  char *p = ctx->tok.ptr;\n  int i;\n\n  /* eat this tok */\n  for (i = 0; i < ctx->tok.len; i++) {\n    if (*p++ == '\\n')\n      lineno++;\n  }\n\n  /* make next tok */\n  while (p < ctx->stop) {\n    /* skip comment. stop just before the \\n. */\n    if (*p == '#') {\n      for (p++; p < ctx->stop && *p != '\\n'; p++)\n        ;\n      continue;\n    }\n\n    if (dotisspecial && *p == '.') {\n      set_token(ctx, DOT, lineno, p, 1);\n      return 0;\n    }\n\n    switch (*p) {\n    case ',':\n      set_token(ctx, COMMA, lineno, p, 1);\n      return 0;\n    case '=':\n      set_token(ctx, EQUAL, lineno, p, 1);\n      return 0;\n    case '{':\n      set_token(ctx, LBRACE, lineno, p, 1);\n      return 0;\n    case '}':\n      set_token(ctx, RBRACE, lineno, p, 1);\n      return 0;\n    case '[':\n      set_token(ctx, LBRACKET, lineno, p, 1);\n      return 0;\n    case ']':\n      set_token(ctx, RBRACKET, lineno, p, 1);\n      return 0;\n    case '\\n':\n      set_token(ctx, NEWLINE, lineno, p, 1);\n      return 0;\n    case '\\r':\n    case ' ':\n    case '\\t':\n      /* ignore white spaces */\n      p++;\n      continue;\n    }\n\n    return scan_string(ctx, p, lineno, dotisspecial);\n  }\n\n  set_eof(ctx, lineno);\n  return 0;\n}\n\nconst char *toml_key_in(const toml_table_t *tab, int keyidx) {\n  if (keyidx < tab->nkval)\n    return tab->kval[keyidx]->key;\n\n  keyidx -= tab->nkval;\n  if (keyidx < tab->narr)\n    return tab->arr[keyidx]->key;\n\n  keyidx -= tab->narr;\n  if (keyidx < tab->ntab)\n    return tab->tab[keyidx]->key;\n\n  return 0;\n}\n\nint toml_key_exists(const toml_table_t *tab, const char *key) {\n  int i;\n  for (i = 0; i < tab->nkval; i++) {\n    if (0 == strcmp(key, tab->kval[i]->key))\n      return 1;\n  }\n  for (i = 0; i < tab->narr; i++) {\n    if (0 == strcmp(key, tab->arr[i]->key))\n      return 1;\n  }\n  for (i = 0; i < tab->ntab; i++) {\n    if (0 == strcmp(key, tab->tab[i]->key))\n      return 1;\n  }\n  return 0;\n}\n\ntoml_raw_t toml_raw_in(const toml_table_t *tab, const char *key) {\n  int i;\n  for (i = 0; i < tab->nkval; i++) {\n    if (0 == strcmp(key, tab->kval[i]->key))\n      return tab->kval[i]->val;\n  }\n  return 0;\n}\n\ntoml_array_t *toml_array_in(const toml_table_t *tab, const char *key) {\n  int i;\n  for (i = 0; i < tab->narr; i++) {\n    if (0 == strcmp(key, tab->arr[i]->key))\n      return tab->arr[i];\n  }\n  return 0;\n}\n\ntoml_table_t *toml_table_in(const toml_table_t *tab, const char *key) {\n  int i;\n  for (i = 0; i < tab->ntab; i++) {\n    if (0 == strcmp(key, tab->tab[i]->key))\n      return tab->tab[i];\n  }\n  return 0;\n}\n\ntoml_raw_t toml_raw_at(const toml_array_t *arr, int idx) {\n  return (0 <= idx && idx < arr->nitem) ? arr->item[idx].val : 0;\n}\n\nchar toml_array_kind(const toml_array_t *arr) { return arr->kind; }\n\nchar toml_array_type(const toml_array_t *arr) {\n  if (arr->kind != 'v')\n    return 0;\n\n  if (arr->nitem == 0)\n    return 0;\n\n  return arr->type;\n}\n\nint toml_array_nelem(const toml_array_t *arr) { return arr->nitem; }\n\nconst char *toml_array_key(const toml_array_t *arr) {\n  return arr ? arr->key : (const char *)NULL;\n}\n\nint toml_table_nkval(const toml_table_t *tab) { return tab->nkval; }\n\nint toml_table_narr(const toml_table_t *tab) { return tab->narr; }\n\nint toml_table_ntab(const toml_table_t *tab) { return tab->ntab; }\n\nconst char *toml_table_key(const toml_table_t *tab) {\n  return tab ? tab->key : (const char *)NULL;\n}\n\ntoml_array_t *toml_array_at(const toml_array_t *arr, int idx) {\n  return (0 <= idx && idx < arr->nitem) ? arr->item[idx].arr : 0;\n}\n\ntoml_table_t *toml_table_at(const toml_array_t *arr, int idx) {\n  return (0 <= idx && idx < arr->nitem) ? arr->item[idx].tab : 0;\n}\n\nstatic int parse_millisec(const char *p, const char **endp);\n\nint toml_rtots(toml_raw_t src_, toml_timestamp_t *ret) {\n  if (!src_)\n    return -1;\n\n  const char *p = src_;\n  int must_parse_time = 0;\n\n  memset(ret, 0, sizeof(*ret));\n\n  int *year = &ret->__buffer.year;\n  int *month = &ret->__buffer.month;\n  int *day = &ret->__buffer.day;\n  int *hour = &ret->__buffer.hour;\n  int *minute = &ret->__buffer.minute;\n  int *second = &ret->__buffer.second;\n  int *millisec = &ret->__buffer.millisec;\n\n  /* parse date YYYY-MM-DD */\n  if (0 == scan_date(p, year, month, day)) {\n    ret->year = year;\n    ret->month = month;\n    ret->day = day;\n\n    p += 10;\n    if (*p) {\n      // parse the T or space separator\n      if (*p != 'T' && *p != 't' && *p != ' ')\n        return -1;\n      must_parse_time = 1;\n      p++;\n    }\n  }\n\n  /* parse time HH:MM:SS */\n  if (0 == scan_time(p, hour, minute, second)) {\n    ret->hour = hour;\n    ret->minute = minute;\n    ret->second = second;\n\n    /* optionally, parse millisec */\n    p += 8;\n    if (*p == '.') {\n      p++; /* skip '.' */\n      const char *qq;\n      *millisec = parse_millisec(p, &qq);\n      ret->millisec = millisec;\n      p = qq;\n    }\n\n    if (*p) {\n      /* parse and copy Z */\n      char *z = ret->__buffer.z;\n      ret->z = z;\n      if (*p == 'Z' || *p == 'z') {\n        *z++ = 'Z';\n        p++;\n        *z = 0;\n\n      } else if (*p == '+' || *p == '-') {\n        *z++ = *p++;\n\n        if (!(isdigit(p[0]) && isdigit(p[1])))\n          return -1;\n        *z++ = *p++;\n        *z++ = *p++;\n\n        if (*p == ':') {\n          *z++ = *p++;\n\n          if (!(isdigit(p[0]) && isdigit(p[1])))\n            return -1;\n          *z++ = *p++;\n          *z++ = *p++;\n        }\n\n        *z = 0;\n      }\n    }\n  }\n  if (*p != 0)\n    return -1;\n\n  if (must_parse_time && !ret->hour)\n    return -1;\n\n  return 0;\n}\n\n/* Raw to boolean */\nint toml_rtob(toml_raw_t src, int *ret_) {\n  if (!src)\n    return -1;\n  int dummy;\n  int *ret = ret_ ? ret_ : &dummy;\n\n  if (0 == strcmp(src, \"true\")) {\n    *ret = 1;\n    return 0;\n  }\n  if (0 == strcmp(src, \"false\")) {\n    *ret = 0;\n    return 0;\n  }\n  return -1;\n}\n\n/* Raw to integer */\nint toml_rtoi(toml_raw_t src, int64_t *ret_) {\n  if (!src)\n    return -1;\n\n  char buf[100];\n  char *p = buf;\n  char *q = p + sizeof(buf);\n  const char *s = src;\n  int base = 0;\n  int64_t dummy;\n  int64_t *ret = ret_ ? ret_ : &dummy;\n\n  /* allow +/- */\n  if (s[0] == '+' || s[0] == '-')\n    *p++ = *s++;\n\n  /* disallow +_100 */\n  if (s[0] == '_')\n    return -1;\n\n  /* if 0* ... */\n  if ('0' == s[0]) {\n    switch (s[1]) {\n    case 'x':\n      base = 16;\n      s += 2;\n      break;\n    case 'o':\n      base = 8;\n      s += 2;\n      break;\n    case 'b':\n      base = 2;\n      s += 2;\n      break;\n    case '\\0':\n      return *ret = 0, 0;\n    default:\n      /* ensure no other digits after it */\n      if (s[1])\n        return -1;\n    }\n  }\n\n  /* just strip underscores and pass to strtoll */\n  while (*s && p < q) {\n    int ch = *s++;\n    if (ch == '_') {\n      // disallow '__'\n      if (s[0] == '_')\n        return -1;\n      // numbers cannot end with '_'\n      if (s[0] == '\\0')\n        return -1;\n      continue; /* skip _ */\n    }\n    *p++ = ch;\n  }\n\n  // if not at end-of-string or we ran out of buffer ...\n  if (*s || p == q)\n    return -1;\n\n  /* cap with NUL */\n  *p = 0;\n\n  /* Run strtoll on buf to get the integer */\n  char *endp;\n  errno = 0;\n  *ret = strtoll(buf, &endp, base);\n  return (errno || *endp) ? -1 : 0;\n}\n\nint toml_rtod_ex(toml_raw_t src, double *ret_, char *buf, int buflen) {\n  if (!src)\n    return -1;\n\n  char *p = buf;\n  char *q = p + buflen;\n  const char *s = src;\n  double dummy;\n  double *ret = ret_ ? ret_ : &dummy;\n\n  /* allow +/- */\n  if (s[0] == '+' || s[0] == '-')\n    *p++ = *s++;\n\n  /* disallow +_1.00 */\n  if (s[0] == '_')\n    return -1;\n\n  /* decimal point, if used, must be surrounded by at least one digit on each\n   * side */\n  {\n    char *dot = strchr(s, '.');\n    if (dot) {\n      if (dot == s || !isdigit(dot[-1]) || !isdigit(dot[1]))\n        return -1;\n    }\n  }\n\n  /* zero must be followed by . or 'e', or NUL */\n  if (s[0] == '0' && s[1] && !strchr(\"eE.\", s[1]))\n    return -1;\n\n  /* just strip underscores and pass to strtod */\n  while (*s && p < q) {\n    int ch = *s++;\n    if (ch == '_') {\n      // disallow '__'\n      if (s[0] == '_')\n        return -1;\n      // disallow last char '_'\n      if (s[0] == 0)\n        return -1;\n      continue; /* skip _ */\n    }\n    *p++ = ch;\n  }\n  if (*s || p == q)\n    return -1; /* reached end of string or buffer is full? */\n\n  /* cap with NUL */\n  *p = 0;\n\n  /* Run strtod on buf to get the value */\n  char *endp;\n  errno = 0;\n  *ret = strtod(buf, &endp);\n  return (errno || *endp) ? -1 : 0;\n}\n\nint toml_rtod(toml_raw_t src, double *ret_) {\n  char buf[100];\n  return toml_rtod_ex(src, ret_, buf, sizeof(buf));\n}\n\nint toml_rtos(toml_raw_t src, char **ret) {\n  int multiline = 0;\n  const char *sp;\n  const char *sq;\n\n  *ret = 0;\n  if (!src)\n    return -1;\n\n  // for strings, first char must be a s-quote or d-quote\n  int qchar = src[0];\n  int srclen = strlen(src);\n  if (!(qchar == '\\'' || qchar == '\"')) {\n    return -1;\n  }\n\n  // triple quotes?\n  if (qchar == src[1] && qchar == src[2]) {\n    multiline = 1;         // triple-quote implies multiline\n    sp = src + 3;          // first char after quote\n    sq = src + srclen - 3; // first char of ending quote\n\n    if (!(sp <= sq && sq[0] == qchar && sq[1] == qchar && sq[2] == qchar)) {\n      // last 3 chars in src must be qchar\n      return -1;\n    }\n\n    /* skip new line immediate after qchar */\n    if (sp[0] == '\\n')\n      sp++;\n    else if (sp[0] == '\\r' && sp[1] == '\\n')\n      sp += 2;\n\n  } else {\n    sp = src + 1;          // first char after quote\n    sq = src + srclen - 1; // ending quote\n    if (!(sp <= sq && *sq == qchar)) {\n      /* last char in src must be qchar */\n      return -1;\n    }\n  }\n\n  // at this point:\n  //     sp points to first valid char after quote.\n  //     sq points to one char beyond last valid char.\n  //     string len is (sq - sp).\n  if (qchar == '\\'') {\n    *ret = norm_lit_str(sp, sq - sp, multiline, 0, 0);\n  } else {\n    *ret = norm_basic_str(sp, sq - sp, multiline, 0, 0);\n  }\n\n  return *ret ? 0 : -1;\n}\n\ntoml_datum_t toml_string_at(const toml_array_t *arr, int idx) {\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  ret.ok = (0 == toml_rtos(toml_raw_at(arr, idx), &ret.u.s));\n  return ret;\n}\n\ntoml_datum_t toml_bool_at(const toml_array_t *arr, int idx) {\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  ret.ok = (0 == toml_rtob(toml_raw_at(arr, idx), &ret.u.b));\n  return ret;\n}\n\ntoml_datum_t toml_int_at(const toml_array_t *arr, int idx) {\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  ret.ok = (0 == toml_rtoi(toml_raw_at(arr, idx), &ret.u.i));\n  return ret;\n}\n\ntoml_datum_t toml_double_at(const toml_array_t *arr, int idx) {\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  ret.ok = (0 == toml_rtod(toml_raw_at(arr, idx), &ret.u.d));\n  return ret;\n}\n\ntoml_datum_t toml_timestamp_at(const toml_array_t *arr, int idx) {\n  toml_timestamp_t ts;\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  ret.ok = (0 == toml_rtots(toml_raw_at(arr, idx), &ts));\n  if (ret.ok) {\n    ret.ok = !!(ret.u.ts = MALLOC(sizeof(*ret.u.ts)));\n    if (ret.ok) {\n      *ret.u.ts = ts;\n      if (ret.u.ts->year)\n        ret.u.ts->year = &ret.u.ts->__buffer.year;\n      if (ret.u.ts->month)\n        ret.u.ts->month = &ret.u.ts->__buffer.month;\n      if (ret.u.ts->day)\n        ret.u.ts->day = &ret.u.ts->__buffer.day;\n      if (ret.u.ts->hour)\n        ret.u.ts->hour = &ret.u.ts->__buffer.hour;\n      if (ret.u.ts->minute)\n        ret.u.ts->minute = &ret.u.ts->__buffer.minute;\n      if (ret.u.ts->second)\n        ret.u.ts->second = &ret.u.ts->__buffer.second;\n      if (ret.u.ts->millisec)\n        ret.u.ts->millisec = &ret.u.ts->__buffer.millisec;\n      if (ret.u.ts->z)\n        ret.u.ts->z = ret.u.ts->__buffer.z;\n    }\n  }\n  return ret;\n}\n\ntoml_datum_t toml_string_in(const toml_table_t *arr, const char *key) {\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  toml_raw_t raw = toml_raw_in(arr, key);\n  if (raw) {\n    ret.ok = (0 == toml_rtos(raw, &ret.u.s));\n  }\n  return ret;\n}\n\ntoml_datum_t toml_bool_in(const toml_table_t *arr, const char *key) {\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  ret.ok = (0 == toml_rtob(toml_raw_in(arr, key), &ret.u.b));\n  return ret;\n}\n\ntoml_datum_t toml_int_in(const toml_table_t *arr, const char *key) {\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  ret.ok = (0 == toml_rtoi(toml_raw_in(arr, key), &ret.u.i));\n  return ret;\n}\n\ntoml_datum_t toml_double_in(const toml_table_t *arr, const char *key) {\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  ret.ok = (0 == toml_rtod(toml_raw_in(arr, key), &ret.u.d));\n  return ret;\n}\n\ntoml_datum_t toml_timestamp_in(const toml_table_t *arr, const char *key) {\n  toml_timestamp_t ts;\n  toml_datum_t ret;\n  memset(&ret, 0, sizeof(ret));\n  ret.ok = (0 == toml_rtots(toml_raw_in(arr, key), &ts));\n  if (ret.ok) {\n    ret.ok = !!(ret.u.ts = MALLOC(sizeof(*ret.u.ts)));\n    if (ret.ok) {\n      *ret.u.ts = ts;\n      if (ret.u.ts->year)\n        ret.u.ts->year = &ret.u.ts->__buffer.year;\n      if (ret.u.ts->month)\n        ret.u.ts->month = &ret.u.ts->__buffer.month;\n      if (ret.u.ts->day)\n        ret.u.ts->day = &ret.u.ts->__buffer.day;\n      if (ret.u.ts->hour)\n        ret.u.ts->hour = &ret.u.ts->__buffer.hour;\n      if (ret.u.ts->minute)\n        ret.u.ts->minute = &ret.u.ts->__buffer.minute;\n      if (ret.u.ts->second)\n        ret.u.ts->second = &ret.u.ts->__buffer.second;\n      if (ret.u.ts->millisec)\n        ret.u.ts->millisec = &ret.u.ts->__buffer.millisec;\n      if (ret.u.ts->z)\n        ret.u.ts->z = ret.u.ts->__buffer.z;\n    }\n  }\n  return ret;\n}\n\nstatic int parse_millisec(const char *p, const char **endp) {\n  int ret = 0;\n  int unit = 100; /* unit in millisec */\n  for (; '0' <= *p && *p <= '9'; p++, unit /= 10) {\n    ret += (*p - '0') * unit;\n  }\n  *endp = p;\n  return ret;\n}\n"
  },
  {
    "path": "third_party/tomlc99/toml.h",
    "content": "/*\n  MIT License\n\n  Copyright (c) CK Tan\n  https://github.com/cktan/tomlc99\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n\n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n  SOFTWARE.\n*/\n#ifndef TOML_H\n#define TOML_H\n\n#ifdef _MSC_VER\n#pragma warning(disable : 4996)\n#endif\n\n#include <stdint.h>\n#include <stdio.h>\n\n#ifdef __cplusplus\n#define TOML_EXTERN extern \"C\"\n#else\n#define TOML_EXTERN extern\n#endif\n\ntypedef struct toml_timestamp_t toml_timestamp_t;\ntypedef struct toml_table_t toml_table_t;\ntypedef struct toml_array_t toml_array_t;\ntypedef struct toml_datum_t toml_datum_t;\n\n/* Parse a file. Return a table on success, or 0 otherwise.\n * Caller must toml_free(the-return-value) after use.\n */\nTOML_EXTERN toml_table_t *toml_parse_file(FILE *fp, char *errbuf, int errbufsz);\n\n/* Parse a string containing the full config.\n * Return a table on success, or 0 otherwise.\n * Caller must toml_free(the-return-value) after use.\n */\nTOML_EXTERN toml_table_t *toml_parse(char *conf, /* NUL terminated, please. */\n                                     char *errbuf, int errbufsz);\n\n/* Free the table returned by toml_parse() or toml_parse_file(). Once\n * this function is called, any handles accessed through this tab\n * directly or indirectly are no longer valid.\n */\nTOML_EXTERN void toml_free(toml_table_t *tab);\n\n/* Timestamp types. The year, month, day, hour, minute, second, z\n * fields may be NULL if they are not relevant. e.g. In a DATE\n * type, the hour, minute, second and z fields will be NULLs.\n */\nstruct toml_timestamp_t {\n  struct { /* internal. do not use. */\n    int year, month, day;\n    int hour, minute, second, millisec;\n    char z[10];\n  } __buffer;\n  int *year, *month, *day;\n  int *hour, *minute, *second, *millisec;\n  char *z;\n};\n\n/*-----------------------------------------------------------------\n *  Enhanced access methods\n */\nstruct toml_datum_t {\n  int ok;\n  union {\n    toml_timestamp_t *ts; /* ts must be freed after use */\n    char *s;              /* string value. s must be freed after use */\n    int b;                /* bool value */\n    int64_t i;            /* int value */\n    double d;             /* double value */\n  } u;\n};\n\n/* on arrays: */\n/* ... retrieve size of array. */\nTOML_EXTERN int toml_array_nelem(const toml_array_t *arr);\n/* ... retrieve values using index. */\nTOML_EXTERN toml_datum_t toml_string_at(const toml_array_t *arr, int idx);\nTOML_EXTERN toml_datum_t toml_bool_at(const toml_array_t *arr, int idx);\nTOML_EXTERN toml_datum_t toml_int_at(const toml_array_t *arr, int idx);\nTOML_EXTERN toml_datum_t toml_double_at(const toml_array_t *arr, int idx);\nTOML_EXTERN toml_datum_t toml_timestamp_at(const toml_array_t *arr, int idx);\n/* ... retrieve array or table using index. */\nTOML_EXTERN toml_array_t *toml_array_at(const toml_array_t *arr, int idx);\nTOML_EXTERN toml_table_t *toml_table_at(const toml_array_t *arr, int idx);\n\n/* on tables: */\n/* ... retrieve the key in table at keyidx. Return 0 if out of range. */\nTOML_EXTERN const char *toml_key_in(const toml_table_t *tab, int keyidx);\n/* ... returns 1 if key exists in tab, 0 otherwise */\nTOML_EXTERN int toml_key_exists(const toml_table_t *tab, const char *key);\n/* ... retrieve values using key. */\nTOML_EXTERN toml_datum_t toml_string_in(const toml_table_t *arr,\n                                        const char *key);\nTOML_EXTERN toml_datum_t toml_bool_in(const toml_table_t *arr, const char *key);\nTOML_EXTERN toml_datum_t toml_int_in(const toml_table_t *arr, const char *key);\nTOML_EXTERN toml_datum_t toml_double_in(const toml_table_t *arr,\n                                        const char *key);\nTOML_EXTERN toml_datum_t toml_timestamp_in(const toml_table_t *arr,\n                                           const char *key);\n/* .. retrieve array or table using key. */\nTOML_EXTERN toml_array_t *toml_array_in(const toml_table_t *tab,\n                                        const char *key);\nTOML_EXTERN toml_table_t *toml_table_in(const toml_table_t *tab,\n                                        const char *key);\n\n/*-----------------------------------------------------------------\n * lesser used\n */\n/* Return the array kind: 't'able, 'a'rray, 'v'alue, 'm'ixed */\nTOML_EXTERN char toml_array_kind(const toml_array_t *arr);\n\n/* For array kind 'v'alue, return the type of values\n   i:int, d:double, b:bool, s:string, t:time, D:date, T:timestamp, 'm'ixed\n   0 if unknown\n*/\nTOML_EXTERN char toml_array_type(const toml_array_t *arr);\n\n/* Return the key of an array */\nTOML_EXTERN const char *toml_array_key(const toml_array_t *arr);\n\n/* Return the number of key-values in a table */\nTOML_EXTERN int toml_table_nkval(const toml_table_t *tab);\n\n/* Return the number of arrays in a table */\nTOML_EXTERN int toml_table_narr(const toml_table_t *tab);\n\n/* Return the number of sub-tables in a table */\nTOML_EXTERN int toml_table_ntab(const toml_table_t *tab);\n\n/* Return the key of a table*/\nTOML_EXTERN const char *toml_table_key(const toml_table_t *tab);\n\n/*--------------------------------------------------------------\n * misc\n */\nTOML_EXTERN int toml_utf8_to_ucs(const char *orig, int len, int64_t *ret);\nTOML_EXTERN int toml_ucs_to_utf8(int64_t code, char buf[6]);\nTOML_EXTERN void toml_set_memutil(void *(*xxmalloc)(size_t),\n                                  void (*xxfree)(void *));\n\n/*--------------------------------------------------------------\n *  deprecated\n */\n/* A raw value, must be processed by toml_rto* before using. */\ntypedef const char *toml_raw_t;\nTOML_EXTERN toml_raw_t toml_raw_in(const toml_table_t *tab, const char *key);\nTOML_EXTERN toml_raw_t toml_raw_at(const toml_array_t *arr, int idx);\nTOML_EXTERN int toml_rtos(toml_raw_t s, char **ret);\nTOML_EXTERN int toml_rtob(toml_raw_t s, int *ret);\nTOML_EXTERN int toml_rtoi(toml_raw_t s, int64_t *ret);\nTOML_EXTERN int toml_rtod(toml_raw_t s, double *ret);\nTOML_EXTERN int toml_rtod_ex(toml_raw_t s, double *ret, char *buf, int buflen);\nTOML_EXTERN int toml_rtots(toml_raw_t s, toml_timestamp_t *ret);\n\n#endif /* TOML_H */\n"
  },
  {
    "path": "third_party/tomlc99/toml_cat.c",
    "content": "/*\n  MIT License\n\n  Copyright (c) 2017 CK Tan\n  https://github.com/cktan/tomlc99\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n\n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n  SOFTWARE.\n*/\n\n#ifdef NDEBUG\n#undef NDEBUG\n#endif\n\n#include \"toml.h\"\n#include <assert.h>\n#include <ctype.h>\n#include <errno.h>\n#include <inttypes.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\ntypedef struct node_t node_t;\nstruct node_t {\n  const char *key;\n  toml_table_t *tab;\n};\n\nnode_t stack[20];\nint stacktop = 0;\nint indent = 0;\n\nstatic void prindent() {\n  for (int i = 0; i < indent; i++)\n    printf(\"  \");\n}\n\nstatic void print_string(const char *s) {\n  int ok = 1;\n  for (const char *p = s; *p && ok; p++) {\n    int ch = *p;\n    ok = isprint(ch) && ch != '\"' && ch != '\\\\';\n  }\n\n  if (ok) {\n    printf(\"\\\"%s\\\"\", s);\n    return;\n  }\n\n  int len = strlen(s);\n\n  printf(\"\\\"\");\n  for (; len; len--, s++) {\n    int ch = *s;\n    if (isprint(ch) && ch != '\"' && ch != '\\\\') {\n      putchar(ch);\n      continue;\n    }\n\n    switch (ch) {\n    case 0x8:\n      printf(\"\\\\b\");\n      continue;\n    case 0x9:\n      printf(\"\\\\t\");\n      continue;\n    case 0xa:\n      printf(\"\\\\n\");\n      continue;\n    case 0xc:\n      printf(\"\\\\f\");\n      continue;\n    case 0xd:\n      printf(\"\\\\r\");\n      continue;\n    case '\"':\n      printf(\"\\\\\\\"\");\n      continue;\n    case '\\\\':\n      printf(\"\\\\\\\\\");\n      continue;\n    default:\n      printf(\"\\\\0x%02x\", ch & 0xff);\n      continue;\n    }\n  }\n  printf(\"\\\"\");\n}\n\nstatic void print_array(toml_array_t *arr);\n\nstatic void print_timestamp(toml_datum_t d) {\n  if (d.u.ts->year) {\n    printf(\"%04d-%02d-%02d%s\", *d.u.ts->year, *d.u.ts->month, *d.u.ts->day,\n           d.u.ts->hour ? \"T\" : \"\");\n  }\n  if (d.u.ts->hour) {\n    printf(\"%02d:%02d:%02d\", *d.u.ts->hour, *d.u.ts->minute, *d.u.ts->second);\n    if (d.u.ts->millisec) {\n      printf(\".%03d\", *d.u.ts->millisec);\n    }\n    if (d.u.ts->z) {\n      printf(\"%s\", d.u.ts->z);\n    }\n  }\n}\n\nstatic void print_table(toml_table_t *curtab) {\n  toml_datum_t d;\n  int i;\n  const char *key;\n  toml_array_t *arr;\n  toml_table_t *tab;\n\n  for (i = 0; 0 != (key = toml_key_in(curtab, i)); i++) {\n\n    if (0 != (arr = toml_array_in(curtab, key))) {\n      prindent();\n      printf(\"%s = [\\n\", key);\n      indent++;\n      print_array(arr);\n      indent--;\n      prindent();\n      printf(\"],\\n\");\n      continue;\n    }\n\n    if (0 != (tab = toml_table_in(curtab, key))) {\n      stack[stacktop].key = key;\n      stack[stacktop].tab = tab;\n      stacktop++;\n      prindent();\n      printf(\"%s = {\\n\", key);\n      indent++;\n      print_table(tab);\n      indent--;\n      prindent();\n      printf(\"},\\n\");\n      stacktop--;\n      continue;\n    }\n\n    d = toml_string_in(curtab, key);\n    if (d.ok) {\n      prindent();\n      printf(\"%s = \", key);\n      print_string(d.u.s);\n      printf(\",\\n\");\n      free(d.u.s);\n      continue;\n    }\n\n    d = toml_bool_in(curtab, key);\n    if (d.ok) {\n      prindent();\n      printf(\"%s = %s,\\n\", key, d.u.b ? \"true\" : \"false\");\n      continue;\n    }\n\n    d = toml_int_in(curtab, key);\n    if (d.ok) {\n      prindent();\n      printf(\"%s = %\" PRId64 \",\\n\", key, d.u.i);\n      continue;\n    }\n\n    d = toml_double_in(curtab, key);\n    if (d.ok) {\n      prindent();\n      printf(\"%s = %f,\\n\", key, d.u.d);\n      continue;\n    }\n\n    d = toml_timestamp_in(curtab, key);\n    if (d.ok) {\n      prindent();\n      printf(\"%s = \", key);\n      print_timestamp(d);\n      printf(\",\\n\");\n      free(d.u.ts);\n      continue;\n    }\n\n    fflush(stdout);\n    fprintf(stderr, \"ERROR: unable to decode value in table\\n\");\n    exit(1);\n  }\n}\n\nstatic void print_array(toml_array_t *curarr) {\n  toml_datum_t d;\n  toml_array_t *arr;\n  toml_table_t *tab;\n  const int n = toml_array_nelem(curarr);\n\n  for (int i = 0; i < n; i++) {\n\n    if (0 != (arr = toml_array_at(curarr, i))) {\n      prindent();\n      printf(\"[\\n\");\n      indent++;\n      print_array(arr);\n      indent--;\n      prindent();\n      printf(\"],\\n\");\n      continue;\n    }\n\n    if (0 != (tab = toml_table_at(curarr, i))) {\n      prindent();\n      printf(\"{\\n\");\n      indent++;\n      print_table(tab);\n      indent--;\n      prindent();\n      printf(\"},\\n\");\n      continue;\n    }\n\n    d = toml_string_at(curarr, i);\n    if (d.ok) {\n      prindent();\n      print_string(d.u.s);\n      printf(\",\\n\");\n      free(d.u.s);\n      continue;\n    }\n\n    d = toml_bool_at(curarr, i);\n    if (d.ok) {\n      prindent();\n      printf(\"%s,\\n\", d.u.b ? \"true\" : \"false\");\n      continue;\n    }\n\n    d = toml_int_at(curarr, i);\n    if (d.ok) {\n      prindent();\n      printf(\"%\" PRId64 \",\\n\", d.u.i);\n      continue;\n    }\n\n    d = toml_double_at(curarr, i);\n    if (d.ok) {\n      prindent();\n      printf(\"%f,\\n\", d.u.d);\n      continue;\n    }\n\n    d = toml_timestamp_at(curarr, i);\n    if (d.ok) {\n      prindent();\n      print_timestamp(d);\n      printf(\",\\n\");\n      free(d.u.ts);\n      continue;\n    }\n\n    fflush(stdout);\n    fprintf(stderr, \"ERROR: unable to decode value in array\\n\");\n    exit(1);\n  }\n}\n\nstatic void cat(FILE *fp) {\n  char errbuf[200];\n\n  toml_table_t *tab = toml_parse_file(fp, errbuf, sizeof(errbuf));\n  if (!tab) {\n    fprintf(stderr, \"ERROR: %s\\n\", errbuf);\n    return;\n  }\n\n  stack[stacktop].tab = tab;\n  stack[stacktop].key = \"\";\n  stacktop++;\n  printf(\"{\\n\");\n  indent++;\n  print_table(tab);\n  indent--;\n  printf(\"}\\n\");\n  stacktop--;\n\n  toml_free(tab);\n}\n\nint main(int argc, const char *argv[]) {\n  int i;\n  if (argc == 1) {\n    cat(stdin);\n  } else {\n    for (i = 1; i < argc; i++) {\n\n      FILE *fp = fopen(argv[i], \"r\");\n      if (!fp) {\n        fprintf(stderr, \"ERROR: cannot open %s: %s\\n\", argv[i],\n                strerror(errno));\n        exit(1);\n      }\n      cat(fp);\n      fclose(fp);\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "third_party/tomlc99/toml_json.c",
    "content": "/*\n  MIT License\n\n  Copyright (c) 2017 CK Tan\n  https://github.com/cktan/tomlc99\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n\n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n  SOFTWARE.\n*/\n#ifdef NDEBUG\n#undef NDEBUG\n#endif\n\n#include \"toml.h\"\n#include <assert.h>\n#include <errno.h>\n#include <inttypes.h>\n#include <stdlib.h>\n#include <string.h>\n\nstatic void print_escape_string(const char *s) {\n  for (; *s; s++) {\n    int ch = *s;\n    switch (ch) {\n    case '\\b':\n      printf(\"\\\\b\");\n      break;\n    case '\\t':\n      printf(\"\\\\t\");\n      break;\n    case '\\n':\n      printf(\"\\\\n\");\n      break;\n    case '\\f':\n      printf(\"\\\\f\");\n      break;\n    case '\\r':\n      printf(\"\\\\r\");\n      break;\n    case '\"':\n      printf(\"\\\\\\\"\");\n      break;\n    case '\\\\':\n      printf(\"\\\\\\\\\");\n      break;\n    default:\n      printf(\"%c\", ch);\n      break;\n    }\n  }\n}\n\nstatic void print_raw(const char *s) {\n  char *sval;\n  int64_t ival;\n  int bval;\n  double dval;\n  toml_timestamp_t ts;\n  char dbuf[100];\n\n  if (0 == toml_rtos(s, &sval)) {\n    printf(\"{\\\"type\\\":\\\"string\\\",\\\"value\\\":\\\"\");\n    print_escape_string(sval);\n    printf(\"\\\"}\");\n    free(sval);\n  } else if (0 == toml_rtoi(s, &ival)) {\n    printf(\"{\\\"type\\\":\\\"integer\\\",\\\"value\\\":\\\"%\" PRId64 \"\\\"}\", ival);\n  } else if (0 == toml_rtob(s, &bval)) {\n    printf(\"{\\\"type\\\":\\\"bool\\\",\\\"value\\\":\\\"%s\\\"}\", bval ? \"true\" : \"false\");\n  } else if (0 == toml_rtod_ex(s, &dval, dbuf, sizeof(dbuf))) {\n    printf(\"{\\\"type\\\":\\\"float\\\",\\\"value\\\":\\\"%s\\\"}\", dbuf);\n  } else if (0 == toml_rtots(s, &ts)) {\n    char millisec[10];\n    if (ts.millisec)\n      sprintf(millisec, \".%03d\", *ts.millisec);\n    else\n      millisec[0] = 0;\n    if (ts.year && ts.hour) {\n      printf(\"{\\\"type\\\":\\\"%s\\\",\\\"value\\\":\\\"%04d-%02d-%02dT%02d:%02d:%02d%\"\n             \"s%s\\\"}\",\n             (ts.z ? \"datetime\" : \"datetime-local\"),\n             *ts.year, *ts.month, *ts.day, *ts.hour, *ts.minute, *ts.second,\n             millisec, (ts.z ? ts.z : \"\"));\n    } else if (ts.year) {\n      printf(\"{\\\"type\\\":\\\"date-local\\\",\\\"value\\\":\\\"%04d-%02d-%02d\\\"}\", *ts.year,\n             *ts.month, *ts.day);\n    } else if (ts.hour) {\n      printf(\"{\\\"type\\\":\\\"time-local\\\",\\\"value\\\":\\\"%02d:%02d:%02d%s\\\"}\", *ts.hour,\n             *ts.minute, *ts.second, millisec);\n    }\n  } else {\n    fprintf(stderr, \"unknown type\\n\");\n    exit(1);\n  }\n}\n\nstatic void print_array(toml_array_t *arr);\nstatic void print_table(toml_table_t *curtab) {\n  int i;\n  const char *key;\n  const char *raw;\n  toml_array_t *arr;\n  toml_table_t *tab;\n\n  printf(\"{\");\n  for (i = 0; 0 != (key = toml_key_in(curtab, i)); i++) {\n\n    printf(\"%s\\\"\", i > 0 ? \",\" : \"\");\n    print_escape_string(key);\n    printf(\"\\\":\");\n\n    if (0 != (raw = toml_raw_in(curtab, key))) {\n      print_raw(raw);\n    } else if (0 != (arr = toml_array_in(curtab, key))) {\n      print_array(arr);\n    } else if (0 != (tab = toml_table_in(curtab, key))) {\n      print_table(tab);\n    } else {\n      abort();\n    }\n  }\n  printf(\"}\");\n}\n\nstatic void print_table_array(toml_array_t *curarr) {\n  int i;\n  toml_table_t *tab;\n\n  printf(\"[\");\n  for (i = 0; 0 != (tab = toml_table_at(curarr, i)); i++) {\n    printf(\"%s\", i > 0 ? \",\" : \"\");\n    print_table(tab);\n  }\n  printf(\"]\");\n}\n\nstatic void print_array(toml_array_t *curarr) {\n  if (toml_array_kind(curarr) == 't') {\n    print_table_array(curarr);\n    return;\n  }\n\n  printf(\"[\");\n\n  const char *raw;\n  toml_array_t *arr;\n  toml_table_t *tab;\n\n  const int n = toml_array_nelem(curarr);\n  for (int i = 0; i < n; i++) {\n    printf(\"%s\", i > 0 ? \",\" : \"\");\n\n    if (0 != (arr = toml_array_at(curarr, i))) {\n      print_array(arr);\n      continue;\n    }\n\n    if (0 != (tab = toml_table_at(curarr, i))) {\n      print_table(tab);\n      continue;\n    }\n\n    raw = toml_raw_at(curarr, i);\n    if (raw) {\n      print_raw(raw);\n      continue;\n    }\n\n    fflush(stdout);\n    fprintf(stderr, \"ERROR: unable to decode value in array\\n\");\n    exit(1);\n  }\n\n  printf(\"]\");\n}\n\nstatic void cat(FILE *fp) {\n  char errbuf[200];\n\n  toml_table_t *tab = toml_parse_file(fp, errbuf, sizeof(errbuf));\n  if (!tab) {\n    fprintf(stderr, \"ERROR: %s\\n\", errbuf);\n    exit(1);\n  }\n\n  print_table(tab);\n  printf(\"\\n\");\n\n  toml_free(tab);\n}\n\nint main(int argc, const char *argv[]) {\n  int i;\n  if (argc == 1) {\n    cat(stdin);\n  } else {\n    for (i = 1; i < argc; i++) {\n\n      FILE *fp = fopen(argv[i], \"r\");\n      if (!fp) {\n        fprintf(stderr, \"ERROR: cannot open %s: %s\\n\", argv[i],\n                strerror(errno));\n        exit(1);\n      }\n      cat(fp);\n      fclose(fp);\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "third_party/tomlc99/toml_sample.c",
    "content": "#include \"toml.h\"\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nstatic void fatal(const char *msg, const char *msg1) {\n  fprintf(stderr, \"ERROR: %s%s\\n\", msg, msg1 ? msg1 : \"\");\n  exit(1);\n}\n\nint main() {\n  FILE *fp;\n  char errbuf[200];\n\n  // 1. Read and parse toml file\n  fp = fopen(\"sample.toml\", \"r\");\n  if (!fp) {\n    fatal(\"cannot open sample.toml - \", strerror(errno));\n  }\n\n  toml_table_t *conf = toml_parse_file(fp, errbuf, sizeof(errbuf));\n  fclose(fp);\n\n  if (!conf) {\n    fatal(\"cannot parse - \", errbuf);\n  }\n\n  // 2. Traverse to a table.\n  toml_table_t *server = toml_table_in(conf, \"server\");\n  if (!server) {\n    fatal(\"missing [server]\", \"\");\n  }\n\n  // 3. Extract values\n  toml_datum_t host = toml_string_in(server, \"host\");\n  if (!host.ok) {\n    fatal(\"cannot read server.host\", \"\");\n  }\n\n  toml_array_t *portarray = toml_array_in(server, \"port\");\n  if (!portarray) {\n    fatal(\"cannot read server.port\", \"\");\n  }\n\n  printf(\"host: %s\\n\", host.u.s);\n  printf(\"port: \");\n  for (int i = 0;; i++) {\n    toml_datum_t port = toml_int_at(portarray, i);\n    if (!port.ok)\n      break;\n    printf(\"%d \", (int)port.u.i);\n  }\n  printf(\"\\n\");\n\n  // 4. Free memory\n  free(host.u.s);\n  toml_free(conf);\n  return 0;\n}\n"
  },
  {
    "path": "third_party/tomlc99/unittest/t1.c",
    "content": "#include \"../toml.h\"\n#include <assert.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <string.h>\n\nint main(int argc, const char *argv[]) {\n  char xxbuf[6], buf[6];\n  int64_t xxcode, code;\n  int xxsize;\n\n  xxsize = 2, xxcode = 0x80;\n  memcpy(xxbuf, \"\\xc2\\x80\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  xxsize = 2, xxcode = 0x7ff;\n  memcpy(xxbuf, \"\\xdf\\xbf\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  xxsize = 3, xxcode = 0x800;\n  memcpy(xxbuf, \"\\xe0\\xa0\\x80\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  xxsize = 3, xxcode = 0xfffd;\n  memcpy(xxbuf, \"\\xef\\xbf\\xbd\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  xxsize = 4, xxcode = 0x10000;\n  memcpy(xxbuf, \"\\xf0\\x90\\x80\\x80\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  xxsize = 4, xxcode = 0x1fffff;\n  memcpy(xxbuf, \"\\xf7\\xbf\\xbf\\xbf\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  xxsize = 5, xxcode = 0x200000;\n  memcpy(xxbuf, \"\\xf8\\x88\\x80\\x80\\x80\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  xxsize = 5, xxcode = 0x3ffffff;\n  memcpy(xxbuf, \"\\xfb\\xbf\\xbf\\xbf\\xbf\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  xxsize = 6, xxcode = 0x4000000;\n  memcpy(xxbuf, \"\\xfc\\x84\\x80\\x80\\x80\\x80\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  xxsize = 6, xxcode = 0x7fffffff;\n  memcpy(xxbuf, \"\\xfd\\xbf\\xbf\\xbf\\xbf\\xbf\", xxsize);\n  assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&\n         0 == memcmp(buf, xxbuf, xxsize));\n  assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);\n\n  return 0;\n}\n"
  },
  {
    "path": "tools/Makefile.am",
    "content": "\nSUBDIRS = \\\n  chkpriv \\\n  devel\n"
  },
  {
    "path": "tools/chkpriv/Makefile.am",
    "content": "xrdppkgdatadir=$(datadir)/xrdp\n\npkglibexec_PROGRAMS = \\\n  xrdp-droppriv\n\nnodist_xrdppkgdata_SCRIPTS = \\\n  xrdp-chkpriv\n\nAM_LDFLAGS = \n\nAM_CPPFLAGS = \\\n  -I$(top_srcdir)/common\n\nxrdp_droppriv_SOURCES = \\\n  xrdp-chkpriv.in \\\n  xrdp-droppriv.c\n\nxrdp_droppriv_LDADD = \\\n  $(top_builddir)/common/libcommon.la \\\n  $(DLOPEN_LIBS)\n\nSUBST_VARS = sed \\\n   -e 's|@pkglibexecdir[@]|$(pkglibexecdir)|g' \\\n   -e 's|@sysconfdir[@]|$(sysconfdir)|g' \\\n   -e 's|@sysconfsubdir[@]|$(sysconfsubdir)|g'\n\nsubst_verbose = $(subst_verbose_@AM_V@)\nsubst_verbose_ = $(subst_verbose_@AM_DEFAULT_V@)\nsubst_verbose_0 = @echo \"  SUBST    $@\";\n\nSUFFIXES = .in\n.in:\n\t$(subst_verbose)$(SUBST_VARS) $< > $@\n\nCLEANFILES = $(nodist_xrdppkgdata_SCRIPTS)\n\n"
  },
  {
    "path": "tools/chkpriv/xrdp-chkpriv.in",
    "content": "#!/bin/sh\n#\n# xrdp: A Remote Desktop Protocol server.\n#\n# Copyright (C) Jay Sorg and contributors 2004-2024\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n# Program to check permissions for xrdp when running in a non-privileged\n# mode\n\n# Change these if they do not match your installation\nCONF_DIR=@sysconfdir@/@sysconfsubdir@\nXRDP_INI=\"$CONF_DIR\"/xrdp.ini\nSESMAN_INI=\"$CONF_DIR\"/sesman.ini\nRSAKEYS_INI=\"$CONF_DIR\"/rsakeys.ini\nDROPPRIV=@pkglibexecdir@/xrdp-droppriv\n\n# Helper functions to print colored tag like \"[  OK  ]\"\n\nif [ -t 1 ]; then\n    print_ok()\n    {\n        printf \"\\033[1m[  \\033[1;32mOK\\033[0m  ]\\033[0m \"\n    }\n\n    print_warn()\n    {\n        printf \"\\033[1m[ \\033[1;33mWARN\\033[0m ]\\033[0m \"\n    }\n\n    print_ng()\n    {\n        printf \"\\033[1m[  \\033[1;31mNG\\033[0m  ]\\033[0m \"\n    }\nelse\n    print_ok()\n    {\n        printf \"[  OK  ] \"\n    }\n\n    print_warn()\n    {\n        printf \"[ WARN ] \"\n    }\n\n    print_ng()\n    {\n        printf \"[  NG  ] \"\n    }\nfi\n\n# -----------------------------------------------------------------------------\n# G E T   I N I   V A L U E\n#\n# Gets a value from an ini file.\n#\n# Params [ini_file] [key]\n# -----------------------------------------------------------------------------\nGetIniValue()\n{\n    # Look for a line matching 'key=' with optional whitespace\n    # either side of the key. When we find one, strip everything\n    # up to and including the first '=', print it, and quit\n    #\n    # This doesn't take sections into account\n    sed -n -e '/^ *'\"$2\"' *=/{\n        s/^[^=]*=//p\n        q\n    }' \"$1\"\n}\n\n# -----------------------------------------------------------------------------\n# M A I N\n# -----------------------------------------------------------------------------\n\nif [ \"$(id -u)\" != 0 ]; then\n    print_ng\n    echo \"** Must run this script as root\" >&2\n    exit 1\nfi\n\nOS=$(uname)\ncase \"$OS\" in\n    FreeBSD | Linux) ;;\n    *) echo \"Unsupported operating system $OS\" >&2\n       exit 1\nesac\n\nerrors=0\n\nruntime_user=$(GetIniValue \"$XRDP_INI\" runtime_user)\nruntime_group=$(GetIniValue \"$XRDP_INI\" runtime_group)\ncertificate=$(GetIniValue \"$XRDP_INI\" certificate)\nkey_file=$(GetIniValue \"$XRDP_INI\" key_file)\nSessionSockdirGroup=$(GetIniValue \"$SESMAN_INI\" SessionSockdirGroup)\n\ncase \"$certificate\" in\n    '') certificate=\"$CONF_DIR\"/cert.pem ;;\n    /*) ;;\n    *) certificate=\"$CONF_DIR\"/\"$certificate\"\nesac\n\ncase \"$key_file\" in\n    '') key_file=\"$CONF_DIR\"/key.pem ;;\n    /*) ;;\n    *) key_file=\"$CONF_DIR\"/\"$key_file\"\nesac\n\necho \"Settings\"\necho \" - [xrdp.ini]   runtime_user        : $runtime_user\"\necho \" - [xrdp.ini]   runtime_group       : $runtime_group\"\necho \" - [xrdp.ini]   certificate         : $certificate\"\necho \" - [xrdp.ini]   key_file            : $key_file\"\necho \" - [sesman.ini] SessionSockdirGroup : $SessionSockdirGroup\"\necho\n\n# Basic checks on runtime user/group\nif [ -z \"$runtime_user\" ] && [ -z \"$runtime_group\" ]; then\n    print_warn\n    echo \"This system is not configured to run xrdp without privilege\"\n    exit 0\nfi\n\nif [ -z \"$runtime_user\" ] || [ -z \"$runtime_group\" ]; then\n    print_ng\n    echo \"Both 'runtime_user' and 'runtime_group' must be set\"\n    errors=$(( errors + 1 ))\n    exit 1\nfi\n\nif getent passwd \"$runtime_user\" >/dev/null ; then\n    print_ok\n    echo \"runtime_user '$runtime_user' appears to exist\"\nelse\n    print_ng\n    echo \"runtime_user '$runtime_user' does not exist\"\n    errors=$(( errors + 1 ))\nfi\n\nGID=\nif getent group \"$runtime_group\" >/dev/null ; then\n    print_ok\n    echo \"runtime_group '$runtime_group' appears to exist\"\n    GID=$(getent group xrdp | cut -d: -f3)\nelse\n    print_ng\n    echo \"runtime_group '$runtime_group' does not exist\"\n    errors=$(( errors + 1 ))\nfi\n\n# Groups agree between sesman and xrdp?\nif [ -z \"$SessionSockdirGroup\" ] || [ \"$SessionSockdirGroup\"  = \"root\" ]; then\n    print_ok\n    echo \"sesman.ini is configured for secure connections to sesman sessions.\"\n\nelif [ \"$SessionSockdirGroup\"  = \"$runtime_group\" ]; then\n    print_ok\n    echo \"xrdp.ini and sesman.ini agree on group ownership\"\n    print_warn\n    echo \"consider setting SessionSockdirGroup = root for maximum security\"\n\nelse\n    print_ng\n    echo \"xrdp.ini and sesman.ini do not agree on group ownership\"\n    errors=$(( errors + 1 ))\nfi\n\n# Check we can access rsakeys.ini\n#\n# This is our file, so we can be completely prescriptive about\n# the permissions\nif [ -e $RSAKEYS_INI ]; then\n    # Only check if we have a GID\n    if [ -n \"$GID\" ]; then\n        # Get the permissions, UID and GID in $1..$3\n        case \"$OS\" in\n            FreeBSD)\n                # shellcheck disable=SC2046\n                set -- $(stat -f \"%Lp %u %g\" $RSAKEYS_INI)\n                ;;\n            *)\n                # shellcheck disable=SC2046\n                set -- $(stat -c \"%a %u %g\" $RSAKEYS_INI)\n        esac\n        if [ \"$1/$2/$3\" = \"640/0/$GID\" ]; then\n            print_ok\n            echo \"$RSAKEYS_INI has correct permissions\"\n        else\n            if [ \"$1\" != 640 ]; then\n                print_ng\n                echo \"$RSAKEYS_INI should have permissions  -rw-r-----\"\n                errors=$(( errors + 1 ))\n            fi\n            if [ \"$2\" != 0 ]; then\n                print_ng\n                echo \"$RSAKEYS_INI should be owned by root\"\n                errors=$(( errors + 1 ))\n            fi\n            if [ \"$3\" != \"$GID\" ]; then\n                print_ng\n                echo \"$RSAKEYS_INI should be in the $runtime_group group\"\n                errors=$(( errors + 1 ))\n            fi\n        fi\n    fi\nelse\n    print_ng\n    echo \"$RSAKEYS_INI does not exist\"\n    errors=$(( errors + 1 ))\nfi\n\n# Are cert and key readable (but NOT writeable) by the user?\n#\n# These aren't necessarily our files, so we can't be too prescriptive about\n# privileges.  On Debian for example, we might be using the 'ssl-cert'\n# group to obtain access to /etc/ssl/private/ssl-cert-snakeoil.key\nfor file in \"$certificate\" \"$key_file\"; do\n    if ! [ -e \"$file\" ]; then\n        print_ng\n        echo \"$file does not exist\"\n        errors=$(( errors + 1 ))\n    elif ! $DROPPRIV \"$runtime_user\" \"$runtime_group\" sh -c '[ -r '\"$file\"' ]'\n    then\n        print_ng\n        echo \"$file is not readable by $runtime_user:$runtime_group\"\n        errors=$(( errors + 1 ))\n    elif $DROPPRIV \"$runtime_user\" \"$runtime_group\" sh -c '[ -w '\"$file\"' ]'\n    then\n        print_ng\n        echo \"$file is writeable by $runtime_user:$runtime_group\"\n        errors=$(( errors + 1 ))\n    else\n        print_ok\n        echo \"$file is read-only for $runtime_user:$runtime_group\"\n    fi\ndone\n\necho\nif [ $errors -eq 0 ]; then\n    print_ok\n    echo \"-Summary- Permissions appear to be correct to run xrdp unprivileged\"\n    status=0\nelse\n    print_ng\n    echo \"-Summary- $errors error(s) found. Please correct these and try again\"\n    status=1\nfi\n\nexit $status\n"
  },
  {
    "path": "tools/chkpriv/xrdp-droppriv.c",
    "content": "/*\n *\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg and contributors 2004-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Shell around the g_drop_privileges() call\n */\n\n#if defined(HAVE_CONFIG_H)\n#include \"config_ac.h\"\n#endif\n\n#include \"os_calls.h\"\n#include \"log.h\"\n\nint main(int argc, char *argv[])\n{\n    struct log_config *logging;\n    int status = 1;\n    logging = log_config_init_for_console(LOG_LEVEL_WARNING,\n                                          g_getenv(\"DROPPRIV_LOG_LEVEL\"));\n    log_start_from_param(logging);\n    log_config_free(logging);\n\n    if (argc < 4)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Usage : %s [user] [group] [cmd...]\\n\", argv[0]);\n    }\n    else if (g_drop_privileges(argv[1], argv[2]) == 0)\n    {\n        status = g_execvp(argv[3], &argv[3]);\n    }\n\n    log_end();\n    return status;\n}\n"
  },
  {
    "path": "tools/devel/Makefile.am",
    "content": "\nEXTRA_DIST = \\\n  gtcp_proxy\n\nSUBDIRS = \\\n  tcp_proxy\n"
  },
  {
    "path": "tools/devel/gtcp_proxy/README.txt",
    "content": "\ngtcp-proxy is a 'man in the middle' program to monitor data flowing between\ntwo network connections.\n\n"
  },
  {
    "path": "tools/devel/gtcp_proxy/gtcp-proxy.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <gtk/gtk.h>\n#include <pthread.h>\n\n#include \"gtcp.h\"\n\n#define WINDOW_TITLE    \"Tcp Proxy Version 1.0\"\n#define CONTEXT_ID      1\n#define MSG_INFO        GTK_MESSAGE_INFO\n#define MSG_WARN        GTK_MESSAGE_WARNING\n#define MSG_ERROR       GTK_MESSAGE_ERROR\n#define MAIN_THREAD_YES 0\n#define MAIN_THREAD_NO  1\n\n/* globals */\npthread_t g_tid;\nint       g_keep_running   = 1;\nint       g_loc_io_count   = 0;  /* bytes read from local port  */\nint       g_rem_io_count   = 0;  /* bytes read from remote port */\n\nGtkWidget *g_btn_start;\nGtkWidget *g_tbx_loc_port;\nGtkWidget *g_tbx_rem_ip;\nGtkWidget *g_tbx_rem_port;\nGtkWidget *g_tbx_loc_stats;\nGtkWidget *g_tbx_rem_stats;\nGtkWidget *g_statusbar;\nGtkWidget *g_txtvu_loc_port;\nGtkWidget *g_txtvu_rem_port;\n\n/* forward declarations */\nstatic void *tcp_proxy(void *arg);\n\nstatic void show_msg(int not_main_thread, int style,\n                     const gchar *title, const gchar *msg);\n\nstatic void show_status(int not_main_thread, char *msg);\nstatic void clear_status(int not_main_thread);\nstatic void enable_btn_start(int main_thread);\nstatic void disable_btn_start(int main_thread);\n\n/* getters */\nstatic char *get_local_port();\nstatic char *get_remote_ip();\nstatic char *get_remote_port();\n\n/* setters */\nstatic void show_loc_port_stats(int main_thread, int count);\nstatic void show_rem_port_stats(int main_thread, int count);\n\n/* handlers */\nstatic gboolean on_delete_event(GtkWidget *widget, GdkEvent *ev, gpointer data);\nstatic void on_destroy(GtkWidget *widget, gpointer data);\nstatic void on_start_clicked(GtkWidget *widget, gpointer data);\nstatic void on_clear_clicked(GtkWidget *widget, gpointer data);\nstatic void on_quit_clicked(GtkWidget *widget, gpointer data);\n\nint main(int argc, char **argv)\n{\n    /* init threads */\n    g_thread_init(NULL);\n    gdk_threads_init();\n\n    /* setup GTK */\n    gtk_init(&argc, &argv);\n\n    /* create labels and right justify them */\n    GtkWidget *lbl_loc_port    = gtk_label_new(\"Local port\");\n    GtkWidget *lbl_rem_ip      = gtk_label_new(\"Remote IP\");\n    GtkWidget *lbl_rem_port    = gtk_label_new(\"Remote port\");\n    GtkWidget *lbl_loc_stats   = gtk_label_new(\"Local port recv stats\");\n    GtkWidget *lbl_rem_stats   = gtk_label_new(\"Remote port recv stats\");\n\n    gtk_misc_set_alignment(GTK_MISC(lbl_loc_port), 1.0, 0.5);\n    gtk_misc_set_alignment(GTK_MISC(lbl_rem_ip), 1.0, 0.5);\n    gtk_misc_set_alignment(GTK_MISC(lbl_rem_port), 1.0, 0.5);\n    gtk_misc_set_alignment(GTK_MISC(lbl_loc_stats), 1.0, 0.5);\n    gtk_misc_set_alignment(GTK_MISC(lbl_rem_stats), 1.0, 0.5);\n\n    /* create text boxes */\n    g_tbx_loc_port   = gtk_entry_new();\n    g_tbx_rem_ip     = gtk_entry_new();\n    g_tbx_rem_port   = gtk_entry_new();\n    g_tbx_loc_stats  = gtk_entry_new();\n    g_tbx_rem_stats  = gtk_entry_new();\n\n    /* stat text boxes are read only */\n    gtk_entry_set_editable(GTK_ENTRY(g_tbx_loc_stats), FALSE);\n    gtk_entry_set_editable(GTK_ENTRY(g_tbx_rem_stats), FALSE);\n\n    /* enable when debugging */\n#if 0\n    gtk_entry_set_text(GTK_ENTRY(g_tbx_loc_port), \"1234\");\n    gtk_entry_set_text(GTK_ENTRY(g_tbx_rem_ip), \"192.168.2.20\");\n    gtk_entry_set_text(GTK_ENTRY(g_tbx_rem_port), \"43222\");\n#endif\n\n    /* setup buttons inside a HBox */\n    g_btn_start          = gtk_button_new_with_label(\"Start listening\");\n    GtkWidget *btn_clear = gtk_button_new_with_label(\"Clear receive stats\");\n    GtkWidget *btn_quit  = gtk_button_new_with_label(\"Quit application\");\n\n    GtkWidget *hbox = gtk_hbox_new(FALSE, 5);\n    gtk_box_pack_start_defaults(GTK_BOX(hbox), g_btn_start);\n    gtk_box_pack_start_defaults(GTK_BOX(hbox), btn_clear);\n    gtk_box_pack_start_defaults(GTK_BOX(hbox), btn_quit);\n\n#if 0\n    g_txtvu_loc_port = gtk_text_view_new();\n    g_txtvu_rem_port = gtk_text_view_new();\n#endif\n\n    /* create table */\n    GtkWidget *table = gtk_table_new(8, 3, FALSE);\n\n    int row = 0;\n\n    /* insert labels into table */\n    gtk_table_attach(GTK_TABLE(table), lbl_loc_port, 0, 1, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n    gtk_table_attach(GTK_TABLE(table), lbl_rem_ip, 0, 1, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n    gtk_table_attach(GTK_TABLE(table), lbl_rem_port, 0, 1, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n    gtk_table_attach(GTK_TABLE(table), lbl_loc_stats, 0, 1, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n    gtk_table_attach(GTK_TABLE(table), lbl_rem_stats, 0, 1, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n    row = 0;\n\n    /* insert text boxes into table */\n    gtk_table_attach(GTK_TABLE(table), g_tbx_loc_port, 1, 2, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n    gtk_table_attach(GTK_TABLE(table), g_tbx_rem_ip, 1, 2, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n    gtk_table_attach(GTK_TABLE(table), g_tbx_rem_port, 1, 2, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n    gtk_table_attach(GTK_TABLE(table), g_tbx_loc_stats, 1, 2, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n    gtk_table_attach(GTK_TABLE(table), g_tbx_rem_stats, 1, 2, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n    row++;\n\n    /* insert hbox with buttons into table */\n    gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n\n#if 0\n    /* text view to display hexdumps */\n    gtk_table_attach(GTK_TABLE(table), g_txtvu_loc_port, 0, 2, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n    row++;\n#endif\n\n    /* status bar to display messages */\n    g_statusbar = gtk_statusbar_new();\n    gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(g_statusbar), TRUE);\n    gtk_table_attach(GTK_TABLE(table), g_statusbar, 0, 2, row, row + 1,\n                     GTK_FILL, GTK_FILL, 5, 0);\n\n    /* setup main window */\n    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);\n    gtk_container_set_border_width(GTK_CONTAINER(window), 5);\n    gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);\n    gtk_window_set_title(GTK_WINDOW(window), WINDOW_TITLE);\n    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);\n    gtk_window_set_resizable(GTK_WINDOW(window), FALSE);\n\n    gtk_container_add(GTK_CONTAINER(window), table);\n    gtk_widget_show_all(window);\n\n    /* setup callbacks */\n    g_signal_connect(window, \"delete-event\", G_CALLBACK(on_delete_event), NULL);\n    g_signal_connect(window, \"destroy\", G_CALLBACK(on_destroy), NULL);\n\n    g_signal_connect(g_btn_start, \"clicked\", G_CALLBACK(on_start_clicked), NULL);\n    g_signal_connect(btn_clear, \"clicked\", G_CALLBACK(on_clear_clicked), NULL);\n    g_signal_connect(btn_quit, \"clicked\", G_CALLBACK(on_quit_clicked), NULL);\n\n    gdk_threads_enter();\n    gtk_main();\n    gdk_threads_leave();\n\n    return 0;\n}\n\n/**\n * Start listening on specified local socket; when we get a connection,\n * connect to specified remote server and transfer data between local\n * and remote server\n *****************************************************************************/\n\nstatic void *tcp_proxy(void *arg)\n{\n    char buf[1024 * 32];\n\n    int lis_skt = -1;\n    int acc_skt = -1;\n    int con_skt = -1;\n    int sel     = 0;\n    int rv      = 0;\n    int i       = 0;\n    int count   = 0;\n    int sent    = 0;\n\n    /* create listener socket */\n    if ((lis_skt = tcp_socket_create()) < 0)\n    {\n        show_msg(MAIN_THREAD_NO, MSG_ERROR, \"Creating socket\",\n                 \"\\nOperation failed. System out of resources\");\n        enable_btn_start(MAIN_THREAD_NO);\n        return NULL;\n    }\n\n    /* place it in non blocking mode */\n    tcp_set_non_blocking(lis_skt);\n\n    if ((rv = tcp_bind(lis_skt, get_local_port())) != 0)\n    {\n        show_msg(MAIN_THREAD_NO, MSG_ERROR, \"Bind error\",\n                 \"\\nUnable to bind socket, cannot continue\");\n        tcp_close(lis_skt);\n        enable_btn_start(MAIN_THREAD_NO);\n        return NULL;\n    }\n\n    /* listen for incoming connection */\n    if (tcp_listen(lis_skt))\n    {\n        show_msg(MAIN_THREAD_NO, MSG_ERROR, \"Listen error\",\n                 \"\\nUnable to listen on socket, cannot continue\");\n        tcp_close(lis_skt);\n        enable_btn_start(MAIN_THREAD_NO);\n        return NULL;\n    }\n\n    show_status(MAIN_THREAD_NO, \"Waiting for client connections\");\n\n    /* accept incoming connection */\n    while (g_keep_running)\n    {\n        acc_skt = tcp_accept(lis_skt);\n        if (acc_skt > 0)\n        {\n            /* client connected */\n            show_status(MAIN_THREAD_NO, \"Client connected\");\n            tcp_close(lis_skt);\n            lis_skt = -1;\n            break;\n        }\n        if ((acc_skt < 0) && (tcp_last_error_would_block()))\n        {\n            /* no connection, try again */\n            usleep(250);\n            continue;\n        }\n        else\n        {\n            tcp_close(lis_skt);\n            lis_skt = -1;\n            enable_btn_start(MAIN_THREAD_NO);\n            return NULL;\n        }\n    }\n\n    /* we have a client connection, try connecting to server */\n    if ((con_skt = tcp_socket()) < 0)\n    {\n        show_msg(MAIN_THREAD_NO, MSG_ERROR, \"Creating socket\",\n                 \"\\nOperation failed. System out of resources\");\n        tcp_close(lis_skt);\n        tcp_close(acc_skt);\n        enable_btn_start(MAIN_THREAD_NO);\n        return NULL;\n    }\n\n    /* place it in non blocking mode */\n    tcp_set_non_blocking(con_skt);\n\n    rv = tcp_connect(con_skt, get_remote_ip(), get_remote_port());\n#if 0\n    if (rv < 0)\n    {\n        show_status(MAIN_THREAD_NO, \"Could not connect to server\");\n        tcp_close(lis_skt);\n        tcp_close(acc_skt);\n        enable_btn_start(MAIN_THREAD_NO);\n        return NULL;\n    }\n#endif\n\n    if ((rv < 0) && (tcp_last_error_would_block(con_skt)))\n    {\n        for (i = 0; i < 100; i++)\n        {\n            if (tcp_can_send(con_skt, 100))\n            {\n                break;\n            }\n\n            usleep(100);\n        }\n\n        if (i == 100)\n        {\n            show_status(MAIN_THREAD_NO, \"Could not connect to server\");\n            tcp_close(lis_skt);\n            tcp_close(acc_skt);\n            enable_btn_start(MAIN_THREAD_NO);\n            return NULL;\n        }\n    }\n\n    show_status(MAIN_THREAD_NO, \"Connected to server\");\n    rv = 0;\n\n    while (g_keep_running && rv == 0)\n    {\n        if ((sel = tcp_select(con_skt, acc_skt)) == 0)\n        {\n            usleep(10);\n            continue;\n        }\n\n        if (sel & 1)\n        {\n            /* can read from con_skt without blocking */\n            count = tcp_recv(con_skt, buf, 1024 * 16, 0);\n            rv = count < 1;\n\n            if (rv == 0)\n            {\n                g_loc_io_count += count;\n                show_loc_port_stats(MAIN_THREAD_NO, g_loc_io_count);\n\n                /* TODO: hexdump data here */\n\n                sent = 0;\n\n                while ((sent < count) && (rv == 0) && (g_keep_running))\n                {\n                    i = tcp_send(acc_skt, buf + sent, count - sent, 0);\n\n                    if ((i == -1) && tcp_last_error_would_block(acc_skt))\n                    {\n                        tcp_can_send(acc_skt, 1000);\n                    }\n                    else if (i < 1)\n                    {\n                        rv = 1;\n                    }\n                    else\n                    {\n                        sent += i;\n                    }\n                }\n            }\n        }\n\n        if (sel & 2)\n        {\n            /* can read from acc_skt without blocking */\n            count = tcp_recv(acc_skt, buf, 1024 * 16, 0);\n            rv = count < 1;\n\n            if (rv == 0)\n            {\n                g_rem_io_count += count;\n                show_rem_port_stats(MAIN_THREAD_NO, g_rem_io_count);\n\n                /* TODO: hexdump data here */\n\n                sent = 0;\n\n                while ((sent < count) && (rv == 0) && (g_keep_running))\n                {\n                    i = tcp_send(con_skt, buf + sent, count - sent, 0);\n\n                    if ((i == -1) && tcp_last_error_would_block(con_skt))\n                    {\n                        tcp_can_send(con_skt, 1000);\n                    }\n                    else if (i < 1)\n                    {\n                        rv = 1;\n                    }\n                    else\n                    {\n                        sent += i;\n                    }\n                }\n            }\n        }\n    }\n\n    tcp_close(lis_skt);\n    tcp_close(con_skt);\n    tcp_close(acc_skt);\n\n    show_status(MAIN_THREAD_NO, \"Connection closed\");\n    enable_btn_start(MAIN_THREAD_NO);\n    return NULL;\n}\n\n/**\n * Display a message using specified style dialog\n *\n * @param  style  information, warning or error\n * @param  title  text to be displayed in title bar\n * @param  msg    message to be displayed\n *****************************************************************************/\n\nstatic void show_msg(int not_main_window, int style,\n                     const gchar *title, const gchar *msg)\n{\n    GtkWidget *dialog;\n\n    if (not_main_window)\n    {\n        gdk_threads_enter();\n    }\n\n    dialog = gtk_message_dialog_new(GTK_WINDOW(NULL),\n                                    GTK_DIALOG_DESTROY_WITH_PARENT,\n                                    style,\n                                    GTK_BUTTONS_OK,\n                                    \"%s\", msg);\n\n    gtk_window_set_title(GTK_WINDOW(dialog), title);\n    gtk_dialog_run(GTK_DIALOG(dialog));\n    gtk_widget_destroy(dialog);\n\n    if (not_main_window)\n    {\n        gdk_threads_leave();\n    }\n}\n\n/**\n * Write message to status bar\n *****************************************************************************/\n\nstatic void show_status(int not_main_thread, char *msg)\n{\n    if (not_main_thread)\n    {\n        gdk_threads_enter();\n    }\n\n    gtk_statusbar_push(GTK_STATUSBAR(g_statusbar), CONTEXT_ID, msg);\n\n    if (not_main_thread)\n    {\n        gdk_threads_leave();\n    }\n}\n\n/**\n * Clear status bar\n *****************************************************************************/\n\nstatic void clear_status(int not_main_thread)\n{\n    if (not_main_thread)\n    {\n        gdk_threads_enter();\n    }\n\n    gtk_statusbar_remove_all(GTK_STATUSBAR(g_statusbar), CONTEXT_ID);\n\n    if (not_main_thread)\n    {\n        gdk_threads_leave();\n    }\n}\n\n/**\n * Enable 'Start Listening' button\n *****************************************************************************/\n\nstatic void enable_btn_start(int not_main_thread)\n{\n    if (not_main_thread)\n    {\n        gdk_threads_enter();\n    }\n\n    gtk_widget_set_sensitive(GTK_WIDGET(g_btn_start), TRUE);\n\n    if (not_main_thread)\n    {\n        gdk_threads_leave();\n    }\n}\n\n/**\n * Disable 'Start Listening' button\n *****************************************************************************/\n\nstatic void disable_btn_start(int not_main_thread)\n{\n    if (not_main_thread)\n    {\n        gdk_threads_enter();\n    }\n\n    gtk_widget_set_sensitive(GTK_WIDGET(g_btn_start), FALSE);\n\n    if (not_main_thread)\n    {\n        gdk_threads_leave();\n    }\n}\n\n/**\n * Return local port setting\n *****************************************************************************/\n\nstatic char *get_local_port()\n{\n    const char *cptr = gtk_entry_get_text(GTK_ENTRY(g_tbx_loc_port));\n    return (char *) cptr;\n}\n\n/**\n * Return remote IP setting\n *****************************************************************************/\n\nstatic char *get_remote_ip()\n{\n    const char *cptr = gtk_entry_get_text(GTK_ENTRY(g_tbx_rem_ip));\n    return (char *) cptr;\n}\n\n/**\n * Return remote port setting\n *****************************************************************************/\n\nstatic char *get_remote_port()\n{\n    const char *cptr = gtk_entry_get_text(GTK_ENTRY(g_tbx_rem_port));\n    return (char *) cptr;\n}\n\n/**\n * Update local port stat counter\n *****************************************************************************/\n\nstatic void show_loc_port_stats(int not_main_thread, int count)\n{\n    char buf[128];\n\n    sprintf(buf, \"%d\", count);\n\n    if (not_main_thread)\n    {\n        gdk_threads_enter();\n    }\n\n    gtk_entry_set_text(GTK_ENTRY(g_tbx_loc_stats), buf);\n\n    if (not_main_thread)\n    {\n        gdk_threads_leave();\n    }\n}\n\n/**\n * Update remote port stat counter\n *****************************************************************************/\n\nstatic void show_rem_port_stats(int not_main_thread, int count)\n{\n    char buf[128];\n\n    sprintf(buf, \"%d\", count);\n\n    if (not_main_thread)\n    {\n        gdk_threads_enter();\n    }\n\n    gtk_entry_set_text(GTK_ENTRY(g_tbx_rem_stats), buf);\n\n    if (not_main_thread)\n    {\n        gdk_threads_leave();\n    }\n}\n\n/**\n * User clicked on window close button\n *****************************************************************************/\n\nstatic gboolean on_delete_event(GtkWidget *widget, GdkEvent *ev, gpointer data)\n{\n    return FALSE;\n}\n\n/**\n * Close application\n *****************************************************************************/\n\nstatic void on_destroy(GtkWidget *widget, gpointer data)\n{\n    /* this will destroy all windows and return control to gtk_main() */\n    gtk_main_quit();\n}\n\n/**\n * Start a thread that listens for incoming connections\n *****************************************************************************/\n\nstatic void on_start_clicked(GtkWidget *widget, gpointer data)\n{\n    /* local port must be specified */\n    if (gtk_entry_get_text_length(GTK_ENTRY(g_tbx_loc_port)) == 0)\n    {\n        show_msg(MAIN_THREAD_YES, MSG_ERROR, \"Invalid entry\",\n                 \"\\nYou must enter a value for Local Port\");\n        return;\n    }\n\n    /* remote IP must be specified */\n    if (gtk_entry_get_text_length(GTK_ENTRY(g_tbx_rem_ip)) == 0)\n    {\n        show_msg(MAIN_THREAD_YES, MSG_ERROR, \"Invalid entry\",\n                 \"\\nYou must enter a value for Remote IP\");\n        return;\n    }\n\n    /* remote port must be specified */\n    if (gtk_entry_get_text_length(GTK_ENTRY(g_tbx_rem_port)) == 0)\n    {\n        show_msg(MAIN_THREAD_YES, MSG_ERROR, \"Invalid entry\",\n                 \"\\nYou must enter a value for Remote Port\");\n        return;\n    }\n\n    if (pthread_create(&g_tid, NULL, tcp_proxy, NULL))\n    {\n        show_msg(MAIN_THREAD_YES, MSG_ERROR, \"Starting listener\",\n                 \"\\nThread create error. System out of resources\");\n        return;\n    }\n\n    disable_btn_start(MAIN_THREAD_YES);\n}\n\n/**\n * Clear stat counters\n *****************************************************************************/\n\nstatic void on_clear_clicked(GtkWidget *widget, gpointer data)\n{\n    g_loc_io_count = 0;\n    g_rem_io_count = 0;\n    show_loc_port_stats(MAIN_THREAD_YES, g_loc_io_count);\n    show_rem_port_stats(MAIN_THREAD_YES, g_rem_io_count);\n}\n\n/**\n * Quit application\n *****************************************************************************/\n\nstatic void on_quit_clicked(GtkWidget *widget, gpointer data)\n{\n    /* this will destroy all windows and return control to gtk_main() */\n    gtk_main_quit();\n}\n"
  },
  {
    "path": "tools/devel/gtcp_proxy/gtcp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"gtcp.h\"\n\n/**\n * Return a newly created socket or -1 on error\n *****************************************************************************/\n\nint tcp_socket_create(void)\n{\n    int rv;\n    int option_value;\n    socklen_t option_len;\n\n    /* in win32 a socket is an unsigned int, in linux, it's an int */\n    if ((rv = (int) socket(PF_INET, SOCK_STREAM, 0)) < 0)\n    {\n        return -1;\n    }\n\n    option_len = sizeof(option_value);\n\n    if (getsockopt(rv, SOL_SOCKET, SO_REUSEADDR, (char *) &option_value,\n                   &option_len) == 0)\n    {\n        if (option_value == 0)\n        {\n            option_value = 1;\n            option_len = sizeof(option_value);\n            setsockopt(rv, SOL_SOCKET, SO_REUSEADDR, (char *) &option_value,\n                       option_len);\n        }\n    }\n\n    option_len = sizeof(option_value);\n\n    if (getsockopt(rv, SOL_SOCKET, SO_SNDBUF, (char *) &option_value,\n                   &option_len) == 0)\n    {\n        if (option_value < (1024 * 32))\n        {\n            option_value = 1024 * 32;\n            option_len = sizeof(option_value);\n            setsockopt(rv, SOL_SOCKET, SO_SNDBUF, (char *) &option_value,\n                       option_len);\n        }\n    }\n\n    return rv;\n}\n\n/**\n * Place specified socket in non blocking mode\n *****************************************************************************/\n\nvoid tcp_set_non_blocking(int skt)\n{\n    unsigned long i;\n\n#if defined(_WIN32)\n    i = 1;\n    ioctlsocket(skt, FIONBIO, &i);\n#else\n    i = fcntl(skt, F_GETFL);\n    i = i | O_NONBLOCK;\n    fcntl(skt, F_SETFL, i);\n#endif\n}\n\n/**\n * Assign name to socket\n *\n * @param  skt  the socket to bind\n * @param  port  the port to bind to\n *\n * @return 0 on success, -1 on error\n *****************************************************************************/\n\nint tcp_bind(int skt, char *port)\n{\n    struct sockaddr_in s;\n\n    memset(&s, 0, sizeof(struct sockaddr_in));\n    s.sin_family = AF_INET;\n    s.sin_port = htons((uint16_t) atoi(port));\n    s.sin_addr.s_addr = INADDR_ANY;\n\n    return bind(skt, (struct sockaddr *) &s, sizeof(struct sockaddr_in));\n}\n\n/**\n * Listen for incoming connections\n *\n * @param  skt  the socket to listen on\n *\n * @return 0 on success, -1 on error\n *****************************************************************************/\n\nint tcp_listen(int skt)\n{\n    return listen(skt, 2);\n}\n\n/**\n * Accept incoming connection\n *\n * @param  skt  socket to accept incoming connection on\n *\n * @return 0 on success, -1 on error\n *****************************************************************************/\n\nint tcp_accept(int skt)\n{\n    struct sockaddr_in s;\n    socklen_t i;\n\n    i = sizeof(struct sockaddr_in);\n    memset(&s, 0, i);\n    return accept(skt, (struct sockaddr *)&s, &i);\n}\n\n/**\n * Check if the socket would block\n *\n * @return TRUE if would block, else FALSE\n *****************************************************************************/\n\nint tcp_last_error_would_block()\n{\n#if defined(_WIN32)\n    return WSAGetLastError() == WSAEWOULDBLOCK;\n#else\n    return (errno == EWOULDBLOCK) || (errno == EAGAIN) || (errno == EINPROGRESS);\n#endif\n}\n\n/**\n * Close specified socket\n *****************************************************************************/\n\nvoid tcp_close(int skt)\n{\n    if (skt <= 0)\n    {\n        return;\n    }\n\n#if defined(_WIN32)\n    closesocket(skt);\n#else\n    close(skt);\n#endif\n}\n\n/**\n * Create a new socket\n *\n * @return new socket or -1 on error\n *****************************************************************************/\n\nint tcp_socket(void)\n{\n    int rv;\n    int option_value;\n    socklen_t option_len;\n\n    /* in win32 a socket is an unsigned int, in linux, it's an int */\n    if ((rv = (int) socket(PF_INET, SOCK_STREAM, 0)) < 0)\n    {\n        return -1;\n    }\n\n    option_len = sizeof(option_value);\n\n    if (getsockopt(rv, SOL_SOCKET, SO_REUSEADDR, (char *) &option_value,\n                   &option_len) == 0)\n    {\n        if (option_value == 0)\n        {\n            option_value = 1;\n            option_len = sizeof(option_value);\n            setsockopt(rv, SOL_SOCKET, SO_REUSEADDR, (char *) &option_value,\n                       option_len);\n        }\n    }\n\n    option_len = sizeof(option_value);\n\n    if (getsockopt(rv, SOL_SOCKET, SO_SNDBUF, (char *) &option_value,\n                   &option_len) == 0)\n    {\n        if (option_value < (1024 * 32))\n        {\n            option_value = 1024 * 32;\n            option_len = sizeof(option_value);\n            setsockopt(rv, SOL_SOCKET, SO_SNDBUF, (char *) &option_value,\n                       option_len);\n        }\n    }\n\n    return rv;\n}\n\n/**\n * Connect to a server\n *\n * @param  skt      opaque socket obj\n * @param  address  connect to this server\n * @param  port     using this port\n *\n * @return 0 on success, -1 on error\n *****************************************************************************/\n\nint tcp_connect(int skt, const char *hostname, const char *port)\n{\n    struct sockaddr_in  s;\n    struct hostent     *h;\n\n    memset(&s, 0, sizeof(struct sockaddr_in));\n    s.sin_family = AF_INET;\n    s.sin_port = htons((uint16_t) atoi(port));\n    s.sin_addr.s_addr = inet_addr(hostname);\n\n    if (s.sin_addr.s_addr == INADDR_NONE)\n    {\n        h = gethostbyname(hostname);\n\n        if (h != 0)\n        {\n            if (h->h_name != 0)\n            {\n                if (h->h_addr_list != 0)\n                {\n                    if ((*(h->h_addr_list)) != 0)\n                    {\n                        s.sin_addr.s_addr = *((int *)(*(h->h_addr_list)));\n                    }\n                }\n            }\n        }\n    }\n\n    return connect(skt, (struct sockaddr *) &s, sizeof(struct sockaddr_in));\n}\n\n/**\n * Return 1 if we can write to the socket, 0 otherwise\n *****************************************************************************/\n\nint tcp_can_send(int skt, int millis)\n{\n    int rv = 0;\n    if (skt > 0)\n    {\n        struct pollfd pollfd;\n\n        pollfd.fd = skt;\n        pollfd.events = POLLOUT;\n        pollfd.revents = 0;\n        if (poll(&pollfd, 1, millis) > 0)\n        {\n            if ((pollfd.revents & POLLOUT) != 0)\n            {\n                rv = 1;\n            }\n        }\n    }\n\n    return rv;\n}\n\n/**\n * Return 1 if socket is OK, 0 otherwise\n *****************************************************************************/\n\nint tcp_socket_ok(int skt)\n{\n    int opt;\n    socklen_t opt_len = sizeof(opt);\n\n    if (getsockopt(skt, SOL_SOCKET, SO_ERROR, (char *) (&opt), &opt_len) == 0)\n    {\n        if (opt == 0)\n        {\n            return 1;\n        }\n    }\n\n    return 0;\n}\n\n/**\n * Check if specified sockets can be operated on without blocking\n *\n * @return 1 if they can be operated on or 0 if blocking would occur\n *****************************************************************************/\n\nint tcp_select(int sck1, int sck2)\n{\n    struct pollfd pollfd[2] = {0};\n    int rvmask[2] = {0}; /* Output masks corresponding to fds in pollfd */\n\n    unsigned int i = 0;\n    int rv = 0;\n\n    if (sck1 > 0)\n    {\n        pollfd[i].fd = sck1;\n        pollfd[i].events = POLLIN;\n        rvmask[i] = 1;\n        ++i;\n    }\n\n    if (sck2 > 0)\n    {\n        pollfd[i].fd = sck2;\n        pollfd[i].events = POLLIN;\n        rvmask[i] = 2;\n        ++i;\n    }\n\n    if (poll(pollfd, i, 0) > 0)\n    {\n        if ((pollfd[0].revents & (POLLIN | POLLHUP)) != 0)\n        {\n            rv |= rvmask[0];\n        }\n\n        if ((pollfd[1].revents & (POLLIN | POLLHUP)) != 0)\n        {\n            rv |= rvmask[1];\n        }\n    }\n\n    return rv;\n}\n\nint tcp_recv(int skt, void *ptr, int len, int flags)\n{\n#if defined(_WIN32)\n    return recv(skt, (char *) ptr, len, flags);\n#else\n    return recv(skt, ptr, len, flags);\n#endif\n}\n\nint tcp_send(int skt, const void *ptr, int len, int flags)\n{\n#if defined(_WIN32)\n    return send(skt, (const char *)ptr, len, flags);\n#else\n    return send(skt, ptr, len, flags);\n#endif\n}\n"
  },
  {
    "path": "tools/devel/gtcp_proxy/gtcp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _GTCP_H\n#define _GTCP_H\n\n#include <stdint.h>\n#include <sys/types.h>\n#include <sys/socket.h>\n#include <errno.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include <string.h>\n#include <netinet/in.h>\n#include <netinet/tcp.h>\n#include <netdb.h>\n\nint  tcp_socket_create(void);\nvoid tcp_set_non_blocking(int skt);\nint  tcp_bind(int skt, char *port);\nint  tcp_listen(int skt);\nint  tcp_accept(int skt);\nint  tcp_last_error_would_block();\nvoid tcp_close(int skt);\nint  tcp_socket(void);\nint  tcp_connect(int skt, const char *hostname, const char *port);\nint  tcp_can_send(int skt, int millis);\nint  tcp_socket_ok(int skt);\nint  tcp_select(int sck1, int sck2);\nint  tcp_recv(int skt, void *ptr, int len, int flags);\nint  tcp_send(int skt, const void *ptr, int len, int flags);\n\n#endif\n"
  },
  {
    "path": "tools/devel/gtcp_proxy/hexdump.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdint.h>\n#include <string.h>\n\n/**\n * An optimized hexdump function\n *\n * @param  address  address to display in address column\n * @param  buf      data to hexdump\n * @param  len      number of bytes to dump\n *****************************************************************************/\n\nvoid hexdump(int address, char *buf, int len)\n{\n    uint32_t addr;\n    char     outbuf[80];\n    int      blocks;\n    int      residual;\n    int      i;\n    int      j;\n    int      buf_index;\n    int      index2;     /* data column    */\n    int      index3;     /* ascii column   */\n\n    unsigned char c;\n\n    const char cvt[] = {'0', '1', '2', '3', '4', '5', '6', '7',\n                        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'\n                       };\n\n    if ((buf == NULL) || (len <= 0))\n    {\n        return;\n    }\n\n    addr = (address < 0) ? 0 : address;\n    blocks = len / 16;\n    residual = len - blocks * 16;\n    buf_index = 0;\n\n    for (i = 0; i < blocks; i++)\n    {\n        index2 = 10;\n        index3 = 60;\n\n        outbuf[9] = ' ';\n        outbuf[8] = ' ';\n        outbuf[7] = cvt[(addr >>  0) & 0x0000000f];\n        outbuf[6] = cvt[(addr >>  4) & 0x0000000f];\n        outbuf[5] = cvt[(addr >>  8) & 0x0000000f];\n        outbuf[4] = cvt[(addr >> 12) & 0x0000000f];\n        outbuf[3] = cvt[(addr >> 16) & 0x0000000f];\n        outbuf[2] = cvt[(addr >> 20) & 0x0000000f];\n        outbuf[1] = cvt[(addr >> 24) & 0x0000000f];\n        outbuf[0] = cvt[(addr >> 28) & 0x0000000f];\n        addr += 16;\n\n        /* insert spaces */\n        outbuf[8] = ' ';\n        outbuf[9] = ' ';\n        outbuf[58] = ' ';\n        outbuf[59] = ' ';\n\n        for (j = 0; j < 16; j++)\n        {\n            c = buf[buf_index++];\n\n            outbuf[index2++] = cvt[(c >> 4) & 0x0f];\n            outbuf[index2++] = cvt[(c >> 0) & 0x0f];\n            outbuf[index2++] = ' ';\n\n            if ((c >= 0x20) && (c <= 0x7e))\n            {\n                outbuf[index3++] = c;\n            }\n            else\n            {\n                outbuf[index3++] = '.';\n            }\n        }\n\n        outbuf[index3] = 0;\n        puts(outbuf);\n    }\n\n    if (!residual)\n    {\n        return;\n    }\n\n    outbuf[7] = cvt[(addr >>  0) & 0x0000000f];\n    outbuf[6] = cvt[(addr >>  4) & 0x0000000f];\n    outbuf[5] = cvt[(addr >>  8) & 0x0000000f];\n    outbuf[4] = cvt[(addr >> 12) & 0x0000000f];\n    outbuf[3] = cvt[(addr >> 16) & 0x0000000f];\n    outbuf[2] = cvt[(addr >> 20) & 0x0000000f];\n    outbuf[1] = cvt[(addr >> 24) & 0x0000000f];\n    outbuf[0] = cvt[(addr >> 28) & 0x0000000f];\n    addr += 16;\n\n    index2 = 10;\n    index3 = 60;\n    memset(&outbuf[8], ' ', 68);\n\n    for (j = 0; j < residual; j++)\n    {\n        c = buf[buf_index++];\n\n        outbuf[index2++] = cvt[(c >> 4) & 0x0f];\n        outbuf[index2++] = cvt[(c >> 0) & 0x0f];\n        outbuf[index2++] = ' ';\n\n        if ((c >= 0x20) && (c <= 0x7e))\n        {\n            outbuf[index3++] = c;\n        }\n        else\n        {\n            outbuf[index3++] = '.';\n        }\n    }\n\n    outbuf[index3] = 0;\n    puts(outbuf);\n}\n"
  },
  {
    "path": "tools/devel/tcp_proxy/Makefile.am",
    "content": "\nAM_CPPFLAGS = \\\n  -I$(top_srcdir)/common\n\nnoinst_PROGRAMS = \\\n  tcp_proxy\n\ntcp_proxy_SOURCES = \\\n  main.c\n\ntcp_proxy_LDADD = \\\n  $(top_builddir)/common/libcommon.la \\\n  $(DLOPEN_LIBS)\n"
  },
  {
    "path": "tools/devel/tcp_proxy/main.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdarg.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include <signal.h>\n#include <errno.h>\n#include <locale.h>\n#include <netdb.h>\n#include <sys/types.h>\n#include <sys/socket.h>\n#include <netinet/in.h>\n#include <arpa/inet.h>\n\n#include \"log.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n\nint  g_loc_io_count = 0;  // bytes read from local port\nint  g_rem_io_count = 0;  // bytes read from remote port\n\nstatic int g_terminated = 0;\n\ntypedef unsigned short tui16;\n\n\n/*****************************************************************************/\nstatic int\ng_tcp_socket_ok(int sck)\n{\n    int opt;\n    socklen_t opt_len = sizeof(opt);\n\n    if (getsockopt(sck, SOL_SOCKET, SO_ERROR, (char *)(&opt), &opt_len) == 0)\n    {\n        if (opt == 0)\n        {\n            return 1;\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\ncopy_sck_to_sck(int from_sck, int to_sck, int hexdump, int local)\n{\n    char buff[1024 * 32];\n    int rv = -1;\n\n    int count = g_tcp_recv(from_sck, buff, sizeof(buff), 0);\n    if (count > 0 && count <= (int)sizeof(buff))\n    {\n        rv = count; // Assume we'll return the amount of data copied\n        if (local)\n        {\n            g_loc_io_count += count;\n            if (hexdump)\n            {\n                LOG_HEXDUMP(LOG_LEVEL_INFO, \"from local:\", buff, count);\n            }\n        }\n        else\n        {\n            g_rem_io_count += count;\n            if (hexdump)\n            {\n                LOG_HEXDUMP(LOG_LEVEL_INFO, \"from remote:\", buff, count);\n            }\n        }\n\n\n        LOG(LOG_LEVEL_DEBUG, \"local_io_count: %d\\tremote_io_count: %d\",\n            g_loc_io_count, g_rem_io_count);\n\n        const char *p = buff;\n        while ((count > 0) && (!g_terminated))\n        {\n            int error = g_tcp_send(to_sck, p, count, 0);\n\n            if (error > 0 && error <= count)\n            {\n                // We wrote some data\n                count -= error;\n                p += error;\n            }\n            else if ((error == -1) && g_tcp_last_error_would_block(to_sck))\n            {\n                if (g_tcp_can_send(to_sck, 1000))\n                {\n                    g_tcp_socket_ok(to_sck);\n                }\n            }\n            else\n            {\n                count = 0; // Terminate loop\n                rv = -1; // tell user\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nmain_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)\n{\n    int lis_sck = -1;\n    int acc_sck = -1;\n    int con_sck = -1;\n    int sel;\n    int count;\n    int error;\n    int i;\n    int acc_to_con = 0;\n    int con_to_acc = 0;\n\n    /* create the listening socket and setup options */\n    lis_sck = g_tcp_socket();\n    if (lis_sck < 0)\n    {\n        error = 1;\n    }\n    else\n    {\n        g_tcp_set_non_blocking(lis_sck);\n        g_sck_set_reuseaddr(lis_sck);\n        error = g_tcp_bind(lis_sck, local_port);\n    }\n\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"bind failed\");\n    }\n\n    /* listen for an incoming connection */\n    if (error == 0)\n    {\n        error = g_tcp_listen(lis_sck);\n\n        if (error == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"listening for connection\");\n        }\n    }\n\n    /* accept an incoming connection */\n    if (error == 0)\n    {\n        while ((!g_terminated) && (error == 0))\n        {\n            acc_sck = g_sck_accept(lis_sck);\n\n            if ((acc_sck == -1) && g_tcp_last_error_would_block(lis_sck))\n            {\n                g_sleep(100);\n            }\n            else if (acc_sck == -1)\n            {\n                error = 1;\n            }\n            else\n            {\n                break;\n            }\n        }\n\n        if (error == 0)\n        {\n            error = g_terminated;\n        }\n\n        /* stop listening */\n        g_tcp_close(lis_sck);\n        lis_sck = -1;\n\n        if (error == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"got connection\");\n        }\n    }\n\n    /* connect outgoing socket */\n    if (error == 0)\n    {\n        con_sck = g_tcp_socket();\n        if (con_sck < 0)\n        {\n            error = 1;\n        }\n        else\n        {\n            g_tcp_set_non_blocking(con_sck);\n            error = g_tcp_connect(con_sck, remote_ip, remote_port);\n        }\n\n        if ((error == -1) && g_tcp_last_error_would_block(con_sck))\n        {\n            error = 0;\n            i = 0;\n\n            while (!g_terminated && i < 100 &&\n                    !g_tcp_can_send(con_sck, 100))\n            {\n                g_sleep(100);\n                i++;\n            }\n\n            if (i > 99)\n            {\n                LOG(LOG_LEVEL_ERROR, \"timeout connecting\");\n                error = 1;\n            }\n            else if (!g_tcp_socket_ok(con_sck))\n            {\n                error = 1;\n            }\n        }\n\n        if ((error != 0) && (!g_terminated))\n        {\n            LOG(LOG_LEVEL_ERROR, \"error connecting to remote\\r\\n\");\n        }\n    }\n\n    while (!g_terminated)\n    {\n        sel = g_tcp_select(con_sck, acc_sck);\n\n        if (sel == 0)\n        {\n            g_sleep(10);\n            continue;\n        }\n\n        if (sel & 1)\n        {\n            // can read from con_sck w/o blocking\n            count = copy_sck_to_sck(con_sck, acc_sck, hexdump, 1);\n            if (count < 0)\n            {\n                break;\n            }\n            con_to_acc += count;\n        }\n        if (sel & 2)\n        {\n            // can read from acc_sck w/o blocking\n            count = copy_sck_to_sck(acc_sck, con_sck, hexdump, 0);\n            if (count < 0)\n            {\n                break;\n            };\n            acc_to_con += count;\n        }\n    }\n\n    if (lis_sck >= 0)\n    {\n        g_tcp_close(lis_sck);\n    }\n    if (con_sck >= 0)\n    {\n        g_tcp_close(con_sck);\n    }\n    if (acc_sck >= 0)\n    {\n        g_tcp_close(acc_sck);\n    }\n    LOG(LOG_LEVEL_INFO, \"acc_to_con %d\", acc_to_con);\n    LOG(LOG_LEVEL_INFO, \"con_to_acc %d\", con_to_acc);\n    return 0;\n}\n\n\n/*****************************************************************************/\nstatic int\nusage(void)\n{\n    g_writeln(\"tcp_proxy <local-port> <remote-ip> <remote-port> [dump]\");\n    return 0;\n}\n\n\n/*****************************************************************************/\nstatic void\nproxy_shutdown(int sig)\n{\n    LOG(LOG_LEVEL_INFO, \"shutting down\");\n    g_terminated = 1;\n}\n\nstatic void\nclear_counters(int sig)\n{\n    LOG(LOG_LEVEL_DEBUG, \"cleared counters at: local_io_count: %d remote_io_count: %d\",\n        g_loc_io_count, g_rem_io_count);\n    g_loc_io_count = 0;\n    g_rem_io_count = 0;\n}\n\n/*****************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    int dump;\n    struct log_config *config;\n\n    if (argc < 4)\n    {\n        usage();\n        return 0;\n    }\n\n    g_init(\"tcp_proxy\");\n    g_signal_user_interrupt(proxy_shutdown); /* SIGINT  */\n    g_signal_usr1(clear_counters);           /* SIGUSR1 */\n    g_signal_terminate(proxy_shutdown);      /* SIGTERM */\n\n    config = log_config_init_for_console(LOG_LEVEL_INFO, NULL);\n    log_start_from_param(config);\n    log_config_free(config);\n\n    if (argc < 5)\n    {\n        while (!g_terminated)\n        {\n            g_loc_io_count = 0;\n            g_rem_io_count = 0;\n            main_loop(argv[1], argv[2], argv[3], 0);\n        }\n    }\n    else\n    {\n        dump = g_strcasecmp(argv[4], \"dump\") == 0;\n\n        while (!g_terminated)\n        {\n            main_loop(argv[1], argv[2], argv[3], dump);\n        }\n    }\n\n    log_end();\n    g_deinit();\n    return 0;\n}\n"
  },
  {
    "path": "vnc/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -I$(top_srcdir)/common\n\nAM_CFLAGS = $(X_CFLAGS)\n\nmodule_LTLIBRARIES = \\\n  libvnc.la\n\nlibvnc_la_SOURCES = \\\n  vnc.c \\\n  vnc_clip.c \\\n  rfb.c \\\n  vnc.h \\\n  vnc_clip.h \\\n  rfb.h\n\nlibvnc_la_LIBADD = \\\n  $(top_builddir)/common/libcommon.la\n\nif !MACOS\nlibvnc_la_LDFLAGS = -avoid-version -module\nendif\n"
  },
  {
    "path": "vnc/rfb.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libvnc - RFB specific functions\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"rfb.h\"\n\n/* Messages for ExtendedDesktopSize status code */\nstatic const char *eds_status_msg[] =\n{\n    /* 0 */ \"No error\",\n    /* 1 */ \"Resize is administratively prohibited\",\n    /* 2 */ \"Out of resources\",\n    /* 3 */ \"Invalid screen layout\",\n    /* 4 */ \"Request forwarded\",\n    /* others */ \"Unknown code\"\n};\n\n/* elements in above list */\n#define EDS_STATUS_MSG_COUNT \\\n    (sizeof(eds_status_msg) / sizeof(eds_status_msg[0]))\n\n/**************************************************************************//**\n * Returns an error string for an ExtendedDesktopSize status code\n */\nconst char *\nrfb_get_eds_status_msg(unsigned int response_code)\n{\n    if (response_code >= EDS_STATUS_MSG_COUNT)\n    {\n        response_code = EDS_STATUS_MSG_COUNT - 1;\n    }\n\n    return eds_status_msg[response_code];\n}\n"
  },
  {
    "path": "vnc/rfb.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libvnc - defines related to the RFB protocol\n */\n\n#ifndef RFB_H\n#define RFB_H\n\n#include \"arch.h\"\n\n/* Client-to-server messages */\nenum c2s\n{\n    RFB_C2S_SET_PIXEL_FORMAT = 0,\n    RFB_C2S_SET_ENCODINGS = 2,\n    RFB_C2S_FRAMEBUFFER_UPDATE_REQUEST = 3,\n    RFB_C2S_KEY_EVENT = 4,\n    RFB_C2S_POINTER_EVENT = 5,\n    RFB_C2S_CLIENT_CUT_TEXT = 6,\n};\n\n/* Server to client messages */\nenum s2c\n{\n    RFB_S2C_FRAMEBUFFER_UPDATE = 0,\n    RFB_S2C_SET_COLOUR_MAP_ENTRIES = 1,\n    RFB_S2C_BELL = 2,\n    RFB_S2C_SERVER_CUT_TEXT = 3\n};\n\n/* Encodings and pseudo-encodings\n *\n * The RFC uses a signed type for these. We use an unsigned type as the\n * binary representation for the negative values is standardised in C\n * (which it wouldn't be for an enum value)\n */\n\ntypedef uint32_t encoding_type;\n\n#define RFB_ENC_RAW                   (encoding_type)0\n#define RFB_ENC_COPY_RECT             (encoding_type)1\n#define RFB_ENC_CURSOR                (encoding_type)-239\n#define RFB_ENC_DESKTOP_SIZE          (encoding_type)-223\n#define RFB_ENC_EXTENDED_DESKTOP_SIZE (encoding_type)-308\n\n/* Security types defined in RFC6143 7.2 (RFB Community wiki 7.1.2) */\nenum sec_type\n{\n    SEC_TYPE_INVALID = 0,\n    SEC_TYPE_NONE = 1,\n    SEC_TYPE_VNC_AUTH = 2,\n    SEC_TYPE_MAX = SEC_TYPE_VNC_AUTH // Max supported security type\n};\n\n#define SEC_TYPE_TO_STR(st) \\\n    (((st) == SEC_TYPE_INVALID) ? \"Invalid\" : \\\n     ((st) == SEC_TYPE_NONE) ? \"None\" : \\\n     ((st) == SEC_TYPE_VNC_AUTH) ? \"VNC Auth\" : \"Unknown\")\n\n/* Constructs an RFB version from a major and minor version */\n#define MAKE_RFBPROTO_VER(maj,min) ((maj * 1000) + (min))\n\n/* Convenience macros */\n#define RFBPROTO_VER_3_3 MAKE_RFBPROTO_VER(3,3)\n#define RFBPROTO_VER_3_7 MAKE_RFBPROTO_VER(3,7)\n#define RFBPROTO_VER_3_8 MAKE_RFBPROTO_VER(3,8)\n\n/*\n * ExtendedDesktopSize status codes\n */\nenum\n{\n    RFB_EDS_NO_ERROR = 0,\n    RFB_EDS_ADMINISTRATIVELY_PROHIBITED = 1,\n    RFB_EDS_OUT_OF_RESOURCES = 2,\n    RFB_EDS_INVALID_SCREEN_LAYOUT = 3,\n    RFB_EDS_REQUEST_FORWARDED = 4\n};\n\n/**\n * Returns an error string for an ExtendedDesktopSize status code\n */\nconst char *\nrfb_get_eds_status_msg(unsigned int response_code);\n\n#endif /* RFB_H */\n"
  },
  {
    "path": "vnc/vnc.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libvnc\n *\n * The message definitions used in this source file can be found mostly\n * in RFC6143 - \"The Remote Framebuffer Protocol\".\n *\n * The ExtendedDesktopSize encoding is reserved in RFC6143, but not\n * documented there. It is documented by the RFB protocol community\n * wiki currently held at https://github.com/rfbproto/rfbroto. This is\n * referred to below as the \"RFB community wiki\"\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <ctype.h>\n#include <limits.h>\n#include <X11/keysym.h>\n\n#include \"vnc.h\"\n#include \"vnc_clip.h\"\n#include \"rfb.h\"\n#include \"log.h\"\n#include \"timers.h\"\n#include \"trans.h\"\n#include \"ssl_calls.h\"\n#include \"string_calls.h\"\n#include \"xrdp_client_info.h\"\n\n/* elements in above list */\n#define EDS_STATUS_MSG_COUNT \\\n    (sizeof(eds_status_msg) / sizeof(eds_status_msg[0]))\n\n/* Used by enabled_encodings_mask */\nenum\n{\n    MSK_EXTENDED_DESKTOP_SIZE = (1 << 0)\n};\n\nenum\n{\n    /** Time to wait for a forwarded resize to complete */\n    FORWARDED_RESIZE_TIMEOUT = 1500  /* milli-seconds */\n};\n\n/******************************************************************************/\nint\nlib_send_copy(struct vnc *v, struct stream *s)\n{\n    return trans_write_copy_s(v->trans, s);\n}\n\n/******************************************************************************/\n/* taken from vncauth.c */\n/* performing the des3 crypt on the password so it can not be seen\n   on the wire\n   'bytes' in, contains 16 bytes server random\n           out, random and 'passwd' conbined */\nstatic void\nrfbEncryptBytes(char *bytes, const char *passwd)\n{\n    char key[24];\n    void *des;\n    int len;\n\n    /* key is simply password padded with nulls */\n    g_memset(key, 0, sizeof(key));\n    len = MIN(g_strlen(passwd), 8);\n    g_mirror_memcpy(key, passwd, len);\n    des = ssl_des3_encrypt_info_create(key, 0);\n    ssl_des3_encrypt(des, 8, bytes, bytes);\n    ssl_des3_info_delete(des);\n    des = ssl_des3_encrypt_info_create(key, 0);\n    ssl_des3_encrypt(des, 8, bytes + 8, bytes + 8);\n    ssl_des3_info_delete(des);\n}\n\n/******************************************************************************/\n/* sha1 hash 'passwd', create a string from the hash and call rfbEncryptBytes */\nstatic void\nrfbHashEncryptBytes(char *bytes, const char *passwd)\n{\n    char passwd_hash[20];\n    char passwd_hash_text[40];\n    void *sha1;\n    int passwd_bytes;\n\n    /* create password hash from password */\n    passwd_bytes = g_strlen(passwd);\n    sha1 = ssl_sha1_info_create();\n    ssl_sha1_clear(sha1);\n    ssl_sha1_transform(sha1, \"xrdp_vnc\", 8);\n    ssl_sha1_transform(sha1, passwd, passwd_bytes);\n    ssl_sha1_transform(sha1, passwd, passwd_bytes);\n    ssl_sha1_complete(sha1, passwd_hash);\n    ssl_sha1_info_delete(sha1);\n    g_snprintf(passwd_hash_text, 39, \"%2.2x%2.2x%2.2x%2.2x\",\n               (tui8)passwd_hash[0], (tui8)passwd_hash[1],\n               (tui8)passwd_hash[2], (tui8)passwd_hash[3]);\n    passwd_hash_text[39] = 0;\n    rfbEncryptBytes(bytes, passwd_hash_text);\n}\n\n/**************************************************************************//**\n * Logs a debug message containing a screen layout\n *\n * @param lvl Level to log at\n * @param source Where the layout came from\n * @param layout Layout to log\n */\nstatic void\nlog_screen_layout(const enum logLevels lvl, const char *source,\n                  const struct vnc_screen_layout *layout)\n{\n    unsigned int i;\n    char text[256];\n    size_t pos;\n    int res;\n\n    pos = 0;\n    res = g_snprintf(text, sizeof(text) - pos,\n                     \"Layout from %s (geom=%dx%d #screens=%u) :\",\n                     source, layout->total_width, layout->total_height,\n                     layout->count);\n\n    i = 0;\n    while (res > 0 && (size_t)res < sizeof(text) - pos && i < layout->count)\n    {\n        pos += res;\n        res = g_snprintf(&text[pos], sizeof(text) - pos,\n                         \" %d:(%dx%d+%d+%d)\",\n                         layout->s[i].id,\n                         layout->s[i].width, layout->s[i].height,\n                         layout->s[i].x, layout->s[i].y);\n        ++i;\n    }\n    LOG(lvl, \"%s\", text);\n}\n\n/**************************************************************************//**\n * Compares two vnc_screen structures\n *\n * @param a First structure\n * @param b Second structure\n *\n * @return Suitable for sorting structures on (x, y, width, height)\n */\nstatic int cmp_vnc_screen(const struct vnc_screen *a,\n                          const struct vnc_screen *b)\n{\n    int result = 0;\n    if (a->x != b->x)\n    {\n        result = a->x - b->x;\n    }\n    else if (a->y != b->y)\n    {\n        result = a->y - b->y;\n    }\n    else if (a->width != b->width)\n    {\n        result = a->width - b->width;\n    }\n    else if (a->height != b->height)\n    {\n        result = a->height - b->height;\n    }\n\n    return result;\n}\n\n/**************************************************************************//**\n * Compares two vnc_screen_layout structures for equality\n * @param a First layout\n * @param b First layout\n * @return != 0 if structures are equal\n */\nstatic int vnc_screen_layouts_equal(const struct vnc_screen_layout *a,\n                                    const struct vnc_screen_layout *b)\n{\n    unsigned int i;\n    int result = (a->total_width == b->total_width &&\n                  a->total_height == b->total_height &&\n                  a->count == b->count);\n    if (result)\n    {\n        for (i = 0 ; result && i < a->count ; ++i)\n        {\n            result = (cmp_vnc_screen(&a->s[i], &b->s[i]) == 0);\n        }\n    }\n\n    return result;\n}\n\n/**************************************************************************//**\n * Reads an extended desktop size rectangle from the VNC server\n *\n * @param v VNC object\n * @param [out] layout Desired layout for server\n * @return != 0 for error\n *\n * @pre The next octet read from v->trans is the number of screens\n *\n * @post Returned structure is in increasing ID order\n * @post layout->total_width is untouched\n * @post layout->total_height is untouched\n */\nstatic int\nread_extended_desktop_size_rect(struct vnc *v,\n                                struct vnc_screen_layout *layout)\n{\n    struct stream *s;\n    int error;\n    unsigned int count;\n\n    layout->count = 0;\n\n    make_stream(s);\n    init_stream(s, 8192);\n\n    /* Read in the current screen config */\n    error = trans_force_read_s(v->trans, s, 4);\n    if (error == 0)\n    {\n        /* Get the number of screens */\n        in_uint8(s, count);\n        if (count <= 0 || count > CLIENT_MONITOR_DATA_MAXIMUM_MONITORS)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Bad monitor count %d in ExtendedDesktopSize rectangle\",\n                count);\n            error = 1;\n        }\n        else\n        {\n            in_uint8s(s, 3);\n\n            error = trans_force_read_s(v->trans, s, 16 * count);\n            if (error == 0)\n            {\n                unsigned int i;\n                for (i = 0 ; i < count ; ++i)\n                {\n                    in_uint32_be(s, layout->s[i].id);\n                    in_uint16_be(s, layout->s[i].x);\n                    in_uint16_be(s, layout->s[i].y);\n                    in_uint16_be(s, layout->s[i].width);\n                    in_uint16_be(s, layout->s[i].height);\n                    in_uint32_be(s, layout->s[i].flags);\n                }\n\n                /* sort monitors in increasing (x,y) order */\n                qsort(layout->s, count, sizeof(layout->s[0]),\n                      (int (*)(const void *, const void *))cmp_vnc_screen);\n                layout->count = count;\n            }\n        }\n    }\n\n    free_stream(s);\n\n    return error;\n}\n\n/**************************************************************************//**\n * Sends a SetDesktopSize message\n *\n * @param v VNC object\n * @param layout Desired layout for server\n * @return != 0 for error\n *\n * The SetDesktopSize message is documented in the RFB community wiki\n * \"SetDesktopSize\" section.\n */\nstatic int\nsend_set_desktop_size(struct vnc *v, const struct vnc_screen_layout *layout)\n{\n    unsigned int i;\n    struct stream *s;\n    int error;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    out_uint8(s, 251);\n    out_uint8(s, 0);\n    out_uint16_be(s, layout->total_width);\n    out_uint16_be(s, layout->total_height);\n\n    out_uint8(s, layout->count);\n    out_uint8(s, 0);\n    for (i = 0 ; i < layout->count ; ++i)\n    {\n        out_uint32_be(s, layout->s[i].id);\n        out_uint16_be(s, layout->s[i].x);\n        out_uint16_be(s, layout->s[i].y);\n        out_uint16_be(s, layout->s[i].width);\n        out_uint16_be(s, layout->s[i].height);\n        out_uint32_be(s, layout->s[i].flags);\n    }\n    s_mark_end(s);\n    LOG(LOG_LEVEL_DEBUG, \"VNC_RESIZE: Sending SetDesktopSize %dx%d\",\n        layout->total_width, layout->total_height);\n    error = lib_send_copy(v, s);\n    free_stream(s);\n\n    return error;\n}\n\n/**************************************************************************//**\n * Initialises a vnc_screen_layout as a single screen\n * @param[in] width Screen Width\n * @param[in] height Screen Height\n * @param[out] layout Layout to initialise\n */\nstatic void\ninit_single_screen_layout(int width, int height,\n                          struct vnc_screen_layout *layout)\n{\n    layout->total_width = width;\n    layout->total_height = height;\n    layout->count = 1;\n    layout->s[0].id = 0;\n    layout->s[0].x = 0;\n    layout->s[0].y = 0;\n    layout->s[0].width = width;\n    layout->s[0].height = height;\n    layout->s[0].flags = 0;\n}\n\n/**************************************************************************//**\n * Resize the client to match the server_layout\n *\n * @param v VNC object\n * @param update_in_progress True if there's a painter update in progress\n * @return != 0 for error\n *\n * The new client layout is recorded in v->client_layout.\n */\nstatic int\nresize_client_to_server(struct vnc *v, int update_in_progress)\n{\n    int error = 0;\n    unsigned int i;\n    const struct vnc_screen_layout *sl = &v->server_layout;\n    struct monitor_info client_mons[CLIENT_MONITOR_DATA_MAXIMUM_MONITORS] = {0};\n\n    if (sl->count <= 0 ||\n            sl->count > CLIENT_MONITOR_DATA_MAXIMUM_MONITORS)\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s: Programming error. Bad monitors %d\",\n            __func__, sl->count);\n        return 1;\n    }\n\n    // Convert the server monitors into client monitors\n    for (i = 0; i < sl->count; ++i)\n    {\n        client_mons[i].left = sl->s[i].x;\n        client_mons[i].top = sl->s[i].y;\n        client_mons[i].right = sl->s[i].x + sl->s[i].width - 1;\n        client_mons[i].bottom = sl->s[i].y + sl->s[i].height - 1;\n    }\n\n    if (update_in_progress && v->server_end_update(v) != 0)\n    {\n        error = 1;\n    }\n    else\n    {\n        error = v->client_monitor_resize(v, sl->total_width, sl->total_height,\n                                         sl->count, client_mons);\n        if (error == 0)\n        {\n            v->client_layout = *sl;\n        }\n\n        if (update_in_progress && v->server_begin_update(v) != 0)\n        {\n            error = 1;\n        }\n    }\n\n    return error;\n}\n\n\n/**************************************************************************//**\n * Resize the server to the client layout\n *\n * @param v VNC object\n * @return != 0 for error\n *\n * The new client layout is recorded in v->client_layout.\n */\nstatic int\nresize_server_to_client_layout(struct vnc *v)\n{\n    int error = 0;\n\n    /* Before checking the 'resize_supported' flag, see if this\n     * is a null operation. We can get here if the server doesn't\n     * support resize, and we've queued a request to resize the client\n     * to the server size */\n    if (vnc_screen_layouts_equal(&v->server_layout, &v->client_layout))\n    {\n        LOG(LOG_LEVEL_DEBUG, \"Server layout is the same \"\n            \"as the client layout\");\n        v->resize_status = VRS_DONE;\n    }\n    else if (v->resize_supported != VRSS_SUPPORTED)\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s: Asked to resize server, but not possible\",\n            __func__);\n        error = 1;\n    }\n    else\n    {\n        /*\n         * If we've only got one screen, and the other side has\n         * only got one screen, we will preserve their screen ID\n         * and any flags.  This may prevent us sending an unwanted\n         * SetDesktopSize message if the screen dimensions are\n         * a match. We can't do this with more than one screen,\n         * as we have no way to map different IDs\n         */\n        if (v->server_layout.count == 1 && v->client_layout.count == 1)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"VNC \"\n                \"setting screen id to %d from server\",\n                v->server_layout.s[0].id);\n\n            v->client_layout.s[0].id = v->server_layout.s[0].id;\n            v->client_layout.s[0].flags = v->server_layout.s[0].flags;\n        }\n\n        LOG(LOG_LEVEL_DEBUG, \"Changing server layout\");\n        error = send_set_desktop_size(v, &v->client_layout);\n        v->resize_status = VRS_WAITING_FOR_RESIZE_CONFIRM;\n    }\n\n    return error;\n}\n\n/*****************************************************************************/\n/**\n * Process keysym messages\n * @param v Module\n * @param keysym Keysym of keypress\n * @param keydown boolean - is key down?\n * @return != 0 for error\n */\nstatic int\nprocess_keysym_msg(struct vnc *v, int keysym, int keydown)\n{\n    struct stream *s = NULL;\n    int error = 0;\n\n    if (keysym > 0)\n    {\n        make_stream(s);\n\n        /* Break key processing [MS-RDPBCGR] 2.2.8.1.1.3.1.1.1 */\n        if (v->ignore_next_numlock)\n        {\n            v->ignore_next_numlock = 0;\n            if (keysym == XK_Num_Lock)\n            {\n                goto end_keysym_msg;\n            }\n        }\n\n        if (keysym == XK_ISO_Level3_Shift)  /* altgr */\n        {\n            if (v->shift_state)\n            {\n                /* fix for mstsc sending left control down with altgr */\n                init_stream(s, 64);\n                out_uint8(s, RFB_C2S_KEY_EVENT);\n                out_uint8(s, 0); /* down flag */\n                out_uint8s(s, 2);\n                out_uint32_be(s, XK_Control_L); /* left control */\n                s_mark_end(s);\n                error = lib_send_copy(v, s);\n                if (error != 0)\n                {\n                    goto end_keysym_msg;\n                }\n            }\n        }\n\n        init_stream(s, 64);\n        out_uint8(s, RFB_C2S_KEY_EVENT);\n        out_uint8(s, keydown ? 1 : 0);\n        out_uint8s(s, 2);\n        out_uint32_be(s, keysym);\n        s_mark_end(s);\n        error = lib_send_copy(v, s);\n\n        switch (keysym)\n        {\n            case XK_Control_L: /* left control */\n                v->shift_state = keydown;\n                break;\n\n            case XK_Pause:\n                // [MS-RDPBCGR] 2.2.8.1.1.3.1.1.1 - A pause key scancode\n                // (up or down) is always immediately followed by a\n                // numlock key which we should ignore\n                v->ignore_next_numlock = 1;\n                break;\n\n            default:\n                break;\n        }\n    }\n\nend_keysym_msg:\n    free_stream(s);\n    return error;\n}\n\n/*****************************************************************************/\nstatic int\nlib_mod_event(struct vnc *v, int msg, long param1, long param2,\n              long param3, long param4)\n{\n    struct stream *s;\n    int error;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int size;\n    int total_size;\n    int chanid;\n    int flags;\n    char *data;\n\n    error = 0;\n    make_stream(s);\n\n    if (msg == WM_CHANNEL_DATA)\n    {\n        chanid = LOWORD(param1);\n        flags = HIWORD(param1);\n        size = (int)param2;\n        data = (char *)param3;\n        total_size = (int)param4;\n\n        if ((size >= 0) && (size <= (32 * 1024)) && (data != 0))\n        {\n            if (chanid == v->clip_chanid)\n            {\n                error = vnc_clip_process_channel_data(v, data, size,\n                                                      total_size, flags);\n            }\n            else\n            {\n                LOG(LOG_LEVEL_DEBUG, \"lib_process_channel_data: unknown chanid: \"\n                    \"%d :(v->clip_chanid) %d\", chanid, v->clip_chanid);\n            }\n        }\n        else\n        {\n            error = 1;\n        }\n    }\n    else if ((msg >= 15) && (msg <= 16)) /* key events */\n    {\n        error = process_keysym_msg(v, param2, (msg == 15));\n    }\n    /* mouse events\n     *\n     * VNC supports up to 8 mouse buttons because mouse buttons are\n     * represented by 7 bits bitmask\n     */\n    else if (msg >= WM_MOUSEMOVE && msg <= WM_BUTTON8DOWN) /* 100 to 116 */\n    {\n        switch (msg)\n        {\n            case WM_MOUSEMOVE:\n                break;\n            case WM_LBUTTONUP:\n                v->mod_mouse_state &= ~1;\n                break;\n            case WM_LBUTTONDOWN:\n                v->mod_mouse_state |= 1;\n                break;\n            case WM_RBUTTONUP:\n                v->mod_mouse_state &= ~4;\n                break;\n            case WM_RBUTTONDOWN:\n                v->mod_mouse_state |= 4;\n                break;\n            case WM_BUTTON3UP:\n                v->mod_mouse_state &= ~2;\n                break;\n            case WM_BUTTON3DOWN:\n                v->mod_mouse_state |= 2;\n                break;\n            case WM_BUTTON4UP:\n                v->mod_mouse_state &= ~8;\n                break;\n            case WM_BUTTON4DOWN:\n                v->mod_mouse_state |= 8;\n                break;\n            case WM_BUTTON5UP:\n                v->mod_mouse_state &= ~16;\n                break;\n            case WM_BUTTON5DOWN:\n                v->mod_mouse_state |= 16;\n                break;\n            case WM_BUTTON6UP:\n                v->mod_mouse_state &= ~32;\n                break;\n            case WM_BUTTON6DOWN:\n                v->mod_mouse_state |= 32;\n                break;\n            case WM_BUTTON7UP:\n                v->mod_mouse_state &= ~64;\n                break;\n            case WM_BUTTON7DOWN:\n                v->mod_mouse_state |= 64;\n                break;\n            case WM_BUTTON8UP:\n                v->mod_mouse_state &= ~128;\n                break;\n            case WM_BUTTON8DOWN:\n                v->mod_mouse_state |= 128;\n                break;\n        }\n\n        init_stream(s, 8192);\n        out_uint8(s, RFB_C2S_POINTER_EVENT);\n        out_uint8(s, v->mod_mouse_state);\n        out_uint16_be(s, param1);\n        out_uint16_be(s, param2);\n        s_mark_end(s);\n        error = lib_send_copy(v, s);\n    }\n    else if (msg == 200) /* invalidate */\n    {\n        if (v->suppress_output == 0)\n        {\n            init_stream(s, 8192);\n            out_uint8(s, RFB_C2S_FRAMEBUFFER_UPDATE_REQUEST);\n            out_uint8(s, 0); /* incremental == 0 : Full contents */\n            x = (param1 >> 16) & 0xffff;\n            out_uint16_be(s, x);\n            y = param1 & 0xffff;\n            out_uint16_be(s, y);\n            cx = (param2 >> 16) & 0xffff;\n            out_uint16_be(s, cx);\n            cy = param2 & 0xffff;\n            out_uint16_be(s, cy);\n            s_mark_end(s);\n            error = lib_send_copy(v, s);\n        }\n    }\n    free_stream(s);\n    return error;\n}\n\n//******************************************************************************\nstatic int\nget_pixel_safe(char *data, int x, int y, int width, int height, int bpp)\n{\n    int start;\n    int shift;\n\n    if (x < 0)\n    {\n        return 0;\n    }\n\n    if (y < 0)\n    {\n        return 0;\n    }\n\n    if (x >= width)\n    {\n        return 0;\n    }\n\n    if (y >= height)\n    {\n        return 0;\n    }\n\n    if (bpp == 1)\n    {\n        width = (width + 7) / 8;\n        start = (y * width) + x / 8;\n        shift = x % 8;\n        return (data[start] & (0x80 >> shift)) != 0;\n    }\n    else if (bpp == 4)\n    {\n        width = (width + 1) / 2;\n        start = y * width + x / 2;\n        shift = x % 2;\n\n        if (shift == 0)\n        {\n            return (data[start] & 0xf0) >> 4;\n        }\n        else\n        {\n            return data[start] & 0x0f;\n        }\n    }\n    else if (bpp == 8)\n    {\n        return *(((unsigned char *)data) + (y * width + x));\n    }\n    else if (bpp == 15 || bpp == 16)\n    {\n        return *(((unsigned short *)data) + (y * width + x));\n    }\n    else if (bpp == 24 || bpp == 32)\n    {\n        return *(((unsigned int *)data) + (y * width + x));\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"error in get_pixel_safe bpp %d\", bpp);\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic void\nset_pixel_safe(char *data, int x, int y, int width, int height, int bpp,\n               int pixel)\n{\n    int start;\n    int shift;\n\n    if (x < 0)\n    {\n        return;\n    }\n\n    if (y < 0)\n    {\n        return;\n    }\n\n    if (x >= width)\n    {\n        return;\n    }\n\n    if (y >= height)\n    {\n        return;\n    }\n\n    if (bpp == 1)\n    {\n        width = (width + 7) / 8;\n        start = (y * width) + x / 8;\n        shift = x % 8;\n\n        if (pixel & 1)\n        {\n            data[start] = data[start] | (0x80 >> shift);\n        }\n        else\n        {\n            data[start] = data[start] & ~(0x80 >> shift);\n        }\n    }\n    else if (bpp == 15 || bpp == 16)\n    {\n        *(((unsigned short *)data) + (y * width + x)) = pixel;\n    }\n    else if (bpp == 24)\n    {\n        *(data + (3 * (y * width + x)) + 0) = pixel >> 0;\n        *(data + (3 * (y * width + x)) + 1) = pixel >> 8;\n        *(data + (3 * (y * width + x)) + 2) = pixel >> 16;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"error in set_pixel_safe bpp %d\", bpp);\n    }\n}\n\n/******************************************************************************/\nstatic int\nsplit_color(int pixel, int *r, int *g, int *b, int bpp, int *palette)\n{\n    if (bpp == 8)\n    {\n        if (pixel >= 0 && pixel < 256 && palette != 0)\n        {\n            *r = (palette[pixel] >> 16) & 0xff;\n            *g = (palette[pixel] >> 8) & 0xff;\n            *b = (palette[pixel] >> 0) & 0xff;\n        }\n    }\n    else if (bpp == 15)\n    {\n        *r = ((pixel >> 7) & 0xf8) | ((pixel >> 12) & 0x7);\n        *g = ((pixel >> 2) & 0xf8) | ((pixel >> 8) & 0x7);\n        *b = ((pixel << 3) & 0xf8) | ((pixel >> 2) & 0x7);\n    }\n    else if (bpp == 16)\n    {\n        *r = ((pixel >> 8) & 0xf8) | ((pixel >> 13) & 0x7);\n        *g = ((pixel >> 3) & 0xfc) | ((pixel >> 9) & 0x3);\n        *b = ((pixel << 3) & 0xf8) | ((pixel >> 2) & 0x7);\n    }\n    else if (bpp == 24 || bpp == 32)\n    {\n        *r = (pixel >> 16) & 0xff;\n        *g = (pixel >> 8) & 0xff;\n        *b = pixel & 0xff;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"error in split_color bpp %d\", bpp);\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nmake_color(int r, int g, int b, int bpp)\n{\n    if (bpp == 24)\n    {\n        return (r << 16) | (g << 8) | b;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"error in make_color bpp %d\", bpp);\n    }\n\n    return 0;\n}\n\n/**\n * Converts a bits-per-pixel value to bytes-per-pixel\n */\nstatic int\nget_bytes_per_pixel(int bpp)\n{\n    int result = (bpp + 7) / 8;\n\n    if (result == 3)\n    {\n        result = 4;\n    }\n\n    return result;\n}\n\n\n/**************************************************************************//**\n * Skips the specified number of bytes from the transport\n *\n * @param trans Transport to read\n * @param bytes Bytes to skip\n * @return != 0 for error\n */\nint\nskip_trans_bytes(struct trans *trans, unsigned int bytes)\n{\n    struct stream *s;\n    int error = 0;\n\n    make_stream(s);\n\n    while (error == 0 && bytes > 0)\n    {\n        int chunk_size = MIN(32768, bytes);\n        init_stream(s, chunk_size);\n        error = trans_force_read_s(trans, s, chunk_size);\n        bytes -= chunk_size;\n    }\n\n    free_stream(s);\n\n    return error;\n}\n\n/**************************************************************************//**\n * Reads an encoding from the input stream and discards it\n *\n * @param v VNC object\n * @param x Encoding X value\n * @param y Encoding Y value\n * @param cx Encoding CX value\n * @param cy Encoding CY value\n * @param encoding Code for encoding\n * @return != 0 for error\n *\n * @pre On entry the input stream is positioned after the encoding header\n */\nstatic int\nskip_encoding(struct vnc *v, int x, int y, int cx, int cy,\n              encoding_type encoding)\n{\n    char text[256];\n    int error = 0;\n\n    switch (encoding)\n    {\n        case RFB_ENC_RAW:\n        {\n            int need_size = cx * cy * get_bytes_per_pixel(v->server_bpp);\n            LOG(LOG_LEVEL_DEBUG, \"Skipping RFB_ENC_RAW encoding\");\n            error = skip_trans_bytes(v->trans, need_size);\n        }\n        break;\n\n        case RFB_ENC_COPY_RECT:\n        {\n            LOG(LOG_LEVEL_DEBUG, \"Skipping RFB_ENC_COPY_RECT encoding\");\n            error = skip_trans_bytes(v->trans, 4);\n        }\n        break;\n\n        case RFB_ENC_CURSOR:\n        {\n            int j = cx * cy * get_bytes_per_pixel(v->server_bpp);\n            int k = ((cx + 7) / 8) * cy;\n\n            LOG(LOG_LEVEL_DEBUG, \"Skipping RFB_ENC_CURSOR encoding\");\n            error = skip_trans_bytes(v->trans, j + k);\n        }\n        break;\n\n        case RFB_ENC_DESKTOP_SIZE:\n            LOG(LOG_LEVEL_DEBUG, \"Skipping RFB_ENC_DESKTOP_SIZE encoding\");\n            break;\n\n        case RFB_ENC_EXTENDED_DESKTOP_SIZE:\n        {\n            struct vnc_screen_layout layout = {0};\n            LOG(LOG_LEVEL_DEBUG,\n                \"VNC_RESIZE: Skipping RFB_ENC_EXTENDED_DESKTOP_SIZE encoding \"\n                \"x=%d, y=%d geom=%dx%d\",\n                x, y, cx, cy);\n            error = read_extended_desktop_size_rect(v, &layout);\n        }\n        break;\n\n        default:\n            g_sprintf(text, \"VNC error in skip_encoding \"\n                      \"encoding = %8.8x\", encoding);\n            v->server_msg(v, text, 1);\n    }\n\n    return error;\n}\n\n/**************************************************************************//**\n * Parses an entire framebuffer update message from the wire, and returns the\n * first matching ExtendedDesktopSize encoding if found.\n *\n * Caller can check for a match by examining match_layout.count after the call\n *\n * @param v VNC object\n * @param match Function to call to check for a match\n * @param [out] match_x Matching x parameter for an encoding (if needed)\n * @param [out] match_y Matching y parameter for an encoding (if needed)\n * @param [out] match_layout Returned layout for the encoding\n * @return != 0 for error\n */\nstatic int\nfind_matching_extended_rect(struct vnc *v,\n                            int (*match)(int x, int y, int cx, int cy),\n                            int *match_x,\n                            int *match_y,\n                            struct vnc_screen_layout *match_layout)\n{\n    int error;\n    struct stream *s;\n    unsigned int num_rects;\n    unsigned int i;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    encoding_type encoding;\n    int found = 0;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    error = trans_force_read_s(v->trans, s, 3);\n\n    if (error == 0)\n    {\n        in_uint8s(s, 1);\n        in_uint16_be(s, num_rects);\n\n        for (i = 0; i < num_rects; ++i)\n        {\n            if (error != 0)\n            {\n                break;\n            }\n\n            init_stream(s, 8192);\n            error = trans_force_read_s(v->trans, s, 12);\n\n            if (error == 0)\n            {\n                in_uint16_be(s, x);\n                in_uint16_be(s, y);\n                in_uint16_be(s, cx);\n                in_uint16_be(s, cy);\n                in_uint32_be(s, encoding);\n\n                if (encoding == RFB_ENC_EXTENDED_DESKTOP_SIZE &&\n                        !found &&\n                        match(x, y, cx, cy))\n                {\n                    LOG(LOG_LEVEL_DEBUG,\n                        \"VNC_RESIZE: VNC matched ExtendedDesktopSize rectangle \"\n                        \"x=%d, y=%d geom=%dx%d\",\n                        x, y, cx, cy);\n                    found = 1;\n                    error = read_extended_desktop_size_rect(v, match_layout);\n                    if (match_x)\n                    {\n                        *match_x = x;\n                    }\n                    if (match_y)\n                    {\n                        *match_y = y;\n                    }\n                    match_layout->total_width = cx;\n                    match_layout->total_height = cy;\n                }\n                else\n                {\n                    error = skip_encoding(v, x, y, cx, cy, encoding);\n                }\n            }\n        }\n    }\n\n    free_stream(s);\n\n    return error;\n}\n\n/**************************************************************************//**\n * Sends a FramebufferUpdateRequest for the resize status state machine\n *\n * The state machine is used at the start of the connection to negotiate\n * a common geometry between the client and the server.\n *\n * The RFB community wiki contains the following paragraph not present\n * in RFC6143:-\n *\n *     Note that an empty area can still solicit a FramebufferUpdate\n *     even though that update will only contain pseudo-encodings\n *\n * This doesn't seem to be as widely supported as we would like at\n * present. We will always request at least a single pixel update to\n * avoid confusing the server.\n *\n * @param v VNC object\n * @return != 0 for error\n */\nstatic int\nsend_update_request_for_resize_status(struct vnc *v)\n{\n    int error = 0;\n    struct stream *s;\n    make_stream(s);\n    init_stream(s, 8192);\n\n    switch (v->resize_status)\n    {\n        case VRS_WAITING_FOR_FIRST_UPDATE:\n        case VRS_WAITING_FOR_RESIZE_CONFIRM:\n            /*\n             * Ask for an immediate, minimal update.\n             */\n            out_uint8(s, RFB_C2S_FRAMEBUFFER_UPDATE_REQUEST);\n            out_uint8(s, 0); /* incremental == 0 : Full update */\n            out_uint16_be(s, 0);\n            out_uint16_be(s, 0);\n            out_uint16_be(s, 1);\n            out_uint16_be(s, 1);\n            s_mark_end(s);\n            error = lib_send_copy(v, s);\n            break;\n\n        default:\n            /*\n             * Ask for a full update from the server\n             */\n            if (v->suppress_output == 0)\n            {\n                out_uint8(s, RFB_C2S_FRAMEBUFFER_UPDATE_REQUEST);\n                out_uint8(s, 0); /* incremental == 0 : Full update */\n                out_uint16_be(s, 0);\n                out_uint16_be(s, 0);\n                out_uint16_be(s, v->server_layout.total_width);\n                out_uint16_be(s, v->server_layout.total_height);\n                s_mark_end(s);\n                error = lib_send_copy(v, s);\n            }\n            break;\n    }\n\n    free_stream(s);\n\n    return error;\n}\n\n/**************************************************************************//**\n * Tests if extended desktop size rect is an initial geometry specification\n *\n * This should be x == 0, but the specification says to treat undefined\n * values as 0 also */\nstatic int\nrect_is_initial_geometry(int x, int y, int cx, int cy)\n{\n    return (x != 1 && x != 2);\n}\n\n/**************************************************************************//**\n * Tests if extended desktop size rect is a reply to a request from us\n */\nstatic int\nrect_is_reply_to_us(int x, int y, int cx, int cy)\n{\n    return (x == 1);\n}\n\n/**************************************************************************//**\n * Tests if extended desktop size rect is a general change.\n *\n * This happens when we are looking for a layout change that the\n * VNC server has reported as forwarded to the real desktop.\n */\nstatic int\nrect_is_general_change(int x, int y, int cx, int cy)\n{\n    return (x == 0);\n}\n\n/**************************************************************************//**\n * Handles the first framebuffer update from the server\n *\n * This is used to determine if the server supports resizes from\n * us. See The RFB community wiki for details.\n *\n * If the server does support resizing, we send our client geometry over.\n *\n * @param v VNC object\n * @return != 0 for error\n */\nstatic int\nlib_framebuffer_first_update(struct vnc *v)\n{\n    int error;\n    struct vnc_screen_layout layout = {0};\n\n    error = find_matching_extended_rect(v,\n                                        rect_is_initial_geometry,\n                                        NULL,\n                                        NULL,\n                                        &layout);\n    if (error == 0)\n    {\n        if (layout.count > 0)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"VNC server supports resizing\");\n            v->resize_supported = VRSS_SUPPORTED;\n            v->server_layout = layout;\n\n            /* Force the client geometry over to the server */\n            log_screen_layout(LOG_LEVEL_INFO, \"ClientLayout\", &v->client_layout);\n            log_screen_layout(LOG_LEVEL_INFO, \"OldServerLayout\", &layout);\n\n            /*\n             * If we've only got one screen, and the other side has\n             * only got one screen, we will preserve their screen ID\n             * and any flags.  This may prevent us sending an unwanted\n             * SetDesktopSize message if the screen dimensions are\n             * a match. We can't do this with more than one screen,\n             * as we have no way to map different IDs\n             */\n            if (layout.count == 1 && v->client_layout.count == 1)\n            {\n                LOG(LOG_LEVEL_DEBUG, \"VNC \"\n                    \"setting screen id to %d from server\",\n                    layout.s[0].id);\n\n                v->client_layout.s[0].id = layout.s[0].id;\n                v->client_layout.s[0].flags = layout.s[0].flags;\n            }\n\n            resize_server_to_client_layout(v);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_DEBUG, \"VNC server does not support resizing\");\n            v->resize_supported = VRSS_NOT_SUPPORTED;\n\n            /* Force client to same size as server */\n            LOG(LOG_LEVEL_DEBUG, \"Resizing client to server %dx%d\",\n                v->server_layout.total_width, v->server_layout.total_height);\n            error = resize_client_to_server(v, 0);\n            v->resize_status = VRS_DONE;\n        }\n    }\n\n    if (error == 0)\n    {\n        error = send_update_request_for_resize_status(v);\n    }\n\n    return error;\n}\n\n/**************************************************************************//**\n * Looks for a resize confirm in a framebuffer update request\n *\n * If the server supports resizes from us, this is used to find the\n * reply to our resize request. See The RFB community wiki for details.\n *\n * @param v VNC object\n * @return != 0 for error\n */\nstatic int\nlib_framebuffer_waiting_for_resize_confirm(struct vnc *v)\n{\n    int error;\n    struct vnc_screen_layout layout = {0};\n    int response_code = 0;\n\n    error = find_matching_extended_rect(v,\n                                        rect_is_reply_to_us,\n                                        NULL,\n                                        &response_code,\n                                        &layout);\n    if (error == 0)\n    {\n        if (layout.count > 0)\n        {\n            if (response_code == RFB_EDS_REQUEST_FORWARDED)\n            {\n                LOG(LOG_LEVEL_DEBUG, \"VNC_RESIZE: VNC server resize forwarded\");\n                log_screen_layout(LOG_LEVEL_INFO, \"ForwardedLayout\", &layout);\n                v->forward_timer =\n                    timers_oneshot_init(FORWARDED_RESIZE_TIMEOUT);\n                v->forwarded_layout = layout;\n            }\n            else\n            {\n                // The resize has either succeeded or failed\n                if (response_code == RFB_EDS_NO_ERROR)\n                {\n                    LOG(LOG_LEVEL_DEBUG, \"VNC_RESIZE:\"\n                        \" VNC server successfully resized\");\n                    log_screen_layout(LOG_LEVEL_INFO, \"NewLayout\", &layout);\n                    v->server_layout = layout;\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"VNC server resize failed - error code %d [%s]\",\n                        response_code,\n                        rfb_get_eds_status_msg(response_code));\n                    // This is awkward. The client has asked for a\n                    // specific size which we can't support.\n                    //\n                    // Currently we handle this by queueing a resize\n                    // to our supported size, and continuing with the\n                    // resize state machine in xrdp_mm.c\n                    LOG(LOG_LEVEL_WARNING, \"Resizing client to server\");\n                    error = resize_client_to_server(v, 0);\n                }\n\n                v->resize_status = VRS_DONE;\n                if (error == 0)\n                {\n                    // If this resize was requested by the client mid-session\n                    // (dynamic resize), we need to tell xrdp_mm that\n                    // it's OK to continue with the resize state machine.\n                    error = v->server_monitor_resize_done(v);\n                    if (error == 0)\n                    {\n                        error = send_update_request_for_resize_status(v);\n                    }\n                }\n            }\n        }\n    }\n\n\n    return error;\n}\n\n/**************************************************************************//**\n * Looks for the forwarded screen layout in a framebuffer update request\n *\n * Looks for an ExtendedDesktopSize rectangle following a notification\n * from the VNC server that the request has been forwarded to the real\n * desktop. See rfbproto/pfbproto#32 for more info.\n *\n * @param v VNC object\n * @return != 0 for error\n */\nstatic int\nlib_framebuffer_look_for_forwarded_layout(struct vnc *v)\n{\n    int error;\n    struct vnc_screen_layout layout = {0};\n    int x = 0;\n    int y = 0;\n\n    error = find_matching_extended_rect(v,\n                                        rect_is_general_change,\n                                        &x,\n                                        &y,\n                                        &layout);\n    if (error == 0)\n    {\n        if (layout.count > 0)\n        {\n            if (vnc_screen_layouts_equal(&layout, &v->forwarded_layout))\n            {\n                LOG(LOG_LEVEL_DEBUG,\n                    \"VNC_RESIZE: VNC server forwarded resize complete\");\n                free(v->forward_timer);\n                v->forward_timer = NULL;\n                v->server_layout = layout;\n                error = v->server_monitor_resize_done(v);\n                v->resize_status = VRS_DONE;\n            }\n            else\n            {\n                LOG(LOG_LEVEL_DEBUG,\n                    \"VNC_RESIZE: Ignored ExtendedDesktopSize %dx%d x=%d y=%d\",\n                    layout.total_width, layout.total_height, x, y);\n                // Delay for a little before we send another request for\n                // the size\n                g_sleep(100);\n            }\n\n            if (error == 0)\n            {\n                error = send_update_request_for_resize_status(v);\n            }\n        }\n    }\n\n    return error;\n}\n\n/******************************************************************************/\n/*\n * The VNC server has not actioned a forwarded resize request\n */\nstatic int\nforward_timer_expired(struct vnc *v)\n{\n    LOG(LOG_LEVEL_WARNING, \"VNC server forwarded resize timed out\");\n    LOG(LOG_LEVEL_DEBUG,\n        \"VNC_RESIZE: VNC server forwarded resize timed out\");\n    free(v->forward_timer);\n    v->forward_timer = NULL;\n    v->resize_status = VRS_DONE;\n\n    int rv = v->server_monitor_resize_done(v);\n    if (rv == 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Resizing client to server\");\n        rv = resize_client_to_server(v, 0);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nlib_framebuffer_update(struct vnc *v)\n{\n    char *d1;\n    char *d2;\n    char cursor_data[32 * (32 * 3)];\n    char cursor_mask[32 * (32 / 8)];\n    char text[256];\n    int num_recs;\n    int i;\n    int j;\n    int k;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int srcx;\n    int srcy;\n    unsigned int encoding;\n    int pixel;\n    int r = 0;\n    int g = 0;\n    int b = 0;\n    int error;\n    int need_size;\n    struct stream *s;\n    struct stream *pixel_s;\n    struct vnc_screen_layout layout = { 0 };\n\n    num_recs = 0;\n\n    make_stream(pixel_s);\n\n    make_stream(s);\n    init_stream(s, 8192);\n    error = trans_force_read_s(v->trans, s, 3);\n\n    if (error == 0)\n    {\n        in_uint8s(s, 1);\n        in_uint16_be(s, num_recs);\n        error = v->server_begin_update(v);\n    }\n\n    for (i = 0; i < num_recs; i++)\n    {\n        if (error != 0)\n        {\n            break;\n        }\n\n        init_stream(s, 8192);\n        error = trans_force_read_s(v->trans, s, 12);\n\n        if (error == 0)\n        {\n            in_uint16_be(s, x);\n            in_uint16_be(s, y);\n            in_uint16_be(s, cx);\n            in_uint16_be(s, cy);\n            in_uint32_be(s, encoding);\n\n            if (encoding == RFB_ENC_RAW)\n            {\n                need_size = cx * cy * get_bytes_per_pixel(v->server_bpp);\n                init_stream(pixel_s, need_size);\n                error = trans_force_read_s(v->trans, pixel_s, need_size);\n\n                if (error == 0)\n                {\n                    error = v->server_paint_rect(v, x, y, cx, cy, pixel_s->data, cx, cy, 0, 0);\n                }\n            }\n            else if (encoding == RFB_ENC_COPY_RECT)\n            {\n                init_stream(s, 8192);\n                error = trans_force_read_s(v->trans, s, 4);\n\n                if (error == 0)\n                {\n                    in_uint16_be(s, srcx);\n                    in_uint16_be(s, srcy);\n                    error = v->server_screen_blt(v, x, y, cx, cy, srcx, srcy);\n                }\n            }\n            else if (encoding == RFB_ENC_CURSOR)\n            {\n                g_memset(cursor_data, 0, 32 * (32 * 3));\n                g_memset(cursor_mask, 0, 32 * (32 / 8));\n                j = cx * cy * get_bytes_per_pixel(v->server_bpp);\n                k = ((cx + 7) / 8) * cy;\n                init_stream(s, j + k);\n                error = trans_force_read_s(v->trans, s, j + k);\n\n                if (error == 0)\n                {\n                    in_uint8p(s, d1, j);\n                    in_uint8p(s, d2, k);\n\n                    for (j = 0; j < 32; j++)\n                    {\n                        for (k = 0; k < 32; k++)\n                        {\n                            pixel = get_pixel_safe(d2, k, 31 - j, cx, cy, 1);\n                            set_pixel_safe(cursor_mask, k, j, 32, 32, 1, !pixel);\n\n                            if (pixel)\n                            {\n                                pixel = get_pixel_safe(d1, k, 31 - j, cx, cy, v->server_bpp);\n                                split_color(pixel, &r, &g, &b, v->server_bpp, v->palette);\n                                pixel = make_color(r, g, b, 24);\n                                set_pixel_safe(cursor_data, k, j, 32, 32, 24, pixel);\n                            }\n                        }\n                    }\n\n                    /* keep these in 32x32, vnc cursor can be a lot bigger */\n                    if (x > 31)\n                    {\n                        x = 31;\n                    }\n\n                    if (y > 31)\n                    {\n                        y = 31;\n                    }\n\n                    error = v->server_set_cursor(v, x, y, cursor_data, cursor_mask);\n                }\n            }\n            else if (encoding == RFB_ENC_DESKTOP_SIZE)\n            {\n                /* Server end has resized */\n                init_single_screen_layout(cx, cy, &v->server_layout);\n                error = resize_client_to_server(v, 1);\n            }\n            else if (encoding == RFB_ENC_EXTENDED_DESKTOP_SIZE)\n            {\n                layout.total_width = cx;\n                layout.total_height = cy;\n                error = read_extended_desktop_size_rect(v, &layout);\n                /* If this is a reply to a request from us, x == 1 */\n                LOG(LOG_LEVEL_DEBUG,\n                    \"VNC_RESIZE: Read ExtendedDesktopSize %dx%d x=%d y=%d\",\n                    layout.total_width, layout.total_height, x, y);\n                if (error == 0 && x != 1)\n                {\n                    if (!vnc_screen_layouts_equal(&v->server_layout, &layout))\n                    {\n                        v->server_layout = layout;\n                        log_screen_layout(LOG_LEVEL_INFO, \"NewServerLayout\",\n                                          &v->server_layout);\n                        error = resize_client_to_server(v, 1);\n                    }\n                }\n            }\n            else\n            {\n                g_sprintf(text, \"VNC error in lib_framebuffer_update encoding = %8.8x\",\n                          encoding);\n                v->server_msg(v, text, 1);\n            }\n        }\n    }\n\n    if (error == 0)\n    {\n        error = v->server_end_update(v);\n    }\n\n    if (error == 0)\n    {\n        if (v->suppress_output == 0)\n        {\n            init_stream(s, 8192);\n            out_uint8(s, RFB_C2S_FRAMEBUFFER_UPDATE_REQUEST);\n            out_uint8(s, 1); /* incremental == 1 : Changes only */\n            out_uint16_be(s, 0);\n            out_uint16_be(s, 0);\n            out_uint16_be(s, v->server_layout.total_width);\n            out_uint16_be(s, v->server_layout.total_height);\n            s_mark_end(s);\n            error = lib_send_copy(v, s);\n        }\n    }\n\n    free_stream(s);\n    free_stream(pixel_s);\n    return error;\n}\n\n/******************************************************************************/\nstatic int\nlib_palette_update(struct vnc *v)\n{\n    struct stream *s;\n    int first_color;\n    int num_colors;\n    int i;\n    int r;\n    int g;\n    int b;\n    int error;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    error = trans_force_read_s(v->trans, s, 5);\n\n    if (error == 0)\n    {\n        in_uint8s(s, 1);\n        in_uint16_be(s, first_color);\n        in_uint16_be(s, num_colors);\n        init_stream(s, 8192);\n        error = trans_force_read_s(v->trans, s, num_colors * 6);\n    }\n\n    if (error == 0)\n    {\n        for (i = 0; i < num_colors; i++)\n        {\n            in_uint16_be(s, r);\n            in_uint16_be(s, g);\n            in_uint16_be(s, b);\n            r = r >> 8;\n            g = g >> 8;\n            b = b >> 8;\n            v->palette[first_color + i] = (r << 16) | (g << 8) | b;\n        }\n\n        error = v->server_begin_update(v);\n    }\n\n    if (error == 0)\n    {\n        error = v->server_palette(v, v->palette);\n    }\n\n    if (error == 0)\n    {\n        error = v->server_end_update(v);\n    }\n\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstatic int\nlib_bell_trigger(struct vnc *v)\n{\n    int error;\n\n    error = v->server_bell_trigger(v);\n    return error;\n}\n\n/******************************************************************************/\nstatic int\nlib_mod_signal(struct vnc *v)\n{\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlib_mod_process_message(struct vnc *v, struct stream *s)\n{\n    char type;\n    int error;\n    char text[256];\n\n    in_uint8(s, type);\n\n    error = 0;\n    if (error == 0)\n    {\n        if (type == RFB_S2C_FRAMEBUFFER_UPDATE)\n        {\n            switch (v->resize_status)\n            {\n                case VRS_WAITING_FOR_FIRST_UPDATE:\n                    error = lib_framebuffer_first_update(v);\n                    break;\n\n                case VRS_WAITING_FOR_RESIZE_CONFIRM:\n                    if (v->forward_timer != NULL)\n                    {\n                        error = lib_framebuffer_look_for_forwarded_layout(v);\n                    }\n                    else\n                    {\n                        error = lib_framebuffer_waiting_for_resize_confirm(v);\n                    }\n                    break;\n\n                default:\n                    error = lib_framebuffer_update(v);\n            }\n        }\n        else if (type == RFB_S2C_SET_COLOUR_MAP_ENTRIES)\n        {\n            error = lib_palette_update(v);\n        }\n        else if (type == RFB_S2C_BELL)\n        {\n            error = lib_bell_trigger(v);\n        }\n        else if (type == RFB_S2C_SERVER_CUT_TEXT) /* clipboard */\n        {\n            LOG(LOG_LEVEL_DEBUG, \"VNC got clip data\");\n            error = vnc_clip_process_rfb_data(v);\n        }\n        else\n        {\n            g_sprintf(text, \"VNC unknown in lib_mod_process_message %d\", type);\n            v->server_msg(v, text, 1);\n        }\n    }\n\n    return error;\n}\n\n/******************************************************************************/\nstatic int\nlib_mod_start(struct vnc *v, int w, int h, int bpp)\n{\n    v->server_begin_update(v);\n    v->server_set_fgcolor(v, 0);\n    v->server_fill_rect(v, 0, 0, w, h);\n    v->server_end_update(v);\n    v->server_bpp = bpp;\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlib_data_in(struct trans *trans)\n{\n    struct vnc *self;\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lib_data_in:\");\n\n    if (trans == 0)\n    {\n        return 1;\n    }\n\n    self = (struct vnc *)(trans->callback_data);\n    s = trans_get_in_s(trans);\n\n    if (s == 0)\n    {\n        return 1;\n    }\n\n    if (lib_mod_process_message(self, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"lib_data_in: lib_mod_process_message failed\");\n        return 1;\n    }\n\n    init_stream(s, 0);\n\n    return 0;\n}\n\n/******************************************************************************/\n/**\n * Gets a reason string from the server\n *\n * Sometimes the server sends an error, which is a 32-bit word\n * followed by a string\n */\nstatic int\nget_reason_string(struct vnc *v, char buff[], unsigned int bufflen)\n{\n    int rv = 1;\n    struct stream *s;\n    make_stream(s);\n    init_stream(s, (int)(bufflen + 4));\n\n    if (trans_force_read_s(v->trans, s, 4) == 0)\n    {\n        unsigned int len;\n        in_uint32_be(s, len);\n        if (len < bufflen)\n        {\n            if (trans_force_read_s(v->trans, s, len) == 0)\n            {\n                in_uint8a(s, buff, len);\n                buff[len] = '\\0';\n                rv = 0;\n            }\n        }\n    }\n\n    free_stream(s);\n    return rv;\n}\n\n/******************************************************************************/\n/**\n * Negotiates the protocol version with the server\n *\n * @param v Module\n * @param[out] next_char Either security-type (version 3.3) or\n *                       number-of-security-types (versions > 3.3)\n * @return 0 for error, or protocol version > 0\n *\n * The protocol negotiation is overlapped with the security negotiation.\n * The result of the protocol negotiation is either good, in which case\n * 'next_char' contains a protocol-dependent value, or not-good, in which\n * case 'next_char' was set to zero and followed by a reason string. The\n * reason string is consumed here, and logged.\n *\n * See sections 7.1.1 and 7.1.2 of the RFB community wiki\n */\nstatic unsigned int\nnegotiate_protocol_version(struct vnc *v, unsigned char *next_char)\n{\n    struct stream *s =  NULL;\n    unsigned int major;\n    unsigned int minor;\n    unsigned int version;\n    int sec_type_size;\n\n    make_stream(s);\n    init_stream(s, 64);\n    if (trans_force_read_s(v->trans, s, 12) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error reading server version string\");\n        goto fail;\n    }\n\n    const char *p;\n    in_uint8p(s, p, 12); /* Moves s->p to end of string */\n    /* Expecting a string \"RFB ???.???\\n\" where ? is a digit */\n    if (*p++ != 'R' || *p++ != 'F' || *p++ != 'B' ||\n            *p++ != ' ' ||\n            !isdigit(*p++) || !isdigit(*p++) || !isdigit(*p++) ||\n            *p++ != '.' ||\n            !isdigit(*p++) || !isdigit(*p++) || !isdigit(*p++) ||\n            *p++ != '\\n')\n    {\n        LOG_HEXDUMP(LOG_LEVEL_ERROR, \"Invalid RFB string :\", s->data, 12);\n        goto fail;\n    }\n\n    /* Parse the major/minor versions in-place */\n    p = s->data;\n    major = (p[4] - '0') * 100 + (p[5] - '0') * 10 + (p[6] - '0');\n    minor = (p[8] - '0') * 100 + (p[9] - '0') * 10 + (p[10] - '0');\n    version = MAKE_RFBPROTO_VER(major, minor);\n\n    if (version == RFBPROTO_VER_3_3 ||\n            version == RFBPROTO_VER_3_7 ||\n            version == RFBPROTO_VER_3_8)\n    {\n        /* Versions documented in RFC6143 */\n        LOG(LOG_LEVEL_INFO,\n            \"RFB version %d.%d is supported by VNC server\",\n            major, minor);\n    }\n    else if (major == 3)\n    {\n        /* RFC6143 section 6 states that unknown 3.x versions should\n         * be treated as 3.3 */\n        LOG(LOG_LEVEL_INFO, \"RFB server reports version %d.%d.\",\n            major, minor);\n\n        minor = 3;\n        version = MAKE_RFBPROTO_VER(major, minor);\n        LOG(LOG_LEVEL_INFO, \"Proposing RFB version %d.%d to server\",\n            major, minor);\n    }\n    else if (major > 3)\n    {\n        /* This must be a new server version. Try to fall back to 3.8 */\n        LOG(LOG_LEVEL_INFO, \"RFB server reports version %d.%d.\",\n            major, minor);\n\n        major = 3;\n        minor = 8;\n        version = MAKE_RFBPROTO_VER(major, minor);\n        LOG(LOG_LEVEL_INFO, \"Proposing RFB version %d.%d to server\",\n            major, minor);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Server reports unsupported RFB version %d.%d\",\n            major, minor);\n        goto fail;\n    }\n\n    /* Send our proposed version back to the server */\n    /* s->p should be in the right place to mark the end\n     * of the string */\n    g_snprintf(s->data, s->size, \"RFB %03d.%03d\\n\", major, minor);\n    s_mark_end(s);\n\n    if (trans_force_write_s(v->trans, s) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error writing server version string\");\n        goto fail;\n    }\n\n    // Version 3.3 sends back a U32 rather than a U8 for the security\n    // type, even though the values it supports fit easily in a U8\n    sec_type_size = (version == RFBPROTO_VER_3_3) ? 4 : 1;\n    init_stream(s, 64);\n    if (trans_force_read_s(v->trans, s, sec_type_size) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Can't read negotiation result from server\");\n        goto fail;\n    }\n\n    // Read the next field, being careful to parse a whole U32 for\n    // version 3.3.\n    if (version == RFBPROTO_VER_3_3)\n    {\n        in_uint8s(s, 3); // Skip the three high octets\n    }\n    in_uint8(s, *next_char);\n\n    if (*next_char == 0)\n    {\n        char text[256];\n        // Server reported a reason for failure\n        if (get_reason_string(v, text, sizeof(text)) != 0)\n        {\n            g_snprintf(text, sizeof(text), \"No reason given\");\n        }\n        LOG(LOG_LEVEL_ERROR,\n            \"Version negotiation with server failed [%s]\", text);\n        goto fail;\n    }\n\n    free_stream(s);\n    return version;\n\nfail:\n    free_stream(s);\n    return 0;\n}\n\n/******************************************************************************/\n/**\n * Chooses the security type from a list sent by the server\n *\n * @param v Module\n * @param max_security_type Max security type to negotiate\n * @return 0 for error, or security type ( > 0)\n *\n * See section 7.1.2 of the RFB community wiki\n *\n * This call is only made for RFB version 3.7 onwards\n */\nstatic enum sec_type\nchoose_security_type(struct vnc *v, unsigned char number_of_security_types,\n                     enum sec_type max_security_type)\n{\n    enum sec_type sec_type = SEC_TYPE_INVALID;\n\n    struct stream *s =  NULL;\n    make_stream(s);\n    init_stream(s, UCHAR_MAX);\n\n    if (trans_force_read_s(v->trans, s, number_of_security_types) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't read list of security types from server\");\n    }\n    else\n    {\n        while (s_rem(s) > 0)\n        {\n            int j;\n            in_uint8(s, j);\n            enum sec_type st = (enum sec_type)j;\n            // Choose the highest security level that we support\n            if (st > max_security_type)\n            {\n                // If in development, log unsupported security types\n                LOG_DEVEL(LOG_LEVEL_INFO,\n                          \"Unsupported VNC security type %d was offered\", j);\n                continue;\n            }\n\n            if (st > sec_type)\n            {\n                sec_type = st;\n            }\n        }\n        if (sec_type == SEC_TYPE_INVALID)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"RFB server did not offer a compatible security type\");\n        }\n        else\n        {\n            init_stream(s, 1);\n            out_uint8(s, sec_type);\n            s_mark_end(s);\n            if (trans_force_write_s(v->trans, s) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Can't send security type to server\");\n                sec_type = SEC_TYPE_INVALID;\n            }\n        }\n    }\n\n    free_stream(s);\n    return sec_type;\n}\n\n/******************************************************************************/\n/**\n * Negotiates the security type with the server\n *\n * @param v Module\n * @param rfbproto_version RFB version negotiated with the server\n * @param next_char The character sent back (>0) when the protocol\n *                  version was agreed.\n * @return the negotiated security type (or SEC_TYPE_INVALID)\n */\nstatic enum sec_type\nnegotiate_security_type(struct vnc *v, unsigned int rfbproto_version,\n                        unsigned char next_char)\n{\n    char text[256];\n    enum sec_type sec_type;\n    // Whether the SecurityResult word is read from the server\n    // (RFB Community wiki section 7.1.3)\n    int check_sec_result = 1;\n\n    struct stream *s =  NULL;\n    make_stream(s);\n    init_stream(s, 64);\n\n    if (rfbproto_version == RFBPROTO_VER_3_3)\n    {\n        // The server has already chosen the security type\n        sec_type = (enum sec_type)next_char;\n    }\n    else\n    {\n        // The client chooses the security type based on what's offered\n        sec_type = choose_security_type(v, next_char, SEC_TYPE_MAX);\n    }\n\n    if (sec_type == SEC_TYPE_INVALID)\n    {\n        goto fail; // An error has already been logged\n    }\n\n    g_sprintf(text, \"VNC security type is %s\", SEC_TYPE_TO_STR(sec_type));\n    v->server_msg(v, text, 0);\n\n    switch (sec_type)\n    {\n        case SEC_TYPE_NONE:\n            if (rfbproto_version < RFBPROTO_VER_3_8)\n            {\n                check_sec_result = 0;\n            }\n            break;\n\n        case SEC_TYPE_VNC_AUTH:\n        {\n            init_stream(s, 64);\n            if (trans_force_read_s(v->trans, s, 16) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"Can't read VNC auth challenge from server\");\n                goto fail;\n            }\n            if (guid_is_set(&v->guid))\n            {\n                char guid_str[GUID_STR_SIZE];\n                guid_to_str(&v->guid, guid_str);\n                rfbHashEncryptBytes(s->data, guid_str);\n            }\n            else\n            {\n                rfbEncryptBytes(s->data, v->password);\n            }\n            s->p += 16;\n            s_mark_end(s);\n            if (trans_force_write_s(v->trans, s) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Can't send VNC auth response to server\");\n                goto fail;\n            }\n            break;\n        }\n        default:\n            // Shouldn't get here\n            LOG(LOG_LEVEL_ERROR, \"VNC unsupported security type %d\", sec_type);\n            goto fail;\n    }\n\n    if (check_sec_result)\n    {\n        /* RFB Community wiki 7.1.3 */\n        init_stream(s, 4);\n        if (trans_force_read_s(v->trans, s, 4) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Can't read SecurityResult from server\");\n            goto fail;\n        }\n\n        int i;\n        in_uint32_be(s, i);\n\n        if (i != 0)\n        {\n            char msg[256];\n            // Versions >= 3.8 of the protocol send a reason string at\n            // this point\n            if (rfbproto_version < RFBPROTO_VER_3_8 ||\n                    get_reason_string(v, text, sizeof(text)) != 0)\n            {\n                g_snprintf(text, sizeof(text), \"No reason given\");\n            }\n            g_snprintf(msg, sizeof(msg),\n                       \"VNC security negotiation failed [%s]\", text);\n            v->server_msg(v, msg, 0);\n            goto fail;\n        }\n    }\n\n    free_stream(s);\n    return sec_type;\n\nfail:\n    free_stream(s);\n    return SEC_TYPE_INVALID;\n}\n\n/******************************************************************************/\n/**\n * Sends the client init to the server (RFC6143 7.3.1)\n *\n * @param v Module\n * @param share_flag Share flag value to send to the server\n * @return 0 for success\n */\nstatic int\nsend_client_init(struct vnc *v, int share_flag)\n{\n    int rv;\n    struct stream *s;\n    make_stream(s);\n    init_stream(s, 64);\n    out_uint8(s, (share_flag) ? 1 : 0);\n    s_mark_end(s);\n    rv = trans_force_write_s(v->trans, s);\n    free_stream(s);\n    return rv;\n}\n\n/******************************************************************************/\n/**\n * Receives the server init from the server (RFC6143 7.3.2)\n *\n * @param v Module\n * @return 0 for success\n */\nstatic int\nreceive_server_init(struct vnc *v)\n{\n    int rv;\n    struct stream *s;\n    int width;\n    int height;\n    int name_len;\n    make_stream(s);\n    init_stream(s, 256);\n    rv = trans_force_read_s(v->trans, s, 2 + 2 + 16 + 4);\n    if (rv == 0)\n    {\n        in_uint16_be(s, width);\n        in_uint16_be(s, height);\n        in_uint8s(s, 16); // skip server pixel format\n        in_uint32_be(s, name_len);\n        init_stream(s, 256); // Reset stream to read name\n\n        if (name_len > 255 || name_len < 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Unexpected name length %d received\",\n                name_len);\n            rv = 1;\n        }\n        else if (trans_force_read_s(v->trans, s, name_len) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Error receiving desktop name\");\n            rv = 1;\n        }\n        else\n        {\n            g_memcpy(v->mod_name, s->data, name_len);\n            v->mod_name[name_len] = 0;\n\n            init_single_screen_layout(width, height, &v->server_layout);\n        }\n    }\n    free_stream(s);\n    return rv;\n}\n\n/******************************************************************************/\n/**\n * Sets the pixel format (RFC6143 7.5.1)\n *\n * @param v Module\n * @return 0 for success\n */\nstatic int\nset_pixel_format(struct vnc *v)\n{\n    struct\n    {\n        unsigned char bits_per_pixel;\n        unsigned char depth;\n        unsigned char true_color;\n        unsigned short red_max;\n        unsigned short green_max;\n        unsigned short blue_max;\n        unsigned char red_shift;\n        unsigned char green_shift;\n        unsigned char blue_shift;\n    } pixel_format = {0};\n\n    int rv;\n    struct stream *s;\n\n    if (v->server_bpp == 8)\n    {\n        pixel_format.bits_per_pixel = 8;\n        pixel_format.depth = 8;\n    }\n    else if (v->server_bpp == 15)\n    {\n        pixel_format.bits_per_pixel = 16;\n        pixel_format.depth = 15;\n        pixel_format.true_color = 1;\n        pixel_format.red_max = 31;\n        pixel_format.green_max = 31;\n        pixel_format.blue_max = 31;\n        pixel_format.red_shift = 10;\n        pixel_format.green_shift = 5;\n        pixel_format.blue_shift = 0;\n    }\n    else if (v->server_bpp == 16)\n    {\n        pixel_format.bits_per_pixel = 16;\n        pixel_format.depth = 16;\n        pixel_format.true_color = 1;\n        pixel_format.red_max = 31;\n        pixel_format.green_max = 63;\n        pixel_format.blue_max = 31;\n        pixel_format.red_shift = 11;\n        pixel_format.green_shift = 5;\n        pixel_format.blue_shift = 0;\n    }\n    else if (v->server_bpp == 24 || v->server_bpp == 32)\n    {\n        pixel_format.bits_per_pixel = 32;\n        pixel_format.depth = 24;\n        pixel_format.true_color = 1;\n        pixel_format.red_max = 255;\n        pixel_format.green_max = 255;\n        pixel_format.blue_max = 255;\n        pixel_format.red_shift = 16;\n        pixel_format.green_shift = 8;\n        pixel_format.blue_shift = 0;\n    }\n\n    make_stream(s);\n    init_stream(s, 64);\n    out_uint8(s, RFB_C2S_SET_PIXEL_FORMAT);\n    out_uint8s(s, 3); /* pad */\n    /* Now send the pixel data block */\n    out_uint8(s, pixel_format.bits_per_pixel);\n    out_uint8(s, pixel_format.depth);\n#if defined(B_ENDIAN)\n    out_uint8(s, 1); /* big endian */\n#else\n    out_uint8(s, 0); /* big endian */\n#endif\n    out_uint8(s, pixel_format.true_color);\n    out_uint16_be(s, pixel_format.red_max);\n    out_uint16_be(s, pixel_format.green_max);\n    out_uint16_be(s, pixel_format.blue_max);\n    out_uint8(s, pixel_format.red_shift);\n    out_uint8(s, pixel_format.green_shift);\n    out_uint8(s, pixel_format.blue_shift);\n    out_uint8s(s, 3); /* pad */\n    s_mark_end(s);\n    rv = trans_force_write_s(v->trans, s);\n    free_stream(s);\n    return rv;\n}\n\n/******************************************************************************/\n/**\n * Sets the encodings (RFC6143 7.5.2)\n *\n * @param v Module\n * @return 0 for success\n */\nstatic int\nset_encodings(struct vnc *v)\n{\n    encoding_type e[10];\n    unsigned int n = 0;\n    unsigned int i;\n\n    int rv;\n    struct stream *s;\n\n    /* These encodings are always supported */\n    e[n++] = RFB_ENC_RAW;\n    e[n++] = RFB_ENC_COPY_RECT;\n    e[n++] = RFB_ENC_CURSOR;\n    e[n++] = RFB_ENC_DESKTOP_SIZE;\n    if (v->enabled_encodings_mask & MSK_EXTENDED_DESKTOP_SIZE)\n    {\n        e[n++] = RFB_ENC_EXTENDED_DESKTOP_SIZE;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"VNC User disabled EXTENDED_DESKTOP_SIZE\");\n    }\n\n    make_stream(s);\n    init_stream(s, (int)(4 + sizeof(e)));\n    out_uint8(s, RFB_C2S_SET_ENCODINGS);\n    out_uint8(s, 0);\n    out_uint16_be(s, n); /* Number of encodings following */\n    for (i = 0 ; i < n; ++i)\n    {\n        out_uint32_be(s, e[i]);\n    }\n    s_mark_end(s);\n    rv = trans_force_write_s(v->trans, s);\n    free_stream(s);\n\n    return rv;\n}\n\n/******************************************************************************/\n/*\n  return error\n*/\nstatic int\nlib_mod_connect(struct vnc *v, int fd)\n{\n    char cursor_data[32 * (32 * 3)];\n    char cursor_mask[32 * (32 / 8)];\n    char con_port[256];\n    char text[256];\n    unsigned int rfbproto_version;\n    int error;\n    int socket_mode;\n\n    g_snprintf(con_port, sizeof(con_port), \"%s\", v->port);\n\n    /* check if bpp is supported for rdp connection */\n    switch (v->server_bpp)\n    {\n        case 8:\n        case 15:\n        case 16:\n        case 24:\n        case 32:\n            break;\n        default:\n            v->server_msg(v, \"VNC error - only supporting 8, 15, 16, 24 and 32 \"\n                          \"bpp rdp connections\", 0);\n            return 1;\n    }\n\n    /* Assume a TCP-port based connection (i.e. not a UDS connection)\n     * if the port is not an absolute path */\n    if (con_port[0] == '/')\n    {\n        socket_mode = TRANS_MODE_UNIX;\n    }\n    else\n    {\n        socket_mode = TRANS_MODE_TCP;\n        if (g_strcmp(v->ip, \"\") == 0)\n        {\n            v->server_msg(v, \"VNC error - no IP set for TCP connection\", 0);\n            goto fail;\n        }\n    }\n\n    v->trans = trans_create(socket_mode, 8 * 8192, 8192);\n    if (v->trans == 0)\n    {\n        v->server_msg(v, \"VNC error: trans_create() failed\", 0);\n        goto fail;\n    }\n\n    v->sck_closed = 0;\n    if (v->delay_ms > 0)\n    {\n        g_sprintf(text, \"Waiting %d ms for VNC to start...\", v->delay_ms);\n        v->server_msg(v, text, 0);\n        g_sleep(v->delay_ms);\n    }\n\n    v->trans->si = v->si;\n    v->trans->my_source = XRDP_SOURCE_MOD;\n\n    if (fd >= 0)\n    {\n        v->trans->sck = fd;\n        v->trans->status = TRANS_STATUS_UP; /* ok */\n        v->trans->type1 = TRANS_TYPE_CLIENT; /* client */\n        error = 0;\n    }\n    else\n    {\n        error = trans_connect(v->trans, v->ip, con_port, 3000);\n    }\n\n    if (error != 0)\n    {\n        g_snprintf(text, sizeof(text), \"Error connecting to VNC server [%s]\",\n                   g_get_strerror());\n        v->server_msg(v, text, 0);\n        goto fail;\n    }\n\n    if (socket_mode == TRANS_MODE_TCP)\n    {\n        g_sprintf(text, \"VNC connected to TCP %s %s\", v->ip, con_port);\n    }\n    else\n    {\n        g_sprintf(text, \"VNC connected to local socket %s\", con_port);\n    }\n    v->server_msg(v, text, 0);\n\n    /* protocol version */\n    unsigned char next_char;\n    if ((rfbproto_version = negotiate_protocol_version(v, &next_char)) == 0)\n    {\n        v->server_msg(v, \"Error negotiating VNC version\", 0);\n        goto fail;\n    }\n\n    if (negotiate_security_type(v, rfbproto_version, next_char) ==\n            SEC_TYPE_INVALID)\n    {\n        // An error has been logged\n        v->server_msg(v, \"Error negotiating security type\", 0);\n        goto fail;\n    }\n\n    if (send_client_init(v, 1) != 0)\n    {\n        v->server_msg(v, \"Error sending client init\", 0);\n        goto fail;\n    }\n\n    if (receive_server_init(v) != 0)\n    {\n        v->server_msg(v, \"Error receiving server init\", 0);\n        goto fail;\n    }\n\n    if (set_pixel_format(v) != 0)\n    {\n        v->server_msg(v, \"Error setting pixel format\", 0);\n        goto fail;\n    }\n\n    if (set_encodings(v) != 0)\n    {\n        v->server_msg(v, \"Error setting encodings\", 0);\n        goto fail;\n    }\n\n    v->resize_supported = VRSS_UNKNOWN;\n    v->resize_status = VRS_WAITING_FOR_FIRST_UPDATE;\n    if (send_update_request_for_resize_status(v) != 0)\n    {\n        v->server_msg(v, \"Error sending resize support request\", 0);\n        goto fail;\n    }\n\n    /* set almost null cursor, this is the little dot cursor */\n    g_memset(cursor_data, 0, 32 * (32 * 3));\n    g_memset(cursor_data + (32 * (32 * 3) - 1 * 32 * 3), 0xff, 9);\n    g_memset(cursor_data + (32 * (32 * 3) - 2 * 32 * 3), 0xff, 9);\n    g_memset(cursor_data + (32 * (32 * 3) - 3 * 32 * 3), 0xff, 9);\n    g_memset(cursor_mask, 0xff, 32 * (32 / 8));\n    if (v->server_set_cursor(v, 3, 3, cursor_data, cursor_mask) != 0)\n    {\n        v->server_msg(v, \"Error sending cursor\", 0);\n        goto fail;\n    }\n\n    v->server_msg(v, \"VNC connection complete, connected ok\", 0);\n    vnc_clip_open_clip_channel(v);\n\n    v->trans->trans_data_in = lib_data_in;\n    v->trans->header_size = 1;\n    v->trans->callback_data = v;\n\n    return 0;\n\nfail:\n    trans_delete(v->trans);\n    v->trans = NULL;\n    v->server_msg(v, \"VNC error - problem connecting\", 0);\n\n    return 1;\n}\n\n/******************************************************************************/\nstatic int\nlib_mod_end(struct vnc *v)\n{\n    if (v->vnc_desktop != 0)\n    {\n    }\n\n    return 0;\n}\n\n/**************************************************************************//**\n * Initialises the client layout from the Windows monitor definition.\n *\n * @param v VNC module\n * @param [in] width session width\n * @param [in] height session height\n * @param [in] num_monitors (can be 0, meaning one monitor)\n * @param [in] monitors Monitor definitions for num_monitors > 0\n */\nstatic void\ninit_client_layout(struct vnc *v,\n                   int width, int height,\n                   int num_monitors,\n                   const struct monitor_info *monitors)\n{\n    struct vnc_screen_layout *layout = &v->client_layout;\n    if (!v->multimon_configured || num_monitors < 1)\n    {\n        init_single_screen_layout(width, height, layout);\n    }\n    else\n    {\n        layout->total_width = width;\n        layout->total_height = height;\n        layout->count = num_monitors;\n\n        unsigned int i;\n        for (i = 0 ; i < layout->count; ++i)\n        {\n            layout->s[i].id = i;\n            layout->s[i].x = monitors[i].left;\n            layout->s[i].y = monitors[i].top;\n            layout->s[i].width = monitors[i].right - monitors[i].left + 1;\n            layout->s[i].height = monitors[i].bottom - monitors[i].top + 1;\n            layout->s[i].flags = 0;\n        }\n    }\n}\n\n/******************************************************************************/\nstatic int\nlib_mod_set_param(struct vnc *v, const char *name, const char *value)\n{\n    if (g_strcasecmp(name, \"username\") == 0)\n    {\n        g_strncpy(v->username, value, 255);\n    }\n    else if (g_strcasecmp(name, \"password\") == 0)\n    {\n        g_strncpy(v->password, value, 255);\n    }\n    else if (g_strcasecmp(name, \"ip\") == 0)\n    {\n        g_strncpy(v->ip, value, 255);\n    }\n    else if (g_strcasecmp(name, \"port\") == 0)\n    {\n        g_strncpy(v->port, value, 255);\n    }\n    else if (g_strcasecmp(name, \"keylayout\") == 0)\n    {\n        v->keylayout = g_atoi(value);\n    }\n    else if (g_strcasecmp(name, \"delay_ms\") == 0)\n    {\n        v->delay_ms = g_atoi(value);\n    }\n    else if (g_strcasecmp(name, \"guid\") == 0)\n    {\n        v->guid = *(struct guid *)value;\n    }\n    else if (g_strcasecmp(name, \"disabled_encodings_mask\") == 0)\n    {\n        v->enabled_encodings_mask = (unsigned int)~g_atoi(value);\n    }\n    else if (g_strcasecmp(name, \"client_info\") == 0)\n    {\n        const struct xrdp_client_info *client_info =\n            (const struct xrdp_client_info *) value;\n\n        v->multimon_configured = client_info->multimon;\n\n        /* Save monitor information from the client\n         * Use minfo_wm, as this is normalised for a top-left of (0,0)\n         * as required by RFC6143 */\n        init_client_layout(v,\n                           client_info->display_sizes.session_width,\n                           client_info->display_sizes.session_height,\n                           client_info->display_sizes.monitorCount,\n                           client_info->display_sizes.minfo_wm);\n        log_screen_layout(LOG_LEVEL_DEBUG, \"client_info\", &v->client_layout);\n    }\n\n\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_get_wait_objs(struct vnc *v, tbus *read_objs, int *rcount,\n                      tbus *write_objs, int *wcount, int *timeout)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lib_mod_get_wait_objs:\");\n\n    if (v != 0)\n    {\n        if (v->trans != 0)\n        {\n            trans_get_wait_objs_rw(v->trans, read_objs, rcount,\n                                   write_objs, wcount, timeout);\n        }\n\n        // Update timeout with any active timers\n        unsigned int now = g_get_elapsed_ms();\n        timers_oneshot_update_poll(v->forward_timer, now, timeout);\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_check_wait_objs(struct vnc *v)\n{\n    int rv;\n\n    rv = 0;\n    if (v != 0)\n    {\n        if (v->trans != 0)\n        {\n            if ((rv = trans_check_wait_objs(v->trans)) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"VNC server closed connection\");\n            }\n            else\n            {\n                // Check timers\n                unsigned int now = g_get_elapsed_ms();\n                if (timers_oneshot_get_remaining(v->forward_timer, now) == 0)\n                {\n                    rv = forward_timer_expired(v);\n                }\n            }\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_frame_ack(struct vnc *v, int flags, int frame_id)\n{\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_suppress_output(struct vnc *v, int suppress,\n                        int left, int top, int right, int bottom)\n{\n    int error;\n    struct stream *s;\n\n    error = 0;\n    v->suppress_output = suppress;\n    if (suppress == 0)\n    {\n        make_stream(s);\n        init_stream(s, 8192);\n        out_uint8(s, RFB_C2S_FRAMEBUFFER_UPDATE_REQUEST);\n        out_uint8(s, 0); /* incremental == 0 : Full contents */\n        out_uint16_be(s, 0);\n        out_uint16_be(s, 0);\n        out_uint16_be(s, v->server_layout.total_width);\n        out_uint16_be(s, v->server_layout.total_height);\n        s_mark_end(s);\n        error = lib_send_copy(v, s);\n        free_stream(s);\n    }\n    return error;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_server_version_message(struct vnc *v)\n{\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_server_monitor_resize(struct vnc *v, int width, int height,\n                              int num_monitors,\n                              const struct monitor_info *monitors,\n                              int *in_progress)\n{\n    int error;\n    *in_progress = 0;\n    init_client_layout(v, width, height, num_monitors, monitors);\n\n    if ((error = resize_server_to_client_layout(v)) == 0)\n    {\n        // If we're waiting for a confirmation, send an update request.\n        // According to the spec this should not be needed, but\n        // it works around a buggy VNC server not sending an\n        // ExtendedDesktopSize rectangle if the desktop change is\n        // small (eg. same dimensions, but 2 monitors -> 1 monitor)\n        if (v->resize_status == VRS_WAITING_FOR_RESIZE_CONFIRM &&\n                (error = send_update_request_for_resize_status(v)) == 0)\n        {\n            *in_progress = 1;\n        }\n    }\n\n    return error;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_server_monitor_full_invalidate(struct vnc *v, int param1, int param2)\n{\n    return 0;\n}\n\n/******************************************************************************/\ntintptr EXPORT_CC\nmod_init(void)\n{\n    struct vnc *v;\n\n    v = (struct vnc *)g_malloc(sizeof(struct vnc), 1);\n    /* set client functions */\n    v->size = sizeof(struct vnc);\n    v->version = CURRENT_MOD_VER;\n    v->handle = (tintptr) v;\n    v->mod_connect = lib_mod_connect;\n    v->mod_start = lib_mod_start;\n    v->mod_event = lib_mod_event;\n    v->mod_signal = lib_mod_signal;\n    v->mod_end = lib_mod_end;\n    v->mod_set_param = lib_mod_set_param;\n    v->mod_get_wait_objs = lib_mod_get_wait_objs;\n    v->mod_check_wait_objs = lib_mod_check_wait_objs;\n    v->mod_frame_ack = lib_mod_frame_ack;\n    v->mod_suppress_output = lib_mod_suppress_output;\n    v->mod_server_monitor_resize = lib_mod_server_monitor_resize;\n    v->mod_server_monitor_full_invalidate = lib_mod_server_monitor_full_invalidate;\n    v->mod_server_version_message = lib_mod_server_version_message;\n\n    /* Member variables */\n    v->enabled_encodings_mask = -1;\n    vnc_clip_init(v);\n\n    return (tintptr) v;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nmod_exit(tintptr handle)\n{\n    struct vnc *v = (struct vnc *) handle;\n    LOG(LOG_LEVEL_TRACE, \"VNC mod_exit\");\n\n    if (v == 0)\n    {\n        return 0;\n    }\n    trans_delete(v->trans);\n    vnc_clip_exit(v);\n    g_free(v);\n    return 0;\n}\n"
  },
  {
    "path": "vnc/vnc.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libvnc\n */\n\n#ifndef VNC_H\n#define VNC_H\n\n/* include other h files */\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"os_calls.h\"\n#include \"defines.h\"\n#include \"guid.h\"\n#include \"ms-rdpbcgr.h\"\n\n#define CURRENT_MOD_VER 4\n\nstruct timers_oneshot;\n\n/* Screen used for ExtendedDesktopSize / Set DesktopSize */\nstruct vnc_screen\n{\n    int id;\n    int x;\n    int y;\n    int width;\n    int height;\n    int flags;\n};\n\nstruct vnc_screen_layout\n{\n    int total_width;\n    int total_height;\n    unsigned int count;\n    /* For comparison, screens are sorted in x, y, width, height) order */\n    struct vnc_screen s[CLIENT_MONITOR_DATA_MAXIMUM_MONITORS];\n};\n\n/**\n * Keep track of resize status at start of connection\n */\nenum vnc_resize_status\n{\n    VRS_WAITING_FOR_FIRST_UPDATE,\n    VRS_WAITING_FOR_RESIZE_CONFIRM,\n    VRS_DONE\n};\n\nenum vnc_resize_support_status\n{\n    VRSS_NOT_SUPPORTED,\n    VRSS_SUPPORTED,\n    VRSS_UNKNOWN\n};\n\nstruct source_info;\nstruct xrdp_client_info;\n\n/* Defined in vnc_clip.c */\nstruct vnc_clipboard_data;\n\n/* Defined in xrdp_client_info.h */\nstruct monitor_info;\n\nstruct vnc\n{\n    int size; /* size of this struct */\n    int version; /* internal version */\n    /* client functions */\n    int (*mod_start)(struct vnc *v, int w, int h, int bpp);\n    int (*mod_connect)(struct vnc *v, int fd);\n    int (*mod_event)(struct vnc *v, int msg, long param1, long param2,\n                     long param3, long param4);\n    int (*mod_signal)(struct vnc *v);\n    int (*mod_end)(struct vnc *v);\n    int (*mod_set_param)(struct vnc *v, const char *name, const char *value);\n    int (*mod_session_change)(struct vnc *v, int, int);\n    int (*mod_get_wait_objs)(struct vnc *v, tbus *read_objs, int *rcount,\n                             tbus *write_objs, int *wcount, int *timeout);\n    int (*mod_check_wait_objs)(struct vnc *v);\n    int (*mod_frame_ack)(struct vnc *v, int flags, int frame_id);\n    int (*mod_suppress_output)(struct vnc *v, int suppress,\n                               int left, int top, int right, int bottom);\n    int (*mod_server_monitor_resize)(struct vnc *v,\n                                     int width, int height,\n                                     int num_monitors,\n                                     const struct monitor_info *monitors,\n                                     int *in_progress);\n    int (*mod_server_monitor_full_invalidate)(struct vnc *v,\n            int width, int height);\n    int (*mod_server_version_message)(struct vnc *v);\n    tintptr mod_dumby[100 - 14]; /* align, 100 minus the number of mod\n                                  functions above */\n    /* server functions */\n    int (*server_begin_update)(struct vnc *v);\n    int (*server_end_update)(struct vnc *v);\n    int (*server_fill_rect)(struct vnc *v, int x, int y, int cx, int cy);\n    int (*server_screen_blt)(struct vnc *v, int x, int y, int cx, int cy,\n                             int srcx, int srcy);\n    int (*server_paint_rect)(struct vnc *v, int x, int y, int cx, int cy,\n                             char *data, int width, int height, int srcx, int srcy);\n    int (*server_set_cursor)(struct vnc *v, int x, int y, char *data, char *mask);\n    int (*server_palette)(struct vnc *v, int *palette);\n    int (*server_msg)(struct vnc *v, const char *msg, int code);\n    int (*server_is_term)(void);\n    int (*server_set_clip)(struct vnc *v, int x, int y, int cx, int cy);\n    int (*server_reset_clip)(struct vnc *v);\n    int (*server_set_fgcolor)(struct vnc *v, int fgcolor);\n    int (*server_set_bgcolor)(struct vnc *v, int bgcolor);\n    int (*server_set_opcode)(struct vnc *v, int opcode);\n    int (*server_set_mixmode)(struct vnc *v, int mixmode);\n    int (*server_set_brush)(struct vnc *v, int x_origin, int y_origin,\n                            int style, char *pattern);\n    int (*server_set_pen)(struct vnc *v, int style,\n                          int width);\n    int (*server_draw_line)(struct vnc *v, int x1, int y1, int x2, int y2);\n    int (*server_add_char)(struct vnc *v, int font, int character,\n                           int offset, int baseline,\n                           int width, int height, char *data);\n    int (*server_draw_text)(struct vnc *v, int font,\n                            int flags, int mixmode, int clip_left, int clip_top,\n                            int clip_right, int clip_bottom,\n                            int box_left, int box_top,\n                            int box_right, int box_bottom,\n                            int x, int y, char *data, int data_len);\n    int (*client_monitor_resize)(struct vnc *v, int width, int height,\n                                 int num_monitors,\n                                 const struct monitor_info *monitors);\n    int (*server_monitor_resize_done)(struct vnc *v);\n    int (*server_get_channel_count)(struct vnc *v);\n    int (*server_query_channel)(struct vnc *v, int index,\n                                char *channel_name,\n                                int *channel_flags);\n    int (*server_get_channel_id)(struct vnc *v, const char *name);\n    int (*server_send_to_channel)(struct vnc *v, int channel_id,\n                                  char *data, int data_len,\n                                  int total_data_len, int flags);\n    int (*server_bell_trigger)(struct vnc *v);\n    int (*server_chansrv_in_use)(struct vnc *v);\n    void (*server_init_xkb_layout)(struct vnc *v,\n                                   struct xrdp_client_info *client_info);\n    tintptr server_dumby[100 - 29]; /* align, 100 minus the number of server\n                                     functions above */\n    /* common */\n    tintptr handle; /* pointer to self as long */\n    tintptr wm;\n    tintptr painter;\n    struct source_info *si;\n    /* mod data */\n    int server_bpp;\n    char mod_name[256];\n    int mod_mouse_state;\n    int palette[256];\n    int vnc_desktop;\n    char username[256];\n    char password[256];\n    char ip[256];\n    char port[256];\n    int sck_closed;\n    int shift_state; /* 0 up, 1 down */\n    int ignore_next_numlock; /* Used in pause key processing */\n    int keylayout;\n    int clip_chanid;\n    struct vnc_clipboard_data *vc;\n    int delay_ms;\n    struct trans *trans;\n    struct guid guid;\n    int suppress_output;\n    unsigned int enabled_encodings_mask;\n    /* Resizeable support */\n    int multimon_configured;\n    struct vnc_screen_layout client_layout;\n    struct vnc_screen_layout server_layout;\n    enum vnc_resize_status resize_status;\n    enum vnc_resize_support_status resize_supported;\n    /* forwarded resize */\n    // This occurs when the VNC server forwards a resize request\n    // elsewhere (RFB_EDS_REQUEST_FORWARDED)\n    struct timers_oneshot *forward_timer;\n    struct vnc_screen_layout forwarded_layout;\n};\n\n/*\n * Functions\n */\nint\nlib_send_copy(struct vnc *v, struct stream *s);\nint\nskip_trans_bytes(struct trans *trans, unsigned int bytes);\n\n#endif /* VNC_H */\n"
  },
  {
    "path": "vnc/vnc_clip.c",
    "content": "\n/* startup_complete is only ever set if we're using the VNC clip facility *//**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libvnc\n *\n * The message definitions used in this source file can be found mostly\n * in RFC6143 - \"The Remote Framebuffer Protocol\".\n *\n * The clipboard messages from the RDP client side are mostly\n * described in [MS-RDPECLIP]\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"arch.h\"\n#include \"vnc.h\"\n#include \"vnc_clip.h\"\n#include \"string_calls.h\"\n#include \"ssl_calls.h\"\n#include \"rfb.h\"\n#include \"log.h\"\n#include \"trans.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"ms-rdpeclip.h\"\n#include \"xrdp_constants.h\"\n\n/**\n * The formats we advertise as supported to the RDP client\n */\nstatic const int\ng_supported_formats[] =\n{\n    CF_UNICODETEXT,\n    CF_LOCALE,\n    CF_TEXT,\n    /* Don't advertise CF_OEMTEXT - anything other than ASCII will be broken */\n    /* CF_OEMTEXT, */\n    0\n};\n\n/**\n * Data private to the VNC clipboard\n *\n * Note that this doesn't include the clip channel ID, as vnc.c needs\n * this to redirect virtual channel PDUs to this module */\nstruct vnc_clipboard_data\n{\n    struct stream *rfb_clip_s;\n    int requested_clip_format; /* Last requested text format */\n    int active_data_requests; /* Number of outstanding FORMAT_DATA_REQUESTs */\n    struct stream *dechunker_s; /* Dechunker for the RDP clip channel */\n    int capability_version;  /* Clipboard virt channel extension version */\n    int capability_flags;    /* Channel capability flags */\n    bool_t startup_complete; /* is the startup sequence done (1.3.2.1) */\n};\n\n/**\n * Summarise a stream contents in a way which allows two streams to\n * be easily compared\n */\nstruct stream_characteristics\n{\n    char digest[16];\n    int length;\n};\n\n#ifdef USE_DEVEL_LOGGING\n/***************************************************************************//**\n * Convert a CF_ constant to text\n *\n * @param CF_xxx constant\n * @param buff Scratchpad for storing a temporary string in\n * @param bufflen Length of the above\n *\n * @return string representation\n */\nstatic const char *\ncf2text(int cf, char *buff, int bufflen)\n{\n    const char *result;\n\n    switch (cf)\n    {\n        case CF_UNICODETEXT:\n            result = \"CF_UNICODETEXT\";\n            break;\n\n        case CF_LOCALE:\n            result = \"CF_LOCALE\";\n            break;\n\n        case CF_TEXT:\n            result = \"CF_TEXT\";\n            break;\n\n        case CF_OEMTEXT:\n            result = \"CF_OEMTEXT\";\n            break;\n\n        default:\n            g_snprintf(buff, bufflen, \"CF_<0x%08x>\", cf);\n            result = buff;\n    };\n\n    return result;\n}\n#endif /* USE_DEVEL_LOGGING */\n\n/***************************************************************************//**\n * Adds a CLIPRDR_HEADER ([MS-RDPECLIP] 2.2.1) to the data stream\n *\n * The location of the length is stored in the unused 'channel_hdr' field\n * of the data stream. When send_stream_to_clip_channel() is called,\n * we can use update the data length.\n *\n * @param s Output stream\n * @param msg_type Message Type\n * @param msg_flags Message flags\n */\nstatic void\nout_cliprdr_header(struct stream *s, int msg_type, int msg_flags)\n{\n    out_uint16_le(s, msg_type);\n    out_uint16_le(s, msg_flags);\n    /* Save the datalen location so we can update it later */\n    s_push_layer(s, channel_hdr, 4);\n}\n\n/***************************************************************************//**\n * Sends the contents of a stream buffer to the clipboard channel\n *\n * Stream contents are chunked appropriately if they are too big to\n * fit in a single PDU\n *\n * The stream object cliprdr datalen header field is updated by this call.\n *\n * @param v VNC object\n * @param s stream buffer\n *\n * @pre stream buffer must have been initialised with a call to\n *      out_cliprdr_header()\n * @pre Stream is terminated with s_mark_end()\n */\nstatic int\nsend_stream_to_clip_channel(struct vnc *v, struct stream *s)\n{\n    int rv = 0;\n    int datalen = 0; /* cliprdr PDU datalen field */\n    int pos = 0;\n    int pdu_len = 0; /* Length of channel PDU */\n    int total_data_len = (int)(s->end - s->data);\n    int flags;\n    int msg_type;\n    int msg_flags;\n\n    /* Use the pointer saved by out_cliprdr_header() to\n     * write the cliprdr PDU length */\n    s_pop_layer(s, channel_hdr);\n    datalen = (int)(s->end - s->p) - 4;\n    out_uint32_le(s, datalen);\n\n    /* Read the other fields of the cliprdr header for logging */\n    s->p = s->data;\n    in_uint16_le(s, msg_type);\n    in_uint16_le(s, msg_flags);\n    LOG(LOG_LEVEL_DEBUG, \"Sending cliprdr PDU type:%s flags:%d datalen:%d\",\n        CB_PDUTYPE_TO_STR(msg_type), msg_flags, datalen);\n\n\n    for ( ; rv == 0 && pos < total_data_len ; pos += pdu_len)\n    {\n        pdu_len = MIN(CHANNEL_CHUNK_LENGTH, (total_data_len - pos));\n\n        /* Determine chunking flags for this PDU (MS-RDPBCGR 3.1.5.2.1) */\n        if (pos == 0)\n        {\n            if ((pos + pdu_len) == total_data_len)\n            {\n                /* Only one chunk */\n                flags = (XR_CHANNEL_FLAG_FIRST | XR_CHANNEL_FLAG_LAST);\n            }\n            else\n            {\n                /* First chunk of several */\n                flags = (XR_CHANNEL_FLAG_FIRST | XR_CHANNEL_FLAG_SHOW_PROTOCOL);\n            }\n        }\n        else if ((pos + pdu_len) == total_data_len)\n        {\n            /* Last chunk of several */\n            flags = (XR_CHANNEL_FLAG_LAST | XR_CHANNEL_FLAG_SHOW_PROTOCOL);\n        }\n        else\n        {\n            /* Intermediate chunk of several */\n            flags = XR_CHANNEL_FLAG_SHOW_PROTOCOL;\n        }\n        rv = v->server_send_to_channel(v, v->clip_chanid,\n                                       s->data + pos, pdu_len,\n                                       total_data_len, flags);\n    }\n\n    return rv;\n}\n\n/***************************************************************************//**\n * Counts the occurrences of a character in a stream\n * @param s stream\n * @param c character\n * @return occurrence count\n */\nstatic int\nchar_count_in(const struct stream *s, char c)\n{\n    int rv = 0;\n    const char *p = s->data;\n    const char *end = s->end;\n\n    while ((p = g_strnchr(p, c, end - p)) != NULL)\n    {\n        ++rv;\n        ++p; /* Skip counted character */\n    }\n\n    return rv;\n}\n\n/***************************************************************************//**\n * Searches a Format List PDU for a preferred text format\n *\n * On entry, the stream contains a formatListData object\n *\n * @param v VNC module\n * @param msg_flags clipHeader msgFlags field\n * @param s formatListData object.\n * @return Preferred text format, or 0 if not found\n */\nstatic int\nfind_preferred_text_format(struct vnc *v, int msg_flags, struct stream *s)\n{\n    int seen_cf_unicodetext = 0;\n    int seen_cf_text = 0;\n    int format_id;\n#ifdef USE_DEVEL_LOGGING\n    char scratch[64];\n#endif\n\n    while (s_check_rem(s, 4))\n    {\n        in_uint32_le(s, format_id);\n\n        if ((v->vc->capability_flags & CB_USE_LONG_FORMAT_NAMES) == 0)\n        {\n            /* Short format name */\n            int skip = MIN(s_rem(s), 32);\n            in_uint8s(s, skip);\n        }\n        else\n        {\n            /* Skip a wsz string */\n            int wc = 1;\n            while (s_check_rem(s, 2) && wc != 0)\n            {\n                in_uint16_le(s, wc);\n            }\n        }\n\n        LOG_DEVEL(LOG_LEVEL_INFO, \"VNC: Format id %s available\"\n                  \" from RDP client\",\n                  cf2text(format_id, scratch, sizeof(scratch)));\n\n        switch (format_id)\n        {\n            case CF_UNICODETEXT:\n                seen_cf_unicodetext = 1;\n                break;\n\n            case CF_TEXT:\n                seen_cf_text = 1;\n                break;\n        }\n    }\n\n    /* Prefer Unicode (UTF-16), as it's most easily converted to\n     * the ISO-8859-1 supported by the VNC clipboard */\n    return\n        (seen_cf_unicodetext != 0 ? CF_UNICODETEXT :\n         seen_cf_text != 0 ? CF_TEXT :\n         /* Default */ 0);\n}\n\n/******************************************************************************/\nstatic int\nhandle_cb_format_list(struct vnc *v, int msg_flags, struct stream *s)\n{\n    struct stream *out_s;\n    int format;\n    int rv = 0;\n#ifdef USE_DEVEL_LOGGING\n    char scratch[64];\n#endif\n\n    /* This is the last stage of the startup sequence in MS-RDPECLIP 1.3.2.1,\n     * although it does occur at other times */\n    v->vc->startup_complete = 1;\n\n    make_stream(out_s);\n\n    /* Reply to the caller */\n    init_stream(out_s, 64);\n    out_cliprdr_header(out_s, CB_FORMAT_LIST_RESPONSE, CB_RESPONSE_OK);\n    s_mark_end(out_s);\n    send_stream_to_clip_channel(v, out_s);\n\n    /* Send a CB_DATA_REQUEST message to the cliprdr channel,\n     * if a suitable text format is available */\n    if ((format = find_preferred_text_format(v, msg_flags, s)) != 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO,\n                  \"Asking RDP client for clip data format=%s\",\n                  cf2text(format, scratch, sizeof(scratch)));\n        v->vc->requested_clip_format = format;\n        ++v->vc->active_data_requests;\n        init_stream(out_s, 64);\n        out_cliprdr_header(out_s, CB_FORMAT_DATA_REQUEST, 0);\n        out_uint32_le(out_s, format);\n        s_mark_end(out_s);\n        send_stream_to_clip_channel(v, out_s);\n    }\n    free_stream(out_s);\n\n    return rv;\n}\n\n/***************************************************************************//**\n * Computes the characteristics of a stream.\n *\n * This can be used to tell if a stream has changed or two streams are\n * the same\n *\n * @param s Stream\n * @param[out] chars Resulting characteristics of stream\n */\nstatic void\ncompute_stream_characteristics(const struct stream *s,\n                               struct stream_characteristics *chars)\n{\n    void *info = ssl_md5_info_create();\n    ssl_md5_clear(info);\n    if (s->data != NULL && s->end != NULL)\n    {\n        chars->length = (int)(s->end - s->data);\n        ssl_md5_transform(info, s->data, chars->length);\n    }\n    else\n    {\n        chars->length = 0;\n    }\n    ssl_md5_complete(info, chars->digest);\n    ssl_md5_info_delete(info);\n}\n\n/***************************************************************************//**\n * Compare two stream characteristics structs for equality\n *\n * @param a characteristics of first stream\n * @param b characteristics of second stream\n * @result != 0 if characteristics are equal\n */\nstatic int\nstream_characteristics_equal(const struct stream_characteristics *a,\n                             const struct stream_characteristics *b)\n{\n    return (a->length == b->length &&\n            g_memcmp(a->digest, b->digest, sizeof(a->digest)) == 0);\n}\n\n/******************************************************************************/\nstatic int\nhandle_cb_format_data_request(struct vnc *v, struct stream *s)\n{\n    int format = 0;\n    struct stream *out_s = NULL;\n    int i;\n    struct vnc_clipboard_data *vc = v->vc;\n    int rv = 0;\n    int msg_flags = CB_RESPONSE_OK;\n    int lf_count;\n    int alloclen = 64;\n#ifdef USE_DEVEL_LOGGING\n    char scratch[64];\n#endif\n\n    if (s_check_rem(s, 4))\n    {\n        in_uint32_le(s, format);\n    }\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"RDP client requested data format=%s\",\n              cf2text(format, scratch, sizeof(scratch)));\n\n\n    /* For all formats, we need to convert to Windows carriage control,\n     * so we need to know how many '\\n' characters become '\\r\\n' */\n    lf_count = char_count_in(vc->rfb_clip_s, '\\n');\n\n    /* If we're writing a big string, we need to increase the alloclen\n     * for the return PDU. We can also vet the requested format here */\n    switch (format)\n    {\n        case CF_TEXT:\n            /* We need to allocate enough characters to hold the string\n             * with '\\n' becoming '\\r\\n' and also for a terminator. */\n            alloclen += vc->rfb_clip_s->size + lf_count + 1;\n            break;\n\n        case CF_UNICODETEXT:\n            /* As CF_TEXT, but twice as much, as each ANSI character maps to\n             * two octets */\n            alloclen += (vc->rfb_clip_s->size + lf_count + 1) * 2;\n            break;\n\n        case CF_LOCALE:\n            break;\n\n        default:\n            /* No idea what this is */\n            msg_flags = CB_RESPONSE_FAIL;\n    }\n\n    /* Allocate the stream and check for failure as the string could be\n     * essentially unlimited in length */\n    if ((make_stream(out_s)) != NULL)\n    {\n        init_stream(out_s, alloclen);\n    }\n    if (out_s == NULL || out_s->data == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Memory exhausted allocating %d bytes for clip data response\",\n            alloclen);\n        rv = 1;\n    }\n    else\n    {\n        /* Write the packet header.... */\n        out_cliprdr_header(out_s, CB_FORMAT_DATA_RESPONSE, msg_flags);\n\n        /* ...and any data */\n        switch (format)\n        {\n            case CF_LOCALE:\n                /*\n                 * This is undocumented.\n                 *\n                 * Reverse engineering by firing this request off to\n                 * a Microsoft client suggests this is a code from\n                 * [MS-LCID]. 0x409 maps to en-us which uses codepage\n                 * 1252. This is a close enough match to ISO8859-1 as used\n                 * by RFB */\n                out_uint32_le(out_s, 0x409);\n                break;\n\n            case CF_TEXT:\n                for (i = 0; i < vc->rfb_clip_s->size; ++i)\n                {\n                    char c = vc->rfb_clip_s->data[i];\n                    if (c == '\\n')\n                    {\n                        out_uint8(out_s, '\\r');\n                    }\n                    out_uint8(out_s, c);\n                }\n\n                out_uint8s(out_s, 1);\n                break;\n\n            case CF_UNICODETEXT:\n                /* The VNC clipboard format (ISO 8859-1)\n                   maps directly to UTF-16LE by moving over the bottom 8 bits,\n                   and setting the top 8 bits to zero */\n                for (i = 0; i < vc->rfb_clip_s->size; ++i)\n                {\n                    char c = vc->rfb_clip_s->data[i];\n                    if (c == '\\n')\n                    {\n                        out_uint8(out_s, '\\r');\n                        out_uint8(out_s, 0);\n                    }\n                    out_uint8(out_s, c);\n                    out_uint8(out_s, 0);\n                }\n\n                out_uint8s(out_s, 2);\n                break;\n        }\n\n        s_mark_end(out_s);\n        send_stream_to_clip_channel(v, out_s);\n    }\n    free_stream(out_s);\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nhandle_cb_format_data_response(struct vnc *v, struct stream *s)\n{\n    int rv = 0;\n\n    struct vnc_clipboard_data *vc = v->vc;\n\n    /* The [MS-RDPECLIP] specification lets a new CB_FORMAT_LIST PDU turn\n     * up before we've received a response to a CB_FORMAT_DATA_REQUEST.\n     * As a result, there might be more than one CB_FORMAT_DATA_RESPONSE\n     * PDUs in-flight. We handle this by ignoring all but the last PDU\n     * we're expecting\n     */\n    if (vc->active_data_requests > 0 && --vc->active_data_requests == 0)\n    {\n        struct stream *out_s;\n        int length;\n        char c;\n        char lastc;\n        int wc;\n        unsigned int out_of_range = 0;\n\n        /* We've got a copy of the current VNC paste buffer in\n         * vc->rfb_clip_s. Since we're about to change the VNC paste\n         * buffer anyway, we'll use this to construct the ISO8859-1\n         * text, and then send it to the VNC server\n         *\n         * We size the buffer as follows:-\n         * TEXT Use the same size buffer.\n         * UTF-16 - Use half the size\n         *\n         * In all cases this is big enough, or a little over when removal\n         * of `\\r` characters is taken into account */\n        if  (vc->requested_clip_format == CF_UNICODETEXT)\n        {\n            length = s_rem(s) / 2;\n        }\n        else\n        {\n            length = s_rem(s);\n        }\n\n        init_stream(vc->rfb_clip_s, length);\n        if (vc->rfb_clip_s->data == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Memory exhausted allocating %d bytes for clip buffer\",\n                length);\n            rv = 1;\n        }\n        else\n        {\n            switch (vc->requested_clip_format)\n            {\n                case CF_TEXT:\n                    lastc = '\\0';\n                    while (s_check_rem(s, 1))\n                    {\n                        in_uint8(s, c);\n                        if (c == '\\n' && lastc == '\\r')\n                        {\n                            /* Overwrite the `\\r' */\n                            --vc->rfb_clip_s->p;\n                        }\n                        out_uint8(vc->rfb_clip_s, c);\n                        lastc = c;\n                    }\n                    break;\n\n                case CF_UNICODETEXT:\n                    lastc = '\\0';\n                    while (s_check_rem(s, 2))\n                    {\n                        in_uint16_le(s, wc);\n                        if (wc / 0x100 == 0)\n                        {\n                            /* Valid ISO8859-1 character in bottom 8 bits */\n                            c = wc % 0x100;\n                            if (c == '\\n' && lastc == '\\r')\n                            {\n                                /* Overwrite the `\\r' */\n                                --vc->rfb_clip_s->p;\n                            }\n                            out_uint8(vc->rfb_clip_s, c);\n                            lastc = c;\n                        }\n                        else\n                        {\n                            /* Character can't be represented in ISO8859-1 */\n                            ++out_of_range;\n                            if (wc & 0xdc00 && wc <= 0xdfff)\n                            {\n                                /* Character is start of a surrogate pair */\n                                if (s_check_rem(s, 2))\n                                {\n                                    in_uint16_le(s, wc);\n                                }\n                            }\n                        }\n                    }\n\n                    if (out_of_range > 0)\n                    {\n                        LOG(LOG_LEVEL_WARNING,\n                            \"VNC: %u out-of-range Unicode characters\"\n                            \" could not be moved to the VNC clipboard\",\n                            out_of_range);\n                    }\n                    break;\n\n            }\n\n            /* Remove a terminator at the end, as RFB doesn't need it */\n            if (vc->rfb_clip_s->p != vc->rfb_clip_s->data &&\n                    *(vc->rfb_clip_s->p - 1) == '\\0')\n            {\n                --vc->rfb_clip_s->p;\n            }\n            s_mark_end(vc->rfb_clip_s);\n\n            /* Update the VNC server */\n            make_stream(out_s);\n            length = (unsigned int)(vc->rfb_clip_s->end -\n                                    vc->rfb_clip_s->data);\n            init_stream(out_s, 1 + 3 + 4 + length);\n            out_uint8(out_s, RFB_C2S_CLIENT_CUT_TEXT);\n            out_uint8s(out_s, 3);  /* padding */\n            out_uint32_be(out_s, length);\n            out_uint8p(out_s, vc->rfb_clip_s->data, length);\n            s_mark_end(out_s);\n            lib_send_copy(v, out_s);\n            free_stream(out_s);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nhandle_cb_caps(struct vnc *v, struct stream *s)\n{\n    int rv = 0;\n    int i;\n    int capset_count;\n    int capset_type;\n    int capset_length;\n    int version;\n    int flags;\n\n    if (!s_check_rem_and_log(s, 4, \"Reading clip capabilities\"))\n    {\n        rv = 1;\n    }\n    else\n    {\n        in_uint16_le(s, capset_count);\n        in_uint8s(s, 2); /* pad */\n\n        for (i = 0; i < capset_count && rv == 0; ++i)\n        {\n            if (!s_check_rem_and_log(s, 4, \"Reading capability set\"))\n            {\n                rv = 1;\n                break;\n            }\n\n            in_uint16_le(s, capset_type); /* Length includes these two fields */\n            in_uint16_le(s, capset_length);\n            capset_length -= 4; /* Account for last two fields */\n\n            switch (capset_type)\n            {\n                case CB_CAPSTYPE_GENERAL:\n                    if (!s_check_rem_and_log(s, 8, \"Reading general cap set\"))\n                    {\n                        rv = 1;\n                    }\n                    else\n                    {\n                        in_uint32_le(s, version); /* version */\n                        in_uint32_le(s, flags); /* generalFlags */\n                        capset_length -= 8;\n\n                        /* Update our own capability fields */\n                        if (version > 0 && version < v->vc->capability_version)\n                        {\n                            v->vc->capability_version = version;\n                        }\n                        v->vc->capability_flags &= flags;\n\n                        LOG(LOG_LEVEL_DEBUG,\n                            \"Agreed MS-RDPECLIP capability\"\n                            \"version=%d flags=%08x with RDP client\",\n                            v->vc->capability_version,\n                            v->vc->capability_flags);\n                    }\n                    break;\n\n                default:\n                    LOG(LOG_LEVEL_WARNING, \"clipboard_process_clip_caps: \"\n                        \"unknown capabilitySetType %d\", capset_type);\n                    break;\n            }\n\n            /* Check for padding at the end of the set */\n            if (capset_length > 0)\n            {\n                if (!s_check_rem_and_log(s, capset_length, \"cap set padding\"))\n                {\n                    rv = 1;\n                }\n                else\n                {\n                    in_uint8s(s, capset_length);\n                }\n            }\n        }\n    }\n\n    return rv;\n}\n\n/***************************************************************************//**\n * Send a format list PDU to the RDP client\n *\n * Described in [MS-RDPECLIP] 2.2.3.1\n *\n * @param v VNC structure\n */\nstatic void\nsend_format_list(struct vnc *v)\n{\n    struct vnc_clipboard_data *vc = v->vc;\n    int use_long_names = vc->capability_flags & CB_USE_LONG_FORMAT_NAMES;\n    struct stream *out_s;\n    unsigned int i = 0;\n    int format;\n\n    make_stream(out_s);\n    init_stream(out_s, 8192);\n    out_cliprdr_header(out_s, CB_FORMAT_LIST, use_long_names);\n\n    while ((format = g_supported_formats[i++]) != 0)\n    {\n        if (use_long_names)\n        {\n            /* Long format name [MS-RDPECLIP] 2.2.3.1.2.1 */\n            out_uint32_le(out_s, format);\n            out_uint8s(out_s, 2); /* wsz terminator */\n        }\n        else\n        {\n            /* Short format name [MS-RDPECLIP] 2.2.3.1.1.1 */\n            out_uint32_le(out_s, format);\n            out_uint8s(out_s, 32);\n        }\n    }\n    s_mark_end(out_s);\n    send_stream_to_clip_channel(v, out_s);\n    free_stream(out_s);\n}\n\n/******************************************************************************/\nvoid\nvnc_clip_init(struct vnc *v)\n{\n    v->vc = (struct vnc_clipboard_data *)g_malloc(sizeof(*v->vc), 1);\n    make_stream(v->vc->rfb_clip_s);\n}\n\n/******************************************************************************/\nvoid\nvnc_clip_exit(struct vnc *v)\n{\n    if (v != NULL && v->vc != NULL)\n    {\n        free_stream(v->vc->rfb_clip_s);\n        free_stream(v->vc->dechunker_s);\n        g_free(v->vc);\n    }\n}\n\n\n/******************************************************************************/\nstatic int\nvnc_clip_process_eclip_pdu(struct vnc *v, struct stream *s)\n{\n    int type;\n    int msg_flags;\n    int datalen;\n    int rv = 0;\n\n    /* Ignore PDUs with no complete header */\n    if (s_check_rem_and_log(s, 8, \"MS-RDPECLIP PDU Header\"))\n    {\n        in_uint16_le(s, type);\n        in_uint16_le(s, msg_flags);\n        in_uint32_le(s, datalen);\n\n        LOG(LOG_LEVEL_DEBUG, \"got clip data type %s msg_flags %d length %d\",\n            CB_PDUTYPE_TO_STR(type), msg_flags, datalen);\n        LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, \"clipboard data\",\n                          s->p, s->end - s->p);\n\n        /* Check the PDU is contained in the stream */\n        if (!s_check_rem_and_log(s, datalen, \"MS-RDPECLIP PDU\"))\n        {\n            datalen = s_rem(s);\n        }\n        else\n        {\n            /* Truncate the PDU to the data length so we can use the\n             * normal functions to parse the PDU */\n            s->end = s->p + datalen;\n        }\n\n        switch (type)\n        {\n            case CB_FORMAT_LIST:\n                rv = handle_cb_format_list(v, msg_flags, s);\n                break;\n\n            case CB_FORMAT_LIST_RESPONSE:\n                /* We don't need to do anything with this */\n                break;\n\n            case CB_FORMAT_DATA_REQUEST:\n                rv = handle_cb_format_data_request(v, s);\n                break;\n\n            case CB_FORMAT_DATA_RESPONSE:\n                if (msg_flags == CB_RESPONSE_OK)\n                {\n                    rv = handle_cb_format_data_response(v, s);\n                }\n                break;\n\n            case CB_CLIP_CAPS:\n                rv = handle_cb_caps(v, s);\n                break;\n        }\n    }\n\n    return rv;\n}\n\n\n/******************************************************************************/\n/**\n * Process a [MS-RDPBCGR] 2.2.6.1 Virtual Channel PDU and re-assemble the\n * data chunks as needed - see 3.1.5.2.2.1\n */\nint\nvnc_clip_process_channel_data(struct vnc *v, char *data, int size,\n                              int total_size, int flags)\n{\n    int rv = 1;\n    struct vnc_clipboard_data *vc = v->vc;\n    bool_t first = ((flags & XR_CHANNEL_FLAG_FIRST) != 0);\n    bool_t last = ((flags & XR_CHANNEL_FLAG_LAST) != 0);\n\n    if (size > total_size)\n    {\n        /* This should never happen */\n        LOG(LOG_LEVEL_ERROR,\n            \"Ignoring bad PDU chunk data on clip channel\");\n    }\n    else if (first && vc->dechunker_s != NULL)\n    {\n        /*\n         * If this packet is marked as 'first', we should not be\n         * dechunking data already */\n        LOG(LOG_LEVEL_ERROR, \"Packet chunking start state error\");\n        free_stream(vc->dechunker_s);\n        vc->dechunker_s = NULL;\n    }\n    else if (!first && vc->dechunker_s == NULL)\n    {\n        /*\n         * This is not the first packet, but the dechunker is not active */\n        LOG(LOG_LEVEL_ERROR, \"Packet chunking end state error\");\n    }\n    else if (first && last)\n    {\n        /* this is a complete packet\n         * Construct a temp stream for the complete packet, and pass it\n         * to the application */\n        struct stream packet_s = {0};\n\n        packet_s.data = data;\n        packet_s.size = size;\n        packet_s.end = packet_s.data + size;\n        packet_s.p = packet_s.data;\n        rv = vnc_clip_process_eclip_pdu(v, &packet_s);\n    }\n    else if (first)\n    {\n        /* Start de-chunking the data */\n        make_stream(vc->dechunker_s);\n        init_stream(vc->dechunker_s, (int)total_size);\n\n        /* MS-RDPBCGR 3.1.5.2.2.1 states:-\n         *\n         *     A reassembly buffer MUST be created by the virtual channel\n         *     endpoint using the size specified by totalLength when\n         *     the first chunk is received.\n         *\n         * The 'total_size' can be several GB in size, so we really need\n         * to check for an allocation failure here */\n        if (vc->dechunker_s->data == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Memory exhausted dechunking a %u byte virtual channel PDU\",\n                total_size);\n        }\n        else\n        {\n            out_uint8a(vc->dechunker_s, data, size);\n            rv = 0;\n        }\n    }\n    else if (s_check_rem_out_and_log(vc->dechunker_s,\n                                     size, \"VNC dechunker:\"))\n    {\n        out_uint8a(vc->dechunker_s, data, size);\n        /* At the end? */\n        if (last)\n        {\n            s_mark_end(vc->dechunker_s);\n            vc->dechunker_s->p = vc->dechunker_s->data;\n\n            /* Call the app and reset the dechunker */\n            rv = vnc_clip_process_eclip_pdu(v, vc->dechunker_s);\n            free_stream(vc->dechunker_s);\n            vc->dechunker_s = NULL;\n        }\n        else\n        {\n            rv = 0;\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/* clip data from the vnc server */\nint\nvnc_clip_process_rfb_data(struct vnc *v)\n{\n    struct vnc_clipboard_data *vc = v->vc;\n    struct stream *s;\n    int size;\n    int rv;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    rv = trans_force_read_s(v->trans, s, 7);\n\n    if (rv == 0)\n    {\n        in_uint8s(s, 3);\n        in_uint32_be(s, size);\n\n        if (v->clip_chanid < 0 || v->server_chansrv_in_use(v))\n        {\n            /* Skip this message */\n            LOG(LOG_LEVEL_DEBUG, \"Skipping %d clip bytes from RFB\", size);\n            rv = skip_trans_bytes(v->trans, size);\n        }\n        else\n        {\n            struct stream_characteristics old_chars;\n            struct stream_characteristics new_chars;\n\n            /* Compute the characteristics of the existing data */\n            compute_stream_characteristics(vc->rfb_clip_s, &old_chars);\n\n            /* Lose any existing RFB clip data */\n            free_stream(vc->rfb_clip_s);\n            vc->rfb_clip_s = 0;\n\n            make_stream(vc->rfb_clip_s);\n            if (size < 0)\n            {\n                /* This shouldn't happen - see Extended Clipboard\n                 * Pseudo-Encoding */\n                LOG(LOG_LEVEL_ERROR, \"Unexpected size %d for RFB data\", size);\n                rv = 1;\n            }\n            else if (size == 0)\n            {\n                LOG(LOG_LEVEL_DEBUG, \"RFB clip data cleared by VNC server\");\n            }\n            else\n            {\n                init_stream(vc->rfb_clip_s, size);\n                if (vc->rfb_clip_s->data == NULL)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Memory exhausted allocating %d bytes\"\n                        \" for RFB clip data\",\n                        size);\n                    rv = 1;\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_DEBUG, \"Reading %d clip bytes from RFB\",\n                        size);\n                    rv = trans_force_read_s(v->trans, vc->rfb_clip_s, size);\n                }\n            }\n\n            /* Consider telling the RDP client about the update only if we've\n             * completed the startup handshake */\n            if (rv == 0 && vc->startup_complete)\n            {\n                /* Has the data actually changed ? */\n                compute_stream_characteristics(vc->rfb_clip_s, &new_chars);\n                if (stream_characteristics_equal(&old_chars, &new_chars))\n                {\n                    LOG_DEVEL(LOG_LEVEL_INFO, \"RFB Clip data is unchanged\");\n                }\n                else\n                {\n                    LOG_DEVEL(LOG_LEVEL_INFO, \"RFB Clip data is updated\");\n                    send_format_list(v);\n                }\n            }\n        }\n    }\n\n    free_stream(s);\n    return rv;\n}\n\n/******************************************************************************/\nint\nvnc_clip_open_clip_channel(struct vnc *v)\n{\n    v->clip_chanid = v->server_get_channel_id(v, CLIPRDR_SVC_CHANNEL_NAME);\n\n    if (v->server_chansrv_in_use(v))\n    {\n        /*\n         * The clipboard is provided by chansrv, if at all - it may of\n         * course be disabled there.\n         */\n        LOG(LOG_LEVEL_INFO, \"VNC: Clipboard (if available) is provided \"\n            \"by chansrv facility\");\n    }\n    else if (v->clip_chanid < 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"VNC: Clipboard is unavailable\");\n    }\n    else\n    {\n        struct stream *s;\n\n        LOG(LOG_LEVEL_INFO, \"VNC: Clipboard supports ISO-8859-1 text only\");\n\n        make_stream(s);\n        init_stream(s, 8192);\n\n        v->vc->capability_version = CB_CAPS_VERSION_2;\n        v->vc->capability_flags = CB_USE_LONG_FORMAT_NAMES;\n        /**\n         * Send two PDUs to initialise the channel. The client should\n         * respond with a CB_CLIP_CAPS PDU of its own. See [MS-RDPECLIP]\n         * 1.3.2.1 */\n        out_cliprdr_header(s, CB_CLIP_CAPS, 0);\n        out_uint16_le(s, 1); /* #cCapabilitiesSets */\n        out_uint16_le(s, 0); /* pad1 */\n        /* CLIPRDR_GENERAL_CAPABILITY */\n        out_uint16_le(s, CB_CAPSTYPE_GENERAL); /* capabilitySetType */\n        out_uint16_le(s, 12); /* lengthCapability */\n        out_uint32_le(s, v->vc->capability_version);\n        out_uint32_le(s, v->vc->capability_flags);\n        s_mark_end(s);\n        send_stream_to_clip_channel(v, s);\n\n        /* Send the monitor ready PDU */\n        init_stream(s, 0);\n        out_cliprdr_header(s, CB_MONITOR_READY, 0);\n        s_mark_end(s);\n        send_stream_to_clip_channel(v, s);\n\n        free_stream(s);\n        /* Need to complete the startup handshake before we send formats */\n        v->vc->startup_complete = 1;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "vnc/vnc_clip.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libvnc - functions used by the VNC clipboard feature\n */\n\n#ifndef VNC_CLIP_H\n#define VNC_CLIP_H\n\nstruct vnc;\nstruct stream;\n\n/**\n * Init the clip module private data structures\n */\nvoid\nvnc_clip_init(struct vnc *v);\n\n/**\n * Deallocate the clip module private data structures\n */\nvoid\nvnc_clip_exit(struct vnc *v);\n\n/**\n * Process incoming data from the RDP clip channel\n * @param v VNC Object\n * @param data Stream object containing data\n *\n * @return Non-zero if error occurs\n */\nint\nvnc_clip_process_channel_data(struct vnc *v, char *data, int size,\n                              int total_size, int flags);\n\n/**\n * Process incoming RFB protocol clipboard data\n * @param v VNC Object\n *\n * @return Non-zero if error occurs\n */\nint\nvnc_clip_process_rfb_data(struct vnc *v);\n\n/**\n * Open the RDP clipboard channel\n *\n * The clip channel ID is written to the VNC object\n * *\n * @param v VNC Object\n * @return Non-zero if error occurs\n */\nint\nvnc_clip_open_clip_channel(struct vnc *v);\n\n#endif /* VNC_CLIP_H */\n"
  },
  {
    "path": "vrplayer/README.txt",
    "content": "A QT based media player that runs on a RDP server and\nredirects audio/video to the client where it is decoded\nand rendered locally\n\nRequired packages to build vrplayer:\n------------------------------------\nlibqt4-gui\nqt4-dev-tools\nlibavutil-dev\nlibavformat-dev\n\nto build vrplayer\n-----------------\ncd ../xrdpvr\nmake\ncd ..\nqmake\nmake\n\nTo run vrplayer\n---------------\ninclude xrdpapi/.libs and xrdpvr/.libs in your LD_LIBRARY_PATH\n\nExample:\n--------\nexport LD_LIBRARY_PATH=../xrdpapi/.libs:../xrdpvr/.libs\nrun vrplayer inside the xfreerdp session\n\nthis is how we run xfreerdp:\n----------------------------\n./xfreerdp --sec rdp --plugin xrdpvr 192.168.2.149\n\n"
  },
  {
    "path": "vrplayer/decoder.cpp",
    "content": "#include \"decoder.h\"\n\nDecoder::Decoder(QObject *parent) :\n    QObject(parent)\n{\n    channel = NULL;\n}\n\n/*\n * inititialize the decoder\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\nint Decoder::init(QString filename)\n{\n    printf(\"Decoder::init\\n\");\n    if (channel)\n        return -1;\n\n    /* open a virtual channel and connect to remote client */\n    channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, \"xrdpvr\", 0);\n    if (channel == NULL)\n    {\n        qDebug() << \"WTSVirtualChannelOpenEx() failed\\n\";\n        return -1;\n    }\n\n    /* initialize the player */\n    if (xrdpvr_init_player(channel, 101, filename.toAscii().data()))\n    {\n        fprintf(stderr, \"failed to initialize the player\\n\");\n        return -1;\n    }\n\n#if 1\n    sleep(1);\n    qDebug() << \"sleeping 1\";\n    xrdpvr_set_geometry(channel, 101, mainWindowGeometry.x(),\n                        mainWindowGeometry.y(), mainWindowGeometry.width(),\n                        mainWindowGeometry.height());\n    qDebug() << \"set geometry to:\" << mainWindowGeometry.x() <<\n                \"\" << mainWindowGeometry.y() <<\n                \"\" << mainWindowGeometry.width() <<\n                \"\" << mainWindowGeometry.height();\n#endif\n\n    /* send compressed media data to client; client will decompress */\n    /* the media and play it locally                                */\n    xrdpvr_play_media(channel, 101, filename.toAscii().data());\n\n    /* perform clean up */\n    xrdpvr_deinit_player(channel, 101);\n\n    WTSVirtualChannelClose(channel);\n\n    return 0;\n}\n\nvoid Decoder::onGeometryChanged(QRect *g)\n{\n#if 1\n    mainWindowGeometry.setX(g->x());\n    mainWindowGeometry.setY(g->y());\n    mainWindowGeometry.setWidth(g->width());\n    mainWindowGeometry.setHeight(g->height());\n#else\n    if (!channel)\n        return;\n\n    xrdpvr_set_geometry(channel, 101, g->x(), g->y(), g->width(), g->height());\n    qDebug() << \"sent geometry\";\n#endif\n}\n"
  },
  {
    "path": "vrplayer/decoder.h",
    "content": "#ifndef DECODER_H\n#define DECODER_H\n\n#include <QObject>\n#include <QDebug>\n#include <QRect>\n\n#ifdef __cplusplus\n#define __STDC_CONSTANT_MACROS\n#ifdef _STDINT_H\n#undef _STDINT_H\n#endif\n#include <stdint.h>\n#endif\n\n#include <libavformat/avformat.h>\n#include <xrdpapi.h>\n#include <xrdpvr.h> /* LK_TODO is this required? */\n\nclass Decoder : public QObject\n{\n        Q_OBJECT\n    public:\n        explicit Decoder(QObject *parent = 0);\n        int init(QString filename);\n        //int deinit();\n        //int setWindow(QRectangle rect);\n\n    private:\n        void *channel;\n        QRect mainWindowGeometry;\n\n    signals:\n\n    public slots: // cppcheck-suppress unknownMacro\n        void onGeometryChanged(QRect *geometry);\n};\n\n#endif // DECODER_H\n"
  },
  {
    "path": "vrplayer/demuxmedia.cpp",
    "content": "\n#include <unistd.h>\n\n#include \"demuxmedia.h\"\n\nDemuxMedia::DemuxMedia(QObject *parent, QQueue<MediaPacket *> *videoQueue,\n                       void *channel, int stream_id) : QObject(parent)\n{\n    this->channel = channel;\n    this->stream_id = stream_id;\n    this->vcrFlag = 0;\n    this->elapsedTime = 0;\n    this->la_seekPos = -1;\n    this->isStopped = 0;\n    this->pausedTime = 0;\n    this->videoQueue = videoQueue;\n\n    playVideo = new PlayVideo(NULL, videoQueue, &sendMutex, channel, 101, 24);\n    playVideoThread = new QThread(this);\n    connect(playVideoThread, SIGNAL(started()), playVideo, SLOT(play()));\n    playVideo->moveToThread(playVideoThread);\n\n    playVideoThread->start();\n\n}\n\nvoid DemuxMedia::setVcrOp(int op)\n{\n    vcrMutex.lock();\n    vcrFlag = op;\n    vcrMutex.unlock();\n    if (op == VCR_STOP)\n    {\n        clear();\n    }\n}\n\nint DemuxMedia::clear()\n{\n    sendMutex.lock();\n    videoQueue->clear();\n    sendMutex.unlock();\n    return 0;\n}\n\nvoid DemuxMedia::startDemuxing()\n{\n    MediaPacket *mediaPkt;\n    int          is_video_frame;\n    int          rv;\n\n    while (1)\n    {\n        vcrMutex.lock();\n        switch (vcrFlag)\n        {\n        case VCR_PLAY:\n            vcrFlag = 0;\n            vcrMutex.unlock();\n            if (pausedTime)\n            {\n                elapsedTime = av_gettime() - pausedTime;\n                pausedTime = 0;\n            }\n            isStopped = false;\n            continue;\n            break;\n\n        case VCR_PAUSE:\n            vcrMutex.unlock();\n            if (!pausedTime)\n            {\n                /* save amount of video played so far */\n                pausedTime = av_gettime() - elapsedTime;\n            }\n            usleep(1000 * 100);\n            isStopped = false;\n            continue;\n            break;\n\n        case VCR_STOP:\n            vcrMutex.unlock();\n\n            if (isStopped)\n            {\n                usleep(1000 * 100);\n                continue;\n            }\n            elapsedTime = 0;\n            pausedTime = 0;\n            la_seekPos = -1;\n            xrdpvr_seek_media(0, 0);\n            isStopped = true;\n            continue;\n            break;\n\n        default:\n            vcrMutex.unlock();\n            break;\n        }\n\n        mediaPkt = new MediaPacket;\n        rv = xrdpvr_get_frame(&mediaPkt->av_pkt,\n                              &is_video_frame,\n                              &mediaPkt->delay_in_us);\n        if (rv < 0)\n        {\n            /* looks like we reached end of file */\n            delete mediaPkt;\n            usleep(1000 * 100);\n            xrdpvr_seek_media(0, 0);\n            this->elapsedTime = 0;\n            continue;\n        }\n\n        if (is_video_frame)\n        {\n            sendMutex.lock();\n#if 1\n            videoQueue->enqueue(mediaPkt);\n#else\n            send_video_pkt(channel, stream_id, mediaPkt->av_pkt);\n            delete mediaPkt;\n#endif\n            sendMutex.unlock();\n        }\n        else\n        {\n            int frame;\n            sendMutex.lock();\n            send_audio_pkt(channel, stream_id, mediaPkt->av_pkt);\n            sendMutex.unlock();\n            xrdpvr_read_ack(channel, &frame);\n            delete mediaPkt;\n        }\n\n        updateMediaPos();\n        if (elapsedTime == 0)\n        {\n            elapsedTime = av_gettime();\n        }\n\n        /* time elapsed in 1/100th sec units since play started */\n        emit onElapsedtime((av_gettime() - elapsedTime) / 10000);\n\n\n    } /* end while (1) */\n}\n\nvoid DemuxMedia::onMediaSeek(int value)\n{\n    posMutex.lock();\n    la_seekPos = value;\n    posMutex.unlock();\n}\n\nvoid DemuxMedia::updateMediaPos()\n{\n    posMutex.lock();\n    if (la_seekPos >= 0)\n    {\n        xrdpvr_seek_media(la_seekPos, 0);\n        elapsedTime = av_gettime() - la_seekPos * 1000000;\n        la_seekPos = -1;\n    }\n    posMutex.unlock();\n}\n"
  },
  {
    "path": "vrplayer/demuxmedia.h",
    "content": "#ifndef DEMUXMEDIA_H\n#define DEMUXMEDIA_H\n\n#ifdef __cplusplus\n#define __STDC_CONSTANT_MACROS\n#ifdef _STDINT_H\n#undef _STDINT_H\n#endif\n#include <stdint.h>\n#endif\n\n#include <QObject>\n#include <QQueue>\n#include <QThread>\n#include <QMutex>\n#include <QDebug>\n\n#include \"mediapacket.h\"\n#include \"playaudio.h\"\n#include \"playvideo.h\"\n\n/* ffmpeg related stuff */\nextern \"C\"\n{\n#include <libavformat/avformat.h>\n#include <libavcodec/avcodec.h>\n}\n\n#define VCR_PLAY        1\n#define VCR_PAUSE       2\n#define VCR_STOP        3\n#define VCR_REWIND      4\n#define VCR_POWER_OFF   5\n\nclass DemuxMedia : public QObject\n{\n        Q_OBJECT\n\n    public:\n        explicit DemuxMedia(QObject *parent = 0, QQueue<MediaPacket *> *videoQueue = 0,\n                            void *channel = 0, int stream_id = 101);\n\n        void setVcrOp(int op);\n        int clear();\n\n    public slots:\n        void       startDemuxing();\n        void       onMediaSeek(int value);\n\n    private:\n        QMutex     vcrMutex;\n        int        vcrFlag;\n        void      *channel;\n        int        stream_id;\n        QMutex     sendMutex;\n        QMutex     posMutex;\n        int64_t    elapsedTime; /* elapsed time in usecs since play started */\n        int64_t    pausedTime;  /* time at which stream was paused          */\n        int64_t    la_seekPos;  /* locked access; must hold posMutex        */\n        bool       isStopped;\n\n        QQueue<MediaPacket *> *videoQueue;\n        PlayVideo             *playVideo;\n        QThread               *playVideoThread;\n\n        void updateMediaPos();\n\n    signals:\n        void onMediaRestarted();\n\n    signals:\n        void onElapsedtime(int val); /* in hundredth of a sec */\n\n};\n\n#endif // DEMUXMEDIA_H\n"
  },
  {
    "path": "vrplayer/dlgabout.cpp",
    "content": "#include \"dlgabout.h\"\n#include \"ui_dlgabout.h\"\n\nDlgAbout::DlgAbout(QWidget *parent) :\n    QDialog(parent),\n    ui(new Ui::DlgAbout)\n{\n    ui->setupUi(this);\n    connect(ui->okButton, SIGNAL(clicked()), this, SLOT(onOk()));\n}\n\nDlgAbout::~DlgAbout()\n{\n    delete ui;\n}\n\nvoid DlgAbout::onOk()\n{\n    this->done(0);\n}\n"
  },
  {
    "path": "vrplayer/dlgabout.h",
    "content": "#ifndef DLGABOUT_H\n#define DLGABOUT_H\n\n#include <QDialog>\n\nnamespace Ui\n{\n    class DlgAbout;\n}\n\nclass DlgAbout : public QDialog\n{\n        Q_OBJECT\n\n    public:\n        explicit DlgAbout(QWidget *parent = 0);\n        ~DlgAbout();\n\n    private:\n        Ui::DlgAbout *ui;\n\n    private slots: // cppcheck-suppress unknownMacro\n        void onOk();\n};\n\n#endif // DLGABOUT_H\n"
  },
  {
    "path": "vrplayer/dlgabout.ui",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ui version=\"4.0\">\n <class>DlgAbout</class>\n <widget class=\"QDialog\" name=\"DlgAbout\">\n  <property name=\"geometry\">\n   <rect>\n    <x>0</x>\n    <y>0</y>\n    <width>288</width>\n    <height>168</height>\n   </rect>\n  </property>\n  <property name=\"windowTitle\">\n   <string>Dialog</string>\n  </property>\n  <widget class=\"QLabel\" name=\"label\">\n   <property name=\"geometry\">\n    <rect>\n     <x>70</x>\n     <y>60</y>\n     <width>151</width>\n     <height>17</height>\n    </rect>\n   </property>\n   <property name=\"text\">\n    <string>VRPlayer v1.6</string>\n   </property>\n  </widget>\n  <widget class=\"QPushButton\" name=\"okButton\">\n   <property name=\"geometry\">\n    <rect>\n     <x>180</x>\n     <y>120</y>\n     <width>94</width>\n     <height>27</height>\n    </rect>\n   </property>\n   <property name=\"text\">\n    <string>OK</string>\n   </property>\n  </widget>\n </widget>\n <resources/>\n <connections/>\n</ui>\n"
  },
  {
    "path": "vrplayer/main.cpp",
    "content": "\n#include <QtGui/QApplication>\n#include \"mainwindow.h\"\n\nint main(int argc, char *argv[])\n{\n    QApplication::setGraphicsSystem(QLatin1String(\"native\"));\n    QApplication a(argc, argv);\n    MainWindow w;\n    w.show();\n    return a.exec();\n}\n"
  },
  {
    "path": "vrplayer/mainwindow.cpp",
    "content": "#include \"mainwindow.h\"\n#include \"ui_mainwindow.h\"\n\n/*\n * TODO\n *      o should we use tick marks in QSlider?\n *      o check for memory leaks\n *      o double click should make it full screen\n *      o when opening files, pause video\n */\n\nMainWindow::MainWindow(QWidget *parent) :\n    QMainWindow(parent),\n    ui(new Ui::MainWindow)\n{\n    gotMediaOnCmdline = false;\n    moveResizeTimer = NULL;\n\n    /* connect to remote client */\n    interface = new OurInterface();\n    if (interface->oneTimeInit())\n    {\n        oneTimeInitSuccess = false;\n\n        /* connection to remote client failed; error msg has  */\n        /* already been displayed so it's ok to close app now */\n        QTimer::singleShot(1000, this, SLOT(close()));\n    }\n    else\n    {\n        oneTimeInitSuccess = true;\n    }\n    remoteClientInited = false;\n    ui->setupUi(this);\n    acceptSliderMove = false;\n    setupUI();\n    vcrFlag = 0;\n\n    connect(this, SIGNAL(onGeometryChanged(int,int,int,int)),\n            interface, SLOT(onGeometryChanged(int,int,int,int)));\n\n    connect(interface, SIGNAL(onMediaDurationInSeconds(int)),\n            this, SLOT(onMediaDurationInSeconds(int)));\n\n    /* if media file is specified on cmd line, use it */\n    QStringList args = QApplication::arguments();\n    if (args.count() > 1)\n    {\n        if (QFile::exists(args.at(1)))\n        {\n            interface->setFilename(args.at(1));\n            filename = args.at(1);\n            gotMediaOnCmdline = true;\n            on_actionOpen_Media_File_triggered();\n        }\n        else\n        {\n            QMessageBox::warning(this, \"Invalid media file specified\",\n                                 \"\\nThe media file\\n\\n\" + args.at(1) +\n                                 \"\\n\\ndoes not exist\");\n        }\n    }\n}\n\nMainWindow::~MainWindow()\n{\n    delete ui;\n\n    //if (moveResizeTimer)\n    //    delete moveResizeTimer;\n}\n\nvoid MainWindow::closeEvent(QCloseEvent *event)\n{\n    if (oneTimeInitSuccess)\n    {\n        interface->deInitRemoteClient();\n    }\n    else\n    {\n        QMessageBox::warning(this, \"Closing application\",\n                \"This is not an xrdp session with xrdpvr\");\n    }\n    event->accept();\n}\n\nvoid MainWindow::resizeEvent(QResizeEvent *)\n{\n    //if (vcrFlag != VCR_PLAY)\n    {\n        QRect rect;\n\n        getVdoGeometry(&rect);\n        interface->sendGeometry(rect);\n        //return;\n    }\n\n    //interface->setVcrOp(VCR_PAUSE);\n    //vcrFlag = VCR_PAUSE;\n\n    //if (!moveResizeTimer)\n    //{\n    //    moveResizeTimer = new QTimer;\n    //    connect(moveResizeTimer, SIGNAL(timeout()),\n    //            this, SLOT(onMoveCompleted()));\n    //}\n    //lblVideo->setStyleSheet(\"QLabel { background-color : black; color : blue; }\");\n    //moveResizeTimer->start(1000);\n}\n\nvoid MainWindow::moveEvent(QMoveEvent *)\n{\n    //if (vcrFlag != VCR_PLAY)\n    {\n        QRect rect;\n\n        getVdoGeometry(&rect);\n        interface->sendGeometry(rect);\n        //return;\n    }\n\n    //interface->setVcrOp(VCR_PAUSE);\n    //vcrFlag = VCR_PAUSE;\n\n    //if (!moveResizeTimer)\n    //{\n    //    moveResizeTimer = new QTimer;\n    //    connect(moveResizeTimer, SIGNAL(timeout()),\n    //            this, SLOT(onMoveCompleted()));\n    //}\n    //lblVideo->setStyleSheet(\"QLabel { background-color : black; color : blue; }\");\n    //moveResizeTimer->start(1000);\n}\n\nvoid MainWindow::onVolSliderValueChanged(int value)\n{\n    int volume;\n\n    volume = (value * 0xffff) / 100;\n    if (interface != 0)\n    {\n        interface->setVolume(volume);\n    }\n    qDebug() << \"vol = \" << volume;\n}\n\nvoid MainWindow::setupUI()\n{\n    this->setWindowTitle(\"vrplayer\");\n\n    /* setup area to display video */\n    lblVideo = new QLabel();\n    lblVideo->setMinimumWidth(320);\n    lblVideo->setMinimumHeight(200);\n    QPalette palette = lblVideo->palette();\n    palette.setColor(lblVideo->backgroundRole(), QColor(0x00, 0x00, 0x01, 0xff));\n    palette.setColor(lblVideo->foregroundRole(), QColor(0x00, 0x00, 0x01, 0xff));\n    lblVideo->setAutoFillBackground(true);\n    lblVideo->setPalette(palette);\n    hboxLayoutTop = new QHBoxLayout;\n    hboxLayoutTop->addWidget(lblVideo);\n\n    /* setup label to display current pos in media */\n    lblCurrentPos = new QLabel(\"00:00:00\");\n    lblCurrentPos->setMinimumHeight(20);\n    lblCurrentPos->setMaximumHeight(20);\n\n    /* setup slider to seek into media */\n    slider = new QSlider();\n    slider->setOrientation(Qt::Horizontal);\n    slider->setMinimumHeight(20);\n    slider->setMaximumHeight(20);\n    connect(slider, SIGNAL(actionTriggered(int)), this, SLOT(onSliderActionTriggered(int)));\n    connect(slider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));\n\n    /* setup label to display media duration */\n    lblDuration = new QLabel(\"00:00:00\");\n    lblDuration->setMinimumHeight(20);\n    lblDuration->setMaximumHeight(20);\n\n    /* add above three widgets to mid layout */\n    hboxLayoutMiddle = new QHBoxLayout;\n    hboxLayoutMiddle->addWidget(lblCurrentPos);\n    hboxLayoutMiddle->addWidget(slider);\n    hboxLayoutMiddle->addWidget(lblDuration);\n\n    /* setup play button */\n    btnPlay = new QPushButton(\"Play\");\n    btnPlay->setMinimumHeight(40);\n    btnPlay->setMaximumHeight(40);\n    btnPlay->setMinimumWidth(40);\n    btnPlay->setMaximumWidth(40);\n    btnPlay->setCheckable(true);\n    connect(btnPlay, SIGNAL(clicked(bool)),\n            this, SLOT(onBtnPlayClicked(bool)));\n\n    /* setup stop button */\n    btnStop = new QPushButton(\"Stop\");\n    btnStop->setMinimumHeight(40);\n    btnStop->setMaximumHeight(40);\n    btnStop->setMinimumWidth(40);\n    btnStop->setMaximumWidth(40);\n    connect(btnStop, SIGNAL(clicked(bool)),\n            this, SLOT(onBtnStopClicked(bool)));\n\n    /* setup rewind button */\n    btnRewind = new QPushButton(\"R\");\n    btnRewind->setMinimumHeight(40);\n    btnRewind->setMaximumHeight(40);\n    btnRewind->setMinimumWidth(40);\n    btnRewind->setMaximumWidth(40);\n    connect(btnRewind, SIGNAL(clicked(bool)),\n            this, SLOT(onBtnRewindClicked(bool)));\n\n    /* setup volume control slider */\n    volSlider = new QSlider();\n    volSlider->setOrientation(Qt::Horizontal);\n    volSlider->setMinimumWidth(100);\n    volSlider->setMaximumWidth(100);\n    volSlider->setMinimum(0);\n    volSlider->setMaximum(100);\n    volSlider->setValue(20);\n    volSlider->setTickPosition(QSlider::TicksAbove);\n    volSlider->setTickInterval(10);\n\n    connect(volSlider, SIGNAL(valueChanged(int)),\n            this, SLOT(onVolSliderValueChanged(int)));\n\n    /* add buttons to bottom panel */\n    hboxLayoutBottom = new QHBoxLayout;\n    hboxLayoutBottom->addWidget(btnPlay);\n    hboxLayoutBottom->addWidget(btnStop);\n    hboxLayoutBottom->addWidget(volSlider);\n\n    //hboxLayoutBottom->addWidget(btnRewind);\n    hboxLayoutBottom->addStretch();\n\n    /* add all three layouts to one vertical layout */\n    vboxLayout = new QVBoxLayout;\n    vboxLayout->addLayout(hboxLayoutTop);\n    vboxLayout->addLayout(hboxLayoutMiddle);\n    vboxLayout->addLayout(hboxLayoutBottom);\n\n    /* add all of them to central widget */\n    window = new QWidget;\n    window->setLayout(vboxLayout);\n    this->setCentralWidget(window);\n}\n\nvoid MainWindow::openMediaFile()\n{\n    /* TODO take last stored value from QSettings */\n\n    if (filename.length() == 0)\n    {\n\n        /* no previous selection - open user's home folder TODO */\n        // TODO filename = QFileDialog::getOpenFileName(this, \"Select Media File\", \"/\");\n        //filename = QFileDialog::getOpenFileName(this, \"Select Media File\",\n        //                                        QDir::currentPath());\n\n        filename = QFileDialog::getOpenFileName(this, \"Select Media File\",\n                                                QDir::currentPath(),\n                                                \"Media *.mov *.mp4 *.mkv (*.mov *.mp4 *.mkv)\");\n\n\n    }\n    else\n    {\n        /* show last selected file */\n        filename = QFileDialog::getOpenFileName(this, \"Select Media File\",\n                                                filename);\n    }\n    interface->setFilename(filename);\n}\n\nvoid MainWindow::getVdoGeometry(QRect *rect)\n{\n    int x;\n    int y;\n    int width;\n    int height;\n    QPoint pt;\n\n    pt = lblVideo->mapToGlobal(QPoint(0, 0));\n    x = pt.x();\n    y = pt.y();\n    width = lblVideo->width();\n    height = lblVideo->height();\n    rect->setX(x);\n    rect->setY(y);\n    rect->setWidth(width);\n    rect->setHeight(height);\n}\n\nvoid MainWindow::clearDisplay()\n{\n    /* TODO: this needs to be set after video actually stops\n     * a few frames come after this */\n    lblVideo->update();\n}\n\n/*******************************************************************************\n *                       actions and slots go here                             *\n ******************************************************************************/\n\nvoid MainWindow::on_actionOpen_Media_File_triggered()\n{\n    if (vcrFlag != 0)\n    {\n        onBtnStopClicked(true);\n    }\n\n    /* if media was specified on cmd line, use it just once */\n    if (gotMediaOnCmdline)\n    {\n        gotMediaOnCmdline = false;\n    }\n    else\n    {\n        openMediaFile();\n    }\n\n    if (filename.length() == 0)\n    {\n        /* cancel btn was clicked */\n        return;\n    }\n\n    if (remoteClientInited)\n    {\n        remoteClientInited = false;\n        interface->deInitRemoteClient();\n        if (interface->initRemoteClient() != 0)\n        {\n            QMessageBox::question(this, \"vrplayer\", \"Unsupported codec\",\n                                  QMessageBox::Ok);\n            return;\n        }\n    }\n    else\n    {\n        if (interface->initRemoteClient() != 0)\n        {\n            QMessageBox::question(this, \"vrplayer\", \"Unsupported codec\",\n                                  QMessageBox::Ok);\n            return;\n        }\n    }\n\n    demuxMedia = interface->getDemuxMediaInstance();\n    if (demuxMedia)\n    {\n        connect(demuxMedia, SIGNAL(onElapsedtime(int)),\n                this, SLOT(onElapsedTime(int)));\n    }\n\n    remoteClientInited = true;\n    interface->playMedia();\n\n    //if (vcrFlag != 0)\n    {\n        interface->setVcrOp(VCR_PLAY);\n        btnPlay->setText(\"Pause\");\n        vcrFlag = VCR_PLAY;\n    }\n}\n\nvoid MainWindow::on_actionExit_triggered()\n{\n    clearDisplay();\n    this->close();\n}\n\nvoid MainWindow::onBtnPlayClicked(bool)\n{\n    if (vcrFlag == 0)\n    {\n        /* first time play button3 has been clicked */\n        on_actionOpen_Media_File_triggered();\n        btnPlay->setText(\"Pause\");\n        vcrFlag = VCR_PLAY;\n    }\n    else if (vcrFlag == VCR_PLAY)\n    {\n        /* btn clicked while in play mode - enter pause mode */\n        btnPlay->setText(\"Play\");\n        interface->setVcrOp(VCR_PAUSE);\n        vcrFlag = VCR_PAUSE;\n    }\n    else if (vcrFlag == VCR_PAUSE)\n    {\n        /* btn clicked while in pause mode - enter play mode */\n        btnPlay->setText(\"Pause\");\n        interface->setVcrOp(VCR_PLAY);\n        vcrFlag = VCR_PLAY;\n    }\n    else if (vcrFlag == VCR_STOP)\n    {\n        /* btn clicked while stopped - enter play mode */\n        btnPlay->setText(\"Play\");\n        interface->setVcrOp(VCR_PLAY);\n        vcrFlag = VCR_PLAY;\n    }\n}\n\nvoid MainWindow::onBtnRewindClicked(bool)\n{\n    //if (playVideo)\n    //    playVideo->onMediaSeek(0);\n}\n\nvoid MainWindow::onBtnStopClicked(bool)\n{\n    vcrFlag = VCR_STOP;\n    btnPlay->setText(\"Play\");\n    interface->setVcrOp(VCR_STOP);\n\n    /* reset slider */\n    slider->setSliderPosition(0);\n    lblCurrentPos->setText(\"00:00:00\");\n\n    /* clear screen by filling it with black */\n    usleep(500 * 1000);\n    clearDisplay();\n\n    btnPlay->setChecked(false);\n}\n\nvoid MainWindow::onMediaDurationInSeconds(int duration)\n{\n    int  hours   = 0;\n    int  minutes = 0;\n    int  secs    = 0;\n    char buf[20];\n\n    /* setup progress bar */\n    slider->setMinimum(0);\n    slider->setMaximum(duration * 100); /* in hundredth of a sec */\n    slider->setValue(0);\n    slider->setSliderPosition(0);\n    lblCurrentPos->setText(\"00:00:00\");\n    //qDebug() << \"media_duration=\" << duration << \" in hundredth of a sec:\" << duration * 100;\n\n    /* convert from seconds to hours:minutes:seconds */\n    hours = duration / 3600;\n    if (hours)\n        duration -= (hours * 3600);\n\n    minutes = duration / 60;\n    if (minutes)\n        duration -= minutes * 60;\n\n    secs = duration;\n\n    sprintf(buf, \"%.2d:%.2d:%.2d\", hours, minutes, secs);\n    lblDuration->setText(QString(buf));\n}\n\n/**\n * time elapsed in 1/100th sec units since play started\n ******************************************************************************/\nvoid MainWindow::onElapsedTime(int val)\n{\n    int  hours    = 0;\n    int  minutes  = 0;\n    int  secs     = 0;\n    int  duration = 0;\n    char buf[20];\n\n    if (vcrFlag == VCR_STOP)\n        return;\n\n    /* if slider bar is down, do not update */\n    if (slider->isSliderDown())\n        return;\n\n    /* update progress bar */\n    if (val >= slider->maximum())\n        val = 0;\n\n    slider->setSliderPosition(val);\n\n    /* convert from seconds to hours:minutes:seconds */\n    duration = val / 100;\n    hours = duration / 3600;\n    if (hours)\n        duration -= (hours * 3600);\n\n    minutes = duration / 60;\n    if (minutes)\n        duration -= minutes * 60;\n\n    secs = duration;\n\n    /* update current position in progress bar */\n    sprintf(buf, \"%.2d:%.2d:%.2d\", hours, minutes, secs);\n    lblCurrentPos->setText(QString(buf));\n}\n\nvoid MainWindow::onSliderValueChanged(int value)\n{\n    if (acceptSliderMove)\n    {\n        acceptSliderMove = false;\n        if (demuxMedia != NULL)\n        {\n            demuxMedia->onMediaSeek(value / 100);\n        }\n    }\n}\n\nvoid MainWindow::onSliderActionTriggered(int action)\n{\n    switch (action)\n    {\n    case QAbstractSlider::SliderPageStepAdd:\n        acceptSliderMove = true;\n        break;\n\n    case QAbstractSlider::SliderPageStepSub:\n        acceptSliderMove = true;\n        break;\n\n    case QAbstractSlider::SliderMove:\n        if (slider->isSliderDown())\n            acceptSliderMove = true;\n        break;\n    }\n}\n\n// not called\nvoid MainWindow::onMoveCompleted()\n{\n    QRect rect;\n\n    getVdoGeometry(&rect);\n    interface->sendGeometry(rect);\n\n    interface->setVcrOp(VCR_PLAY);\n    vcrFlag = VCR_PLAY;\n    //moveResizeTimer->stop();\n}\n\nvoid MainWindow::on_actionAbout_triggered()\n{\n#if 0\n    QMessageBox msgBox;\n\n    msgBox.setText(\"VRPlayer version 1.2\");\n    msgBox.setStandardButtons(QMessageBox::Ok);\n    msgBox.setDefaultButton(QMessageBox::Ok);\n    msgBox.exec();\n#else\n    DlgAbout *dlgabt = new DlgAbout(this);\n    dlgabt->exec();\n\n#endif\n}\n"
  },
  {
    "path": "vrplayer/mainwindow.h",
    "content": "#ifndef MAINWINDOW_H\n#define MAINWINDOW_H\n\n#ifdef __cplusplus\n#define __STDC_CONSTANT_MACROS\n#ifdef _STDINT_H\n#undef _STDINT_H\n#endif\n#include <stdint.h>\n#endif\n\n#include <QMainWindow>\n#include <QFileDialog>\n#include <QDebug>\n#include <QMessageBox>\n#include <QCloseEvent>\n#include <QMoveEvent>\n#include <QPoint>\n#include <QRect>\n#include <QLabel>\n#include <QHBoxLayout>\n#include <QVBoxLayout>\n#include <QPushButton>\n#include <QSlider>\n#include <QTimer>\n#include <QPixmap>\n#include <QPainter>\n#include <QFile>\n#include <QTimer>\n\n#include \"xrdpapi.h\"\n#include \"xrdpvr.h\"\n#include \"decoder.h\"\n#include \"ourinterface.h\"\n#include \"playvideo.h\"\n#include \"dlgabout.h\"\n\n/* ffmpeg related stuff */\nextern \"C\"\n{\n#include <libavformat/avformat.h>\n#include <libavcodec/avcodec.h>\n}\n\n#define VCR_PLAY        1\n#define VCR_PAUSE       2\n#define VCR_STOP        3\n#define VCR_REWIND      4\n#define VCR_POWER_OFF   5\n\nnamespace Ui\n{\n    class MainWindow;\n}\n\nclass MainWindow : public QMainWindow\n{\n        Q_OBJECT\n\n    public:\n        explicit MainWindow(QWidget *parent = 0);\n        ~MainWindow();\n\n    signals:\n        void onGeometryChanged(int x, int y, int width, int height);\n\n    public slots:\n        void onSliderValueChanged(int value);\n\n    private slots:\n        void on_actionOpen_Media_File_triggered();\n        void on_actionExit_triggered();\n\n        void onBtnPlayClicked(bool flag);\n        void onBtnRewindClicked(bool flag);\n        void onBtnStopClicked(bool flag);\n\n        void onMediaDurationInSeconds(int duration);\n        void onElapsedTime(int secs);\n        void onSliderActionTriggered(int value);\n        void onMoveCompleted();\n\n        void on_actionAbout_triggered();\n\n        void onVolSliderValueChanged(int value);\n\n    protected:\n        void resizeEvent(QResizeEvent *e);\n        void closeEvent(QCloseEvent *e);\n        void moveEvent(QMoveEvent *e);\n\n    private:\n        Ui::MainWindow *ui;\n\n        /* for UI */\n        QLabel        *lblCurrentPos;\n        QLabel        *lblDuration;\n        QLabel        *lblVideo;\n        QHBoxLayout   *hboxLayoutTop;\n        QHBoxLayout   *hboxLayoutMiddle;\n        QHBoxLayout   *hboxLayoutBottom;\n        QVBoxLayout   *vboxLayout;\n        QPushButton   *btnPlay;\n        QPushButton   *btnStop;\n        QPushButton   *btnRewind;\n        QSlider       *slider;\n        QSlider       *volSlider;\n        QWidget       *window;\n        bool           acceptSliderMove;\n        QTimer        *moveResizeTimer;\n\n        /* private stuff */\n        OurInterface  *interface;\n        //PlayVideo     *playVideo;\n        DemuxMedia    *demuxMedia;\n        QString        filename;\n        bool           oneTimeInitSuccess;\n        bool           remoteClientInited;\n        void          *channel;\n        int            stream_id;\n        int64_t        elapsedTime; /* elapsed time in usecs since play started */\n        int            vcrFlag;\n        bool           gotMediaOnCmdline;\n\n        /* private methods */\n        void setupUI();\n        void openMediaFile();\n        void getVdoGeometry(QRect *rect);\n        void clearDisplay();\n};\n\n#endif // MAINWINDOW_H\n"
  },
  {
    "path": "vrplayer/mainwindow.ui",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ui version=\"4.0\">\n <class>MainWindow</class>\n <widget class=\"QMainWindow\" name=\"MainWindow\">\n  <property name=\"geometry\">\n   <rect>\n    <x>0</x>\n    <y>0</y>\n    <width>800</width>\n    <height>600</height>\n   </rect>\n  </property>\n  <property name=\"windowTitle\">\n   <string>MainWindow</string>\n  </property>\n  <widget class=\"QWidget\" name=\"centralWidget\"/>\n  <widget class=\"QMenuBar\" name=\"menuBar\">\n   <property name=\"geometry\">\n    <rect>\n     <x>0</x>\n     <y>0</y>\n     <width>800</width>\n     <height>25</height>\n    </rect>\n   </property>\n   <widget class=\"QMenu\" name=\"menuFile\">\n    <property name=\"title\">\n     <string>File</string>\n    </property>\n    <addaction name=\"actionOpen_Media_File\"/>\n    <addaction name=\"separator\"/>\n    <addaction name=\"actionExit\"/>\n   </widget>\n   <widget class=\"QMenu\" name=\"menuHelp\">\n    <property name=\"title\">\n     <string>Help</string>\n    </property>\n    <addaction name=\"actionAbout\"/>\n   </widget>\n   <addaction name=\"menuFile\"/>\n   <addaction name=\"menuHelp\"/>\n  </widget>\n  <widget class=\"QToolBar\" name=\"mainToolBar\">\n   <attribute name=\"toolBarArea\">\n    <enum>TopToolBarArea</enum>\n   </attribute>\n   <attribute name=\"toolBarBreak\">\n    <bool>false</bool>\n   </attribute>\n  </widget>\n  <widget class=\"QStatusBar\" name=\"statusBar\"/>\n  <action name=\"actionOpen_Media_File\">\n   <property name=\"text\">\n    <string>Open Media File</string>\n   </property>\n  </action>\n  <action name=\"actionExit\">\n   <property name=\"text\">\n    <string>Exit application</string>\n   </property>\n   <property name=\"toolTip\">\n    <string>Exit application</string>\n   </property>\n  </action>\n  <action name=\"actionAbout\">\n   <property name=\"text\">\n    <string>About</string>\n   </property>\n  </action>\n </widget>\n <layoutdefault spacing=\"6\" margin=\"11\"/>\n <resources/>\n <connections/>\n</ui>\n"
  },
  {
    "path": "vrplayer/mediapacket.cpp",
    "content": "#include \"mediapacket.h\"\n\nMediaPacket::MediaPacket()\n{\n    av_pkt = 0;\n    delay_in_us = 0;\n    seq = 0;\n}\n"
  },
  {
    "path": "vrplayer/mediapacket.h",
    "content": "#ifndef MEDIAPACKET_H\n#define MEDIAPACKET_H\n\nclass MediaPacket\n{\n    public:\n        MediaPacket();\n\n        void *av_pkt;\n        int   delay_in_us;\n        int   seq;\n};\n\n#endif // MEDIAPACKET_H\n"
  },
  {
    "path": "vrplayer/ourinterface.cpp",
    "content": "\n#include \"ourinterface.h\"\n\nOurInterface::OurInterface(QObject *parent) :\n    QObject(parent)\n{\n    channel = NULL;\n    savedGeometry.setX(0);\n    savedGeometry.setY(0);\n    savedGeometry.setWidth(0);\n    savedGeometry.setHeight(0);\n    stream_id = 101;\n    demuxMedia = 0;\n    demuxMediaThread = NULL;\n    //elapsedTime = 0;\n}\n\nint OurInterface::oneTimeInit()\n{\n    /* connect to remote client */\n    if (openVirtualChannel())\n        return -1;\n\n    /* register all formats/codecs */\n    av_register_all();\n\n    return 0;\n}\n\nvoid OurInterface::oneTimeDeinit()\n{\n    /* clean up resources */\n    closeVirtualChannel();\n}\n\n/* returns error */\nint OurInterface::initRemoteClient()\n{\n    int64_t start_time;\n    int64_t duration;\n\n    //elapsedTime = 0;\n\n    if (sendMetadataFile())\n        return 1;\n\n    if (sendVideoFormat())\n        return 1;\n\n    if (sendAudioFormat())\n        return 1;\n\n    if (sendGeometry(savedGeometry))\n        return 1;\n\n    if (xrdpvr_play_media(channel, 101, filename.toAscii().data()) != 0)\n    {\n        return 1;\n    }\n\n    xrdpvr_get_media_duration(&start_time, &duration);\n    //qDebug() << \"ourInterface:initRemoteClient: emit onMediaDurationInSecs: dur=\" << duration;\n    emit onMediaDurationInSeconds(duration);\n\n    /* LK_TODO this needs to be undone in deinitRemoteClient() */\n    if (!demuxMedia)\n    {\n        demuxMedia = new DemuxMedia(NULL, &videoQueue, channel, stream_id);\n        demuxMediaThread = new QThread(this);\n        connect(demuxMediaThread, SIGNAL(started()), demuxMedia, SLOT(startDemuxing()));\n        demuxMedia->moveToThread(demuxMediaThread);\n        //playVideo = demuxMedia->getPlayVideoInstance();\n    }\n    return 0;\n}\n\nvoid OurInterface::deInitRemoteClient()\n{\n    /* perform clean up */\n    xrdpvr_deinit_player(channel, 101);\n}\n\n/**\n * @brief Open a virtual connection to remote client\n *\n * @return 0 on success, -1 on failure\n ******************************************************************************/\nint OurInterface::openVirtualChannel()\n{\n    /* is channel already open? */\n    if (channel)\n        return -1;\n\n    printf(\"OurInterface::openVirtualChannel:\\n\");\n    /* open a virtual channel and connect to remote client */\n    channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, \"xrdpvr\", 0);\n    if (channel == NULL)\n    {\n\n        emit on_ErrorMsg(\"Connection failure\",\n                         \"Error connecting to remote client. Application will close now\");\n        return -1;\n    }\n    return 0;\n}\n\nint OurInterface::closeVirtualChannel()\n{\n    /* channel must be opened first */\n    if (!channel)\n        return -1;\n\n    WTSVirtualChannelClose(channel);\n    return 0;\n}\n\n/**\n * @brief this is a temp hack while we figure out how to set up the right\n *        context for avcodec_decode_video2() on the server side; the workaround\n *        is to send the first 1MB of the media file to the server end which\n *        reads this file and sets up its context\n *\n * @return 0 on success, -1 on failure\n ******************************************************************************/\nint OurInterface::sendMetadataFile()\n{\n\n    if (xrdpvr_init_player(channel, 101, filename.toAscii().data()))\n    {\n        fprintf(stderr, \"failed to initialize the player\\n\");\n        return -1;\n    }\n#if 0\n    if (xrdpvr_create_metadata_file(channel, filename.toAscii().data()))\n    {\n        emit on_ErrorMsg(\"I/O Error\",\n                         \"An error occurred while sending data to remote client\");\n        return -1;\n    }\n#endif\n    return 0;\n}\n\nint OurInterface::sendVideoFormat()\n{\n#if 0\n    if (xrdpvr_set_video_format(channel, stream_id))\n    {\n        emit on_ErrorMsg(\"I/O Error\",\n                         \"Error sending video format to remote client\");\n        return -1;\n    }\n#endif\n    return 0;\n}\n\nint OurInterface::sendAudioFormat()\n{\n#if 0\n    if (xrdpvr_set_audio_format(channel, stream_id))\n    {\n        emit on_ErrorMsg(\"I/O Error\",\n                         \"Error sending audio format to remote client\");\n        return -1;\n    }\n#endif\n    return 0;\n}\n\nint OurInterface::sendGeometry(QRect rect)\n{\n    int rv;\n\n    savedGeometry.setX(rect.x());\n    savedGeometry.setY(rect.y());\n    savedGeometry.setWidth(rect.width());\n    savedGeometry.setHeight(rect.height());\n\n    rv = xrdpvr_set_geometry(channel, stream_id, savedGeometry.x(),\n                             savedGeometry.y(), savedGeometry.width(),\n                             savedGeometry.height());\n\n    if (rv)\n    {\n        emit on_ErrorMsg(\"I/O Error\",\n                         \"Error sending screen geometry to remote client\");\n        return -1;\n    }\n\n    return 0;\n}\n\nvoid OurInterface::onGeometryChanged(int x, int y, int width, int height)\n{\n    savedGeometry.setX(x);\n    savedGeometry.setY(y);\n    savedGeometry.setWidth(width);\n    savedGeometry.setHeight(height);\n\n#if 0\n    qDebug() << \"OurInterface:signal\" <<\n                \"\" << savedGeometry.x() <<\n                \"\" << savedGeometry.y() <<\n                \"\" << savedGeometry.width() <<\n                \"\" << savedGeometry.height();\n#endif\n\n    if (channel)\n    {\n        xrdpvr_set_geometry(channel, 101, savedGeometry.x(), savedGeometry.y(),\n                            savedGeometry.width(), savedGeometry.height());\n    }\n}\n\nvoid OurInterface::setFilename(QString filename)\n{\n    this->filename = filename;\n}\n\nvoid OurInterface::playMedia()\n{\n    demuxMediaThread->start();\n}\n\n//PlayVideo * OurInterface::getPlayVideoInstance()\n//{\n//    return this->playVideo;\n//}\n\nDemuxMedia * OurInterface::getDemuxMediaInstance()\n{\n    return this->demuxMedia;\n}\n\n\nvoid OurInterface::setVcrOp(int op)\n{\n    if (demuxMedia)\n        demuxMedia->setVcrOp(op);\n}\n\nint OurInterface::setVolume(int volume)\n{\n    printf(\"OurInterface::setVolume\\n\");\n    if (xrdpvr_set_volume(channel, volume))\n    {\n        emit on_ErrorMsg(\"I/O Error\",\n                         \"Error sending volume to remote client\");\n        return -1;\n    }\n    return 0;\n}\n"
  },
  {
    "path": "vrplayer/ourinterface.h",
    "content": "#ifndef OURINTERFACE_H\n#define OURINTERFACE_H\n\n#ifdef __cplusplus\n#define __STDC_CONSTANT_MACROS\n#ifdef _STDINT_H\n#undef _STDINT_H\n#endif\n#include <stdint.h>\n#endif\n\n#include <QObject>\n#include <QRect>\n#include <QDebug> // LK_TODO\n\n#include \"xrdpvr.h\"\n#include \"xrdpapi.h\"\n#include \"demuxmedia.h\"\n#include \"playvideo.h\"\n\n/* ffmpeg related stuff */\nextern \"C\"\n{\n#include <libavformat/avformat.h>\n#include <libavcodec/avcodec.h>\n}\n\nclass OurInterface : public QObject\n{\n        Q_OBJECT\n\n    public:\n        explicit OurInterface(QObject *parent = 0);\n\n        /* public methods */\n        int  oneTimeInit();\n        void oneTimeDeinit();\n        int initRemoteClient();\n        void deInitRemoteClient();\n        int  sendGeometry(QRect rect);\n        void setFilename(QString filename);\n        void playMedia();\n        //PlayVideo *getPlayVideoInstance();\n        DemuxMedia *getDemuxMediaInstance();\n        void setVcrOp(int op);\n        int setVolume(int volume);\n\n    public slots:\n        void onGeometryChanged(int x, int y, int width, int height);\n\n    signals:\n        void on_ErrorMsg(QString title, QString msg);\n        void onMediaDurationInSeconds(int duration);\n\n    private:\n\n        /* private stuff */\n\n        QQueue<MediaPacket *> videoQueue;\n\n        DemuxMedia     *demuxMedia;\n        QThread        *demuxMediaThread;\n        //PlayVideo      *playVideo;\n        QString         filename;\n        void           *channel;\n        int             stream_id;\n        QRect           savedGeometry;\n\n        /* private methods */\n        int  openVirtualChannel();\n        int  closeVirtualChannel();\n        int  sendMetadataFile();\n        int  sendVideoFormat();\n        int  sendAudioFormat();\n};\n\n#endif // INTERFACE_H\n"
  },
  {
    "path": "vrplayer/playaudio.cpp",
    "content": "\n#include <unistd.h>\n\n#include \"playaudio.h\"\n#include <QDebug>\n\nPlayAudio::PlayAudio(QObject *parent,\n                     QQueue<MediaPacket *> *audioQueue,\n                     QMutex *sendMutex,\n                     void *channel,\n                     int stream_id) :\n    QObject(parent)\n{\n    this->audioQueue = audioQueue;\n    this->sendMutex = sendMutex;\n    this->channel = channel;\n    this->stream_id = stream_id;\n    this->vcrFlag = 0;\n}\n\nvoid PlayAudio::play()\n{\n    MediaPacket *pkt;\n\n    while (1)\n    {\n        vcrMutex.lock();\n        switch (vcrFlag)\n        {\n        case VCR_PLAY:\n            vcrFlag = 0;\n            vcrMutex.unlock();\n            continue;\n            break;\n\n        case VCR_PAUSE:\n            vcrMutex.unlock();\n            usleep(1000 * 100);\n            continue;\n            break;\n\n        case VCR_STOP:\n            vcrMutex.unlock();\n            clearAudioQ();\n            usleep(1000 * 100);\n            continue;\n            break;\n\n        default:\n            vcrMutex.unlock();\n            goto label1;\n            break;\n        }\n\nlabel1:\n\n        printf(\"audio\\n\");\n        if (audioQueue->isEmpty())\n        {\n            qDebug() << \"PlayAudio::play: GOT EMPTY\";\n            usleep(1000 * 10);\n            continue;\n        }\n\n        printf(\"\");\n        pkt = audioQueue->dequeue();\n        sendMutex->lock();\n        send_audio_pkt(channel, stream_id, pkt->av_pkt);\n        sendMutex->unlock();\n        usleep(pkt->delay_in_us);\n        delete pkt;\n    }\n}\n\nvoid PlayAudio::setVcrOp(int op)\n{\n    vcrMutex.lock();\n    this->vcrFlag = op;\n    vcrMutex.unlock();\n}\n\nvoid PlayAudio::clearAudioQ()\n{\n    MediaPacket *pkt;\n\n    while (!audioQueue->isEmpty())\n    {\n        pkt = audioQueue->dequeue();\n        av_free_packet((AVPacket *) pkt->av_pkt);\n        delete pkt;\n    }\n}\n"
  },
  {
    "path": "vrplayer/playaudio.h",
    "content": "#ifndef PLAYAUDIO_H\n#define PLAYAUDIO_H\n\n#ifdef __cplusplus\n#define __STDC_CONSTANT_MACROS\n#ifdef _STDINT_H\n#undef _STDINT_H\n#endif\n#include <stdint.h>\n#endif\n\n#include <QObject>\n#include <QQueue>\n#include <QMutex>\n\n#include \"mediapacket.h\"\n#include \"xrdpvr.h\"\n\n/* ffmpeg related stuff */\nextern \"C\"\n{\n#include <libavformat/avformat.h>\n#include <libavcodec/avcodec.h>\n}\n\n#define VCR_PLAY        1\n#define VCR_PAUSE       2\n#define VCR_STOP        3\n#define VCR_REWIND      4\n#define VCR_POWER_OFF   5\n\nclass PlayAudio : public QObject\n{\n        Q_OBJECT\n\n    public:\n        explicit PlayAudio(QObject *parent = 0,\n                           QQueue<MediaPacket *> *audioQueue = 0,\n                           QMutex *sendMutex = 0,\n                           void *channel = 0,\n                           int stream_id = 101);\n\n        void setVcrOp(int op);\n\n    public slots: // cppcheck-suppress unknownMacro\n        void play();\n\n    private:\n        QQueue<MediaPacket *> *audioQueue;\n        QMutex                *sendMutex;\n        QMutex                 vcrMutex;\n        int                    vcrFlag;\n        void                  *channel;\n        int                    stream_id;\n\n        void clearAudioQ();\n};\n\n#endif // PLAYAUDIO_H\n"
  },
  {
    "path": "vrplayer/playvideo.cpp",
    "content": "\n#include <unistd.h>\n#include <sys/time.h>\n\n#include \"playvideo.h\"\n#include <QDebug>\n\nPlayVideo::PlayVideo(QObject *parent,\n                     QQueue<MediaPacket *> *videoQueue,\n                     QMutex *sendMutex,\n                     void *channel,\n                     int stream_id, int fps) :\n    QObject(parent)\n{\n    this->videoQueue = videoQueue;\n    this->channel = channel;\n    this->sendMutex = sendMutex;\n    this->stream_id = stream_id;\n    this->fps = fps;\n}\n\n/**\n ******************************************************************************/\nstatic int\nget_mstime(void)\n{\n    struct timeval tp;\n\n    gettimeofday(&tp, 0);\n    return (tp.tv_sec * 1000) + (tp.tv_usec / 1000);\n}\n\nvoid PlayVideo::play()\n{\n    MediaPacket *pkt;\n    int now_time;\n    int sleep_time;\n    int last_display_time;\n\n    last_display_time = 0;\n    while (1)\n    {\n        sendMutex->lock();\n        if (videoQueue->isEmpty())\n        {\n            sendMutex->unlock();\n            usleep(10 * 1000);\n            continue;\n        }\n        pkt = videoQueue->dequeue();\n        send_video_pkt(channel, stream_id, pkt->av_pkt);\n        sendMutex->unlock();\n        now_time = get_mstime();\n        sleep_time = now_time - last_display_time;\n        if (sleep_time > (1000 / fps))\n        {\n            sleep_time = (1000 / fps);\n        }\n        if (sleep_time > 0)\n        {\n            usleep(sleep_time * 1000);\n        }\n        last_display_time = now_time;\n        delete pkt;\n    }\n}\n"
  },
  {
    "path": "vrplayer/playvideo.h",
    "content": "#ifndef PLAYVIDEO_H\n#define PLAYVIDEO_H\n\n#ifdef __cplusplus\n#define __STDC_CONSTANT_MACROS\n#ifdef _STDINT_H\n#undef _STDINT_H\n#endif\n#include <stdint.h>\n#endif\n\n#include <QObject>\n#include <QQueue>\n#include <QMutex>\n\n#include \"mediapacket.h\"\n#include \"xrdpvr.h\"\n#include \"xrdpapi.h\"\n\n/* ffmpeg related stuff */\nextern \"C\"\n{\n#include <libavformat/avformat.h>\n#include <libavcodec/avcodec.h>\n}\n\n#define VCR_PLAY        1\n#define VCR_PAUSE       2\n#define VCR_STOP        3\n#define VCR_REWIND      4\n#define VCR_POWER_OFF   5\n\nclass PlayVideo : public QObject\n{\n        Q_OBJECT\n\n    public:\n        explicit PlayVideo(QObject *parent = 0,\n                           QQueue<MediaPacket *> *videoQueue = 0,\n                           QMutex *sendMutex = 0,\n                           void *channel = 0,\n                           int stream_id = 101,\n                           int fps = 24);\n\n        //void onMediaSeek(int value);\n        //void setVcrOp(int op);\n        //void onMediaRestarted();\n\n    public slots: // cppcheck-suppress unknownMacro\n        void play();\n\n        //signals:\n        //    void onElapsedtime(int val); /* in hundredth of a sec */\n\n    private:\n        QQueue<MediaPacket *> *videoQueue;\n\n        //    int       vcrFlag;\n        //    QMutex    vcrMutex;\n        QMutex   *sendMutex;\n        //    QMutex    posMutex;\n        //    int64_t   la_seekPos;  /* locked access; must hold posMutex */\n        void     *channel;\n        int       stream_id;\n        int       fps;\n        //    int64_t   elapsedTime; /* elapsed time in usecs since play started */\n        //    int64_t   pausedTime;  /* time at which stream was paused          */\n        //    bool      isStopped;\n\n        //    void updateMediaPos();\n        //    void clearVideoQ();\n};\n\n#endif // PLAYVIDEO_H\n"
  },
  {
    "path": "vrplayer/vrplayer.pro",
    "content": "#-------------------------------------------------\n#\n# Project created by QtCreator 2012-11-13T11:52:36\n#\n#-------------------------------------------------\n\nQT       += core gui\n\nTARGET = vrplayer\nTEMPLATE = app\n\n\nSOURCES += main.cpp\\\n    playvideo.cpp \\\n    mainwindow.cpp \\\n    mediapacket.cpp \\\n    playaudio.cpp \\\n    demuxmedia.cpp \\\n    ourinterface.cpp \\\n    dlgabout.cpp\n\nHEADERS  += mainwindow.h \\\n    mediapacket.h \\\n    playvideo.h \\\n    playaudio.h \\\n    demuxmedia.h \\\n    ourinterface.h \\\n    dlgabout.h\n\nFORMS    += mainwindow.ui \\\n    dlgabout.ui\n\n# added by LK\nINCLUDEPATH += ../xrdpvr\nINCLUDEPATH += ../xrdpapi\n\nLIBS += -Wl,-rpath\nLIBS += -Wl,/usr/local/lib/xrdp\n\nLIBS += -L../xrdpvr/.libs -lxrdpvr\nLIBS += -L../xrdpapi/.libs -lxrdpapi\nLIBS += -L/usr/lib/x86_64-linux-gnu -lavformat -lavcodec -lavutil\n"
  },
  {
    "path": "waitforx/Makefile.am",
    "content": "pkglibexec_PROGRAMS = \\\n  waitforx\n\nAM_LDFLAGS = $(X_LIBS) -lX11 -lXrandr\n\nAM_CPPFLAGS = \\\n  -DXRDP_SOCKET_ROOT_PATH=\\\"${socketdir}\\\" \\\n  -I$(top_srcdir)/sesman/sesexec \\\n  -I$(top_srcdir)/common\n\nAM_CFLAGS = $(X_CFLAGS)\n\nwaitforx_SOURCES = waitforx.c\n\nwaitforx_LDADD = \\\n  $(top_builddir)/common/libcommon.la\n"
  },
  {
    "path": "waitforx/waitforx.c",
    "content": "#include <X11/extensions/Xrandr.h>\n#include <signal.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <ctype.h>\n#include <unistd.h>\n#include <limits.h>\n\n#include \"config_ac.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"xrdp_sockets.h\"\n#include \"xwait.h\" // For return status codes\n\n#define ATTEMPTS 10\n#define ALARM_WAIT 30\n\n/*****************************************************************************/\nstatic void\nalarm_handler(int signal_num)\n{\n    /* Avoid printf() in signal handler (see signal-safety(7))\n     *\n     * Prefix the message with a newline in case another message\n     * has been partly output */\n    const char msg[] = \"\\n<E>Timed out waiting for X display\\n\";\n    g_file_write(1, msg, g_strlen(msg));\n    exit(XW_STATUS_TIMED_OUT);\n}\n\n/*****************************************************************************/\n/***\n * Checks whether display can be reached via a Unix Domain Socket socket.\n *\n * Local displays can be reached by a Unix Domain socket. The display\n * string will be of the form ':n' or ':n.m' where 'n' and 'm'\n * are unsigned numbers\n *\n * @param display Display string\n * @param[out] sock_name sock_name or \"\"\n * @param sock_name_len Length of sock_name\n * @return !=0 if sock_name is not NULL\n */\nstatic int\nget_display_sock_name(const char *display, char *sock_name,\n                      size_t sock_name_len)\n{\n    int local = 0;\n    int dnum = 0;\n    if (display != NULL && *display++ == ':' && isdigit(*display))\n    {\n        do\n        {\n            if (dnum > (INT_MAX / 10 - 1))\n            {\n                break; // Avoid signed integer overflow\n            }\n            dnum = (dnum * 10) + (*display - '0');\n            ++display;\n        }\n        while (isdigit(*display));\n\n        // Skip the optional screen identifier\n        if (*display == '.' && isdigit(*(display + 1)))\n        {\n            do\n            {\n                ++display;\n            }\n            while (isdigit(*display));\n        }\n\n        local = (*display == '\\0');\n    }\n\n    if (local)\n    {\n        snprintf(sock_name, sock_name_len, X11_UNIX_SOCKET_STR, dnum);\n    }\n    else\n    {\n        sock_name[0] = '\\0';\n    }\n\n\n    return (sock_name[0] != '\\0');\n}\n\n/*****************************************************************************/\nstatic Display *\nopen_display(const char *display)\n{\n    char sock_name[XRDP_SOCKETS_MAXPATH];\n    int local_fd = -1;\n    Display *dpy = NULL;\n    unsigned int wait = ATTEMPTS;\n    unsigned int n;\n\n    // If the display is local, we try to connect to the X11 socket for\n    // the display first. If we can't do this, we don't attempt to open\n    // the display.\n    //\n    // This is to ensure the display open code in libxcb doesn't attempt\n    // to connect to the X server over TCP. This can block if the network\n    // is configured in an unexpected way, which leads to use failing\n    // to detect the X server starting up shortly after.\n    //\n    // Some versions of libxcb support a 'unix:' prefix to the display\n    // string to allow a connection to be restricted to a local socket.\n    // This is not documented, and varies significantly between versions\n    // of libxcb. We can't use it here.\n    if (get_display_sock_name(display, sock_name, sizeof(sock_name)) != 0)\n    {\n        for (n = 1; n <= wait ; ++n)\n        {\n            printf(\"<D>Opening socket %s. Attempt %u of %u\\n\",\n                   sock_name, n, wait);\n            if ((local_fd = g_sck_local_socket()) >= 0)\n            {\n                if  (g_sck_local_connect(local_fd, sock_name) == 0)\n                {\n                    printf(\"<D>Socket '%s' open succeeded.\\n\", sock_name);\n                    break;\n                }\n                else\n                {\n                    printf(\"<D>Socket '%s' open failed [%s].\\n\",\n                           sock_name, g_get_strerror());\n                    g_file_close(local_fd);\n                    local_fd = -1;\n                }\n            }\n            g_sleep(1000);\n        }\n\n        // Subtract the wait time for this stage from the overall wait time\n        wait -= (n - 1);\n    }\n\n    for (n = 1; n <= wait; ++n)\n    {\n        printf(\"<D>Opening display '%s'. Attempt %u of %u\\n\", display, n, wait);\n        if ((dpy = XOpenDisplay(display)) != NULL)\n        {\n            printf(\"<D>Opened display %s\\n\", display);\n            break;\n        }\n        g_sleep(1000);\n    }\n\n    // Close the file after we try the display open, to prevent\n    // a display reset if our connect was the last client.\n    if (local_fd >= 0)\n    {\n        g_file_close(local_fd);\n    }\n\n    return dpy;\n}\n\n/*****************************************************************************/\n/**\n * Wait for the RandR extension (if in use) to be available\n *\n * @param dpy Display\n * @return 0 if/when outputs are available, 1 otherwise\n */\nstatic int\nwait_for_r_and_r(Display *dpy)\n{\n    int error_base = 0;\n    int event_base = 0;\n    unsigned int outputs = 0;\n    unsigned int wait = ATTEMPTS;\n    unsigned int n;\n\n    XRRScreenResources *res = NULL;\n\n    if (!XRRQueryExtension(dpy, &event_base, &error_base))\n    {\n        printf(\"<I>RandR not supported on display %s\\n\",\n               DisplayString(dpy));\n        return 0;\n    }\n\n    for (n = 1; n <= wait; ++n)\n    {\n        printf(\"<D>Waiting for outputs. Attempt %u of %u\\n\", n, wait);\n        res = XRRGetScreenResources(dpy, DefaultRootWindow(dpy));\n        if (res != NULL)\n        {\n            if (res->noutput > 0)\n            {\n                outputs = res->noutput;\n            }\n            XRRFreeScreenResources(res);\n        }\n\n        if (outputs > 0)\n        {\n            printf(\"<D>Display %s ready with %u RandR outputs\\n\",\n                   DisplayString(dpy), outputs);\n            return 0;\n        }\n        g_sleep(1000);\n    }\n\n    printf(\"<E>Unable to find any RandR outputs\\n\");\n    return 1;\n}\n\n/*****************************************************************************/\nstatic void\nusage(const char *argv0, int status)\n{\n    printf(\"Usage: %s -d display\\n\", argv0);\n    exit(status);\n}\n\n/*****************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    const char *display_name = NULL;\n    int opt;\n    int status = XW_STATUS_MISC_ERROR;\n    Display *dpy = NULL;\n\n    /* Disable stdout buffering so any messages are passed immediately\n     * to sesman */\n    setvbuf(stdout, NULL, _IONBF, 0);\n\n    while ((opt = getopt(argc, argv, \"d:\")) != -1)\n    {\n        switch (opt)\n        {\n            case 'd':\n                display_name = optarg;\n                break;\n            default: /* '?' */\n                usage(argv[0], status);\n        }\n    }\n\n    if (!display_name)\n    {\n        usage(argv[0], status);\n    }\n\n    g_set_alarm(alarm_handler, ALARM_WAIT);\n\n    dpy = open_display(display_name);\n    if (!dpy)\n    {\n        printf(\"<E>Unable to open display %s\\n\", display_name);\n        status = XW_STATUS_FAILED_TO_START;\n    }\n    else\n    {\n        if (wait_for_r_and_r(dpy) == 0)\n        {\n            status = XW_STATUS_OK;\n        }\n        XCloseDisplay(dpy);\n    }\n\n    return status;\n}\n"
  },
  {
    "path": "xrdp/Makefile.am",
    "content": "EXTRA_DIST = \\\n  czech.txt \\\n  rdp-scan-codes.txt \\\n  xrdpwin.c\n\nAM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -DXRDP_MODULE_PATH=\\\"${moduledir}\\\" \\\n  -DXRDP_SOCKET_ROOT_PATH=\\\"${socketdir}\\\" \\\n  -I$(top_builddir) \\\n  -I$(top_srcdir)/common \\\n  -I$(top_srcdir)/libipm \\\n  -I$(top_srcdir)/libxrdp \\\n  -I$(top_srcdir)/third_party \\\n  -I$(top_srcdir)/third_party/tomlc99\n\nXRDP_EXTRA_LIBS =\nXRDP_EXTRA_SOURCES =\n\nif XRDP_RFXCODEC\nAM_CPPFLAGS += -DXRDP_RFXCODEC\nAM_CPPFLAGS += -I$(top_srcdir)/librfxcodec/include\nXRDP_EXTRA_LIBS += $(top_builddir)/librfxcodec/src/.libs/librfxencode.a\nendif\n\nif XRDP_X264\nAM_CPPFLAGS += -DXRDP_X264\nAM_CPPFLAGS += $(XRDP_X264_CFLAGS)\nXRDP_EXTRA_LIBS += $(XRDP_X264_LIBS)\nXRDP_EXTRA_SOURCES += xrdp_encoder_x264.c xrdp_encoder_x264.h\nendif\n\nif XRDP_OPENH264\nAM_CPPFLAGS += -DXRDP_OPENH264\nAM_CPPFLAGS += $(XRDP_OPENH264_CFLAGS)\nXRDP_EXTRA_LIBS += $(XRDP_OPENH264_LIBS)\nXRDP_EXTRA_SOURCES += xrdp_encoder_openh264.c xrdp_encoder_openh264.h\nendif\n\nif XRDP_PIXMAN\nAM_CPPFLAGS += -DXRDP_PIXMAN\nAM_CPPFLAGS += $(PIXMAN_CFLAGS)\nXRDP_EXTRA_LIBS += $(PIXMAN_LIBS)\nendif\n\nif XRDP_PAINTER\nAM_CPPFLAGS += -DXRDP_PAINTER\nAM_CPPFLAGS += -I$(top_srcdir)/libpainter/include\nXRDP_EXTRA_LIBS += $(top_builddir)/libpainter/src/.libs/libpainter.a\nendif\n\nsbin_PROGRAMS = \\\n  xrdp\n\nxrdp_SOURCES = \\\n  funcs.c \\\n  lang.c \\\n  xrdp.c \\\n  xrdp.h \\\n  xrdp.ini.in \\\n  xrdp_bitmap.c \\\n  xrdp_bitmap_load.c \\\n  xrdp_bitmap_common.c \\\n  xrdp_cache.c \\\n  xrdp_encoder.c \\\n  xrdp_encoder.h \\\n  xrdp_font.c \\\n  xrdp_listen.c \\\n  xrdp_login_wnd.c \\\n  xrdp_mm.c \\\n  xrdp_mm_ccp.c \\\n  xrdp_mm.h \\\n  xrdp_painter.c \\\n  xrdp_process.c \\\n  xrdp_region.c \\\n  xrdp_types.h \\\n  xrdp_egfx.c \\\n  xrdp_egfx.h \\\n  xrdp_wm.c \\\n  xrdp_main_utils.c \\\n  xrdp_tconfig.c \\\n  xrdp_tconfig.h \\\n  $(XRDP_EXTRA_SOURCES)\n\nxrdp_LDADD = \\\n  $(top_builddir)/common/libcommon.la \\\n  $(top_builddir)/libipm/libipm.la \\\n  $(top_builddir)/libxrdp/libxrdp.la \\\n  $(top_builddir)/third_party/tomlc99/libtoml.la \\\n  $(IMLIB2_LIBS) \\\n  $(XRDP_EXTRA_LIBS)\n\nxrdpsysconfdir=$(sysconfdir)/$(sysconfsubdir)\n\nif MACOS\nlib_extension = dylib\nelse\nlib_extension = so\nendif\n\nSUBST_VARS = sed \\\n   -e 's|@lib_extension[@]|$(lib_extension)|g'\n\nsubst_verbose = $(subst_verbose_@AM_V@)\nsubst_verbose_ = $(subst_verbose_@AM_DEFAULT_V@)\nsubst_verbose_0 = @echo \"  SUBST    $@\";\n\nSUFFIXES = .in\n.in:\n\t$(subst_verbose)$(SUBST_VARS) $< > $@\n\ndist_xrdpsysconf_DATA = \\\n  gfx.toml \\\n  xrdp_keyboard.toml\n\nnodist_xrdpsysconf_DATA = \\\n  xrdp.ini\n\nxrdppkgdatadir=$(datadir)/xrdp\n\ndist_xrdppkgdata_DATA = \\\n  ad24b.bmp \\\n  ad256.bmp \\\n  xrdp24b.bmp \\\n  xrdp256.bmp \\\n  xrdp_logo.bmp \\\n  xrdp_logo.png \\\n  README.logo \\\n  sans-10.fv1 \\\n  sans-18.fv1 \\\n  cursor0.cur \\\n  cursor1.cur\n\nCLEANFILES = $(nodist_xrdpsysconf_DATA)\n"
  },
  {
    "path": "xrdp/README.logo",
    "content": "About xrdp_logo.png / xrdp_logo.bmp\n\nThese new xrdp logo files were created by processing vector image files by @metalefty.\n\nThe base images can be found at\nhttps://github.com/metalefty/xrdp-logo\n"
  },
  {
    "path": "xrdp/czech.txt",
    "content": "no shift\r\n003b 002b 011b 0161 010d 0159 017e 00fd 00e1 00ed 0039 003d 00b4\r\n;    +    ě    š    č    ř    ž    ý    á    í    é    =    ´\r\n       0071 0071 0065 0072 0074 007a 0075 0069 006f 0070 00fa 0029 00a8\r\n       q    w    e    r    t    z    u    i    o    p    ú    )    ¨\r\n         0061 0073 0064 0066 0067 0068 006a 006b 006c 016f 00a7\r\n         a    s    d    f    g    h    j    k    l    ů    §\r\n           0079 0078 0063 0076 0062 006e 006d 002c 002e 002d\r\n           y    x    c    v    b    n    m    ,    .    -\r\n\r\nshift\r\n00b0 0031 0032 0033 0034 0035 0036 0037 0038 0039 0030 0025 02c7\r\n°    1    2    3    4    5    6    7    8    9    0    %    ˇ\r\n       0051 0057 0045 0052 0054 005a 0055 0049 004f 0050 002f 0028 0027\r\n       Q    W    E    R    T    Z    U    I    O    P    /    (    '\r\n         0041 0053 0044 0046 0047 0048 004a 004b 004c 0022 0021\r\n         A    S    D    F    G    H    J    K    L    \"    !\r\n           0059 0058 0043 0056 0042 004e 004d 003f 003a 005f\r\n           Y    X    C    V    B    N    M    ?    :    _\r\n\r\naltgr\r\n     007e 02c7 005e 02d8 00b0 02db 0060 00b7 00b4 02dd 00a8 00b8\r\n     ~    ˇ    ^    ˘    °    ˛    `    ·    ´    ˝    ¨    ¸\r\n       005c 007c 20ac                                    00f7 00d7 00a4\r\n       \\    |    €                                       ÷    ×    ¤\r\n         0111 0110 005b 005d           0142 0141 0024 00df\r\n         đ    Đ    [    ]              ł    Ł    $    ß\r\n           0023 0026 0040 007b 007d      003c 003e 002a\r\n           #    &    @    {    }         <    >    *\r\n"
  },
  {
    "path": "xrdp/funcs.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * simple functions\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp.h\"\n#include \"string_calls.h\"\n\n/*****************************************************************************/\n/* returns boolean */\nint\nrect_contains_pt(struct xrdp_rect *in, int x, int y)\n{\n    if (x < in->left)\n    {\n        return 0;\n    }\n\n    if (y < in->top)\n    {\n        return 0;\n    }\n\n    if (x >= in->right)\n    {\n        return 0;\n    }\n\n    if (y >= in->bottom)\n    {\n        return 0;\n    }\n\n    return 1;\n}\n\n/*****************************************************************************/\nint\nrect_intersect(struct xrdp_rect *in1, struct xrdp_rect *in2,\n               struct xrdp_rect *out)\n{\n    int rv;\n    struct xrdp_rect dumby;\n\n    if (out == 0)\n    {\n        out = &dumby;\n    }\n\n    *out = *in1;\n\n    if (in2->left > in1->left)\n    {\n        out->left = in2->left;\n    }\n\n    if (in2->top > in1->top)\n    {\n        out->top = in2->top;\n    }\n\n    if (in2->right < in1->right)\n    {\n        out->right = in2->right;\n    }\n\n    if (in2->bottom < in1->bottom)\n    {\n        out->bottom = in2->bottom;\n    }\n\n    rv = !ISRECTEMPTY(*out);\n\n    if (!rv)\n    {\n        g_memset(out, 0, sizeof(struct xrdp_rect));\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns boolean */\nint\nrect_contained_by(struct xrdp_rect *in1, int left, int top,\n                  int right, int bottom)\n{\n    if (left < in1->left || top < in1->top ||\n            right > in1->right || bottom > in1->bottom)\n    {\n        return 0;\n    }\n    else\n    {\n        return 1;\n    }\n}\n\n/*****************************************************************************/\n/* adjust the bounds to fit in the bitmap */\n/* return false if there is nothing to draw else return true */\nint\ncheck_bounds(struct xrdp_bitmap *b, int *x, int *y, int *cx, int *cy)\n{\n    if (*x >= b->width)\n    {\n        return 0;\n    }\n\n    if (*y >= b->height)\n    {\n        return 0;\n    }\n\n    if (*x < 0)\n    {\n        *cx += *x;\n        *x = 0;\n    }\n\n    if (*y < 0)\n    {\n        *cy += *y;\n        *y = 0;\n    }\n\n    if (*cx <= 0)\n    {\n        return 0;\n    }\n\n    if (*cy <= 0)\n    {\n        return 0;\n    }\n\n    if (*x + *cx > b->width)\n    {\n        *cx = b->width - *x;\n    }\n\n    if (*y + *cy > b->height)\n    {\n        *cy = b->height - *y;\n    }\n\n    return 1;\n}\n\n/*****************************************************************************/\nint\nset_string(char **in_str, const char *in)\n{\n    if (in_str == 0)\n    {\n        return 0;\n    }\n\n    g_free(*in_str);\n    *in_str = g_strdup(in);\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/gfx.toml",
    "content": "[codec]\norder = [ \"H.264\", \"RFX\" ]\n\n# Specify a preferred H.264 encoder, \"x264\" or \"OpenH264\".\n# This parameter takes effect only when more than one encoder is\n# enabled at compile time. If only one encoder is enabled, the encoder\n# will be used regardless the value of this parameter.\nh264_encoder = \"x264\"\n\n#\n# Configurations for x264\n#\n[x264.default]\n# NOTE: x264 specifies bitrate in unit of kbps.\npreset = \"ultrafast\"\ntune = \"zerolatency\"\nprofile = \"main\"     # profile is forced to baseline if preset == ultrafast\nvbv_max_bitrate = 0\nvbv_buffer_size = 0\nfps_num = 60\nfps_den = 1\nthreads = 1          # recommended: 1 or 2, see `man gfx.toml` for details\n\n[x264.lan]\n# inherits default\n\n[x264.wan]\nvbv_max_bitrate = 15_000\nvbv_buffer_size = 1_500\n\n[x264.broadband_high]\npreset = \"superfast\"\nvbv_max_bitrate = 8_000\nvbv_buffer_Size = 800\n\n[x264.satellite]\npreset = \"superfast\"\nvbv_max_bitrate = 5_000\nvbv_buffer_size = 500\n\n[x264.broadband_low]\npreset = \"veryfast\"\nvbv_max_bitrate = 1_600\nvbv_buffer_size = 66\n\n[x264.modem]\npreset = \"fast\"\nvbv_max_bitrate = 1_200\nvbv_buffer_size = 50\n\n#\n# Configurations for OpenH264\n#\n[OpenH264.default]\n# NOTE: OpenH264 specifies bitrate in unit of bps, not kbps.\nEnableFrameSkip = false\nTargetBitrate = 20_000_000\nMaxBitrate =    0          # unspecified\nMaxFrameRate = 60.0\n\n[OpenH264.lan]\n# inherits default\n\n[OpenH264.wan]\nTargetBitrate = 10_000_000\nMaxBitrate =    12_000_000\n\n[OpenH264.broadband_high]\nEnableFrameSkip = true\nTargetBitrate = 8_000_000\nMaxBitrate =   10_000_000\n\n[OpenH264.satellite]\nEnableFrameSkip = true\nTargetBitrate = 4_000_000\nMaxBitrate =    6_000_000\n\n[OpenH264.broadband_low]\nEnableFrameSkip = true\nTargetBitrate = 1_600_000\nMaxBitrate =    1_800_000\n\n[OpenH264.modem]\nEnableFrameSkip = true\nTargetBitrate =   600_000\nMaxBitrate =    1_200_000\n\n"
  },
  {
    "path": "xrdp/lang.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * keylayout\n * maximum unicode 19996(0x4e00)\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <ctype.h>\n\n#include \"xrdp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n#include \"toml.h\"\n\n// Macro to return 0..15 for a valid isxdigit() character\n#define XDIGIT_TO_VAL(d) (\\\n                          isdigit(d) ? (d) - '0' : \\\n                          ((d) >= 'a' && (d) <= 'f') ? (d) - 'a' + 10 : \\\n                          (d) - 'A' + 10)\n\n/*\n * Struct representing the contents of a km file [General] section\n */\nstruct km_general\n{\n    unsigned int version;\n    int caps_lock_supported;\n};\n\nconst struct km_general km_general_default =\n{\n    .version = 0,\n    .caps_lock_supported = 1\n};\n\n/*****************************************************************************/\nstruct xrdp_key_info *\nget_key_info_from_kbd_event(int keyboard_flags, int key_code, int *keys,\n                            int caps_lock, int num_lock, int scroll_lock,\n                            struct xrdp_keymap *keymap)\n{\n    struct xrdp_key_info *rv;\n    int shift;\n    int altgr;\n    int index;\n\n    shift = keys[SCANCODE_INDEX_LSHIFT_KEY] || keys[SCANCODE_INDEX_RSHIFT_KEY];\n    altgr = keys[SCANCODE_INDEX_RALT_KEY];  /* right alt */\n    rv = 0;\n\n    index = scancode_to_index(SCANCODE_FROM_KBD_EVENT(key_code, keyboard_flags));\n    // Don't take caps_lock into account if the keymap doesn't support it.\n    caps_lock = caps_lock && keymap->caps_lock_supported;\n\n    if (index >= 0)\n    {\n        // scancode_to_index() guarantees to map numlock scancodes\n        // to the same index values.\n        if (num_lock &&\n                index >= SCANCODE_MIN_NUMLOCK &&\n                index <= SCANCODE_MAX_NUMLOCK)\n        {\n            rv = &(keymap->keys_numlock[index - SCANCODE_MIN_NUMLOCK]);\n        }\n        else if (shift && caps_lock && altgr)\n        {\n            rv = &(keymap->keys_shiftcapslockaltgr[index]);\n        }\n        else if (shift && caps_lock)\n        {\n            rv = &(keymap->keys_shiftcapslock[index]);\n        }\n        else if (shift && altgr)\n        {\n            rv = &(keymap->keys_shiftaltgr[index]);\n        }\n        else if (shift)\n        {\n            rv = &(keymap->keys_shift[index]);\n        }\n        else if (caps_lock && altgr)\n        {\n            rv = &(keymap->keys_capslockaltgr[index]);\n        }\n        else if (caps_lock)\n        {\n            rv = &(keymap->keys_capslock[index]);\n        }\n        else if (altgr)\n        {\n            rv = &(keymap->keys_altgr[index]);\n        }\n        else\n        {\n            rv = &(keymap->keys_noshift[index]);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/**\n * Converts a table key to a scancode index value\n *\n * @param key Table key\n * @return index >= 0, or < 0 for an invalid key\n */\nstatic int\nkey_to_scancode_index(const char *key)\n{\n    int rv = -1;\n    int keyboard_flags = 0;\n    if ((key[0] == 'E' || key[0] == 'e') && key[2] == '_')\n    {\n        if (key[1] == '0')\n        {\n            keyboard_flags |= KBDFLAGS_EXTENDED;\n            key += 3;\n        }\n        else if (key[1] == '1')\n        {\n            keyboard_flags |= KBDFLAGS_EXTENDED1;\n            key += 3;\n        }\n    }\n\n    if (isxdigit(key[0]) && isxdigit(key[1]) && key[2] == '\\0')\n    {\n        int code = XDIGIT_TO_VAL(key[0]) * 16 + XDIGIT_TO_VAL(key[1]);\n        rv = scancode_to_index(SCANCODE_FROM_KBD_EVENT(code, keyboard_flags));\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/**\n * Tests a value to see if it's a valid KeySym (decimal number)\n *\n * @param[out] sym Keysym value if 1 is returned\n * @return Boolean != 0 if the string is valid\n */\nstatic int\nis_valid_keysym(const char *val, int *sym)\n{\n    int rv = 0;\n    int s = 0;\n    if (*val != '\\0')\n    {\n        while (isdigit(*val))\n        {\n            s = s * 10 + (*val++ - '0');\n        }\n        if (*val == '\\0')\n        {\n            *sym = s;\n            rv = 1;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/**\n * Tests a value to see if it's a valid unicode character (U+xxxx)\n *\n * @param[out] chr value if 1 is returned\n * @return Boolean != 0 if the string is valid\n */\nstatic int\nis_valid_unicode_char(const char *val, char32_t *chr)\n{\n    int rv = 0;\n\n    if ((val[0] == 'U' || val[0] == 'u') &&\n            val[1] == '+' && isxdigit(val[2]))\n    {\n        val += 2;  // Skip 'U+'\n        const char *p = val;\n        char32_t c = 0;\n\n        while (isxdigit(*p))\n        {\n            c = c * 16 + XDIGIT_TO_VAL(*p);\n            ++p;\n        }\n\n        if (*p == '\\0' && (p - val) >= 4 && (p - val) <= 6)\n        {\n            rv = 1;\n            *chr = c;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/**\n * keymap must be cleared before calling this function\n */\nstatic int\nkm_read_section(toml_table_t *tfile, const char *section_name,\n                struct xrdp_key_info *keymap)\n{\n    toml_table_t *section = toml_table_in(tfile, section_name);\n\n    if (section == NULL)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Section [%s] not found in keymap file\",\n            section_name);\n    }\n    else\n    {\n        const char *key;\n        toml_datum_t  val;\n        int i;\n        char *p;\n        const char *unicode_str;\n        for (i = 0 ; (key = toml_key_in(section, i)) != NULL; ++i)\n        {\n            // Get a scancode index from the key if possible\n            int sindex = key_to_scancode_index(key);\n            if (sindex < 0)\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Can't parse value '%s' in [%s] in keymap file\",\n                    key, section_name);\n                continue;\n            }\n            val = toml_string_in(section, key);\n            if (!val.ok)\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Can't read value for [%s]:%s in keymap file\",\n                    section_name, key);\n                continue;\n            }\n\n            // Does the value contain a unicode character?\n            if ((p = strchr(val.u.s, ':')) != NULL)\n            {\n                unicode_str = (p + 1);\n                *p = '\\0'; // val is a copy, writeable by us\n            }\n            else\n            {\n                unicode_str = NULL;\n            }\n\n            /* Parse both values and add them to the keymap, logging any\n             * errors */\n            if (!is_valid_keysym(val.u.s, &keymap[sindex].sym))\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Can't read KeySym for [%s]:%s in keymap file\",\n                    section_name, key);\n            }\n\n            if (unicode_str != NULL &&\n                    !is_valid_unicode_char(unicode_str, &keymap[sindex].chr))\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Can't read unicode character for [%s]:%s in keymap file\",\n                    section_name, key);\n            }\n\n            free(val.u.s);\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nget_keymaps(int keylayout, struct xrdp_keymap *keymap)\n{\n    int basic_key_layout = keylayout & 0x0000ffff;\n    char filename[256];\n    int layout_list[10];\n    int layout_count = 0;\n    int i;\n\n    /* Work out a list of layouts to try to load */\n    layout_list[layout_count++] = keylayout; // Requested layout\n    if (basic_key_layout != keylayout)\n    {\n        layout_list[layout_count++] = basic_key_layout; // First fallback\n    }\n    layout_list[layout_count++] = 0x0409; // Last chance 'en-US'\n\n    /* search for a loadable layout in the list */\n    for (i = 0; i < layout_count; ++i)\n    {\n        // Convert key layout to a filename\n        g_snprintf(filename, sizeof(filename),\n                   XRDP_CFG_PATH \"/km-%08x.toml\", layout_list[i]);\n\n        if (km_load_file(filename, keymap) == 0)\n        {\n            return 0;\n        }\n    }\n\n    /* No luck finding anything */\n    LOG(LOG_LEVEL_ERROR, \"Cannot find a usable keymap file\");\n\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Parses the [General] section in a keymap file\n * @param tfile TOML file in memory\n * @param general result (initialised to defaults)\n */\nstatic void\nparse_km_general(toml_table_t *tfile, struct km_general *general)\n{\n    toml_table_t *section;\n\n    if (tfile != NULL && (section = toml_table_in(tfile, \"General\")) != NULL)\n    {\n        toml_datum_t d;\n        if ((d = toml_int_in(section, \"version\")).ok)\n        {\n            general->version = d.u.i;\n        }\n        if ((d = toml_bool_in(section, \"caps_lock_supported\")).ok)\n        {\n            general->caps_lock_supported = d.u.b;\n        }\n    }\n}\n\n/*****************************************************************************/\n/**\n * Loads the [General] section only from a TOML file\n * @param filename Name of TOML file\n * @param quiet Set true to not log errors\n * @param[out] general Contents of [General] section. Defaults are provided.\n * @return 0 if the operation was successful\n */\nstatic int\nkm_load_file_general(const char *filename, int quiet,\n                     struct km_general *general)\n{\n    FILE *fp;\n    toml_table_t *tfile;\n    char errbuf[200];\n    int rv = 1;\n\n    *general = km_general_default;\n\n    if ((fp = fopen(filename, \"r\")) == NULL)\n    {\n        if (!quiet)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Error loading keymap file %s (%s)\",\n                filename, g_get_strerror());\n        }\n    }\n    else\n    {\n        tfile = toml_parse_file(fp, errbuf, sizeof(errbuf));\n        fclose(fp);\n        if (tfile == NULL)\n        {\n            if (!quiet)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Error in keymap file %s - %s\",\n                    filename, errbuf);\n            }\n        }\n        else\n        {\n            parse_km_general(tfile, general);\n            rv = 0;\n            toml_free(tfile);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/**\n * Boolean to test if a keylayout supports the caps_lock modifier key\n * @param keylayout keyboardLayout from TS_UD_CS_CORE (see [MS-RDPBCGR])\n * @return True if layout supports caps lock\n */\nstatic int\nkeylayout_supports_caps_lock(int keylayout)\n{\n    char filename[256];\n    struct km_general general;\n\n    g_snprintf(filename, sizeof(filename),\n               XRDP_CFG_PATH \"/km-%08x.toml\", keylayout);\n\n    (void)km_load_file_general(filename, 1, &general);\n\n    return general.caps_lock_supported;\n}\n\n/*****************************************************************************/\nint\nkm_load_file(const char *filename, struct xrdp_keymap *keymap)\n{\n    FILE *fp;\n    toml_table_t *tfile;\n    char errbuf[200];\n    int rv = 0;\n    struct km_general general = km_general_default;\n\n    if ((fp = fopen(filename, \"r\")) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error loading keymap file %s (%s)\",\n            filename, g_get_strerror());\n        rv = 1;\n    }\n    else if ((tfile = toml_parse_file(fp, errbuf, sizeof(errbuf))) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error in keymap file %s - %s\", filename, errbuf);\n        fclose(fp);\n        rv = 1;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO, \"Loading keymap file %s\", filename);\n        fclose(fp);\n\n        /* Clear the whole keymap */\n        memset(keymap, 0, sizeof(*keymap));\n\n        /* Check to see if we should expect caps lock entries */\n        parse_km_general(tfile, &general);\n        keymap->caps_lock_supported = general.caps_lock_supported;\n\n        /* read the keymap sections */\n        km_read_section(tfile, \"noshift\", keymap->keys_noshift);\n        km_read_section(tfile, \"shift\", keymap->keys_shift);\n        km_read_section(tfile, \"altgr\", keymap->keys_altgr);\n        km_read_section(tfile, \"shiftaltgr\", keymap->keys_shiftaltgr);\n        if (keymap->caps_lock_supported)\n        {\n            km_read_section(tfile, \"capslock\", keymap->keys_capslock);\n            km_read_section(tfile, \"capslockaltgr\", keymap->keys_capslockaltgr);\n            km_read_section(tfile, \"shiftcapslock\", keymap->keys_shiftcapslock);\n            km_read_section(tfile, \"shiftcapslockaltgr\",\n                            keymap->keys_shiftcapslockaltgr);\n        }\n\n        /* The numlock map is much smaller and offset by\n         * SCANCODE_MIX_NUMLOCK. Read the section into a temporary\n         * area and copy it over */\n        struct xrdp_key_info keys_numlock[SCANCODE_MAX_INDEX + 1];\n        int i;\n        for (i = SCANCODE_MIN_NUMLOCK; i <= SCANCODE_MAX_NUMLOCK; ++i)\n        {\n            keys_numlock[i].sym = 0;\n            keys_numlock[i].chr = 0;\n        }\n        km_read_section(tfile, \"numlock\", keys_numlock);\n        for (i = SCANCODE_MIN_NUMLOCK; i <= SCANCODE_MAX_NUMLOCK; ++i)\n        {\n            keymap->keys_numlock[i - SCANCODE_MIN_NUMLOCK] = keys_numlock[i];\n        }\n\n        toml_free(tfile);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/***\n * reverse-looks up a keylayout in a TOML table\n *\n * @param keylayout (e.g. 0x000000409)\n * @param table TOML table\n * @param rdp_layout Buffer for result\n * @param rdp_layout_len Size of rdp_layout\n * @return != 0 for a successful lookup\n */\nstatic int\nlookup_keylayout(int keylayout,\n                 toml_table_t *table,\n                 char rdp_layout[], unsigned int rdp_layout_len)\n{\n    int i;\n    const char *key;\n    toml_datum_t datum;\n    toml_array_t *arr;\n\n    for (i = 0 ; (key = toml_key_in(table, i)) != NULL ; ++i)\n    {\n        if ((datum = toml_int_in(table, key)).ok)\n        {\n            /* It's an integer */\n            if ((int)datum.u.i == keylayout)\n            {\n                strlcpy(rdp_layout, key, rdp_layout_len);\n                return 1;\n            }\n        }\n        else if ((arr = toml_array_in(table, key)) != NULL)\n        {\n            /* It's an array */\n            int nelem = toml_array_nelem(arr);\n            int j;\n            for (j = 0 ; j < nelem; ++j)\n            {\n                if ((datum = toml_int_at(arr, j)).ok)\n                {\n                    /* It's an integer */\n                    if ((int)datum.u.i == keylayout)\n                    {\n                        strlcpy(rdp_layout, key, rdp_layout_len);\n                        return 1;\n                    }\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"%s:%d in table [%s] is not a valid value\",\n                        key, j + 1, toml_table_key(table));\n                }\n            }\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"Key '%s' in table [%s] is neither an integer or an array\",\n                key, toml_table_key(table));\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Looks up a string in a TOML table based on a key\n * @param arr TOML table\n * @param key Key to look up\n * @param out Buffer for result\n * @param out_size Length of buffer for result\n * @return != 0 if a string was read\n */\nstatic int\nget_toml_string(const toml_table_t *arr, const char *key,\n                char out[], unsigned int out_size)\n{\n    toml_datum_t datum = toml_string_in(arr, key);\n    if (datum.ok)\n    {\n        strlcpy(out, datum.u.s, out_size);\n        free(datum.u.s);\n    }\n    return datum.ok;\n}\n\n/*****************************************************************************/\n/**\n * Looks up an integer in a TOML table based on a key\n * @param arr TOML table\n * @param key Key to look up\n * @param default_val Default to return if no match\n *\n * @return value for key, or default_val\n */\nstatic int\nget_toml_int(const toml_table_t *arr, const char *key, int default_val)\n{\n    toml_datum_t datum = toml_int_in(arr, key);\n    return (datum.ok) ? (int)datum.u.i : default_val;\n}\n\n/*****************************************************************************/\n/**\n * Reads settable parameters from a TOML table\n *\n * @param table Table\n * @param layouts      Buffer to get 'layouts' parameter\n * @param layouts_size Size of the above\n * @param map          Buffer to get 'map' parameter\n * @param map_size     Size of the above\n * @param model        Buffer to get 'model' parameter\n * @param model_size   Size of the above\n * @param variant      Buffer to get 'variant' parameter\n * @param variant_size Size of the above\n * @param options      Buffer to get 'options' parameter\n * @param options_size Size of the above\n */\nstatic void\nread_param_set(toml_table_t *table,\n               char layouts[], unsigned int layouts_size,\n               char map[], unsigned int map_size,\n               char model[], unsigned int model_size,\n               char variant[], unsigned int variant_size,\n               char options[], unsigned int options_size)\n{\n    (void)get_toml_string(table, \"layouts\", layouts, layouts_size);\n    (void)get_toml_string(table, \"map\", map, map_size);\n    (void)get_toml_string(table, \"model\", model, model_size);\n    (void)get_toml_string(table, \"variant\", variant, variant_size);\n    (void)get_toml_string(table, \"options\", options, options_size);\n}\n\n/*****************************************************************************/\n/**\n * Scans the [overrides.kb_type] sub-tables\n *\n * Looks for matches on keyboard type/subtype, and sets the keyboard\n * parameters appropriately.\n *\n * @param kb_type                TOML source table\n * @param client_info            Client info pointer\n * @param layouts_table_str      Buffer to receive name of layouts table\n * @param layouts_table_str_len  Length of above buffer\n * @param map_table_str          Buffer to receive name of map table\n * @param map_table_str_len      Length of above buffer\n */\nstatic void\nscan_overrides_kbtype_tables(toml_table_t *kb_type,\n                             struct xrdp_client_info *client_info,\n                             char layouts_table_str[],\n                             unsigned int layouts_table_str_len,\n                             char map_table_str[],\n                             unsigned int map_table_str_len)\n{\n    int i;\n    const char *key;\n\n    for (i = 0 ; (key = toml_key_in(kb_type, i)) != NULL ; ++i)\n    {\n        toml_table_t *subtable = toml_table_in(kb_type, key);\n        if (subtable == NULL)\n        {\n            continue; // Guard - shouldn't happen\n        }\n        int kb_type = get_toml_int(subtable, \"type\", 0);\n        int kb_subtype = get_toml_int(subtable, \"subtype\", 0);\n        if (kb_type == 0 && kb_subtype == 0)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Keyboard config - table \"\n                \"[overrides.kbtype.%s] is missing both type and subtype\",\n                key);\n            continue;\n        }\n        if (kb_type != 0 && kb_type != client_info->keyboard_type)\n        {\n            continue; // Table specified a type which doesn't match\n        }\n        if (kb_subtype != 0 && kb_subtype != client_info->keyboard_subtype)\n        {\n            continue; // Table specified a subtype which doesn't match\n        }\n\n        LOG(LOG_LEVEL_DEBUG, \"Keyboard config - \"\n            \"Matched overrides table [overrides.kb_type.%s]\", key);\n\n        // Override any values we can find in the subtable\n        read_param_set(subtable,\n                       layouts_table_str, layouts_table_str_len,\n                       map_table_str, map_table_str_len,\n                       client_info->model, sizeof(client_info->model),\n                       client_info->variant, sizeof(client_info->variant),\n                       client_info->options, sizeof(client_info->options));\n    }\n}\n\n/*****************************************************************************/\nstatic void\nread_toml_config(struct xrdp_client_info *client_info,\n                 const char filename[],\n                 toml_table_t *tfile)\n{\n    char layouts_table_str[64];\n    char map_table_str[64];\n    char layout_name[64];\n\n    toml_table_t *defaults;\n    toml_table_t *overrides;\n    toml_table_t *layouts_table;\n    toml_table_t *map_table;\n\n\n    /* Step 1 - Parse the [defaults] table looking for the\n     * layouts table name, the map table name, and (optionally) the\n     * XKB model, variant and options\n     */\n    if ((defaults = toml_table_in(tfile, \"defaults\")) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Keyboard config - can't find [defaults] table\");\n        return;\n    }\n\n    layouts_table_str[0] = '\\0';\n    map_table_str[0] = '\\0';\n    read_param_set(defaults,\n                   layouts_table_str, sizeof(layouts_table_str),\n                   map_table_str, sizeof(map_table_str),\n                   client_info->model, sizeof(client_info->model),\n                   client_info->variant, sizeof(client_info->variant),\n                   client_info->options, sizeof(client_info->options));\n\n    if (layouts_table_str[0] == '\\0' || map_table_str[0] == '\\0')\n    {\n        LOG(LOG_LEVEL_ERROR, \"Keyboard config - \"\n            \"[defaults] table is missing layouts and/or map keys\");\n        return;\n    }\n\n    // Step 2 - Now scan the [overrides] table, looking for\n    // subtables\n    if ((overrides = toml_table_in(tfile, \"overrides\")) != NULL)\n    {\n        toml_table_t *kb_type = toml_table_in(overrides, \"kb_type\");\n        if (kb_type != NULL)\n        {\n            // Look for overrides on type and/or subtype\n            scan_overrides_kbtype_tables(kb_type,\n                                         client_info,\n                                         layouts_table_str,\n                                         sizeof(layouts_table_str),\n                                         map_table_str, sizeof(map_table_str));\n        }\n    }\n\n    /* Check we have valid layouts and map tables */\n    if ((layouts_table = toml_table_in(tfile, layouts_table_str)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't find layouts table ['%s'] in %s\",\n            layouts_table_str, filename);\n        return;\n    }\n\n    if ((map_table = toml_table_in(tfile, map_table_str)) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't find map table ['%s'] in %s\",\n            map_table_str, filename);\n        return;\n    }\n\n    /* Step 2 - Look up the keylayout passed from the client to get a\n     * layout_name */\n    layout_name[0] = '\\0';\n    if (!lookup_keylayout(client_info->keylayout, layouts_table,\n                          layout_name, sizeof(layout_name)))\n    {\n        if ((client_info->keylayout & ~0xffff) != 0)\n        {\n            // We failed to match the layout, but we may be able\n            // to match on the lower 16-bits\n            int alt_layout = client_info->keylayout & 0xffff;\n            if (lookup_keylayout(alt_layout, layouts_table,\n                                 layout_name, sizeof(layout_name)))\n            {\n                LOG(LOG_LEVEL_INFO,\n                    \"Failed to match layout 0x%08X, but matched 0x%04X to %s\",\n                    client_info->keylayout, alt_layout, layout_name);\n            }\n        }\n    }\n    if (layout_name[0] == '\\0')\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't find layout %08x in layout table %s\",\n            client_info->keylayout, layouts_table_str);\n        return;\n    }\n\n    // Step 3 - use the layout name we matched from the layouts table to\n    // lookup the corresponding X11 layout in the map table, e.g. if we\n    // matched 0xe0200411 to 'rdp_layout_jp, copy 'jp' for the client.\n    if (!get_toml_string(map_table, layout_name,\n                         client_info->layout, sizeof(client_info->layout)))\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't find layout name %s in map table %s\",\n            layout_name, map_table_str);\n    }\n}\n\n/*****************************************************************************/\nvoid\nxrdp_init_xkb_layout(struct xrdp_client_info *client_info)\n{\n    FILE *fp;\n    const char *keyboard_cfg_file = XRDP_CFG_PATH \"/xrdp_keyboard.toml\";\n\n    const struct xrdp_keyboard_overrides *ko =\n            &client_info->xrdp_keyboard_overrides;\n\n    LOG(LOG_LEVEL_INFO, \"xrdp_init_xkb_layout: Keyboard information sent\"\n        \" by the RDP client, keyboard_type:[0x%02X], keyboard_subtype:[0x%02X],\"\n        \" keylayout:[0x%08X]\",\n        client_info->keyboard_type, client_info->keyboard_subtype,\n        client_info->keylayout);\n\n    if (ko->type != -1)\n    {\n        LOG(LOG_LEVEL_INFO, \"overrode keyboard_type 0x%02X\"\n            \" with 0x%02X\", client_info->keyboard_type, ko->type);\n        client_info->keyboard_type = ko->type;\n    }\n    if (ko->subtype != -1)\n    {\n        LOG(LOG_LEVEL_INFO, \"overrode keyboard_subtype 0x%02X\"\n            \" with 0x%02X\", client_info->keyboard_subtype,\n            ko->subtype);\n        client_info->keyboard_subtype = ko->subtype;\n    }\n    if (ko->layout != -1)\n    {\n        LOG(LOG_LEVEL_INFO, \"overrode keylayout 0x%08X\"\n            \" with 0x%08X\", client_info->keylayout, ko->layout);\n        client_info->keylayout = ko->layout;\n    }\n    /* infer model/variant */\n    /* TODO specify different X11 keyboard models/variants */\n    client_info->model[0] = '\\0';\n    client_info->variant[0] = '\\0';\n    strlcpy(client_info->layout, \"us\", sizeof(client_info->layout));\n    if (client_info->keyboard_subtype == 0)\n    {\n        /* default - standard subtype */\n        client_info->keyboard_subtype = 1;\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"keyboard_cfg_file %s\", keyboard_cfg_file);\n\n    if ((fp = fopen(keyboard_cfg_file, \"r\")) == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error loading keyboard config file %s (%s)\",\n            keyboard_cfg_file, g_get_strerror());\n    }\n    else\n    {\n        char errbuf[200];\n        toml_table_t *tfile = toml_parse_file(fp, errbuf, sizeof(errbuf));\n        fclose(fp); // No longer need this open\n        fp = NULL;\n\n        if (tfile == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Error in keyboard config file %s - %s\",\n                keyboard_cfg_file, errbuf);\n        }\n        else\n        {\n            read_toml_config(client_info, keyboard_cfg_file, tfile);\n            LOG(LOG_LEVEL_INFO, \"xrdp_init_xkb_layout: model [%s] variant [%s] \"\n                \"layout [%s] options [%s]\",\n                client_info->model, client_info->variant,\n                client_info->layout, client_info->options);\n            toml_free(tfile);\n        }\n    }\n\n    // Initialise the rules and a few keycodes for xorgxrdp\n    strlcpy(client_info->xkb_rules, scancode_get_xkb_rules(),\n            sizeof(client_info->xkb_rules));\n    if (keylayout_supports_caps_lock(client_info->keylayout))\n    {\n        client_info->x11_keycode_caps_lock =\n            scancode_to_x11_keycode(SCANCODE_CAPS_KEY);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_init_xkb_layout: caps lock is not supported\");\n        client_info->x11_keycode_caps_lock = 0;\n    }\n    client_info->x11_keycode_num_lock =\n        scancode_to_x11_keycode(SCANCODE_NUMLOCK_KEY);\n    client_info->x11_keycode_scroll_lock =\n        scancode_to_x11_keycode(SCANCODE_SCROLL_KEY);\n}\n"
  },
  {
    "path": "xrdp/rdp-scan-codes.txt",
    "content": "\ncomplete rdp key code listing\n\nen-us\n\n4000s in the down flags column is from repeating keys(holding a key down)\nWhen holding a key down, the down flags repeat but the up flags only\ncome once at the end.\nRdesktop does not do this as of yet.  It always sends down and up\nfor each repeat.\n\nkey         rdp code       down flags  up flags\nesc         0x01  1        0000        8000\n1           0x02  2        0000        8000\n2           0x03  3        0000        8000\n3           0x04  4        0000        8000\n4           0x05  5        0000        8000\n5           0x06  6        0000        8000\n6           0x07  7        0000        8000\n7           0x08  8        0000        8000\n8           0x09  9        0000        8000\n9           0x0a  10       0000        8000\n0           0x0b  11       0000        8000\n-           0x0c  12       0000        8000\n=           0x0d  13       0000        8000\nbackspace   0x0e  14       0000        8000\ntab         0x0f  15       0000        8000\nq           0x10  16       0000        8000\nw           0x11  17       0000        8000\ne           0x12  18       0000        8000\nr           0x13  19       0000        8000\nt           0x14  20       0000        8000\ny           0x15  21       0000        8000\nu           0x16  22       0000        8000\ni           0x17  23       0000        8000\no           0x18  24       0000        8000\np           0x19  25       0000        8000\n[           0x1a  26       0000        8000\n]           0x1b  27       0000        8000\nenter       0x1c  28       0000        8000\nleft ctrl   0x1d  29       0000/4000   c000\nright ctrl  0x1d  29       0100/4100   c100\na           0x1e  30       0000        8000\ns           0x1f  31       0000        8000\nd           0x20  32       0000        8000\nf           0x21  33       0000        8000\ng           0x22  34       0000        8000\nh           0x23  35       0000        8000\nj           0x24  36       0000        8000\nk           0x25  37       0000        8000\nl           0x26  38       0000        8000\n;           0x27  39       0000        8000\n'           0x28  40       0000        8000\n`           0x29  41       0000        8000\nleft shift  0x2a  42       0000/4000   c000\n\\           0x2b  43       0000        8000\nz           0x2c  44       0000        8000\nx           0x2d  45       0000        8000\nc           0x2e  46       0000        8000\nv           0x2f  47       0000        8000\nb           0x30  48       0000        8000\nn           0x31  49       0000        8000\nm           0x32  50       0000        8000\n,           0x33  51       0000        8000\n.           0x34  52       0000        8000\n/           0x35  53       0000        8000\n/(keypad)   0x35  53       0100        8100\nright shift 0x36  54       0000/4000   c000\n*(keypad)   0x37  55       0000        8000\nprint scrn  0x37  55       0100        8100\nleft alt    0x38  56       0000/4000   c000\nright alt   0x38  56       0100/4100   c100\nspace       0x39  57       0000        8000\ncaps lock   0x3a  58       0000/4000   c000\nf1          0x3b  59       0000        8000\nf2          0x3c  60       0000        8000\nf3          0x3d  61       0000        8000\nf4          0x3e  62       0000        8000\nf5          0x3f  63       0000        8000\nf6          0x40  64       0000        8000\nf7          0x41  65       0000        8000\nf8          0x42  66       0000        8000\nf9          0x43  67       0000        8000\nf10         0x44  68       0000        8000\nnum lock    0x45  69       0000/4000   c000\nscroll lock 0x46  70       0000/4000   c000\n7(keypad)   0x47  71       0000        8000\nhome        0x47  71       0100        8100\n8(keypad)   0x48  72       0000        8000\nup arrow    0x48  72       0100        8100\n9(keypad)   0x49  73       0000        8000\npg up       0x49  73       0100        8100\n-(keypad)   0x4a  74       0000        8000\n4(keypad)   0x4b  75       0000        8000\nleft arrow  0x4b  75       0100        8100\n5(keypad)   0x4c  76       0000        8000\n6(keypad)   0x4d  77       0000        8000\nright arrow 0x4d  77       0100        8100\n+(keypad)   0x4e  78       0000        8000\n1(keypad)   0x4f  79       0000        8000\nend         0x4f  79       0100        8100\n2(keypad)   0x50  80       0000        8000\ndown arrow  0x50  80       0100        8100\n3(keypad)   0x51  81       0000        8000\npg down     0x51  81       0100        8100\n0(keypad)   0x52  82       0000        8000\ninsert      0x52  82       0100        8100\n.(keypad)   0x53  83       0000        8000\ndelete      0x53  83       0100        8100\n?           0x54  84\n?           0x55  85\n?           0x56  86\nf11         0x57  87       0000        8000\nf12         0x58  88       0000        8000\n?           0x59  89\n?           0x5a  90\nleft win    0x5b  91       0100        8100\nright win   0x5c  92       0100        8100\nmenu key    0x5d  93       0100        8100\n\npause break 0x1d  29       0200        8200\n            0x45  69       0000        8000\nThis is a special key that sends 2 down and 2 up like this\ndown 001d 0200\ndown 0045 0000\nup   001d 8200\nup   0045 8000\n"
  },
  {
    "path": "xrdp/xrdp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * main program\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdarg.h>\n\n#include \"xrdp.h\"\n#include \"log.h\"\n#include \"xrdp_configure_options.h\"\n#include \"copying_third_party.h\"\n#include \"string_calls.h\"\n\n#if !defined(PACKAGE_VERSION)\n#define PACKAGE_VERSION \"???\"\n#endif\n\nstatic struct xrdp_listen *g_listen = 0;\n\n\n/*****************************************************************************/\nstatic void\nprint_license(void)\n{\n    g_writeln(\"Third Party Code Additional Copyright Notices and License Terms\");\n    g_writeln(\"%s\", \"\");\n    g_writeln(\"Following third-party code are used in xrdp %s:\", PACKAGE_VERSION);\n    g_writeln(\"%s\", \"\");\n    g_writeln(\"%s\", copying_third_party);\n}\n/*****************************************************************************/\nstatic void\nprint_version(void)\n{\n    g_writeln(\"xrdp %s\", PACKAGE_VERSION);\n    g_writeln(\"  A Remote Desktop Protocol Server.\");\n    g_writeln(\"  Copyright (C) 2004-%d Jay Sorg, \"\n              \"Neutrino Labs, and all contributors.\",\n              VERSION_YEAR);\n    g_writeln(\"  See https://github.com/neutrinolabs/xrdp for more information.\");\n    g_writeln(\"%s\", \"\");\n\n#if defined(XRDP_CONFIGURE_OPTIONS)\n    g_writeln(\"  Configure options:\");\n    g_writeln(\"%s\", XRDP_CONFIGURE_OPTIONS);\n#endif\n\n    g_writeln(\"  Compiled with %s\", get_openssl_version());\n\n}\n\n/*****************************************************************************/\nstatic void\nprint_help(void)\n{\n    g_writeln(\"Usage: xrdp [options]\");\n    g_writeln(\"   -k, --kill        shut down xrdp\");\n    g_writeln(\"   -h, --help        show help\");\n    g_writeln(\"   -v, --version     show version\");\n    g_writeln(\"   -n, --nodaemon    don't fork into background\");\n    g_writeln(\"   -p, --port        tcp listen port\");\n    g_writeln(\"   -f, --fork        fork on new connection\");\n    g_writeln(\"   -c, --config      specify new path to xrdp.ini\");\n    g_writeln(\"       --dump-config display config on stdout on startup\");\n    g_writeln(\"       --license     show additional license information\");\n}\n\n/*****************************************************************************/\n/* Signal handler for SIGINT and SIGTERM\n * Note: only signal safe code (eg. setting wait event) should be executed in\n * this function. For more details see `man signal-safety`\n */\nstatic void\nxrdp_shutdown(int sig)\n{\n    g_set_wait_obj(g_get_term());\n}\n\n/*****************************************************************************/\n/* Signal handler for SIGCHLD\n * Note: only signal safe code (eg. setting wait event) should be executed in\n * this function. For more details see `man signal-safety`\n */\nstatic void\nxrdp_child(int sig)\n{\n    g_set_sigchld(1);\n}\n\n/*****************************************************************************/\n/**\n * @brief looks for a case-insensitive match of a string in a list\n * @param candidate  String to match\n * @param ... NULL-terminated list of strings to compare the candidate with\n * @return !=0 if the candidate is found in the list\n */\nstatic int nocase_matches(const char *candidate, ...)\n{\n    va_list vl;\n    const char *member;\n    int result = 0;\n\n    va_start(vl, candidate);\n    while ((member = va_arg(vl, const char *)) != NULL)\n    {\n        if (g_strcasecmp(candidate, member) == 0)\n        {\n            result = 1;\n            break;\n        }\n    }\n\n    va_end(vl);\n    return result;\n}\n\n/*****************************************************************************/\n/* No-op signal handler.\n * Note: only signal safe code (eg. setting wait event) should be executed in\n * this function. For more details see `man signal-safety`\n */\nstatic void\nxrdp_sig_no_op(int sig)\n{\n    /* no-op */\n}\n\n/*****************************************************************************/\n/**\n *\n * @brief  Command line argument parser\n * @param argc number of command line arguments\n * @param argv pointer array of commandline arguments\n * @param startup_params [out] Returned startup parameters\n * @return 0 on success, n on nth argument is unknown\n *\n */\nstatic int\nxrdp_process_params(int argc, char **argv,\n                    struct xrdp_startup_params *startup_params)\n{\n    int index;\n    const char *option;\n    const char *value;\n\n    index = 1;\n\n    while (index < argc)\n    {\n        option = argv[index];\n\n        if (index + 1 < argc)\n        {\n            value = argv[index + 1];\n        }\n        else\n        {\n            value = \"\";\n        }\n\n        if (nocase_matches(option, \"-help\", \"--help\", \"-h\", (const char *)0))\n        {\n            startup_params->help = 1;\n        }\n        else if (nocase_matches(option, \"-kill\", \"--kill\", \"-k\",\n                                (const char *)0))\n        {\n            startup_params->kill = 1;\n        }\n        else if (nocase_matches(option, \"-nodaemon\", \"--nodaemon\", \"-n\",\n                                \"-nd\", \"--nd\", \"-ns\", \"--ns\", (const char *)0))\n        {\n            startup_params->no_daemon = 1;\n        }\n        else if (nocase_matches(option, \"-v\", \"--version\", (const char *)0))\n        {\n            startup_params->version = 1;\n        }\n        else if (nocase_matches(option, \"-p\", \"--port\", (const char *)0))\n        {\n            index++;\n            g_strncpy(startup_params->port, value,\n                      sizeof(startup_params->port) - 1);\n\n            if (g_strlen(startup_params->port) < 1)\n            {\n                g_writeln(\"error processing params, port [%s]\", startup_params->port);\n                return 1;\n            }\n            else\n            {\n                g_writeln(\"--port parameter found, ini override [%s]\",\n                          startup_params->port);\n            }\n        }\n        else if (nocase_matches(option, \"-f\", \"--fork\", (const char *)0))\n        {\n            startup_params->fork = 1;\n            g_writeln(\"--fork parameter found, ini override\");\n        }\n        else if (nocase_matches(option, \"--dump-config\", (const char *)0))\n        {\n            startup_params->dump_config = 1;\n        }\n        else if (nocase_matches(option, \"--license\", (const char *)0))\n        {\n            startup_params->license = 1;\n        }\n        else if (nocase_matches(option, \"-c\", \"--config\", (const char *)0))\n        {\n            index++;\n            startup_params->xrdp_ini = value;\n        }\n        else /* unknown option */\n        {\n            return index;\n        }\n\n        index++;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n *\n * @brief  Read additional startup parameters from xrdp.ini\n *\n * @param[in,out] startup_params parameters from the command line\n * @return 0 on success\n *\n */\nstatic int\nread_xrdp_ini_startup_params(struct xrdp_startup_params *startup_params)\n{\n    int rv = 0;\n    int fd;\n    int index;\n    int port_override;\n    int fork_override;\n    const char *name;\n    const char *val;\n    struct list *names;\n    struct list *values;\n\n    port_override = startup_params->port[0] != 0;\n    fork_override = startup_params->fork;\n    names = list_create();\n    names->auto_free = 1;\n    values = list_create();\n    values->auto_free = 1;\n\n    fd = g_file_open_ro(startup_params->xrdp_ini);\n    if (fd < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't open %s [%s]\", startup_params->xrdp_ini,\n            g_get_strerror());\n        rv = 1;\n    }\n    else if (file_read_section(fd, \"globals\", names, values) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't read [Globals] from %s\",\n            startup_params->xrdp_ini);\n        rv = 1;\n    }\n    else\n    {\n        for (index = 0; index < names->count; index++)\n        {\n            name = (const char *)list_get_item(names, index);\n            val = (const char *)list_get_item(values, index);\n            if (name == 0 || val == 0)\n            {\n                continue;\n            }\n\n            if (g_strcasecmp(name, \"port\") == 0)\n            {\n                if (port_override == 0)\n                {\n                    g_strncpy(startup_params->port, val,\n                              sizeof(startup_params->port) - 1);\n                }\n            }\n\n            if (g_strcasecmp(name, \"instance_name\") == 0)\n            {\n                strlcpy(startup_params->instance_name, val,\n                        sizeof(startup_params->instance_name) - 1);\n            }\n\n            else if (g_strcasecmp(name, \"fork\") == 0)\n            {\n                if (fork_override == 0)\n                {\n                    startup_params->fork = g_text2bool(val);\n                }\n            }\n\n            else if (g_strcasecmp(name, \"tcp_nodelay\") == 0)\n            {\n                startup_params->tcp_nodelay = g_text2bool(val);\n            }\n\n            else if (g_strcasecmp(name, \"tcp_keepalive\") == 0)\n            {\n                startup_params->tcp_keepalive = g_text2bool(val);\n            }\n\n            else if (g_strcasecmp(name, \"tcp_send_buffer_bytes\") == 0)\n            {\n                startup_params->tcp_send_buffer_bytes = g_atoi(val);\n            }\n\n            else if (g_strcasecmp(name, \"tcp_recv_buffer_bytes\") == 0)\n            {\n                startup_params->tcp_recv_buffer_bytes = g_atoi(val);\n            }\n\n            else if (g_strcasecmp(name, \"use_vsock\") == 0)\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Config parameter 'use_vsock' is obsolete. \"\n                    \"Use 'port=vsock://...' instead\");\n                startup_params->use_vsock = g_text2bool(val);\n            }\n\n            else if (g_strcasecmp(name, \"runtime_user\") == 0)\n            {\n                g_snprintf(startup_params->runtime_user,\n                           sizeof(startup_params->runtime_user),\n                           \"%s\", val);\n            }\n\n            else if (g_strcasecmp(name, \"runtime_group\") == 0)\n            {\n                g_snprintf(startup_params->runtime_group,\n                           sizeof(startup_params->runtime_group),\n                           \"%s\", val);\n            }\n        }\n    }\n\n    list_delete(names);\n    list_delete(values);\n    if (fd >= 0)\n    {\n        g_file_close(fd);\n    }\n    return rv;\n}\n\n\n/*****************************************************************************/\n/* Basic sanity checks before any forking */\nstatic int\nxrdp_sanity_check(void)\n{\n    int intval = 1;\n    int host_be;\n    const char *key_file = XRDP_CFG_PATH \"/rsakeys.ini\";\n\n    /* check compiled endian with actual endian */\n    host_be = !((int)(*(unsigned char *)(&intval)));\n\n#if defined(B_ENDIAN)\n    if (!host_be)\n    {\n        g_writeln(\"Not a big endian machine, edit arch.h\");\n        return 1;\n    }\n#endif\n#if defined(L_ENDIAN)\n    if (host_be)\n    {\n        g_writeln(\"Not a little endian machine, edit arch.h\");\n        return 1;\n    }\n#endif\n\n    /* check long, int and void* sizes */\n#if SIZEOF_INT != 4\n#   error unusable int size, must be 4\n#endif\n\n#if SIZEOF_LONG != SIZEOF_VOID_P\n#   error sizeof(long) must match sizeof(void*)\n#endif\n\n#if SIZEOF_LONG != 4 && SIZEOF_LONG != 8\n#   error sizeof(long), must be 4 or 8\n#endif\n\n    if (sizeof(tui64) != 8)\n    {\n        g_writeln(\"unusable tui64 size, must be 8\");\n        return 1;\n    }\n\n    if (!g_file_exist(key_file))\n    {\n        g_writeln(\"File %s is missing, create it using xrdp-keygen\", key_file);\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\ncheck_drop_privileges(struct xrdp_startup_params *startup_params)\n{\n    int rv = 1;\n    const char *user = startup_params->runtime_user;\n    const char *group = startup_params->runtime_group;\n    int entry_uid = g_getuid();\n    int entry_gid = g_getgid();\n\n    // Regard a user as privileged if either the UID or GID is zero\n    int privileged_user = (entry_uid == 0 || entry_gid == 0);\n    if (!privileged_user)\n    {\n        // xrdp daemon UID:GID is already set by whatever started it. We'll\n        // log this as it may be unexpected and continue. We don't have\n        // any privilege to override this.\n        LOG(LOG_LEVEL_INFO,\n            \"xrdp is already running as an unprivileged user uid=%d gid=%d\",\n            entry_uid, entry_gid);\n        rv = 0;\n    }\n    else if (user[0] == '\\0' && group[0] == '\\0')\n    {\n        // We're running as a privileged user, and this isn't\n        // overridden in our own config\n        LOG(LOG_LEVEL_ALWAYS,\n            \"You are running xrdp as uid=%d gid=%d. This is not recommended.\",\n            entry_uid, entry_gid);\n        rv = 0; // Allowed for now for old configs\n    }\n    else if (user[0] == '\\0' || group[0] == '\\0')\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"Both a runtime_user and a runtime_group MUST be specified\");\n    }\n    else\n    {\n        rv = g_drop_privileges(user, group);\n        if (rv == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"Switched user:group to %s:%s\", user, group);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nread_pid_file(const char *pid_file)\n{\n    int pid = -1;\n    int fd = g_file_open_ro(pid_file); /* xrdp.pid */\n    if (fd >= 0)\n    {\n        char text[32];\n        g_memset(text, 0, sizeof(text));\n        g_file_read(fd, text, sizeof(text) - 1);\n        pid = g_atoi(text);\n        g_file_close(fd);\n    }\n\n    return pid;\n}\n\n/*****************************************************************************/\n/**\n * Kills an active xrdp daemon\n *\n * It is assumed that logging is not active\n *\n * @param pid_file PID file\n * @return 0 for success\n */\nstatic int\nkill_daemon(const char *pid_file)\n{\n    int status = 1;\n    int pid;\n    if (g_getuid() != 0)\n    {\n        g_writeln(\"Must be root\");\n    }\n    else if ((pid = read_pid_file(pid_file)) > 0)\n    {\n        if (!g_pid_is_active(pid))\n        {\n            g_writeln(\"Daemon not active\");\n            status = 0;\n        }\n        else\n        {\n            g_writeln(\"stopping process id %d\", pid);\n            int i;\n            g_sigterm(pid);\n            g_sleep(100);\n            i = 5 * 1000 / 500;\n            while (i > 0 && g_pid_is_active(pid))\n            {\n                g_sleep(500);\n                --i;\n            }\n\n            if (g_pid_is_active(pid))\n            {\n                g_writeln(\"Can't stop process\");\n            }\n            else\n            {\n                status = 0;\n            }\n        }\n\n        if (status == 0)\n        {\n            /* delete the xrdp.pid file, as xrdp can't do this\n             * if it's running without privilege */\n            g_file_delete(pid_file);\n        }\n    }\n\n    return status;\n}\n\n/*****************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    int exit_status = 1;\n    enum logReturns error;\n    struct xrdp_startup_params startup_params = {0};\n    int pid;\n    int daemon_pid = 0;\n    int daemon;\n    char text[256];\n    const char *pid_file = XRDP_PID_PATH \"/xrdp.pid\";\n    int errored_argc;\n\n#ifdef USE_DEVEL_LOGGING\n    int test;\n    for (test = 0; test < argc; test++)\n    {\n        g_writeln(\"Argument %i - %s\", test, argv[test]);\n    }\n#endif\n\n    g_init(\"xrdp\");\n    ssl_init();\n\n    startup_params.xrdp_ini = XRDP_CFG_PATH \"/xrdp.ini\";\n\n    errored_argc = xrdp_process_params(argc, argv, &startup_params);\n    if (errored_argc > 0)\n    {\n        print_version();\n        g_writeln(\"%s\", \"\");\n        print_help();\n        g_writeln(\"%s\", \"\");\n\n        g_writeln(\"Unknown option: %s\", argv[errored_argc]);\n        g_deinit();\n        g_exit(1);\n    }\n\n    if (startup_params.help)\n    {\n        print_version();\n        g_writeln(\"%s\", \"\");\n        print_help();\n\n        g_deinit();\n        g_exit(0);\n    }\n\n    if (startup_params.version)\n    {\n        print_version();\n        g_deinit();\n        g_exit(0);\n    }\n\n    if (startup_params.license)\n    {\n        print_license();\n        g_deinit();\n        g_exit(0);\n    }\n\n    if (xrdp_sanity_check() != 0)\n    {\n        g_writeln(\"Fatal error occurred, exiting\");\n        g_deinit();\n        g_exit(1);\n    }\n\n    if (startup_params.kill)\n    {\n        int status = kill_daemon(pid_file);\n        g_deinit();\n        g_exit(status);\n    }\n\n    /* starting logging subsystem */\n    error = log_start(startup_params.xrdp_ini, \"xrdp\",\n                      (startup_params.dump_config) ? LOG_START_DUMP_CONFIG : 0);\n\n    if (error != LOG_STARTUP_OK)\n    {\n        switch (error)\n        {\n            case LOG_ERROR_MALLOC:\n                g_writeln(\"error on malloc. cannot start logging. quitting.\");\n                break;\n            case LOG_ERROR_FILE_OPEN:\n                g_writeln(\"error opening log file [%s]. quitting.\",\n                          getLogFile(text, 255));\n                break;\n            case LOG_ERROR_NO_CFG:\n                g_writeln(\"config file %s unreadable or missing\",\n                          startup_params.xrdp_ini);\n                break;\n            default:\n                g_writeln(\"log_start error\");\n                break;\n        }\n\n        g_deinit();\n        g_exit(1);\n    }\n\n    if (read_xrdp_ini_startup_params(&startup_params) != 0)\n    {\n        log_end();\n        g_deinit();\n        g_exit(1);\n    }\n\n    if ((pid = read_pid_file(pid_file)) > 0 && g_pid_is_active(pid))\n    {\n        LOG(LOG_LEVEL_ALWAYS,\n            \"It looks like xrdp (pid=%d) is already running.\", pid);\n        LOG(LOG_LEVEL_ALWAYS, \"If not, delete %s and try again.\", pid_file);\n        log_end();\n        g_deinit();\n        g_exit(1);\n    }\n\n    daemon = !startup_params.no_daemon;\n\n\n    if (daemon)\n    {\n        /* make sure containing directory exists */\n        g_create_path(pid_file);\n\n        /* make sure we can write to pid file */\n        int pid_fd = g_file_open_rw(pid_file); /* xrdp.pid */\n\n        if (pid_fd == -1)\n        {\n            LOG(LOG_LEVEL_ALWAYS,\n                \"running in daemon mode with no access to pid files, quitting\");\n            log_end();\n            g_deinit();\n            g_exit(1);\n        }\n\n        /* Before daemonising, check we can listen.\n         * If we can't listen, exit with failure status */\n        struct xrdp_listen *xrdp_listen;\n        xrdp_listen = xrdp_listen_create(&startup_params);\n        int status = xrdp_listen_init(xrdp_listen);\n        xrdp_listen_delete(xrdp_listen);\n\n        if (status != 0)\n        {\n            LOG(LOG_LEVEL_ALWAYS, \"Failed to start xrdp daemon, \"\n                \"possibly address already in use.\");\n            log_end();\n            g_deinit();\n            /* must exit with failure status,\n               or systemd cannot detect xrdp daemon couldn't start properly */\n            g_exit(1);\n        }\n\n        /* start of daemonizing code */\n        pid = g_fork();\n\n        if (pid == -1)\n        {\n            LOG(LOG_LEVEL_ALWAYS, \"problem forking [%s]\", g_get_strerror());\n            log_end();\n            g_deinit();\n            g_exit(1);\n        }\n\n        if (0 != pid)\n        {\n            /* exit, this is the main process */\n            log_end();\n            g_deinit();\n            g_exit(0);\n        }\n\n        daemon_pid = g_getpid();\n        g_sleep(1000);\n        /* write our pid to file */\n        g_sprintf(text, \"%d\", g_getpid());\n        g_file_write(pid_fd, text, g_strlen(text));\n        g_file_close(pid_fd);\n\n        g_sleep(1000);\n        g_file_close(0);\n        g_file_close(1);\n        g_file_close(2);\n\n        if (g_file_open_rw(\"/dev/null\") < 0)\n        {\n        }\n\n        if (g_file_open_rw(\"/dev/null\") < 0)\n        {\n        }\n\n        if (g_file_open_rw(\"/dev/null\") < 0)\n        {\n        }\n\n        /* end of daemonizing code */\n    }\n\n    g_listen = xrdp_listen_create(&startup_params);\n    if (xrdp_listen_init(g_listen) != 0)\n    {\n        LOG(LOG_LEVEL_ALWAYS, \"Failed to start xrdp daemon, \"\n            \"possibly address already in use.\");\n    }\n    else if (check_drop_privileges(&startup_params) == 0)\n    {\n        g_set_threadid(tc_get_threadid());\n        g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */\n        g_signal_pipe(xrdp_sig_no_op);          /* SIGPIPE */\n        g_signal_terminate(xrdp_shutdown);      /* SIGTERM */\n        g_signal_child_stop(xrdp_child);        /* SIGCHLD */\n        g_signal_hang_up(xrdp_sig_no_op);       /* SIGHUP */\n        g_set_sync_mutex(tc_mutex_create());\n        g_set_sync1_mutex(tc_mutex_create());\n        pid = g_getpid();\n        LOG(LOG_LEVEL_INFO, \"starting xrdp with pid %d\", pid);\n        g_snprintf(text, 255, \"xrdp_%8.8x_main_term\", pid);\n        g_set_term_event(g_create_wait_obj(text));\n\n        if (g_get_term() == 0)\n        {\n            LOG(LOG_LEVEL_WARNING, \"error creating g_term_event\");\n        }\n\n        g_snprintf(text, 255, \"xrdp_%8.8x_main_sigchld\", pid);\n        g_set_sigchld_event(g_create_wait_obj(text));\n\n        if (g_get_sigchld() == 0)\n        {\n            LOG(LOG_LEVEL_WARNING, \"error creating g_sigchld_event\");\n        }\n\n        g_snprintf(text, 255, \"xrdp_%8.8x_main_sync\", pid);\n        g_set_sync_event(g_create_wait_obj(text));\n\n        if (g_get_sync_event() == 0)\n        {\n            LOG(LOG_LEVEL_WARNING, \"error creating g_sync_event\");\n        }\n\n        exit_status = xrdp_listen_main_loop(g_listen);\n    }\n\n    xrdp_listen_delete(g_listen);\n\n    tc_mutex_delete(g_get_sync_mutex());\n    g_set_sync_mutex(0);\n\n    tc_mutex_delete(g_get_sync1_mutex());\n    g_set_sync1_mutex(0);\n\n    g_delete_wait_obj(g_get_term());\n    g_set_term_event(0);\n\n    g_delete_wait_obj(g_get_sigchld());\n    g_set_sigchld_event(0);\n\n    g_delete_wait_obj(g_get_sync_event());\n    g_set_sync_event(0);\n\n    if (daemon && (daemon_pid == g_getpid()))\n    {\n        /* Try to delete the PID file, although if we've dropped\n         * privileges this won't be successful */\n        g_file_delete(pid_file);\n    }\n\n    log_end();\n    g_deinit();\n\n    if (exit_status == 0)\n    {\n        g_exit(0);\n    }\n    else\n    {\n        g_exit(1);\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/xrdp.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * main include file\n */\n\n#ifndef _XRDP_XRDP_H_\n#define _XRDP_XRDP_H_\n\n/* include other h files */\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"trans.h\"\n#include \"list.h\"\n#include \"list16.h\"\n#include \"libxrdpinc.h\"\n#include \"xrdp_constants.h\"\n#include \"xrdp_types.h\"\n#include \"defines.h\"\n#include \"os_calls.h\"\n#include \"ssl_calls.h\"\n#include \"thread_calls.h\"\n#include \"file.h\"\n#include \"xrdp_client_info.h\"\n#include \"log.h\"\n\n#if defined(XRDP_X264) || defined(XRDP_OPENH264) || defined(XRDP_NVENC)\n#if !defined(XRDP_H264)\n#define XRDP_H264 1\n#endif\n#else\n#undef XRDP_H264\n#endif\n\n/* xrdp.c */\nlong\ng_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1,\n            long sync_param2);\nint\nxrdp_child_fork(void);\nlong\ng_get_sync_mutex(void);\nvoid\ng_set_sync_mutex(long mutex);\nlong\ng_get_sync1_mutex(void);\nvoid\ng_set_sync1_mutex(long mutex);\nvoid\ng_set_term_event(tbus event);\nvoid\ng_set_sigchld_event(tbus event);\nvoid\ng_set_sync_event(tbus event);\nlong\ng_get_threadid(void);\nvoid\ng_set_threadid(long id);\ntbus\ng_get_term(void);\ntbus\ng_get_sigchld(void);\nint\ng_is_term(void);\nvoid\ng_set_term(int in_val);\nvoid\ng_set_sigchld(int in_val);\ntbus\ng_get_sync_event(void);\nvoid\ng_process_waiting_function(void);\n\n/* xrdp_cache.c */\nstruct xrdp_cache *\nxrdp_cache_create(struct xrdp_wm *owner, struct xrdp_session *session,\n                  struct xrdp_client_info *client_info);\nvoid\nxrdp_cache_delete(struct xrdp_cache *self);\nint\nxrdp_cache_reset(struct xrdp_cache *self,\n                 struct xrdp_client_info *client_info);\nint\nxrdp_cache_add_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap,\n                      int hints);\nint\nxrdp_cache_add_palette(struct xrdp_cache *self, int *palette);\nint\nxrdp_cache_add_char(struct xrdp_cache *self,\n                    struct xrdp_font_char *font_item);\nint\nxrdp_cache_add_pointer(struct xrdp_cache *self,\n                       struct xrdp_pointer_item *pointer_item);\nint\nxrdp_cache_add_pointer_static(struct xrdp_cache *self,\n                              struct xrdp_pointer_item *pointer_item,\n                              int index);\nint\nxrdp_cache_add_brush(struct xrdp_cache *self,\n                     char *brush_item_data);\nint\nxrdp_cache_add_os_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap,\n                         int rdpindex);\nint\nxrdp_cache_remove_os_bitmap(struct xrdp_cache *self, int rdpindex);\nstruct xrdp_os_bitmap_item *\nxrdp_cache_get_os_bitmap(struct xrdp_cache *self, int rdpindex);\n\n/* xrdp_wm.c */\nstruct xrdp_wm *\nxrdp_wm_create(struct xrdp_process *owner,\n               struct xrdp_client_info *client_info);\nvoid\nxrdp_wm_delete(struct xrdp_wm *self);\nint\nxrdp_wm_send_palette(struct xrdp_wm *self);\nint\nxrdp_wm_send_bell(struct xrdp_wm *self);\nint\nxrdp_wm_load_static_colors_plus(struct xrdp_wm *self, char *autorun_name);\nint\nxrdp_wm_load_static_pointers(struct xrdp_wm *self);\nint\nxrdp_wm_init(struct xrdp_wm *self);\nint\nxrdp_wm_send_bitmap(struct xrdp_wm *self, struct xrdp_bitmap *bitmap,\n                    int x, int y, int cx, int cy);\nint\nxrdp_wm_set_pointer(struct xrdp_wm *self, int cache_idx);\nint\nxrdp_wm_set_focused(struct xrdp_wm *self, struct xrdp_bitmap *wnd);\nint\nxrdp_wm_get_vis_region(struct xrdp_wm *self, struct xrdp_bitmap *bitmap,\n                       int x, int y, int cx, int cy,\n                       struct xrdp_region *region, int clip_children);\nint\nxrdp_wm_mouse_move(struct xrdp_wm *self, int x, int y);\nint\nxrdp_wm_mouse_touch(struct xrdp_wm *self, int gesture, int param);\nint\nxrdp_wm_mouse_click(struct xrdp_wm *self, int x, int y, int but, int down);\n/**\n * Handle a TS_KEYBOARD_EVENT ([MS-RDPBCGR] 2.2.8.1.1.3.1.1.1)\n *\n * @param keyboard_flags keyboardFlags value from PDU\n * @param key_code keyCode value from PDU\n */\nint\nxrdp_wm_key(struct xrdp_wm *self, int keyboard_flags, int key_code);\nint\nxrdp_wm_key_sync(struct xrdp_wm *self, int device_flags, int key_flags);\nint\nxrdp_wm_pu(struct xrdp_wm *self, struct xrdp_bitmap *control);\nint\nxrdp_wm_send_pointer_system(struct xrdp_wm *self, int pointer_type);\nint\nxrdp_wm_send_pointer_position(struct xrdp_wm *self, int x, int y);\nint\nxrdp_wm_send_pointer(struct xrdp_wm *self, int cache_idx,\n                     char *data, char *mask, int x, int y, int bpp,\n                     int width, int height);\nint\nxrdp_wm_pointer(struct xrdp_wm *self, char *data, char *mask, int x, int y,\n                int bpp, int width, int height);\nint\ncallback(struct xrdp_process *id, int msg, intptr_t param1, intptr_t param2,\n         intptr_t param3, intptr_t param4);\nint\nxrdp_wm_delete_all_children(struct xrdp_wm *self);\nint\nxrdp_wm_show_log(struct xrdp_wm *self);\nint\nxrdp_wm_log_msg(struct xrdp_wm *self, enum logLevels loglevel,\n                const char *fmt, ...) printflike(3, 4);\nint\nxrdp_wm_get_wait_objs(struct xrdp_wm *self, tbus *robjs, int *rc,\n                      tbus *wobjs, int *wc, int *timeout);\nint\nxrdp_wm_check_wait_objs(struct xrdp_wm *self);\nconst char *\nxrdp_wm_login_state_to_str(enum wm_login_state login_state);\nint\nxrdp_wm_set_login_state(struct xrdp_wm *self, enum wm_login_state login_state);\nint\nxrdp_wm_can_resize(struct xrdp_wm *self);\nvoid\nxrdp_wm_mod_connect_done(struct xrdp_wm *self, int status);\n\n/* xrdp_process.c */\nstruct xrdp_process *\nxrdp_process_create(struct xrdp_listen *owner, tbus done_event);\nvoid\nxrdp_process_delete(struct xrdp_process *self);\nint\nxrdp_process_main_loop(struct xrdp_process *self);\n\n/* xrdp_listen.c */\nstruct xrdp_listen *\nxrdp_listen_create(struct xrdp_startup_params *startup_params);\nint\nxrdp_listen_init(struct xrdp_listen *self);\nvoid\nxrdp_listen_delete(struct xrdp_listen *self);\nint\nxrdp_listen_main_loop(struct xrdp_listen *self);\n\n\n/* xrdp_region.c */\nstruct xrdp_region *\nxrdp_region_create(struct xrdp_wm *wm);\nvoid\nxrdp_region_delete(struct xrdp_region *self);\nint\nxrdp_region_add_rect(struct xrdp_region *self, struct xrdp_rect *rect);\nint\nxrdp_region_subtract_rect(struct xrdp_region *self, struct xrdp_rect *rect);\nint\nxrdp_region_intersect_rect(struct xrdp_region *self, struct xrdp_rect *rect);\nint\nxrdp_region_get_rect(struct xrdp_region *self, int index,\n                     struct xrdp_rect *rect);\nint\nxrdp_region_get_bounds(struct xrdp_region *self, struct xrdp_rect *rect);\nint\nxrdp_region_not_empty(struct xrdp_region *self);\n\n/* xrdp_bitmap_common.c */\nstruct xrdp_bitmap *\nxrdp_bitmap_create(int width, int height, int bpp,\n                   int type, struct xrdp_wm *wm);\nstruct xrdp_bitmap *\nxrdp_bitmap_create_with_data(int width, int height,\n                             int bpp, char *data,\n                             struct xrdp_wm *wm);\nvoid\nxrdp_bitmap_delete(struct xrdp_bitmap *self);\nint\nxrdp_bitmap_resize(struct xrdp_bitmap *self, int width, int height);\nint\nxrdp_bitmap_get_pixel(struct xrdp_bitmap *self, int x, int y);\nint\nxrdp_bitmap_set_pixel(struct xrdp_bitmap *self, int x, int y, int pixel);\nint\nxrdp_bitmap_copy_box(struct xrdp_bitmap *self,\n                     struct xrdp_bitmap *dest,\n                     int x, int y, int cx, int cy);\n\n/* xrdp_bitmap.c */\nstruct xrdp_bitmap *\nxrdp_bitmap_get_child_by_id(struct xrdp_bitmap *self, int id);\nint\nxrdp_bitmap_set_focus(struct xrdp_bitmap *self, int focused);\nint\nxrdp_bitmap_hash_crc(struct xrdp_bitmap *self);\nint\nxrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,\n                              struct xrdp_bitmap *dest,\n                              int x, int y, int cx, int cy);\nint\nxrdp_bitmap_compare(struct xrdp_bitmap *self,\n                    struct xrdp_bitmap *b);\nint\nxrdp_bitmap_invalidate(struct xrdp_bitmap *self, struct xrdp_rect *rect);\nint\nxrdp_bitmap_def_proc(struct xrdp_bitmap *self, int msg,\n                     int param1, int param2);\nint\nxrdp_bitmap_to_screenx(struct xrdp_bitmap *self, int x);\nint\nxrdp_bitmap_to_screeny(struct xrdp_bitmap *self, int y);\nint\nxrdp_bitmap_from_screenx(struct xrdp_bitmap *self, int x);\nint\nxrdp_bitmap_from_screeny(struct xrdp_bitmap *self, int y);\nint\nxrdp_bitmap_get_screen_clip(struct xrdp_bitmap *self,\n                            struct xrdp_painter *painter,\n                            struct xrdp_rect *rect,\n                            int *dx, int *dy);\n\n/* xrdp_bitmap_load.c */\n/**\n * Loads a bitmap from a file and (optionally) transforms it\n *\n * @param self from rdp_bitmap_create()\n * @param filename Filename to load\n * @param[in] palette For 8-bit conversions. Currently unused\n * @param background Background color for alpha-blending\n * @param transform Transform to apply to the image after loading\n * @param twidth target width if transform != XBLT_NONE\n * @param theight target height if transform != XBLT_NONE\n * @return 0 for success.\n *\n * The background color is only used if the specified image contains\n * an alpha layer. It is in HCOLOR format, and the bpp must correspond to\n * the bpp used to create 'self'.\n *\n * After a successful call, the bitmap is resized to the image file size.\n *\n * If the call is not successful, the bitmap will be in an indeterminate\n * state and should not be used.\n */\nint\nxrdp_bitmap_load(struct xrdp_bitmap *self, const char *filename,\n                 const int *palette,\n                 int background,\n                 enum xrdp_bitmap_load_transform transform,\n                 int twidth,\n                 int theight);\n/* xrdp_painter.c */\nstruct xrdp_painter *\nxrdp_painter_create(struct xrdp_wm *wm, struct xrdp_session *session);\nvoid\nxrdp_painter_delete(struct xrdp_painter *self);\nint\nwm_painter_set_target(struct xrdp_painter *self);\nint\nxrdp_painter_begin_update(struct xrdp_painter *self);\nint\nxrdp_painter_end_update(struct xrdp_painter *self);\nint\nxrdp_painter_font_needed(struct xrdp_painter *self);\nint\nxrdp_painter_set_clip(struct xrdp_painter *self,\n                      int x, int y, int cx, int cy);\nint\nxrdp_painter_clr_clip(struct xrdp_painter *self);\nint\nxrdp_painter_fill_rect(struct xrdp_painter *self,\n                       struct xrdp_bitmap *bitmap,\n                       int x, int y, int cx, int cy);\nint\nxrdp_painter_draw_bitmap(struct xrdp_painter *self,\n                         struct xrdp_bitmap *bitmap,\n                         struct xrdp_bitmap *to_draw,\n                         int x, int y, int cx, int cy);\nint\nxrdp_painter_text_width(struct xrdp_painter *self, const char *text);\n\n/* As above, but have a maximum Unicode character count for the string */\nint\nxrdp_painter_text_width_count(struct xrdp_painter *self,\n                              const char *text, unsigned int c32_count);\n\n/* Size of a string composed of a repeated number of Unicode characters */\nint\nxrdp_painter_repeated_char_width(struct xrdp_painter *self,\n                                 char32_t c32, unsigned int repeat_count);\n\nunsigned int\nxrdp_painter_font_body_height(const struct xrdp_painter *self);\nint\nxrdp_painter_draw_text(struct xrdp_painter *self,\n                       struct xrdp_bitmap *bitmap,\n                       int x, int y, const char *text);\nint\nxrdp_painter_draw_text2(struct xrdp_painter *self,\n                        struct xrdp_bitmap *bitmap,\n                        int font, int flags, int mixmode,\n                        int clip_left, int clip_top,\n                        int clip_right, int clip_bottom,\n                        int box_left, int box_top,\n                        int box_right, int box_bottom,\n                        int x, int y, char *data, int data_len);\nint\nxrdp_painter_draw_char(struct xrdp_painter *self,\n                       struct xrdp_bitmap *bitmap,\n                       int x, int y, char32_t chr,\n                       unsigned int repeat_count);\nint\nxrdp_painter_copy(struct xrdp_painter *self,\n                  struct xrdp_bitmap *src,\n                  struct xrdp_bitmap *dst,\n                  int x, int y, int cx, int cy,\n                  int srcx, int srcy);\nint\nxrdp_painter_composite(struct xrdp_painter *self,\n                       struct xrdp_bitmap *src,\n                       int srcformat,\n                       int srcwidth,\n                       int srcrepeat,\n                       struct xrdp_bitmap *dst,\n                       int *srctransform,\n                       int mskflags,\n                       struct xrdp_bitmap *msk,\n                       int mskformat, int mskwidth, int mskrepeat, int op,\n                       int srcx, int srcy, int mskx, int msky,\n                       int dstx, int dsty, int width, int height,\n                       int dstformat);\nint\nxrdp_painter_line(struct xrdp_painter *self,\n                  struct xrdp_bitmap *bitmap,\n                  int x1, int y1, int x2, int y2);\n\n/* xrdp_font.c */\nstruct xrdp_font *\nxrdp_font_create(struct xrdp_wm *wm, unsigned int dpi);\nvoid\nxrdp_font_delete(struct xrdp_font *self);\nint\nxrdp_font_item_compare(struct xrdp_font_char *font1,\n                       struct xrdp_font_char *font2);\n/**\n * Gets a checked xrdp_font_char from a font\n * @param f Font\n * @param c32 Unicode codepoint\n */\n#define XRDP_FONT_GET_CHAR(f, c32) \\\n    (((unsigned int)(c32) >= ' ') && ((unsigned int)(c32) < (f)->char_count) \\\n     ? ((f)->chars + (unsigned int)(c32)) \\\n     : (f)->default_char)\n\n/* funcs.c */\nint\nrect_contains_pt(struct xrdp_rect *in, int x, int y);\nint\nrect_intersect(struct xrdp_rect *in1, struct xrdp_rect *in2,\n               struct xrdp_rect *out);\nint\nrect_contained_by(struct xrdp_rect *in1, int left, int top,\n                  int right, int bottom);\nint\ncheck_bounds(struct xrdp_bitmap *b, int *x, int *y, int *cx, int *cy);\nint\nset_string(char **in_str, const char *in);\n\n/* in lang.c */\nstruct xrdp_key_info *\nget_key_info_from_kbd_event(int keyboard_flags, int key_code, int *keys,\n                            int caps_lock, int num_lock, int scroll_lock,\n                            struct xrdp_keymap *keymap);\nint\nget_keymaps(int keylayout, struct xrdp_keymap *keymap);\n\nint\nkm_load_file(const char *filename, struct xrdp_keymap *keymap);\n\n/**\n * initialise the XKB layout\n *\n * Not all backends need to use XKB for keyboard mapping. This\n * call is used by those modules that do need an XKB mapping.\n *\n * Other modules and the login screen use  other routines in\n * lang.c to interpret incoming RDP scancodes\n * @param client_info Client info struct to initialise\n */\nvoid\nxrdp_init_xkb_layout(struct xrdp_client_info *client_info);\n\n/* xrdp_login_wnd.c */\n/**\n * Gets the DPI of the login (primary) monitor\n *\n * @param self xrdp_wm instance\n * @return DPI of primary monitor, or 0 if unavailable.\n */\nunsigned int\nxrdp_login_wnd_get_monitor_dpi(struct xrdp_wm *self);\nint\nxrdp_login_wnd_create(struct xrdp_wm *self);\nint\nload_xrdp_config(struct xrdp_config *config, const char *xrdp_ini, int bpp);\nvoid\nxrdp_login_wnd_scale_config_values(struct xrdp_wm *self);\n\n/* xrdp_bitmap_compress.c */\nint\nxrdp_bitmap_compress(char *in_data, int width, int height,\n                     struct stream *s, int bpp, int byte_limit,\n                     int start_line, struct stream *temp,\n                     int e);\n\n/* xrdp_mm.c */\n\nstruct display_control_monitor_layout_data\n{\n    struct display_size_description description;\n    enum display_resize_state state;\n    unsigned int last_state_update_timestamp;\n    unsigned int start_time;\n    /// This flag is set if the state machine needs to\n    /// shutdown/startup EGFX\n    int using_egfx;\n};\n\nenum resize_queue_source\n{\n    RQ_IGNORE_MARKER, // Ignore marker\n    RQ_FROM_SERVER, // Requested by display server / desktop\n    RQ_FROM_CLIENT  // Requested by client (dynamic monitor data)\n};\n\n// Items stored on the resize queue\nstruct resize_queue_item\n{\n    enum resize_queue_source src; // Where the item came from\n    struct display_size_description description;\n};\n\nint\nxrdp_mm_drdynvc_up(struct xrdp_mm *self);\nint\nxrdp_mm_suppress_output(struct xrdp_mm *self, int suppress,\n                        int left, int top, int right, int bottom);\nint\nxrdp_mm_up_and_running(struct xrdp_mm *self);\n\n/**\n * Ask the xrdp process (or thread) to terminate\n * @param self xrdp_mm struct\n * @param errinfo Error code to return to the client\n *\n * Execution continues after this call until the main process loop\n * is reached. This routine could be called multiple times. In this\n * instance the first code set is passed back to the client.\n */\nvoid\nxrdp_mm_set_fatal(struct xrdp_mm *self, int errinfo);\n\n/**\n * Tell the user via the log window a fatal error has occurred\n * @param self xrdp_mm struct\n * @param errinfo Error code to return to the client\n *\n * The log window must already contain the fatal error.\n * When the user presses OK in the log window, the xrdp process\n * (or thread) is terminated.\n */\nvoid\nxrdp_mm_logwnd_fatal(struct xrdp_mm *self, int errinfo);\n\nint\nxrdp_mm_send_unicode_to_chansrv(struct xrdp_mm *self,\n                                int key_down,\n                                char32_t unicode);\n\nstruct xrdp_mm *\nxrdp_mm_create(struct xrdp_wm *owner);\nvoid\nxrdp_mm_delete(struct xrdp_mm *self);\nvoid\nxrdp_mm_connect(struct xrdp_mm *self);\nint\nxrdp_mm_process_channel_data(struct xrdp_mm *self, tbus param1, tbus param2,\n                             tbus param3, tbus param4);\nint\nxrdp_mm_get_wait_objs(struct xrdp_mm *self,\n                      tbus *read_objs, int *rcount,\n                      tbus *write_objs, int *wcount, int *timeout);\nint\nxrdp_mm_check_chan(struct xrdp_mm *self);\nint\nxrdp_mm_check_wait_objs(struct xrdp_mm *self);\nint\nxrdp_mm_frame_ack(struct xrdp_mm *self, int frame_id);\nvoid\nxrdp_mm_efgx_add_dirty_region_to_planar_list(struct xrdp_mm *self,\n        struct xrdp_region *dirty_region);\nint\nxrdp_mm_egfx_send_planar_bitmap(struct xrdp_mm *self,\n                                struct xrdp_bitmap *bitmap,\n                                struct xrdp_rect *rect,\n                                int surface_id, int x, int y);\n\n/* xrdp_mm_cpp.c */\n\n/* Callback registered for sesman communication replies over CCP */\nint\nxrdp_mm_ccp_data_in(struct trans *trans);\n\n#endif\n"
  },
  {
    "path": "xrdp/xrdp.ini.in",
    "content": "[Globals]\n; xrdp.ini file version number\nini_version=1\n\n; fork a new process for each incoming connection\nfork=true\n\n; ports to listen on, number alone means listen on all interfaces\n; 0.0.0.0 or :: if ipv6 is configured\n; space between multiple occurrences\n; ALL specified interfaces must be UP when xrdp starts, otherwise xrdp will fail to start\n;\n; Examples:\n;   port=3389\n;   port=unix://./tmp/xrdp.socket\n;   port=tcp://.:3389                           127.0.0.1:3389\n;   port=tcp://:3389                            *:3389\n;   port=tcp://<any ipv4 format addr>:3389      192.168.1.1:3389\n;   port=tcp6://.:3389                          ::1:3389\n;   port=tcp6://:3389                           *:3389\n;   port=tcp6://{<any ipv6 format addr>}:3389   {FC00:0:0:0:0:0:0:1}:3389\n;   port=vsock://<cid>:<port>\nport=3389\n\n; name of the xrdp instance. This can be set to an arbitrary string\n; used to distinguish sessions when the \"N\" policy is activated.\n; Defaults to an empty string.\n#instance_name=\n\n; if used inside a Hyper-V VM through vmconnect and bound on vsock,\n; turn this on to enable wider security protocol support.\n#vmconnect=true\n\n; Unprivileged User name and group to run the xrdp daemon.\n; It is HIGHLY RECOMMENDED you set these values. See the xrdp.ini(5)\n; manpage for more information on setting and checking these.\n#runtime_user=xrdp\n#runtime_group=xrdp\n\n; regulate if the listening socket use socket option tcp_nodelay\n; no buffering will be performed in the TCP stack\ntcp_nodelay=true\n\n; regulate if the listening socket use socket option keepalive\n; if the network connection disappear without close messages the connection will be closed\ntcp_keepalive=true\n\n; set tcp send/recv buffer\n; These parameters are largely historic. On systems with dynamic TCP\n; buffer sizes, setting them manually will either impact performance or\n; waste memory\n#tcp_send_buffer_bytes=32768\n#tcp_recv_buffer_bytes=32768\n\n; security layer can be 'tls', 'rdp' or 'negotiate':-\n;\n; tls       - Insist on TLS for security (maximum security)\n; rdp       - Insist on RDP for security (testing only)\n; negotiate - Negotiate whatever can be supported by both client and\n;             server (maximum compatibility)\n;\nsecurity_layer=negotiate\n\n; minimum security level allowed for client for classic RDP encryption\n; use tls_ciphers to configure TLS encryption\n; can be 'none', 'low', 'medium', 'high', 'fips'\ncrypt_level=high\n\n; X.509 certificate and private key\n; openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365\ncertificate=\nkey_file=\n\n; [Debug] Log file for TLS pre-master secrets - see xrdp.ini(5)\n#tls_pms_log_file=/tmp/xrdp-pms/premaster.log\n\n; set SSL protocols\n; can be comma separated list of 'SSLv3', 'TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'\nssl_protocols=TLSv1.2, TLSv1.3\n; set TLS cipher suites\n#tls_ciphers=HIGH\n\n; concats the domain name to the user if set for authentication with the separator\n; for example when the server is multi homed with SSSd\n#domain_user_separator=@\n\n; The following options will override the keyboard layout settings.\n; These options are for DEBUG and are not recommended for regular use.\n#xrdp.override_keyboard_type=0x04\n#xrdp.override_keyboard_subtype=0x01\n#xrdp.override_keylayout=0x00000409\n\n; Section name to use for automatic login if the client sends username\n; and password. If empty, the domain name sent by the client is used.\n; If empty and no domain name is given, the first suitable section in\n; this file will be used.\nautorun=\n\nallow_channels=true\nallow_multimon=true\nbitmap_cache=true\nbitmap_compression=true\nbulk_compression=true\n#hidelogwindow=true\nmax_bpp=32\nnew_cursors=true\n; fastpath - can be 'input', 'output', 'both', 'none'\nuse_fastpath=both\n; when true, userid/password *must* be passed on cmd line. If the password\n; is incorrect, the login will fail\n#require_credentials=true\n; when true, the userid will be used to try to authenticate\n#enable_token_login=true\n; You can set the PAM error text in a gateway setup (MAX 256 chars)\n#pamerrortxt=change your password according to policy at http://url\n\n;\n; colors used by windows in RGB format\n;\n#black=000000\ngrey=e1e1e1\ndark_grey=b4b4b4\nblue=0078d7\ndark_blue=0078d7\n#white=ffffff\n#red=ff0000\n#green=00ff00\n#background=626c72\n\n;\n; Select a default fv1 font\n;\n; This parameter is a comma-separated list of DPI:name pairs.\n; The list is scanned from left-to-right. The font used is the first\n; font whose DPI value is less-than-or-equal to the vertical DPI of\n; the monitor used for the login screen.\n#fv1_select=130:sans-18.fv1,0:sans-10.fv1\n; Default DPI used for a monitor when that information is unknown\n#default_dpi=96\n\n;\n; configure login screen\n;\n\n; Login Screen Window Title\n#ls_title=My Login Title\n\n; top level window background color in RGB format\nls_top_window_bg_color=003057\n\n; width and height of login screen\n;\n; When the sans-10.fv1 font is selected, these values are in pixels.\n; For other fonts, these values (and other size values) will be scaled\n; appropriately to preserve the proportions of the login screen.\n;\n; The default height allows for about 5 fields to be comfortably displayed\n; above the buttons at the bottom. To display more fields, make <ls_height>\n; larger, and also increase <ls_btn_ok_y_pos> and <ls_btn_cancel_y_pos>\n; below\n;\nls_width=350\nls_height=360\n\n; login screen background color in RGB format\nls_bg_color=f0f0f0\n\n; optional background image filename. BMP format is always supported,\n; but other formats will be supported if xrdp is build with imlib2\n; The transform can be one of the following:-\n;     none  : No transformation. Image is placed in bottom-right corner\n;             of the screen.\n;     scale : Image is scaled to the screen size. The image aspect\n;             ratio is not preserved.\n;     zoom  : Image is scaled to the screen size. The image aspect\n;             ratio is preserved by clipping the image.\n#ls_background_image=\n#ls_background_transform=none\n\n; logo\n; full path to file or file in shared folder. BMP format is always supported,\n; but other formats will be supported if xrdp is build with imlib2\n; For transform values, see 'ls_background_transform'. The logo width and\n; logo height are ignored for a transform of 'none'.\nls_logo_filename=\nls_logo_transform=scale\nls_logo_width=250\nls_logo_height=110\nls_logo_x_pos=55\nls_logo_y_pos=35\n\n; for positioning labels such as username, password etc\nls_label_x_pos=30\nls_label_width=68\n\n; for positioning text and combo boxes next to above labels\nls_input_x_pos=110\nls_input_width=210\n\n; y pos for first label and combo box\nls_input_y_pos=158\n\n; OK button\nls_btn_ok_x_pos=142\nls_btn_ok_y_pos=308\nls_btn_ok_width=85\nls_btn_ok_height=30\n\n; Cancel button\nls_btn_cancel_x_pos=237\nls_btn_cancel_y_pos=308\nls_btn_cancel_width=85\nls_btn_cancel_height=30\n\n[Logging]\n; Note: Log levels can be any of: core, error, warning, info, debug, or trace\nLogFile=xrdp.log\nLogLevel=INFO\nEnableSyslog=true\n#SyslogLevel=INFO\n#EnableConsole=false\n#ConsoleLevel=INFO\n#EnableProcessId=false\n\n[LoggingPerLogger]\n; Note: per logger configuration is only used if xrdp is built with\n; --enable-devel-logging\n#xrdp.c=INFO\n#main()=INFO\n\n[Channels]\n; Channel names not listed here will be blocked by XRDP.\n; You can block any channel by setting its value to false.\n; IMPORTANT! All channels are not supported in all use\n; cases even if you set all values to true.\n; You can override these settings on each session type\n; These settings are only used if allow_channels=true\nrdpdr=true\nrdpsnd=true\ndrdynvc=true\ncliprdr=true\nrail=true\nxrdpvr=true\n\n; for debugging xrdp, in section xrdp1, change port=-1 to this:\n#port=/tmp/.xrdp/xrdp_display_10\n\n\n;\n; Session types\n;\n\n; Some session types such as Xorg and Xvnc start a display server.\n; Startup command-line parameters for the display server are configured\n; in sesman.ini. See and configure also sesman.ini.\n[Xorg]\nname=Xorg\nlib=libxup.@lib_extension@\nusername=ask\npassword=ask\nport=-1\ncode=20\n#keycode_set=evdev\n; Frame capture interval (milliseconds)\nh264_frame_interval=16\nrfx_frame_interval=32\nnormal_frame_interval=40\n\n[Xvnc]\nname=Xvnc\nlib=libvnc.@lib_extension@\nusername=ask\npassword=ask\nip=127.0.0.1\n; port is -1 (sesman controlled), numeric (TCP connection) or an\n; absolute path (UDS connection).\nport=-1\n; For sesman-controlled Xvnc, the 'code' parameter can be used to switch\n; the connection protocol:-\n; 0 - Use a TCP connection\n; 1 - Use a Unix Domain Sockets (UDS) connection\n;     UDS connections are not supported by older VNC servers, but are\n;     supported by TigerVNC. If you select this option, comment out\n;     (or remove) the 'ip=' setting.\n;\n; UDS connections are recommended, if your X server supports them. They are\n; more secure, and untroubled by firewalls.\n;\n; On FIPS-based systems, TCP CANNOT be used, as the classic algorithm used for\n; VNC password files is no longer considered secure by FIPS\n;\n; The default value is 0 on non-FIPS systems, and 1 on FIPS-based systems.\n#code=0\n#xserverbpp=24\n#delay_ms=2000\n; Disable requested encodings to support buggy VNC servers\n; (1 = ExtendedDesktopSize)\n#disabled_encodings_mask=0\n\n; Generic VNC Proxy\n; Tailor this to specific hosts and VNC instances by specifying an ip\n; and port and setting a suitable name.\n[vnc-any]\nname=vnc-any\nlib=libvnc.@lib_extension@\nip=ask\nport=ask5900\nusername=na\npassword=ask\n#pamusername=asksame\n#pampassword=asksame\n#delay_ms=2000\n; Use one of these to connect to a chansrv instance created outside of sesman\n; (e.g. as part of an x11vnc console session). Replace 's' with the\n; display string of the session, and (if applicable) 'u' with the numeric\n; UID of the session.\n;\n; For compatibility, a completely numeric display string is taken to be\n; an X11 display number\n;\n; You will also need to change the value of SessionSockdirGroup in\n; sesman.ini to allow xrdp to reach the chansrv instance\n;\n; If 'username' or 'pamusername' is set, you probably don't need to use\n; the two parameter variant with 'u'.\n#chansrvport=DISPLAY(n)\n#chansrvport=DISPLAY(n,u)\n\n; Generic RDP proxy using NeutrinoRDP\n; Tailor this to specific hosts by specifying an ip and port and setting\n; a suitable name.\n[neutrinordp-any]\nname=neutrinordp-any\n; To use this section, you should build xrdp with configure option\n; --enable-neutrinordp.\nlib=libxrdpneutrinordp.@lib_extension@\nip=ask\nport=ask3389\nusername=ask\npassword=ask\n; Uncomment the following lines to enable PAM authentication for proxy\n; connections.\n#pamusername=ask\n#pampassword=ask\n; Currently NeutrinoRDP doesn't support dynamic resizing. Uncomment\n; this line if you're using a client which does.\n#enable_dynamic_resizing=false\n; By default, performance settings requested by the RDP client are ignored\n; and chosen by NeutrinoRDP. Uncomment this line to allow the user to\n; select performance settings in the RDP client.\n#perf.allow_client_experiencesettings=true\n; Override any experience setting by uncommenting one or more of the\n; following lines.\n#perf.wallpaper=false\n#perf.font_smoothing=false\n#perf.desktop_composition=false\n#perf.full_window_drag=false\n#perf.menu_anims=false\n#perf.themes=false\n#perf.cursor_blink=false\n; By default NeutrinoRDP supports cursor shadows. If this is giving\n; you problems (e.g. cursor is a black rectangle) try disabling cursor\n; shadows by uncommenting the following line.\n#perf.cursor_shadow=false\n; By default, NeutrinoRDP uses the keyboard layout of the remote RDP Server.\n; If you want to tell the remote the keyboard layout of the RDP Client,\n; by uncommenting the following line.\n#neutrinordp.allow_client_keyboardLayout=true\n; The following options will override the remote keyboard layout settings.\n; These options are for DEBUG and are not recommended for regular use.\n#neutrinordp.override_keyboardLayout_mask=0x0000FFFF\n#neutrinordp.override_kbd_type=0x04\n#neutrinordp.override_kbd_subtype=0x01\n#neutrinordp.override_kbd_fn_keys=12\n#neutrinordp.override_kbd_layout=0x00000409\n\n; You can override the common channel settings for each session type\n#channel.rdpdr=true\n#channel.rdpsnd=true\n#channel.drdynvc=true\n#channel.cliprdr=true\n#channel.rail=true\n#channel.xrdpvr=true\n"
  },
  {
    "path": "xrdp/xrdp_bitmap.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * bitmap, drawable\n * this is a object that can be drawn on with a painter\n * all windows, bitmaps, even the screen are of this type\n * maybe it should be called xrdp_drawable\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n\n// For a very few key functions, using the keysym is preferable to the\n// raw scancode. Here are defines to avoid pulling an X11 dependency\n// into the xrdp:-\n#define XK_BackSpace 0xff08\n\n\nstatic const unsigned int g_crc_table[256] =\n{\n    0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,\n    0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n    0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,\n    0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n    0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n    0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n    0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,\n    0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n    0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,\n    0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n    0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,\n    0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n    0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,\n    0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n    0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n    0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n    0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,\n    0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n    0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,\n    0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n    0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,\n    0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n    0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,\n    0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n    0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n    0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n    0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,\n    0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n    0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,\n    0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n    0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,\n    0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n    0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,\n    0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n    0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n    0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n    0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,\n    0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n    0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,\n    0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n    0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\n    0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n    0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d\n};\n\n#define CRC_START(in_crc) (in_crc) = 0xFFFFFFFF\n#define CRC_PASS(in_pixel, in_crc) \\\n    (in_crc) = g_crc_table[((in_crc) ^ (in_pixel)) & 0xff] ^ ((in_crc) >> 8)\n#define CRC_END(in_crc) (in_crc) = ((in_crc) ^ 0xFFFFFFFF)\n\n/*****************************************************************************/\nstruct xrdp_bitmap *\nxrdp_bitmap_get_child_by_id(struct xrdp_bitmap *self, int id)\n{\n    int i = 0;\n    struct xrdp_bitmap *b = (struct xrdp_bitmap *)NULL;\n\n    for (i = 0; i < self->child_list->count; i++)\n    {\n        b = (struct xrdp_bitmap *)list_get_item(self->child_list, i);\n\n        if (b->id == id)\n        {\n            return b;\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* if focused is true focus this window else unfocus it */\n/* returns error */\nint\nxrdp_bitmap_set_focus(struct xrdp_bitmap *self, int focused)\n{\n    struct xrdp_painter *painter = (struct xrdp_painter *)NULL;\n    unsigned int font_height;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (self->type != WND_TYPE_WND) /* 1 */\n    {\n        return 0;\n    }\n\n    painter = xrdp_painter_create(self->wm, self->wm->session);\n    xrdp_painter_font_needed(painter);\n    xrdp_painter_begin_update(painter);\n    font_height = xrdp_painter_font_body_height(painter);\n\n    if (focused)\n    {\n        /* active title bar */\n        painter->fg_color = self->wm->blue;\n        xrdp_painter_fill_rect(painter, self, 3, 3,\n                               self->width - 5, font_height + 5);\n        painter->fg_color = self->wm->white;\n    }\n    else\n    {\n        /* inactive title bar */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, 3, 3,\n                               self->width - 5, font_height + 5);\n        painter->fg_color = self->wm->black;\n    }\n\n    xrdp_painter_draw_text(painter, self, 4, 4, self->caption1);\n    xrdp_painter_end_update(painter);\n    xrdp_painter_delete(painter);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_bitmap_hash_crc(struct xrdp_bitmap *self)\n{\n    void *hash;\n    int bytes;\n    unsigned int crc;\n    int index;\n    char hash_data[16];\n\n    if (self->bpp >= 24)\n    {\n        bytes = self->width * self->height * 4;\n    }\n    else if (self->bpp == 15 || self->bpp == 16)\n    {\n        bytes = self->width * self->height * 2;\n    }\n    else if (self->bpp == 8)\n    {\n        bytes = self->width * self->height;\n    }\n    else\n    {\n        return 1;\n    }\n    hash = ssl_md5_info_create();\n    ssl_md5_clear(hash);\n    ssl_md5_transform(hash, self->data, bytes);\n    ssl_md5_complete(hash, hash_data);\n    ssl_md5_info_delete(hash);\n    CRC_START(crc);\n    CRC_PASS(self->width, crc);\n    CRC_PASS(self->width >> 8, crc);\n    CRC_PASS(self->height, crc);\n    CRC_PASS(self->height >> 8, crc);\n    for (index = 0; index < 16; index++)\n    {\n        CRC_PASS(hash_data[index], crc);\n    }\n    CRC_END(crc);\n    self->crc32 = crc;\n    self->crc16 = self->crc32 & 0xffff;\n    return 0;\n}\n\n/*****************************************************************************/\n/* copy part of self at x, y to 0, 0 in dest */\n/* returns error */\nint\nxrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,\n                              struct xrdp_bitmap *dest,\n                              int x, int y, int cx, int cy)\n{\n    int i;\n    int j;\n    int destx;\n    int desty;\n    int pixel;\n    unsigned int crc;\n    int incs;\n    int incd;\n    tui8 *s8;\n    tui8 *d8;\n    tui16 *s16;\n    tui16 *d16;\n    tui32 *s32;\n    tui32 *d32;\n\n    if (self == 0)\n    {\n        return 1;\n    }\n\n    if (dest == 0)\n    {\n        return 1;\n    }\n\n    if (self->type != WND_TYPE_BITMAP && self->type != WND_TYPE_IMAGE)\n    {\n        return 1;\n    }\n\n    if (dest->type != WND_TYPE_BITMAP && dest->type != WND_TYPE_IMAGE)\n    {\n        return 1;\n    }\n\n    if (self->bpp != dest->bpp)\n    {\n        return 1;\n    }\n\n    destx = 0;\n    desty = 0;\n\n    if (!check_bounds(self, &x, &y, &cx, &cy))\n    {\n        return 1;\n    }\n\n    if (!check_bounds(dest, &destx, &desty, &cx, &cy))\n    {\n        return 1;\n    }\n\n    CRC_START(crc);\n\n    CRC_PASS(self->width, crc);\n    CRC_PASS(self->width >> 8, crc);\n\n    CRC_PASS(self->height, crc);\n    CRC_PASS(self->height >> 8, crc);\n\n    if (self->bpp == 32)\n    {\n        s32 = ((tui32 *)(self->data)) + (self->width * y + x);\n        d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx);\n        incs = self->width - cx;\n        incd = dest->width - cx;\n\n        for (i = 0; i < cy; i++)\n        {\n            j = 0;\n\n            while (j < cx - 4)\n            {\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                CRC_PASS(pixel >> 24, crc);\n                s32++;\n                d32++;\n\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                CRC_PASS(pixel >> 24, crc);\n                s32++;\n                d32++;\n\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                CRC_PASS(pixel >> 24, crc);\n                s32++;\n                d32++;\n\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                CRC_PASS(pixel >> 24, crc);\n                s32++;\n                d32++;\n\n                j += 4;\n            }\n            while (j < cx)\n            {\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                CRC_PASS(pixel >> 24, crc);\n                s32++;\n                d32++;\n\n                j += 1;\n            }\n\n            s32 += incs;\n            d32 += incd;\n        }\n    }\n    else if (self->bpp == 24)\n    {\n        s32 = ((tui32 *)(self->data)) + (self->width * y + x);\n        d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx);\n        incs = self->width - cx;\n        incd = dest->width - cx;\n\n        for (i = 0; i < cy; i++)\n        {\n            j = 0;\n\n            while (j < cx - 4)\n            {\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                s32++;\n                d32++;\n\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                s32++;\n                d32++;\n\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                s32++;\n                d32++;\n\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                s32++;\n                d32++;\n\n                j += 4;\n            }\n            while (j < cx)\n            {\n                pixel = *s32;\n                *d32 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                CRC_PASS(pixel >> 16, crc);\n                s32++;\n                d32++;\n\n                j += 1;\n            }\n\n            s32 += incs;\n            d32 += incd;\n        }\n    }\n    else if (self->bpp == 15 || self->bpp == 16)\n    {\n        s16 = ((tui16 *)(self->data)) + (self->width * y + x);\n        d16 = ((tui16 *)(dest->data)) + (dest->width * desty + destx);\n        incs = self->width - cx;\n        incd = dest->width - cx;\n\n        for (i = 0; i < cy; i++)\n        {\n            for (j = 0; j < cx; j++)\n            {\n                pixel = *s16;\n                *d16 = pixel;\n                CRC_PASS(pixel, crc);\n                CRC_PASS(pixel >> 8, crc);\n                s16++;\n                d16++;\n            }\n\n            s16 += incs;\n            d16 += incd;\n        }\n    }\n    else if (self->bpp == 8)\n    {\n        s8 = ((tui8 *)(self->data)) + (self->width * y + x);\n        d8 = ((tui8 *)(dest->data)) + (dest->width * desty + destx);\n        incs = self->width - cx;\n        incd = dest->width - cx;\n\n        for (i = 0; i < cy; i++)\n        {\n            for (j = 0; j < cx; j++)\n            {\n                pixel = *s8;\n                *d8 = pixel;\n                CRC_PASS(pixel, crc);\n                s8++;\n                d8++;\n            }\n\n            s8 += incs;\n            d8 += incd;\n        }\n    }\n    else\n    {\n        return 1;\n    }\n\n    CRC_END(crc);\n    dest->crc32 = crc;\n    dest->crc16 = dest->crc32 & 0xffff;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_bitmap_copy_box_with_crc: crc16 0x%4.4x\",\n              dest->crc16);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_bitmap_copy_box_with_crc: width %d height %d\",\n              dest->width, dest->height);\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns true if they are the same, else returns false */\nint\nxrdp_bitmap_compare(struct xrdp_bitmap *self,\n                    struct xrdp_bitmap *b)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_bitmap_compare:\");\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (b == 0)\n    {\n        return 0;\n    }\n\n    if (self->bpp != b->bpp)\n    {\n        return 0;\n    }\n\n    if (self->width != b->width)\n    {\n        return 0;\n    }\n\n    if (self->height != b->height)\n    {\n        return 0;\n    }\n\n    if (g_memcmp(self->data, b->data, b->height * b->line_size) == 0)\n    {\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_bitmap_draw_focus_box(struct xrdp_bitmap *self,\n                           struct xrdp_painter *painter,\n                           int x, int y, int cx, int cy)\n{\n    painter->rop = 0xf0;\n    xrdp_painter_begin_update(painter);\n    painter->use_clip = 0;\n    painter->mix_mode = 1;\n    painter->brush.pattern[0] = 0xaa;\n    painter->brush.pattern[1] = 0x55;\n    painter->brush.pattern[2] = 0xaa;\n    painter->brush.pattern[3] = 0x55;\n    painter->brush.pattern[4] = 0xaa;\n    painter->brush.pattern[5] = 0x55;\n    painter->brush.pattern[6] = 0xaa;\n    painter->brush.pattern[7] = 0x55;\n    painter->brush.x_origin = x;\n    painter->brush.y_origin = y;\n    painter->brush.style = 3;\n    painter->fg_color = self->wm->black;\n    painter->bg_color = self->parent->bg_color;\n    /* top */\n    xrdp_painter_fill_rect(painter, self, x, y, cx, 1);\n    /* bottom */\n    xrdp_painter_fill_rect(painter, self, x, y + (cy - 1), cx, 1);\n    /* left */\n    xrdp_painter_fill_rect(painter, self, x, y + 1, 1, cy - 2);\n    /* right */\n    xrdp_painter_fill_rect(painter, self, x + (cx - 1), y + 1, 1, cy - 2);\n    xrdp_painter_end_update(painter);\n    painter->rop = 0xcc;\n    painter->mix_mode = 0;\n    return 0;\n}\n\n/*****************************************************************************/\n/* x and y are in relation to self for 0, 0 is the top left of the control */\nstatic int\nxrdp_bitmap_draw_button(struct xrdp_bitmap *self,\n                        struct xrdp_painter *painter,\n                        int x, int y, int w, int h,\n                        int down)\n{\n    if (down)\n    {\n        /* gray box */\n        painter->fg_color = self->wm->grey;\n        xrdp_painter_fill_rect(painter, self, x, y, w, h);\n        /* black top line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, x, y, w, 1);\n        /* black left line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, x, y, 1, h);\n        /* dark grey top line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, x + 1, y + 1, w - 2, 1);\n        /* dark grey left line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, x + 1, y + 1, 1, h - 2);\n        /* dark grey bottom line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, x + 1, y + (h - 2), w - 1, 1);\n        /* dark grey right line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, x + (w - 2), y + 1, 1, h - 1);\n        /* black bottom line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, x, y + (h - 1), w, 1);\n        /* black right line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, x + (w - 1), y, 1, h);\n    }\n    else\n    {\n        /* gray box */\n        painter->fg_color = self->wm->grey;\n        xrdp_painter_fill_rect(painter, self, x, y, w, h);\n        /* white top line */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, x, y, w, 1);\n        /* white left line */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, x, y, 1, h);\n        /* dark grey bottom line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, x + 1, y + (h - 2), w - 1, 1);\n        /* dark grey right line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, (x + w) - 2, y + 1, 1, h - 1);\n        /* black bottom line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, x, y + (h - 1), w, 1);\n        /* black right line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, x + (w - 1), y, 1, h);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* nil for rect means the whole thing */\n/* returns error */\nint\nxrdp_bitmap_invalidate(struct xrdp_bitmap *self, struct xrdp_rect *rect)\n{\n    int i;\n    int w;\n    int h;\n    int x;\n    int y;\n    struct xrdp_bitmap *b;\n    struct xrdp_rect r1;\n    struct xrdp_rect r2;\n    struct xrdp_painter *painter;\n    unsigned int font_height;\n    char *p;\n\n    if (self == 0) /* if no bitmap */\n    {\n        return 0;\n    }\n\n    if (self->type == WND_TYPE_BITMAP) /* if 0, bitmap, leave */\n    {\n        return 0;\n    }\n\n    painter = xrdp_painter_create(self->wm, self->wm->session);\n    xrdp_painter_font_needed(painter);\n    font_height = xrdp_painter_font_body_height(painter);\n    painter->rop = 0xcc; /* copy */\n\n    if (rect == 0)\n    {\n        painter->use_clip = 0;\n    }\n    else\n    {\n        if (ISRECTEMPTY(*rect))\n        {\n            xrdp_painter_delete(painter);\n            return 0;\n        }\n\n        painter->clip = *rect;\n        painter->use_clip = &painter->clip;\n    }\n\n    xrdp_painter_begin_update(painter);\n\n    if (self->type == WND_TYPE_WND) /* 1 */\n    {\n        /* draw grey background */\n        painter->fg_color = self->bg_color;\n        xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);\n        /* top white line */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 2, 1);\n        /* left white line */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, 1, 1, 1, self->height - 2);\n        /* bottom dark grey line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, 1, self->height - 2,\n                               self->width - 2, 1);\n        /* right dark grey line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, self->width - 2, 1, 1,\n                               self->height - 2);\n        /* bottom black line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, 0, self->height - 1,\n                               self->width, 1);\n        /* right black line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, self->width - 1, 0,\n                               1, self->height);\n\n        if (self->wm->focused_window == self)\n        {\n            /* active title bar */\n            painter->fg_color = self->wm->blue;\n            xrdp_painter_fill_rect(painter, self, 3, 3,\n                                   self->width - 5, font_height + 5);\n            painter->fg_color = self->wm->white;\n        }\n        else\n        {\n            /* inactive title bar */\n            painter->fg_color = self->wm->dark_grey;\n            xrdp_painter_fill_rect(painter, self, 3, 3,\n                                   self->width - 5, font_height + 5);\n            painter->fg_color = self->wm->black;\n        }\n\n        xrdp_painter_draw_text(painter, self, 4, 4, self->caption1);\n    }\n    else if (self->type == WND_TYPE_SCREEN) /* 2 */\n    {\n        struct xrdp_wm *wm = self->wm;\n        if (wm == 0)\n        {\n            goto bail;\n        }\n        struct xrdp_mm *mm = wm->mm;\n        if (mm == 0)\n        {\n            goto bail;\n        }\n        struct xrdp_mod *m = mm->mod;\n        if (m != 0 && m->mod_event != 0)\n        {\n            if (rect != 0)\n            {\n                x = rect->left;\n                y = rect->top;\n                w = rect->right - rect->left;\n                h = rect->bottom - rect->top;\n\n                if (check_bounds(self->wm->screen, &x, &y, &w, &h))\n                {\n                    m->mod_event(m, WM_INVALIDATE,\n                                 MAKELONG(y, x), MAKELONG(h, w),\n                                 0, 0);\n                }\n            }\n            else\n            {\n                x = 0;\n                y = 0;\n                w = self->wm->screen->width;\n                h = self->wm->screen->height;\n                m->mod_event(m, WM_INVALIDATE,\n                             MAKELONG(y, x), MAKELONG(h, w),\n                             0, 0);\n            }\n        }\n        else\n        {\n            painter->fg_color = self->bg_color;\n            xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);\n        }\n    }\n    else if (self->type == WND_TYPE_BUTTON) /* 3 */\n    {\n        if (self->state == BUTTON_STATE_UP) /* 0 */\n        {\n            xrdp_bitmap_draw_button(self, painter, 0, 0,\n                                    self->width, self->height, 0);\n            w = xrdp_painter_text_width(painter, self->caption1);\n            h = xrdp_painter_font_body_height(painter);\n            painter->fg_color = self->wm->black;\n            xrdp_painter_draw_text(painter, self, self->width / 2 - w / 2,\n                                   self->height / 2 - h / 2, self->caption1);\n\n            if (self->parent != 0)\n            {\n                if (self->wm->focused_window == self->parent)\n                {\n                    if (self->parent->focused_control == self)\n                    {\n                        xrdp_bitmap_draw_focus_box(self, painter, 4, 4, self->width - 8,\n                                                   self->height - 8);\n                    }\n                }\n            }\n        }\n        else if (self->state == BUTTON_STATE_DOWN) /* 1 */\n        {\n            xrdp_bitmap_draw_button(self, painter, 0, 0,\n                                    self->width, self->height, 1);\n            w = xrdp_painter_text_width(painter, self->caption1);\n            h = xrdp_painter_font_body_height(painter);\n            painter->fg_color = self->wm->black;\n            xrdp_painter_draw_text(painter, self, (self->width / 2 - w / 2) + 1,\n                                   (self->height / 2 - h / 2) + 1, self->caption1);\n\n            if (self->parent != 0)\n                if (self->wm->focused_window == self->parent)\n                    if (self->parent->focused_control == self)\n                        xrdp_bitmap_draw_focus_box(self, painter, 4, 4, self->width - 8,\n                                                   self->height - 8);\n        }\n    }\n    else if (self->type == WND_TYPE_IMAGE) /* 4 */\n    {\n        xrdp_painter_copy(painter, self, self, 0, 0, self->width,\n                          self->height, 0, 0);\n    }\n    else if (self->type == WND_TYPE_EDIT) /* 5 */\n    {\n        /* draw gray box */\n        painter->fg_color = self->wm->grey;\n        xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);\n        /* main white background */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3,\n                               self->height - 3);\n        /* dark grey top line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, 0, 0, self->width, 1);\n        /* dark grey left line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, 0, 0, 1, self->height);\n        /* white bottom line */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, 0, self->height - 1, self->width, 1);\n        /* white right line */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, self->width - 1, 0, 1, self->height);\n        /* black left line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, 1, 1, 1, self->height - 3);\n        /* black top line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3, 1);\n        /* draw text */\n        painter->fg_color = self->wm->black;\n\n        if (self->password_char != 0)\n        {\n            unsigned int repeat_count = utf8_char_count(self->caption1);\n            xrdp_painter_draw_char(painter, self, 4, 2, self->password_char,\n                                   repeat_count);\n        }\n        else\n        {\n            xrdp_painter_draw_text(painter, self, 4, 2, self->caption1);\n        }\n\n        /* draw xor box(cursor) */\n        if (self->parent != 0)\n        {\n            if (self->parent->focused_control == self)\n            {\n                if (self->password_char != 0)\n                {\n                    w = xrdp_painter_repeated_char_width(painter,\n                                                         self->password_char,\n                                                         self->edit_pos);\n                }\n                else\n                {\n                    w = xrdp_painter_text_width_count(painter, self->caption1,\n                                                      self->edit_pos);\n                }\n\n                painter->fg_color = self->wm->white;\n                painter->rop = 0x5a;\n                xrdp_painter_fill_rect(painter, self, 4 + w, 3, 2, self->height - 6);\n            }\n        }\n\n        /* reset rop back */\n        painter->rop = 0xcc;\n    }\n    else if (self->type == WND_TYPE_LABEL) /* 6 */\n    {\n        painter->fg_color = self->wm->black;\n        xrdp_painter_draw_text(painter, self, 0, 0, self->caption1);\n    }\n    else if (self->type == WND_TYPE_COMBO) /* 7 combo box */\n    {\n        /* draw gray box */\n        painter->fg_color = self->wm->grey;\n        xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);\n        /* white background */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3,\n                               self->height - 3);\n\n        if (self->parent->focused_control == self)\n        {\n            painter->fg_color = self->wm->dark_blue;\n            xrdp_painter_fill_rect(painter, self, 3, 3, (self->width - 6) - 18,\n                                   self->height - 5);\n        }\n\n        /* dark grey top line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, 0, 0, self->width, 1);\n        /* dark grey left line */\n        painter->fg_color = self->wm->dark_grey;\n        xrdp_painter_fill_rect(painter, self, 0, 0, 1, self->height);\n        /* white bottom line */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, 0, self->height - 1, self->width, 1);\n        /* white right line */\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, self->width - 1, 0, 1, self->height);\n        /* black left line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, 1, 1, 1, self->height - 3);\n        /* black top line */\n        painter->fg_color = self->wm->black;\n        xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3, 1);\n\n        /* draw text */\n        if (self->parent->focused_control == self)\n        {\n            painter->fg_color = self->wm->white;\n        }\n        else\n        {\n            painter->fg_color = self->wm->black;\n        }\n\n        xrdp_painter_draw_text(painter, self, 4, 2,\n                               (char *)list_get_item(self->string_list, self->item_index));\n        /* draw button on right */\n        x = self->width - 20;\n        y = 2;\n        w = (self->width - x) - 2;\n        h = self->height - 4;\n        /* looks better with a background around */\n        painter->fg_color = self->wm->grey;\n        xrdp_painter_fill_rect(painter, self, x, y, w, h);\n\n        if (self->state == BUTTON_STATE_UP) /* 0 */\n        {\n            xrdp_bitmap_draw_button(self, painter, x + 1, y + 1, w - 1, h - 1, 0);\n        }\n        else\n        {\n            xrdp_bitmap_draw_button(self, painter, x + 1, y + 1, w - 1, h - 1, 1);\n        }\n\n        /* draw the arrow */\n        w = w / 2;\n        x = x + (w / 2) + 1;\n        h = (h / 2) + 2;\n        y = y + (h / 2) + 1;\n        painter->fg_color = self->wm->black;\n\n        for (i = w; i > 0; i = i - 2)\n        {\n            xrdp_painter_fill_rect(painter, self, x, y, i, 1);\n            y++;\n            x = x + 1;\n        }\n    }\n    else if (self->type == WND_TYPE_SPECIAL) /* 8 special */\n    {\n        if (self->popped_from != 0)\n        {\n            /* change height if there are too many items in the list */\n            i = xrdp_painter_font_body_height(painter);\n            i = self->popped_from->string_list->count * i;\n\n            if (i > self->height)\n            {\n                self->height = i;\n            }\n        }\n\n        painter->fg_color = self->wm->white;\n        xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);\n\n        /* draw the list items */\n        if (self->popped_from != 0)\n        {\n            y = 0;\n\n            for (i = 0; i < self->popped_from->string_list->count; i++)\n            {\n                p = (char *)list_get_item(self->popped_from->string_list, i);\n                h = xrdp_painter_font_body_height(painter);\n                self->item_height = h;\n\n                if (i == self->item_index)\n                {\n                    painter->fg_color = self->wm->blue;\n                    xrdp_painter_fill_rect(painter, self, 0, y, self->width, h);\n                    painter->fg_color = self->wm->white;\n                }\n                else\n                {\n                    painter->fg_color = self->wm->black;\n                }\n\n                xrdp_painter_draw_text(painter, self, 2, y, p);\n                y = y + h;\n            }\n        }\n    }\n\n    /* notify */\n    if (self->notify != 0)\n    {\n        self->notify(self, self, WM_PAINT, (long)painter, 0); /* 3 */\n    }\n\n    /* draw any child windows in the area */\n    for (i = 0; i < self->child_list->count; i++)\n    {\n        b = (struct xrdp_bitmap *)list_get_item(self->child_list, i);\n\n        if (rect == 0)\n        {\n            xrdp_bitmap_invalidate(b, 0);\n        }\n        else\n        {\n            MAKERECT(r1, b->left, b->top, b->width, b->height);\n\n            if (rect_intersect(rect, &r1, &r2))\n            {\n                RECTOFFSET(r2, -(b->left), -(b->top));\n                xrdp_bitmap_invalidate(b, &r2);\n            }\n        }\n    }\n\nbail:\n    xrdp_painter_end_update(painter);\n    xrdp_painter_delete(painter);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_bitmap_def_proc(struct xrdp_bitmap *self, int msg,\n                     int param1, int param2)\n{\n    int n;\n    int i;\n    struct xrdp_bitmap *b;\n    struct xrdp_bitmap *focus_out_control;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (self->wm == 0)\n    {\n        return 0;\n    }\n\n    if (self->type == WND_TYPE_WND)\n    {\n        if (msg == WM_KEYDOWN)\n        {\n            int scan_code = SCANCODE_FROM_KBD_EVENT(param1, param2);\n            int shift = self->wm->keys[SCANCODE_INDEX_LSHIFT_KEY] ||\n                        self->wm->keys[SCANCODE_INDEX_RSHIFT_KEY];\n\n            if (scan_code == SCANCODE_TAB_KEY) /* tab */\n            {\n                /* move to next tab stop */\n                i = -1;\n\n                if (self->child_list != 0)\n                {\n                    i = list_index_of(self->child_list, (long)self->focused_control);\n\n                    if (shift)\n                    {\n                        i--;\n\n                        if (i < 0)\n                        {\n                            i = self->child_list->count - 1;\n                        }\n                    }\n                    else\n                    {\n                        i++;\n\n                        if (i >= self->child_list->count)\n                        {\n                            i = 0;\n                        }\n                    }\n\n                    n = self->child_list->count;\n                    b = (struct xrdp_bitmap *)list_get_item(self->child_list, i);\n\n                    while (b != self->focused_control && b != 0 && n > 0)\n                    {\n                        n--;\n\n                        if (b->tab_stop)\n                        {\n                            focus_out_control = self->focused_control;\n                            self->focused_control = b;\n                            xrdp_bitmap_invalidate(focus_out_control, 0);\n                            xrdp_bitmap_invalidate(b, 0);\n                            break;\n                        }\n\n                        if (shift)\n                        {\n                            i--;\n\n                            if (i < 0)\n                            {\n                                i = self->child_list->count - 1;\n                            }\n                        }\n                        else\n                        {\n                            i++;\n\n                            if (i >= self->child_list->count)\n                            {\n                                i = 0;\n                            }\n                        }\n\n                        b = (struct xrdp_bitmap *)list_get_item(self->child_list, i);\n                    }\n                }\n            }\n            else if (scan_code == SCANCODE_ENTER_KEY ||\n                     scan_code == SCANCODE_KP_ENTER_KEY)\n            {\n                if (self->default_button != 0)\n                {\n                    if (self->notify != 0)\n                    {\n                        /* I think this should use def_proc */\n                        self->notify(self, self->default_button, 1, 0, 0);\n                        return 0;\n                    }\n                }\n            }\n            else if (scan_code == SCANCODE_ESC_KEY)\n            {\n                if (self->esc_button != 0)\n                {\n                    if (self->notify != 0)\n                    {\n                        /* I think this should use def_proc */\n                        self->notify(self, self->esc_button, 1, 0, 0);\n                        return 0;\n                    }\n                }\n            }\n        }\n\n        if (self->focused_control != 0)\n        {\n            struct xrdp_bitmap *fc = self->focused_control;\n            if (fc != 0 && fc->wm != 0)\n            {\n                xrdp_bitmap_def_proc(fc, msg, param1, param2);\n            }\n        }\n    }\n    else if (self->type == WND_TYPE_EDIT)\n    {\n        if (msg == WM_KEYDOWN)\n        {\n            int scan_code = SCANCODE_FROM_KBD_EVENT(param1, param2);\n            int num_lock = self->wm->num_lock;\n            /* We may need a keysym or a printable character for the key */\n            struct xrdp_key_info *ki = get_key_info_from_kbd_event\n                                       (param2, param1, self->wm->keys,\n                                        self->wm->caps_lock,\n                                        self->wm->num_lock, self->wm->scroll_lock,\n                                        &(self->wm->keymap));\n\n            /* left or up arrow */\n            if ((scan_code == SCANCODE_LEFT_ARROW_KEY) ||\n                    (scan_code == SCANCODE_UP_ARROW_KEY) ||\n                    (!num_lock && (scan_code == SCANCODE_KP_4_KEY)) ||\n                    (!num_lock && (scan_code == SCANCODE_KP_8_KEY)))\n            {\n                if (self->edit_pos > 0)\n                {\n                    self->edit_pos--;\n                    xrdp_bitmap_invalidate(self, 0);\n                }\n            }\n            /* right or down arrow */\n            else if ((scan_code == SCANCODE_RIGHT_ARROW_KEY) ||\n                     (scan_code == SCANCODE_DOWN_ARROW_KEY) ||\n                     (!num_lock && (scan_code == SCANCODE_KP_6_KEY)) ||\n                     (!num_lock && (scan_code == SCANCODE_KP_2_KEY)))\n            {\n                if (self->edit_pos < (int)utf8_char_count(self->caption1))\n                {\n                    self->edit_pos++;\n                    xrdp_bitmap_invalidate(self, 0);\n                }\n            }\n            /* backspace. Test keysym rather than scan code, so keys\n             * other than SCANCODE_BACKSPACE_KEY can generate backspace */\n            else if (ki != NULL && ki->sym == XK_BackSpace)\n            {\n                n = utf8_char_count(self->caption1);\n\n                if (n > 0)\n                {\n                    if (self->edit_pos > 0)\n                    {\n                        self->edit_pos--;\n                        utf8_remove_char_at(self->caption1, self->edit_pos);\n                        xrdp_bitmap_invalidate(self, 0);\n                    }\n                }\n            }\n            /* delete */\n            else if ((scan_code == SCANCODE_DEL_KEY)  ||\n                     (!num_lock && (scan_code == SCANCODE_KP_DEL_KEY)))\n\n            {\n                n = utf8_char_count(self->caption1);\n\n                if (n > 0)\n                {\n                    if (self->edit_pos < n)\n                    {\n                        utf8_remove_char_at(self->caption1, self->edit_pos);\n                        xrdp_bitmap_invalidate(self, 0);\n                    }\n                }\n            }\n            /* end */\n            else if ((scan_code == SCANCODE_END_KEY) ||\n                     (!num_lock && (scan_code == SCANCODE_KP_1_KEY)))\n            {\n                n = utf8_char_count(self->caption1);\n\n                if (self->edit_pos < n)\n                {\n                    self->edit_pos = n;\n                    xrdp_bitmap_invalidate(self, 0);\n                }\n            }\n            /* home */\n            else if ((scan_code == SCANCODE_HOME_KEY) ||\n                     (!num_lock && (scan_code == SCANCODE_KP_7_KEY)))\n            {\n                if (self->edit_pos > 0)\n                {\n                    self->edit_pos = 0;\n                    xrdp_bitmap_invalidate(self, 0);\n                }\n            }\n            else\n            {\n                char32_t c = (ki == NULL) ? 0 : ki->chr;\n                // Add a printing character to the string. If successful,\n                // bump the edit position and re-display the string\n                if (c >= ' ' &&\n                        utf8_add_char_at(self->caption1, 256, c, self->edit_pos))\n                {\n                    self->edit_pos++;\n                    xrdp_bitmap_invalidate(self, 0);\n                }\n            }\n        }\n    }\n    else if (self->type == WND_TYPE_COMBO)\n    {\n        if (msg == WM_KEYDOWN)\n        {\n            int scan_code = SCANCODE_FROM_KBD_EVENT(param1, param2);\n            int num_lock = self->wm->num_lock;\n\n            /* left or up arrow */\n            if ((scan_code == SCANCODE_LEFT_ARROW_KEY) ||\n                    (scan_code == SCANCODE_UP_ARROW_KEY) ||\n                    (!num_lock && (scan_code == SCANCODE_KP_4_KEY)) ||\n                    (!num_lock && (scan_code == SCANCODE_KP_8_KEY)))\n            {\n                if (self->item_index > 0)\n                {\n                    self->item_index--;\n                    xrdp_bitmap_invalidate(self, 0);\n\n                    struct xrdp_bitmap *p = self->parent;\n                    if (p != 0 && p->notify != 0)\n                    {\n                        p->notify(p, self, CB_ITEMCHANGE, 0, 0);\n                    }\n                }\n            }\n            /* right or down arrow */\n            else if ((scan_code == SCANCODE_RIGHT_ARROW_KEY) ||\n                     (scan_code == SCANCODE_DOWN_ARROW_KEY) ||\n                     (!num_lock && (scan_code == SCANCODE_KP_6_KEY)) ||\n                     (!num_lock && (scan_code == SCANCODE_KP_2_KEY)))\n            {\n                if ((self->item_index + 1) < self->string_list->count)\n                {\n                    self->item_index++;\n                    xrdp_bitmap_invalidate(self, 0);\n\n                    struct xrdp_bitmap *p = self->parent;\n                    if (p != 0 && p->notify != 0)\n                    {\n                        p->notify(p, self, CB_ITEMCHANGE, 0, 0);\n                    }\n                }\n            }\n        }\n    }\n    else if (self->type == WND_TYPE_SPECIAL)\n    {\n        if (msg == WM_MOUSEMOVE)\n        {\n            if (self->item_height > 0 && self->popped_from != 0)\n            {\n                i = param2;\n                i = i / self->item_height;\n\n                if (i != self->item_index &&\n                        i < self->popped_from->string_list->count)\n                {\n                    self->item_index = i;\n                    xrdp_bitmap_invalidate(self, 0);\n                }\n            }\n        }\n        else if (msg == WM_LBUTTONUP)\n        {\n            struct xrdp_bitmap *pf = self->popped_from;\n            if (pf != 0)\n            {\n                pf->item_index = self->item_index;\n                xrdp_bitmap_invalidate(pf, 0);\n\n                struct xrdp_bitmap *p = pf->parent;\n                if (p != 0 && p->notify != 0)\n                {\n                    p->notify(p, pf, CB_ITEMCHANGE, 0, 0);\n                }\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* convert the controls coords to screen coords */\nint\nxrdp_bitmap_to_screenx(struct xrdp_bitmap *self, int x)\n{\n    int i;\n\n    i = x;\n\n    while (self != 0)\n    {\n        i = i + self->left;\n        self = self->parent;\n    }\n\n    return i;\n}\n\n/*****************************************************************************/\n/* convert the controls coords to screen coords */\nint\nxrdp_bitmap_to_screeny(struct xrdp_bitmap *self, int y)\n{\n    int i;\n\n    i = y;\n\n    while (self != 0)\n    {\n        i = i + self->top;\n        self = self->parent;\n    }\n\n    return i;\n}\n\n/*****************************************************************************/\n/* convert the screen coords to controls coords */\nint\nxrdp_bitmap_from_screenx(struct xrdp_bitmap *self, int x)\n{\n    int i;\n\n    i = x;\n\n    while (self != 0)\n    {\n        i = i - self->left;\n        self = self->parent;\n    }\n\n    return i;\n}\n\n/*****************************************************************************/\n/* convert the screen coords to controls coords */\nint\nxrdp_bitmap_from_screeny(struct xrdp_bitmap *self, int y)\n{\n    int i;\n\n    i = y;\n\n    while (self != 0)\n    {\n        i = i - self->top;\n        self = self->parent;\n    }\n\n    return i;\n}\n\n/*****************************************************************************/\nint\nxrdp_bitmap_get_screen_clip(struct xrdp_bitmap *self,\n                            struct xrdp_painter *painter,\n                            struct xrdp_rect *rect,\n                            int *dx, int *dy)\n{\n    int ldx;\n    int ldy;\n\n    if (painter->use_clip)\n    {\n        *rect = painter->clip;\n    }\n    else\n    {\n        rect->left = 0;\n        rect->top = 0;\n        rect->right = self->width;\n        rect->bottom = self->height;\n    }\n\n    ldx = xrdp_bitmap_to_screenx(self, 0);\n    ldy = xrdp_bitmap_to_screeny(self, 0);\n    rect->left += ldx;\n    rect->top += ldy;\n    rect->right += ldx;\n    rect->bottom += ldy;\n\n    if (dx != 0)\n    {\n        *dx = ldx;\n    }\n\n    if (dy != 0)\n    {\n        *dy = ldy;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/xrdp_bitmap_common.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Common bitmap functions for all xrdp_bitmap*.c files\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <limits.h>\n\n#include \"xrdp.h\"\n\n/*****************************************************************************/\n/* Allocate bitmap for specified dimensions, checking for int overflow */\nstatic char *\nalloc_bitmap_data(int width, int height, int Bpp)\n{\n    char *result = NULL;\n    if (width > 0 && height > 0 && Bpp > 0)\n    {\n        int len = width;\n        /* g_malloc() currently takes an 'int' size */\n        if (len < INT_MAX / height)\n        {\n            len *= height;\n            if (len < INT_MAX / Bpp)\n            {\n                len *= Bpp;\n                result = (char *)malloc(len);\n            }\n        }\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nstruct xrdp_bitmap *\nxrdp_bitmap_create(int width, int height, int bpp,\n                   int type, struct xrdp_wm *wm)\n{\n    struct xrdp_bitmap *self = (struct xrdp_bitmap *)NULL;\n    int Bpp = 0;\n\n    self = (struct xrdp_bitmap *)g_malloc(sizeof(struct xrdp_bitmap), 1);\n    if (self == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_bitmap_create: no memory\");\n        return self;\n    }\n\n    self->type = type;\n    self->width = width;\n    self->height = height;\n    self->bpp = bpp;\n    Bpp = 4;\n\n    switch (bpp)\n    {\n        case 8:\n            Bpp = 1;\n            break;\n        case 15:\n            Bpp = 2;\n            break;\n        case 16:\n            Bpp = 2;\n            break;\n    }\n\n    if (self->type == WND_TYPE_BITMAP || self->type == WND_TYPE_IMAGE)\n    {\n        self->data = alloc_bitmap_data(width, height, Bpp);\n        if (self->data == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_bitmap_create: size overflow %dx%dx%d\",\n                width, height, Bpp);\n            g_free(self);\n            return NULL;\n        }\n    }\n\n#if defined(XRDP_PAINTER)\n    if (self->type == WND_TYPE_SCREEN) /* noorders */\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_bitmap_create: noorders\");\n        self->data = alloc_bitmap_data(width, height, Bpp);\n        if (self->data == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_bitmap_create: size overflow %dx%dx%d\",\n                width, height, Bpp);\n            g_free(self);\n            return NULL;\n        }\n    }\n#endif\n\n    if (self->type != WND_TYPE_BITMAP)\n    {\n        self->child_list = list_create();\n    }\n\n    self->line_size = width * Bpp;\n\n    if (self->type == WND_TYPE_COMBO)\n    {\n        self->string_list = list_create();\n        self->string_list->auto_free = 1;\n        self->data_list = list_create();\n        self->data_list->auto_free = 1;\n    }\n\n    self->wm = wm;\n    return self;\n}\n\n/*****************************************************************************/\nstruct xrdp_bitmap *\nxrdp_bitmap_create_with_data(int width, int height,\n                             int bpp, char *data,\n                             struct xrdp_wm *wm)\n{\n    struct xrdp_bitmap *self = (struct xrdp_bitmap *)NULL;\n    int Bpp;\n#if defined(NEED_ALIGN)\n    tintptr data_as_int;\n#endif\n\n    self = (struct xrdp_bitmap *)g_malloc(sizeof(struct xrdp_bitmap), 1);\n    self->type = WND_TYPE_BITMAP;\n    self->width = width;\n    self->height = height;\n    self->bpp = bpp;\n    self->wm = wm;\n\n    Bpp = 4;\n    switch (bpp)\n    {\n        case 8:\n            Bpp = 1;\n            break;\n        case 15:\n            Bpp = 2;\n            break;\n        case 16:\n            Bpp = 2;\n            break;\n    }\n    self->line_size = width * Bpp;\n\n#if defined(NEED_ALIGN)\n    data_as_int = (tintptr) data;\n    if (((bpp >= 24) && (data_as_int & 3)) ||\n            (((bpp == 15) || (bpp == 16)) && (data_as_int & 1)))\n    {\n        /* got to copy data here, it's not aligned\n           other calls in this file assume alignment */\n        self->data = (char *)g_malloc(width * height * Bpp, 0);\n        g_memcpy(self->data, data, width * height * Bpp);\n        return self;\n    }\n#endif\n    self->data = data;\n    self->do_not_free_data = 1;\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_bitmap_delete(struct xrdp_bitmap *self)\n{\n    int i;\n    struct xrdp_mod_data *mod_data = (struct xrdp_mod_data *)NULL;\n\n    if (self == 0)\n    {\n        return;\n    }\n\n    if (self->wm != 0)\n    {\n        if (self->wm->focused_window == self)\n        {\n            self->wm->focused_window = 0;\n        }\n\n        if (self->wm->popup_wnd != 0)\n        {\n            if (self->wm->popup_wnd == self || self->wm->popup_wnd->popped_from == self)\n            {\n                self->wm->popup_wnd = 0;\n            }\n        }\n\n        if (self->wm->dragging_window == self)\n        {\n            self->wm->dragging_window = 0;\n        }\n\n        if (self->wm->button_down == self)\n        {\n            self->wm->button_down = 0;\n        }\n\n        if (self->wm->login_window == self)\n        {\n            self->wm->login_window = 0;\n        }\n\n        if (self->wm->log_wnd == self)\n        {\n            self->wm->log_wnd = 0;\n        }\n    }\n\n    if (self->child_list != 0)\n    {\n        for (i = self->child_list->count - 1; i >= 0; i--)\n        {\n            xrdp_bitmap_delete((struct xrdp_bitmap *)self->child_list->items[i]);\n        }\n\n        list_delete(self->child_list);\n    }\n\n    if (self->parent != 0)\n    {\n        i = list_index_of(self->parent->child_list, (long)self);\n\n        if (i >= 0)\n        {\n            list_remove_item(self->parent->child_list, i);\n        }\n    }\n\n    if (self->string_list != 0) /* for combo */\n    {\n        list_delete(self->string_list);\n    }\n\n    if (self->data_list != 0) /* for combo */\n    {\n        for (i = 0; i < self->data_list->count; i++)\n        {\n            mod_data = (struct xrdp_mod_data *)list_get_item(self->data_list, i);\n\n            if (mod_data != 0)\n            {\n                list_delete(mod_data->names);\n                list_delete(mod_data->values);\n            }\n        }\n\n        list_delete(self->data_list);\n    }\n\n    if (!self->do_not_free_data)\n    {\n        g_free(self->data);\n    }\n\n    g_free(self->caption1);\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_bitmap_resize(struct xrdp_bitmap *self, int width, int height)\n{\n    int Bpp = 0;\n\n    if ((width == self->width) && (height == self->height))\n    {\n        return 0;\n    }\n\n    if (self->do_not_free_data)\n    {\n        return 1;\n    }\n\n    Bpp = 4;\n\n    switch (self->bpp)\n    {\n        case 8:\n            Bpp = 1;\n            break;\n        case 15:\n            Bpp = 2;\n            break;\n        case 16:\n            Bpp = 2;\n            break;\n    }\n\n    /* To prevent valgrind errors (particularly on a screen resize),\n       clear extra memory */\n    unsigned long old_size = self->width * self->height * Bpp;\n    unsigned long new_size = width * height * Bpp;\n\n    char *new_data = (char *)realloc(self->data, new_size);\n    if (new_data == NULL)\n    {\n        return 1;\n    }\n\n    self->width = width;\n    self->height = height;\n    if (new_data != self->data)\n    {\n        self->data = new_data;\n        memset(self->data, 0, new_size);\n    }\n    else if (new_size > old_size)\n    {\n        memset(self->data + old_size, 0, new_size - old_size);\n    }\n    self->line_size = width * Bpp;\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_bitmap_get_pixel(struct xrdp_bitmap *self, int x, int y)\n{\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (self->data == 0)\n    {\n        return 0;\n    }\n\n    if (x >= 0 && x < self->width && y >= 0 && y < self->height)\n    {\n        if (self->bpp == 8)\n        {\n            return GETPIXEL8(self->data, x, y, self->width);\n        }\n        else if (self->bpp == 15 || self->bpp == 16)\n        {\n            return GETPIXEL16(self->data, x, y, self->width);\n        }\n        else if (self->bpp >= 24)\n        {\n            return GETPIXEL32(self->data, x, y, self->width);\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_bitmap_set_pixel(struct xrdp_bitmap *self, int x, int y, int pixel)\n{\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (self->data == 0)\n    {\n        return 0;\n    }\n\n    if (x >= 0 && x < self->width && y >= 0 && y < self->height)\n    {\n        if (self->bpp == 8)\n        {\n            SETPIXEL8(self->data, x, y, self->width, pixel);\n        }\n        else if (self->bpp == 15 || self->bpp == 16)\n        {\n            SETPIXEL16(self->data, x, y, self->width, pixel);\n        }\n        else if (self->bpp >= 24)\n        {\n            SETPIXEL32(self->data, x, y, self->width, pixel);\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* copy part of self at x, y to 0, 0 in dest */\n/* returns error */\nint\nxrdp_bitmap_copy_box(struct xrdp_bitmap *self,\n                     struct xrdp_bitmap *dest,\n                     int x, int y, int cx, int cy)\n{\n    int i;\n    int destx;\n    int desty;\n    int incs;\n    int incd;\n    tui8 *s8;\n    tui8 *d8;\n    tui16 *s16;\n    tui16 *d16;\n    tui32 *s32;\n    tui32 *d32;\n\n    if (self == 0)\n    {\n        return 1;\n    }\n\n    if (dest == 0)\n    {\n        return 1;\n    }\n\n    if (self->type != WND_TYPE_BITMAP && self->type != WND_TYPE_IMAGE)\n    {\n        return 1;\n    }\n\n    if (dest->type != WND_TYPE_BITMAP && dest->type != WND_TYPE_IMAGE)\n    {\n        return 1;\n    }\n\n    if (self->bpp != dest->bpp)\n    {\n        return 1;\n    }\n\n    destx = 0;\n    desty = 0;\n\n    if (!check_bounds(self, &x, &y, &cx, &cy))\n    {\n        return 1;\n    }\n\n    if (!check_bounds(dest, &destx, &desty, &cx, &cy))\n    {\n        return 1;\n    }\n\n    if (self->bpp >= 24)\n    {\n        s32 = ((tui32 *)(self->data)) + (self->width * y + x);\n        d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx);\n        incs = self->width - cx;\n        incd = dest->width - cx;\n\n        for (i = 0; i < cy; i++)\n        {\n            g_memcpy(d32, s32, cx * 4);\n            s32 += cx;\n            d32 += cx;\n\n            s32 += incs;\n            d32 += incd;\n        }\n\n    }\n    else if (self->bpp == 15 || self->bpp == 16)\n    {\n        s16 = ((tui16 *)(self->data)) + (self->width * y + x);\n        d16 = ((tui16 *)(dest->data)) + (dest->width * desty + destx);\n        incs = self->width - cx;\n        incd = dest->width - cx;\n\n        for (i = 0; i < cy; i++)\n        {\n            g_memcpy(d16, s16, cx * 2);\n            s16 += cx;\n            d16 += cx;\n\n            s16 += incs;\n            d16 += incd;\n        }\n    }\n    else if (self->bpp == 8)\n    {\n        s8 = ((tui8 *)(self->data)) + (self->width * y + x);\n        d8 = ((tui8 *)(dest->data)) + (dest->width * desty + destx);\n        incs = self->width - cx;\n        incd = dest->width - cx;\n\n        for (i = 0; i < cy; i++)\n        {\n            g_memcpy(d8, s8, cx);\n            s8 += cx;\n            d8 += cx;\n\n            s8 += incs;\n            d8 += incd;\n        }\n    }\n    else\n    {\n        return 1;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/xrdp_bitmap_load.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Load xrdp_bitmap from file\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#ifdef USE_IMLIB2\n#   include <Imlib2.h>\n#endif\n\n#include \"xrdp.h\"\n#include \"log.h\"\n\n/* Rounds up to the nearest multiple of 4 */\n#define ROUND4(x) (((x) + 3) / 4 * 4)\n\n/* Are we using the builtin BMP format-only loader */\n\n#ifdef USE_BUILTIN_LOADER\n#   undef USE_BUILTIN_LOADER\n#endif\n\n#ifndef USE_IMLIB2\n#   define USE_BUILTIN_LOADER\n#endif\n\n/**\n * Describes a box within an image\n */\nstruct box\n{\n    int left_margin;\n    int width;\n    int top_margin;\n    int height;\n};\n\n/**************************************************************************//**\n * Calculates a zoom box, from source and destination image dimensions\n *\n * The zoom box is the largest centred part of the source image which\n * preserves the aspect ratio of the destination image. We find it\n * by cutting off the left and right sides of the source, or the top\n * and bottom.\n *\n * @param src_width    Width of source image\n * @param src_height   Height of source image\n * @param dst_width    Width of destination image\n * @param dst_height   Height of destination image\n * @param[out] zb_return Zoom box\n * @return 0 for success\n */\nstatic int\ncalculate_zoom_box(int src_width, int src_height,\n                   int dst_width, int dst_height,\n                   struct box *zb_return)\n{\n    int result = 1;\n    struct box zb;\n\n    if (dst_height == 0 || src_height == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't zoom to or from zero-width images\");\n    }\n    else\n    {\n        double dst_ratio = (double)dst_width / dst_height;\n        double src_ratio = (double)src_width / src_height;\n\n        if (src_ratio > dst_ratio)\n        {\n            /* Source is relatively wider than source. Select a box\n             * narrower than the source, but the same height */\n            zb.width = (int)(dst_ratio * src_height + .5);\n            zb.left_margin = (src_width - zb.width) / 2;\n            zb.height = src_height;\n            zb.top_margin = 0;\n        }\n        else\n        {\n            /* Source is relatively taller than source (or same shape) */\n            zb.width = src_width;\n            zb.left_margin = 0;\n            zb.height = (int)(src_width / dst_ratio + .5);\n            zb.top_margin = (src_height - zb.height) / 2;\n        }\n\n        /* Only allow meaningful zoom boxes */\n        if (zb.width < 1 || zb.height < 1)\n        {\n            LOG(LOG_LEVEL_WARNING, \"Ignoring pathological zoom\"\n                \" request (%dx%d) -> (%dx%d)\", src_width, src_height,\n                dst_width, dst_height);\n        }\n        else\n        {\n            *zb_return = zb;\n            result = 0;\n        }\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_bitmap_get_index(struct xrdp_bitmap *self, const int *palette, int color)\n{\n    int r = 0;\n    int g = 0;\n    int b = 0;\n\n    r = (color & 0xff0000) >> 16;\n    g = (color & 0x00ff00) >> 8;\n    b = (color & 0x0000ff) >> 0;\n    r = (r >> 5) << 0;\n    g = (g >> 5) << 3;\n    b = (b >> 6) << 6;\n    return (b | g | r);\n}\n\n#ifdef USE_BUILTIN_LOADER\n/**************************************************************************//**\n * Private routine to swap pixel data between two pixmaps\n * @param a First bitmap\n * @param b Second bitmap\n *\n * The main use-case for this routine is to modify an existing bitmap using\n * the following logic:-\n * - Create a temporary WND_TYPE_BITMAP\n * - Process the data in a bitmap in some way, moving it to the temporary\n * - Call this routine\n * - Delete the temporary\n *\n */\nstatic void\nswap_pixel_data(struct xrdp_bitmap *a, struct xrdp_bitmap *b)\n{\n    int tmp_width = a->width;\n    int tmp_height = a->height;\n    int tmp_bpp = a->bpp;\n    int tmp_line_size = a->line_size;\n    char *tmp_data = a->data;\n    int tmp_do_not_free_data = a->do_not_free_data;\n\n    a->width = b->width;\n    a->height = b->height;\n    a->bpp = b->bpp;\n    a->line_size = b->line_size;\n    a->data = b->data;\n    a->do_not_free_data = b->do_not_free_data;\n\n    b->width = tmp_width;\n    b->height = tmp_height;\n    b->bpp = tmp_bpp;\n    b->line_size = tmp_line_size;\n    b->data = tmp_data;\n    b->do_not_free_data = tmp_do_not_free_data;\n}\n#endif /* USE_BUILTIN_LOADER */\n\n#ifdef USE_BUILTIN_LOADER\n/**************************************************************************//**\n * Scales a bitmap image\n *\n * @param self Bitmap to scale\n * @param targ_width target width\n * @param targ_height target height\n * @return 0 for success\n */\nstatic int\nxrdp_bitmap_scale(struct xrdp_bitmap *self, int targ_width, int targ_height)\n{\n    int src_width = self->width;\n    int src_height = self->height;\n\n    if (src_width != targ_width || src_height != targ_height)\n    {\n        struct xrdp_bitmap *target =\n            xrdp_bitmap_create(targ_width, targ_height,\n                               self->bpp, WND_TYPE_BITMAP, 0);\n        int targ_x, targ_y;\n\n        if (target == NULL)\n        {\n            /* Error is logged */\n            return 1;\n        }\n\n        /* For each pixel in the target pixmap, scale to one in the source */\n        for (targ_x = 0 ; targ_x < targ_width; ++targ_x)\n        {\n            int src_x = targ_x * src_width / targ_width;\n            for (targ_y = 0 ; targ_y < targ_height; ++targ_y)\n            {\n                int src_y = targ_y * src_height / targ_height;\n                int pixel = xrdp_bitmap_get_pixel(self, src_x, src_y);\n                xrdp_bitmap_set_pixel(target, targ_x, targ_y, pixel);\n            }\n        }\n        swap_pixel_data(self, target);\n        xrdp_bitmap_delete(target);\n    }\n\n    return 0;\n}\n#endif /* USE_BUILTIN_LOADER */\n\n\n#ifdef USE_BUILTIN_LOADER\n/**************************************************************************//**\n * Zooms a bitmap image\n *\n * @param self Bitmap to zoom\n * @param targ_width target width\n * @param targ_height target height\n * @return 0 for success\n *\n * This works the same way as a scaled image, but the aspect ratio is\n * maintained by removing pixels from the top-and-bottom,\n * or the left-and-right before scaling.\n */\nstatic int\nxrdp_bitmap_zoom(struct xrdp_bitmap *self, int targ_width, int targ_height)\n{\n    struct box zb;\n\n    int result = 0;\n\n    if (calculate_zoom_box(self->width, self->height,\n                           targ_width, targ_height, &zb) == 0)\n    {\n        /* Need to chop anything? */\n        if (zb.top_margin != 0 || zb.left_margin != 0)\n        {\n            struct xrdp_bitmap *zbitmap;\n            zbitmap = xrdp_bitmap_create(zb.width, zb.height, self->bpp,\n                                         WND_TYPE_BITMAP, 0);\n            if (zbitmap == NULL)\n            {\n                LOG(LOG_LEVEL_ERROR, \"xrdp_bitmap_zoom: no memory\");\n                result = 1;\n            }\n            else\n            {\n                result = xrdp_bitmap_copy_box(self, zbitmap,\n                                              zb.left_margin, zb.top_margin,\n                                              zb.width, zb.height);\n                if (result != 0)\n                {\n                    LOG(LOG_LEVEL_ERROR, \"xrdp_bitmap_zoom: can't copy box\");\n                }\n                else\n                {\n                    swap_pixel_data(self, zbitmap);\n                }\n                xrdp_bitmap_delete(zbitmap);\n            }\n        }\n    }\n\n    if (result == 0)\n    {\n        result = xrdp_bitmap_scale(self, targ_width, targ_height);\n    }\n\n    return result;\n}\n#endif /* USE_BUILTIN_LOADER */\n\n#ifdef USE_BUILTIN_LOADER\n/**************************************************************************//**\n * reads the palette from a bmp file with a palette embedded in it\n *\n * @pre The read position in the file is at the end of the bmp DIB header.\n *\n * @param filename  Name of file\n * @param fd   File descriptor for file\n * @param header Pointer to BMP header info struct\n * @param palette output. Must be at least 256 elements\n */\nstatic void\nread_palette(const char *filename, int fd,\n             const struct xrdp_bmp_header *header, int *palette)\n{\n    struct stream *s;\n    int clr_used;\n    int palette_size;\n    int len;\n    int i;\n\n    /* Find the number of colors used in the bitmap */\n    if (header->clr_used != 0)\n    {\n        clr_used = header->clr_used;\n        /* Is the header value sane? */\n        if (clr_used < 0 || clr_used > 256)\n        {\n            clr_used = 256;\n            LOG(LOG_LEVEL_WARNING, \"%s : Invalid palette size %d in file %s\",\n                __func__, header->clr_used, filename);\n        }\n    }\n    else if (header->bit_count == 4)\n    {\n        clr_used = 16;\n    }\n    else\n    {\n        clr_used = 256;\n    }\n\n    palette_size = clr_used * 4;\n\n    make_stream(s);\n    init_stream(s, palette_size);\n\n    /* Pre-fill the buffer, so if we get short reads we're\n     * not working with uninitialised data */\n    g_memset(s->data, 0, palette_size);\n    s->end = s->data + palette_size;\n\n    len = g_file_read(fd, s->data, palette_size);\n    if (len != palette_size)\n    {\n        LOG(LOG_LEVEL_WARNING, \"%s: unexpected read length in file %s\",\n            __func__, filename);\n    }\n\n    for (i = 0; i < clr_used; ++i)\n    {\n        in_uint32_le(s, palette[i]);\n    }\n\n    free_stream(s);\n}\n#endif /* USE_BUILTIN_LOADER */\n\n#ifdef USE_BUILTIN_LOADER\n/**************************************************************************//**\n * Process a row of data from a 24-bit bmp file\n *\n * @param self Bitmap we're filling in\n * @param s Stream containing bitmap data\n * @param in_palette Palette from bmp file (unused)\n * @param out_palette Palette for output bitmap\n * @param row Row number\n */\nstatic void\nprocess_row_data_24bit(struct xrdp_bitmap *self,\n                       struct stream *s,\n                       const int *in_palette,\n                       const int *out_palette,\n                       int row)\n{\n    int j;\n    int k;\n    int color;\n\n    for (j = 0; j < self->width; ++j)\n    {\n        in_uint8(s, k);\n        color = k;\n        in_uint8(s, k);\n        color |= k << 8;\n        in_uint8(s, k);\n        color |= k << 16;\n\n        if (self->bpp == 8)\n        {\n            color = xrdp_bitmap_get_index(self, out_palette, color);\n        }\n        else if (self->bpp == 15)\n        {\n            color = COLOR15((color & 0xff0000) >> 16,\n                            (color & 0x00ff00) >> 8,\n                            (color & 0x0000ff) >> 0);\n        }\n        else if (self->bpp == 16)\n        {\n            color = COLOR16((color & 0xff0000) >> 16,\n                            (color & 0x00ff00) >> 8,\n                            (color & 0x0000ff) >> 0);\n        }\n\n        xrdp_bitmap_set_pixel(self, j, row, color);\n    }\n}\n#endif /* USE_BUILTIN_LOADER */\n\n#ifdef USE_BUILTIN_LOADER\n/**************************************************************************//**\n * Process a row of data from an 8-bit bmp file\n *\n * @param self Bitmap we're filling in\n * @param s Stream containing bitmap data\n * @param in_palette Palette from bmp file\n * @param out_palette Palette for output bitmap\n * @param row Row number\n */\nstatic void\nprocess_row_data_8bit(struct xrdp_bitmap *self,\n                      struct stream *s,\n                      const int *in_palette,\n                      const int *out_palette,\n                      int row)\n{\n    int j;\n    int k;\n    int color;\n\n    for (j = 0; j < self->width; ++j)\n    {\n        in_uint8(s, k);\n        color = in_palette[k];\n\n        if (self->bpp == 8)\n        {\n            color = xrdp_bitmap_get_index(self, out_palette, color);\n        }\n        else if (self->bpp == 15)\n        {\n            color = COLOR15((color & 0xff0000) >> 16,\n                            (color & 0x00ff00) >> 8,\n                            (color & 0x0000ff) >> 0);\n        }\n        else if (self->bpp == 16)\n        {\n            color = COLOR16((color & 0xff0000) >> 16,\n                            (color & 0x00ff00) >> 8,\n                            (color & 0x0000ff) >> 0);\n        }\n\n        xrdp_bitmap_set_pixel(self, j, row, color);\n    }\n}\n#endif /* USE_BUILTIN_LOADER */\n\n#ifdef USE_BUILTIN_LOADER\n/**************************************************************************//**\n * Process a row of data from an 4-bit bmp file\n *\n * @param self Bitmap we're filling in\n * @param s Stream containing bitmap data\n * @param in_palette Palette from bmp file\n * @param out_palette Palette for output bitmap\n * @param row Row number\n */\nstatic void\nprocess_row_data_4bit(struct xrdp_bitmap *self,\n                      struct stream *s,\n                      const int *in_palette,\n                      const int *out_palette,\n                      int row)\n{\n    int j;\n    int k = 0;\n    int color;\n\n    for (j = 0; j < self->width; ++j)\n    {\n        if ((j & 1) == 0)\n        {\n            in_uint8(s, k);\n            color = (k >> 4) & 0xf;\n        }\n        else\n        {\n            color = k & 0xf;\n        }\n\n        color = in_palette[color];\n\n        if (self->bpp == 8)\n        {\n            color = xrdp_bitmap_get_index(self, out_palette, color);\n        }\n        else if (self->bpp == 15)\n        {\n            color = COLOR15((color & 0xff0000) >> 16,\n                            (color & 0x00ff00) >> 8,\n                            (color & 0x0000ff) >> 0);\n        }\n        else if (self->bpp == 16)\n        {\n            color = COLOR16((color & 0xff0000) >> 16,\n                            (color & 0x00ff00) >> 8,\n                            (color & 0x0000ff) >> 0);\n        }\n\n        xrdp_bitmap_set_pixel(self, j, row, color);\n    }\n}\n#endif /* USE_BUILTIN_LOADER */\n\n#ifdef USE_BUILTIN_LOADER\n/*****************************************************************************/\n/* load a bmp file */\n/* return 0 ok */\n/* return 1 error */\nstatic int\nxrdp_bitmap_load_bmp(struct xrdp_bitmap *self, const char *filename,\n                     const int *out_palette)\n{\n    int fd = 0;\n    int len = 0;\n    int row = 0;\n    int row_size = 0;\n    int bmp_palette[256] = {0};\n    char fixed_header[14] = {0};\n    struct xrdp_bmp_header header = {0};\n    struct stream *s = (struct stream *)NULL;\n    /* Pointer to row data processing function */\n    void (*process_row_data)(struct xrdp_bitmap * self,\n                             struct stream * s,\n                             const int *in_palette,\n                             const int *out_palette,\n                             int row);\n\n    if (!g_file_exist(filename))\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s: error bitmap file [%s] does not exist\",\n            __func__, filename);\n        return 1;\n    }\n\n    fd = g_file_open_ro(filename);\n\n    if (fd == -1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s: error loading bitmap from file [%s]\",\n            __func__, filename);\n        return 1;\n    }\n\n    /* read the fixed file header */\n    if (g_file_read(fd, fixed_header, 14) != 14)\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s: error bitmap file [%s] read error\",\n            __func__, filename);\n        g_file_close(fd);\n        return 1;\n    }\n\n    if ((fixed_header[0] != 'B') || (fixed_header[1] != 'M'))\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s: error bitmap file [%s] not BMP file\",\n            __func__, filename);\n        g_file_close(fd);\n        return 1;\n    }\n\n    /* read information header */\n    make_stream(s);\n    init_stream(s, 8192);\n    len = g_file_read(fd, s->data, 40); /* size better be 40 */\n    if (len != 40)\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s: unexpected read length %d in file %s\",\n            __func__, len, filename);\n        free_stream(s);\n        g_file_close(fd);\n        return 1;\n    }\n    s->end = s->data + len;\n    in_uint32_le(s, header.size);\n    in_uint32_le(s, header.image_width);\n    in_uint32_le(s, header.image_height);\n    in_uint16_le(s, header.planes);\n    in_uint16_le(s, header.bit_count);\n    in_uint32_le(s, header.compression);\n    in_uint32_le(s, header.image_size);\n    in_uint32_le(s, header.x_pels_per_meter);\n    in_uint32_le(s, header.y_pels_per_meter);\n    in_uint32_le(s, header.clr_used);\n    in_uint32_le(s, header.clr_important);\n\n    if (header.compression != 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"%s: error bitmap file [%s]\"\n            \" unsupported compression value %d\",\n            __func__, filename, header.compression);\n    }\n\n    if (g_file_seek(fd, 14 + header.size) < 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"%s: seek error in file %s\",\n            __func__, filename);\n    }\n\n    /* Validate the bit count for the file, read any palette, and\n     * determine the row size and row processing function */\n    switch (header.bit_count)\n    {\n        case 24:\n            row_size = ROUND4(header.image_width * 3);\n            process_row_data = process_row_data_24bit;\n            break;\n\n        case 8:\n            read_palette(filename, fd, &header, bmp_palette);\n            row_size = ROUND4(header.image_width);\n            process_row_data = process_row_data_8bit;\n            break;\n\n        case 4:\n            read_palette(filename, fd, &header, bmp_palette);\n            /* The storage for a row is a complex calculation for 4 bit pixels.\n             * a width of 1-8 pixels takes 4 bytes\n             * a width of 9-16 pixels takes 8 bytes, etc\n             * So bytes = (width + 7) / 8 * 4\n             */\n            row_size = ((header.image_width + 7) / 8 * 4);\n            process_row_data = process_row_data_4bit;\n            break;\n\n        default:\n            LOG(LOG_LEVEL_ERROR, \"%s: error bitmap file [%s] bad bpp %d\",\n                __func__, filename, header.bit_count);\n            free_stream(s);\n            g_file_close(fd);\n            return 1;\n    }\n\n    xrdp_bitmap_resize(self, header.image_width, header.image_height);\n\n    /* Set up the row data buffer. Pre fill it, so if we get short reads\n     * we're not working with uninitialised data */\n    init_stream(s, row_size);\n    g_memset(s->data, 0, row_size);\n    s->end = s->data + row_size;\n\n    /* read and process the pixel data a row at a time */\n    for (row = header.image_height - 1; row >= 0; row--)\n    {\n        len = g_file_read(fd, s->data, row_size);\n\n        if (len != row_size)\n        {\n            LOG(LOG_LEVEL_WARNING, \"%s: error bitmap file [%s] read\",\n                __func__, filename);\n        }\n\n        s->p = s->data;\n        (*process_row_data)(self, s, bmp_palette, out_palette, row);\n    }\n\n    g_file_close(fd);\n    free_stream(s);\n\n    return 0;\n}\n#endif /* USE_BUILTIN_LOADER */\n\n#ifdef USE_BUILTIN_LOADER\n/*****************************************************************************/\nint\nxrdp_bitmap_load(struct xrdp_bitmap *self, const char *filename,\n                 const int *palette,\n                 int background,\n                 enum xrdp_bitmap_load_transform transform,\n                 int twidth,\n                 int theight)\n{\n    /* this is the default bmp-only implementation if a graphics library\n     * isn't built in */\n\n    int result = xrdp_bitmap_load_bmp(self, filename, palette);\n    if (result == 0)\n    {\n        switch (transform)\n        {\n            case XBLT_NONE:\n                break;\n\n            case XBLT_SCALE:\n                result = xrdp_bitmap_scale(self, twidth, theight);\n                break;\n\n            case XBLT_ZOOM:\n                result = xrdp_bitmap_zoom(self, twidth, theight);\n                break;\n\n            default:\n                LOG(LOG_LEVEL_WARNING, \"Invalid bitmap transform %d specified\",\n                    transform);\n        }\n    }\n\n    return result;\n}\n#endif /* USE_BUILTIN_LOADER */\n\n#ifdef USE_IMLIB2\n/**************************************************************************//**\n * Log an error from the Imlib2 library\n *\n * @param level Log level to use\n * @param filename file we're trying to load\n * @param lerr Error return from imlib2\n */\nstatic void\nlog_imlib2_error(enum logLevels level, const char *filename,\n                 Imlib_Load_Error lerr)\n{\n    const char *msg;\n    char buff[256];\n\n    switch (lerr)\n    {\n        case IMLIB_LOAD_ERROR_NONE:\n            msg = \"No error\";\n            break;\n        case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST:\n            msg = \"No such file\";\n            break;\n        case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ:\n            msg = \"Permission denied\";\n            break;\n        case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT:\n            msg = \"Unrecognised file format\";\n            break;\n        case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY:\n        case IMLIB_LOAD_ERROR_PATH_TOO_LONG:\n        case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT:\n        case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE:\n        case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS:\n            msg = \"Bad filename\";\n            break;\n        case IMLIB_LOAD_ERROR_OUT_OF_MEMORY:\n            msg = \" No memory\";\n            break;\n        case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS:\n            msg = \"No file descriptors\";\n            break;\n        case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE:\n            msg = \"No disk space\";\n            break;\n        case IMLIB_LOAD_ERROR_UNKNOWN:\n            msg = \"Unknown error\";\n            break;\n        default:\n            g_snprintf(buff, sizeof(buff), \"Unrecognised code %d\", lerr);\n            msg = buff;\n    }\n\n    LOG(LOG_LEVEL_ERROR, \"Error loading %s [%s]\", filename, msg);\n}\n#endif /* USE_IMLIB2 */\n\n#ifdef USE_IMLIB2\n/**************************************************************************//**\n * Blend an imlib2 image onto a background of the specified color\n *\n * The current context image is merged. On return the new image is the\n * current context image, and the old image is deleted.\n *\n * @param filename Filename we're working on (for error reporting)\n * @param r Background red\n * @param g Background green\n * @param b Background blue\n *\n * @return 0 for success. On failure the current context image is unchanged.\n */\nstatic int\nblend_imlib_image_onto_background(const char *filename, int r, int g, int b)\n{\n    int result = 0;\n    Imlib_Image img = imlib_context_get_image();\n\n    if (img == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"No context for blending image\");\n        result = 1;\n    }\n    else\n    {\n        int width = imlib_image_get_width();\n        int height = imlib_image_get_height();\n\n        /* Create a suitable image to merge this one onto */\n        Imlib_Image bg = imlib_create_image(width, height);\n        if (bg == NULL)\n        {\n            log_imlib2_error(LOG_LEVEL_ERROR, filename,\n                             IMLIB_LOAD_ERROR_OUT_OF_MEMORY);\n            result = 1;\n        }\n        else\n        {\n            imlib_context_set_image(bg);\n            imlib_context_set_color(r, g, b, 0xff);\n            imlib_image_fill_rectangle(0, 0, width, height);\n            imlib_blend_image_onto_image(img, 0,\n                                         0, 0, width, height,\n                                         0, 0, width, height);\n            imlib_context_set_image(img);\n            imlib_free_image();\n            imlib_context_set_image(bg);\n        }\n    }\n    return result;\n}\n#endif /* USE_IMLIB2 */\n\n#ifdef USE_IMLIB2\n/**************************************************************************//**\n * Scales an imlib2 image\n *\n * The current context image is scaled. On return the new image is the\n * current context image, and the old image is deleted.\n *\n * @param filename Filename we're working on (for error reporting)\n * @param twidth target width\n * @param theight target height\n * @return 0 for success\n */\nstatic int\nscale_imlib_image(const char *filename, int twidth, int theight)\n{\n    int result = 0;\n    Imlib_Image img = imlib_context_get_image();\n\n    if (img == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"No context for scaling image\");\n        result = 1;\n    }\n    else\n    {\n        int width = imlib_image_get_width();\n        int height = imlib_image_get_height();\n\n        Imlib_Image newimg = imlib_create_cropped_scaled_image(\n                                 0, 0, width, height, twidth, theight);\n        if (newimg == NULL)\n        {\n            log_imlib2_error(LOG_LEVEL_ERROR, filename,\n                             IMLIB_LOAD_ERROR_OUT_OF_MEMORY);\n            result = 1;\n        }\n        else\n        {\n            imlib_free_image();\n            imlib_context_set_image(newimg);\n        }\n    }\n    return result;\n}\n#endif /* USE_IMLIB2 */\n\n#ifdef USE_IMLIB2\n/**************************************************************************//**\n * Zooms an imlib2 image\n *\n * @param filename Filename we're working on (for error reporting)\n * @param twidth target width\n * @param theight target height\n * @return 0 for success\n */\nstatic int\nzoom_imlib_image(const char *filename, int twidth, int theight)\n{\n    int result = 0;\n    Imlib_Image img = imlib_context_get_image();\n\n    if (img == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"No context for zooming image\");\n        result = 1;\n    }\n    else\n    {\n        struct box zb;\n        Imlib_Image newimg = NULL;\n        int width = imlib_image_get_width();\n        int height = imlib_image_get_height();\n\n        if (calculate_zoom_box(width, height,\n                               twidth, theight, &zb) == 0)\n        {\n            newimg = imlib_create_cropped_scaled_image(\n                         zb.left_margin, zb.top_margin,\n                         zb.width, zb.height, twidth, theight);\n        }\n        else\n        {\n            /* Can't zoom - scale the image instead */\n            newimg = imlib_create_cropped_scaled_image(\n                         0, 0, width, height, twidth, theight);\n        }\n        if (newimg == NULL)\n\n        {\n            log_imlib2_error(LOG_LEVEL_ERROR, filename,\n                             IMLIB_LOAD_ERROR_OUT_OF_MEMORY);\n            result = 1;\n        }\n        else\n        {\n            imlib_free_image();\n            imlib_context_set_image(newimg);\n        }\n    }\n    return result;\n}\n#endif /* USE_IMLIB2 */\n\n#ifdef USE_IMLIB2\n/**************************************************************************//**\n * Copies imlib2 image data to a bitmap\n *\n * @param self bitmap to copy data to\n * @param out_palette Palette for output bitmap\n * @return 0 for success\n */\nstatic int\ncopy_imlib_data_to_bitmap(struct xrdp_bitmap *self,\n                          const int *out_palette)\n{\n    int result = 0;\n    Imlib_Image img = imlib_context_get_image();\n\n    if (img == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"No context for zooming image\");\n        result = 1;\n    }\n    else\n    {\n        int width = imlib_image_get_width();\n        int height = imlib_image_get_height();\n        int i;\n        int j;\n        DATA32 *bdata;\n        int color;\n        xrdp_bitmap_resize(self, width, height);\n\n        bdata = imlib_image_get_data_for_reading_only();\n        for (j = 0 ; j < height; ++j)\n        {\n            for (i = 0 ; i < width ; ++i)\n            {\n                color = (*bdata++ & 0xffffff);\n\n                if (self->bpp == 8)\n                {\n                    color = xrdp_bitmap_get_index(self, out_palette, color);\n                }\n                else if (self->bpp == 15)\n                {\n                    color = COLOR15((color & 0xff0000) >> 16,\n                                    (color & 0x00ff00) >> 8,\n                                    (color & 0x0000ff) >> 0);\n                }\n                else if (self->bpp == 16)\n                {\n                    color = COLOR16((color & 0xff0000) >> 16,\n                                    (color & 0x00ff00) >> 8,\n                                    (color & 0x0000ff) >> 0);\n                }\n\n                xrdp_bitmap_set_pixel(self, i, j, color);\n            }\n        }\n    }\n\n    return result;\n}\n#endif /* USE_IMLIB2 */\n\n#ifdef USE_IMLIB2\n/**\n * Converts an xrdp HCOLOR into RGB values used by imlib2\n *\n * @param hcolor Color to convert\n * @param bpp    Bits-per-pixel for the hcolor\n * @param[out] r Red value\n * @param[out] g Green value\n * @param[out] b Blue value\n */\nstatic void hcolor_to_rgb(int hcolor, int bpp, int *r, int *g, int *b)\n{\n    switch (bpp)\n    {\n        case 8:\n            *r = (hcolor & 0x7) << 5;\n            *g = (hcolor & 0x38) << 2;\n            *b = (hcolor & 0xc0);\n            break;\n\n        case 15:\n            SPLITCOLOR15(*r, *g, *b, hcolor);\n            break;\n\n        case 16:\n            SPLITCOLOR16(*r, *g, *b, hcolor);\n            break;\n\n        default:\n            /* Beware : HCOLOR is BGR, not RGB */\n            *r = hcolor & 0xff;\n            *g = (hcolor >> 8) & 0xff;\n            *b = (hcolor >> 16) & 0xff;\n            break;\n    }\n}\n#endif\n\n#ifdef USE_IMLIB2\n/*****************************************************************************/\nint\nxrdp_bitmap_load(struct xrdp_bitmap *self, const char *filename,\n                 const int *palette,\n                 int background,\n                 enum xrdp_bitmap_load_transform transform,\n                 int twidth,\n                 int theight)\n{\n    int result = 0;\n    Imlib_Load_Error lerr;\n    int free_context_image = 0; /* Set if we've got an image loaded */\n    Imlib_Image img = imlib_load_image_with_error_return(filename, &lerr);\n\n    /* Load the image */\n    if (img == NULL)\n    {\n        log_imlib2_error(LOG_LEVEL_ERROR, filename, lerr);\n        result = 1;\n    }\n    else\n    {\n        imlib_context_set_image(img);\n        free_context_image = 1;\n    }\n\n    /* Sort out the background */\n    if (result == 0 && imlib_image_has_alpha())\n    {\n        int r;\n        int g;\n        int b;\n        hcolor_to_rgb(background, self->bpp, &r, &g, &b);\n\n        result = blend_imlib_image_onto_background(filename, r, g, b);\n    }\n\n    if (result == 0)\n    {\n        switch (transform)\n        {\n            case XBLT_NONE:\n                break;\n\n            case XBLT_SCALE:\n                result = scale_imlib_image(filename, twidth, theight);\n                break;\n\n            case XBLT_ZOOM:\n                result = zoom_imlib_image(filename, twidth, theight);\n                break;\n\n            default:\n                LOG(LOG_LEVEL_WARNING, \"Invalid bitmap transform %d specified\",\n                    transform);\n        }\n    }\n\n    if (result == 0)\n    {\n        result = copy_imlib_data_to_bitmap(self, palette);\n    }\n\n    if (free_context_image)\n    {\n        imlib_free_image();\n    }\n\n    return result;\n}\n#endif /* USE_IMLIB2 */\n"
  },
  {
    "path": "xrdp/xrdp_cache.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * cache\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp.h\"\n#include \"log.h\"\n\n\n\n/*****************************************************************************/\nstatic int\nxrdp_cache_reset_lru(struct xrdp_cache *self)\n{\n    int index;\n    int jndex;\n    struct xrdp_lru_item *lru;\n\n    for (index = 0; index < XRDP_MAX_BITMAP_CACHE_ID; index++)\n    {\n        /* fist item */\n        lru = &(self->bitmap_lrus[index][0]);\n        lru->next = 1;\n        lru->prev = -1;\n        /* middle items */\n        for (jndex = 1; jndex < XRDP_MAX_BITMAP_CACHE_IDX - 1; jndex++)\n        {\n            lru = &(self->bitmap_lrus[index][jndex]);\n            lru->next = jndex + 1;\n            lru->prev = jndex - 1;\n        }\n        /* last item */\n        lru = &(self->bitmap_lrus[index][XRDP_MAX_BITMAP_CACHE_IDX - 1]);\n        lru->next = -1;\n        lru->prev = XRDP_MAX_BITMAP_CACHE_IDX - 2;\n\n        self->lru_head[index] = 0;\n        self->lru_tail[index] = XRDP_MAX_BITMAP_CACHE_IDX - 1;\n\n        self->lru_reset[index] = 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_cache_reset_crc(struct xrdp_cache *self)\n{\n    int index;\n    int jndex;\n\n    for (index = 0; index < XRDP_MAX_BITMAP_CACHE_ID; index++)\n    {\n        for (jndex = 0; jndex < 64 * 1024; jndex++)\n        {\n            /* it's ok to deinit a zeroed out struct list16 */\n            list16_deinit(&(self->crc16[index][jndex]));\n            list16_init(&(self->crc16[index][jndex]));\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstruct xrdp_cache *\nxrdp_cache_create(struct xrdp_wm *owner,\n                  struct xrdp_session *session,\n                  struct xrdp_client_info *client_info)\n{\n    struct xrdp_cache *self;\n\n    self = (struct xrdp_cache *)g_malloc(sizeof(struct xrdp_cache), 1);\n    self->wm = owner;\n    self->session = session;\n    self->use_bitmap_comp = client_info->use_bitmap_comp;\n\n    self->cache1_entries = MIN(XRDP_MAX_BITMAP_CACHE_IDX,\n                               client_info->cache1_entries);\n    self->cache1_entries = MAX(self->cache1_entries, 0);\n    self->cache1_size = client_info->cache1_size;\n\n    self->cache2_entries = MIN(XRDP_MAX_BITMAP_CACHE_IDX,\n                               client_info->cache2_entries);\n    self->cache2_entries = MAX(self->cache2_entries, 0);\n    self->cache2_size = client_info->cache2_size;\n\n    self->cache3_entries = MIN(XRDP_MAX_BITMAP_CACHE_IDX,\n                               client_info->cache3_entries);\n    self->cache3_entries = MAX(self->cache3_entries, 0);\n    self->cache3_size = client_info->cache3_size;\n\n    self->bitmap_cache_persist_enable = client_info->bitmap_cache_persist_enable;\n    self->bitmap_cache_version = client_info->bitmap_cache_version;\n    self->pointer_cache_entries = client_info->pointer_cache_entries;\n    self->xrdp_os_del_list = list_create();\n    xrdp_cache_reset_lru(self);\n    xrdp_cache_reset_crc(self);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_cache_create: 0 %d 1 %d 2 %d\",\n              self->cache1_entries, self->cache2_entries, self->cache3_entries);\n    return self;\n}\n\n/*****************************************************************************/\nstatic void\nclear_all_cached_items(struct xrdp_cache *self)\n{\n    int i;\n    int j;\n\n    if (self == 0)\n    {\n        return;\n    }\n\n    /* free all the cached bitmaps */\n    for (i = 0; i < XRDP_MAX_BITMAP_CACHE_ID; i++)\n    {\n        for (j = 0; j < XRDP_MAX_BITMAP_CACHE_IDX; j++)\n        {\n            xrdp_bitmap_delete(self->bitmap_items[i][j].bitmap);\n        }\n    }\n\n    /* free all the cached font items */\n    for (i = 0; i < 12; i++)\n    {\n        for (j = 0; j < 256; j++)\n        {\n            g_free(self->char_items[i][j].font_item.data);\n        }\n    }\n\n    /* free all the off screen bitmaps */\n    for (i = 0; i < 2000; i++)\n    {\n        xrdp_bitmap_delete(self->os_bitmap_items[i].bitmap);\n    }\n\n    list_delete(self->xrdp_os_del_list);\n\n    /* free all crc lists */\n    for (i = 0; i < XRDP_MAX_BITMAP_CACHE_ID; i++)\n    {\n        for (j = 0; j < 64 * 1024; j++)\n        {\n            list16_deinit(&(self->crc16[i][j]));\n        }\n    }\n}\n\n/*****************************************************************************/\nvoid\nxrdp_cache_delete(struct xrdp_cache *self)\n{\n    clear_all_cached_items(self);\n    g_free(self);\n}\n\n/*****************************************************************************/\nint\nxrdp_cache_reset(struct xrdp_cache *self,\n                 struct xrdp_client_info *client_info)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_session *session;\n\n    /* save these */\n    wm = self->wm;\n    session = self->session;\n    /* De-allocate any allocated memory */\n    clear_all_cached_items(self);\n    /* set whole struct to zero */\n    g_memset(self, 0, sizeof(struct xrdp_cache));\n    /* set some stuff back */\n    self->wm = wm;\n    self->session = session;\n    self->use_bitmap_comp = client_info->use_bitmap_comp;\n    self->cache1_entries = client_info->cache1_entries;\n    self->cache1_size = client_info->cache1_size;\n    self->cache2_entries = client_info->cache2_entries;\n    self->cache2_size = client_info->cache2_size;\n    self->cache3_entries = client_info->cache3_entries;\n    self->cache3_size = client_info->cache3_size;\n    self->bitmap_cache_persist_enable = client_info->bitmap_cache_persist_enable;\n    self->bitmap_cache_version = client_info->bitmap_cache_version;\n    self->pointer_cache_entries = client_info->pointer_cache_entries;\n    xrdp_cache_reset_lru(self);\n    xrdp_cache_reset_crc(self);\n    return 0;\n}\n\n#define COMPARE_WITH_CRC32(_b1, _b2) \\\n    ((_b1->crc32 == _b2->crc32) && \\\n     (_b1->bpp == _b2->bpp) && \\\n     (_b1->width == _b2->width) && (_b1->height == _b2->height))\n\n/*****************************************************************************/\nstatic int\nxrdp_cache_update_lru(struct xrdp_cache *self, int cache_id, int lru_index)\n{\n    int tail_index;\n    struct xrdp_lru_item *nextlru;\n    struct xrdp_lru_item *prevlru;\n    struct xrdp_lru_item *thislru;\n    struct xrdp_lru_item *taillru;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_cache_update_lru: lru_index %d\", lru_index);\n    if ((lru_index < 0) || (lru_index >= XRDP_MAX_BITMAP_CACHE_IDX))\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_cache_update_lru: error\");\n        return 1;\n    }\n    if (self->lru_tail[cache_id] == lru_index)\n    {\n        /* nothing to do */\n        return 0;\n    }\n    else if (self->lru_head[cache_id] == lru_index)\n    {\n        /* moving head item to tail */\n\n        thislru = &(self->bitmap_lrus[cache_id][lru_index]);\n        nextlru = &(self->bitmap_lrus[cache_id][thislru->next]);\n        tail_index = self->lru_tail[cache_id];\n        taillru = &(self->bitmap_lrus[cache_id][tail_index]);\n\n        /* unhook old */\n        nextlru->prev = -1;\n\n        /* set head to next */\n        self->lru_head[cache_id] = thislru->next;\n\n        /* move to tail and hook up */\n        taillru->next = lru_index;\n        thislru->prev = tail_index;\n        thislru->next = -1;\n\n        /* update tail */\n        self->lru_tail[cache_id] = lru_index;\n\n    }\n    else\n    {\n        /* move middle item */\n\n        thislru = &(self->bitmap_lrus[cache_id][lru_index]);\n        prevlru = &(self->bitmap_lrus[cache_id][thislru->prev]);\n        nextlru = &(self->bitmap_lrus[cache_id][thislru->next]);\n        tail_index = self->lru_tail[cache_id];\n        taillru = &(self->bitmap_lrus[cache_id][tail_index]);\n\n        /* unhook old */\n        prevlru->next = thislru->next;\n        nextlru->prev = thislru->prev;\n\n        /* move to tail and hook up */\n        taillru->next = lru_index;\n        thislru->prev = tail_index;\n        thislru->next = -1;\n\n        /* update tail */\n        self->lru_tail[cache_id] = lru_index;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns cache id */\nint\nxrdp_cache_add_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap,\n                      int hints)\n{\n    int index;\n    int jndex;\n    int cache_id;\n    int cache_idx;\n    int bmp_size;\n    int e;\n    int Bpp;\n    int crc16;\n    int iig;\n    int found;\n    int cache_entries;\n    int lru_index;\n    struct list16 *ll;\n    struct xrdp_bitmap *lbm;\n    struct xrdp_lru_item *llru;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_cache_add_bitmap:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_cache_add_bitmap: crc16 0x%4.4x\",\n              bitmap->crc16);\n\n    e = (4 - (bitmap->width % 4)) & 3;\n    found = 0;\n    cache_id = 0;\n    cache_entries = 0;\n\n    /* client Bpp, bmp_size */\n    Bpp = (bitmap->bpp + 7) / 8;\n    bmp_size = (bitmap->width + e) * bitmap->height * Bpp;\n    self->bitmap_stamp++;\n\n    if (bmp_size <= self->cache1_size)\n    {\n        cache_id = 0;\n        cache_entries = self->cache1_entries;\n    }\n    else if (bmp_size <= self->cache2_size)\n    {\n        cache_id = 1;\n        cache_entries = self->cache2_entries;\n    }\n    else if (bmp_size <= self->cache3_size)\n    {\n        cache_id = 2;\n        cache_entries = self->cache3_entries;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"error in xrdp_cache_add_bitmap, \"\n            \"too big(%d) bpp %d\", bmp_size, bitmap->bpp);\n        return 0;\n    }\n\n    crc16 = bitmap->crc16;\n    ll = &(self->crc16[cache_id][crc16]);\n    for (jndex = 0; jndex < ll->count; jndex++)\n    {\n        cache_idx = list16_get_item(ll, jndex);\n        lbm = self->bitmap_items[cache_id][cache_idx].bitmap;\n        if ((lbm != NULL) && COMPARE_WITH_CRC32(lbm, bitmap))\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"found bitmap at %d %d\", cache_idx, jndex);\n            found = 1;\n            break;\n        }\n    }\n    if (found)\n    {\n        lru_index = self->bitmap_items[cache_id][cache_idx].lru_index;\n        self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp;\n        xrdp_bitmap_delete(bitmap);\n\n        /* update lru to end */\n        xrdp_cache_update_lru(self, cache_id, lru_index);\n\n        return MAKELONG(cache_idx, cache_id);\n    }\n\n    /* find lru */\n\n    /* check for reset */\n    if (self->lru_reset[cache_id])\n    {\n        self->lru_reset[cache_id] = 0;\n        LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_cache_add_bitmap: reset detected cache_id %d\",\n                  cache_id);\n        self->lru_tail[cache_id] = cache_entries - 1;\n        index = self->lru_tail[cache_id];\n        llru = &(self->bitmap_lrus[cache_id][index]);\n        llru->next = -1;\n    }\n\n    /* lru is item at head */\n    lru_index = self->lru_head[cache_id];\n    cache_idx = lru_index;\n\n    /* update lru to end */\n    xrdp_cache_update_lru(self, cache_id, lru_index);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_cache_add_bitmap: oldest %d %d\", cache_id, cache_idx);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"adding bitmap at %d %d old ptr %p new ptr %p\",\n              cache_id, cache_idx,\n              self->bitmap_items[cache_id][cache_idx].bitmap,\n              bitmap);\n\n    /* remove old, about to be deleted, from crc16 list */\n    lbm = self->bitmap_items[cache_id][cache_idx].bitmap;\n    if (lbm != 0)\n    {\n        crc16 = lbm->crc16;\n        ll = &(self->crc16[cache_id][crc16]);\n        iig = list16_index_of(ll, cache_idx);\n        if (iig == -1)\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_cache_add_bitmap: error removing cache_idx\");\n        }\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_cache_add_bitmap: removing index %d from crc16 %d\",\n                  iig, crc16);\n        list16_remove_item(ll, iig);\n        xrdp_bitmap_delete(lbm);\n    }\n\n    /* set, send bitmap and return */\n\n    self->bitmap_items[cache_id][cache_idx].bitmap = bitmap;\n    self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp;\n    self->bitmap_items[cache_id][cache_idx].lru_index = lru_index;\n\n    /* add to crc16 list */\n    crc16 = bitmap->crc16;\n    ll = &(self->crc16[cache_id][crc16]);\n    list16_add_item(ll, cache_idx);\n    if (ll->count > 1)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_cache_add_bitmap: count %d\", ll->count);\n    }\n\n    if (self->use_bitmap_comp)\n    {\n        if (self->bitmap_cache_version & 4)\n        {\n            if (libxrdp_orders_send_bitmap3(self->session, bitmap->width,\n                                            bitmap->height, bitmap->bpp,\n                                            bitmap->data, cache_id, cache_idx,\n                                            hints) == 0)\n            {\n                return MAKELONG(cache_idx, cache_id);\n            }\n        }\n\n        if (self->bitmap_cache_version & 2)\n        {\n            libxrdp_orders_send_bitmap2(self->session, bitmap->width,\n                                        bitmap->height, bitmap->bpp,\n                                        bitmap->data, cache_id, cache_idx,\n                                        hints);\n        }\n        else if (self->bitmap_cache_version & 1)\n        {\n            libxrdp_orders_send_bitmap(self->session, bitmap->width,\n                                       bitmap->height, bitmap->bpp,\n                                       bitmap->data, cache_id, cache_idx);\n        }\n    }\n    else\n    {\n        if (self->bitmap_cache_version & 2)\n        {\n            libxrdp_orders_send_raw_bitmap2(self->session, bitmap->width,\n                                            bitmap->height, bitmap->bpp,\n                                            bitmap->data, cache_id, cache_idx);\n        }\n        else if (self->bitmap_cache_version & 1)\n        {\n            libxrdp_orders_send_raw_bitmap(self->session, bitmap->width,\n                                           bitmap->height, bitmap->bpp,\n                                           bitmap->data, cache_id, cache_idx);\n        }\n    }\n\n    return MAKELONG(cache_idx, cache_id);\n}\n\n/*****************************************************************************/\n/* not used */\n/* not sure how to use a palette in rdp */\nint\nxrdp_cache_add_palette(struct xrdp_cache *self, int *palette)\n{\n    int i;\n    int oldest;\n    int index;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (palette == 0)\n    {\n        return 0;\n    }\n\n    if (self->wm->screen->bpp > 8)\n    {\n        return 0;\n    }\n\n    self->palette_stamp++;\n\n    /* look for match */\n    for (i = 0; i < 6; i++)\n    {\n        if (g_memcmp(palette, self->palette_items[i].palette,\n                     256 * sizeof(int)) == 0)\n        {\n            self->palette_items[i].stamp = self->palette_stamp;\n            return i;\n        }\n    }\n\n    /* look for oldest */\n    index = 0;\n    oldest = 0x7fffffff;\n\n    for (i = 0; i < 6; i++)\n    {\n        if (self->palette_items[i].stamp < oldest)\n        {\n            oldest = self->palette_items[i].stamp;\n            index = i;\n        }\n    }\n\n    /* set, send palette and return */\n    g_memcpy(self->palette_items[index].palette, palette, 256 * sizeof(int));\n    self->palette_items[index].stamp = self->palette_stamp;\n    libxrdp_orders_send_palette(self->session, palette, index);\n    return index;\n}\n\n/*****************************************************************************/\nint\nxrdp_cache_add_char(struct xrdp_cache *self,\n                    struct xrdp_font_char *font_item)\n{\n    int i;\n    int j;\n    int oldest;\n    int f;\n    int c;\n    int datasize;\n    struct xrdp_font_char *fi;\n\n    self->char_stamp++;\n\n    /* look for match */\n    for (i = 7; i < 12; i++)\n    {\n        for (j = 0; j < 250; j++)\n        {\n            if (xrdp_font_item_compare(&self->char_items[i][j].font_item, font_item))\n            {\n                self->char_items[i][j].stamp = self->char_stamp;\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"found font at %d %d\", i, j);\n                return MAKELONG(j, i);\n            }\n        }\n    }\n\n    /* look for oldest */\n    f = 0;\n    c = 0;\n    oldest = 0x7fffffff;\n\n    for (i = 7; i < 12; i++)\n    {\n        for (j = 0; j < 250; j++)\n        {\n            if (self->char_items[i][j].stamp < oldest)\n            {\n                oldest = self->char_items[i][j].stamp;\n                f = i;\n                c = j;\n            }\n        }\n    }\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"adding char at %d %d\", f, c);\n    /* set, send char and return */\n    fi = &self->char_items[f][c].font_item;\n    g_free(fi->data);\n    datasize = FONT_DATASIZE(font_item);\n    fi->data = (char *)g_malloc(datasize, 1);\n    g_memcpy(fi->data, font_item->data, datasize);\n    fi->offset = font_item->offset;\n    fi->baseline = font_item->baseline;\n    fi->width = font_item->width;\n    fi->height = font_item->height;\n    self->char_items[f][c].stamp = self->char_stamp;\n    libxrdp_orders_send_font(self->session, fi, f, c);\n    return MAKELONG(c, f);\n}\n\n/*****************************************************************************/\n/* added the pointer to the cache and send it to client, it also sets the\n   client if it finds it\n   returns the index in the cache\n   does not take ownership of pointer_item */\nint\nxrdp_cache_add_pointer(struct xrdp_cache *self,\n                       struct xrdp_pointer_item *pointer_item)\n{\n    int i;\n    int oldest;\n    int index;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    self->pointer_stamp++;\n\n    /* look for match */\n    for (i = 2; i < self->pointer_cache_entries; i++)\n    {\n        if (self->pointer_items[i].x == pointer_item->x &&\n                self->pointer_items[i].y == pointer_item->y &&\n                g_memcmp(self->pointer_items[i].data,\n                         pointer_item->data, 96 * 96 * 4) == 0 &&\n                g_memcmp(self->pointer_items[i].mask,\n                         pointer_item->mask, 96 * 96 / 8) == 0 &&\n                self->pointer_items[i].bpp == pointer_item->bpp &&\n                self->pointer_items[i].width == pointer_item->width &&\n                self->pointer_items[i].height == pointer_item->height)\n        {\n            self->pointer_items[i].stamp = self->pointer_stamp;\n            xrdp_wm_set_pointer(self->wm, i);\n            self->wm->current_pointer = i;\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"found pointer at %d\", i);\n            return i;\n        }\n    }\n\n    /* look for oldest */\n    index = 2;\n    oldest = 0x7fffffff;\n\n    for (i = 2; i < self->pointer_cache_entries; i++)\n    {\n        if (self->pointer_items[i].stamp < oldest)\n        {\n            oldest = self->pointer_items[i].stamp;\n            index = i;\n        }\n    }\n\n    self->pointer_items[index].x = pointer_item->x;\n    self->pointer_items[index].y = pointer_item->y;\n    g_memcpy(self->pointer_items[index].data,\n             pointer_item->data, 96 * 96 * 4);\n    g_memcpy(self->pointer_items[index].mask,\n             pointer_item->mask, 96 * 96 / 8);\n    self->pointer_items[index].stamp = self->pointer_stamp;\n    self->pointer_items[index].bpp = pointer_item->bpp;\n    self->pointer_items[index].width = pointer_item->width;\n    self->pointer_items[index].height = pointer_item->height;\n    xrdp_wm_send_pointer(self->wm, index,\n                         self->pointer_items[index].data,\n                         self->pointer_items[index].mask,\n                         self->pointer_items[index].x,\n                         self->pointer_items[index].y,\n                         self->pointer_items[index].bpp,\n                         self->pointer_items[index].width,\n                         self->pointer_items[index].height);\n    self->wm->current_pointer = index;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"adding pointer at %d\", index);\n    return index;\n}\n\n/*****************************************************************************/\n/* this does not take ownership of pointer_item, it makes a copy */\nint\nxrdp_cache_add_pointer_static(struct xrdp_cache *self,\n                              struct xrdp_pointer_item *pointer_item,\n                              int index)\n{\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    self->pointer_items[index].x = pointer_item->x;\n    self->pointer_items[index].y = pointer_item->y;\n    g_memcpy(self->pointer_items[index].data,\n             pointer_item->data, 96 * 96 * 4);\n    g_memcpy(self->pointer_items[index].mask,\n             pointer_item->mask, 96 * 96 / 8);\n    self->pointer_items[index].stamp = self->pointer_stamp;\n    self->pointer_items[index].bpp = pointer_item->bpp;\n    xrdp_wm_send_pointer(self->wm, index,\n                         self->pointer_items[index].data,\n                         self->pointer_items[index].mask,\n                         self->pointer_items[index].x,\n                         self->pointer_items[index].y,\n                         self->pointer_items[index].bpp,\n                         self->pointer_items[index].width,\n                         self->pointer_items[index].height);\n    self->wm->current_pointer = index;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"adding pointer at %d\", index);\n    return index;\n}\n\n/*****************************************************************************/\n/* this does not take ownership of brush_item_data, it makes a copy */\nint\nxrdp_cache_add_brush(struct xrdp_cache *self,\n                     char *brush_item_data)\n{\n    int i;\n    int oldest;\n    int index;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    self->brush_stamp++;\n\n    /* look for match */\n    for (i = 0; i < 64; i++)\n    {\n        if (g_memcmp(self->brush_items[i].pattern,\n                     brush_item_data, 8) == 0)\n        {\n            self->brush_items[i].stamp = self->brush_stamp;\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"found brush at %d\", i);\n            return i;\n        }\n    }\n\n    /* look for oldest */\n    index = 0;\n    oldest = 0x7fffffff;\n\n    for (i = 0; i < 64; i++)\n    {\n        if (self->brush_items[i].stamp < oldest)\n        {\n            oldest = self->brush_items[i].stamp;\n            index = i;\n        }\n    }\n\n    g_memcpy(self->brush_items[index].pattern,\n             brush_item_data, 8);\n    self->brush_items[index].stamp = self->brush_stamp;\n    libxrdp_orders_send_brush(self->session, 8, 8, 1, 0x81, 8,\n                              self->brush_items[index].pattern, index);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"adding brush at %d\", index);\n    return index;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_cache_add_os_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap,\n                         int rdpindex)\n{\n    struct xrdp_os_bitmap_item *bi;\n\n    if ((rdpindex < 0) || (rdpindex >= 2000))\n    {\n        return 1;\n    }\n\n    bi = self->os_bitmap_items + rdpindex;\n    bi->bitmap = bitmap;\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_cache_remove_os_bitmap(struct xrdp_cache *self, int rdpindex)\n{\n    struct xrdp_os_bitmap_item *bi;\n    int index;\n\n    if ((rdpindex < 0) || (rdpindex >= 2000))\n    {\n        return 1;\n    }\n\n    bi = self->os_bitmap_items + rdpindex;\n\n    if (bi->bitmap->tab_stop)\n    {\n        index = list_index_of(self->xrdp_os_del_list, rdpindex);\n\n        if (index == -1)\n        {\n            list_add_item(self->xrdp_os_del_list, rdpindex);\n        }\n    }\n\n    xrdp_bitmap_delete(bi->bitmap);\n    g_memset(bi, 0, sizeof(struct xrdp_os_bitmap_item));\n    return 0;\n}\n\n/*****************************************************************************/\nstruct xrdp_os_bitmap_item *\nxrdp_cache_get_os_bitmap(struct xrdp_cache *self, int rdpindex)\n{\n    struct xrdp_os_bitmap_item *bi;\n\n    if ((rdpindex < 0) || (rdpindex >= 2000))\n    {\n        return 0;\n    }\n\n    bi = self->os_bitmap_items + rdpindex;\n    return bi;\n}\n"
  },
  {
    "path": "xrdp/xrdp_egfx.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2019\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * MS-RDPEGFX\n */\n\n/**\n *\n * @file xrdp_egfx.c\n * @brief Stream functions for the EGFX extension to the MSRDP protocol.\n * @author Jay Sorg, Christopher Pitstick\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"parse.h\"\n#include \"xrdp_egfx.h\"\n#include \"libxrdp.h\"\n#include \"xrdp_channel.h\"\n#include \"xrdp_mm.h\"\n#include <limits.h>\n\n#define MAX_PART_SIZE 0xFFFF\n#define PACKET_COMPR_TYPE_RDP8 0x04 /* MS-RDPEGFX 2.2.5.3 */\n\n/******************************************************************************/\nint\nxrdp_egfx_send_data(struct xrdp_egfx *egfx, const char *data, int bytes)\n{\n    int error;\n    int to_send;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_data:\");\n\n    if (bytes <= 1500)\n    {\n        error = libxrdp_drdynvc_data(egfx->session, egfx->channel_id,\n                                     data, bytes);\n    }\n    else\n    {\n        error = libxrdp_drdynvc_data_first(egfx->session, egfx->channel_id,\n                                           data, 1500, bytes);\n        data += 1500;\n        bytes -= 1500;\n        while ((bytes > 0) && (error == 0))\n        {\n            to_send = bytes;\n            if (to_send > 1500)\n            {\n                to_send = 1500;\n            }\n            error = libxrdp_drdynvc_data(egfx->session, egfx->channel_id,\n                                         data, to_send);\n            data += to_send;\n            bytes -= to_send;\n        }\n    }\n    return error;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_s(struct xrdp_egfx *egfx, struct stream *s)\n{\n    int error;\n    int bytes;\n\n    if (s == NULL)\n    {\n        return 1;\n    }\n    bytes = (int) (s->end - s->data);\n    error = xrdp_egfx_send_data(egfx, s->data, bytes);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_create_surface(struct xrdp_egfx_bulk *bulk, int surface_id,\n                         int width, int height, int pixel_format)\n{\n    int bytes;\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_egfx_create_surface:\");\n    make_stream(s);\n    init_stream(s, 8192);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE0); /* descriptor = SINGLE */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_CREATESURFACE); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    s_push_layer(s, iso_hdr, 4); /* pduLength, set later */\n    out_uint16_le(s, surface_id);\n    out_uint16_le(s, width);\n    out_uint16_le(s, height);\n    out_uint8(s, pixel_format);\n    s_mark_end(s);\n    bytes = (int) ((s->end - s->iso_hdr) + 4);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, bytes);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_create_surface(struct xrdp_egfx *egfx, int surface_id,\n                              int width, int height, int pixel_format)\n{\n    int error;\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_egfx_send_create_surface:\");\n    s = xrdp_egfx_create_surface(egfx->bulk, surface_id, width, height,\n                                 pixel_format);\n    error = xrdp_egfx_send_s(egfx, s);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_create_surface: xrdp_egfx_send_s \"\n              \"error %d\", error);\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_delete_surface(struct xrdp_egfx_bulk *bulk, int surface_id)\n{\n    int bytes;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_delete_surface:\");\n    make_stream(s);\n    init_stream(s, 8192);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE0); /* descriptor = SINGLE */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_DELETESURFACE); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    s_push_layer(s, iso_hdr, 4); /* pduLength, set later */\n    out_uint16_le(s, surface_id);\n    s_mark_end(s);\n    bytes = (int) ((s->end - s->iso_hdr) + 4);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, bytes);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_delete_surface(struct xrdp_egfx *egfx, int surface_id)\n{\n    int error;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_delete_surface:\");\n    s = xrdp_egfx_delete_surface(egfx->bulk, surface_id);\n    error = xrdp_egfx_send_s(egfx, s);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_delete_surface: xrdp_egfx_send_s \"\n              \"error %d\", error);\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_map_surface(struct xrdp_egfx_bulk *bulk, int surface_id,\n                      int x, int y)\n{\n    int bytes;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_map_surface:\");\n    make_stream(s);\n    init_stream(s, 8192);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE0); /* descriptor = SINGLE */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_MAPSURFACETOOUTPUT); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    s_push_layer(s, iso_hdr, 4); /* pduLength, set later */\n    out_uint16_le(s, surface_id);\n    out_uint16_le(s, 0);\n    out_uint32_le(s, x);\n    out_uint32_le(s, y);\n    s_mark_end(s);\n    bytes = (int) ((s->end - s->iso_hdr) + 4);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, bytes);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_map_surface(struct xrdp_egfx *egfx, int surface_id,\n                           int x, int y)\n{\n    int error;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_map_surface:\");\n    s = xrdp_egfx_map_surface(egfx->bulk, surface_id, x, y);\n    error = xrdp_egfx_send_s(egfx, s);\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_map_surface: xrdp_egfx_send_s \"\n        \"error %d\", error);\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_fill_surface(struct xrdp_egfx_bulk *bulk, int surface_id,\n                       int fill_color, int num_rects,\n                       const struct xrdp_egfx_rect *rects)\n{\n    int bytes;\n    int index;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_fill_surface:\");\n    make_stream(s);\n    init_stream(s, 1024 + num_rects * 8);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE0); /* descriptor = SINGLE */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_SOLIDFILL); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    s_push_layer(s, iso_hdr, 4); /* pduLength, set later */\n    out_uint16_le(s, surface_id);\n    out_uint32_le(s, fill_color);\n    out_uint16_le(s, num_rects);\n    for (index = 0; index < num_rects; index++)\n    {\n        out_uint16_le(s, rects[index].x1);\n        out_uint16_le(s, rects[index].y1);\n        out_uint16_le(s, rects[index].x2);\n        out_uint16_le(s, rects[index].y2);\n    }\n    s_mark_end(s);\n    bytes = (int) ((s->end - s->iso_hdr) + 4);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, bytes);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_fill_surface(struct xrdp_egfx *egfx, int surface_id,\n                            int fill_color, int num_rects,\n                            const struct xrdp_egfx_rect *rects)\n{\n    int error;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_fill_surface:\");\n    s = xrdp_egfx_fill_surface(egfx->bulk, surface_id, fill_color,\n                               num_rects, rects);\n    error = xrdp_egfx_send_s(egfx, s);\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_fill_surface: xrdp_egfx_send_s \"\n        \"error %d\", error);\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_surface_to_surface(struct xrdp_egfx_bulk *bulk, int src_surface_id,\n                             int dst_surface_id,\n                             const struct xrdp_egfx_rect *src_rect,\n                             int num_dst_points,\n                             const struct xrdp_egfx_point *dst_points)\n{\n    int bytes;\n    int index;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_surface_to_surface:\");\n    make_stream(s);\n    init_stream(s, 1024 + num_dst_points * 4);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE0); /* descriptor = SINGLE */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_SURFACETOSURFACE); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    s_push_layer(s, iso_hdr, 4); /* pduLength, set later */\n    out_uint16_le(s, src_surface_id);\n    out_uint16_le(s, dst_surface_id);\n    out_uint16_le(s, src_rect->x1);\n    out_uint16_le(s, src_rect->y1);\n    out_uint16_le(s, src_rect->x2);\n    out_uint16_le(s, src_rect->y2);\n    out_uint16_le(s, num_dst_points);\n    for (index = 0; index < num_dst_points; index++)\n    {\n        out_uint16_le(s, dst_points[index].x);\n        out_uint16_le(s, dst_points[index].y);\n    }\n    s_mark_end(s);\n    bytes = (int) ((s->end - s->iso_hdr) + 4);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, bytes);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_surface_to_surface(struct xrdp_egfx *egfx, int src_surface_id,\n                                  int dst_surface_id,\n                                  const struct xrdp_egfx_rect *src_rect,\n                                  int num_dst_points,\n                                  const struct xrdp_egfx_point *dst_points)\n{\n    int error;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_surface_to_surface:\");\n    s = xrdp_egfx_surface_to_surface(egfx->bulk, src_surface_id,\n                                     dst_surface_id, src_rect,\n                                     num_dst_points, dst_points);\n    error = xrdp_egfx_send_s(egfx, s);\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_surface_to_surface: xrdp_egfx_send_s \"\n        \"error %d\", error);\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_frame_start(struct xrdp_egfx_bulk *bulk, int frame_id, int timestamp)\n{\n    int bytes;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_frame_start:\");\n    make_stream(s);\n    init_stream(s, 8192);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE0); /* descriptor = SINGLE */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_STARTFRAME); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    s_push_layer(s, iso_hdr, 4); /* pduLength, set later */\n    out_uint32_le(s, timestamp);\n    out_uint32_le(s, frame_id);\n    s_mark_end(s);\n    bytes = (int) ((s->end - s->iso_hdr) + 4);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, bytes);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_frame_start(struct xrdp_egfx *egfx, int frame_id, int timestamp)\n{\n    int error;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_frame_start:\");\n    s = xrdp_egfx_frame_start(egfx->bulk, frame_id, timestamp);\n    error = xrdp_egfx_send_s(egfx, s);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_frame_start: xrdp_egfx_send_s \"\n            \"error %d\", error);\n    }\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_frame_end(struct xrdp_egfx_bulk *bulk, int frame_id)\n{\n    int bytes;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_frame_end:\");\n    make_stream(s);\n    init_stream(s, 8192);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE0); /* descriptor = SINGLE */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_ENDFRAME); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    s_push_layer(s, iso_hdr, 4); /* pduLength, set later */\n    out_uint32_le(s, frame_id);\n    s_mark_end(s);\n    bytes = (int) ((s->end - s->iso_hdr) + 4);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, bytes);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_frame_end(struct xrdp_egfx *egfx, int frame_id)\n{\n    int error;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_frame_end:\");\n    s = xrdp_egfx_frame_end(egfx->bulk, frame_id);\n    error = xrdp_egfx_send_s(egfx, s);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_frame_end: xrdp_egfx_send_s \"\n            \"error %d\", error);\n    }\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_capsconfirm(struct xrdp_egfx_bulk *bulk, int version, int flags)\n{\n    int bytes;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_capsconfirm:\");\n    make_stream(s);\n    init_stream(s, 8192);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE0); /* descriptor = SINGLE */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_CAPSCONFIRM); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    s_push_layer(s, iso_hdr, 4); /* pduLength, set later */\n    out_uint32_le(s, version); /* version */\n    out_uint32_le(s, 4); /* capsDataLength */\n    out_uint32_le(s, flags);\n    s_mark_end(s);\n    bytes = (int) ((s->end - s->iso_hdr) + 4);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, bytes);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_capsconfirm(struct xrdp_egfx *egfx, int version, int flags)\n{\n    int error;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_capsconfirm:\");\n    s = xrdp_egfx_capsconfirm(egfx->bulk, version, flags);\n    error = xrdp_egfx_send_s(egfx, s);\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_capsconfirm: xrdp_egfx_send_s \"\n        \"error %d\", error);\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_wire_to_surface1(struct xrdp_egfx_bulk *bulk, int surface_id,\n                           int codec_id, int pixel_format,\n                           struct xrdp_egfx_rect *dest_rect,\n                           void *bitmap_data, int bitmap_data_length)\n{\n    int bytes;\n    int index;\n    int segment_size;\n    int segment_count;\n    struct stream *s;\n    char *bitmap_data8;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_wire_to_surface1:\");\n    make_stream(s);\n    bytes = bitmap_data_length + 8192;\n    bytes += 5 * (bitmap_data_length / MAX_PART_SIZE);\n    init_stream(s, bytes);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE1); /* descriptor = MULTIPART */\n    s_push_layer(s, iso_hdr, 2); /* segmentCount, set later */\n    out_uint32_le(s, 25 + bitmap_data_length); /* uncompressedSize */\n    /* RDP_DATA_SEGMENT */\n    out_uint32_le(s, 1 + 25); /* segmentArray size */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_WIRETOSURFACE_1); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    out_uint32_le(s, 25 + bitmap_data_length); /* pduLength */\n    out_uint16_le(s, surface_id);\n    out_uint16_le(s, codec_id);\n    out_uint8(s, pixel_format);\n    out_uint16_le(s, dest_rect->x1);\n    out_uint16_le(s, dest_rect->y1);\n    out_uint16_le(s, dest_rect->x2);\n    out_uint16_le(s, dest_rect->y2);\n    out_uint32_le(s, bitmap_data_length);\n    segment_count = 1;\n    index = 0;\n    bitmap_data8 = (char *) bitmap_data;\n    while (index < bitmap_data_length)\n    {\n        segment_size = bitmap_data_length - index;\n        if (segment_size > MAX_PART_SIZE)\n        {\n            segment_size = MAX_PART_SIZE;\n        }\n        /* RDP_DATA_SEGMENT */\n        out_uint32_le(s, 1 + segment_size); /* segmentArray size */\n        /* RDP8_BULK_ENCODED_DATA */\n        out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n        out_uint8a(s, bitmap_data8 + index, segment_size);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  segment index %d segment_size %d\",\n                  segment_count, segment_size);\n        index += segment_size;\n        segment_count++;\n    }\n    s_mark_end(s);\n    s_pop_layer(s, iso_hdr);\n    out_uint16_le(s, segment_count);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_egfx_wire_to_surface1: segment_count %d\",\n              segment_count);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_wire_to_surface1(struct xrdp_egfx *egfx, int surface_id,\n                                int codec_id, int pixel_format,\n                                struct xrdp_egfx_rect *dest_rect,\n                                void *bitmap_data, int bitmap_data_length)\n{\n    int error;\n    struct stream *s;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_egfx_send_wire_to_surface1:\");\n    s = xrdp_egfx_wire_to_surface1(egfx->bulk, surface_id, codec_id,\n                                   pixel_format, dest_rect,\n                                   bitmap_data, bitmap_data_length);\n    error = xrdp_egfx_send_s(egfx, s);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_wire_to_surface1: xrdp_egfx_send_s \"\n              \"error %d\", error);\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_wire_to_surface2(struct xrdp_egfx_bulk *bulk, int surface_id,\n                           int codec_id, int codec_context_id,\n                           int pixel_format,\n                           void *bitmap_data, int bitmap_data_length)\n{\n    int bytes;\n    int index;\n    int segment_size;\n    int segment_count;\n    struct stream *s;\n    char *bitmap_data8;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_egfx_wire_to_surface2:\");\n    make_stream(s);\n    bytes = bitmap_data_length + 8192;\n    bytes += 5 * (bitmap_data_length / MAX_PART_SIZE);\n    init_stream(s, bytes);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE1); /* descriptor = MULTIPART */\n    s_push_layer(s, iso_hdr, 2); /* segmentCount, set later */\n    out_uint32_le(s, 21 + bitmap_data_length); /* uncompressedSize */\n    /* RDP_DATA_SEGMENT */\n    out_uint32_le(s, 1 + 21); /* segmentArray size */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_WIRETOSURFACE_2); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    out_uint32_le(s, 21 + bitmap_data_length); /* pduLength */\n    out_uint16_le(s, surface_id);\n    out_uint16_le(s, codec_id);\n    out_uint32_le(s, codec_context_id);\n    out_uint8(s, pixel_format);\n    out_uint32_le(s, bitmap_data_length);\n    segment_count = 1;\n    index = 0;\n    bitmap_data8 = (char *) bitmap_data;\n    while (index < bitmap_data_length)\n    {\n        segment_size = bitmap_data_length - index;\n        if (segment_size > MAX_PART_SIZE)\n        {\n            segment_size = MAX_PART_SIZE;\n        }\n        /* RDP_DATA_SEGMENT */\n        out_uint32_le(s, 1 + segment_size); /* segmentArray size */\n        /* RDP8_BULK_ENCODED_DATA */\n        out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n        out_uint8a(s, bitmap_data8 + index, segment_size);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"  segment index %d segment_size %d\",\n                  segment_count, segment_size);\n        index += segment_size;\n        segment_count++;\n    }\n    s_mark_end(s);\n    s_pop_layer(s, iso_hdr);\n    out_uint16_le(s, segment_count);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_egfx_wire_to_surface2: segment_count %d\",\n              segment_count);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_wire_to_surface2(struct xrdp_egfx *egfx, int surface_id,\n                                int codec_id, int codec_context_id,\n                                int pixel_format,\n                                void *bitmap_data, int bitmap_data_length)\n{\n    int error;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_wire_to_surface2:\");\n    s = xrdp_egfx_wire_to_surface2(egfx->bulk, surface_id, codec_id,\n                                   codec_context_id, pixel_format,\n                                   bitmap_data, bitmap_data_length);\n    error = xrdp_egfx_send_s(egfx, s);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_wire_to_surface2: xrdp_egfx_send_s \"\n              \"error %d\", error);\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\nstruct stream *\nxrdp_egfx_reset_graphics(struct xrdp_egfx_bulk *bulk, int width, int height,\n                         int monitor_count, struct monitor_info *mi)\n{\n    int bytes;\n    int index;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_INFO, \"xrdp_egfx_reset_graphics:\");\n    if (monitor_count > 16)\n    {\n        return NULL;\n    }\n    make_stream(s);\n    /* this should always be enough because limited to 16 monitors\n       and message is always 340 bytes */\n    init_stream(s, 8192);\n    /* RDP_SEGMENTED_DATA */\n    out_uint8(s, 0xE0); /* descriptor = SINGLE */\n    /* RDP8_BULK_ENCODED_DATA */\n    out_uint8(s, PACKET_COMPR_TYPE_RDP8); /* header */\n    /* RDPGFX_HEADER */\n    out_uint16_le(s, XR_RDPGFX_CMDID_RESETGRAPHICS); /* cmdId */\n    out_uint16_le(s, 0); /* flags = 0 */\n    out_uint32_le(s, 340); /* pduLength */\n    out_uint32_le(s, width);\n    out_uint32_le(s, height);\n    /*\n        TODO: Fix hack where working around 0 monitors is necessary.\n\n        In cases where multi-mon is not used for XRDP, internally 0 monitors\n        are represented, even though we implicitly have one: The entire session!\n\n        Some Microsoft clients (Mainly the Mac OS one) require that at least\n        one monitor be transmitted for EGFX to function, which is why this\n        change was necessary.\n\n        See https://github.com/neutrinolabs/xrdp/pull/2338#discussion_r944685856\n        https://github.com/neutrinolabs/xrdp/issues/2503\n    */\n    out_uint32_le(s, monitor_count == 0 ? 1 : monitor_count);\n    if (monitor_count == 0)\n    {\n        out_uint32_le(s, 0);\n        out_uint32_le(s, 0);\n        out_uint32_le(s, width - 1);\n        out_uint32_le(s, height - 1);\n        out_uint32_le(s, 1);\n        monitor_count = 1;\n    }\n    else\n    {\n        for (index = 0; index < monitor_count; ++index)\n        {\n            out_uint32_le(s, mi[index].left);\n            out_uint32_le(s, mi[index].top);\n            out_uint32_le(s, mi[index].right);\n            out_uint32_le(s, mi[index].bottom);\n            out_uint32_le(s, mi[index].is_primary);\n            LOG(LOG_LEVEL_INFO, \"xrdp_egfx_reset_graphics: (index %d) \"\n                \"monitor left %d top %d right %d bottom %d is_primary %d\",\n                index, mi[index].left, mi[index].top,\n                mi[index].right, mi[index].bottom,\n                mi[index].is_primary);\n        }\n    }\n    LOG(LOG_LEVEL_INFO, \"xrdp_egfx_reset_graphics: width %d height %d \"\n        \"monitorcount %d\", width, height, monitor_count);\n    if (monitor_count < 16)\n    {\n        bytes = 340 - (20 + (monitor_count * 20));\n        out_uint8s(s, bytes);\n    }\n    s_mark_end(s);\n    return s;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_send_reset_graphics(struct xrdp_egfx *egfx, int width, int height,\n                              int monitor_count, struct monitor_info *mi)\n{\n    int error;\n    struct stream *s;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_send_reset_graphics:\");\n    s = xrdp_egfx_reset_graphics(egfx->bulk, width, height, monitor_count, mi);\n    error = xrdp_egfx_send_s(egfx, s);\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_send_reset_graphics: xrdp_egfx_send_s \"\n        \"error %d\", error);\n    free_stream(s);\n    return error;\n}\n\n/******************************************************************************/\n/* RDPGFX_CMDID_FRAMEACKNOWLEDGE */\nstatic int\nxrdp_egfx_process_frame_ack(struct xrdp_egfx *egfx, struct stream *s)\n{\n    uint32_t queueDepth;\n    uint32_t intframeId;\n    uint32_t totalFramesDecoded;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_process_frame_ack:\");\n    if (!s_check_rem(s, 12))\n    {\n        return 1;\n    }\n    in_uint32_le(s, queueDepth);\n    in_uint32_le(s, intframeId);\n    in_uint32_le(s, totalFramesDecoded);\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_process_frame_ack: queueDepth %d\"\n        \" intframeId %d totalFramesDecoded %d\",\n        queueDepth, intframeId, totalFramesDecoded);\n    if (egfx->frame_ack != NULL)\n    {\n        egfx->frame_ack(egfx->user, queueDepth, intframeId, totalFramesDecoded);\n    }\n    return 0;\n}\n\n/******************************************************************************/\n/* RDPGFX_CMDID_CAPSADVERTISE */\nstatic int\nxrdp_egfx_process_capsadvertise(struct xrdp_egfx *egfx, struct stream *s)\n{\n    int index;\n    int capsSetCount;\n    int caps_count;\n    int version;\n    int capsDataLength;\n    int flags;\n    char *holdp;\n    int *versions;\n    int *flagss;\n    int rv = 0;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_process_capsadvertise:\");\n    if (egfx->caps_advertise == NULL)\n    {\n        return 0;\n    }\n    in_uint16_le(s, capsSetCount);\n    if ((capsSetCount < 1) || (capsSetCount > 1024))\n    {\n        return 1;\n    }\n    caps_count = 0;\n    versions = g_new(int, capsSetCount);\n    flagss = g_new(int, capsSetCount);\n    if (versions == NULL || flagss == NULL)\n    {\n        rv = 1;\n    }\n    else\n    {\n        for (index = 0; index < capsSetCount; index++)\n        {\n            if (!s_check_rem(s, 8))\n            {\n                rv = 1;\n                break;\n            }\n            in_uint32_le(s, version);\n            in_uint32_le(s, capsDataLength);\n            if (!s_check_rem(s, capsDataLength))\n            {\n                rv = 1;\n                break;\n            }\n            holdp = s->p;\n            // This implicity excludes caps version 101.\n            if (capsDataLength == 4)\n            {\n                in_uint32_le(s, flags);\n                versions[caps_count] = version;\n                flagss[caps_count] = flags;\n                caps_count++;\n            }\n            s->p = holdp + capsDataLength;\n        }\n    }\n    if (rv == 0 && caps_count > 0)\n    {\n        egfx->caps_advertise(egfx->user, caps_count, versions, flagss);\n    }\n    g_free(versions);\n    g_free(flagss);\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nxrdp_egfx_process(struct xrdp_egfx *egfx, struct stream *s)\n{\n    int error;\n    int cmdId;\n    int flags;\n    int pduLength;\n    char *holdp;\n    char *holdend;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_process:\");\n    error = 0;\n    while (s_check_rem(s, 8))\n    {\n        holdp = s->p;\n        holdend = s->end;\n        in_uint16_le(s, cmdId);\n        in_uint16_le(s, flags);\n        in_uint32_le(s, pduLength);\n        s->end = holdp + pduLength;\n        LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_process: cmdId 0x%x flags %d\"\n            \" pduLength %d\", cmdId, flags, pduLength);\n        if (pduLength < 8)\n        {\n            return 1;\n        }\n        if (!s_check_rem(s, pduLength - 8))\n        {\n            return 1;\n        }\n        switch (cmdId)\n        {\n            case XR_RDPGFX_CMDID_FRAMEACKNOWLEDGE:\n                error = xrdp_egfx_process_frame_ack(egfx, s);\n                break;\n            case XR_RDPGFX_CMDID_CAPSADVERTISE:\n                error = xrdp_egfx_process_capsadvertise(egfx, s);\n                break;\n            case XR_RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE:\n                break;\n            /*\n               TODO: Handle Cache Import PDU here.\n               https://github.com/neutrinolabs/xrdp/issues/2502\n               case XR_RDPGFX_CMDID_CACHEIMPORTOFFER:\n               2.2.2.16 RDPGFX_CACHE_IMPORT_OFFER_PDU\n               Reply with\n               2.2.2.17 RDPGFX_CACHE_IMPORT_REPLY_PDU\n            */\n            default:\n                LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_process:\"\n                    \" unknown cmdId 0x%x\", cmdId);\n                break;\n        }\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_process: error %d\", error);\n            return error;\n        }\n        s->p = holdp + pduLength;\n        s->end = holdend;\n    }\n    return error;\n}\n\n/******************************************************************************/\n/* from client */\nstatic int\nxrdp_egfx_open_response(struct xrdp_process *id, int chan_id,\n                        int creation_status)\n{\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_open_response:\");\n    return 0;\n}\n\n/******************************************************************************/\n/* from client */\nstatic int\nxrdp_egfx_close_response(struct xrdp_process *id, int chan_id)\n{\n    struct xrdp_mm *mm;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_close_response:\");\n\n    mm = id->wm->mm;\n\n    if (mm->resize_queue == 0 || mm->resize_queue->count <= 0)\n    {\n        return 0;\n    }\n    if (mm->resize_data != NULL\n            && mm->resize_data->state == WMRZ_EGFX_CONN_CLOSING)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_close_response: egfx deleted.\");\n        advance_resize_state_machine(mm, WMRZ_EGFX_CONN_CLOSED);\n    }\n    return 0;\n}\n\n/******************************************************************************/\n/* from client */\nstatic int\nxrdp_egfx_data_first(struct xrdp_process *id, int chan_id,\n                     char *data, int bytes, int total_bytes)\n{\n    struct xrdp_egfx *egfx;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_data_first: bytes %d\"\n        \" total_bytes %d\", bytes, total_bytes);\n    egfx = id->wm->mm->egfx;\n    if (egfx->s != NULL)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_data_first: Error!\"\n            \" Stream is not working on initial data received!\");\n    }\n    make_stream(egfx->s);\n    init_stream(egfx->s, total_bytes);\n    out_uint8a(egfx->s, data, bytes);\n    return 0;\n}\n\n/******************************************************************************/\n/* from client */\nstatic int\nxrdp_egfx_data(struct xrdp_process *id, int chan_id, char *data, int bytes)\n{\n    int error;\n    struct stream ls;\n    struct xrdp_wm *wm;\n    struct xrdp_mm *mm;\n    struct xrdp_egfx *egfx;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_data:\");\n\n    if (id == NULL)\n    {\n        return 0;\n    }\n\n    wm = id->wm;\n    if (wm == NULL)\n    {\n        return 0;\n    }\n\n    mm = wm->mm;\n    if (mm == NULL)\n    {\n        return 0;\n    }\n\n    egfx = mm->egfx;\n    if (egfx == NULL)\n    {\n        return 0;\n    }\n\n    if (egfx->s == NULL)\n    {\n        g_memset(&ls, 0, sizeof(ls));\n        ls.data = data;\n        ls.size = bytes;\n        ls.p = data;\n        ls.end = data + bytes;\n        return xrdp_egfx_process(egfx, &ls);\n    }\n    if (!s_check_rem_out(egfx->s, bytes))\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_data: error\");\n        return 1;\n    }\n    out_uint8a(egfx->s, data, bytes);\n    if (!s_check_rem_out(egfx->s, 1))\n    {\n        s_mark_end(egfx->s);\n        egfx->s->p = egfx->s->data;\n        error = xrdp_egfx_process(egfx, egfx->s);\n        free_stream(egfx->s);\n        egfx->s = NULL;\n        return error;\n    }\n    return 0;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_create(struct xrdp_mm *mm, struct xrdp_egfx **egfx)\n{\n    int error;\n    struct xrdp_drdynvc_procs procs;\n    struct xrdp_egfx *self;\n    struct xrdp_process *process;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_create:\");\n\n    self = g_new0(struct xrdp_egfx, 1);\n    if (self == NULL)\n    {\n        return 1;\n    }\n    procs.open_response = xrdp_egfx_open_response;\n    procs.close_response = xrdp_egfx_close_response;\n    procs.data_first = xrdp_egfx_data_first;\n    procs.data = xrdp_egfx_data;\n    process = mm->wm->pro_layer;\n    error = libxrdp_drdynvc_open(process->session,\n                                 \"Microsoft::Windows::RDS::Graphics\",\n                                 1, /* WTS_CHANNEL_OPTION_DYNAMIC */\n                                 &procs, &(self->channel_id));\n    LOG(LOG_LEVEL_INFO, \"xrdp_egfx_create: error %d channel_id %d\",\n        error, self->channel_id);\n    self->session = process->session;\n    self->surface_id = 0;\n    *egfx = self;\n    return 0;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_shutdown_delete_surface(struct xrdp_egfx *egfx)\n{\n    int error;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_shutdown_delete_surface:\");\n\n    if (egfx == 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_shutdown_delete_surface:\"\n            \" EGFX is already null!\");\n        return 0;\n    }\n\n    error = xrdp_egfx_send_delete_surface(egfx, egfx->surface_id);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_shutdown_delete_surface:\"\n            \" xrdp_egfx_send_delete_surface failed %d\", error);\n    }\n    return error;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_shutdown_close_connection(struct xrdp_egfx *egfx)\n{\n    int error;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_shutdown_close_connection:\");\n\n    if (egfx == 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_shutdown_close_connection:\"\n            \" EGFX is already null!\");\n        return 0;\n    }\n\n    error = libxrdp_drdynvc_close(egfx->session, egfx->channel_id);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_shutdown_close_connection:\"\n            \" libxrdp_drdynvc_close failed %d\", error);\n        return error;\n    }\n\n    // Ignore any messages we haven't processed yet\n    egfx->caps_advertise = NULL;\n    egfx->frame_ack = NULL;\n\n    return error;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_shutdown_delete(struct xrdp_egfx *egfx)\n{\n    int error = 0;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_delete:\");\n\n    if (egfx == 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_delete: EGFX is already null!\");\n        return 0;\n    }\n\n    g_free(egfx);\n\n    return error;\n}\n\n/******************************************************************************/\nint\nxrdp_egfx_shutdown_full(struct xrdp_egfx *egfx)\n{\n    int error;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_egfx_shutdown_full:\");\n\n    if (egfx == 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_shutdown_full: EGFX is already null!\");\n        return 0;\n    }\n\n    error = xrdp_egfx_shutdown_delete_surface(egfx);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_shutdown_full:\"\n            \" xrdp_egfx_shutdown_delete_surface failed %d\", error);\n        return error;\n    }\n\n    error = xrdp_egfx_shutdown_close_connection(egfx);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_shutdown_full:\"\n            \" xrdp_egfx_shutdown_close_connection failed %d\", error);\n        return error;\n    }\n\n    error = xrdp_egfx_shutdown_delete(egfx);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_egfx_shutdown_full:\"\n            \" xrdp_egfx_shutdown_delete failed %d\", error);\n        return error;\n    }\n\n    return error;\n}\n"
  },
  {
    "path": "xrdp/xrdp_egfx.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2019\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * MS-RDPEGFX\n */\n\n/**\n *\n * @file xrdp_egfx.h\n * @brief Stream function headers for the EGFX extension to the MSRDP protocol.\n * @author Jay Sorg, Christopher Pitstick\n *\n */\n\n#ifndef _XRDP_EGFX_H\n#define _XRDP_EGFX_H\n\n#include \"xrdp.h\"\n\n#define XR_RDPGFX_CAPVERSION_8      0x00080004\n#define XR_RDPGFX_CAPVERSION_81     0x00080105\n#define XR_RDPGFX_CAPVERSION_10     0x000A0002\n#define XR_RDPGFX_CAPVERSION_101    0x000A0100\n#define XR_RDPGFX_CAPVERSION_102    0x000A0200\n#define XR_RDPGFX_CAPVERSION_103    0x000A0301\n#define XR_RDPGFX_CAPVERSION_104    0x000A0400\n#define XR_RDPGFX_CAPVERSION_105    0x000A0502\n#define XR_RDPGFX_CAPVERSION_106    0x000A0600\n#define XR_RDPGFX_CAPVERSION_107    0x000A0701\n\n#define XR_PIXEL_FORMAT_XRGB_8888   0x20\n#define XR_PIXEL_FORMAT_ARGB_8888   0x21\n\n#define XR_RDPGFX_CAPS_FLAG_THINCLIENT      0x00000001\n#define XR_RDPGFX_CAPS_FLAG_SMALL_CACHE     0x00000002\n#define XR_RDPGFX_CAPS_FLAG_AVC420_ENABLED  0x00000010\n#define XR_RDPGFX_CAPS_FLAG_AVC_DISABLED    0x00000020\n#define XR_RDPGFX_CAPS_FLAG_AVC_THINCLIENT  0x00000040\n\n#define XR_RDPGFX_CMDID_WIRETOSURFACE_1             0x0001\n#define XR_RDPGFX_CMDID_WIRETOSURFACE_2             0x0002\n#define XR_RDPGFX_CMDID_DELETEENCODINGCONTEXT       0x0003\n#define XR_RDPGFX_CMDID_SOLIDFILL                   0x0004\n#define XR_RDPGFX_CMDID_SURFACETOSURFACE            0x0005\n#define XR_RDPGFX_CMDID_SURFACETOCACHE              0x0006\n#define XR_RDPGFX_CMDID_CACHETOSURFACE              0x0007\n#define XR_RDPGFX_CMDID_EVICTCACHEENTRY             0x0008\n#define XR_RDPGFX_CMDID_CREATESURFACE               0x0009\n#define XR_RDPGFX_CMDID_DELETESURFACE               0x000A\n#define XR_RDPGFX_CMDID_STARTFRAME                  0x000B\n#define XR_RDPGFX_CMDID_ENDFRAME                    0x000C\n#define XR_RDPGFX_CMDID_FRAMEACKNOWLEDGE            0x000D\n#define XR_RDPGFX_CMDID_RESETGRAPHICS               0x000E\n#define XR_RDPGFX_CMDID_MAPSURFACETOOUTPUT          0x000F\n#define XR_RDPGFX_CMDID_CACHEIMPORTOFFER            0x0010\n#define XR_RDPGFX_CMDID_CACHEIMPORTREPLY            0x0011\n#define XR_RDPGFX_CMDID_CAPSADVERTISE               0x0012\n#define XR_RDPGFX_CMDID_CAPSCONFIRM                 0x0013\n#define XR_RDPGFX_CMDID_MAPSURFACETOWINDOW          0x0015\n#define XR_RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE         0x0016\n#define XR_RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT    0x0017\n#define XR_RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW    0x0018\n\n#define XR_QUEUE_DEPTH_UNAVAILABLE          0x00000000\n#define XR_SUSPEND_FRAME_ACKNOWLEDGEMENT    0xFFFFFFFF\n\n/* The bitmap data encapsulated in the bitmapData field is uncompressed.\n   Pixels in the uncompressed data are ordered from left to right and then\n   top to bottom. */\n#define XR_RDPGFX_CODECID_UNCOMPRESSED      0x0000\n/* The bitmap data encapsulated in the bitmapData field is compressed using\n   the RemoteFX Codec ([MS-RDPRFX] sections 2.2.1 and 3.1.8). Note that the\n   TS_RFX_RECT ([MS-RDPRFX] section 2.2.2.1.6) structures encapsulated in\n   the bitmapData field MUST all be relative to the top-left corner of the\n   rectangle defined by the destRect field. */\n#define XR_RDPGFX_CODECID_CAVIDEO           0x0003\n/* The bitmap data encapsulated in the bitmapData field is compressed using\n   the ClearCodec Codec (sections 2.2.4.1 and 3.3.8.1). */\n#define XR_RDPGFX_CODECID_CLEARCODEC        0x0008\n/* The bitmap data encapsulated in the bitmapData field is compressed using\n   the Planar Codec ([MS-RDPEGDI] sections 2.2.2.5.1 and 3.1.9). */\n#define XR_RDPGFX_CODECID_PLANAR            0x000A\n/* The bitmap data encapsulated in the bitmapData field is compressed using\n   the MPEG-4 AVC/H.264 Codec in YUV420p mode (section 2.2.4.4). */\n#define XR_RDPGFX_CODECID_AVC420            0x000B\n/* The bitmap data encapsulated in the bitmapData field is compressed using\n   the Alpha Codec (section 2.2.4.3). */\n#define XR_RDPGFX_CODECID_ALPHA             0x000C\n/* The bitmap data encapsulated in the bitmapData field is compressed using\n   the MPEG-4 AVC/H.264 Codec in YUV444 mode (section 2.2.4.5). */\n#define XR_RDPGFX_CODECID_AVC444            0x000E\n/* The bitmap data encapsulated in the bitmapData field is compressed using\n   the MPEG-4 AVC/H.264 Codec in YUV444v2 mode (section 2.2.4.6). */\n#define XR_RDPGFX_CODECID_AVC444V2          0x000F\n\nstruct xrdp_egfx_rect\n{\n    short x1;\n    short y1;\n    short x2;\n    short y2;\n};\n\nstruct xrdp_egfx_point\n{\n    short x;\n    short y;\n};\n\nstruct xrdp_egfx\n{\n    struct xrdp_session *session;\n    int channel_id;\n    int surface_id;\n    int frame_id;\n    struct stream *s;\n    void *user;\n    struct xrdp_egfx_bulk *bulk;\n    int (*caps_advertise)(void *user, int num_caps, int *version, int *flags);\n    int (*frame_ack)(void *user, uint32_t queue_depth,\n                     int frame_id, int frames_decoded);\n};\n\nstruct xrdp_egfx_bulk\n{\n    int id;\n};\n\nint\nxrdp_egfx_send_data(struct xrdp_egfx *egfx, const char *data, int bytes);\nint\nxrdp_egfx_send_s(struct xrdp_egfx *egfx, struct stream *s);\nint\nxrdp_egfx_create(struct xrdp_mm *mm, struct xrdp_egfx **egfx);\nint\nxrdp_egfx_shutdown_delete_surface(struct xrdp_egfx *egfx);\nint\nxrdp_egfx_shutdown_close_connection(struct xrdp_egfx *egfx);\nint\nxrdp_egfx_shutdown_delete(struct xrdp_egfx *egfx);\nint\nxrdp_egfx_shutdown_full(struct xrdp_egfx *egfx);\nstruct stream *\nxrdp_egfx_create_surface(struct xrdp_egfx_bulk *bulk, int surface_id,\n                         int width, int height, int pixel_format);\nint\nxrdp_egfx_send_create_surface(struct xrdp_egfx *egfx, int surface_id,\n                              int width, int height, int pixel_format);\nstruct stream *\nxrdp_egfx_delete_surface(struct xrdp_egfx_bulk *bulk, int surface_id);\nint\nxrdp_egfx_send_delete_surface(struct xrdp_egfx *egfx, int surface_id);\nstruct stream *\nxrdp_egfx_map_surface(struct xrdp_egfx_bulk *bulk, int surface_id,\n                      int x, int y);\nint\nxrdp_egfx_send_map_surface(struct xrdp_egfx *egfx, int surface_id,\n                           int x, int y);\nstruct stream *\nxrdp_egfx_fill_surface(struct xrdp_egfx_bulk *bulk, int surface_id,\n                       int fill_color, int num_rects,\n                       const struct xrdp_egfx_rect *rects);\nint\nxrdp_egfx_send_fill_surface(struct xrdp_egfx *egfx, int surface_id,\n                            int fill_color, int num_rects,\n                            const struct xrdp_egfx_rect *rects);\nstruct stream *\nxrdp_egfx_surface_to_surface(struct xrdp_egfx_bulk *bulk, int src_surface_id,\n                             int dst_surface_id,\n                             const struct xrdp_egfx_rect *src_rect,\n                             int num_dst_points,\n                             const struct xrdp_egfx_point *dst_points);\nint\nxrdp_egfx_send_surface_to_surface(struct xrdp_egfx *egfx, int src_surface_id,\n                                  int dst_surface_id,\n                                  const struct xrdp_egfx_rect *src_rect,\n                                  int num_dst_points,\n                                  const struct xrdp_egfx_point *dst_points);\nstruct stream *\nxrdp_egfx_frame_start(struct xrdp_egfx_bulk *bulk, int frame_id, int timestamp);\nint\nxrdp_egfx_send_frame_start(struct xrdp_egfx *egfx, int frame_id, int timestamp);\nstruct stream *\nxrdp_egfx_frame_end(struct xrdp_egfx_bulk *bulk, int frame_id);\nint\nxrdp_egfx_send_frame_end(struct xrdp_egfx *egfx, int frame_id);\nstruct stream *\nxrdp_egfx_capsconfirm(struct xrdp_egfx_bulk *bulk, int version, int flags);\nint\nxrdp_egfx_send_capsconfirm(struct xrdp_egfx *egfx, int version, int flags);\nstruct stream *\nxrdp_egfx_wire_to_surface1(struct xrdp_egfx_bulk *bulk, int surface_id,\n                           int codec_id, int pixel_format,\n                           struct xrdp_egfx_rect *dest_rect,\n                           void *bitmap_data, int bitmap_data_length);\nint\nxrdp_egfx_send_wire_to_surface1(struct xrdp_egfx *egfx, int surface_id,\n                                int codec_id, int pixel_format,\n                                struct xrdp_egfx_rect *dest_rect,\n                                void *bitmap_data, int bitmap_data_length);\nstruct stream *\nxrdp_egfx_wire_to_surface2(struct xrdp_egfx_bulk *bulk, int surface_id,\n                           int codec_id, int codec_context_id,\n                           int pixel_format,\n                           void *bitmap_data, int bitmap_data_length);\nint\nxrdp_egfx_send_wire_to_surface2(struct xrdp_egfx *egfx, int surface_id,\n                                int codec_id, int codec_context_id,\n                                int pixel_format,\n                                void *bitmap_data, int bitmap_data_length);\n/*\n * NB: mi below must be such that the (top,left) co-ordinate of\n * the primary monitor is (0.0)\n */\nstruct stream *\nxrdp_egfx_reset_graphics(struct xrdp_egfx_bulk *bulk, int width, int height,\n                         int monitor_count, struct monitor_info *mi);\nint\nxrdp_egfx_send_reset_graphics(struct xrdp_egfx *egfx, int width, int height,\n                              int monitor_count, struct monitor_info *mi);\n\n#endif\n"
  },
  {
    "path": "xrdp/xrdp_encoder.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Encoder\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp_encoder.h\"\n#include \"xrdp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"thread_calls.h\"\n#include \"fifo.h\"\n#include \"xrdp_egfx.h\"\n#include \"string_calls.h\"\n\n#ifdef XRDP_RFXCODEC\n#include \"rfxcodec_encode.h\"\n#endif\n\n#ifdef XRDP_X264\n#include \"xrdp_encoder_x264.h\"\n#endif\n\n#ifdef XRDP_OPENH264\n#include \"xrdp_encoder_openh264.h\"\n#endif\n\n#define DEFAULT_XRDP_GFX_FRAMES_IN_FLIGHT 2\n/* limits used for validate env var XRDP_GFX_FRAMES_IN_FLIGHT */\n#define MIN_XRDP_GFX_FRAMES_IN_FLIGHT 1\n#define MAX_XRDP_GFX_FRAMES_IN_FLIGHT 16\n\n#define DEFAULT_XRDP_GFX_MAX_COMPRESSED_BYTES (3 * 1024 * 1024)\n/* limits used for validate env var XRDP_GFX_MAX_COMPRESSED_BYTES */\n#define MIN_XRDP_GFX_MAX_COMPRESSED_BYTES (64 * 1024)\n#define MAX_XRDP_GFX_MAX_COMPRESSED_BYTES (256 * 1024 * 1024)\n\n#define XRDP_SURCMD_PREFIX_BYTES 256\n#define OUT_DATA_BYTES_DEFAULT_SIZE (16 * 1024 * 1024)\n\n#ifdef XRDP_RFXCODEC\n/*\n * LH3 LL3, HH3 HL3, HL2 LH2, LH1 HH2, HH1 HL1\n * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdprfx/3e9c8af4-7539-4c9d-95de-14b1558b902c\n */\n\n/* standard quality */\nstatic const unsigned char g_rfx_quantization_values_std[] =\n{\n    0x66, 0x66, 0x77, 0x87, 0x98,\n    0x76, 0x77, 0x88, 0x98, 0x99\n};\n\n/* low quality */\nstatic const unsigned char g_rfx_quantization_values_lq[] =\n{\n    0x66, 0x66, 0x77, 0x87, 0x98,\n    0xAA, 0xAA, 0xAA, 0xAA, 0xAA /* TODO: tentative value */\n};\n\n/* ultra low quality */\nstatic const unsigned char g_rfx_quantization_values_ulq[] =\n{\n    0x66, 0x66, 0x77, 0x87, 0x98,\n    0xBB, 0xBB, 0xBB, 0xBB, 0xBB /* TODO: tentative value */\n};\n#endif\n\nstruct enc_rect\n{\n    short x1;\n    short y1;\n    short x2;\n    short y2;\n};\n\n/*****************************************************************************/\nstatic int\nprocess_enc_jpg(struct xrdp_encoder *self, XRDP_ENC_DATA *enc);\n#ifdef XRDP_RFXCODEC\nstatic int\nprocess_enc_rfx(struct xrdp_encoder *self, XRDP_ENC_DATA *enc);\n#endif\n#if defined(XRDP_X264) || defined(XRDP_OPENH264)\nstatic int\nprocess_enc_h264(struct xrdp_encoder *self, XRDP_ENC_DATA *enc);\n#endif\nstatic int\nprocess_enc_egfx(struct xrdp_encoder *self, XRDP_ENC_DATA *enc);\n\n/*****************************************************************************/\n/* Item destructor for self->fifo_to_proc */\nstatic void\nxrdp_enc_data_destructor(void *item, void *closure)\n{\n    XRDP_ENC_DATA *enc = (XRDP_ENC_DATA *)item;\n    if (ENC_IS_BIT_SET(enc->flags, ENC_FLAGS_GFX_BIT))\n    {\n        g_free(enc->u.gfx.cmd);\n    }\n    else\n    {\n        g_free(enc->u.sc.drects);\n        g_free(enc->u.sc.crects);\n    }\n    g_free(enc);\n}\n\n/* Item destructor for self->fifo_processed */\nstatic void\nxrdp_enc_data_done_destructor(void *item, void *closure)\n{\n    XRDP_ENC_DATA_DONE *enc_done = (XRDP_ENC_DATA_DONE *)item;\n    g_free(enc_done->comp_pad_data);\n    g_free(enc_done);\n}\n\n/*****************************************************************************/\n/**\n * Sets the methods used by the software H.264 module\n */\nstatic void\nset_h264_encoder_methods(struct xrdp_encoder *self)\n{\n    const char *encoder_name = NULL;\n#if defined(XRDP_X264) && defined(XRDP_OPENH264)\n    struct xrdp_tconfig_gfx gfxconfig;\n    tconfig_load_gfx(GFX_CONF, &gfxconfig);\n\n    switch (gfxconfig.h264_encoder)\n    {\n        case XTC_H264_OPENH264:\n            encoder_name = \"OpenH264\";\n            self->xrdp_encoder_h264_create = xrdp_encoder_openh264_create;\n            self->xrdp_encoder_h264_delete = xrdp_encoder_openh264_delete;\n            self->xrdp_encoder_h264_encode = xrdp_encoder_openh264_encode;\n            break;\n        case XTC_H264_X264:\n        default:\n            /* x264 is the default H.264 software encoder */\n            encoder_name = \"x264\";\n            self->xrdp_encoder_h264_create = xrdp_encoder_x264_create;\n            self->xrdp_encoder_h264_delete = xrdp_encoder_x264_delete;\n            self->xrdp_encoder_h264_encode = xrdp_encoder_x264_encode;\n            break;\n    }\n#elif defined(XRDP_OPENH264)\n    encoder_name = \"OpenH264\";\n    self->xrdp_encoder_h264_create = xrdp_encoder_openh264_create;\n    self->xrdp_encoder_h264_delete = xrdp_encoder_openh264_delete;\n    self->xrdp_encoder_h264_encode = xrdp_encoder_openh264_encode;\n#elif defined(XRDP_X264)\n    encoder_name = \"x264\";\n    self->xrdp_encoder_h264_create = xrdp_encoder_x264_create;\n    self->xrdp_encoder_h264_delete = xrdp_encoder_x264_delete;\n    self->xrdp_encoder_h264_encode = xrdp_encoder_x264_encode;\n#endif\n\n    // Don't log the library we're going to use if we\n    // couldn't load it.\n    if (encoder_name != NULL && self->mm->libh264_loaded)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_encoder_create: using %s for \"\n            \"software encoder\", encoder_name);\n    }\n}\n\n/*****************************************************************************/\nstruct xrdp_encoder *\nxrdp_encoder_create(struct xrdp_mm *mm)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_encoder_create:\");\n\n    struct xrdp_encoder *self;\n    struct xrdp_client_info *client_info;\n    char buf[1024];\n    int pid;\n\n    client_info = mm->wm->client_info;\n\n    /* RemoteFX 7.1 requires LAN but GFX does not */\n    if (client_info->mcs_connection_type != CONNECTION_TYPE_LAN)\n    {\n        if ((mm->egfx_flags & (XRDP_EGFX_H264 | XRDP_EGFX_RFX_PRO)) == 0)\n        {\n            return 0;\n        }\n    }\n    if (client_info->bpp < 24)\n    {\n        return 0;\n    }\n\n    self = g_new0(struct xrdp_encoder, 1);\n    if (self == NULL)\n    {\n        return NULL;\n    }\n    self->mm = mm;\n    self->process_enc = process_enc_egfx;\n    if (client_info->jpeg_codec_id != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_encoder_create: starting jpeg codec session\");\n        self->codec_id = client_info->jpeg_codec_id;\n        self->in_codec_mode = 1;\n        self->codec_quality = client_info->jpeg_prop[0];\n        client_info->capture_code = CC_SIMPLE;\n        client_info->capture_format = XRDP_a8b8g8r8;\n        self->process_enc = process_enc_jpg;\n    }\n#if defined(XRDP_X264) || defined(XRDP_OPENH264)\n    else if (mm->libh264_loaded && (mm->egfx_flags & XRDP_EGFX_H264) != 0)\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"xrdp_encoder_create: starting h264 codec session gfx\");\n        self->in_codec_mode = 1;\n        client_info->capture_code = CC_GFX_A2;\n        client_info->capture_format = XRDP_nv12_709fr;\n        self->gfx = 1;\n    }\n    else if (mm->libh264_loaded && client_info->h264_codec_id != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_encoder_create: starting h264 codec session\");\n        self->codec_id = client_info->h264_codec_id;\n        self->in_codec_mode = 1;\n        client_info->capture_code = CC_SUF_A2;\n        client_info->capture_format = XRDP_nv12;\n        self->process_enc = process_enc_h264;\n    }\n#endif\n#ifdef XRDP_RFXCODEC\n    else if (mm->egfx_flags & XRDP_EGFX_RFX_PRO)\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"xrdp_encoder_create: starting gfx rfx pro codec session\");\n        self->in_codec_mode = 1;\n        client_info->capture_code = CC_GFX_PRO;\n        self->gfx = 1;\n        self->num_quants = 2;\n        self->quant_idx_y = 0;\n        self->quant_idx_u = 1;\n        self->quant_idx_v = 1;\n\n        switch (client_info->mcs_connection_type)\n        {\n            case CONNECTION_TYPE_MODEM:\n            case CONNECTION_TYPE_BROADBAND_LOW:\n            case CONNECTION_TYPE_SATELLITE:\n                self->quants = (const char *) g_rfx_quantization_values_ulq;\n                break;\n            case CONNECTION_TYPE_BROADBAND_HIGH:\n            case CONNECTION_TYPE_WAN:\n                self->quants = (const char *) g_rfx_quantization_values_lq;\n                break;\n            case CONNECTION_TYPE_LAN:\n            case CONNECTION_TYPE_AUTODETECT: /* not implemented yet */\n            default:\n                self->quants = (const char *) g_rfx_quantization_values_std;\n\n        }\n    }\n    else if (client_info->rfx_codec_id != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_encoder_create: starting rfx codec session\");\n        self->codec_id = client_info->rfx_codec_id;\n        self->in_codec_mode = 1;\n        client_info->capture_code = CC_SUF_RFX;\n        self->process_enc = process_enc_rfx;\n        self->codec_handle_rfx = rfxcodec_encode_create(mm->wm->screen->width,\n                                 mm->wm->screen->height,\n                                 RFX_FORMAT_YUV, 0);\n    }\n#endif\n    else\n    {\n        g_free(self);\n        return 0;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_INFO,\n              \"init_xrdp_encoder: initializing encoder codec_id %d\",\n              self->codec_id);\n\n    /* setup required FIFOs */\n    self->fifo_to_proc = fifo_create(xrdp_enc_data_destructor);\n    self->fifo_processed = fifo_create(xrdp_enc_data_done_destructor);\n    self->mutex = tc_mutex_create();\n\n    pid = g_getpid();\n    /* setup wait objects for signalling */\n    g_snprintf(buf, 1024, \"xrdp_%8.8x_encoder_event_to_proc\", pid);\n    self->xrdp_encoder_event_to_proc = g_create_wait_obj(buf);\n    g_snprintf(buf, 1024, \"xrdp_%8.8x_encoder_event_processed\", pid);\n    self->xrdp_encoder_event_processed = g_create_wait_obj(buf);\n    g_snprintf(buf, 1024, \"xrdp_%8.8x_encoder_term\", pid);\n    self->xrdp_encoder_term_request = g_create_wait_obj(buf);\n    self->xrdp_encoder_term_done = g_create_wait_obj(buf);\n    if (client_info->gfx)\n    {\n        const char *env_var = g_getenv(\"XRDP_GFX_FRAMES_IN_FLIGHT\");\n        self->frames_in_flight = DEFAULT_XRDP_GFX_FRAMES_IN_FLIGHT;\n        if (env_var != NULL)\n        {\n            int fif = g_atoix(env_var);\n            if (fif >= MIN_XRDP_GFX_FRAMES_IN_FLIGHT &&\n                    fif <= MAX_XRDP_GFX_FRAMES_IN_FLIGHT)\n            {\n                self->frames_in_flight = fif;\n                LOG(LOG_LEVEL_INFO, \"xrdp_encoder_create: \"\n                    \"XRDP_GFX_FRAMES_IN_FLIGHT set to %d\", fif);\n            }\n            else\n            {\n                LOG(LOG_LEVEL_INFO, \"xrdp_encoder_create: \"\n                    \"XRDP_GFX_FRAMES_IN_FLIGHT set but invalid %s\",\n                    env_var);\n            }\n        }\n        env_var = g_getenv(\"XRDP_GFX_MAX_COMPRESSED_BYTES\");\n        self->max_compressed_bytes = DEFAULT_XRDP_GFX_MAX_COMPRESSED_BYTES;\n        if (env_var != NULL)\n        {\n            int mcb = g_atoix(env_var);\n            if (mcb >= MIN_XRDP_GFX_MAX_COMPRESSED_BYTES &&\n                    mcb <= MAX_XRDP_GFX_MAX_COMPRESSED_BYTES)\n            {\n                self->max_compressed_bytes = mcb;\n                LOG(LOG_LEVEL_INFO, \"xrdp_encoder_create: \"\n                    \"XRDP_GFX_MAX_COMPRESSED_BYTES set to %d\", mcb);\n            }\n            else\n            {\n                LOG(LOG_LEVEL_INFO, \"xrdp_encoder_create: \"\n                    \"XRDP_GFX_MAX_COMPRESSED_BYTES set but invalid %s\",\n                    env_var);\n            }\n        }\n        LOG_DEVEL(LOG_LEVEL_INFO, \"Using %d max_compressed_bytes for encoder\",\n                  self->max_compressed_bytes);\n    }\n    else\n    {\n        self->frames_in_flight = client_info->max_unacknowledged_frame_count;\n        self->max_compressed_bytes = client_info->max_fastpath_frag_bytes & ~15;\n    }\n    /* make sure frames_in_flight is at least 1 */\n    self->frames_in_flight = MAX(self->frames_in_flight, 1);\n\n    set_h264_encoder_methods(self);\n\n    /* create thread to process messages */\n    tc_thread_create(proc_enc_msg, self);\n\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_encoder_delete(struct xrdp_encoder *self)\n{\n#if defined(XRDP_RFXCODEC) || defined(XRDP_X264) || defined(XRDP_OPENH264)\n    int index;\n#endif\n\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_encoder_delete:\");\n    if (self == 0)\n    {\n        return;\n    }\n    if (self->in_codec_mode == 0)\n    {\n        return;\n    }\n    /* tell worker thread to shut down */\n    g_set_wait_obj(self->xrdp_encoder_term_request);\n    (void)g_obj_wait(&self->xrdp_encoder_term_done, 1, NULL, 0, 5000);\n    if (!g_is_wait_obj_set(self->xrdp_encoder_term_done))\n    {\n        LOG(LOG_LEVEL_WARNING, \"Encoder failed to shut down cleanly\");\n    }\n\n#ifdef XRDP_RFXCODEC\n    for (index = 0; index < 16; index++)\n    {\n        if (self->codec_handle_prfx_gfx[index] != NULL)\n        {\n            rfxcodec_encode_destroy(self->codec_handle_prfx_gfx[index]);\n        }\n    }\n    if (self->codec_handle_rfx != NULL)\n    {\n        rfxcodec_encode_destroy(self->codec_handle_rfx);\n    }\n#endif\n\n#if defined(XRDP_X264) || defined(XRDP_OPENH264)\n    for (index = 0; index < 16; index++)\n    {\n        if (self->codec_handle_h264_gfx[index] != NULL)\n        {\n            self->xrdp_encoder_h264_delete(self->codec_handle_h264_gfx[index]);\n        }\n    }\n    if (self->codec_handle_h264 != NULL)\n    {\n        self->xrdp_encoder_h264_delete(self->codec_handle_h264);\n    }\n#endif\n\n    /* destroy wait objects used for signalling */\n    g_delete_wait_obj(self->xrdp_encoder_event_to_proc);\n    g_delete_wait_obj(self->xrdp_encoder_event_processed);\n    g_delete_wait_obj(self->xrdp_encoder_term_request);\n    g_delete_wait_obj(self->xrdp_encoder_term_done);\n\n    /* cleanup fifos */\n    fifo_delete(self->fifo_to_proc, NULL);\n    fifo_delete(self->fifo_processed, NULL);\n    tc_mutex_delete(self->mutex);\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* called from encoder thread */\nstatic int\nprocess_enc_jpg(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)\n{\n    int index;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int quality;\n    int error;\n    int out_data_bytes;\n    int count;\n    char *out_data;\n    XRDP_ENC_DATA_DONE *enc_done;\n    struct fifo *fifo_processed;\n    tbus mutex;\n    tbus event_processed;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_enc_jpg:\");\n    quality = self->codec_quality;\n    fifo_processed = self->fifo_processed;\n    mutex = self->mutex;\n    event_processed = self->xrdp_encoder_event_processed;\n    count = enc->u.sc.num_crects;\n    for (index = 0; index < count; index++)\n    {\n        x = enc->u.sc.crects[index * 4 + 0];\n        y = enc->u.sc.crects[index * 4 + 1];\n        cx = enc->u.sc.crects[index * 4 + 2];\n        cy = enc->u.sc.crects[index * 4 + 3];\n        if (cx < 1 || cy < 1)\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING, \"process_enc_jpg: error 1\");\n            continue;\n        }\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_enc_jpg: x %d y %d cx %d cy %d\",\n                  x, y, cx, cy);\n\n        out_data_bytes = MAX((cx + 4) * cy * 4, 8192);\n        if ((out_data_bytes < 1)\n                || (out_data_bytes > OUT_DATA_BYTES_DEFAULT_SIZE))\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"process_enc_jpg: error 2\");\n            return 1;\n        }\n        out_data = (char *) g_malloc(out_data_bytes\n                                     + XRDP_SURCMD_PREFIX_BYTES + 2, 0);\n        if (out_data == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"process_enc_jpg: error 3\");\n            return 1;\n        }\n\n        out_data[256] = 0; /* header bytes */\n        out_data[257] = 0;\n        error = libxrdp_codec_jpeg_compress(self->mm->wm->session, 0, enc->u.sc.data,\n                                            enc->u.sc.width, enc->u.sc.height,\n                                            enc->u.sc.width * 4, x, y, cx, cy,\n                                            quality,\n                                            out_data\n                                            + XRDP_SURCMD_PREFIX_BYTES + 2,\n                                            &out_data_bytes);\n        if (error < 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_ERROR, \"process_enc_jpg: jpeg error %d \"\n                      \"bytes %d\", error, out_data_bytes);\n            g_free(out_data);\n            return 1;\n        }\n        LOG_DEVEL(LOG_LEVEL_WARNING,\n                  \"jpeg error %d bytes %d\", error, out_data_bytes);\n        enc_done = (XRDP_ENC_DATA_DONE *)\n                   g_malloc(sizeof(XRDP_ENC_DATA_DONE), 1);\n        enc_done->comp_bytes = out_data_bytes + 2;\n        enc_done->pad_bytes = 256;\n        enc_done->comp_pad_data = out_data;\n        enc_done->enc = enc;\n        enc_done->last = index == (enc->u.sc.num_crects - 1);\n        enc_done->x = x;\n        enc_done->y = y;\n        enc_done->cx = cx;\n        enc_done->cy = cy;\n        enc_done->frame_id = enc->u.sc.frame_id;\n        /* done with msg */\n        /* inform main thread done */\n        tc_mutex_lock(mutex);\n        fifo_add_item(fifo_processed, enc_done);\n        tc_mutex_unlock(mutex);\n        /* signal completion for main thread */\n        g_set_wait_obj(event_processed);\n    }\n    return 0;\n}\n\n#ifdef XRDP_RFXCODEC\n/*****************************************************************************/\n/* called from encoder thread */\nstatic int\nprocess_enc_rfx(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)\n{\n    int index;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int out_data_bytes;\n    int count;\n    int tiles_written;\n    int all_tiles_written;\n    int tiles_left;\n    int finished;\n    char *out_data;\n    XRDP_ENC_DATA_DONE *enc_done;\n    struct fifo *fifo_processed;\n    tbus mutex;\n    tbus event_processed;\n    struct rfx_tile *tiles;\n    struct rfx_rect *rfxrects;\n    int alloc_bytes;\n    int encode_flags;\n    int encode_passes;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_enc_rfx:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_enc_rfx: num_crects %d num_drects %d\",\n              enc->u.sc.num_crects, enc->u.sc.num_drects);\n    fifo_processed = self->fifo_processed;\n    mutex = self->mutex;\n    event_processed = self->xrdp_encoder_event_processed;\n\n    all_tiles_written = 0;\n    encode_passes = 0;\n    do\n    {\n        tiles_written = 0;\n        tiles_left = enc->u.sc.num_crects - all_tiles_written;\n        out_data = NULL;\n        out_data_bytes = 0;\n\n        if ((tiles_left > 0) && (enc->u.sc.num_drects > 0))\n        {\n            alloc_bytes = XRDP_SURCMD_PREFIX_BYTES;\n            alloc_bytes += self->max_compressed_bytes;\n            alloc_bytes += sizeof(struct rfx_tile) * tiles_left +\n                           sizeof(struct rfx_rect) * enc->u.sc.num_drects;\n            out_data = g_new(char, alloc_bytes);\n            if (out_data != NULL)\n            {\n                tiles = (struct rfx_tile *)\n                        (out_data + XRDP_SURCMD_PREFIX_BYTES +\n                         self->max_compressed_bytes);\n                rfxrects = (struct rfx_rect *) (tiles + tiles_left);\n\n                count = tiles_left;\n                for (index = 0; index < count; index++)\n                {\n                    x = enc->u.sc.crects[(index + all_tiles_written) * 4 + 0];\n                    y = enc->u.sc.crects[(index + all_tiles_written) * 4 + 1];\n                    cx = enc->u.sc.crects[(index + all_tiles_written) * 4 + 2];\n                    cy = enc->u.sc.crects[(index + all_tiles_written) * 4 + 3];\n                    tiles[index].x = x;\n                    tiles[index].y = y;\n                    tiles[index].cx = cx;\n                    tiles[index].cy = cy;\n                    tiles[index].quant_y = self->quant_idx_y;\n                    tiles[index].quant_cb = self->quant_idx_u;\n                    tiles[index].quant_cr = self->quant_idx_v;\n                }\n\n                count = enc->u.sc.num_drects;\n                for (index = 0; index < count; index++)\n                {\n                    x = enc->u.sc.drects[index * 4 + 0];\n                    y = enc->u.sc.drects[index * 4 + 1];\n                    cx = enc->u.sc.drects[index * 4 + 2];\n                    cy = enc->u.sc.drects[index * 4 + 3];\n                    rfxrects[index].x = x;\n                    rfxrects[index].y = y;\n                    rfxrects[index].cx = cx;\n                    rfxrects[index].cy = cy;\n                }\n\n                out_data_bytes = self->max_compressed_bytes;\n\n                encode_flags = 0;\n                if (((int)enc->flags & KEY_FRAME_REQUESTED) && encode_passes == 0)\n                {\n                    encode_flags = RFX_FLAGS_PRO_KEY;\n                }\n                tiles_written = rfxcodec_encode_ex(self->codec_handle_rfx,\n                                                   out_data + XRDP_SURCMD_PREFIX_BYTES,\n                                                   &out_data_bytes, enc->u.sc.data,\n                                                   enc->u.sc.width, enc->u.sc.height,\n                                                   ((enc->u.sc.width + 63) & ~63) * 4,\n                                                   rfxrects, enc->u.sc.num_drects,\n                                                   tiles, enc->u.sc.num_crects,\n                                                   self->quants, self->num_quants,\n                                                   encode_flags);\n            }\n            ++encode_passes;\n        }\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG,\n                  \"process_enc_rfx: rfxcodec_encode tiles_written %d\",\n                  tiles_written);\n        /* only if enc_done->comp_bytes is not zero is something sent\n           to the client but you must always send something back even\n           on error so Xorg can get ack */\n        enc_done = g_new0(XRDP_ENC_DATA_DONE, 1);\n        if (enc_done == NULL)\n        {\n            return 1;\n        }\n        enc_done->comp_bytes = tiles_written > 0 ? out_data_bytes : 0;\n        enc_done->pad_bytes = XRDP_SURCMD_PREFIX_BYTES;\n        enc_done->comp_pad_data = out_data;\n        enc_done->enc = enc;\n        enc_done->x = enc->u.sc.left;\n        enc_done->y = enc->u.sc.top;\n        enc_done->cx = enc->u.sc.width;\n        enc_done->cy = enc->u.sc.height;\n        enc_done->frame_id = enc->u.sc.frame_id;\n        enc_done->continuation = all_tiles_written > 0;\n        if (tiles_written > 0)\n        {\n            all_tiles_written += tiles_written;\n        }\n        finished =\n            (all_tiles_written == enc->u.sc.num_crects) || (tiles_written < 0);\n        enc_done->last = finished;\n\n        /* done with msg */\n        /* inform main thread done */\n        tc_mutex_lock(mutex);\n        fifo_add_item(fifo_processed, enc_done);\n        tc_mutex_unlock(mutex);\n    }\n    while (!finished);\n\n    /* signal completion for main thread */\n    g_set_wait_obj(event_processed);\n\n    return 0;\n}\n#endif\n\n#if defined(XRDP_X264) || defined(XRDP_OPENH264)\n\n/*****************************************************************************/\nstatic int\nout_RFX_AVC420_METABLOCK(struct xrdp_egfx_rect *dst_rect,\n                         struct stream *s,\n                         struct xrdp_egfx_rect *rects,\n                         int num_rects)\n{\n    struct xrdp_region *reg;\n    struct xrdp_rect rect;\n    int index;\n    int count;\n\n    /* RFX_AVC420_METABLOCK */\n    s_push_layer(s, iso_hdr, 4); /* numRegionRects, set later */\n    reg = xrdp_region_create(NULL);\n    if (reg == NULL)\n    {\n        return 1;\n    }\n    for (index = 0; index < num_rects; index++)\n    {\n        rect.left = MAX(0, rects[index].x1 - dst_rect->x1 - 1);\n        rect.top = MAX(0, rects[index].y1 - dst_rect->y1 - 1);\n        rect.right = MIN(dst_rect->x2 - dst_rect->x1,\n                         rects[index].x2 - dst_rect->x1 + 1);\n        rect.bottom = MIN(dst_rect->y2 - dst_rect->y1,\n                          rects[index].y2 - dst_rect->y1 + 1);\n        xrdp_region_add_rect(reg, &rect);\n    }\n    index = 0;\n    while (xrdp_region_get_rect(reg, index, &rect) == 0)\n    {\n        out_uint16_le(s, rect.left);\n        out_uint16_le(s, rect.top);\n        out_uint16_le(s, rect.right);\n        out_uint16_le(s, rect.bottom);\n        index++;\n    }\n    xrdp_region_delete(reg);\n    count = index;\n    while (index > 0)\n    {\n        out_uint8(s, 23); /* qp */\n        out_uint8(s, 100); /* quality level 0..100 */\n        index--;\n    }\n    s_push_layer(s, mcs_hdr, 0);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, count); /* numRegionRects */\n    s_pop_layer(s, mcs_hdr);\n    return 0;\n}\n\n/*****************************************************************************/\n/* called from encoder thread */\nstatic int\nprocess_enc_h264(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)\n{\n    LOG_DEVEL(LOG_LEVEL_INFO, \"process_enc_h264: dummy func\");\n    return 0;\n}\n#endif\n\n/*****************************************************************************/\nstatic int\ngfx_send_done(struct xrdp_encoder *self, XRDP_ENC_DATA *enc,\n              int comp_bytes, int pad_bytes, char *comp_pad_data,\n              int got_frame_id, int frame_id, int is_last)\n\n{\n    XRDP_ENC_DATA_DONE *enc_done;\n\n    enc_done = g_new0(XRDP_ENC_DATA_DONE, 1);\n    if (enc_done == NULL)\n    {\n        return 1;\n    }\n    ENC_SET_BIT(enc_done->flags, ENC_DONE_FLAGS_GFX_BIT);\n    enc_done->enc = enc;\n    enc_done->last = is_last;\n    enc_done->pad_bytes = pad_bytes;\n    enc_done->comp_bytes = comp_bytes;\n    enc_done->comp_pad_data = comp_pad_data;\n    if (got_frame_id)\n    {\n        ENC_SET_BIT(enc_done->flags, ENC_DONE_FLAGS_FRAME_ID_BIT);\n        enc_done->frame_id = frame_id;\n    }\n    /* inform main thread done */\n    tc_mutex_lock(self->mutex);\n    fifo_add_item(self->fifo_processed, enc_done);\n    tc_mutex_unlock(self->mutex);\n    /* signal completion for main thread */\n    g_set_wait_obj(self->xrdp_encoder_event_processed);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_wiretosurface1(struct xrdp_encoder *self,\n                   struct xrdp_egfx_bulk *bulk, struct stream *in_s,\n                   XRDP_ENC_DATA *enc)\n{\n#if defined(XRDP_X264) || defined(XRDP_OPENH264)\n    int index;\n    int surface_id;\n    int codec_id;\n    int pixel_format;\n    int num_rects_d;\n    int num_rects_c;\n    struct stream *rv;\n    short left;\n    short top;\n    short width;\n    short height;\n    short twidth;\n    short theight;\n    int bitmap_data_length;\n    int flags;\n    struct xrdp_egfx_rect *d_rects;\n    struct xrdp_egfx_rect *c_rects;\n    struct xrdp_egfx_rect dst_rect;\n    int error;\n    struct stream ls;\n    struct stream *s;\n    short *crects;\n    struct xrdp_enc_gfx_cmd *enc_gfx_cmd = &(enc->u.gfx);\n    int mon_index;\n    int connection_type;\n\n    connection_type = self->mm->wm->client_info->mcs_connection_type;\n\n    s = &ls;\n    g_memset(s, 0, sizeof(struct stream));\n    s->size = self->max_compressed_bytes;\n    s->data = g_new(char, s->size);\n    if (s->data == NULL)\n    {\n        return NULL;\n    }\n    s->p = s->data;\n    if (!s_check_rem(in_s, 11))\n    {\n        g_free(s->data);\n        return NULL;\n    }\n    in_uint16_le(in_s, surface_id);\n    in_uint16_le(in_s, codec_id);\n    in_uint8(in_s, pixel_format);\n    in_uint32_le(in_s, flags);\n    mon_index = (flags >> 28) & 0xF;\n    in_uint16_le(in_s, num_rects_d);\n    if ((num_rects_d < 1) || (num_rects_d > 16 * 1024) ||\n            (!s_check_rem(in_s, num_rects_d * 8)))\n    {\n        g_free(s->data);\n        return NULL;\n    }\n    d_rects = g_new0(struct xrdp_egfx_rect, num_rects_d);\n    if (d_rects == NULL)\n    {\n        g_free(s->data);\n        return NULL;\n    }\n    for (index = 0; index < num_rects_d; index++)\n    {\n        in_uint16_le(in_s, left);\n        in_uint16_le(in_s, top);\n        in_uint16_le(in_s, width);\n        in_uint16_le(in_s, height);\n        d_rects[index].x1 = left;\n        d_rects[index].y1 = top;\n        d_rects[index].x2 = left + width;\n        d_rects[index].y2 = top + height;\n\n    }\n    if (!s_check_rem(in_s, 2))\n    {\n        g_free(s->data);\n        g_free(d_rects);\n        return NULL;\n    }\n    in_uint16_le(in_s, num_rects_c);\n    if ((num_rects_c < 1) || (num_rects_c > 16 * 1024) ||\n            (!s_check_rem(in_s, num_rects_c * 8)))\n    {\n        g_free(s->data);\n        g_free(d_rects);\n        return NULL;\n    }\n    c_rects = g_new0(struct xrdp_egfx_rect, num_rects_c);\n    if (c_rects == NULL)\n    {\n        g_free(s->data);\n        g_free(d_rects);\n        return NULL;\n    }\n    crects = g_new(short, num_rects_c * 4);\n    if (crects == NULL)\n    {\n        g_free(s->data);\n        g_free(c_rects);\n        g_free(d_rects);\n        return NULL;\n    }\n    g_memcpy(crects, in_s->p, num_rects_c * 2 * 4);\n    for (index = 0; index < num_rects_c; index++)\n    {\n        in_uint16_le(in_s, left);\n        in_uint16_le(in_s, top);\n        in_uint16_le(in_s, width);\n        in_uint16_le(in_s, height);\n        c_rects[index].x1 = left;\n        c_rects[index].y1 = top;\n        c_rects[index].x2 = left + width;\n        c_rects[index].y2 = top + height;\n    }\n    if (!s_check_rem(in_s, 8))\n    {\n        g_free(s->data);\n        g_free(c_rects);\n        g_free(d_rects);\n        g_free(crects);\n        return NULL;\n    }\n    in_uint16_le(in_s, left);\n    in_uint16_le(in_s, top);\n    in_uint16_le(in_s, width);\n    in_uint16_le(in_s, height);\n    twidth = width;\n    theight = height;\n    dst_rect.x1 = 0;\n    dst_rect.y1 = 0;\n    dst_rect.x2 = width;\n    dst_rect.y2 = height;\n    LOG_DEVEL(LOG_LEVEL_INFO, \"gfx_wiretosurface1: left %d top \"\n              \"%d width %d height %d mon_index %d\",\n              left, top, width, height, mon_index);\n    /* RFX_AVC420_METABLOCK */\n    if (out_RFX_AVC420_METABLOCK(&dst_rect, s, d_rects, num_rects_d) != 0)\n    {\n        g_free(s->data);\n        g_free(c_rects);\n        g_free(d_rects);\n        g_free(crects);\n        LOG(LOG_LEVEL_INFO, \"10\");\n        return NULL;\n    }\n\n    g_free(c_rects);\n    g_free(d_rects);\n\n    if (ENC_IS_BIT_SET(flags, 0))\n    {\n        /* already compressed */\n        out_uint8a(s, enc_gfx_cmd->data, enc_gfx_cmd->data_bytes);\n    }\n    else\n    {\n        /* assume NV12 format */\n        if (twidth * theight * 3 / 2 > enc_gfx_cmd->data_bytes)\n        {\n            g_free(s->data);\n            g_free(crects);\n            return NULL;\n        }\n        bitmap_data_length = s_rem_out(s);\n        if (self->codec_handle_h264_gfx[mon_index] == NULL)\n        {\n            self->codec_handle_h264_gfx[mon_index] =\n                self->xrdp_encoder_h264_create();\n            if (self->codec_handle_h264_gfx[mon_index] == NULL)\n            {\n                g_free(s->data);\n                g_free(crects);\n                return NULL;\n            }\n        }\n        error = self->xrdp_encoder_h264_encode(\n                    self->codec_handle_h264_gfx[mon_index], 0,\n                    0, 0,\n                    width, height, twidth, theight, 0,\n                    enc_gfx_cmd->data,\n                    crects, num_rects_c,\n                    s->p, &bitmap_data_length,\n                    connection_type, NULL);\n        if (error == 0)\n        {\n            xstream_seek(s, bitmap_data_length);\n        }\n        else\n        {\n            g_free(s->data);\n            g_free(crects);\n            return NULL;\n        }\n    }\n    s_mark_end(s);\n    bitmap_data_length = (int) (s->end - s->data);\n    rv = xrdp_egfx_wire_to_surface1(bulk, surface_id,\n                                    codec_id,\n                                    pixel_format, &dst_rect,\n                                    s->data, bitmap_data_length);\n    g_free(s->data);\n    g_free(crects);\n    return rv;\n#else\n    (void)self;\n    (void)bulk;\n    (void)in_s;\n    (void)enc;\n    return NULL;\n#endif\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_wiretosurface2(struct xrdp_encoder *self,\n                   struct xrdp_egfx_bulk *bulk, struct stream *in_s,\n                   XRDP_ENC_DATA *enc)\n{\n#ifdef XRDP_RFXCODEC\n    int index;\n    int surface_id;\n    int codec_id;\n    int codec_context_id;\n    int pixel_format;\n    int num_rects_d;\n    int num_rects_c;\n    struct stream *rv;\n    short left;\n    short top;\n    short width;\n    short height;\n    char *bitmap_data;\n    int bitmap_data_length;\n    struct rfx_tile *tiles;\n    struct rfx_rect *rfxrects;\n    int tiles_compressed;\n    int flags;\n    int total_tiles;\n    int tiles_written;\n    int mon_index;\n\n    if (!s_check_rem(in_s, 15))\n    {\n        return NULL;\n    }\n    in_uint16_le(in_s, surface_id);\n    in_uint16_le(in_s, codec_id);\n    in_uint32_le(in_s, codec_context_id);\n    in_uint8(in_s, pixel_format);\n    in_uint32_le(in_s, flags);\n    mon_index = (flags >> 28) & 0xF;\n    in_uint16_le(in_s, num_rects_d);\n    if ((num_rects_d < 1) || (num_rects_d > 16 * 1024) ||\n            (!s_check_rem(in_s, num_rects_d * 8)))\n    {\n        return NULL;\n    }\n    rfxrects = g_new0(struct rfx_rect, num_rects_d);\n    if (rfxrects == NULL)\n    {\n        return NULL;\n    }\n    for (index = 0; index < num_rects_d; index++)\n    {\n        in_uint16_le(in_s, left);\n        in_uint16_le(in_s, top);\n        in_uint16_le(in_s, width);\n        in_uint16_le(in_s, height);\n        rfxrects[index].x = left;\n        rfxrects[index].y = top;\n        rfxrects[index].cx = width;\n        rfxrects[index].cy = height;\n    }\n    if (!s_check_rem(in_s, 2))\n    {\n        g_free(rfxrects);\n        return NULL;\n    }\n    in_uint16_le(in_s, num_rects_c);\n    if ((num_rects_c < 1) || (num_rects_c > 16 * 1024) ||\n            (!s_check_rem(in_s, num_rects_c * 8)))\n    {\n        g_free(rfxrects);\n        return NULL;\n    }\n    tiles = g_new0(struct rfx_tile, num_rects_c);\n    if (tiles == NULL)\n    {\n        g_free(rfxrects);\n        return NULL;\n    }\n    for (index = 0; index < num_rects_c; index++)\n    {\n        in_uint16_le(in_s, left);\n        in_uint16_le(in_s, top);\n        in_uint16_le(in_s, width);\n        in_uint16_le(in_s, height);\n        tiles[index].x = left;\n        tiles[index].y = top;\n        tiles[index].cx = width;\n        tiles[index].cy = height;\n        tiles[index].quant_y = self->quant_idx_y;\n        tiles[index].quant_cb = self->quant_idx_u;\n        tiles[index].quant_cr = self->quant_idx_v;\n    }\n    if (!s_check_rem(in_s, 8))\n    {\n        g_free(tiles);\n        g_free(rfxrects);\n        return NULL;\n    }\n    in_uint16_le(in_s, left);\n    in_uint16_le(in_s, top);\n    in_uint16_le(in_s, width);\n    in_uint16_le(in_s, height);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"gfx_wiretosurface2: left %d top \"\n              \"%d width %d height %d mon_index %d\",\n              left, top, width, height, mon_index);\n    if (self->codec_handle_prfx_gfx[mon_index] == NULL)\n    {\n        self->codec_handle_prfx_gfx[mon_index] = rfxcodec_encode_create(\n                width,\n                height,\n                RFX_FORMAT_YUV,\n                RFX_FLAGS_RLGR1 | RFX_FLAGS_PRO1);\n        if (self->codec_handle_prfx_gfx[mon_index] == NULL)\n        {\n            g_free(tiles);\n            g_free(rfxrects);\n            return NULL;\n        }\n    }\n    bitmap_data_length = self->max_compressed_bytes;\n    bitmap_data = g_new(char, bitmap_data_length);\n    if (bitmap_data == NULL)\n    {\n        g_free(tiles);\n        g_free(rfxrects);\n        return NULL;\n    }\n    rv = NULL;\n    tiles_written = 0;\n    total_tiles = num_rects_c;\n    for (;;)\n    {\n        tiles_compressed =\n            rfxcodec_encode(self->codec_handle_prfx_gfx[mon_index],\n                            bitmap_data,\n                            &bitmap_data_length,\n                            enc->u.gfx.data,\n                            width, height,\n                            ((width + 63) & ~63) * 4,\n                            rfxrects, num_rects_d,\n                            tiles + tiles_written, total_tiles - tiles_written,\n                            self->quants, self->num_quants);\n        if (tiles_compressed < 1)\n        {\n            break;\n        }\n        tiles_written += tiles_compressed;\n        rv = xrdp_egfx_wire_to_surface2(bulk, surface_id,\n                                        codec_id, codec_context_id,\n                                        pixel_format,\n                                        bitmap_data, bitmap_data_length);\n        if (rv == NULL)\n        {\n            break;\n        }\n        LOG_DEVEL(LOG_LEVEL_INFO, \"gfx_wiretosurface2: \"\n                  \"tiles_compressed %d total_tiles %d tiles_written %d\",\n                  tiles_compressed, total_tiles,\n                  tiles_written);\n        if (tiles_written >= total_tiles)\n        {\n            /* ok, done with last tile set */\n            break;\n        }\n        /* we have another tile set, send this one to main thread */\n        if (gfx_send_done(self, enc, (int)(rv->end - rv->data), 0,\n                          rv->data, 0, 0, 0) != 0)\n        {\n            free_stream(rv);\n            rv = NULL;\n            break;\n        }\n        g_free(rv); /* don't call free_stream() here so s->data is valid */\n        rv = NULL;\n        bitmap_data_length = self->max_compressed_bytes;\n    }\n    g_free(tiles);\n    g_free(rfxrects);\n    g_free(bitmap_data);\n    return rv;\n#else\n    (void)self;\n    (void)bulk;\n    (void)in_s;\n    (void)enc;\n    return NULL;\n#endif\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_solidfill(struct xrdp_encoder *self,\n              struct xrdp_egfx_bulk *bulk, struct stream *in_s)\n{\n    int surface_id;\n    int pixel;\n    int num_rects;\n    char *ptr8;\n    struct xrdp_egfx_rect *rects;\n\n    if (!s_check_rem(in_s, 8))\n    {\n        return NULL;\n    }\n    in_uint16_le(in_s, surface_id);\n    in_uint32_le(in_s, pixel);\n    in_uint16_le(in_s, num_rects);\n    if (!s_check_rem(in_s, num_rects * 8))\n    {\n        return NULL;\n    }\n    in_uint8p(in_s, ptr8, num_rects * 8);\n    rects = (struct xrdp_egfx_rect *) ptr8;\n    return xrdp_egfx_fill_surface(bulk, surface_id, pixel, num_rects, rects);\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_surfacetosurface(struct xrdp_encoder *self,\n                     struct xrdp_egfx_bulk *bulk, struct stream *in_s)\n{\n    int surface_id_src;\n    int surface_id_dst;\n    char *ptr8;\n    int num_pts;\n    struct xrdp_egfx_rect *rects;\n    struct xrdp_egfx_point *pts;\n\n    if (!s_check_rem(in_s, 14))\n    {\n        return NULL;\n    }\n    in_uint16_le(in_s, surface_id_src);\n    in_uint16_le(in_s, surface_id_dst);\n    in_uint8p(in_s, ptr8, 8);\n    rects = (struct xrdp_egfx_rect *) ptr8;\n    in_uint16_le(in_s, num_pts);\n    if (!s_check_rem(in_s, num_pts * 4))\n    {\n        return NULL;\n    }\n    in_uint8p(in_s, ptr8, num_pts * 4);\n    pts = (struct xrdp_egfx_point *) ptr8;\n    return xrdp_egfx_surface_to_surface(bulk, surface_id_src, surface_id_dst,\n                                        rects, num_pts, pts);\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_createsurface(struct xrdp_encoder *self,\n                  struct xrdp_egfx_bulk *bulk, struct stream *in_s)\n{\n    int surface_id;\n    int width;\n    int height;\n    int pixel_format;\n\n    if (!s_check_rem(in_s, 7))\n    {\n        return NULL;\n    }\n    in_uint16_le(in_s, surface_id);\n    in_uint16_le(in_s, width);\n    in_uint16_le(in_s, height);\n    in_uint8(in_s, pixel_format);\n    return xrdp_egfx_create_surface(bulk, surface_id,\n                                    width, height, pixel_format);\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_deletesurface(struct xrdp_encoder *self,\n                  struct xrdp_egfx_bulk *bulk, struct stream *in_s)\n{\n    int surface_id;\n\n    if (!s_check_rem(in_s, 2))\n    {\n        return NULL;\n    }\n    in_uint16_le(in_s, surface_id);\n    return xrdp_egfx_delete_surface(bulk, surface_id);\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_startframe(struct xrdp_encoder *self,\n               struct xrdp_egfx_bulk *bulk, struct stream *in_s)\n{\n    int frame_id;\n    int time_stamp;\n\n    if (!s_check_rem(in_s, 8))\n    {\n        return NULL;\n    }\n    in_uint32_le(in_s, frame_id);\n    in_uint32_le(in_s, time_stamp);\n    return xrdp_egfx_frame_start(bulk, frame_id, time_stamp);\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_endframe(struct xrdp_encoder *self,\n             struct xrdp_egfx_bulk *bulk, struct stream *in_s, int *aframe_id)\n{\n    int frame_id;\n\n    if (!s_check_rem(in_s, 4))\n    {\n        return NULL;\n    }\n    in_uint32_le(in_s, frame_id);\n    *aframe_id = frame_id;\n    return xrdp_egfx_frame_end(bulk, frame_id);\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_resetgraphics(struct xrdp_encoder *self,\n                  struct xrdp_egfx_bulk *bulk, struct stream *in_s)\n{\n    int width;\n    int height;\n    int monitor_count;\n    int index;\n    struct monitor_info *mi;\n    struct stream *rv;\n\n    if (!s_check_rem(in_s, 12))\n    {\n        return NULL;\n    }\n    in_uint32_le(in_s, width);\n    in_uint32_le(in_s, height);\n    in_uint32_le(in_s, monitor_count);\n    if ((monitor_count < 1) || (monitor_count > 16) ||\n            !s_check_rem(in_s, monitor_count * 20))\n    {\n        return NULL;\n    }\n    mi = g_new0(struct monitor_info, monitor_count);\n    if (mi == NULL)\n    {\n        return NULL;\n    }\n    for (index = 0; index < monitor_count; index++)\n    {\n        in_uint32_le(in_s, mi[index].left);\n        in_uint32_le(in_s, mi[index].top);\n        in_uint32_le(in_s, mi[index].right);\n        in_uint32_le(in_s, mi[index].bottom);\n        in_uint32_le(in_s, mi[index].is_primary);\n    }\n    rv = xrdp_egfx_reset_graphics(bulk, width, height, monitor_count, mi);\n    g_free(mi);\n    return rv;\n}\n\n/*****************************************************************************/\nstatic struct stream *\ngfx_mapsurfacetooutput(struct xrdp_encoder *self,\n                       struct xrdp_egfx_bulk *bulk, struct stream *in_s)\n{\n    int surface_id;\n    int x;\n    int y;\n\n    if (!s_check_rem(in_s, 10))\n    {\n        return NULL;\n    }\n    in_uint16_le(in_s, surface_id);\n    in_uint32_le(in_s, x);\n    in_uint32_le(in_s, y);\n    return xrdp_egfx_map_surface(bulk, surface_id, x, y);\n}\n\n/*****************************************************************************/\n/* called from encoder thread */\nstatic int\nprocess_enc_egfx(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)\n{\n    struct stream *s;\n    struct stream in_s;\n    struct xrdp_egfx_bulk *bulk;\n    int cmd_id;\n    int cmd_bytes;\n    int frame_id;\n    int got_frame_id;\n    int error;\n    char *holdp;\n    char *holdend;\n\n    bulk = self->mm->egfx->bulk;\n    g_memset(&in_s, 0, sizeof(in_s));\n    in_s.data = enc->u.gfx.cmd;\n    in_s.size = enc->u.gfx.cmd_bytes;\n    in_s.p = in_s.data;\n    in_s.end = in_s.data + in_s.size;\n    while (s_check_rem(&in_s, 8))\n    {\n        s = NULL;\n        frame_id = 0;\n        got_frame_id = 0;\n        holdp = in_s.p;\n        in_uint16_le(&in_s, cmd_id);\n        in_uint8s(&in_s, 2); /* flags */\n        in_uint32_le(&in_s, cmd_bytes);\n        if ((cmd_bytes < 8) || (cmd_bytes > 32 * 1024))\n        {\n            return 1;\n        }\n        holdend = in_s.end;\n        in_s.end = holdp + cmd_bytes;\n        LOG_DEVEL(LOG_LEVEL_INFO, \"process_enc_egfx: cmd_id %d\", cmd_id);\n        switch (cmd_id)\n        {\n            case XR_RDPGFX_CMDID_WIRETOSURFACE_1:       /* 0x0001 */\n                s = gfx_wiretosurface1(self, bulk, &in_s, enc);\n                break;\n            case XR_RDPGFX_CMDID_WIRETOSURFACE_2:       /* 0x0002 */\n                s = gfx_wiretosurface2(self, bulk, &in_s, enc);\n                break;\n            case XR_RDPGFX_CMDID_SOLIDFILL:             /* 0x0004 */\n                s = gfx_solidfill(self, bulk, &in_s);\n                break;\n            case XR_RDPGFX_CMDID_SURFACETOSURFACE:      /* 0x0005 */\n                s = gfx_surfacetosurface(self, bulk, &in_s);\n                break;\n            case XR_RDPGFX_CMDID_CREATESURFACE:         /* 0x0009 */\n                s = gfx_createsurface(self, bulk, &in_s);\n                break;\n            case XR_RDPGFX_CMDID_DELETESURFACE:         /* 0x000A */\n                s = gfx_deletesurface(self, bulk, &in_s);\n                break;\n            case XR_RDPGFX_CMDID_STARTFRAME:            /* 0x000B */\n                s = gfx_startframe(self, bulk, &in_s);\n                break;\n            case XR_RDPGFX_CMDID_ENDFRAME:              /* 0x000C */\n                s = gfx_endframe(self, bulk, &in_s, &frame_id);\n                got_frame_id = 1;\n                break;\n            case XR_RDPGFX_CMDID_RESETGRAPHICS:         /* 0x000E */\n                s = gfx_resetgraphics(self, bulk, &in_s);\n                break;\n            case XR_RDPGFX_CMDID_MAPSURFACETOOUTPUT:    /* 0x000F */\n                s = gfx_mapsurfacetooutput(self, bulk, &in_s);\n                break;\n            default:\n                break;\n        }\n        /* setup for next cmd */\n        in_s.p = holdp + cmd_bytes;\n        in_s.end = holdend;\n        if (s != NULL)\n        {\n            /* send message to main thread */\n            error = gfx_send_done(self, enc, (int) (s->end - s->data),\n                                  0, s->data, got_frame_id, frame_id,\n                                  !s_check_rem(&in_s, 8));\n            if (error != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"process_enc_egfx: gfx_send_done failed \"\n                    \"error %d\", error);\n                free_stream(s);\n                return 1;\n            }\n            g_free(s); /* don't call free_stream() here so s->data is valid */\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_INFO, \"process_enc_egfx: nil\");\n        }\n    }\n    return 0;\n}\n\n/**\n * Encoder thread main loop\n *****************************************************************************/\nTHREAD_RV THREAD_CC\nproc_enc_msg(void *arg)\n{\n    XRDP_ENC_DATA *enc;\n    struct fifo *fifo_to_proc;\n    tbus mutex;\n    tbus event_to_proc;\n    tbus term_obj;\n    tbus lterm_obj;\n    int robjs_count;\n    int wobjs_count;\n    int cont;\n    int timeout;\n    tbus robjs[32];\n    tbus wobjs[32];\n    struct xrdp_encoder *self;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"proc_enc_msg: thread is running\");\n\n    self = (struct xrdp_encoder *) arg;\n    if (self == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"proc_enc_msg: self nil\");\n        return 0;\n    }\n\n    fifo_to_proc = self->fifo_to_proc;\n    mutex = self->mutex;\n    event_to_proc = self->xrdp_encoder_event_to_proc;\n\n    term_obj = g_get_term();\n    lterm_obj = self->xrdp_encoder_term_request;\n\n    cont = 1;\n    while (cont)\n    {\n        timeout = -1;\n        robjs_count = 0;\n        wobjs_count = 0;\n        robjs[robjs_count++] = term_obj;\n        robjs[robjs_count++] = lterm_obj;\n        robjs[robjs_count++] = event_to_proc;\n\n        if (g_obj_wait(robjs, robjs_count, wobjs, wobjs_count, timeout) != 0)\n        {\n            /* error, should not get here */\n            g_sleep(100);\n        }\n\n        if (g_is_wait_obj_set(term_obj)) /* global term */\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"Received termination signal, stopping the encoder thread\");\n            break;\n        }\n\n        if (g_is_wait_obj_set(lterm_obj)) /* xrdp_mm term */\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"proc_enc_msg: xrdp_mm term\");\n            break;\n        }\n\n        if (g_is_wait_obj_set(event_to_proc))\n        {\n            /* clear it right away */\n            g_reset_wait_obj(event_to_proc);\n            /* get first msg */\n            tc_mutex_lock(mutex);\n            enc = (XRDP_ENC_DATA *) fifo_remove_item(fifo_to_proc);\n            tc_mutex_unlock(mutex);\n            while (enc != 0)\n            {\n                /* do work */\n                self->process_enc(self, enc);\n                /* get next msg */\n                tc_mutex_lock(mutex);\n                enc = (XRDP_ENC_DATA *) fifo_remove_item(fifo_to_proc);\n                tc_mutex_unlock(mutex);\n            }\n        }\n\n    } /* end while (cont) */\n    g_set_wait_obj(self->xrdp_encoder_term_done);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"proc_enc_msg: thread exit\");\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/xrdp_encoder.h",
    "content": "\n#ifndef _XRDP_ENCODER_H\n#define _XRDP_ENCODER_H\n\n#include \"arch.h\"\n#include \"fifo.h\"\n#include \"xrdp_client_info.h\"\n\n#define ENC_IS_BIT_SET(_flags, _bit) (((_flags) & (1 << (_bit))) != 0)\n#define ENC_SET_BIT(_flags, _bit) do { _flags |= (1 << (_bit)); } while (0)\n#define ENC_CLR_BIT(_flags, _bit) do { _flags &= ~(1 << (_bit)); } while (0)\n#define ENC_SET_BITS(_flags, _mask, _bits) \\\n    do { _flags &= ~(_mask); _flags |= (_bits) & (_mask); } while (0)\n\nstruct xrdp_enc_data;\n\ntypedef void *(*xrdp_encoder_h264_create_proc)(void);\ntypedef int (*xrdp_encoder_h264_delete_proc)(void *handle);\ntypedef int (*xrdp_encoder_h264_encode_proc)(\n    void *handle, int session, int left, int top,\n    int width, int height, int twidth, int theight,\n    int format, const char *data,\n    short *crects, int num_crects,\n    char *cdata, int *cdata_bytes,\n    int connection_type, int *flags_ptr);\n\n/* for codec mode operations */\nstruct xrdp_encoder\n{\n    struct xrdp_mm *mm;\n    int in_codec_mode;\n    int codec_id;\n    int codec_quality;\n    int max_compressed_bytes;\n    tbus xrdp_encoder_event_to_proc;\n    tbus xrdp_encoder_event_processed;\n    tbus xrdp_encoder_term_request;\n    tbus xrdp_encoder_term_done;\n    struct fifo *fifo_to_proc;\n    struct fifo *fifo_processed;\n    tbus mutex;\n    int (*process_enc)(struct xrdp_encoder *self, struct xrdp_enc_data *enc);\n    void *codec_handle_rfx;\n    void *codec_handle_jpg;\n    void *codec_handle_h264;\n    void *codec_handle_prfx_gfx[16];\n    void *codec_handle_h264_gfx[16];\n    int frame_id_client; /* last frame id received from client */\n    int frame_id_server; /* last frame id received from Xorg */\n    int frame_id_server_sent;\n    int frames_in_flight;\n    int gfx;\n    int gfx_ack_off;\n    const char *quants;\n    int num_quants;\n    int quant_idx_y;\n    int quant_idx_u;\n    int quant_idx_v;\n    int pad0;\n    xrdp_encoder_h264_create_proc xrdp_encoder_h264_create;\n    xrdp_encoder_h264_delete_proc xrdp_encoder_h264_delete;\n    xrdp_encoder_h264_encode_proc xrdp_encoder_h264_encode;\n};\n\n/* cmd_id = 0 */\nstruct xrdp_enc_surface_command\n{\n    struct xrdp_mod *mod;\n    int num_drects;\n    int pad0;\n    short *drects;  /* 4 * num_drects */\n    int num_crects;\n    int pad1;\n    short *crects;  /* 4 * num_crects */\n    char *data;\n    int left;\n    int top;\n    int width;\n    int height;\n    int flags;\n    int frame_id;\n};\n\nstruct xrdp_enc_gfx_cmd\n{\n    char *cmd;\n    char *data;\n    int cmd_bytes;\n    int data_bytes;\n};\n\ntypedef struct xrdp_enc_data XRDP_ENC_DATA;\n\n#define ENC_DONE_FLAGS_GFX_BIT      0\n#define ENC_DONE_FLAGS_FRAME_ID_BIT 1\n\n/* used when scheduling tasks from xrdp_encoder.c */\nstruct xrdp_enc_data_done\n{\n    int comp_bytes;\n    int pad_bytes;\n    char *comp_pad_data;\n    struct xrdp_enc_data *enc;\n    int last; /* true is this is last message for enc */\n    int continuation; /* true if this isn't the start of a frame */\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int flags; /* ENC_DONE_FLAGS_* */\n    int frame_id;\n};\n\n#define ENC_FLAGS_GFX_BIT   0\n\n/* used when scheduling tasks in xrdp_encoder.c */\nstruct xrdp_enc_data\n{\n    struct xrdp_mod *mod;\n    int flags; /* ENC_FLAGS_* */\n    int pad0;\n    void *shmem_ptr;\n    int shmem_bytes;\n    int pad1;\n    union _u\n    {\n        struct xrdp_enc_surface_command sc;\n        struct xrdp_enc_gfx_cmd gfx;\n    } u;\n};\n\ntypedef struct xrdp_enc_data_done XRDP_ENC_DATA_DONE;\n\nstruct xrdp_encoder *\nxrdp_encoder_create(struct xrdp_mm *mm);\nvoid\nxrdp_encoder_delete(struct xrdp_encoder *self);\nTHREAD_RV THREAD_CC\nproc_enc_msg(void *arg);\n\n#endif\n"
  },
  {
    "path": "xrdp/xrdp_encoder_openh264.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2016-2024\n * Copyright (C) Christopher Pitstick 2023-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * openh264 Encoder\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#include <inttypes.h>\n#include <wels/codec_api.h>\n#include <wels/codec_def.h>\n\n#include \"xrdp.h\"\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"xrdp_encoder_openh264.h\"\n#include \"xrdp_tconfig.h\"\n\n#define OPENH264_MAX_ENCODERS 16\n\nstruct openh264_encoder\n{\n    ISVCEncoder *openh264_enc_han;\n    char *yuvdata;\n    int width;\n    int height;\n};\n\nstruct openh264_global\n{\n    struct openh264_encoder encoders[OPENH264_MAX_ENCODERS];\n    struct xrdp_tconfig_gfx_openh264_param\n        openh264_param[NUM_CONNECTION_TYPES];\n};\n\n/* The method invocations on ISVCEncoder are different for C and C++, as\n   ISVCEncoder is a true class in C++, but an emulated one in C */\n#ifdef __cplusplus /* compiling with g++  */\n#define ENC_GET_DEFAULT_PARAMS(obj, pParam) (obj)->GetDefaultParams(pParam)\n#define ENC_INITIALIZE_EXT(obj, pParam)     (obj)->InitializeExt(pParam)\n#define ENC_ENCODE_FRAME(obj, kpSrcPic, pBsInfo) \\\n    (obj)->EncodeFrame(kpSrcPic, pBsInfo)\n#else\n#define ENC_GET_DEFAULT_PARAMS(obj, pParam) (*obj)->GetDefaultParams(obj, pParam)\n#define ENC_INITIALIZE_EXT(obj, pParam)     (*obj)->InitializeExt(obj, pParam)\n#define ENC_ENCODE_FRAME(obj, kpSrcPic, pBsInfo) \\\n    (*obj)->EncodeFrame(obj, kpSrcPic, pBsInfo)\n#endif\n\n/*****************************************************************************/\nvoid *\nxrdp_encoder_openh264_create(void)\n{\n    struct openh264_global *og;\n    struct xrdp_tconfig_gfx gfxconfig;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_encoder_openh264_create:\");\n    og = g_new0(struct openh264_global, 1);\n    tconfig_load_gfx(GFX_CONF, &gfxconfig);\n    memcpy(&og->openh264_param, &gfxconfig.openh264_param,\n           sizeof(struct xrdp_tconfig_gfx_openh264_param) *\n           NUM_CONNECTION_TYPES);\n    return og;\n\n}\n\n/*****************************************************************************/\nint\nxrdp_encoder_openh264_delete(void *handle)\n{\n    struct openh264_global *og;\n    struct openh264_encoder *oe;\n    int index;\n\n    if (handle == NULL)\n    {\n        return 0;\n    }\n    og = (struct openh264_global *) handle;\n    for (index = 0; index < 16; index++)\n    {\n        oe = &(og->encoders[index]);\n        if (oe->openh264_enc_han != NULL)\n        {\n            WelsDestroySVCEncoder(oe->openh264_enc_han);\n        }\n        g_free(oe->yuvdata);\n    }\n    g_free(og);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_encoder_openh264_encode(void *handle, int session, int left, int top,\n                             int width, int height, int twidth, int theight,\n                             int format, const char *data,\n                             short *crects, int num_crects,\n                             char *cdata, int *cdata_bytes,\n                             int connection_type, int *flags_ptr)\n{\n    struct openh264_global *og;\n    struct openh264_encoder *oe;\n    const char *src8;\n    const char *src8a;\n    char *dst8;\n    char *dst8a;\n    char *dst8b;\n    char *dst8c;\n    int index;\n    int jndex;\n    int flags;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int ct; /* connection_type */\n    SSourcePicture pic1;\n    SFrameBSInfo info;\n    SLayerBSInfo *layer;\n    SEncParamExt encParamExt;\n    SSpatialLayerConfig *slc;\n    int status;\n    int layer_position;\n    char *write_location;\n    unsigned char *payload;\n    int size;\n    int lcdata_bytes;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_encoder_openh264_encode:\");\n    flags = 0;\n    og = (struct openh264_global *) handle;\n    oe = &(og->encoders[session % OPENH264_MAX_ENCODERS]);\n    /* validate connection type */\n    ct = connection_type;\n    if (ct > CONNECTION_TYPE_LAN || ct < CONNECTION_TYPE_MODEM)\n    {\n        ct = CONNECTION_TYPE_LAN;\n    }\n    if ((oe->openh264_enc_han == NULL) ||\n            (oe->width != width) || (oe->height != height))\n    {\n        if (oe->openh264_enc_han != NULL)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_encoder_openh264_encode: \"\n                \"WelsDestroySVCEncoder %p\", oe->openh264_enc_han);\n            WelsDestroySVCEncoder(oe->openh264_enc_han);\n            oe->openh264_enc_han = NULL;\n            g_free(oe->yuvdata);\n            oe->yuvdata = NULL;\n            flags |= 2;\n        }\n        if ((width > 0) && (height > 0))\n        {\n            status = WelsCreateSVCEncoder(&oe->openh264_enc_han);\n            if ((status != 0) || (oe->openh264_enc_han == NULL))\n            {\n                LOG(LOG_LEVEL_ERROR, \"Failed to create H.264 encoder\");\n                return 1;\n            }\n            LOG(LOG_LEVEL_INFO, \"xrdp_encoder_openh264_encode: \"\n                \"WelsCreateSVCEncoder rv %p for width %d height %d\",\n                oe->openh264_enc_han, width, height);\n            status = ENC_GET_DEFAULT_PARAMS(\n                         oe->openh264_enc_han, &encParamExt);\n            LOG(LOG_LEVEL_INFO, \"xrdp_encoder_openh264_encode: \"\n                \"GetDefaultParams rv %d\", status);\n            if (status == 0)\n            {\n                encParamExt.iUsageType = CAMERA_VIDEO_REAL_TIME;\n                encParamExt.iPicWidth = (width + 15) & ~15;\n                encParamExt.iPicHeight = (height + 15) & ~15;\n                encParamExt.iRCMode = RC_BITRATE_MODE;\n                encParamExt.iSpatialLayerNum = 1;\n                /* Set encode parameters from config */\n                encParamExt.bEnableFrameSkip = og->openh264_param[ct].EnableFrameSkip;\n                encParamExt.iTargetBitrate = og->openh264_param[ct].TargetBitrate;\n                encParamExt.iMaxBitrate = og->openh264_param[ct].MaxBitrate;\n                encParamExt.fMaxFrameRate = og->openh264_param[ct].MaxFrameRate;\n                /* defaults to INCREASING_ID, Mac client needs CONSTANT_ID */\n                encParamExt.eSpsPpsIdStrategy = CONSTANT_ID;\n                slc = encParamExt.sSpatialLayers + 0;\n                slc->fFrameRate = encParamExt.fMaxFrameRate;\n                slc->iVideoWidth = encParamExt.iPicWidth;\n                slc->iVideoHeight = encParamExt.iPicHeight;\n                slc->iSpatialBitrate = encParamExt.iTargetBitrate;\n                slc->iMaxSpatialBitrate = encParamExt.iMaxBitrate;\n                status = ENC_INITIALIZE_EXT(\n                             oe->openh264_enc_han, &encParamExt);\n                LOG(LOG_LEVEL_INFO, \"xrdp_encoder_openh264_encode: \"\n                    \"InitializeExt rv %d\", status);\n            }\n            oe->yuvdata = g_new(char, (width + 16) * (height + 16) * 2);\n            if (oe->yuvdata == NULL)\n            {\n                WelsDestroySVCEncoder(oe->openh264_enc_han);\n                oe->openh264_enc_han = NULL;\n                return 2;\n            }\n            flags |= 1;\n        }\n        oe->width = width;\n        oe->height = height;\n    }\n\n    if ((data != NULL) && (oe->openh264_enc_han != NULL))\n    {\n        g_memset(&pic1, 0, sizeof(pic1));\n        pic1.iPicWidth = (width + 15) & ~15;\n        pic1.iPicHeight = (height + 15) & ~15;\n        pic1.iColorFormat = videoFormatI420;\n        pic1.iStride[0] = pic1.iPicWidth;\n        pic1.iStride[1] = pic1.iPicWidth / 2;\n        pic1.iStride[2] = pic1.iPicWidth / 2;\n        pic1.pData[0] = (unsigned char *) (oe->yuvdata);\n        pic1.pData[1] = pic1.pData[0] + pic1.iPicWidth * pic1.iPicHeight;\n        pic1.pData[2] = pic1.pData[1] + (pic1.iPicWidth / 2) *\n                        (pic1.iPicHeight / 2);\n        for (index = 0; index < num_crects; index++)\n        {\n            src8 = data;\n            dst8 = (char *) (pic1.pData[0]);\n            x = crects[index * 4 + 0];\n            y = crects[index * 4 + 1];\n            cx = crects[index * 4 + 2];\n            cy = crects[index * 4 + 3];\n            LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_encoder_openh264_encode: \"\n                      \"x %d y %d cx %d cy %d\", x, y, cx, cy);\n            src8 += twidth * y + x;\n            dst8 += pic1.iStride[0] * (y - top) + (x - left);\n            for (; cy > 0; cy -= 1)\n            {\n                g_memcpy(dst8, src8, cx);\n                src8 += twidth;\n                dst8 += pic1.iStride[0];\n            }\n        }\n        for (index = 0; index < num_crects; index++)\n        {\n            src8 = data; /* uv */\n            src8 += twidth * theight;\n            dst8 = (char *) (pic1.pData[1]); /* u */\n            dst8a = (char *) (pic1.pData[2]); /* v */\n            x = crects[index * 4 + 0];\n            y = crects[index * 4 + 1];\n            cx = crects[index * 4 + 2];\n            cy = crects[index * 4 + 3];\n            src8 += twidth * (y / 2) + x;\n            dst8 += pic1.iStride[1] * ((y - top) / 2) + ((x - left) / 2);\n            dst8a += pic1.iStride[2] * ((y - top) / 2) + ((x - left) / 2);\n            for (; cy > 0; cy -= 2)\n            {\n                src8a = src8; /* uv */\n                dst8b = dst8; /* u */\n                dst8c = dst8a; /* v */\n                for (jndex = 0; jndex < cx; jndex += 2)\n                {\n                    *(dst8b++) = *(src8a++); /* u */\n                    *(dst8c++) = *(src8a++); /* v */\n                }\n                src8 += twidth; /* uv */\n                dst8 += pic1.iStride[1]; /* u */\n                dst8a += pic1.iStride[2]; /* v */\n            }\n        }\n        g_memset(&info, 0, sizeof(info));\n        status = ENC_ENCODE_FRAME(oe->openh264_enc_han, &pic1, &info);\n        if (status != 0)\n        {\n            LOG(LOG_LEVEL_TRACE, \"OpenH264: Failed to encode frame\");\n            return 3;\n        }\n        if (info.eFrameType == videoFrameTypeSkip)\n        {\n            LOG(LOG_LEVEL_TRACE, \"OpenH264: frame was skipped!\");\n            return 4;\n        }\n        lcdata_bytes = 0;\n        for (index = 0; index < info.iLayerNum; index++)\n        {\n            layer_position = 0;\n            layer = info.sLayerInfo + index;\n            for (jndex = 0; jndex < layer->iNalCount; jndex++)\n            {\n                write_location = cdata + lcdata_bytes;\n                payload = layer->pBsBuf + layer_position;\n                size = layer->pNalLengthInByte[jndex];\n                if (lcdata_bytes + size > *cdata_bytes)\n                {\n                    LOG(LOG_LEVEL_INFO, \"out of room\");\n                    return 5;\n                }\n                g_memcpy(write_location, payload, size);\n                layer_position += size;\n                lcdata_bytes += size;\n            }\n        }\n        *cdata_bytes = lcdata_bytes;\n    }\n    if (flags_ptr != NULL)\n    {\n        *flags_ptr = flags;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_encoder_openh264_install_ok(void)\n{\n    int rv;\n\n    // Declare something with maximal alignment we can take the address\n    // of to pass to WelsCreateSVCEncoder. This object is not directly\n    // accessed.\n    //\n    // Note we can't use the ISVCEncoder type directly, as in C++ this\n    // is an abstract class.\n    long double dummy;\n\n    ISVCEncoder *p = (ISVCEncoder *)&dummy;\n\n    // The real OpenH264 library will ALWAYS change the value of the\n    // passed-in pointer\n    // The noopenh264 library will NEVER change the value of the passed-in\n    // pointer\n    // For both libraries, the relevant source is in\n    // codec/encoder/plus/src/welsEncoderExt.cpp\n    WelsCreateSVCEncoder(&p);\n    rv = (p != (ISVCEncoder *)&dummy); // Did the passed-in value change\n    // If p is &dummy or NULL, this call does nothing, otherwise resources\n    // are deallocated.\n    WelsDestroySVCEncoder(p);\n\n    return rv;\n}\n"
  },
  {
    "path": "xrdp/xrdp_encoder_openh264.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2016-2024\n * Copyright (C) Christopher Pitstick 2023-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * openh264 Encoder\n */\n\n#ifndef _XRDP_ENCODER_OPENH264_H\n#define _XRDP_ENCODER_OPENH264_H\n\n#include \"arch.h\"\n\nvoid *\nxrdp_encoder_openh264_create(void);\nint\nxrdp_encoder_openh264_delete(void *handle);\nint\nxrdp_encoder_openh264_encode(void *handle, int session, int left, int top,\n                             int width, int height, int twidth, int theight,\n                             int format, const char *data,\n                             short *crects, int num_crects,\n                             char *cdata, int *cdata_bytes,\n                             int connection_type, int *flags_ptr);\n\n/**\n * Test OpenH264 library is installed correctly\n *\n * It's possible on some distros to install the noopenh264 package\n * (https://gitlab.com/freedesktop-sdk/noopenh264) for building. If this\n * is installed at runtime, openh264 cannot be used.\n * @return Boolean (!= 0 -> working)\n */\nint\nxrdp_encoder_openh264_install_ok(void);\n\n#endif\n"
  },
  {
    "path": "xrdp/xrdp_encoder_x264.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2016-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * x264 Encoder\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#include <inttypes.h>\n#include <x264.h>\n\n#include \"xrdp.h\"\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"xrdp_encoder_x264.h\"\n#include \"xrdp_tconfig.h\"\n\n#define X264_MAX_ENCODERS 16\n\nstruct x264_encoder\n{\n    x264_t *x264_enc_han;\n    char *yuvdata;\n    x264_param_t x264_params;\n    int width;\n    int height;\n};\n\nstruct x264_global\n{\n    struct x264_encoder encoders[X264_MAX_ENCODERS];\n    struct xrdp_tconfig_gfx_x264_param x264_param[NUM_CONNECTION_TYPES];\n};\n\n/*****************************************************************************/\nvoid *\nxrdp_encoder_x264_create(void)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_encoder_x264_create:\");\n\n    struct x264_global *xg;\n    struct xrdp_tconfig_gfx gfxconfig;\n    xg = g_new0(struct x264_global, 1);\n    tconfig_load_gfx(GFX_CONF, &gfxconfig);\n\n    memcpy(&xg->x264_param, &gfxconfig.x264_param,\n           sizeof(struct xrdp_tconfig_gfx_x264_param) * NUM_CONNECTION_TYPES);\n\n    return xg;\n\n}\n\n/*****************************************************************************/\nint\nxrdp_encoder_x264_delete(void *handle)\n{\n    struct x264_global *xg;\n    struct x264_encoder *xe;\n    int index;\n\n    if (handle == NULL)\n    {\n        return 0;\n    }\n    xg = (struct x264_global *) handle;\n    for (index = 0; index < 16; index++)\n    {\n        xe = &(xg->encoders[index]);\n        if (xe->x264_enc_han != NULL)\n        {\n            x264_encoder_close(xe->x264_enc_han);\n        }\n        g_free(xe->yuvdata);\n    }\n    g_free(xg);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_encoder_x264_encode(void *handle, int session, int left, int top,\n                         int width, int height, int twidth, int theight,\n                         int format, const char *data,\n                         short *crects, int num_crects,\n                         char *cdata, int *cdata_bytes, int connection_type,\n                         int *flags_ptr)\n{\n    struct x264_global *xg;\n    struct x264_encoder *xe;\n    const char *src8;\n    char *dst8;\n    int index;\n    x264_nal_t *nals;\n    int num_nals;\n    int frame_size;\n    int x264_width_height;\n    int flags;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int ct; /* connection_type */\n\n    x264_picture_t pic_in;\n    x264_picture_t pic_out;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_encoder_x264_encode:\");\n    flags = 0;\n    xg = (struct x264_global *) handle;\n    xe = &(xg->encoders[session % X264_MAX_ENCODERS]);\n\n    /* validate connection type */\n    ct = connection_type;\n    if (ct > CONNECTION_TYPE_LAN || ct < CONNECTION_TYPE_MODEM)\n    {\n        ct = CONNECTION_TYPE_LAN;\n    }\n\n    if ((xe->x264_enc_han == NULL) ||\n            (xe->width != width) || (xe->height != height))\n    {\n        if (xe->x264_enc_han != NULL)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_encoder_x264_encode: \"\n                \"x264_encoder_close %p\", xe->x264_enc_han);\n            x264_encoder_close(xe->x264_enc_han);\n            xe->x264_enc_han = NULL;\n            g_free(xe->yuvdata);\n            xe->yuvdata = NULL;\n            flags |= 2;\n        }\n        if ((width > 0) && (height > 0))\n        {\n            x264_param_default_preset(&(xe->x264_params),\n                                      xg->x264_param[ct].preset,\n                                      xg->x264_param[ct].tune);\n            xe->x264_params.i_threads = xg->x264_param[ct].threads;\n            xe->x264_params.i_width = (width + 15) & ~15;\n            xe->x264_params.i_height = (height + 15) & ~15;\n            xe->x264_params.i_fps_num = xg->x264_param[ct].fps_num;\n            xe->x264_params.i_fps_den = xg->x264_param[ct].fps_den;\n            xe->x264_params.rc.i_rc_method = X264_RC_CRF;\n            xe->x264_params.rc.i_vbv_max_bitrate = xg->x264_param[ct].vbv_max_bitrate;\n            xe->x264_params.rc.i_vbv_buffer_size = xg->x264_param[ct].vbv_buffer_size;\n            x264_param_apply_profile(&(xe->x264_params),\n                                     xg->x264_param[ct].profile);\n            xe->x264_enc_han = x264_encoder_open(&(xe->x264_params));\n            LOG(LOG_LEVEL_INFO, \"xrdp_encoder_x264_encode: \"\n                \"x264_encoder_open rv %p for width %d height %d\",\n                xe->x264_enc_han, width, height);\n            if (xe->x264_enc_han == NULL)\n            {\n                return 1;\n            }\n            xe->yuvdata = g_new(char, width * height * 2);\n            if (xe->yuvdata == NULL)\n            {\n                x264_encoder_close(xe->x264_enc_han);\n                xe->x264_enc_han = NULL;\n                return 2;\n            }\n            flags |= 1;\n        }\n        xe->width = width;\n        xe->height = height;\n    }\n\n    if ((data != NULL) && (xe->x264_enc_han != NULL))\n    {\n        x264_width_height = xe->x264_params.i_width * xe->x264_params.i_height;\n        for (index = 0; index < num_crects; index++)\n        {\n            src8 = data;\n            dst8 = xe->yuvdata;\n            x = crects[index * 4 + 0];\n            y = crects[index * 4 + 1];\n            cx = crects[index * 4 + 2];\n            cy = crects[index * 4 + 3];\n            LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_encoder_x264_encode: x %d y %d \"\n                      \"cx %d cy %d\", x, y, cx, cy);\n            src8 += twidth * y + x;\n            dst8 += xe->x264_params.i_width * (y - top) + (x - left);\n            for (; cy > 0; cy -= 1)\n            {\n                g_memcpy(dst8, src8, cx);\n                src8 += twidth;\n                dst8 += xe->x264_params.i_width;\n            }\n        }\n        for (index = 0; index < num_crects; index++)\n        {\n            src8 = data;\n            src8 += twidth * theight;\n            dst8 = xe->yuvdata;\n            dst8 += x264_width_height;\n            x = crects[index * 4 + 0];\n            y = crects[index * 4 + 1];\n            cx = crects[index * 4 + 2];\n            cy = crects[index * 4 + 3];\n            src8 += twidth * (y / 2) + x;\n            dst8 += xe->x264_params.i_width * ((y - top) / 2) + (x - left);\n            for (; cy > 0; cy -= 2)\n            {\n                g_memcpy(dst8, src8, cx);\n                src8 += twidth;\n                dst8 += xe->x264_params.i_width;\n            }\n        }\n        g_memset(&pic_in, 0, sizeof(pic_in));\n        pic_in.img.i_csp = X264_CSP_NV12;\n        pic_in.img.i_plane = 2;\n        pic_in.img.plane[0] = (unsigned char *) (xe->yuvdata);\n        pic_in.img.plane[1] = (unsigned char *)\n                              (xe->yuvdata + x264_width_height);\n        pic_in.img.i_stride[0] = xe->x264_params.i_width;\n        pic_in.img.i_stride[1] = xe->x264_params.i_width;\n        num_nals = 0;\n        frame_size = x264_encoder_encode(xe->x264_enc_han, &nals, &num_nals,\n                                         &pic_in, &pic_out);\n        LOG(LOG_LEVEL_TRACE, \"i_type %d\", pic_out.i_type);\n        if (frame_size < 1)\n        {\n            return 3;\n        }\n        if (*cdata_bytes < frame_size)\n        {\n            return 4;\n        }\n        g_memcpy(cdata, nals[0].p_payload, frame_size);\n        *cdata_bytes = frame_size;\n    }\n    if (flags_ptr != NULL)\n    {\n        *flags_ptr = flags;\n    }\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/xrdp_encoder_x264.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2016-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libx264 Encoder\n */\n\n#ifndef _XRDP_ENCODER_X264_H\n#define _XRDP_ENCODER_X264_H\n\n#include \"arch.h\"\n\nvoid *\nxrdp_encoder_x264_create(void);\nint\nxrdp_encoder_x264_delete(void *handle);\nint\nxrdp_encoder_x264_encode(void *handle, int session, int left, int top,\n                         int width, int height, int twidth, int theight,\n                         int format, const char *data,\n                         short *crects, int num_crects,\n                         char *cdata, int *cdata_bytes, int connection_type,\n                         int *flags_ptr);\n\n#endif\n\n"
  },
  {
    "path": "xrdp/xrdp_font.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * fonts\n */\n\n/* fv1 files are described in fontutils/README_fv1.txt */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <ctype.h>\n\n#include \"xrdp.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n\n#if 0 /* not used */\nstatic char w_char[] =\n{\n    0x00, 0x00, 0x00, // ........................\n    0x00, 0x00, 0x00, // ........................\n    0x00, 0x00, 0x00, // ........................\n    0x08, 0x20, 0x80, // ....X.....X.....X.......\n    0x08, 0x50, 0x80, // ....X....X.X....X.......\n    0x04, 0x51, 0x00, // .....X...X.X...X........\n    0x04, 0x51, 0x00, // .....X...X.X...X........\n    0x04, 0x51, 0x00, // .....X...X.X...X........\n    0x02, 0x8a, 0x00, // ......X.X...X.X.........\n    0x02, 0x8a, 0x00, // ......X.X...X.X.........\n    0x02, 0x8a, 0x00, // ......X.X...X.X.........\n    0x01, 0x04, 0x00, // .......X.....X..........\n    0x01, 0x04, 0x00, // .......X.....X..........\n    0x00, 0x00, 0x00, // ........................\n    0x00, 0x00, 0x00, // ........................\n    0x00, 0x00, 0x00, // ........................\n};\n#endif\n\n// First character allocated in the 'struct xrdp_font.chars' array\n#define FIRST_CHAR ' '\n\n/*****************************************************************************/\n/**\n * Parses the fv1_select configuration value to get the font to use,\n * based on the DPI of the primary monitor\n *\n * @param globals Configuration globals\n * @param dpi DPI of primary monitor. If not known, a suitable\n *            default should be passed in here.\n * @param[out] font_name Name of font to use\n * @param[in] font_name_len Length of font name buffer\n */\nstatic void\nget_font_name_from_dpi(const struct xrdp_cfg_globals *globals,\n                       unsigned int dpi,\n                       char *font_name, int font_name_len)\n{\n    int bad_selector = 0;\n\n    font_name[0] = '\\0';\n\n    const char *fv1_select = globals->fv1_select;\n    if (fv1_select == NULL || fv1_select[0] == '\\0')\n    {\n        fv1_select = DEFAULT_FV1_SELECT;\n    }\n\n    const char *p = fv1_select;\n\n    while (p != NULL)\n    {\n        /* DPI value must be next in string */\n        if (!isdigit(*p))\n        {\n            bad_selector = 1;\n            break;\n        }\n        unsigned int field_dpi = g_atoi(p);\n        if (field_dpi <= dpi)\n        {\n            /* Use this font */\n            p = g_strchr(p, ':');\n            if (p == NULL)\n            {\n                bad_selector = 1;\n            }\n            else\n            {\n                ++p;\n                const char *q = g_strchr(p, ',');\n                if (q == NULL)\n                {\n                    q = p + g_strlen(p);\n                }\n                if (q - p > (font_name_len - 1))\n                {\n                    q = p + font_name_len - 1;\n                }\n                g_memcpy(font_name, p, q - p);\n                font_name[q - p] = '\\0';\n            }\n            break;\n        }\n        else\n        {\n            p = g_strchr(p, ',');\n            if (p != NULL)\n            {\n                ++p;\n            }\n        }\n    }\n\n    if (bad_selector)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Unable to parse fv1_select configuration\");\n    }\n\n    if (font_name[0] == '\\0')\n    {\n        LOG(LOG_LEVEL_WARNING, \"Loading default font \" DEFAULT_FONT_NAME);\n        g_snprintf(font_name, font_name_len, DEFAULT_FONT_NAME);\n    }\n}\n\n/*****************************************************************************/\nstruct xrdp_font *\nxrdp_font_create(struct xrdp_wm *wm, unsigned int dpi)\n{\n    struct xrdp_font *self;\n    struct stream *s;\n    int fd;\n    int b;\n    int i;\n    unsigned int char_count;\n    unsigned int datasize; // Size of glyph data on disk\n    int file_size;\n    struct xrdp_font_char *f;\n    const char *file_path;\n    char file_path_buff[256];\n    int min_descender;\n    char font_name[256];\n    const struct xrdp_cfg_globals *globals = &wm->xrdp_config->cfg_globals;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"in xrdp_font_create\");\n\n    if (dpi == 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"No DPI value is available to find login font\");\n        dpi = globals->default_dpi;\n        LOG(LOG_LEVEL_WARNING, \"Using the default_dpi of %u\", dpi);\n    }\n    get_font_name_from_dpi(globals, dpi, font_name, sizeof(font_name));\n\n    if (font_name[0] == '/')\n    {\n        /* User specified absolute path */\n        file_path = font_name;\n    }\n    else\n    {\n        g_snprintf(file_path_buff, sizeof(file_path_buff),\n                   XRDP_SHARE_PATH \"/%s\",\n                   font_name);\n        file_path = file_path_buff;\n    }\n\n    if (!g_file_exist(file_path))\n    {\n        /* Try to fall back to the default */\n        const char *default_file_path = XRDP_SHARE_PATH \"/\" DEFAULT_FONT_NAME;\n        if (g_file_exist(default_file_path))\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"xrdp_font_create: font file [%s] does not exist - using [%s]\",\n                file_path, default_file_path);\n            file_path = default_file_path;\n        }\n        else\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"xrdp_font_create: Can't load either [%s] or [%s]\",\n                file_path, default_file_path);\n            return 0;\n        }\n    }\n\n    file_size = g_file_get_size(file_path);\n\n    if (file_size < 1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_font_create: error reading font from file [%s]\",\n            file_path);\n        return 0;\n    }\n\n    self = (struct xrdp_font *)g_malloc(sizeof(struct xrdp_font), 1);\n    if (self == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_font_create: \"\n            \"Can't allocate memory for font\");\n        return self;\n    }\n    self->wm = wm;\n    make_stream(s);\n    init_stream(s, file_size + 1024);\n    fd = g_file_open_ro(file_path);\n\n    if (fd < 0)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"xrdp_font_create: Can't open %s - %s\", file_path,\n            g_get_strerror());\n        g_free(self);\n        self = NULL;\n    }\n    else\n    {\n        b = g_file_read(fd, s->data, file_size + 1024);\n        g_file_close(fd);\n\n        // Got at least a header?\n        if (b < (4 + 32 + 2 + 2 + 2 + 2 + 4))\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"xrdp_font_create: Font %s is truncated\", file_path);\n            g_free(self);\n            self = NULL;\n        }\n        else\n        {\n            s->end = s->data + b;\n            in_uint8s(s, 4);\n            in_uint8a(s, self->name, 32);\n            in_uint16_le(s, self->size);\n            in_uint16_le(s, self->style);\n            in_uint16_le(s, self->body_height);\n            in_sint16_le(s, min_descender);\n            in_uint8s(s, 4);\n            char_count = FIRST_CHAR;\n\n            while (!s_check_end(s))\n            {\n                if (!s_check_rem(s, 16))\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"xrdp_font_create: \"\n                        \"Can't parse header for character U+%X\", char_count);\n                    break;\n                }\n\n                if (char_count >= MAX_FONT_CHARS)\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"xrdp_font_create: \"\n                        \"Ignoring characters >= U+%x\", MAX_FONT_CHARS);\n                    break;\n                }\n\n                f = self->chars + char_count;\n                in_sint16_le(s, i);\n                f->width = i;\n                in_sint16_le(s, i);\n                f->height = i;\n                in_sint16_le(s, i);\n                /* Move the glyph up so there are no descenders */\n                f->baseline = i + min_descender;\n                in_sint16_le(s, i);\n                f->offset = i;\n                in_sint16_le(s, i);\n                f->incby = i;\n                in_uint8s(s, 6);\n                datasize = FONT_DATASIZE(f);\n\n                if (datasize > 512)\n                {\n                    /* shouldn't happen */\n                    LOG(LOG_LEVEL_ERROR,\n                        \"xrdp_font_create: \"\n                        \"datasize for U+%x wrong \"\n                        \"width %d, height %d, datasize %u\",\n                        char_count, f->width, f->height, datasize);\n                    break;\n                }\n\n                if (!s_check_rem(s, datasize))\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"xrdp_font_create: \"\n                        \"Not enough data for character U+%X\", char_count);\n                    break;\n                }\n\n                if (datasize == 0)\n                {\n                    /* Allocate a single blank pixel for the glyph, so\n                     * that it can be added to the glyph cache if required */\n                    f->width = 1;\n                    f->height = 1;\n\n                    /* GOTCHA - we need to allocate more than one byte in\n                     * memory for this glyph */\n                    f->data = (char *)g_malloc(FONT_DATASIZE(f), 1);\n                }\n                else\n                {\n                    f->data = (char *)g_malloc(datasize, 0);\n                }\n\n                if (f->data == NULL)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"xrdp_font_create: \"\n                        \"Allocation error for character U+%X\", char_count);\n                    break;\n                }\n                in_uint8a(s, f->data, datasize);\n\n                ++char_count;\n            }\n\n            self->char_count = char_count;\n            if (char_count <= FIRST_CHAR)\n            {\n                /* We read no characters from the font */\n                xrdp_font_delete(self);\n                self = NULL;\n            }\n            else\n            {\n                if (self->body_height == 0)\n                {\n                    /* Older font made for xrdp v0.9.x. Synthesise this\n                     * value from the first glyph */\n                    self->body_height = -self->chars[FIRST_CHAR].baseline + 1;\n                }\n\n                // Find a default glyph\n                if (char_count > UCS_WHITE_SQUARE)\n                {\n                    self->default_char = &self->chars[UCS_WHITE_SQUARE];\n                }\n                else if (char_count > '?')\n                {\n                    self->default_char = &self->chars['?'];\n                }\n                else\n                {\n                    self->default_char = &self->chars[FIRST_CHAR];\n                }\n            }\n        }\n    }\n\n    free_stream(s);\n    /*\n      self->font_items[0].offset = -4;\n      self->font_items[0].baseline = -16;\n      self->font_items[0].width = 24;\n      self->font_items[0].height = 16;\n      self->font_items[0].data = g_malloc(3 * 16, 0);\n      g_memcpy(self->font_items[0].data, w_char, 3 * 16);\n    */\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"out xrdp_font_create\");\n    return self;\n}\n\n/*****************************************************************************/\n/* free the font and all the items */\nvoid\nxrdp_font_delete(struct xrdp_font *self)\n{\n    unsigned int i;\n\n    if (self == 0)\n    {\n        return;\n    }\n\n    for (i = FIRST_CHAR; i < self->char_count; i++)\n    {\n        g_free(self->chars[i].data);\n    }\n\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* compare the two font items returns 1 if they match */\nint\nxrdp_font_item_compare(struct xrdp_font_char *font1,\n                       struct xrdp_font_char *font2)\n{\n    int datasize;\n\n    if (font1 == 0)\n    {\n        return 0;\n    }\n\n    if (font2 == 0)\n    {\n        return 0;\n    }\n\n    if (font1->offset != font2->offset)\n    {\n        return 0;\n    }\n\n    if (font1->baseline != font2->baseline)\n    {\n        return 0;\n    }\n\n    if (font1->width != font2->width)\n    {\n        return 0;\n    }\n\n    if (font1->height != font2->height)\n    {\n        return 0;\n    }\n\n    datasize = FONT_DATASIZE(font1);\n\n    if (g_memcmp(font1->data, font2->data, datasize) == 0)\n    {\n        return 1;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/xrdp_keyboard.toml",
    "content": "#\n# RDP Keyboard <-> X11 Keyboard layout map (xorgxrdp support)\n#\n# How this file works\n# -------------------\n#\n#   Inputs from the RDP client:-\n#   - Keyboard type 'kb_type' (see below)\n#   - Keyboard subtype 'kb_subtype' (see below)\n#   - RDP layout identifier 'layout_id' (see [MS-LCID])\n#\n#   1. The following values are read from the [defaults] table:-\n#       - layouts   Required. The name of the table which translates the\n#                   layout_id to a layout_name, using reverse-lookup.\n#       - map       Required. A table mapping layout names to XKB\n#                   layout strings.\n#       - model     Optional. Value defining the XKB model name\n#       - variant   Optional. Value defining the XKB variant name\n#       - options   Optional. Value defining the XKB options string\n#\n#   2. The [overrides] sub-tables are scanned:-\n#      a) The [overrides.kb_type.*] tables are scanned looking for a\n#         match on kb_type, kb_subtype, or both. A successful match\n#         results in overrides being applied to the values described in 1.\n#\n#      Other table names directly under the [overrides] table are reserved\n#      for future use.\n#\n#   3. The ['layouts'] table is reverse-looked-up to get a layout_name using\n#      the 'layout_id'.\n#   4. The ['map'] table is looked-up by the layout_name to get an XKB\n#      layout for the session.\n#\n# There are some subtleties:-\n#   1. (In step 3) If a layout_id > 0xffff fails to match, the lookup\n#      is retried with the lower 16-bits of the layout_id.\n#   2. (In step 2). More than one layout_id can be mapped to the\n#      same layout_name using an array of values.\n#\n#       RDP Keyboard Type [MS-RDPBCGR] section 2.2.7.1.6\n#       ------------------------------------------------\n#\n#          0 is not a valid value\n#\n#          1 - IBM PC/XT or compatible (83-key) keyboard\n#          2 - Olivetti \"ICO\" (102-key) keyboard\n#          3 - IBM PC/AT (84-key) or similar keyboard\n#          4 - IBM enhanced (101- or 102-key) keyboard\n#          5 - Nokia 1050 and similar keyboards\n#          6 - Nokia 9140 and similar keyboards\n#          7 - Japanese keyboard\n#\n#       RDP Keyboard Subtype\n#       --------------------\n#       This is vendor dependent. XRDP defines as follows:\n#\n#          0 is not a valid value\n#\n#          1 - Standard\n#          2 - FreeRDP JP keyboard\n#          3 - Macintosh\n#          ... - < any vendor dependent subtype >\n#\n#       The list can be augmented.\n\n[defaults]\nlayouts = \"layouts\"\nmap = \"default_layouts_map\"\n# user can set these values, but generally they should be inferred\n# automatically based on keyboard type and subtype\n#model = \n#variant = \n#options = \n\n[overrides.kb_type.mac]\n# Mac - set a variant and alternate layouts map\nsubtype = 3\nmap = \"mac_layouts_map\"\nvariant = \"mac\"\n\n[overrides.kb_type.jp]\n# Japanese - set the keyboard model\ntype = 7\nsubtype = 2\nmodel = \"pc105\"\n\n[layouts]\nrdp_layout_us = 0x00000409\nrdp_layout_us_colemak = 0x00060409\nrdp_layout_us_dvorak = 0x00010409\nrdp_layout_us_dvp = 0x19360409\nrdp_layout_cz = 0x00000405\nrdp_layout_dk = 0x00000406\nrdp_layout_de = 0x00000407\nrdp_layout_es = 0x0000040A\nrdp_layout_fi = 0x0000040B\nrdp_layout_fr = 0x0000040C\nrdp_layout_hu = 0x0000040E\nrdp_layout_it = 0x00000410\nrdp_layout_jp = [ 0x00000411, 0xe0010411, 0xe0200411, 0xe0210411 ]\nrdp_layout_kr = 0x00000412\nrdp_layout_no = 0x00000414\nrdp_layout_pl = 0x00000415\nrdp_layout_br = 0x00000416\nrdp_layout_ru = 0x00000419\nrdp_layout_se = 0x0000041D\nrdp_layout_si = 0x00000424\nrdp_layout_lv = 0x00000426\nrdp_layout_lv_std = [ 0x00010426, 0x00020426 ]\nrdp_layout_ch = 0x00000807\nrdp_layout_ch_fr = 0x0000100C\nrdp_layout_gb = 0x00000809\nrdp_layout_latam = 0x0000080A\nrdp_layout_be = 0x00000813\nrdp_layout_pt = 0x00000816\n\n\n# <rdp layout name> = <X11 keyboard layout value>\n[default_layouts_map]\nrdp_layout_us = \"us\"\nrdp_layout_us_colemak = \"us(colemak)\"\nrdp_layout_us_dvorak = \"us(dvorak)\"\nrdp_layout_us_dvp = \"us(dvp)\"\nrdp_layout_cz = \"cz\"\nrdp_layout_dk = \"dk\"\nrdp_layout_de = \"de\"\nrdp_layout_es = \"es\"\nrdp_layout_fi = \"fi\"\nrdp_layout_fr = \"fr\"\nrdp_layout_hu = \"hu\"\nrdp_layout_it = \"it\"\nrdp_layout_jp = \"jp\"\nrdp_layout_kr = \"kr\"\nrdp_layout_no = \"no\"\nrdp_layout_pl = \"pl\"\nrdp_layout_br = \"br(abnt2)\"\nrdp_layout_ru = \"ru\"\nrdp_layout_se = \"se\"\nrdp_layout_si = \"si\"\nrdp_layout_lv = \"lv(ergonomic)\"\nrdp_layout_lv_std = \"lv\"\nrdp_layout_ch = \"ch\"\nrdp_layout_ch_fr = \"ch(fr)\"\nrdp_layout_gb = \"gb\"\nrdp_layout_latam = \"latam\"\nrdp_layout_be = \"be\"\nrdp_layout_pt = \"pt\"\n\n[mac_layouts_map]\nrdp_layout_us = \"us\"\nrdp_layout_us_colemak = \"us(colemak)\"\nrdp_layout_us_dvorak = \"us(dvorak)\"\nrdp_layout_us_dvp = \"us(dvp)\"\nrdp_layout_cz = \"cz\"\nrdp_layout_dk = \"dk\"\nrdp_layout_de = \"de\"\nrdp_layout_es = \"es\"\nrdp_layout_fi = \"fi\"\nrdp_layout_fr = \"fr\"\nrdp_layout_hu = \"hu\"\nrdp_layout_it = \"it\"\nrdp_layout_jp = \"jp\"\nrdp_layout_kr = \"kr\"\nrdp_layout_pl = \"pl\"\nrdp_layout_br = \"br(abnt2)\"\nrdp_layout_ru = \"ru\"\nrdp_layout_se = \"se\"\nrdp_layout_si = \"si\"\nrdp_layout_lv = \"lv(ergonomic)\"\nrdp_layout_lv_std = \"lv\"\nrdp_layout_ch = \"ch\"\nrdp_layout_ch_fr = \"ch(fr)\"\nrdp_layout_gb = \"gb\"\nrdp_layout_latam = \"latam\"\nrdp_layout_be = \"be\"\nrdp_layout_pt = \"pt\"\n"
  },
  {
    "path": "xrdp/xrdp_listen.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * listen for incoming connection\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n\n/* 'g_process' is protected by the semaphore 'g_process_sem'.  One thread sets\n   g_process and waits for the other to process it */\nstatic tbus g_process_sem = 0;\nstatic struct xrdp_process *g_process = 0;\n\nint\nxrdp_listen_conn_in(struct trans *self, struct trans *new_self);\n\n/*****************************************************************************/\nstatic int\nxrdp_listen_create_pro_done(struct xrdp_listen *self)\n{\n    int pid;\n    char text[256];\n\n    pid = g_getpid();\n    g_snprintf(text, 255, \"xrdp_%8.8x_listen_pro_done_event\", pid);\n    self->pro_done_event = g_create_wait_obj(text);\n\n    if (self->pro_done_event == 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Failure creating pro_done_event\");\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstruct xrdp_listen *\nxrdp_listen_create(struct xrdp_startup_params *startup_params)\n{\n    struct xrdp_listen *self;\n\n    self = (struct xrdp_listen *)g_malloc(sizeof(struct xrdp_listen), 1);\n    xrdp_listen_create_pro_done(self);\n    self->trans_list = list_create();\n    self->process_list = list_create();\n    self->fork_list = list_create();\n    self->startup_params = startup_params;\n\n    if (g_process_sem == 0)\n    {\n        g_process_sem = tc_sem_create(0);\n    }\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_listen_delete(struct xrdp_listen *self)\n{\n    int index;\n    struct trans *ltrans;\n\n    if (self == NULL)\n    {\n        return;\n    }\n    if (self->trans_list != NULL)\n    {\n        for (index = 0; index < self->trans_list->count; index++)\n        {\n            ltrans = (struct trans *) list_get_item(self->trans_list, index);\n            trans_delete(ltrans);\n        }\n        list_delete(self->trans_list);\n    }\n\n    if (g_process_sem != 0)\n    {\n        tc_sem_delete(g_process_sem);\n        g_process_sem = 0;\n    }\n\n    g_delete_wait_obj(self->pro_done_event);\n    list_delete(self->process_list);\n    list_delete(self->fork_list);\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_listen_add_pro(struct xrdp_listen *self, struct xrdp_process *process)\n{\n    list_add_item(self->process_list, (tbus)process);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_listen_delete_done_pro(struct xrdp_listen *self)\n{\n    int i;\n    struct xrdp_process *pro;\n\n    for (i = self->process_list->count - 1; i >= 0; i--)\n    {\n        pro = (struct xrdp_process *)list_get_item(self->process_list, i);\n\n        if (pro != 0)\n        {\n            if (pro->status < 0)\n            {\n                xrdp_process_delete(pro);\n                list_remove_item(self->process_list, i);\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* i can't get stupid in_val to work, hum using global var for now */\nstatic THREAD_RV THREAD_CC\nxrdp_process_run(void *in_val)\n{\n    struct xrdp_process *process;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"process started\");\n    process = g_process;\n    g_process = 0;\n    tc_sem_inc(g_process_sem);\n    xrdp_process_main_loop(process);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"process done\");\n    return 0;\n}\n/*****************************************************************************/\nstatic int\nxrdp_listen_stop_all_listen(struct xrdp_listen *self)\n{\n    int index;\n    struct trans *ltrans;\n\n    if (self->trans_list == NULL)\n    {\n        return 0;\n    }\n    for (index = 0; index < self->trans_list->count; index++)\n    {\n        ltrans = (struct trans *)\n                 list_get_item(self->trans_list, index);\n        trans_delete(ltrans);\n    }\n    list_clear(self->trans_list);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_listen_parse_filename(char *strout, int strout_max,\n                           const char *strin, int strin_max)\n{\n    int count;\n    int in;\n    int strin_index;\n    int strout_index;\n\n    strin_index = 0;\n    strout_index = 0;\n    in = 0;\n    count = 0;\n    while ((strin_index < strin_max) && (strout_index < strout_max))\n    {\n        if (in)\n        {\n            if ((strin[strin_index] > ' ') && (strin[strin_index] != ','))\n            {\n                strout[strout_index++] = strin[strin_index++];\n                count++;\n                continue;\n            }\n            else\n            {\n                break;\n            }\n        }\n        else\n        {\n            if ((strin[strin_index] > ' ') && (strin[strin_index] != ','))\n            {\n                in = 1;\n                strout[strout_index++] = strin[strin_index++];\n                count++;\n                continue;\n            }\n        }\n        strin_index++;\n        count++;\n    }\n    strout[strout_index] = 0;\n    return count;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_listen_parse_integer(char *strout, int strout_max,\n                          const char *strin, int strin_max)\n{\n    int count;\n    int in;\n    int strin_index;\n    int strout_index;\n\n    strin_index = 0;\n    strout_index = 0;\n    in = 0;\n    count = 0;\n    while ((strin_index < strin_max) && (strout_index < strout_max))\n    {\n        if (in)\n        {\n            if ((strin[strin_index] >= '0') && (strin[strin_index] <= '9'))\n            {\n                strout[strout_index++] = strin[strin_index++];\n                count++;\n                continue;\n            }\n            else\n            {\n                break;\n            }\n        }\n        else\n        {\n            if ((strin[strin_index] >= '0') && (strin[strin_index] <= '9'))\n            {\n                in = 1;\n                strout[strout_index++] = strin[strin_index++];\n                count++;\n                continue;\n            }\n        }\n        strin_index++;\n        count++;\n    }\n    strout[strout_index] = 0;\n    return count;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_listen_parse_vsock(char *strout, int strout_max,\n                        const char *strin, int strin_max)\n{\n    int count;\n    int in;\n    int strin_index;\n    int strout_index;\n\n    strin_index = 0;\n    strout_index = 0;\n    in = 0;\n    count = 0;\n    while ((strin_index < strin_max) && (strout_index < strout_max))\n    {\n        if (in)\n        {\n            if ((strin[strin_index] >= '0') && (strin[strin_index] <= '9'))\n            {\n                strout[strout_index++] = strin[strin_index++];\n                count++;\n                continue;\n            }\n            else\n            {\n                break;\n            }\n        }\n        else\n        {\n            if (((strin[strin_index] >= '0') && (strin[strin_index] <= '9')) ||\n                    (strin[strin_index] == '-'))\n            {\n                in = 1;\n                strout[strout_index++] = strin[strin_index++];\n                count++;\n                continue;\n            }\n        }\n        strin_index++;\n        count++;\n    }\n    strout[strout_index] = 0;\n    return count;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_listen_parse_ipv4(char *strout, int strout_max,\n                       const char *strin, int strin_max)\n{\n    int count;\n    int in;\n    int strin_index;\n    int strout_index;\n\n    strin_index = 0;\n    strout_index = 0;\n    in = 0;\n    count = 0;\n    while ((strin_index < strin_max) && (strout_index < strout_max))\n    {\n        if (in)\n        {\n            if (((strin[strin_index] >= '0') && (strin[strin_index] <= '9')) ||\n                    (strin[strin_index] == '.'))\n            {\n                strout[strout_index++] = strin[strin_index++];\n                count++;\n                continue;\n            }\n            else\n            {\n                break;\n            }\n        }\n        else\n        {\n            if ((strin[strin_index] >= '0') && (strin[strin_index] <= '9'))\n            {\n                in = 1;\n                strout[strout_index++] = strin[strin_index++];\n                count++;\n                continue;\n            }\n        }\n        strin_index++;\n        count++;\n    }\n    strout[strout_index] = 0;\n    return count;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_listen_parse_ipv6(char *strout, int strout_max,\n                       const char *strin, int strin_max)\n{\n    int count;\n    int in;\n    int strin_index;\n    int strout_index;\n\n    strin_index = 0;\n    strout_index = 0;\n    in = 0;\n    count = 0;\n    while ((strin_index < strin_max) && (strout_index < strout_max))\n    {\n        if (in)\n        {\n            if (strin[strin_index] != '}')\n            {\n                strout[strout_index++] = strin[strin_index++];\n                count++;\n                continue;\n            }\n            else\n            {\n                break;\n            }\n        }\n        else\n        {\n            if (strin[strin_index] == '{')\n            {\n                in = 1;\n                strin_index++;\n                count++;\n                continue;\n            }\n        }\n        strin_index++;\n        count++;\n    }\n    strout[strout_index] = 0;\n    return count;\n}\n\n/*****************************************************************************/\n/* address and port are assumed 128 bytes */\nstatic int\nxrdp_listen_pp(struct xrdp_listen *self, int *index,\n               char *address, char *port, int *mode)\n{\n    struct xrdp_startup_params *startup_params;\n    const char *str;\n    const char *str_end;\n    int lindex;\n    int bytes;\n\n    startup_params = self->startup_params;\n    lindex = *index;\n    str = startup_params->port + lindex;\n    str_end = startup_params->port + g_strlen(startup_params->port);\n    while (str < str_end)\n    {\n        if (g_strncmp(str, \"unix://.\", 8) == 0)\n        {\n            str += 8;\n            lindex += 8;\n            address[0] = 0;\n            bytes = xrdp_listen_parse_filename(port, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            *mode = TRANS_MODE_UNIX;\n            *index = lindex;\n            return 0;\n        }\n        else if (g_strncmp(str, \"tcp://.:\", 8) == 0)\n        {\n            str += 8;\n            lindex += 8;\n            g_strncpy(address, \"127.0.0.1\", 127);\n            bytes = xrdp_listen_parse_integer(port, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            *mode = TRANS_MODE_TCP4;\n            *index = lindex;\n            return 0;\n        }\n        else if (g_strncmp(str, \"tcp://:\", 7) == 0)\n        {\n            str += 7;\n            lindex += 7;\n            g_strncpy(address, \"0.0.0.0\", 127);\n            bytes = xrdp_listen_parse_integer(port, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            *mode = TRANS_MODE_TCP4;\n            *index = lindex;\n            return 0;\n        }\n        else if (g_strncmp(str, \"tcp://\", 6) == 0)\n        {\n            str += 6;\n            lindex += 6;\n            bytes = xrdp_listen_parse_ipv4(address, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            bytes = xrdp_listen_parse_integer(port, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            *mode = TRANS_MODE_TCP4;\n            *index = lindex;\n            return 0;\n        }\n        else if (g_strncmp(str, \"tcp6://.:\", 9) == 0)\n        {\n            str += 9;\n            lindex += 9;\n            g_strncpy(address, \"::1\", 127);\n            bytes = xrdp_listen_parse_integer(port, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            *mode = TRANS_MODE_TCP6;\n            *index = lindex;\n            return 0;\n        }\n        else if (g_strncmp(str, \"tcp6://:\", 8) == 0)\n        {\n            str += 8;\n            lindex += 8;\n            g_strncpy(address, \"::\", 127);\n            bytes = xrdp_listen_parse_integer(port, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            *mode = TRANS_MODE_TCP6;\n            *index = lindex;\n            return 0;\n        }\n        else if (g_strncmp(str, \"tcp6://\", 7) == 0)\n        {\n            str += 7;\n            lindex += 7;\n            bytes = xrdp_listen_parse_ipv6(address, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            bytes = xrdp_listen_parse_integer(port, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            *mode = TRANS_MODE_TCP6;\n            *index = lindex;\n            return 0;\n        }\n        else if (g_strncmp(str, \"vsock://\", 8) == 0)\n        {\n            str += 8;\n            lindex += 8;\n            bytes = xrdp_listen_parse_vsock(address, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            bytes = xrdp_listen_parse_vsock(port, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            *mode = TRANS_MODE_VSOCK;\n            *index = lindex;\n            return 0;\n        }\n        else if ((str[0] >= '0') && (str[0] <= '9'))\n        {\n            g_strncpy(address, \"0.0.0.0\", 127);\n            bytes = xrdp_listen_parse_integer(port, 128, str, str_end - str);\n            str += bytes;\n            lindex += bytes;\n            if (startup_params->use_vsock)\n            {\n                *mode = TRANS_MODE_VSOCK;\n            }\n            else\n            {\n                *mode = TRANS_MODE_TCP;\n            }\n            *index = lindex;\n            return 0;\n        }\n        else\n        {\n            str++;\n            lindex++;\n        }\n    }\n    if (lindex == *index)\n    {\n        return 1;\n    }\n    if (str >= str_end)\n    {\n        return 1;\n    }\n    *index = lindex;\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns 0 if xrdp is listening correctly\n   returns 1 if xrdp is not listening correctly */\nint\nxrdp_listen_init(struct xrdp_listen *self)\n{\n    int mode; /* TRANS_MODE_TCP*, TRANS_MODE_UNIX, TRANS_MODE_VSOCK */\n    int error;\n    int cont;\n    int bytes;\n    int index;\n    struct trans *ltrans;\n    char address[128];\n    char port[128];\n    struct xrdp_startup_params *startup_params;\n\n    startup_params = self->startup_params;\n    index = 0;\n    cont = 1;\n    while (cont)\n    {\n        if (xrdp_listen_pp(self, &index, address, port, &mode) != 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_listen_pp done\");\n            cont = 0;\n            break;\n        }\n        LOG(LOG_LEVEL_INFO, \"address [%s] port [%s] mode %d\",\n            address, port, mode);\n        ltrans = trans_create(mode, 16, 16);\n        if (ltrans == NULL)\n        {\n            LOG(LOG_LEVEL_ERROR, \"trans_create failed\");\n            xrdp_listen_stop_all_listen(self);\n            return 1;\n        }\n        LOG(LOG_LEVEL_INFO, \"listening to port %s on %s\",\n            port, address);\n        error = trans_listen_address(ltrans, port, address);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"trans_listen_address failed\");\n            trans_delete(ltrans);\n            xrdp_listen_stop_all_listen(self);\n            return 1;\n        }\n        if ((mode == TRANS_MODE_TCP) ||\n                (mode == TRANS_MODE_TCP4) ||\n                (mode == TRANS_MODE_TCP6))\n        {\n            if (startup_params->tcp_nodelay)\n            {\n                if (g_tcp_set_no_delay(ltrans->sck))\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Error setting tcp_nodelay\");\n                }\n            }\n            if (startup_params->tcp_keepalive)\n            {\n                if (g_tcp_set_keepalive(ltrans->sck))\n                {\n                    LOG(LOG_LEVEL_ERROR, \"Error setting \"\n                        \"tcp_keepalive\");\n                }\n            }\n            if (startup_params->tcp_send_buffer_bytes > 0)\n            {\n                bytes = startup_params->tcp_send_buffer_bytes;\n                if (g_sck_set_send_buffer_bytes(ltrans->sck, bytes) != 0)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"error setting send buffer\");\n                }\n                else if (g_sck_get_send_buffer_bytes(ltrans->sck, &bytes) != 0)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"error getting send buffer\");\n                }\n                else if (bytes != startup_params->tcp_send_buffer_bytes)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"send buffer set to %d \"\n                        \"bytes but %d bytes requested\", bytes,\n                        startup_params->tcp_send_buffer_bytes);\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_INFO, \"send buffer set to %d bytes\", bytes);\n                }\n            }\n            if (startup_params->tcp_recv_buffer_bytes > 0)\n            {\n                bytes = startup_params->tcp_recv_buffer_bytes;\n                if (g_sck_set_recv_buffer_bytes(ltrans->sck, bytes) != 0)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"error setting recv buffer\");\n                }\n                else if (g_sck_get_recv_buffer_bytes(ltrans->sck, &bytes) != 0)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"error getting recv buffer\");\n                }\n                else if (bytes != startup_params->tcp_recv_buffer_bytes)\n                {\n                    LOG(LOG_LEVEL_WARNING, \"recv buffer set to %d \"\n                        \"bytes but %d bytes requested\", bytes,\n                        startup_params->tcp_recv_buffer_bytes);\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_INFO, \"recv buffer set to %d bytes\", bytes);\n                }\n            }\n        }\n        ltrans->trans_conn_in = xrdp_listen_conn_in;\n        ltrans->callback_data = self;\n        ltrans->is_term = g_is_term;\n        list_add_item(self->trans_list, (intptr_t) ltrans);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_listen_fork(struct xrdp_listen *self, struct trans *server_trans)\n{\n    int pid;\n    int index;\n    struct xrdp_process *process;\n    struct trans *ltrans;\n\n    pid = g_fork();\n\n    if (pid == 0)\n    {\n        /* child */\n        /* recreate some main globals */\n        xrdp_child_fork();\n        /* recreate the process done wait object, not used in fork mode */\n        /* close, don't delete this */\n        g_close_wait_obj(self->pro_done_event);\n        xrdp_listen_create_pro_done(self);\n        /* delete listener, child need not listen */\n        for (index = 0; index < self->trans_list->count; index++)\n        {\n            ltrans = (struct trans *) list_get_item(self->trans_list, index);\n            trans_delete_from_child(ltrans);\n        }\n        list_delete(self->trans_list);\n        self->trans_list = NULL;\n        /* new connect instance */\n        process = xrdp_process_create(self, 0);\n        process->server_trans = server_trans;\n        g_process = process;\n        xrdp_process_run(0);\n        tc_sem_dec(g_process_sem);\n        xrdp_process_delete(process);\n        /* mark this process to exit */\n        g_set_term(1);\n        return 1;\n    }\n\n    /* parent */\n    trans_delete(server_trans);\n    return 0;\n}\n\n/*****************************************************************************/\n/* a new connection is coming in */\nint\nxrdp_listen_conn_in(struct trans *self, struct trans *new_self)\n{\n    struct xrdp_process *process;\n    struct xrdp_listen *lis;\n\n    lis = (struct xrdp_listen *)(self->callback_data);\n\n    if (lis->startup_params->fork)\n    {\n        list_add_item(lis->fork_list, (intptr_t) new_self);\n        return 0;\n    }\n\n    process = xrdp_process_create(lis, lis->pro_done_event);\n\n    if (xrdp_listen_add_pro(lis, process) == 0)\n    {\n        /* start thread */\n        process->server_trans = new_self;\n        g_process = process;\n        tc_thread_create(xrdp_process_run, 0);\n        tc_sem_dec(g_process_sem); /* this will wait */\n    }\n    else\n    {\n        xrdp_process_delete(process);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Process pending SIGCHLD events in the listen process\n *\n * The main reason for this is to log children which fail\n * on a signal. This should be investigated.\n */\nstatic void\nprocess_pending_sigchld_events(void)\n{\n    struct proc_exit_status e;\n    int pid;\n\n    while ((pid = g_waitchild(&e)) > 0)\n    {\n        if (e.reason == E_PXR_SIGNAL)\n        {\n            char sigstr[MAXSTRSIGLEN];\n            LOG(LOG_LEVEL_ERROR,\n                \"Child %d terminated unexpectedly with signal %s\",\n                pid, g_sig2text(e.val, sigstr));\n        }\n    }\n}\n/*****************************************************************************/\n/* wait for incoming connections\n   passes through trans_listen_address return value */\nint\nxrdp_listen_main_loop(struct xrdp_listen *self)\n{\n    int robjs_count;\n    int cont;\n    int index;\n    int timeout;\n    intptr_t robjs[32];\n    intptr_t term_obj;\n    intptr_t sigchld_obj;\n    intptr_t sync_obj;\n    intptr_t done_obj;\n    struct trans *ltrans;\n\n    self->status = 1;\n\n    term_obj = g_get_term(); /*Global termination event */\n    sigchld_obj = g_get_sigchld();\n    sync_obj = g_get_sync_event();\n    done_obj = self->pro_done_event;\n    cont = 1;\n    while (cont)\n    {\n        /* build the wait obj list */\n        robjs_count = 0;\n        robjs[robjs_count++] = term_obj;\n        robjs[robjs_count++] = sigchld_obj;\n        robjs[robjs_count++] = sync_obj;\n        robjs[robjs_count++] = done_obj;\n        timeout = -1;\n\n        for (index = 0; index < self->trans_list->count; index++)\n        {\n            ltrans = (struct trans *)\n                     list_get_item(self->trans_list, index);\n            if (trans_get_wait_objs(ltrans, robjs, &robjs_count) != 0)\n            {\n                cont = 0;\n                break;\n            }\n        }\n        if (cont == 0)\n        {\n            break;\n        }\n\n        /* wait - timeout -1 means wait indefinitely*/\n        if (g_obj_wait(robjs, robjs_count, 0, 0, timeout) != 0)\n        {\n            /* error, should not get here */\n            g_sleep(100);\n        }\n\n        if (g_is_wait_obj_set(term_obj)) /* termination called */\n        {\n            LOG(LOG_LEVEL_INFO,\n                \"Received termination signal, stopping the server accept new \"\n                \"connections thread\");\n            break;\n        }\n\n        if (g_is_wait_obj_set(sigchld_obj)) /* SIGCHLD caught */\n        {\n            g_set_sigchld(0);\n            process_pending_sigchld_events();\n        }\n\n        /* some function must be processed by this thread */\n        if (g_is_wait_obj_set(sync_obj))\n        {\n            g_reset_wait_obj(sync_obj);\n            g_process_waiting_function(); /* run the function */\n        }\n\n        if (g_is_wait_obj_set(done_obj)) /* pro_done_event */\n        {\n            g_reset_wait_obj(done_obj);\n            /* a process has died remove it from lists*/\n            xrdp_listen_delete_done_pro(self);\n        }\n\n        /* Run the callback when accept() returns a new socket*/\n        for (index = 0; index < self->trans_list->count; index++)\n        {\n            ltrans = (struct trans *)\n                     list_get_item(self->trans_list, index);\n            if (trans_check_wait_objs(ltrans) != 0)\n            {\n                cont = 0;\n                break;\n            }\n        }\n        if (cont == 0)\n        {\n            break;\n        }\n        while (self->fork_list->count > 0)\n        {\n            ltrans = (struct trans *) list_get_item(self->fork_list, 0);\n            list_remove_item(self->fork_list, 0);\n            if (xrdp_listen_fork(self, ltrans) != 0)\n            {\n                cont = 0;\n                break;\n            }\n        }\n        if (cont == 0)\n        {\n            break;\n        }\n    }\n\n    /* stop listening */\n    xrdp_listen_stop_all_listen(self);\n\n    /* second loop to wait for all process threads to close */\n    cont = 1;\n\n    while (cont)\n    {\n        if (self->process_list->count == 0)\n        {\n            break;\n        }\n\n        timeout = -1;\n        /* build the wait obj list */\n        robjs_count = 0;\n        robjs[robjs_count++] = sync_obj;\n        robjs[robjs_count++] = done_obj;\n\n        /* wait - timeout -1 means wait indefinitely*/\n        if (g_obj_wait(robjs, robjs_count, 0, 0, timeout) != 0)\n        {\n            /* error, should not get here */\n            g_sleep(100);\n        }\n\n        /* some function must be processed by this thread */\n        if (g_is_wait_obj_set(sync_obj))\n        {\n            g_reset_wait_obj(sync_obj);\n            g_process_waiting_function(); /* run the function that is waiting*/\n        }\n\n        if (g_is_wait_obj_set(done_obj)) /* pro_done_event */\n        {\n            g_reset_wait_obj(done_obj);\n            xrdp_listen_delete_done_pro(self);\n        }\n    }\n\n    self->status = -1;\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/xrdp_login_wnd.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * main login window and login help window\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"base64.h\"\n#include \"xrdp.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n\n#define ASK \"ask\"\n#define ASK_LEN g_strlen(ASK)\n#define BASE64PREFIX \"{base64}\"\n#define BASE64PREFIX_LEN g_strlen(BASE64PREFIX)\n\n/*****************************************************************************/\n/* all login help screen events go here */\nstatic int\nxrdp_wm_login_help_notify(struct xrdp_bitmap *wnd,\n                          struct xrdp_bitmap *sender,\n                          int msg, long param1, long param2)\n{\n    struct xrdp_painter *p;\n\n    if (wnd == 0)\n    {\n        return 0;\n    }\n\n    if (sender == 0)\n    {\n        return 0;\n    }\n\n    if (wnd->owner == 0)\n    {\n        return 0;\n    }\n\n    if (msg == 1) /* click */\n    {\n        if (sender->id == 1) /* ok button */\n        {\n            struct xrdp_bitmap *o = wnd->owner;\n            if (o != 0 && o->notify != 0)\n            {\n                o->notify(o, wnd, 100, 1, 0); /* ok */\n            }\n        }\n    }\n    else if (msg == WM_PAINT) /* 3 */\n    {\n        p = (struct xrdp_painter *)param1;\n\n        if (p != 0)\n        {\n            const int x = 10;\n            int y = xrdp_painter_font_body_height(p) * 2;\n            const int row_height = xrdp_painter_font_body_height(p);\n            const int end_para_height = row_height * 3 / 2;\n\n            p->fg_color = wnd->wm->black;\n            xrdp_painter_draw_text(p, wnd, x, y, \"You must be authenticated \\\nbefore using this\");\n            y += row_height;\n            xrdp_painter_draw_text(p, wnd, x, y, \"session.\");\n            y += end_para_height;\n            xrdp_painter_draw_text(p, wnd, x, y, \"Enter a valid username in \\\nthe username edit box.\");\n            y += end_para_height;\n            xrdp_painter_draw_text(p, wnd, x, y, \"Enter the password in \\\nthe password edit box.\");\n            y += end_para_height;\n            xrdp_painter_draw_text(p, wnd, x, y, \"Both the username and \\\npassword are case\");\n            y += row_height;\n            xrdp_painter_draw_text(p, wnd, x, y, \"sensitive.\");\n            y += end_para_height;\n            xrdp_painter_draw_text(p, wnd, x, y, \"Contact your system \\\nadministrator if you are\");\n            y += row_height;\n            xrdp_painter_draw_text(p, wnd, x, y, \"having problems \\\nlogging on.\");\n        }\n    }\n\n    return 0;\n}\n\n#if 0\n/*****************************************************************************/\nstatic int\nxrdp_wm_popup_notify(struct xrdp_bitmap *wnd,\n                     struct xrdp_bitmap *sender,\n                     int msg, int param1, int param2)\n{\n    return 0;\n}\n#endif\n\n/*****************************************************************************/\nint\nxrdp_wm_delete_all_children(struct xrdp_wm *self)\n{\n    int index;\n    struct xrdp_bitmap *b;\n    struct xrdp_rect rect;\n\n    for (index = self->screen->child_list->count - 1; index >= 0; index--)\n    {\n        b = (struct xrdp_bitmap *)list_get_item(self->screen->child_list, index);\n        MAKERECT(rect, b->left, b->top, b->width, b->height);\n        xrdp_bitmap_delete(b);\n        xrdp_bitmap_invalidate(self->screen, &rect);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nset_mod_data_item(struct xrdp_mod_data *mod, char *name, char *value)\n{\n    int index;\n\n    for (index = 0; index < mod->names->count; index++)\n    {\n        if (g_strncmp(name, (char *)list_get_item(mod->names, index), 255) == 0)\n        {\n            list_remove_item(mod->values, index);\n            list_insert_item(mod->values, index, (long)g_strdup(value));\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_help_clicked(struct xrdp_bitmap *wnd)\n{\n    struct xrdp_bitmap *help;\n    struct xrdp_bitmap *but;\n    const int width =\n        wnd->wm->xrdp_config->cfg_globals.ls_scaled.help_wnd_width;\n    const int height =\n        wnd->wm->xrdp_config->cfg_globals.ls_scaled.help_wnd_height;\n    const int ok_height =\n        wnd->wm->xrdp_config->cfg_globals.ls_scaled.default_btn_height;\n    const char *ok_string = \"OK\";\n\n    /* Get a width for the OK button */\n    struct xrdp_painter *p = xrdp_painter_create(wnd->wm, wnd->wm->session);\n    xrdp_painter_font_needed(p);\n    const int ok_width = xrdp_painter_text_width(p, ok_string) +\n                         DEFAULT_BUTTON_MARGIN_W;\n    xrdp_painter_delete(p);\n\n    /* create help screen */\n    help = xrdp_bitmap_create(width, height, wnd->wm->screen->bpp,\n                              WND_TYPE_WND, wnd->wm);\n    list_insert_item(wnd->wm->screen->child_list, 0, (long)help);\n    help->parent = wnd->wm->screen;\n    help->owner = wnd;\n    wnd->modal_dialog = help;\n    help->bg_color = wnd->wm->grey;\n    help->left = wnd->wm->screen->width / 2 - help->width / 2;\n    help->top = wnd->wm->screen->height / 2 - help->height / 2;\n    help->notify = xrdp_wm_login_help_notify;\n    set_string(&help->caption1, \"Login help\");\n    /* ok button */\n    but = xrdp_bitmap_create(ok_width, ok_height, wnd->wm->screen->bpp,\n                             WND_TYPE_BUTTON, wnd->wm);\n    list_insert_item(help->child_list, 0, (long)but);\n    but->parent = help;\n    but->owner = help;\n    but->left = ((help->width / 2) - (ok_width / 2)); /* center */\n    but->top = help->height - ok_height - 15;\n    but->id = 1;\n    but->tab_stop = 1;\n    set_string(&but->caption1, ok_string);\n    /* draw it */\n    help->focused_control = but;\n    help->default_button = but;\n    help->esc_button = but;\n    xrdp_bitmap_invalidate(help, 0);\n    xrdp_wm_set_focused(wnd->wm, help);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_cancel_clicked(struct xrdp_bitmap *wnd)\n{\n    if (wnd != 0)\n    {\n        if (wnd->wm != 0)\n        {\n            if (wnd->wm->pro_layer != 0)\n            {\n                wnd->wm->pro_layer->errinfo =\n                    ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES;\n                g_set_wait_obj(wnd->wm->pro_layer->self_term_event);\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_ok_clicked(struct xrdp_bitmap *wnd)\n{\n    struct xrdp_bitmap *combo;\n    struct xrdp_bitmap *label;\n    struct xrdp_bitmap *edit;\n    struct xrdp_wm *wm;\n    struct xrdp_mod_data *mod_data;\n    int i;\n\n    wm = wnd->wm;\n    combo = xrdp_bitmap_get_child_by_id(wnd, 6);\n\n    if (combo != 0)\n    {\n        mod_data = (struct xrdp_mod_data *)\n                   list_get_item(combo->data_list, combo->item_index);\n\n        if (mod_data != 0)\n        {\n            /* get the user typed values */\n            i = 100;\n            label = xrdp_bitmap_get_child_by_id(wnd, i);\n            edit = xrdp_bitmap_get_child_by_id(wnd, i + 1);\n\n            while (label != 0 && edit != 0)\n            {\n                set_mod_data_item(mod_data, label->caption1, edit->caption1);\n                i += 2;\n                label = xrdp_bitmap_get_child_by_id(wnd, i);\n                edit = xrdp_bitmap_get_child_by_id(wnd, i + 1);\n            }\n\n            list_delete(wm->mm->login_names);\n            list_delete(wm->mm->login_values);\n            wm->mm->login_names = list_create();\n            wm->mm->login_names->auto_free = 1;\n            wm->mm->login_values = list_create();\n            wm->mm->login_values->auto_free = 1;\n            /* will copy these cause dialog gets freed */\n            list_append_list_strdup(mod_data->names, wm->mm->login_names, 0);\n            list_append_list_strdup(mod_data->values, wm->mm->login_values, 0);\n            xrdp_wm_set_login_state(wm, WMLS_START_CONNECT);\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"Combo is NULL - potential programming error\");\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n* This is an internal function in this file used to parse the domain\n* information sent from the client. If the information starts\n* with '_' the domain field contains the IP/DNS to connect to.\n* If the domain field contains an additional '__' the char that\n* follows this '__' is an index number of a preferred combo choice.\n* Valid values for this choice is 0-9. But this function will only return\n* index numbers between 0 and the max number of combo items -1.\n* Example: _192.168.1.2__1 result in a resultbuffer containing\n* 192.168.1.2  and the return value will be 1. Meaning that\n* index 1 is the preferred combo choice.\n*\n* Users can create shortcuts where this information is configured. These\n* shortcuts simplifies login.\n* @param originalDomainInfo indata to this function\n* @param comboMax the max number of combo choices\n* @param decode if true then we perform decoding of combo choice\n* @param resultBuffer must be pre allocated before calling this function.\n* Holds the IP. The size of this buffer must be 256 bytes\n* @return the index number of the combobox that the user prefer.\n* 0 if the user does not prefer any choice.\n*/\nstatic int\nxrdp_wm_parse_domain_information(char *originalDomainInfo, int comboMax,\n                                 int decode,\n                                 char *resultBuffer, unsigned int resultSize)\n{\n    int ret;\n    int pos;\n    int comboxindex;\n    char index[2];\n\n    /* If the first char in the domain name is '_' we use the domain\n       name as IP*/\n    ret = 0; /* default return value */\n    g_memset(resultBuffer, 0, resultSize);\n    if (originalDomainInfo[0] == '_')\n    {\n        /* we try to locate a number indicating what combobox index the user\n         * prefer the information is loaded from domain field, from the client\n         * We must use valid chars in the domain name.\n         * Underscore is a valid name in the domain.\n         * Invalid chars are ignored in microsoft client therefore we use '_'\n         * again. this sec '__' contains the split for index.*/\n        pos = g_pos(&originalDomainInfo[1], \"__\");\n        if (pos > 0 && (unsigned int)pos < resultSize)\n        {\n            /* an index is found we try to use it */\n            LOG(LOG_LEVEL_DEBUG, \"domain contains index char __\");\n            if (decode)\n            {\n                g_memset(index, 0, 2);\n                /* we just accept values 0-9  (one figure) */\n                g_strncpy(index, &originalDomainInfo[pos + 3], 1);\n                comboxindex = g_htoi(index);\n                LOG(LOG_LEVEL_DEBUG,\n                    \"index value as string: %s, as int: %d, max: %d\",\n                    index, comboxindex, comboMax - 1);\n                /* limit to max number of items in combo box */\n                if ((comboxindex > 0) && (comboxindex < comboMax))\n                {\n                    LOG(LOG_LEVEL_DEBUG, \"domain contains a valid \"\n                        \"index number\");\n                    ret = comboxindex; /* preferred index for combo box. */\n                }\n            }\n            /* pos limit the String to only contain the IP */\n            strlcpy(resultBuffer, &originalDomainInfo[1], pos + 1);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_DEBUG, \"domain does not contain _\");\n            strlcpy(resultBuffer, &originalDomainInfo[1], resultSize);\n        }\n    }\n    return ret;\n}\n\n/******************************************************************************/\nstatic int\nxrdp_wm_show_edits(struct xrdp_wm *self, struct xrdp_bitmap *combo)\n{\n    int count;\n    int index;\n    int insert_index;\n    int username_set;\n    char *name;\n    char *value;\n    struct xrdp_mod_data *mod;\n    struct xrdp_bitmap *b;\n    struct xrdp_cfg_globals *globals;\n    char resultIP[256];\n    char *plain; /* base64 decoded string */\n    size_t plain_length; /* length of decoded base64 string */\n    size_t base64_length; /* length of base64 string */\n\n    globals = &self->xrdp_config->cfg_globals;\n\n    username_set = 0;\n\n    /* free labels and edits, cause we will create them */\n    /* creation or combo changed */\n    for (index = 100; index < 200; index++)\n    {\n        b = xrdp_bitmap_get_child_by_id(combo->parent, index);\n        xrdp_bitmap_delete(b);\n    }\n\n    insert_index = list_index_of(self->login_window->child_list,\n                                 (long)combo); /* find combo in the list */\n    insert_index++;\n    mod = (struct xrdp_mod_data *)\n          list_get_item(combo->data_list, combo->item_index);\n\n    if (mod != 0)\n    {\n        count = 0;\n\n        for (index = 0; index < mod->names->count; index++)\n        {\n            value = (char *)list_get_item(mod->values, index);\n\n            /* if the value begins with \"{base64}\", decode the string following it */\n            if (g_strncmp(BASE64PREFIX, value, BASE64PREFIX_LEN) == 0)\n            {\n                base64_length = g_strlen(value + BASE64PREFIX_LEN);\n                plain = (char *)g_malloc(base64_length, 0);\n                base64_decode(value + BASE64PREFIX_LEN,\n                              plain, base64_length, &plain_length);\n                g_strncpy(value, plain, plain_length);\n                g_free(plain);\n            }\n            else if (g_strncmp(ASK, value, ASK_LEN) == 0)\n            {\n                const int combo_height =\n                    self->xrdp_config->cfg_globals.ls_scaled.combo_height;\n                const int edit_height =\n                    self->xrdp_config->cfg_globals.ls_scaled.edit_height;\n                /* label */\n                b = xrdp_bitmap_create(globals->ls_scaled.label_width,\n                                       edit_height, self->screen->bpp,\n                                       WND_TYPE_LABEL, self);\n                list_insert_item(self->login_window->child_list, insert_index,\n                                 (long)b);\n                insert_index++;\n                b->parent = self->login_window;\n                b->owner = self->login_window;\n                b->left = globals->ls_scaled.label_x_pos;\n\n                b->top = globals->ls_scaled.input_y_pos + combo_height + 5 +\n                         (edit_height + 5) * count;\n                b->id = 100 + 2 * count;\n                name = (char *)list_get_item(mod->names, index);\n                set_string(&b->caption1, name);\n\n                /* edit */\n                b = xrdp_bitmap_create(globals->ls_scaled.input_width,\n                                       edit_height, self->screen->bpp,\n                                       WND_TYPE_EDIT, self);\n                list_insert_item(self->login_window->child_list, insert_index,\n                                 (long)b);\n                insert_index++;\n                b->parent = self->login_window;\n                b->owner = self->login_window;\n                b->left = globals->ls_scaled.input_x_pos;\n\n                b->top = globals->ls_scaled.input_y_pos + combo_height + 5 +\n                         (edit_height + 5) * count;\n\n                b->id = 100 + 2 * count + 1;\n                b->pointer = 1;\n                b->tab_stop = 1;\n                b->caption1 = (char *)g_malloc(256, 1);\n                /* ask{base64}... 3 for \"ask\", 8 for \"{base64}\" */\n                if (g_strncmp(BASE64PREFIX, value + ASK_LEN, BASE64PREFIX_LEN) == 0)\n                {\n                    base64_length = g_strlen(value + ASK_LEN + BASE64PREFIX_LEN);\n                    plain = (char *)g_malloc(base64_length, 0);\n                    base64_decode(value + ASK_LEN + BASE64PREFIX_LEN,\n                                  plain, base64_length, &plain_length);\n                    plain[plain_length] = '\\0';\n                    g_strncpy(b->caption1, plain, 255);\n                    g_free(plain);\n                }\n                else\n                {\n                    g_strncpy(b->caption1, value + ASK_LEN, 255);\n                }\n                b->edit_pos = utf8_char_count(b->caption1);\n\n                if (self->login_window->focused_control == 0)\n                {\n                    self->login_window->focused_control = b;\n                }\n\n                /* Use the domain name as the destination IP/DNS\n                   This is useful in a gateway setup. */\n                if (g_strncasecmp(name, \"ip\", 255) == 0)\n                {\n                    /* If the first char in the domain name is '_' we use the\n                       domain name as IP */\n                    if (self->session->client_info->domain[0] == '_')\n                    {\n                        xrdp_wm_parse_domain_information(\n                            self->session->client_info->domain,\n                            combo->data_list->count, 0,\n                            resultIP, sizeof(resultIP));\n                        g_strncpy(b->caption1, resultIP, 255);\n                        b->edit_pos = utf8_char_count(b->caption1);\n                    }\n\n                }\n\n                if (g_strncasecmp(name, \"username\", 255) == 0 &&\n                        self->session->client_info->username[0])\n                {\n                    g_strncpy(b->caption1, self->session->client_info->username, 255);\n                    b->edit_pos = utf8_char_count(b->caption1);\n\n                    if (b->edit_pos > 0)\n                    {\n                        username_set = 1;\n                    }\n                }\n\n                if ((g_strncasecmp(name, \"password\", 255) == 0) ||\n                        (g_strncasecmp(name, \"pampassword\", 255) == 0))\n                {\n                    b->password_char = '*';\n\n                    if (username_set)\n                    {\n                        if (b->parent != 0)\n                        {\n                            b->parent->focused_control = b;\n                        }\n                    }\n                }\n\n                count++;\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* all login screen events go here */\nstatic int\nxrdp_wm_login_notify(struct xrdp_bitmap *wnd,\n                     struct xrdp_bitmap *sender,\n                     int msg, long param1, long param2)\n{\n    struct xrdp_bitmap *b;\n    struct xrdp_rect rect;\n    int i;\n\n    if (wnd->modal_dialog != 0 && msg != 100)\n    {\n        return 0;\n    }\n\n    if (msg == 1) /* click */\n    {\n        if (sender->id == 1) /* help button */\n        {\n            xrdp_wm_help_clicked(wnd);\n        }\n        else if (sender->id == 2) /* cancel button */\n        {\n            xrdp_wm_cancel_clicked(wnd);\n        }\n        else if (sender->id == 3) /* ok button */\n        {\n            xrdp_wm_ok_clicked(wnd);\n        }\n    }\n    else if (msg == 2) /* mouse move */\n    {\n    }\n    else if (msg == 100) /* modal result is done */\n    {\n        i = list_index_of(wnd->wm->screen->child_list, (long)sender);\n\n        if (i >= 0)\n        {\n            b = (struct xrdp_bitmap *)\n                list_get_item(wnd->wm->screen->child_list, i);\n            list_remove_item(sender->wm->screen->child_list, i);\n            MAKERECT(rect, b->left, b->top, b->width, b->height);\n            xrdp_bitmap_invalidate(wnd->wm->screen, &rect);\n            xrdp_bitmap_delete(sender);\n            wnd->modal_dialog = 0;\n            xrdp_wm_set_focused(wnd->wm, wnd);\n        }\n    }\n    else if (msg == CB_ITEMCHANGE) /* combo box change */\n    {\n        xrdp_wm_show_edits(wnd->wm, sender);\n        xrdp_bitmap_invalidate(wnd, 0); /* invalidate the whole dialog for now */\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nxrdp_wm_login_fill_in_combo(struct xrdp_wm *self, struct xrdp_bitmap *b)\n{\n    struct list *sections;\n    struct list *section_names;\n    struct list *section_values;\n    int fd;\n    int i;\n    int j;\n    char *p;\n    char *q;\n    char *r;\n    char name[256];\n    struct xrdp_mod_data *mod_data;\n    const char *xrdp_ini = self->session->xrdp_ini;\n\n    sections = list_create();\n    sections->auto_free = 1;\n    section_names = list_create();\n    section_names->auto_free = 1;\n    section_values = list_create();\n    section_values->auto_free = 1;\n    fd = g_file_open_ro(xrdp_ini);\n\n    if (fd < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Could not read xrdp ini file %s\",\n            xrdp_ini);\n        list_delete(sections);\n        list_delete(section_names);\n        list_delete(section_values);\n        return 1;\n    }\n\n    file_read_sections(fd, sections);\n\n    for (i = 0; i < sections->count; i++)\n    {\n        p = (char *)list_get_item(sections, i);\n        file_read_section(fd, p, section_names, section_values);\n\n        if ((g_strncasecmp(p, \"globals\", 255) == 0)\n                || (g_strncasecmp(p, \"channels\", 255) == 0)\n                || (g_strncasecmp(p, \"Logging\", 255) == 0)\n                || (g_strncasecmp(p, \"LoggingPerLogger\", 255) == 0))\n        {\n        }\n        else\n        {\n            g_strncpy(name, p, 255);\n            mod_data = (struct xrdp_mod_data *)\n                       g_malloc(sizeof(struct xrdp_mod_data), 1);\n            mod_data->names = list_create();\n            mod_data->names->auto_free = 1;\n            mod_data->values = list_create();\n            mod_data->values->auto_free = 1;\n\n            for (j = 0; j < section_names->count; j++)\n            {\n                q = (char *)list_get_item(section_names, j);\n                r = (char *)list_get_item(section_values, j);\n\n                if (g_strncmp(\"name\", q, 255) == 0)\n                {\n                    g_strncpy(name, r, 255);\n                }\n\n                list_add_strdup(mod_data->names, q);\n                list_add_strdup(mod_data->values, r);\n            }\n\n            list_add_strdup(b->string_list, name);\n            list_add_item(b->data_list, (long)mod_data);\n        }\n    }\n\n    g_file_close(fd);\n    list_delete(sections);\n    list_delete(section_names);\n    list_delete(section_values);\n    return 0;\n}\n\n/******************************************************************************/\nunsigned int\nxrdp_login_wnd_get_monitor_dpi(struct xrdp_wm *self)\n{\n    unsigned int result = 0;\n    const struct display_size_description *display_sizes =\n            &self->client_info->display_sizes;\n    unsigned int height_pixels = 0;\n    unsigned int height_mm = 0;\n\n    unsigned int i;\n\n    /* Look at the monitor data first */\n    for (i = 0; i < display_sizes->monitorCount; ++i)\n    {\n        const struct monitor_info *mi = &display_sizes->minfo_wm[i];\n        {\n            if (mi->is_primary)\n            {\n                height_pixels = mi->bottom - mi->top + 1;\n                height_mm = mi->physical_height;\n                break;\n            }\n        }\n    }\n\n    /* No primary monitor, or values not defined - use the desktop size */\n    if (height_mm == 0)\n    {\n        height_pixels = display_sizes->session_height;\n        height_mm = self->client_info->session_physical_height;\n\n        if (height_mm == 0)\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"No information is available to determine login screen DPI\");\n        }\n        else if (height_pixels < 768)\n        {\n            /* A bug was encountered with mstsc.exe version\n               10.0.19041.1682 where the full physical monitor size was\n               sent in TS_UD_CS_CORE when the desktop size was set to\n               less than the screen size.\n               To generate the bug, make a connection with a full-screen\n               single window, cancel the login, and reconnect at\n               (e.g.) 800x600.\n               We can't detect that exact situation here, but if the\n               session height is so small as to likely be in a window\n               (rather than full screen), we should ignore the physical\n               size */\n            LOG(LOG_LEVEL_WARNING,\n                \"Ignoring unlikely physical session size %u \"\n                \"for height of %u pixels\", height_mm, height_pixels);\n            height_mm = 0;\n        }\n    }\n\n    if (height_mm != 0)\n    {\n        /*\n         * DPI = height_pixels / (height_mm / 25.4)\n         *     = (height_pixels * 25.4) / height_mm\n         *     = (height_pixels * 127) / (height_mm * 5)\n         */\n        result = (height_pixels * 127 ) / (height_mm * 5);\n        LOG(LOG_LEVEL_INFO,\n            \"Login screen monitor height is %u pixels over %u mm (%u DPI)\",\n            height_pixels,\n            height_mm,\n            result);\n    }\n    return result;\n}\n\n\n/******************************************************************************/\nint\nxrdp_login_wnd_create(struct xrdp_wm *self)\n{\n    struct xrdp_bitmap      *but;\n    struct xrdp_bitmap      *combo;\n    struct xrdp_cfg_globals *globals;\n\n    char buf[256];\n    char buf1[256];\n    char resultIP[256];\n    int log_width;\n    int log_height;\n    int regular;\n    int primary_width;     /* Dimensions of primary screen */\n    int primary_height;\n    int primary_x_offset;  /* Offset of centre of primary screen */\n    int primary_y_offset;\n    uint32_t index;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    const int combo_height =\n        self->xrdp_config->cfg_globals.ls_scaled.combo_height;\n    const int edit_height =\n        self->xrdp_config->cfg_globals.ls_scaled.edit_height;\n\n    globals = &self->xrdp_config->cfg_globals;\n\n    primary_width = self->screen->width;\n    primary_height = self->screen->height;\n    primary_x_offset = primary_width / 2;\n    primary_y_offset = primary_height / 2;\n\n    log_width = globals->ls_scaled.width;\n    log_height = globals->ls_scaled.height;\n    regular = 1;\n\n    if (self->screen->width < log_width)\n    {\n        if (self->screen->width < 240)\n        {\n            log_width = self->screen->width - 4;\n        }\n        else\n        {\n            log_width = 240;\n        }\n\n        regular = 0;\n    }\n\n    /* multimon scenario, draw login window on primary monitor */\n    if (self->client_info->display_sizes.monitorCount > 1)\n    {\n        for (index = 0; index < self->client_info->display_sizes.monitorCount; index++)\n        {\n            if (self->client_info->display_sizes.minfo_wm[index].is_primary)\n            {\n                x = self->client_info->display_sizes.minfo_wm[index].left;\n                y = self->client_info->display_sizes.minfo_wm[index].top;\n                cx = self->client_info->display_sizes.minfo_wm[index].right;\n                cy = self->client_info->display_sizes.minfo_wm[index].bottom;\n\n                primary_width = cx - x;\n                primary_height = cy - y;\n                primary_x_offset = x + (primary_width / 2);\n                primary_y_offset = y + (primary_height / 2);\n                break;\n            }\n        }\n    }\n\n    /* draw login window */\n    self->login_window = xrdp_bitmap_create(log_width, log_height, self->screen->bpp,\n                                            WND_TYPE_WND, self);\n    list_add_item(self->screen->child_list, (long)self->login_window);\n    self->login_window->parent = self->screen;\n    self->login_window->owner = self->screen;\n    self->login_window->bg_color = globals->ls_bg_color;\n\n    self->login_window->left = primary_x_offset - self->login_window->width / 2;\n    self->login_window->top = primary_y_offset - self->login_window->height / 2;\n\n\n    self->login_window->notify = xrdp_wm_login_notify;\n\n    /* if window title not specified, use hostname as default */\n    if (globals->ls_title[0] == 0)\n    {\n        g_gethostname(buf1, 256);\n        g_snprintf(buf, sizeof(buf), \"Login to %s\", buf1);\n        set_string(&self->login_window->caption1, buf);\n    }\n    else\n    {\n        /*self->login_window->caption1 = globals->ls_title[0];*/\n        g_snprintf(buf, sizeof(buf), \"%s\", globals->ls_title);\n        set_string(&self->login_window->caption1, buf);\n    }\n\n    if (regular)\n    {\n        /* Load the background image. */\n        /* If no file is specified no default image will be loaded. */\n        /* We only load the image if bpp > 8, and if the user hasn't\n         * disabled wallpaper in the performance settings */\n        if (globals->ls_background_image[0] != 0)\n        {\n            if (self->screen->bpp <= 8)\n            {\n                LOG(LOG_LEVEL_INFO, \"Login background not loaded for bpp=%d\",\n                    self->screen->bpp);\n            }\n            else if ((self->client_info->rdp5_performanceflags &\n                      RDP5_NO_WALLPAPER) != 0)\n            {\n                LOG(LOG_LEVEL_INFO, \"Login background not loaded as client \"\n                    \"has requested PERF_DISABLE_WALLPAPER\");\n            }\n            else\n            {\n                char fileName[256] ;\n                but = xrdp_bitmap_create(4, 4, self->screen->bpp,\n                                         WND_TYPE_IMAGE, self);\n                if (globals->ls_background_image[0] == '/')\n                {\n                    g_snprintf(fileName, 255, \"%s\",\n                               globals->ls_background_image);\n                }\n                else\n                {\n                    g_snprintf(fileName, 255, \"%s/%s\",\n                               XRDP_SHARE_PATH, globals->ls_background_image);\n                }\n                LOG(LOG_LEVEL_DEBUG, \"We try to load the following background file: %s\", fileName);\n                if (globals->ls_background_transform == XBLT_NONE)\n                {\n                    xrdp_bitmap_load(but, fileName, self->palette,\n                                     globals->ls_top_window_bg_color,\n                                     globals->ls_background_transform,\n                                     0, 0);\n                    /* Place the background in the bottom right corner */\n                    but->left = primary_x_offset + (primary_width / 2) -\n                                but->width;\n                    but->top = primary_y_offset + (primary_height / 2) -\n                               but->height;\n                }\n                else\n                {\n                    xrdp_bitmap_load(but, fileName, self->palette,\n                                     globals->ls_top_window_bg_color,\n                                     globals->ls_background_transform,\n                                     primary_width, primary_height);\n                    but->left = primary_x_offset - (primary_width / 2);\n                    but->top = primary_y_offset - (primary_height / 2);\n                }\n                but->parent = self->screen;\n                but->owner = self->screen;\n                list_add_item(self->screen->child_list, (long)but);\n            }\n        }\n\n        /* if logo image not specified, use default */\n        if (globals->ls_logo_filename[0] == 0)\n        {\n#ifdef USE_IMLIB2\n            g_snprintf(globals->ls_logo_filename, 255, \"%s/xrdp_logo.png\",\n                       XRDP_SHARE_PATH);\n#else\n            g_snprintf(globals->ls_logo_filename, 255, \"%s/xrdp_logo.bmp\",\n                       XRDP_SHARE_PATH);\n#endif\n        }\n\n        /* logo image */\n        but = xrdp_bitmap_create(4, 4, self->screen->bpp, WND_TYPE_IMAGE, self);\n\n        if (self->screen->bpp <= 8)\n        {\n            g_snprintf(globals->ls_logo_filename, 255, \"%s/ad256.bmp\", XRDP_SHARE_PATH);\n        }\n\n        LOG(LOG_LEVEL_DEBUG, \"ls_logo_filename: %s\", globals->ls_logo_filename);\n\n        xrdp_bitmap_load(but, globals->ls_logo_filename, self->palette,\n                         globals->ls_bg_color,\n                         globals->ls_logo_transform,\n                         globals->ls_scaled.logo_width,\n                         globals->ls_scaled.logo_height);\n        but->parent = self->login_window;\n        but->owner = self->login_window;\n        but->left = globals->ls_scaled.logo_x_pos;\n        but->top = globals->ls_scaled.logo_y_pos;\n        list_add_item(self->login_window->child_list, (long)but);\n    }\n\n    /* label */\n    but = xrdp_bitmap_create(globals->ls_scaled.label_width, edit_height,\n                             self->screen->bpp, WND_TYPE_LABEL, self);\n    list_add_item(self->login_window->child_list, (long)but);\n    but->parent = self->login_window;\n    but->owner = self->login_window;\n    but->left = globals->ls_scaled.label_x_pos;\n    but->top = globals->ls_scaled.input_y_pos;\n    set_string(&but->caption1, \"Session\");\n\n    /* combo */\n    combo = xrdp_bitmap_create(globals->ls_scaled.input_width, combo_height,\n                               self->screen->bpp, WND_TYPE_COMBO, self);\n    list_add_item(self->login_window->child_list, (long)combo);\n    combo->parent = self->login_window;\n    combo->owner = self->login_window;\n    combo->left = globals->ls_scaled.input_x_pos;\n    combo->top = globals->ls_scaled.input_y_pos;\n    combo->id = 6;\n    combo->tab_stop = 1;\n    xrdp_wm_login_fill_in_combo(self, combo);\n\n    /* OK button */\n    but = xrdp_bitmap_create(globals->ls_scaled.btn_ok_width,\n                             globals->ls_scaled.btn_ok_height,\n                             self->screen->bpp, WND_TYPE_BUTTON, self);\n    list_add_item(self->login_window->child_list, (long)but);\n    but->parent = self->login_window;\n    but->owner = self->login_window;\n    but->left = globals->ls_scaled.btn_ok_x_pos;\n    but->top = globals->ls_scaled.btn_ok_y_pos;\n    but->id = 3;\n    set_string(&but->caption1, \"OK\");\n    but->tab_stop = 1;\n    self->login_window->default_button = but;\n\n    /* Cancel button */\n    but = xrdp_bitmap_create(globals->ls_scaled.btn_cancel_width,\n                             globals->ls_scaled.btn_cancel_height,\n                             self->screen->bpp,\n                             WND_TYPE_BUTTON, self);\n    list_add_item(self->login_window->child_list, (long)but);\n    but->parent = self->login_window;\n    but->owner = self->login_window;\n    but->left = globals->ls_scaled.btn_cancel_x_pos;\n    but->top = globals->ls_scaled.btn_cancel_y_pos;\n    but->id = 2;\n    set_string(&but->caption1, \"Cancel\");\n    but->tab_stop = 1;\n    self->login_window->esc_button = but;\n\n    /* labels and edits.\n    * parameter: 1 = decode domain field index information from client.\n    * We only perform this the first time for each connection.\n    */\n    combo->item_index = xrdp_wm_parse_domain_information(\n                            self->session->client_info->domain,\n                            combo->data_list->count, 1,\n                            resultIP,/* just a dummy place holder, we ignore */\n                            sizeof(resultIP));\n    xrdp_wm_show_edits(self, combo);\n\n    return 0;\n}\n\n/**\n * Map a bitmap transform string to a value\n *\n * @param param Param we're trying to read\n * @param str   String we're trying to map\n *\n * @return enum xrdp_bitmap_load_transform value\n *\n * A warning is logged if the string is not recognised\n *****************************************************************************/\nstatic enum xrdp_bitmap_load_transform\nbitmap_transform_str_to_val(const char *param, const char *str)\n{\n    enum xrdp_bitmap_load_transform rv;\n    if (g_strcmp(str, \"none\") == 0)\n    {\n        rv = XBLT_NONE;\n    }\n    else if (g_strcmp(str, \"scale\") == 0)\n    {\n        rv = XBLT_SCALE;\n    }\n    else if (g_strcmp(str, \"zoom\") == 0)\n    {\n        rv = XBLT_ZOOM;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"Param '%s' has unrecognised value '%s'\"\n            \" - assuming 'none'\", param, str);\n        rv = XBLT_NONE;\n    }\n\n    return rv;\n}\n\n/**\n * Load configuration from xrdp.ini file\n *\n * @param config XRDP configuration to initialise\n * @param xrdp_ini Path to xrdp.ini\n * @param bpp bits-per-pixel for this connection\n *\n * @return 0 on success, -1 on failure\n *****************************************************************************/\nint\nload_xrdp_config(struct xrdp_config *config, const char *xrdp_ini, int bpp)\n{\n    struct xrdp_cfg_globals  *globals;\n\n    struct list *names;\n    struct list *values;\n\n    char *n;\n    char *v;\n    int   fd;\n    int   i;\n\n    if (!config)\n    {\n        return -1;\n    }\n\n    globals = &config->cfg_globals;\n\n    /* set default values in case we can't get them from xrdp.ini file */\n    globals->ini_version = 1;\n    globals->default_dpi = 96;\n\n    globals->ls_top_window_bg_color = HCOLOR(bpp, g_htoi(\"009cb5\"));\n    globals->ls_bg_color = HCOLOR(bpp, g_htoi(\"dedede\"));\n    globals->ls_unscaled.width = 350;\n    globals->ls_unscaled.height = 350;\n    globals->ls_background_transform = XBLT_NONE;\n    globals->ls_logo_transform = XBLT_NONE;\n    globals->ls_unscaled.logo_x_pos = 63;\n    globals->ls_unscaled.logo_y_pos = 50;\n    globals->ls_unscaled.label_x_pos = 30;\n    globals->ls_unscaled.label_width = 65;\n    globals->ls_unscaled.input_x_pos = 110;\n    globals->ls_unscaled.input_width = 210;\n    globals->ls_unscaled.input_y_pos = 150;\n    globals->ls_unscaled.btn_ok_x_pos = 150;\n    globals->ls_unscaled.btn_ok_y_pos = 300;\n    globals->ls_unscaled.btn_ok_width = 85;\n    globals->ls_unscaled.btn_ok_height = 30;\n    globals->ls_unscaled.btn_cancel_x_pos = 245;\n    globals->ls_unscaled.btn_cancel_y_pos = 300;\n    globals->ls_unscaled.btn_cancel_width = 85;\n    globals->ls_unscaled.btn_cancel_height = 30;\n    globals->ls_unscaled.default_btn_height =\n        DEFAULT_FONT_PIXEL_SIZE + DEFAULT_BUTTON_MARGIN_H;\n    globals->ls_unscaled.log_wnd_width = DEFAULT_WND_LOG_W;\n    globals->ls_unscaled.log_wnd_height = DEFAULT_WND_LOG_H;\n    globals->ls_unscaled.edit_height =\n        DEFAULT_FONT_PIXEL_SIZE + DEFAULT_EDIT_MARGIN_H;\n    globals->ls_unscaled.combo_height =\n        DEFAULT_FONT_PIXEL_SIZE + DEFAULT_COMBO_MARGIN_H;\n    globals->ls_unscaled.help_wnd_width = DEFAULT_WND_HELP_W;\n    globals->ls_unscaled.help_wnd_height = DEFAULT_WND_HELP_H;\n\n    /* open xrdp.ini file */\n    if ((fd = g_file_open_ro(xrdp_ini)) < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"load_config: Could not read \"\n            \"xrdp.ini file %s\", xrdp_ini);\n        return -1;\n\n    }\n\n    names = list_create();\n    values = list_create();\n    names->auto_free = 1;\n    values->auto_free = 1;\n\n    if (file_read_section(fd, \"globals\", names, values) != 0)\n    {\n        list_delete(names);\n        list_delete(values);\n        g_file_close(fd);\n        LOG(LOG_LEVEL_ERROR, \"load_config: Could not read globals \"\n            \"section from xrdp.ini file %s\", xrdp_ini);\n        return -1;\n    }\n\n    for (i = 0; i < names->count; i++)\n    {\n        n = (char *) list_get_item(names, i);\n        v = (char *) list_get_item(values, i);\n\n        /*\n         * parse globals section\n         */\n\n        if (g_strncmp(n, \"ini_version\", 64) == 0)\n        {\n            globals->ini_version = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"bitmap_cache\", 64) == 0)\n        {\n            globals->use_bitmap_cache = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"bitmap_compression\", 64) == 0)\n        {\n            globals->use_bitmap_compression = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"port\", 64) == 0)\n        {\n            globals->port = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"crypt_level\", 64) == 0)\n        {\n            if (g_strcmp(v, \"low\") == 0)\n            {\n                globals->crypt_level = 1;\n            }\n            else if (g_strcmp(v, \"medium\") == 0)\n            {\n                globals->crypt_level = 2;\n            }\n            else\n            {\n                globals->crypt_level = 3;\n            }\n        }\n\n        else if (g_strncmp(n, \"allow_channels\", 64) == 0)\n        {\n            globals->allow_channels = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"max_bpp\", 64) == 0)\n        {\n            globals->max_bpp = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"fork\", 64) == 0)\n        {\n            globals->fork = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"tcp_nodelay\", 64) == 0)\n        {\n            globals->tcp_nodelay = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"tcp_keepalive\", 64) == 0)\n        {\n            globals->tcp_keepalive = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"tcp_send_buffer_bytes\", 64) == 0)\n        {\n            globals->tcp_send_buffer_bytes = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"tcp_recv_buffer_bytes\", 64) == 0)\n        {\n            globals->tcp_recv_buffer_bytes = g_atoi(v);\n        }\n\n        /* colors */\n\n        else if (g_strncmp(n, \"grey\", 64) == 0)\n        {\n            globals->grey = g_htoi(v);\n        }\n\n        else if (g_strncmp(n, \"black\", 64) == 0)\n        {\n            globals->black = g_htoi(v);\n        }\n\n        else if (g_strncmp(n, \"dark_grey\", 64) == 0)\n        {\n            globals->dark_grey = g_htoi(v);\n        }\n\n        else if (g_strncmp(n, \"blue\", 64) == 0)\n        {\n            globals->blue = g_htoi(v);\n        }\n\n        else if (g_strncmp(n, \"dark_blue\", 64) == 0)\n        {\n            globals->dark_blue = g_htoi(v);\n        }\n\n        else if (g_strncmp(n, \"white\", 64) == 0)\n        {\n            globals->white = g_htoi(v);\n        }\n\n        else if (g_strncmp(n, \"red\", 64) == 0)\n        {\n            globals->red = g_htoi(v);\n        }\n\n        else if (g_strncmp(n, \"green\", 64) == 0)\n        {\n            globals->green = g_htoi(v);\n        }\n\n        else if (g_strncmp(n, \"background\", 64) == 0)\n        {\n            globals->background = g_htoi(v);\n        }\n\n        /* misc stuff */\n\n        else if (g_strncmp(n, \"autorun\", 255) == 0)\n        {\n            g_strncpy(globals->autorun, v, 255);\n        }\n\n        else if (g_strncmp(n, \"hidelogwindow\", 64) == 0)\n        {\n            globals->hidelogwindow = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"require_credentials\", 64) == 0)\n        {\n            globals->require_credentials = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"bulk_compression\", 64) == 0)\n        {\n            globals->bulk_compression = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"new_cursors\", 64) == 0)\n        {\n            globals->new_cursors = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"nego_sec_layer\", 64) == 0)\n        {\n            globals->nego_sec_layer = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"allow_multimon\", 64) == 0)\n        {\n            globals->allow_multimon = g_text2bool(v);\n        }\n\n        else if (g_strncmp(n, \"enable_token_login\", 64) == 0)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"Token login detection enabled x\");\n            globals->enable_token_login = g_text2bool(v);\n        }\n\n        /* login screen values */\n        else if (g_strcmp(n, \"default_dpi\") == 0)\n        {\n            globals->default_dpi = g_atoi(v);\n        }\n\n        else if (g_strcmp(n, \"fv1_select\") == 0)\n        {\n            g_strncpy(globals->fv1_select, v, sizeof(globals->fv1_select) - 1);\n        }\n\n        else if (g_strncmp(n, \"ls_top_window_bg_color\", 64) == 0)\n        {\n            globals->ls_top_window_bg_color = HCOLOR(bpp, g_htoi(v));\n        }\n\n        else if (g_strncmp(n, \"ls_width\", 64) == 0)\n        {\n            globals->ls_unscaled.width = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_height\", 64) == 0)\n        {\n            globals->ls_unscaled.height = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_bg_color\", 64) == 0)\n        {\n            globals->ls_bg_color = HCOLOR(bpp, g_htoi(v));\n        }\n\n        else if (g_strncmp(n, \"ls_title\", 255) == 0)\n        {\n            g_strncpy(globals->ls_title, v, 255);\n            globals->ls_title[255] = 0;\n        }\n\n        else if (g_strncmp(n, \"ls_background_image\", 255) == 0)\n        {\n            g_strncpy(globals->ls_background_image, v, 255);\n            globals->ls_background_image[255] = 0;\n        }\n\n        else if (g_strncmp(n, \"ls_background_transform\", 255) == 0)\n        {\n            globals->ls_background_transform =\n                bitmap_transform_str_to_val(n, v);\n        }\n\n        else if (g_strncmp(n, \"ls_logo_filename\", 255) == 0)\n        {\n            g_strncpy(globals->ls_logo_filename, v, 255);\n            globals->ls_logo_filename[255] = 0;\n        }\n\n        else if (g_strncmp(n, \"ls_logo_transform\", 255) == 0)\n        {\n            globals->ls_logo_transform = bitmap_transform_str_to_val(n, v);\n        }\n\n        else if (g_strncmp(n, \"ls_logo_width\", 64) == 0)\n        {\n            globals->ls_unscaled.logo_width = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_logo_height\", 64) == 0)\n        {\n            globals->ls_unscaled.logo_height = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_logo_x_pos\", 64) == 0)\n        {\n            globals->ls_unscaled.logo_x_pos = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_logo_y_pos\", 64) == 0)\n        {\n            globals->ls_unscaled.logo_y_pos = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_label_x_pos\", 64) == 0)\n        {\n            globals->ls_unscaled.label_x_pos = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_label_width\", 64) == 0)\n        {\n            globals->ls_unscaled.label_width = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_input_x_pos\", 64) == 0)\n        {\n            globals->ls_unscaled.input_x_pos = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_input_width\", 64) == 0)\n        {\n            globals->ls_unscaled.input_width = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_input_y_pos\", 64) == 0)\n        {\n            globals->ls_unscaled.input_y_pos = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_btn_ok_x_pos\", 64) == 0)\n        {\n            globals->ls_unscaled.btn_ok_x_pos = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_btn_ok_y_pos\", 64) == 0)\n        {\n            globals->ls_unscaled.btn_ok_y_pos = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_btn_ok_width\", 64) == 0)\n        {\n            globals->ls_unscaled.btn_ok_width = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_btn_ok_height\", 64) == 0)\n        {\n            globals->ls_unscaled.btn_ok_height = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_btn_cancel_x_pos\", 64) == 0)\n        {\n            globals->ls_unscaled.btn_cancel_x_pos = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_btn_cancel_y_pos\", 64) == 0)\n        {\n            globals->ls_unscaled.btn_cancel_y_pos = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_btn_cancel_width\", 64) == 0)\n        {\n            globals->ls_unscaled.btn_cancel_width = g_atoi(v);\n        }\n\n        else if (g_strncmp(n, \"ls_btn_cancel_height\", 64) == 0)\n        {\n            globals->ls_unscaled.btn_cancel_height = g_atoi(v);\n        }\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"ini_version:             %d\", globals->ini_version);\n    LOG(LOG_LEVEL_DEBUG, \"use_bitmap_cache:        %d\", globals->use_bitmap_cache);\n    LOG(LOG_LEVEL_DEBUG, \"use_bitmap_compression:  %d\", globals->use_bitmap_compression);\n    LOG(LOG_LEVEL_DEBUG, \"port:                    %d\", globals->port);\n    LOG(LOG_LEVEL_DEBUG, \"crypt_level:             %d\", globals->crypt_level);\n    LOG(LOG_LEVEL_DEBUG, \"allow_channels:          %d\", globals->allow_channels);\n    LOG(LOG_LEVEL_DEBUG, \"max_bpp:                 %d\", globals->max_bpp);\n    LOG(LOG_LEVEL_DEBUG, \"fork:                    %d\", globals->fork);\n    LOG(LOG_LEVEL_DEBUG, \"tcp_nodelay:             %d\", globals->tcp_nodelay);\n    LOG(LOG_LEVEL_DEBUG, \"tcp_keepalive:           %d\", globals->tcp_keepalive);\n    LOG(LOG_LEVEL_DEBUG, \"tcp_send_buffer_bytes:   %d\", globals->tcp_send_buffer_bytes);\n    LOG(LOG_LEVEL_DEBUG, \"tcp_recv_buffer_bytes:   %d\", globals->tcp_recv_buffer_bytes);\n\n    LOG(LOG_LEVEL_DEBUG, \"grey:                    %d\", globals->grey);\n    LOG(LOG_LEVEL_DEBUG, \"black:                   %d\", globals->black);\n    LOG(LOG_LEVEL_DEBUG, \"dark_grey:               %d\", globals->dark_grey);\n    LOG(LOG_LEVEL_DEBUG, \"blue:                    %d\", globals->blue);\n    LOG(LOG_LEVEL_DEBUG, \"dark_blue:               %d\", globals->dark_blue);\n    LOG(LOG_LEVEL_DEBUG, \"white:                   %d\", globals->white);\n    LOG(LOG_LEVEL_DEBUG, \"red:                     %d\", globals->red);\n    LOG(LOG_LEVEL_DEBUG, \"green:                   %d\", globals->green);\n    LOG(LOG_LEVEL_DEBUG, \"background:              %d\", globals->background);\n\n    LOG(LOG_LEVEL_DEBUG, \"autorun:                 %s\", globals->autorun);\n    LOG(LOG_LEVEL_DEBUG, \"hidelogwindow:           %d\", globals->hidelogwindow);\n    LOG(LOG_LEVEL_DEBUG, \"require_credentials:     %d\", globals->require_credentials);\n    LOG(LOG_LEVEL_DEBUG, \"bulk_compression:        %d\", globals->bulk_compression);\n    LOG(LOG_LEVEL_DEBUG, \"new_cursors:             %d\", globals->new_cursors);\n    LOG(LOG_LEVEL_DEBUG, \"nego_sec_layer:          %d\", globals->nego_sec_layer);\n    LOG(LOG_LEVEL_DEBUG, \"allow_multimon:          %d\", globals->allow_multimon);\n    LOG(LOG_LEVEL_DEBUG, \"enable_token_login:      %d\", globals->enable_token_login);\n\n    LOG(LOG_LEVEL_DEBUG, \"ls_top_window_bg_color:  %x\", globals->ls_top_window_bg_color);\n    LOG(LOG_LEVEL_DEBUG, \"ls_width (unscaled):     %d\", globals->ls_unscaled.width);\n    LOG(LOG_LEVEL_DEBUG, \"ls_height (unscaled):    %d\", globals->ls_unscaled.height);\n    LOG(LOG_LEVEL_DEBUG, \"ls_bg_color:             %x\", globals->ls_bg_color);\n    LOG(LOG_LEVEL_DEBUG, \"ls_title:                %s\", globals->ls_title);\n    LOG(LOG_LEVEL_DEBUG, \"ls_logo_filename:        %s\", globals->ls_logo_filename);\n    LOG(LOG_LEVEL_DEBUG, \"ls_logo_x_pos :          %d\", globals->ls_unscaled.logo_x_pos);\n    LOG(LOG_LEVEL_DEBUG, \"ls_logo_y_pos :          %d\", globals->ls_unscaled.logo_y_pos);\n    LOG(LOG_LEVEL_DEBUG, \"ls_label_x_pos :         %d\", globals->ls_unscaled.label_x_pos);\n    LOG(LOG_LEVEL_DEBUG, \"ls_label_width :         %d\", globals->ls_unscaled.label_width);\n    LOG(LOG_LEVEL_DEBUG, \"ls_input_x_pos :         %d\", globals->ls_unscaled.input_x_pos);\n    LOG(LOG_LEVEL_DEBUG, \"ls_input_width :         %d\", globals->ls_unscaled.input_width);\n    LOG(LOG_LEVEL_DEBUG, \"ls_input_y_pos :         %d\", globals->ls_unscaled.input_y_pos);\n    LOG(LOG_LEVEL_DEBUG, \"ls_btn_ok_x_pos :        %d\", globals->ls_unscaled.btn_ok_x_pos);\n    LOG(LOG_LEVEL_DEBUG, \"ls_btn_ok_y_pos :        %d\", globals->ls_unscaled.btn_ok_y_pos);\n    LOG(LOG_LEVEL_DEBUG, \"ls_btn_ok_width :        %d\", globals->ls_unscaled.btn_ok_width);\n    LOG(LOG_LEVEL_DEBUG, \"ls_btn_ok_height :       %d\", globals->ls_unscaled.btn_ok_height);\n    LOG(LOG_LEVEL_DEBUG, \"ls_btn_cancel_x_pos :    %d\", globals->ls_unscaled.btn_cancel_x_pos);\n    LOG(LOG_LEVEL_DEBUG, \"ls_btn_cancel_y_pos :    %d\", globals->ls_unscaled.btn_cancel_y_pos);\n    LOG(LOG_LEVEL_DEBUG, \"ls_btn_cancel_width :    %d\", globals->ls_unscaled.btn_cancel_width);\n    LOG(LOG_LEVEL_DEBUG, \"ls_btn_cancel_height :   %d\", globals->ls_unscaled.btn_cancel_height);\n\n    list_delete(names);\n    list_delete(values);\n    g_file_close(fd);\n    return 0;\n}\n\n/**\n * Scale the configuration values\n *\n * After a font has been loaded, we can produce scaled versions of the\n * login screen layout parameters which will correspond to the size of the\n * font\n */\nvoid\nxrdp_login_wnd_scale_config_values(struct xrdp_wm *self)\n{\n    const struct xrdp_ls_dimensions *unscaled =\n            &self->xrdp_config->cfg_globals.ls_unscaled;\n    struct xrdp_ls_dimensions *scaled =\n            &self->xrdp_config->cfg_globals.ls_scaled;\n\n    /* Clear the scaled values, so if we add one and forget to scale it,\n     * it will be obvious */\n    g_memset(scaled, '\\0', sizeof(*scaled));\n\n    /* If we don't have a font, use zeros for everything */\n    if (self->default_font == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Can't scale login values - no font available\");\n    }\n    else\n    {\n        const int fheight = self->default_font->body_height;\n        /* Define a Macro to scale to the nearest pixel value,\n         * rounding up as appropriate */\n#define SCALE_AND_ROUND(x) \\\n    (((x) * fheight + (DEFAULT_FONT_PIXEL_SIZE / 2)) / \\\n     DEFAULT_FONT_PIXEL_SIZE)\n\n        LOG(LOG_LEVEL_DEBUG, \"Login screen scale factor %f\",\n            (float)fheight / DEFAULT_FONT_PIXEL_SIZE);\n\n        scaled->width = SCALE_AND_ROUND(unscaled->width);\n        scaled->height = SCALE_AND_ROUND(unscaled->height);\n        scaled->logo_width = SCALE_AND_ROUND(unscaled->logo_width);\n        scaled->logo_height = SCALE_AND_ROUND(unscaled->logo_height);\n        scaled->logo_x_pos = SCALE_AND_ROUND(unscaled->logo_x_pos);\n        scaled->logo_y_pos = SCALE_AND_ROUND(unscaled->logo_y_pos);\n        scaled->label_x_pos = SCALE_AND_ROUND(unscaled->label_x_pos);\n        scaled->label_width = SCALE_AND_ROUND(unscaled->label_width);\n        scaled->input_x_pos = SCALE_AND_ROUND(unscaled->input_x_pos);\n        scaled->input_width = SCALE_AND_ROUND(unscaled->input_width);\n        scaled->input_y_pos = SCALE_AND_ROUND(unscaled->input_y_pos);\n        scaled->btn_ok_x_pos = SCALE_AND_ROUND(unscaled->btn_ok_x_pos);\n        scaled->btn_ok_y_pos = SCALE_AND_ROUND(unscaled->btn_ok_y_pos);\n        scaled->btn_ok_width = SCALE_AND_ROUND(unscaled->btn_ok_width);\n        scaled->btn_ok_height = SCALE_AND_ROUND(unscaled->btn_ok_height);\n        scaled->btn_cancel_x_pos = SCALE_AND_ROUND(unscaled->btn_cancel_x_pos);\n        scaled->btn_cancel_y_pos = SCALE_AND_ROUND(unscaled->btn_cancel_y_pos);\n        scaled->btn_cancel_width = SCALE_AND_ROUND(unscaled->btn_cancel_width);\n        scaled->btn_cancel_height = SCALE_AND_ROUND(unscaled->btn_cancel_height);\n        scaled->default_btn_height = fheight + DEFAULT_BUTTON_MARGIN_H;\n        scaled->log_wnd_width = SCALE_AND_ROUND(unscaled->log_wnd_width);\n        scaled->log_wnd_height = SCALE_AND_ROUND(unscaled->log_wnd_height);\n        scaled->edit_height = fheight + DEFAULT_EDIT_MARGIN_H;\n        scaled->combo_height = fheight + DEFAULT_COMBO_MARGIN_H;\n        scaled->help_wnd_width = SCALE_AND_ROUND(unscaled->help_wnd_width);\n        scaled->help_wnd_height = SCALE_AND_ROUND(unscaled->help_wnd_height);\n#undef SCALE_AND_ROUND\n    }\n}\n"
  },
  {
    "path": "xrdp/xrdp_main_utils.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\n/**\n *\n * @file xrdp_main_utils.c\n * @brief Functions used by XRDP's main() routine and needed elsewhere.\n * @author Jay Sorg, Christopher Pitstick\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp.h\"\n#include \"log.h\"\n\n#define THREAD_WAITING 100\n\nstatic long g_threadid = 0; /* main threadid */\n\nstatic long g_sync_mutex = 0;\nstatic long g_sync1_mutex = 0;\nstatic tbus g_term_event = 0;\nstatic tbus g_sigchld_event = 0;\nstatic tbus g_sync_event = 0;\n/* synchronize stuff */\nstatic int g_sync_command = 0;\nstatic long g_sync_result = 0;\nstatic long g_sync_param1 = 0;\nstatic long g_sync_param2 = 0;\nstatic long (*g_sync_func)(long param1, long param2);\n\n/*****************************************************************************/\n/* This function is used to run a function from the main thread.\n   Sync_func is the function pointer that will run from main thread\n   The function can have two long in parameters and must return long */\nlong\ng_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1,\n            long sync_param2)\n{\n    long sync_result;\n    int sync_command;\n\n    /* If the function is called from the main thread, the function can\n     * be called directly. g_threadid= main thread ID*/\n    if (tc_threadid_equal(tc_get_threadid(), g_threadid))\n    {\n        /* this is the main thread, call the function directly */\n        /* in fork mode, this always happens too */\n        sync_result = sync_func(sync_param1, sync_param2);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"g_xrdp_sync processed IN main thread -> continue\");\n    }\n    else\n    {\n        /* All threads have to wait here until the main thread\n         * process the function. g_process_waiting_function() is called\n         * from the listening thread. g_process_waiting_function() process the function*/\n        tc_mutex_lock(g_sync1_mutex);\n        tc_mutex_lock(g_sync_mutex);\n        g_sync_param1 = sync_param1;\n        g_sync_param2 = sync_param2;\n        g_sync_func = sync_func;\n        /* set a value THREAD_WAITING so the g_process_waiting_function function\n         * know if any function must be processed */\n        g_sync_command = THREAD_WAITING;\n        tc_mutex_unlock(g_sync_mutex);\n        /* set this event so that the main thread know if\n         * g_process_waiting_function() must be called */\n        g_set_wait_obj(g_sync_event);\n\n        do\n        {\n            g_sleep(100);\n            tc_mutex_lock(g_sync_mutex);\n            /* load new value from global to see if the g_process_waiting_function()\n             * function has processed the function */\n            sync_command = g_sync_command;\n            sync_result = g_sync_result;\n            tc_mutex_unlock(g_sync_mutex);\n        }\n        while (sync_command != 0); /* loop until g_process_waiting_function()\n                                * has processed the request */\n        tc_mutex_unlock(g_sync1_mutex);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"g_xrdp_sync processed BY main thread -> continue\");\n    }\n\n    return sync_result;\n}\n\n/*****************************************************************************/\n/* Signal handler for SIGCHLD in the child\n * Note: only signal safe code (eg. setting wait event) should be executed in\n * this function. For more details see `man signal-safety`\n */\nstatic void\nxrdp_child_sigchld_handler(int sig)\n{\n    while (g_waitchild(NULL) > 0)\n    {\n    }\n}\n\n/*****************************************************************************/\n/* called in child just after fork */\nint\nxrdp_child_fork(void)\n{\n    int pid;\n    char text[256];\n\n    /* SIGCHLD in the child is of no interest to us */\n    g_signal_child_stop(xrdp_child_sigchld_handler);        /* SIGCHLD */\n\n    g_close_wait_obj(g_term_event);\n    g_close_wait_obj(g_sigchld_event);\n    g_close_wait_obj(g_sync_event);\n\n    pid = g_getpid();\n    g_snprintf(text, 255, \"xrdp_%8.8x_main_term\", pid);\n    g_term_event = g_create_wait_obj(text);\n    g_sigchld_event = -1;\n    g_snprintf(text, 255, \"xrdp_%8.8x_main_sync\", pid);\n    g_sync_event = g_create_wait_obj(text);\n    return 0;\n}\n\n/*****************************************************************************/\nlong\ng_get_sync_mutex(void)\n{\n    return g_sync_mutex;\n}\n\n/*****************************************************************************/\nvoid\ng_set_sync_mutex(long mutex)\n{\n    g_sync_mutex = mutex;\n}\n\n/*****************************************************************************/\nlong\ng_get_sync1_mutex(void)\n{\n    return g_sync1_mutex;\n}\n\n/*****************************************************************************/\nvoid\ng_set_sync1_mutex(long mutex)\n{\n    g_sync1_mutex = mutex;\n}\n\n/*****************************************************************************/\nvoid\ng_set_term_event(tbus event)\n{\n    g_term_event = event;\n}\n\n/*****************************************************************************/\nvoid\ng_set_sigchld_event(tbus event)\n{\n    g_sigchld_event = event;\n}\n\n/*****************************************************************************/\ntbus\ng_get_sync_event(void)\n{\n    return g_sync_event;\n}\n\n/*****************************************************************************/\nvoid\ng_set_sync_event(tbus event)\n{\n    g_sync_event = event;\n}\n\n/*****************************************************************************/\nlong\ng_get_threadid(void)\n{\n    return g_threadid;\n}\n\n/*****************************************************************************/\nvoid\ng_set_threadid(long id)\n{\n    g_threadid = id;\n}\n\n/*****************************************************************************/\ntbus\ng_get_term(void)\n{\n    return g_term_event;\n}\n\n/*****************************************************************************/\ntbus\ng_get_sigchld(void)\n{\n    return g_sigchld_event;\n}\n\n/*****************************************************************************/\nint\ng_is_term(void)\n{\n    return g_is_wait_obj_set(g_term_event);\n}\n\n/*****************************************************************************/\nvoid\ng_set_term(int in_val)\n{\n    if (in_val)\n    {\n        g_set_wait_obj(g_term_event);\n    }\n    else\n    {\n        g_reset_wait_obj(g_term_event);\n    }\n}\n\n/*****************************************************************************/\nvoid\ng_set_sigchld(int in_val)\n{\n    if (in_val)\n    {\n        g_set_wait_obj(g_sigchld_event);\n    }\n    else\n    {\n        g_reset_wait_obj(g_sigchld_event);\n    }\n}\n\n/*****************************************************************************/\n/*Some function must be called from the main thread.\n if g_sync_command==THREAD_WAITING a function is waiting to be processed*/\nvoid\ng_process_waiting_function(void)\n{\n    tc_mutex_lock(g_sync_mutex);\n\n    if (g_sync_command != 0)\n    {\n        if (g_sync_func != 0)\n        {\n            if (g_sync_command == THREAD_WAITING)\n            {\n                g_sync_result = g_sync_func(g_sync_param1, g_sync_param2);\n            }\n        }\n\n        g_sync_command = 0;\n    }\n\n    tc_mutex_unlock(g_sync_mutex);\n}\n"
  },
  {
    "path": "xrdp/xrdp_mm.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * module manager\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n#include \"xrdp_mm.h\"\n#include \"xrdp.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n#include \"guid.h\"\n#include \"ms-rdpedisp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"ccp.h\"\n#include \"scp.h\"\n#include <ctype.h>\n#include \"xrdp_encoder.h\"\n#include \"xrdp_sockets.h\"\n#include \"xrdp_egfx.h\"\n#include \"libxrdp.h\"\n#include \"xrdp_channel.h\"\n#include <limits.h>\n\n#if defined(XRDP_OPENH264)\n#include \"xrdp_encoder_openh264.h\"\n#endif\n\n/* Forward declarations */\nstatic int\nxrdp_mm_setup_mod1(struct xrdp_mm *self);\nstatic int\nxrdp_mm_setup_mod2(struct xrdp_mm *self);\nstatic void\nxrdp_mm_connect_sm(struct xrdp_mm *self);\nstatic int\nxrdp_mm_send_unicode_shutdown(struct xrdp_mm *self, struct trans *trans);\n\n/*****************************************************************************/\nstatic void\ninit_libh264_loaded(struct xrdp_mm *self)\n{\n#if defined(XRDP_OPENH264)\n    // Note that if this fails, and x264 is also configured, x264\n    // will not be considered as a fallback.\n    self->libh264_loaded = xrdp_encoder_openh264_install_ok();\n    if (!self->libh264_loaded)\n    {\n        LOG(LOG_LEVEL_ERROR, \"OpenH264 Codec is not installed correctly. \"\n            \"H.264 will not be used\");\n    }\n#elif defined (XRDP_H264)\n    self->libh264_loaded = 1;\n#else\n    self->libh264_loaded = 0;\n#endif\n}\n\n/*****************************************************************************/\nstruct xrdp_mm *\nxrdp_mm_create(struct xrdp_wm *owner)\n{\n    struct xrdp_mm *self;\n\n    self = (struct xrdp_mm *)g_malloc(sizeof(struct xrdp_mm), 1);\n    self->wm = owner;\n    self->login_names = list_create();\n    self->login_names->auto_free = 1;\n    self->login_values = list_create();\n    self->login_values->auto_free = 1;\n\n    self->sesman_display_fd = -1;\n    self->sesman_chansrv_fd = -1;\n    self->uid = -1; /* Never good to default UIDs to 0 */\n\n    // Resize queue support. The resize queue is available early on,\n    // but isn't processed until start_processing_resize_queue() is\n    // called.\n    self->resize_queue = list_create();\n    self->resize_queue->auto_free = 1;\n    self->resize_data = NULL;\n    self->resize_ready = NULL_WAIT_OBJ;\n\n    init_libh264_loaded(self);\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_mm_create: bpp %d mcs_connection_type %d \"\n              \"jpeg_codec_id %d v3_codec_id %d rfx_codec_id %d \"\n              \"h264_codec_id %d\",\n              self->wm->client_info->bpp,\n              self->wm->client_info->mcs_connection_type,\n              self->wm->client_info->jpeg_codec_id,\n              self->wm->client_info->v3_codec_id,\n              self->wm->client_info->rfx_codec_id,\n              self->wm->client_info->h264_codec_id);\n\n    if ((self->wm->client_info->gfx == 0) &&\n            ((self->wm->client_info->h264_codec_id != 0 && self->libh264_loaded) ||\n             (self->wm->client_info->jpeg_codec_id != 0) ||\n             (self->wm->client_info->rfx_codec_id != 0)))\n    {\n        self->encoder = xrdp_encoder_create(self);\n    }\n\n    return self;\n}\n\n/*****************************************************************************/\n/* called from main thread */\nstatic long\nxrdp_mm_sync_unload(long param1, long param2)\n{\n    return g_free_library(param1);\n}\n\n/*****************************************************************************/\n/* called from main thread */\nstatic long\nxrdp_mm_sync_load(long param1, long param2)\n{\n    long rv;\n    char *libname;\n\n    libname = (char *)param1;\n    rv = g_load_library(libname);\n    return rv;\n}\n\n/*****************************************************************************/\nstatic void\nxrdp_mm_module_cleanup(struct xrdp_mm *self)\n{\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_mm_module_cleanup\");\n\n    if (self->mod != 0)\n    {\n        if (self->mod_exit != 0)\n        {\n            /* let the module cleanup */\n            self->mod_exit(self->mod);\n        }\n    }\n\n    if (self->mod_handle != 0)\n    {\n        /* Let the main thread unload the module.*/\n        g_xrdp_sync(xrdp_mm_sync_unload, self->mod_handle, 0);\n    }\n\n    trans_delete(self->chan_trans);\n    self->chan_trans = 0;\n    self->mod_init = 0;\n    self->mod_exit = 0;\n    self->mod = 0;\n    self->mod_handle = 0;\n\n    if (self->wm && self->wm->hide_log_window)\n    {\n        /* make sure autologin is off.\n         * Check pointers are valid in case we're ending the process */\n        if (self->wm->session != NULL &&\n                self->wm->session->client_info != NULL)\n        {\n            self->wm->session->client_info->rdp_autologin = 0;\n        }\n        xrdp_wm_set_login_state(self->wm, WMLS_RESET); /* reset session */\n    }\n\n}\n\n/*****************************************************************************/\n/**\n * Close file descriptors from sesman\n * @param self xrdp_mm object\n *\n * When we connect to a session, sesman sends us some file descriptors\n * for the display and chansrv. When we deallocate resources, we need\n * to close these descriptors if they haven't been consumed.\n */\nstatic void\nclose_sesman_file_descriptors(struct xrdp_mm *self)\n{\n    if (self->sesman_display_fd >= 0)\n    {\n        g_file_close(self->sesman_display_fd);\n        self->sesman_display_fd = -1;\n    }\n    if (self->sesman_chansrv_fd >= 0)\n    {\n        g_file_close(self->sesman_chansrv_fd);\n        self->sesman_chansrv_fd = -1;\n    }\n}\n\n/*****************************************************************************/\nvoid\nxrdp_mm_delete(struct xrdp_mm *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n\n    /* shutdown input method */\n    xrdp_mm_send_unicode_shutdown(self, self->chan_trans);\n\n    /* free any module stuff */\n    xrdp_mm_module_cleanup(self);\n\n    /* shutdown thread */\n    xrdp_encoder_delete(self->encoder);\n\n    trans_delete(self->sesman_trans);\n    self->sesman_trans = 0;\n    list_delete(self->login_names);\n    list_delete(self->login_values);\n    list_delete(self->resize_queue);\n    g_free(self->resize_data);\n    g_delete_wait_obj(self->resize_ready);\n    xrdp_egfx_shutdown_full(self->egfx);\n\n    close_sesman_file_descriptors(self);\n    g_free(self);\n}\n\n/**************************************************************************//**\n * Looks for a string value in the login_names/login_values array\n *\n * In the event of multiple matches, the LAST value matched is returned.\n * This currently allows for values to be replaced by writing a new value\n * to the end of the list\n *\n * Returned strings are valid until the module is destroyed.\n *\n * @param self This module\n * @param aname Name to lookup (case-insensitive)\n *\n * @return pointer to value, or NULL if not found.\n */\nstatic const char *\nxrdp_mm_get_value(struct xrdp_mm *self, const char *aname)\n{\n    const char *name;\n    const char *value = NULL;\n    unsigned int index = self->login_names->count;\n\n    while (index > 0 && value == NULL)\n    {\n        --index;\n        name = (const char *)list_get_item(self->login_names, index);\n\n        if (name != NULL && g_strcasecmp(name, aname) == 0)\n        {\n            value = (const char *)list_get_item(self->login_values, index);\n        }\n    }\n\n    return value;\n}\n/**************************************************************************//**\n * Looks for a numeric value in the login_names/login_values array\n *\n * Returned strings are valid until the module is destroyed.\n *\n * @param self This module\n * @param aname Name to lookup (case-insensitive)\n * @param def Default to return if value not found.\n *\n * @return value from name, or the specified default.\n */\nstatic int\nxrdp_mm_get_value_int(struct xrdp_mm *self, const char *aname, int def)\n{\n    const char *value = xrdp_mm_get_value(self, aname);\n\n    return (value == NULL) ? def : g_atoi(value);\n}\n\n/*****************************************************************************/\n/* Send gateway login information to sesman */\nstatic int\nxrdp_mm_send_sys_login_request(struct xrdp_mm *self, const char *username,\n                               const char *password)\n{\n    xrdp_wm_log_msg(self->wm, LOG_LEVEL_DEBUG,\n                    \"sending login info to session manager, please wait...\");\n\n    return scp_send_sys_login_request(\n               self->sesman_trans, username, password,\n               self->wm->client_info->client_ip);\n}\n\n/*****************************************************************************/\n/* Send a create session request to sesman */\nstatic int\nxrdp_mm_create_session(struct xrdp_mm *self)\n{\n    int rv = 0;\n    int xserverbpp;\n    enum scp_session_type type;\n\n    /* Map the session code to an SCP session type */\n    switch (self->code)\n    {\n        case XVNC_SESSION_CODE:\n            type = SCP_SESSION_TYPE_XVNC;\n            break;\n\n        case XVNC_UDS_SESSION_CODE:\n            type = SCP_SESSION_TYPE_XVNC_UDS;\n            break;\n\n        case XORG_SESSION_CODE:\n            type = SCP_SESSION_TYPE_XORG;\n            break;\n\n        default:\n            xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                            \"Unrecognised session code %d\", self->code);\n            rv = 1;\n    }\n\n    if (rv == 0)\n    {\n        xserverbpp = xrdp_mm_get_value_int(self, \"xserverbpp\",\n                                           self->wm->screen->bpp);\n\n        xrdp_wm_log_msg(self->wm, LOG_LEVEL_DEBUG,\n                        \"sending create session request to session\"\n                        \" manager. Please wait...\");\n        rv = scp_send_create_session_request(\n                 self->sesman_trans,\n                 type,\n                 self->wm->screen->width,\n                 self->wm->screen->height,\n                 xserverbpp,\n                 self->wm->client_info->program,\n                 self->wm->client_info->directory,\n                 self->wm->pro_layer->lis_layer->startup_params->instance_name);\n    }\n\n    return rv;\n}\n\n\n/*****************************************************************************/\n/* Send a request to sesman to get session file descriptors */\nstatic int\nxrdp_mm_get_session_fds(struct xrdp_mm *self)\n{\n    int rv;\n    unsigned int flags = 0;\n\n    if (self->wm->client_info->channels_allowed != 0)\n    {\n        flags = E_SCP_SCONNECT_FLAG_NEED_CHANSRV;\n    }\n\n    rv = scp_send_connect_session_request(self->sesman_trans,\n                                          &self->guid,\n                                          self->wm->client_info->client_ip,\n                                          self->wm->client_info->client_name,\n                                          flags);\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error\n   send a list of channels to the channel handler */\nstatic int\nxrdp_mm_trans_send_channel_setup(struct xrdp_mm *self, struct trans *trans)\n{\n    int chan_count;\n    /* This value should be the same as chan_count, but we need to\n     * cater for a possible failure of libxrdp_query_channel() */\n    int output_chan_count;\n    int chan_id;\n    int chan_flags;\n    int size;\n    struct stream *s;\n    char chan_name[CHANNEL_NAME_LEN + 1];\n\n    s = trans_get_out_s(trans, 8192);\n\n    if (s == 0)\n    {\n        return 1;\n    }\n\n    s_push_layer(s, iso_hdr, 8);\n    s_push_layer(s, mcs_hdr, 8);\n    s_push_layer(s, sec_hdr, 2);\n\n    chan_count = libxrdp_get_channel_count(self->wm->session);\n    output_chan_count = 0;\n    for (chan_id = 0 ; chan_id < chan_count; ++chan_id)\n    {\n        if (libxrdp_query_channel(self->wm->session, chan_id, chan_name,\n                                  &chan_flags) == 0)\n        {\n            out_uint8a(s, chan_name, CHANNEL_NAME_LEN + 1);\n            out_uint16_le(s, chan_id);\n            out_uint16_le(s, chan_flags);\n            ++output_chan_count;\n        }\n    }\n\n    s_mark_end(s);\n    s_pop_layer(s, sec_hdr);\n    out_uint16_le(s, output_chan_count);\n    s_pop_layer(s, mcs_hdr);\n    size = (int)(s->end - s->p);\n    out_uint32_le(s, 3); /* msg id */\n    out_uint32_le(s, size); /* msg size */\n    s_pop_layer(s, iso_hdr);\n    size = (int)(s->end - s->p);\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, size); /* block size */\n    return trans_force_write(trans);\n}\n\n/*****************************************************************************/\n/* returns error\n   data coming in from the channel handler, send it to the client */\nstatic int\nxrdp_mm_trans_process_channel_data(struct xrdp_mm *self, struct stream *s)\n{\n    unsigned int size;\n    unsigned int total_size;\n    int chan_id;\n    int chan_flags;\n    int rv = 0;\n\n    if (!s_check_rem_and_log(s, 10, \"Reading channel data header\"))\n    {\n        rv = 1;\n    }\n    else\n    {\n        in_uint16_le(s, chan_id);\n        in_uint16_le(s, chan_flags);\n        in_uint16_le(s, size);\n        in_uint32_le(s, total_size);\n        if (!s_check_rem_and_log(s, size, \"Reading channel data data\"))\n        {\n            rv = 1;\n        }\n        else\n        {\n            rv = libxrdp_send_to_channel(self->wm->session, chan_id,\n                                         s->p, size, total_size, chan_flags);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_send_unicode_shutdown(struct xrdp_mm *self, struct trans *trans)\n{\n    struct stream *s = trans_get_out_s(self->chan_trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n\n    out_uint32_le(s, 0);     /* version */\n    out_uint32_le(s, 8 + 8); /* size */\n    out_uint32_le(s, 25);    /* msg id */\n    out_uint32_le(s, 8);     /* size */\n    s_mark_end(s);\n\n    return trans_write_copy(self->chan_trans);\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_send_unicode_setup(struct xrdp_mm *self, struct trans *trans)\n{\n    int rv = 0;\n\n    if (self->wm->client_info->unicode_input_support == UIS_SUPPORTED)\n    {\n        struct stream *s = trans_get_out_s(self->chan_trans, 8192);\n        if (s == NULL)\n        {\n            rv = 1;\n        }\n        else\n        {\n            out_uint32_le(s, 0); /* version */\n            out_uint32_le(s, 8 + 8); /* size */\n            out_uint32_le(s, 21); /* msg id */\n            out_uint32_le(s, 8); /* size */\n            s_mark_end(s);\n\n            rv = trans_write_copy(self->chan_trans);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nint xrdp_mm_send_unicode_to_chansrv(struct xrdp_mm *self,\n                                    int key_down,\n                                    char32_t unicode)\n{\n    struct stream *s = trans_get_out_s(self->chan_trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0);  /* version */\n    out_uint32_le(s, 24); /* size */\n    out_uint32_le(s, 23); /* msg id */\n    out_uint32_le(s, 16); /* size */\n    out_uint32_le(s, key_down);\n    out_uint32_le(s, unicode);\n    s_mark_end(s);\n    return trans_write_copy(self->chan_trans);\n}\n\n/*****************************************************************************/\n/* returns error\n   process rail create window order */\nstatic int\nxrdp_mm_process_rail_create_window(struct xrdp_mm *self, struct stream *s)\n{\n    int flags;\n    int window_id;\n    int title_bytes;\n    int index;\n    int bytes;\n    int rv;\n    struct rail_window_state_order rwso;\n\n    g_memset(&rwso, 0, sizeof(rwso));\n    in_uint32_le(s, window_id);\n\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_mm_process_rail_create_window: 0x%8.8x\", window_id);\n\n    in_uint32_le(s, rwso.owner_window_id);\n    in_uint32_le(s, rwso.style);\n    in_uint32_le(s, rwso.extended_style);\n    in_uint32_le(s, rwso.show_state);\n    in_uint16_le(s, title_bytes);\n    if (title_bytes > 0)\n    {\n        rwso.title_info = g_new(char, title_bytes + 1);\n        in_uint8a(s, rwso.title_info, title_bytes);\n        rwso.title_info[title_bytes] = 0;\n    }\n    in_uint32_le(s, rwso.client_offset_x);\n    in_uint32_le(s, rwso.client_offset_y);\n    in_uint32_le(s, rwso.client_area_width);\n    in_uint32_le(s, rwso.client_area_height);\n    in_uint32_le(s, rwso.rp_content);\n    in_uint32_le(s, rwso.root_parent_handle);\n    in_uint32_le(s, rwso.window_offset_x);\n    in_uint32_le(s, rwso.window_offset_y);\n    in_uint32_le(s, rwso.window_client_delta_x);\n    in_uint32_le(s, rwso.window_client_delta_y);\n    in_uint32_le(s, rwso.window_width);\n    in_uint32_le(s, rwso.window_height);\n    in_uint16_le(s, rwso.num_window_rects);\n    if (rwso.num_window_rects > 0)\n    {\n        bytes = sizeof(struct rail_window_rect) * rwso.num_window_rects;\n        rwso.window_rects = (struct rail_window_rect *)g_malloc(bytes, 0);\n        for (index = 0; index < rwso.num_window_rects; index++)\n        {\n            in_uint16_le(s, rwso.window_rects[index].left);\n            in_uint16_le(s, rwso.window_rects[index].top);\n            in_uint16_le(s, rwso.window_rects[index].right);\n            in_uint16_le(s, rwso.window_rects[index].bottom);\n        }\n    }\n    in_uint32_le(s, rwso.visible_offset_x);\n    in_uint32_le(s, rwso.visible_offset_y);\n    in_uint16_le(s, rwso.num_visibility_rects);\n    if (rwso.num_visibility_rects > 0)\n    {\n        bytes = sizeof(struct rail_window_rect) * rwso.num_visibility_rects;\n        rwso.visibility_rects = (struct rail_window_rect *)g_malloc(bytes, 0);\n        for (index = 0; index < rwso.num_visibility_rects; index++)\n        {\n            in_uint16_le(s, rwso.visibility_rects[index].left);\n            in_uint16_le(s, rwso.visibility_rects[index].top);\n            in_uint16_le(s, rwso.visibility_rects[index].right);\n            in_uint16_le(s, rwso.visibility_rects[index].bottom);\n        }\n    }\n    in_uint32_le(s, flags);\n    rv = libxrdp_orders_init(self->wm->session);\n    if (rv == 0)\n    {\n        rv = libxrdp_window_new_update(self->wm->session, window_id, &rwso, flags);\n    }\n    if (rv == 0)\n    {\n        rv = libxrdp_orders_send(self->wm->session);\n    }\n    g_free(rwso.title_info);\n    g_free(rwso.window_rects);\n    g_free(rwso.visibility_rects);\n    return rv;\n}\n\n#if 0\n/*****************************************************************************/\n/* returns error\n   process rail configure window order */\nstatic int\nxrdp_mm_process_rail_configure_window(struct xrdp_mm *self, struct stream *s)\n{\n    int flags;\n    int window_id;\n    int index;\n    int bytes;\n    int rv;\n    struct rail_window_state_order rwso;\n\n    g_memset(&rwso, 0, sizeof(rwso));\n    in_uint32_le(s, window_id);\n\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_mm_process_rail_configure_window: 0x%8.8x\", window_id);\n\n    in_uint32_le(s, rwso.client_offset_x);\n    in_uint32_le(s, rwso.client_offset_y);\n    in_uint32_le(s, rwso.client_area_width);\n    in_uint32_le(s, rwso.client_area_height);\n    in_uint32_le(s, rwso.rp_content);\n    in_uint32_le(s, rwso.root_parent_handle);\n    in_uint32_le(s, rwso.window_offset_x);\n    in_uint32_le(s, rwso.window_offset_y);\n    in_uint32_le(s, rwso.window_client_delta_x);\n    in_uint32_le(s, rwso.window_client_delta_y);\n    in_uint32_le(s, rwso.window_width);\n    in_uint32_le(s, rwso.window_height);\n    in_uint16_le(s, rwso.num_window_rects);\n    if (rwso.num_window_rects > 0)\n    {\n        bytes = sizeof(struct rail_window_rect) * rwso.num_window_rects;\n        rwso.window_rects = (struct rail_window_rect *)g_malloc(bytes, 0);\n        for (index = 0; index < rwso.num_window_rects; index++)\n        {\n            in_uint16_le(s, rwso.window_rects[index].left);\n            in_uint16_le(s, rwso.window_rects[index].top);\n            in_uint16_le(s, rwso.window_rects[index].right);\n            in_uint16_le(s, rwso.window_rects[index].bottom);\n        }\n    }\n    in_uint32_le(s, rwso.visible_offset_x);\n    in_uint32_le(s, rwso.visible_offset_y);\n    in_uint16_le(s, rwso.num_visibility_rects);\n    if (rwso.num_visibility_rects > 0)\n    {\n        bytes = sizeof(struct rail_window_rect) * rwso.num_visibility_rects;\n        rwso.visibility_rects = (struct rail_window_rect *)g_malloc(bytes, 0);\n        for (index = 0; index < rwso.num_visibility_rects; index++)\n        {\n            in_uint16_le(s, rwso.visibility_rects[index].left);\n            in_uint16_le(s, rwso.visibility_rects[index].top);\n            in_uint16_le(s, rwso.visibility_rects[index].right);\n            in_uint16_le(s, rwso.visibility_rects[index].bottom);\n        }\n    }\n    in_uint32_le(s, flags);\n    rv = libxrdp_orders_init(self->wm->session);\n    if (rv == 0)\n    {\n        rv = libxrdp_window_new_update(self->wm->session, window_id, &rwso, flags);\n    }\n    if (rv == 0)\n    {\n        rv = libxrdp_orders_send(self->wm->session);\n    }\n    g_free(rwso.window_rects);\n    g_free(rwso.visibility_rects);\n    return rv;\n}\n#endif\n\n/*****************************************************************************/\n/* returns error\n   process rail destroy window order */\nstatic int\nxrdp_mm_process_rail_destroy_window(struct xrdp_mm *self, struct stream *s)\n{\n    int window_id;\n    int rv;\n\n    in_uint32_le(s, window_id);\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_mm_process_rail_destroy_window 0x%8.8x\", window_id);\n    rv = libxrdp_orders_init(self->wm->session);\n    if (rv == 0)\n    {\n        rv = libxrdp_window_delete(self->wm->session, window_id);\n    }\n    if (rv == 0)\n    {\n        rv = libxrdp_orders_send(self->wm->session);\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error\n   process rail update window (show state) order */\nstatic int\nxrdp_mm_process_rail_show_window(struct xrdp_mm *self, struct stream *s)\n{\n    int window_id;\n    int rv;\n    int flags;\n    struct rail_window_state_order rwso;\n\n    g_memset(&rwso, 0, sizeof(rwso));\n    in_uint32_le(s, window_id);\n    in_uint32_le(s, flags);\n    in_uint32_le(s, rwso.show_state);\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_mm_process_rail_show_window 0x%8.8x %x\", window_id,\n        rwso.show_state);\n    rv = libxrdp_orders_init(self->wm->session);\n    if (rv == 0)\n    {\n        rv = libxrdp_window_new_update(self->wm->session, window_id, &rwso, flags);\n    }\n    if (rv == 0)\n    {\n        rv = libxrdp_orders_send(self->wm->session);\n    }\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error\n   process rail update window (title) order */\nstatic int\nxrdp_mm_process_rail_update_window_text(struct xrdp_mm *self, struct stream *s)\n{\n    int size;\n    int flags;\n    int rv;\n    int window_id;\n    struct rail_window_state_order rwso;\n\n    LOG(LOG_LEVEL_DEBUG, \"xrdp_mm_process_rail_update_window_text:\");\n    in_uint32_le(s, window_id);\n    in_uint32_le(s, flags);\n    LOG(LOG_LEVEL_DEBUG, \"  update window title info: 0x%8.8x\", window_id);\n\n    g_memset(&rwso, 0, sizeof(rwso));\n    in_uint32_le(s, size); /* title size */\n    if (size < 0 || !s_check_rem(s, size))\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s : invalid window text size %d\",\n            __func__, size);\n        return 1;\n    }\n    rwso.title_info = g_new(char, size + 1);\n    in_uint8a(s, rwso.title_info, size);\n    rwso.title_info[size] = 0;\n    LOG(LOG_LEVEL_DEBUG, \"  set window title %s size %d 0x%8.8x\", rwso.title_info, size, flags);\n    rv = libxrdp_orders_init(self->wm->session);\n    if (rv == 0)\n    {\n        rv = libxrdp_window_new_update(self->wm->session, window_id, &rwso, flags);\n    }\n    if (rv == 0)\n    {\n        rv = libxrdp_orders_send(self->wm->session);\n    }\n    LOG(LOG_LEVEL_DEBUG, \"  set window title %s %d\", rwso.title_info, rv);\n\n    g_free(rwso.title_info);\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns error\n   process alternate secondary drawing orders for rail channel */\nstatic int\nxrdp_mm_process_rail_drawing_orders(struct xrdp_mm *self, struct stream *s)\n{\n    int order_type;\n    int rv;\n\n    rv = 0;\n    in_uint32_le(s, order_type);\n\n    switch (order_type)\n    {\n        case 2: /* create_window */\n            xrdp_mm_process_rail_create_window(self, s);\n            break;\n        case 4: /* destroy_window */\n            xrdp_mm_process_rail_destroy_window(self, s);\n            break;\n        case 6: /* show_window */\n            rv = xrdp_mm_process_rail_show_window(self, s);\n            break;\n        case 8: /* update title info */\n            rv = xrdp_mm_process_rail_update_window_text(self, s);\n            break;\n        default:\n            break;\n    }\n\n    return rv;\n}\n\n#define GFX_PLANAR_BYTES (32 * 1024)\n\n/******************************************************************************/\nint\nxrdp_mm_egfx_send_planar_bitmap(struct xrdp_mm *self,\n                                struct xrdp_bitmap *bitmap,\n                                struct xrdp_rect *rect, int surface_id,\n                                int x, int y)\n{\n    struct xrdp_egfx_rect gfx_rect;\n    struct stream *comp_s;\n    struct stream *temp_s;\n    char *pixels;\n    char *src8;\n    char *dst8;\n    int index;\n    int lines;\n    int comp_bytes;\n    int xindex;\n    int yindex;\n    int bwidth;\n    int bheight;\n    int cx;\n    int cy;\n    int rv = 0;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_egfx_send_planar_bitmap:\");\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_egfx_send_planar_bitmap: \"\n              \"surface_id %d rect %d %d %d %d x %d y %d\",\n              surface_id, rect->left, rect->top, rect->right, rect->bottom,\n              x, y);\n    bwidth = rect->right - rect->left;\n    bheight = rect->bottom - rect->top;\n    if ((bwidth < 1) || (bheight < 1))\n    {\n        return 0;\n    }\n    if (bwidth < 64)\n    {\n        cx = bwidth;\n        cy = 4096 / cx;\n    }\n    else if (bheight < 64)\n    {\n        cy = bheight;\n        cx = 4096 / cy;\n    }\n    else\n    {\n        cx = 64;\n        cy = 64;\n    }\n    while (cx * cy < 4096)\n    {\n        if (cx < cy)\n        {\n            cx++;\n            cy = 4096 / cx;\n        }\n        else\n        {\n            cy++;\n            cx = 4096 / cy;\n        }\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_egfx_send_planar_bitmap: cx %d cy %d\", cx, cy);\n    pixels = g_new(char, GFX_PLANAR_BYTES);\n    make_stream(comp_s);\n    init_stream(comp_s, GFX_PLANAR_BYTES);\n    make_stream(temp_s);\n    init_stream(temp_s, GFX_PLANAR_BYTES);\n    if (xrdp_egfx_send_frame_start(self->egfx, 1, 0) != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_send_planar_bitmap: \"\n            \"xrdp_egfx_send_frame_start error\");\n        rv = 1;\n        goto cleanup;\n    }\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_egfx_send_planar_bitmap: left %d top %d right %d \"\n              \"bottom %d\", rect->left, rect->top, rect->right, rect->bottom);\n    for (yindex = rect->top; yindex < rect->bottom; yindex += cy)\n    {\n        bheight = rect->bottom - yindex;\n        bheight = MIN(bheight, cy);\n        for (xindex = rect->left; xindex < rect->right; xindex += cx)\n        {\n            bwidth = rect->right - xindex;\n            bwidth = MIN(bwidth, cx);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_egfx_send_planar_bitmap: xindex %d \"\n                      \"yindex %d, bwidth %d bheight %d\",\n                      xindex, yindex, bwidth, bheight);\n            src8 = bitmap->data + bitmap->line_size * yindex + xindex * 4;\n            dst8 = pixels + (bheight - 1) * bwidth * 4;\n            for (index = 0; index < bheight; index++)\n            {\n                g_memcpy(dst8, src8, bwidth * 4);\n                src8 += bitmap->line_size;\n                dst8 -= bwidth * 4;\n            }\n            lines = libxrdp_planar_compress(pixels, bwidth, bheight, comp_s,\n                                            32, GFX_PLANAR_BYTES, bheight - 1,\n                                            temp_s, 0, 0x10);\n            comp_s->end = comp_s->p;\n            comp_s->p = comp_s->data;\n            if (lines != bheight)\n            {\n                LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_send_planar_bitmap: \"\n                    \"lines(%d) != bheight(%d) error\", lines, bheight);\n            }\n            else\n            {\n                comp_bytes = (int)(comp_s->end - comp_s->data);\n                LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_egfx_send_planar_bitmap: lines %d \"\n                          \"comp_bytes %d\", lines, comp_bytes);\n                gfx_rect.x1 = xindex - x;\n                gfx_rect.y1 = yindex - y;\n                gfx_rect.x2 = gfx_rect.x1 + bwidth;\n                gfx_rect.y2 = gfx_rect.y1 + bheight;\n                if (xrdp_egfx_send_wire_to_surface1(self->egfx, surface_id,\n                                                    XR_RDPGFX_CODECID_PLANAR,\n                                                    XR_PIXEL_FORMAT_XRGB_8888,\n                                                    &gfx_rect, comp_s->data,\n                                                    comp_bytes) != 0)\n                {\n                    LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_send_planar_bitmap: \"\n                        \"xrdp_egfx_send_wire_to_surface1 error\");\n                    rv = 1;\n                    goto cleanup;\n                }\n            }\n        }\n    }\n    if (xrdp_egfx_send_frame_end(self->egfx, 1) != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_send_planar_bitmap: \"\n            \"xrdp_egfx_send_frame_end error\");\n        rv = 1;\n    }\ncleanup:\n    g_free(pixels);\n    free_stream(comp_s);\n    free_stream(temp_s);\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\nxrdp_mm_egfx_invalidate_wm_screen(struct xrdp_mm *self)\n{\n    int error = 0;\n\n    LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_invalidate_wm_screen:\");\n\n    // Only invalidate the WM screen if the module is using the WM screen,\n    // or we haven't loaded the module yet.\n    //\n    // Otherwise we may send client updates which conflict with the\n    // updates sent directly from the module via the encoder.\n    if (self->mod_uses_wm_screen_for_gfx || self->mod_handle == 0)\n    {\n        struct xrdp_bitmap *screen = self->wm->screen;\n        struct xrdp_rect xr_rect;\n\n        xr_rect.left = 0;\n        xr_rect.top = 0;\n        xr_rect.right = screen->width;\n        xr_rect.bottom = screen->height;\n        if (self->wm->screen_dirty_region == NULL)\n        {\n            self->wm->screen_dirty_region = xrdp_region_create(self->wm);\n        }\n        error = xrdp_region_add_rect(self->wm->screen_dirty_region, &xr_rect);\n    }\n    return error;\n}\n\n/******************************************************************************/\nstatic int\ndynamic_monitor_open_response(struct xrdp_process *id, int chan_id,\n                              int creation_status)\n{\n    struct xrdp_wm *wm;\n    struct stream *s;\n    int bytes;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"dynamic_monitor_open_response: chan_id %d \"\n              \"creation_status 0x%8.8x\", chan_id, creation_status);\n    if (creation_status != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"dynamic_monitor_open_response: error\");\n        return 1;\n    }\n    wm = id->wm;\n    make_stream(s);\n    init_stream(s, 1024);\n    out_uint32_le(s, 5); /* DISPLAYCONTROL_PDU_TYPE_CAPS */\n    out_uint32_le(s, 8 + 12);\n    out_uint32_le(s, CLIENT_MONITOR_DATA_MAXIMUM_MONITORS); /* MaxNumMonitors */\n    out_uint32_le(s, 4096); /* MaxMonitorAreaFactorA */\n    out_uint32_le(s, 2048); /* MaxMonitorAreaFactorB */\n    s_mark_end(s);\n    bytes = (int) (s->end - s->data);\n    libxrdp_drdynvc_data(wm->session, chan_id, s->data, bytes);\n    free_stream(s);\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\ndynamic_monitor_close_response(struct xrdp_process *id, int chan_id)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"dynamic_monitor_close_response:\");\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\ndynamic_monitor_data_first(struct xrdp_process *id, int chan_id,\n                           char *data, int bytes, int total_bytes)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"dynamic_monitor_data_first:\");\n    return 0;\n}\n\n/******************************************************************************/\nint\nadvance_resize_state_machine(struct xrdp_mm *mm,\n                             enum display_resize_state new_state)\n{\n    struct display_control_monitor_layout_data *description = mm->resize_data;\n    LOG_DEVEL(LOG_LEVEL_INFO,\n              \"advance_resize_state_machine:\"\n              \" Processing resize to: %d x %d.\"\n              \" Advancing state from %s to %s.\"\n              \" Previous state took %u MS.\",\n              description->description.session_width,\n              description->description.session_height,\n              XRDP_DISPLAY_RESIZE_STATE_TO_STR(description->state),\n              XRDP_DISPLAY_RESIZE_STATE_TO_STR(new_state),\n              g_get_elapsed_ms() - description->last_state_update_timestamp);\n    description->state = new_state;\n    description->last_state_update_timestamp = g_get_elapsed_ms();\n    g_set_wait_obj(mm->resize_ready);\n    return 0;\n}\n\nstruct ver_flags_t\n{\n    int version;\n    int flags;\n};\n\n/******************************************************************************/\nstatic int\ncmpverfunc (const void *a, const void *b)\n{\n    return ((struct ver_flags_t *)a)->version -\n           ((struct ver_flags_t *)b)->version;\n}\n\n/******************************************************************************/\nstatic int\nxrdp_mm_egfx_create_surfaces(struct xrdp_mm *self)\n{\n    int surface_id;\n    int index;\n    int count;\n    int left;\n    int top;\n    int width;\n    int height;\n    struct monitor_info *mi;\n    struct xrdp_bitmap *screen;\n\n    screen = self->wm->screen;\n    count = self->wm->client_info->display_sizes.monitorCount;\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_mm_egfx_create_surfaces: \"\n              \"monitor count %d\", count);\n    if (count < 1)\n    {\n        left = 0;\n        top = 0;\n        width = screen->width;\n        height = screen->height;\n        xrdp_egfx_send_create_surface(self->egfx, self->egfx->surface_id,\n                                      width, height,\n                                      XR_PIXEL_FORMAT_XRGB_8888);\n        xrdp_egfx_send_map_surface(self->egfx, self->egfx->surface_id,\n                                   left, top);\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_create_surfaces: map \"\n            \"surface_id %d left %d top %d width %d height %d\",\n            self->egfx->surface_id, left, top, width, height);\n        return 0;\n    }\n    for (index = 0; index < count; index++)\n    {\n        surface_id = index;\n        mi = self->wm->client_info->display_sizes.minfo_wm + index;\n        left = mi->left;\n        top = mi->top;\n        width = mi->right - mi->left + 1;\n        height = mi->bottom - mi->top + 1;\n        xrdp_egfx_send_create_surface(self->egfx, surface_id,\n                                      width, height,\n                                      XR_PIXEL_FORMAT_XRGB_8888);\n        xrdp_egfx_send_map_surface(self->egfx, surface_id, left, top);\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_create_surfaces: map \"\n            \"surface_id %d left %d top %d width %d height %d\",\n            surface_id, left, top, width, height);\n    }\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nxrdp_mm_egfx_caps_advertise(void *user, int caps_count,\n                            int *versions, int *flagss)\n{\n    struct xrdp_mm *self;\n    struct xrdp_bitmap *screen;\n    int index;\n    int best_h264_index;\n    int best_pro_index;\n    int error;\n    int version;\n    int flags;\n    struct ver_flags_t *ver_flags;\n\n#if !defined(XRDP_H264)\n    UNUSED_VAR(best_h264_index);\n#endif\n\n    LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_caps_advertise:\");\n    self = (struct xrdp_mm *) user;\n    screen = self->wm->screen;\n    if (screen->data == NULL)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_caps_advertise: can not do gfx\");\n    }\n    /* create copy for sorting */\n    ver_flags = g_new(struct ver_flags_t, caps_count);\n    if (ver_flags == NULL)\n    {\n        return 1;\n    }\n    for (index = 0; index < caps_count; index++)\n    {\n        ver_flags[index].version = versions[index];\n        ver_flags[index].flags = flagss[index];\n    }\n    /* sort by version */\n    g_qsort(ver_flags, caps_count, sizeof(struct ver_flags_t), cmpverfunc);\n    best_h264_index = -1;\n    best_pro_index = -1;\n    for (index = 0; index < caps_count; index++)\n    {\n        version = ver_flags[index].version;\n        flags = ver_flags[index].flags;\n        LOG(LOG_LEVEL_INFO, \"  version 0x%8.8x flags 0x%8.8x (index: %d)\",\n            version, flags, index);\n        switch (version)\n        {\n            case XR_RDPGFX_CAPVERSION_8: /* FALLTHROUGH */\n            case XR_RDPGFX_CAPVERSION_101:\n                best_pro_index = index;\n                break;\n            case XR_RDPGFX_CAPVERSION_81:\n                if (flags & XR_RDPGFX_CAPS_FLAG_AVC420_ENABLED)\n                {\n                    best_h264_index = index;\n                }\n                best_pro_index = index;\n                break;\n            case XR_RDPGFX_CAPVERSION_10:\n                if (!(flags & XR_RDPGFX_CAPS_FLAG_AVC_DISABLED))\n                {\n                    best_h264_index = index;\n                }\n                best_pro_index = index;\n                break;\n            case XR_RDPGFX_CAPVERSION_102: /* FALLTHROUGH */\n            case XR_RDPGFX_CAPVERSION_103: /* FALLTHROUGH */\n            case XR_RDPGFX_CAPVERSION_104: /* FALLTHROUGH */\n            case XR_RDPGFX_CAPVERSION_105: /* FALLTHROUGH */\n            case XR_RDPGFX_CAPVERSION_106: /* FALLTHROUGH */\n            case XR_RDPGFX_CAPVERSION_107:\n                if (!(flags & XR_RDPGFX_CAPS_FLAG_AVC_DISABLED))\n                {\n                    best_h264_index = index;\n                }\n                best_pro_index = index;\n                break;\n            default:\n                /* just skip unknwown */\n                LOG(LOG_LEVEL_INFO, \"unknown version 0x%8.8x\", version);\n                break;\n        }\n    }\n\n    int best_index = -1;\n    struct xrdp_tconfig_gfx_codec_order *co = &self->wm->gfx_config->codec;\n    char cobuff[64];\n\n    LOG(LOG_LEVEL_INFO, \"Codec search order is %s\",\n        tconfig_codec_order_to_str(co, cobuff, sizeof(cobuff)));\n    for (index = 0 ; index < co->codec_count ; ++index)\n    {\n#if defined(XRDP_H264)\n        if (co->codecs[index] == XTC_H264 && best_h264_index >= 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"Matched H264 mode\");\n            best_index = best_h264_index;\n            self->egfx_flags = XRDP_EGFX_H264;\n            break;\n        }\n#endif\n\n        if (co->codecs[index] == XTC_RFX && best_pro_index >= 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"Matched RFX mode\");\n            best_index = best_pro_index;\n            self->egfx_flags = XRDP_EGFX_RFX_PRO;\n            break;\n        }\n    }\n\n    if (best_index >= 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"  replying version 0x%8.8x flags 0x%8.8x\",\n            ver_flags[best_index].version, ver_flags[best_index].flags);\n        error = xrdp_egfx_send_capsconfirm(self->egfx,\n                                           ver_flags[best_index].version,\n                                           ver_flags[best_index].flags);\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_caps_advertise: xrdp_egfx_send_capsconfirm \"\n            \"error %d best_index %d\", error, best_index);\n        error = xrdp_egfx_send_reset_graphics(self->egfx,\n                                              screen->width, screen->height,\n                                              self->wm->client_info->display_sizes.monitorCount,\n                                              self->wm->client_info->display_sizes.minfo);\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_caps_advertise: xrdp_egfx_send_reset_graphics \"\n            \"error %d monitorCount %d\",\n            error, self->wm->client_info->display_sizes.monitorCount);\n        self->egfx_up = 1;\n        xrdp_mm_egfx_create_surfaces(self);\n        self->encoder = xrdp_encoder_create(self);\n        xrdp_mm_egfx_invalidate_wm_screen(self);\n\n        if (self->resize_data != NULL\n                && self->resize_data->state == WMRZ_EGFX_INITALIZING)\n        {\n            advance_resize_state_machine(self, WMRZ_EGFX_INITIALIZED);\n        }\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_caps_advertise: egfx created.\");\n        if (self->gfx_delay_autologin)\n        {\n            self->gfx_delay_autologin = 0;\n            xrdp_wm_set_login_state(self->wm, WMLS_START_CONNECT);\n        }\n    }\n    else\n    {\n        struct xrdp_rect lrect;\n\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_caps_advertise: no good gfx, canceling\");\n        lrect.left = 0;\n        lrect.top = 0;\n        lrect.right = screen->width;\n        lrect.bottom = screen->height;\n        self->wm->client_info->gfx = 0;\n        xrdp_encoder_delete(self->encoder);\n        self->encoder = xrdp_encoder_create(self);\n        xrdp_bitmap_invalidate(screen, &lrect);\n    }\n    g_free(ver_flags);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_update_module_frame_ack(struct xrdp_mm *self)\n{\n    struct xrdp_encoder *encoder;\n\n    encoder = self->encoder;\n    if (encoder == NULL)\n    {\n        // Can't pass the ack to the encoder. Tell the module all\n        // frames are ACK'd\n        struct xrdp_mod *m = self->mod;\n        if (m != NULL)\n        {\n            m->mod_frame_ack(m, 0, INT_MAX);\n        }\n    }\n    else\n    {\n        int fif = encoder->frames_in_flight;\n        if (encoder->frame_id_client + fif > encoder->frame_id_server)\n        {\n            if (encoder->frame_id_server > encoder->frame_id_server_sent)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_update_module_ack: \"\n                          \"frame_id_server %d\", encoder->frame_id_server);\n                encoder->frame_id_server_sent = encoder->frame_id_server;\n                struct xrdp_mod *m = self->mod;\n                if (m != NULL)\n                {\n                    m->mod_frame_ack(m, 0,\n                                     encoder->frame_id_server);\n                }\n            }\n        }\n    }\n    return 0;\n}\n\nstatic int\nxrdp_mm_egfx_frame_ack(void *user, uint32_t queue_depth, int frame_id,\n                       int frames_decoded)\n{\n    struct xrdp_mm *self;\n    struct xrdp_encoder *encoder;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_egfx_frame_ack:\");\n    self = (struct xrdp_mm *) user;\n    encoder = self->encoder;\n    if (encoder == NULL)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_frame_ack: encoder is nil\");\n        return 0;\n    }\n    if (queue_depth == XR_SUSPEND_FRAME_ACKNOWLEDGEMENT)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_frame_ack: \"\n            \"queue_depth %d frame_id %d frames_decoded %d\",\n            queue_depth, frame_id, frames_decoded);\n        if (encoder->gfx_ack_off == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_mm_egfx_frame_ack: \"\n                \"client request turn off frame acks.\");\n            encoder->gfx_ack_off = 1;\n            frame_id = -1;\n        }\n    }\n    else\n    {\n        if (encoder->gfx_ack_off)\n        {\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_egfx_frame_ack: \"\n                      \"client request turn on frame acks\");\n            encoder->gfx_ack_off = 0;\n        }\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_egfx_frame_ack: \"\n              \"incoming %d, client %d, server %d\",\n              frame_id, encoder->frame_id_client, encoder->frame_id_server);\n    if (frame_id < 0 || frame_id > encoder->frame_id_server)\n    {\n        /* if frame_id is negative or bigger then what server last sent\n           just ack all sent frames */\n        /* some clients can send big number just to clear all\n           pending frames */\n        encoder->frame_id_client = encoder->frame_id_server;\n    }\n    else\n    {\n        /* frame acks can come out of order so ignore older one */\n        encoder->frame_id_client = MAX(frame_id, encoder->frame_id_client);\n    }\n    xrdp_mm_update_module_frame_ack(self);\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\negfx_initialize(struct xrdp_mm *self)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"egfx_initialize\");\n    if (!(self->wm->client_info->gfx))\n    {\n        return 0;\n    }\n    LOG_DEVEL(LOG_LEVEL_INFO, \"egfx_initialize: gfx capable client\");\n    if (xrdp_egfx_create(self, &(self->egfx)) == 0)\n    {\n        self->egfx->user = self;\n        self->egfx->caps_advertise = xrdp_mm_egfx_caps_advertise;\n        self->egfx->frame_ack = xrdp_mm_egfx_frame_ack;\n        return 0;\n    }\n    LOG_DEVEL(LOG_LEVEL_INFO, \"egfx_initialize: xrdp_egfx_create failed\");\n    return 1;\n}\n\n/******************************************************************************/\nstatic const int MAXIMUM_MONITOR_SIZE\n    = sizeof(struct monitor_info) * CLIENT_MONITOR_DATA_MAXIMUM_MONITORS;\n\n/******************************************************************************/\nstatic void\nsync_dynamic_monitor_data(struct xrdp_wm *wm,\n                          struct display_size_description *description)\n{\n    struct display_size_description *display_sizes\n        = &(wm->client_info->display_sizes);\n\n    display_sizes->monitorCount = description->monitorCount;\n    display_sizes->session_width = description->session_width;\n    display_sizes->session_height = description->session_height;\n    g_memcpy(display_sizes->minfo,\n             description->minfo,\n             MAXIMUM_MONITOR_SIZE);\n    g_memcpy(display_sizes->minfo_wm,\n             description->minfo_wm,\n             MAXIMUM_MONITOR_SIZE);\n}\n\n/******************************************************************************/\n/**\n * Single point to add requests to the resize queue\n *\n * @param self xrdp_mm object\n * @param src Where the request is coming from\n * @param description The requt we're adding\n * @return 0 for success\n */\nstatic int\nadd_resize_request_to_queue(struct xrdp_mm *self,\n                            enum resize_queue_source src,\n                            const struct display_size_description *description)\n{\n    int rv = 0;\n    struct resize_queue_item *resize_queue_item;\n    resize_queue_item = (struct resize_queue_item *)\n                        malloc(sizeof(struct resize_queue_item));\n    if (resize_queue_item == NULL)\n    {\n        rv = 1;\n    }\n    else\n    {\n        resize_queue_item->src = src;\n        resize_queue_item->description = *description;\n\n        // See if there's already a previous item on the queue\n        if (self->resize_queue->count > 0)\n        {\n            int prev_num = self->resize_queue->count - 1;\n            struct resize_queue_item *prev;\n            prev = (struct resize_queue_item *)\n                   list_get_item(self->resize_queue, prev_num);\n            // If this is a RQ_FROM_CLIENT, and the previous item on the\n            // resize_queue is also RQ_FROM_CLIENT, and it hasn't yet been\n            // processed, we can simply ignore it\n            if (src == RQ_FROM_CLIENT && prev->src == RQ_FROM_CLIENT)\n            {\n                LOG_DEVEL(LOG_LEVEL_DEBUG,\n                          \"dynamic_monitor_data: Removing unactioned resize request\"\n                          \" width %d, height %d.\",\n                          prev->description.session_width,\n                          prev->description.session_height);\n                list_remove_item(self->resize_queue, prev_num);\n            }\n        }\n        if (!list_add_item(self->resize_queue, (tintptr)resize_queue_item))\n        {\n            free(resize_queue_item);\n            rv = 1;\n        }\n        else\n        {\n            // This call only has an effect if the wait_obj is not\n            // NULL_WAIT_OBJ\n            g_set_wait_obj(self->resize_ready);\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\nstatic int\ndynamic_monitor_data(struct xrdp_process *id, int chan_id,\n                     char *data, int bytes)\n{\n    int error = 0;\n    struct stream ls;\n    struct stream *s;\n    int msg_type;\n    int msg_length;\n    struct xrdp_wm *wm;\n    int monitor_layout_size;\n    struct display_size_description description;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"dynamic_monitor_data:\");\n    wm = id->wm;\n\n    if (OUTPUT_SUPPRESSED_FOR_REASON(wm->client_info,\n                                     XSO_REASON_CLIENT_REQUEST))\n    {\n        LOG(LOG_LEVEL_INFO, \"dynamic_monitor_data: Not allowing resize.\"\n            \" Suppress output requested by client\");\n        return error;\n    }\n\n    g_memset(&ls, 0, sizeof(ls));\n    ls.data = data;\n    ls.p = ls.data;\n    ls.size = bytes;\n    ls.end = ls.data + bytes;\n    s = &ls;\n    in_uint32_le(s, msg_type);\n    in_uint32_le(s, msg_length);\n    LOG_DEVEL(LOG_LEVEL_DEBUG,\n              \"dynamic_monitor_data: msg_type %d msg_length %d\",\n              msg_type, msg_length);\n\n    if (msg_type != DISPLAYCONTROL_PDU_TYPE_MONITOR_LAYOUT\n            && msg_length >= 0)\n    {\n        // Unsupported message types\n        switch (msg_type)\n        {\n            case DISPLAYCONTROL_PDU_TYPE_CAPS:\n                LOG(LOG_LEVEL_ERROR, \"dynamic_monitor_data: Received\"\n                    \" DISPLAYCONTROL_PDU_TYPE_CAPS. Per MS-RDPEDISP 2.2.2.1,\"\n                    \" this is a server-to-client message, client should never\"\n                    \" send this. Ignoring message\");\n                break;\n            default:\n                LOG(LOG_LEVEL_ERROR, \"dynamic_monitor_data: Received neither\"\n                    \" DISPLAYCONTROL_PDU_TYPE_MONITOR_LAYOUT nor\"\n                    \" DISPLAYCONTROL_PDU_TYPE_CAPS. Ignoring message.\");\n                break;\n        }\n        return 0;\n    }\n    in_uint32_le(s, monitor_layout_size);\n    if (monitor_layout_size != 40)\n    {\n        /* 2.2.2.2 DISPLAYCONTROL_MONITOR_LAYOUT_PDU */\n        LOG(LOG_LEVEL_ERROR, \"dynamic_monitor_data: monitor_layout_size\"\n            \" is %d. Per spec ([MS-RDPEDISP] 2.2.2.2\"\n            \" DISPLAYCONTROL_MONITOR_LAYOUT_PDU) it must be 40.\",\n            monitor_layout_size);\n        return 1;\n    }\n\n    error = libxrdp_process_monitor_stream(s, &description, 1);\n    if (error)\n    {\n        LOG(LOG_LEVEL_ERROR, \"dynamic_monitor_data:\"\n            \" libxrdp_process_monitor_stream\"\n            \" failed with error %d.\", error);\n        return error;\n    }\n    error = add_resize_request_to_queue(wm->mm, RQ_FROM_CLIENT, &description);\n    if (error)\n    {\n        LOG(LOG_LEVEL_ERROR, \"dynamic_monitor_data:\"\n            \" out of memory adding resize request to queue\");\n        return error;\n    }\n    LOG(LOG_LEVEL_DEBUG, \"dynamic_monitor_data:\"\n        \" received width %d, received height %d, queue %s\",\n        description.session_width,\n        description.session_height,\n        (wm->mm->resize_ready == NULL_WAIT_OBJ) ? \"inactive\" : \"active\");\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nadvance_error(int error,\n              struct xrdp_mm *mm)\n{\n    advance_resize_state_machine(mm, WMRZ_ERROR);\n    return error;\n}\n\n/******************************************************************************/\nstatic int\nprocess_display_control_monitor_layout_data(struct xrdp_wm *wm)\n{\n    int error = 0;\n    struct xrdp_mm *mm;\n    struct xrdp_mod *module;\n    struct xrdp_rdp *rdp;\n    struct xrdp_sec *sec;\n    struct xrdp_channel *chan;\n    int in_progress;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"process_display_control_monitor_layout_data:\");\n\n    if (wm == NULL)\n    {\n        return 1;\n    }\n    mm = wm->mm;\n    if (mm == NULL)\n    {\n        return 1;\n    }\n    module = mm->mod;\n    if (module == NULL)\n    {\n        return 1;\n    }\n\n    if (!xrdp_wm_can_resize(wm))\n    {\n        return 0;\n    }\n\n    struct display_control_monitor_layout_data *description\n            = mm->resize_data;\n    const unsigned int desc_width = description->description.session_width;\n    const unsigned int desc_height = description->description.session_height;\n\n    switch (description->state)\n    {\n        case WMRZ_ENCODER_DELETE:\n            // Stop any output from the module\n            rdp = wm->session->rdp;\n            xrdp_rdp_suppress_output(rdp,\n                                     1, XSO_REASON_DYNAMIC_RESIZE,\n                                     0, 0, 0, 0);\n            // Disable the encoder until the resize is complete.\n            if (mm->encoder != NULL)\n            {\n                xrdp_encoder_delete(mm->encoder);\n                mm->encoder = NULL;\n            }\n            if (mm->resize_data->using_egfx == 0)\n            {\n                advance_resize_state_machine(mm, WMRZ_SERVER_MONITOR_RESIZE);\n            }\n            else\n            {\n                advance_resize_state_machine(mm, WMRZ_EGFX_DELETE_SURFACE);\n            }\n            break;\n        case WMRZ_EGFX_DELETE_SURFACE:\n            if (error == 0 && module != 0)\n            {\n                xrdp_egfx_shutdown_delete_surface(mm->egfx);\n            }\n            advance_resize_state_machine(mm, WMRZ_EGFX_CONN_CLOSE);\n            break;\n        case WMRZ_EGFX_CONN_CLOSE:\n            if (error == 0 && module != 0)\n            {\n                xrdp_egfx_shutdown_close_connection(wm->mm->egfx);\n                mm->egfx_up = 0;\n            }\n            advance_resize_state_machine(mm, WMRZ_EGFX_CONN_CLOSING);\n            break;\n        // Also processed in xrdp_egfx_close_response\n        case WMRZ_EGFX_CONN_CLOSING:\n            rdp = wm->session->rdp;\n            sec = rdp->sec_layer;\n            chan = sec->chan_layer;\n\n            // Continue to check to see if the connection is closed. If it\n            // ever is, advance the state machine!\n            if (chan->drdynvcs[mm->egfx->channel_id].status\n                    == XRDP_DRDYNVC_STATUS_CLOSED\n                    || (g_get_elapsed_ms() - description->last_state_update_timestamp) > 100)\n            {\n                advance_resize_state_machine(mm, WMRZ_EGFX_CONN_CLOSED);\n                break;\n            }\n            g_set_wait_obj(mm->resize_ready);\n            break;\n        case WMRZ_EGFX_CONN_CLOSED:\n            advance_resize_state_machine(mm, WRMZ_EGFX_DELETE);\n            break;\n        case WRMZ_EGFX_DELETE:\n            if (error == 0 && module != 0)\n            {\n                xrdp_egfx_shutdown_delete(wm->mm->egfx);\n                mm->egfx = NULL;\n            }\n            advance_resize_state_machine(mm, WMRZ_SERVER_MONITOR_RESIZE);\n            break;\n        case WMRZ_SERVER_MONITOR_RESIZE:\n            error = module->mod_server_monitor_resize(\n                        module, desc_width, desc_height,\n                        description->description.monitorCount,\n                        description->description.minfo,\n                        &in_progress);\n            if (error != 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_INFO,\n                          \"process_display_control_monitor_layout_data:\"\n                          \" mod_server_monitor_resize failed %d\", error);\n                return advance_error(error, mm);\n            }\n            else if (in_progress)\n            {\n                // Call is proceeding asynchronously\n                advance_resize_state_machine(\n                    mm, WMRZ_SERVER_MONITOR_MESSAGE_PROCESSING);\n            }\n            else\n            {\n                // Call is done\n                advance_resize_state_machine(\n                    mm, WMRZ_SERVER_MONITOR_MESSAGE_PROCESSED);\n            }\n            break;\n        // Not processed here. Processed in client_monitor_resize\n        // case WMRZ_SERVER_MONITOR_MESSAGE_PROCESSING:\n        case WMRZ_SERVER_MONITOR_MESSAGE_PROCESSED:\n            advance_resize_state_machine(mm, WMRZ_XRDP_CORE_RESET);\n            break;\n        case WMRZ_XRDP_CORE_RESET:\n            sync_dynamic_monitor_data(wm, &(description->description));\n            error = libxrdp_reset(wm->session);\n            if (error != 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_INFO,\n                          \"process_display_control_monitor_layout_data:\"\n                          \" libxrdp_reset failed %d\", error);\n                return advance_error(error, mm);\n            }\n            /* reset cache */\n            error = xrdp_cache_reset(wm->cache, wm->client_info);\n            if (error != 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_INFO,\n                          \"process_display_control_monitor_layout_data:\"\n                          \" xrdp_cache_reset failed %d\", error);\n                return advance_error(error, mm);\n            }\n            advance_resize_state_machine(mm, WMRZ_XRDP_CORE_RESET_PROCESSING);\n            break;\n\n        // Not processed here. Processed in xrdp_mm_up_and_running()\n        // case WMRZ_XRDP_CORE_RESET_PROCESSING:\n        case WMRZ_XRDP_CORE_RESET_PROCESSED:\n            /* load some stuff */\n            error = xrdp_wm_load_static_colors_plus(wm, 0);\n            if (error != 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_INFO,\n                          \"process_display_control_monitor_layout_data:\"\n                          \" xrdp_wm_load_static_colors_plus failed %d\", error);\n                return advance_error(error, mm);\n            }\n\n            error = xrdp_wm_load_static_pointers(wm);\n            if (error != 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_INFO,\n                          \"process_display_control_monitor_layout_data:\"\n                          \" xrdp_wm_load_static_pointers failed %d\", error);\n                return advance_error(error, mm);\n            }\n            /* resize the main window */\n            error = xrdp_bitmap_resize(\n                        wm->screen, desc_width, desc_height);\n            if (error != 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_INFO,\n                          \"process_display_control_monitor_layout_data:\"\n                          \" xrdp_bitmap_resize failed %d\", error);\n                return advance_error(error, mm);\n            }\n            advance_resize_state_machine(mm, WMRZ_EGFX_INITIALIZE);\n            break;\n        case WMRZ_EGFX_INITIALIZE:\n            if (mm->resize_data->using_egfx)\n            {\n                egfx_initialize(mm);\n                advance_resize_state_machine(mm, WMRZ_EGFX_INITALIZING);\n            }\n            else\n            {\n                advance_resize_state_machine(mm, WMRZ_EGFX_INITIALIZED);\n            }\n            break;\n        // Not processed here. Processed in xrdp_mm_egfx_caps_advertise\n        // case WMRZ_EGFX_INITALIZING:\n        case WMRZ_EGFX_INITIALIZED:\n            advance_resize_state_machine(mm, WMRZ_ENCODER_CREATE);\n            break;\n        case WMRZ_ENCODER_CREATE:\n            if (mm->encoder == NULL)\n            {\n                mm->encoder = xrdp_encoder_create(mm);\n            }\n            advance_resize_state_machine(mm, WMRZ_SERVER_INVALIDATE);\n            break;\n        case WMRZ_SERVER_INVALIDATE:\n            if (module != 0)\n            {\n                // Ack all frames to speed up resize.\n                module->mod_frame_ack(module, 0, INT_MAX);\n            }\n            // Restart module output after invalidating\n            // the screen. This causes an automatic redraw.\n            xrdp_bitmap_invalidate(wm->screen, 0);\n            rdp = wm->session->rdp;\n            xrdp_rdp_suppress_output(rdp,\n                                     0, XSO_REASON_DYNAMIC_RESIZE,\n                                     0, 0, desc_width, desc_height);\n            advance_resize_state_machine(mm, WMRZ_COMPLETE);\n            break;\n        default:\n            break;\n    }\n    return 0;\n}\n\n/******************************************************************************/\n#ifdef USE_DEVEL_LOGGING\nstatic const char *\nresize_queue_source_to_str(enum resize_queue_source src)\n{\n    return\n        (src == RQ_IGNORE_MARKER) ? \"RQ_IGNORE_MARKER\" :\n        (src == RQ_FROM_SERVER) ? \"RQ_FROM_SERVER\" :\n        (src == RQ_FROM_CLIENT) ? \"RQ_FROM_CLIENT\" :\n        /* default */ \"<unknown>\";\n}\n#endif\n\n/******************************************************************************/\nstatic int\ndynamic_monitor_process_queue(struct xrdp_mm *self)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"dynamic_monitor_process_queue:\");\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    struct xrdp_wm *wm = self->wm;\n\n    if (!xrdp_wm_can_resize(wm))\n    {\n        return 0;\n    }\n\n    if (self->resize_data == NULL && self->resize_queue != NULL)\n    {\n        if  (self->resize_queue->count <= 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"Resize queue is empty.\");\n            return 0;\n        }\n        const struct resize_queue_item *queue_head =\n            (struct resize_queue_item *)list_get_item(self->resize_queue, 0);\n\n        LOG_DEVEL(LOG_LEVEL_INFO, \"dynamic_monitor_process_queue: source of\"\n                  \" resize queue head is %s\",\n                  resize_queue_source_to_str(queue_head->src));\n        const struct display_size_description *queued_size =\n                &queue_head->description;\n\n        const int invalid_dimensions = queued_size->session_width <= 0\n                                       || queued_size->session_height <= 0;\n\n        if (invalid_dimensions)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"dynamic_monitor_process_queue: Not allowing\"\n                \" resize due to invalid dimensions (w: %d x h: %d)\",\n                queued_size->session_width,\n                queued_size->session_height);\n        }\n\n        const struct display_size_description *current_size\n                = &wm->client_info->display_sizes;\n\n        const int already_this_size = queued_size->session_width\n                                      == current_size->session_width\n                                      && queued_size->session_height\n                                      == current_size->session_height;\n\n        if (already_this_size)\n        {\n            LOG(LOG_LEVEL_DEBUG,\n                \"dynamic_monitor_process_queue: Not resizing.\"\n                \" Already this size. (w: %d x h: %d)\",\n                queued_size->session_width,\n                queued_size->session_height);\n        }\n\n        if (!invalid_dimensions && !already_this_size)\n        {\n            const int LAYOUT_DATA_SIZE =\n                sizeof(struct display_control_monitor_layout_data);\n            self->resize_data = (struct display_control_monitor_layout_data *)\n                                g_malloc(LAYOUT_DATA_SIZE, 1);\n            self->resize_data->description = *queued_size;\n            const unsigned int time = g_get_elapsed_ms();\n            self->resize_data->start_time = time;\n            self->resize_data->last_state_update_timestamp = time;\n            self->resize_data->using_egfx = (self->egfx != NULL);\n            advance_resize_state_machine(self, WMRZ_ENCODER_DELETE);\n        }\n        else\n        {\n            g_set_wait_obj(self->resize_ready);\n        }\n        list_remove_item(self->resize_queue, 0);\n        return 0;\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"dynamic_monitor_process_queue:\"\n                  \" Resize data is not null.\");\n    }\n\n    if (self->resize_data == NULL)\n    {\n        return 0;\n    }\n\n    if (self->resize_data->state == WMRZ_COMPLETE)\n    {\n        LOG(LOG_LEVEL_INFO, \"dynamic_monitor_process_queue: Clearing\"\n            \" completed resize (w: %d x h: %d). It took %u milliseconds.\",\n            self->resize_data->description.session_width,\n            self->resize_data->description.session_height,\n            g_get_elapsed_ms() - self->resize_data->start_time);\n        g_set_wait_obj(self->resize_ready);\n    }\n    else if (self->resize_data->state == WMRZ_ERROR)\n    {\n        LOG(LOG_LEVEL_INFO, \"dynamic_monitor_process_queue: Clearing\"\n            \" failed request to resize to: (w: %d x h: %d)\",\n            self->resize_data->description.session_width,\n            self->resize_data->description.session_height);\n        g_set_wait_obj(self->resize_ready);\n    }\n    else\n    {\n        // No errors, process it!\n        return process_display_control_monitor_layout_data(self->wm);\n    }\n    g_free(self->resize_data);\n    self->resize_data = NULL;\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\ndynamic_monitor_initialize(struct xrdp_mm *self)\n{\n    struct xrdp_drdynvc_procs d_procs;\n    int flags;\n    int error;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"dynamic_monitor_initialize:\");\n\n    g_memset(&d_procs, 0, sizeof(d_procs));\n    d_procs.open_response = dynamic_monitor_open_response;\n    d_procs.close_response = dynamic_monitor_close_response;\n    d_procs.data_first = dynamic_monitor_data_first;\n    d_procs.data = dynamic_monitor_data;\n    flags = 0;\n    error = libxrdp_drdynvc_open(self->wm->session,\n                                 \"Microsoft::Windows::RDS::DisplayControl\",\n                                 flags, &d_procs,\n                                 &(self->dynamic_monitor_chanid));\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"dynamic_monitor_initialize: \"\n            \"libxrdp_drdynvc_open failed %d\", error);\n        return error;\n    }\n\n    return error;\n}\n\n/******************************************************************************/\nint\nxrdp_mm_drdynvc_up(struct xrdp_mm *self)\n{\n    struct display_size_description null_desc =\n    {\n        .monitorCount = 0,\n        .session_width = 0,\n        .session_height = 0\n    };\n    const char *enable_dynamic_resize;\n    int error = 0;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_drdynvc_up:\");\n\n    error = egfx_initialize(self);\n    if (error != 0)\n    {\n        return error;\n    }\n\n    enable_dynamic_resize = xrdp_mm_get_value(self, \"enable_dynamic_resizing\");\n    /*\n     * User can disable dynamic resizing if necessary\n     */\n    if (enable_dynamic_resize != NULL && enable_dynamic_resize[0] != '\\0' &&\n            !g_text2bool(enable_dynamic_resize))\n    {\n        LOG(LOG_LEVEL_INFO, \"User has disabled dynamic resizing.\");\n        return error;\n    }\n    error = dynamic_monitor_initialize(self);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"Dynamic monitor initialize failed.\"\n            \" Client likely does not support it.\");\n        return error;\n    }\n    error = add_resize_request_to_queue(self, RQ_IGNORE_MARKER, &null_desc);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"%s: Out of memory\", __func__);\n        error = 1;\n    }\n    return error;\n}\n\n/******************************************************************************/\nint\nxrdp_mm_suppress_output(struct xrdp_mm *self, int suppress,\n                        int left, int top, int right, int bottom)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_suppress_output: suppress %d \"\n              \"left %d top %d right %d bottom %d\",\n              suppress, left, top, right, bottom);\n    if (self->mod != NULL)\n    {\n        if (self->mod->mod_suppress_output != NULL)\n        {\n            self->mod->mod_suppress_output(self->mod, suppress,\n                                           left, top, right, bottom);\n        }\n    }\n    return 0;\n}\n\n/******************************************************************************/\nint\nxrdp_mm_up_and_running(struct xrdp_mm *self)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_up_and_running:\");\n    if (self->resize_data != NULL &&\n            self->resize_data->state == WMRZ_XRDP_CORE_RESET_PROCESSING)\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"xrdp_mm_up_and_running: Core reset done.\");\n        advance_resize_state_machine(self, WMRZ_XRDP_CORE_RESET_PROCESSED);\n    }\n    return 0;\n}\n\n/******************************************************************************/\nvoid\nxrdp_mm_set_fatal(struct xrdp_mm *self, int errinfo)\n{\n    if (self->wm->pro_layer->errinfo == ERRINFO_NONE)\n    {\n        self->wm->pro_layer->errinfo = errinfo;\n    }\n    g_set_wait_obj(self->wm->pro_layer->self_term_event);\n}\n\n/******************************************************************************/\nvoid\nxrdp_mm_logwnd_fatal(struct xrdp_mm *self, int errinfo)\n{\n    xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO, \"Close the log window to exit.\");\n    self->wm->pro_layer->errinfo = errinfo;\n    self->wm->fatal_error_in_log_window = 1;\n}\n\n/*****************************************************************************/\n/* open response from client going to channel server */\nstatic int\nxrdp_mm_drdynvc_open_response(struct xrdp_process *id, int chan_id,\n                              int creation_status)\n{\n    struct trans *trans;\n    struct stream *s;\n    struct xrdp_wm *wm;\n    int chansrv_chan_id;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_drdynvc_open_response: \"\n              \" chan_id %d creation_status %d\",\n              chan_id, creation_status);\n    wm = id->wm;\n    trans = wm->mm->chan_trans;\n    s = trans_get_out_s(trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 24); /* size */\n    out_uint32_le(s, 13); /* msg id */\n    out_uint32_le(s, 16); /* size */\n    chansrv_chan_id = wm->mm->xr2cr_cid_map[chan_id];\n    out_uint32_le(s, chansrv_chan_id);\n    out_uint32_le(s, creation_status); /* status */\n    s_mark_end(s);\n    return trans_write_copy(trans);\n}\n\n/*****************************************************************************/\n/* close response from client going to channel server */\nstatic int\nxrdp_mm_drdynvc_close_response(struct xrdp_process *id, int chan_id)\n{\n    struct trans *trans;\n    struct stream *s;\n    struct xrdp_wm *wm;\n    int chansrv_chan_id;\n\n    wm = id->wm;\n    trans = wm->mm->chan_trans;\n    s = trans_get_out_s(trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 20); /* size */\n    out_uint32_le(s, 15); /* msg id */\n    out_uint32_le(s, 12); /* size */\n    chansrv_chan_id = wm->mm->xr2cr_cid_map[chan_id];\n    out_uint32_le(s, chansrv_chan_id);\n    s_mark_end(s);\n    return trans_write_copy(trans);\n}\n\n/*****************************************************************************/\n/* part data from client going to channel server */\nstatic int\nxrdp_mm_drdynvc_data_first(struct xrdp_process *id, int chan_id, char *data,\n                           int bytes, int total_bytes)\n{\n    struct trans *trans;\n    struct stream *s;\n    struct xrdp_wm *wm;\n    int chansrv_chan_id;\n\n    wm = id->wm;\n    trans = wm->mm->chan_trans;\n    s = trans_get_out_s(trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 8 + 8 + 4 + 4 + 4 + bytes);\n    out_uint32_le(s, 17); /* msg id */\n    out_uint32_le(s, 8 + 4 + 4 + 4 + bytes);\n    chansrv_chan_id = wm->mm->xr2cr_cid_map[chan_id];\n    out_uint32_le(s, chansrv_chan_id);\n    out_uint32_le(s, bytes);\n    out_uint32_le(s, total_bytes);\n    out_uint8a(s, data, bytes);\n    s_mark_end(s);\n    return trans_write_copy(trans);\n}\n\n/*****************************************************************************/\n/* data from client going to channel server */\nstatic int\nxrdp_mm_drdynvc_data(struct xrdp_process *id, int chan_id,\n                     char *data, int bytes)\n{\n    struct trans *trans;\n    struct stream *s;\n    struct xrdp_wm *wm;\n    int chansrv_chan_id;\n\n    wm = id->wm;\n    trans = wm->mm->chan_trans;\n    s = trans_get_out_s(trans, 8192);\n    if (s == NULL)\n    {\n        return 1;\n    }\n    out_uint32_le(s, 0); /* version */\n    out_uint32_le(s, 8 + 8 + 4 + 4 + bytes);\n    out_uint32_le(s, 19); /* msg id */\n    out_uint32_le(s, 8 + 4 + 4 + bytes);\n    chansrv_chan_id = wm->mm->xr2cr_cid_map[chan_id];\n    out_uint32_le(s, chansrv_chan_id);\n    out_uint32_le(s, bytes);\n    out_uint8a(s, data, bytes);\n    s_mark_end(s);\n    return trans_write_copy(trans);\n}\n\n/*****************************************************************************/\n/* open message from channel server going to client */\nstatic int\nxrdp_mm_trans_process_drdynvc_channel_open(struct xrdp_mm *self,\n        struct stream *s)\n{\n    int name_bytes;\n    int flags;\n    int error;\n    int chan_id;\n    int chansrv_chan_id;\n    char name[1024 + 1];\n    struct xrdp_drdynvc_procs procs;\n\n    if (!s_check_rem(s, 2))\n    {\n        return 1;\n    }\n    in_uint32_le(s, name_bytes);\n    if ((name_bytes < 1) || (name_bytes > (int)(sizeof(name) - 1)))\n    {\n        return 1;\n    }\n    if (!s_check_rem(s, name_bytes))\n    {\n        return 1;\n    }\n    in_uint8a(s, name, name_bytes);\n    name[name_bytes] = 0;\n    if (!s_check_rem(s, 8))\n    {\n        return 1;\n    }\n    in_uint32_le(s, flags);\n    in_uint32_le(s, chansrv_chan_id);\n    if (chansrv_chan_id < 0 || chansrv_chan_id > 255)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Attempting to open invalid chansrv channel %d\",\n            chansrv_chan_id);\n        return 1;\n    }\n\n    if (flags == 0)\n    {\n        /* open static channel, not supported */\n        return 1;\n    }\n    else\n    {\n        /* dynamic channel */\n        g_memset(&procs, 0, sizeof(procs));\n        procs.open_response = xrdp_mm_drdynvc_open_response;\n        procs.close_response = xrdp_mm_drdynvc_close_response;\n        procs.data_first = xrdp_mm_drdynvc_data_first;\n        procs.data = xrdp_mm_drdynvc_data;\n        chan_id = 0;\n        error = libxrdp_drdynvc_open(self->wm->session, name, flags, &procs,\n                                     &chan_id);\n        if (error != 0)\n        {\n            return 1;\n        }\n        self->xr2cr_cid_map[chan_id] = chansrv_chan_id;\n        self->cs2xr_cid_map[chansrv_chan_id] = chan_id;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* close message from channel server going to client */\nstatic int\nxrdp_mm_trans_process_drdynvc_channel_close(struct xrdp_mm *self,\n        struct stream *s)\n{\n    int chansrv_chan_id;\n    int chan_id;\n    int error;\n\n    if (!s_check_rem(s, 4))\n    {\n        return 1;\n    }\n    in_uint32_le(s, chansrv_chan_id);\n    if (chansrv_chan_id < 0 || chansrv_chan_id > 255)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Attempting to close invalid chansrv channel %d\",\n            chansrv_chan_id);\n        return 1;\n    }\n    chan_id = self->cs2xr_cid_map[chansrv_chan_id];\n    /* close dynamic channel */\n    error = libxrdp_drdynvc_close(self->wm->session, chan_id);\n    if (error != 0)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* data from channel server going to client */\nstatic int\nxrdp_mm_trans_process_drdynvc_data_first(struct xrdp_mm *self,\n        struct stream *s)\n{\n    int chansrv_chan_id;\n    int chan_id;\n    int error;\n    int data_bytes;\n    int total_bytes;\n    char *data;\n\n    if (!s_check_rem(s, 12))\n    {\n        return 1;\n    }\n    in_uint32_le(s, chansrv_chan_id);\n    in_uint32_le(s, data_bytes);\n    in_uint32_le(s, total_bytes);\n    if ((!s_check_rem(s, data_bytes)))\n    {\n        return 1;\n    }\n    in_uint8p(s, data, data_bytes);\n    chan_id = self->cs2xr_cid_map[chansrv_chan_id];\n    error = libxrdp_drdynvc_data_first(self->wm->session, chan_id, data,\n                                       data_bytes, total_bytes);\n    if (error != 0)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* data from channel server going to client */\nstatic int\nxrdp_mm_trans_process_drdynvc_data(struct xrdp_mm *self,\n                                   struct stream *s)\n{\n    int chansrv_chan_id;\n    int chan_id;\n    int error;\n    int data_bytes;\n    char *data;\n\n    if (!s_check_rem(s, 8))\n    {\n        return 1;\n    }\n    in_uint32_le(s, chansrv_chan_id);\n    in_uint32_le(s, data_bytes);\n    if ((!s_check_rem(s, data_bytes)))\n    {\n        return 1;\n    }\n    in_uint8p(s, data, data_bytes);\n    chan_id = self->cs2xr_cid_map[chansrv_chan_id];\n    error = libxrdp_drdynvc_data(self->wm->session, chan_id, data, data_bytes);\n    if (error != 0)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* Acknowledgement from chansrv that Unicode input is supported\n */\nstatic int\nxrdp_mm_trans_process_unicode_ack(struct xrdp_mm *self,\n                                  struct stream *s)\n{\n    int status;\n    if (!s_check_rem(s, 4))\n    {\n        return 1;\n    }\n    in_uint32_le(s, status);\n    switch (status)\n    {\n        case 0:\n            LOG(LOG_LEVEL_INFO, \"Chansrv is handling Unicode input\");\n            self->wm->client_info->unicode_input_support = UIS_ACTIVE;\n            break;\n\n        case 1:\n            LOG(LOG_LEVEL_INFO, \"Chansrv does not support Unicode input\");\n            break;\n\n        case 2:\n            LOG(LOG_LEVEL_INFO,\n                \"Chansrv reported an error starting the Unicode input method\");\n            break;\n\n        default:\n            LOG(LOG_LEVEL_INFO,\n                \"Chansrv reported an unknown status %d\"\n                \" starting the Unicode input method\", status);\n            break;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error\n   process a message for the channel handler */\nstatic int\nxrdp_mm_chan_process_msg(struct xrdp_mm *self, struct trans *trans,\n                         struct stream *s)\n{\n    int rv;\n    int id;\n    int size;\n    char *next_msg;\n    char *s_end;\n\n    rv = 0;\n\n    while (s_check_rem(s, 8))\n    {\n        next_msg = s->p;\n        in_uint32_le(s, id);\n        in_uint32_le(s, size);\n        if (size < 8)\n        {\n            return 1;\n        }\n        if (!s_check_rem(s, size - 8))\n        {\n            return 1;\n        }\n        next_msg += size;\n        s_end = s->end;\n        s->end = next_msg;\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_chan_process_msg: got msg id %d\", id);\n        switch (id)\n        {\n            case 8: /* channel data */\n                rv = xrdp_mm_trans_process_channel_data(self, s);\n                break;\n            case 10: /* rail alternate secondary drawing orders */\n                rv = xrdp_mm_process_rail_drawing_orders(self, s);\n                break;\n            case 12:\n                rv = xrdp_mm_trans_process_drdynvc_channel_open(self, s);\n                break;\n            case 14:\n                rv = xrdp_mm_trans_process_drdynvc_channel_close(self, s);\n                break;\n            case 16:\n                rv = xrdp_mm_trans_process_drdynvc_data_first(self, s);\n                break;\n            case 18:\n                rv = xrdp_mm_trans_process_drdynvc_data(self, s);\n                break;\n            case 20:\n                rv = xrdp_mm_trans_process_unicode_ack(self, s);\n                break;\n            default:\n                LOG(LOG_LEVEL_ERROR, \"xrdp_mm_chan_process_msg: unknown id %d\", id);\n                break;\n        }\n        s->end = s_end;\n        if (rv != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_mm_chan_process_msg: error rv %d id %d\", rv, id);\n            rv = 0;\n        }\n\n        s->p = next_msg;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* this is callback from trans obj\n   returns error */\nstatic int\nxrdp_mm_chan_data_in(struct trans *trans)\n{\n    struct xrdp_mm *self;\n    struct stream *s;\n    int size;\n    int error;\n\n    if (trans == NULL)\n    {\n        return 1;\n    }\n\n    self = (struct xrdp_mm *)(trans->callback_data);\n    s = trans_get_in_s(trans);\n\n    if (s == 0)\n    {\n        return 1;\n    }\n\n    if (trans->extra_flags == 0)\n    {\n        in_uint8s(s, 4); /* id */\n        in_uint32_le(s, size);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_chan_data_in: got header, size %d\", size);\n        if (size > 8)\n        {\n            self->chan_trans->header_size = size;\n            trans->extra_flags = 1;\n            return 0;\n        }\n    }\n    /* here, the entire message block is read in, process it */\n    error = xrdp_mm_chan_process_msg(self, trans, s);\n    self->chan_trans->header_size = 8;\n    trans->extra_flags = 0;\n    init_stream(s, 0);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_chan_data_in: got whole message, reset for \"\n              \"next header\");\n    return error;\n}\n\n/*****************************************************************************/\n/* does the section in xrdp.ini has any channel.*=true | false */\nstatic int\nxrdp_mm_update_allowed_channels(struct xrdp_mm *self)\n{\n    int index;\n    int count;\n    int chan_id;\n    int disabled;\n    const char *name;\n    const char *value;\n    const char *chan_name;\n    struct xrdp_session *session;\n\n    session = self->wm->session;\n    count = self->login_names->count;\n    for (index = 0; index < count; index++)\n    {\n        name = (const char *) list_get_item(self->login_names, index);\n        if (g_strncasecmp(name, \"channel.\", 8) == 0)\n        {\n            value = (const char *) list_get_item(self->login_values, index);\n            chan_name = name + 8;\n            chan_id = libxrdp_get_channel_id(session, chan_name);\n            disabled = !g_text2bool(value);\n            libxrdp_disable_channel(session, chan_id, disabled);\n            if (disabled)\n            {\n                LOG(LOG_LEVEL_INFO, \"xrdp_mm_update_allowed_channels: channel %s \"\n                    \"channel id %d is disabled\", chan_name, chan_id);\n            }\n            else\n            {\n                LOG(LOG_LEVEL_INFO, \"xrdp_mm_update_allowed_channels: channel %s \"\n                    \"channel id %d is allowed\", chan_name, chan_id);\n            }\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_get_sesman_port(char *port, int port_bytes)\n{\n    int fd;\n    int error;\n    int index;\n    char *val;\n    char cfg_file[256];\n    struct list *names;\n    struct list *values;\n\n    g_memset(cfg_file, 0, sizeof(char) * 256);\n    /* default to port 3350 */\n    strlcpy(port, \"3350\", port_bytes);\n    /* see if port is in sesman.ini file */\n    g_snprintf(cfg_file, 255, \"%s/sesman.ini\", XRDP_CFG_PATH);\n    fd = g_file_open_ro(cfg_file);\n\n    if (fd >= 0)\n    {\n        names = list_create();\n        names->auto_free = 1;\n        values = list_create();\n        values->auto_free = 1;\n\n        if (file_read_section(fd, \"Globals\", names, values) == 0)\n        {\n            for (index = 0; index < names->count; index++)\n            {\n                val = (char *)list_get_item(names, index);\n\n                if (val != 0)\n                {\n                    if (g_strcasecmp(val, \"ListenPort\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        error = g_atoi(val);\n\n                        if ((error > 0) && (error < 65000))\n                        {\n                            strlcpy(port, val, port_bytes);\n                        }\n\n                        break;\n                    }\n                }\n            }\n        }\n\n        list_delete(names);\n        list_delete(values);\n        g_file_close(fd);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error\n   data coming from client that need to go to channel handler */\nint\nxrdp_mm_process_channel_data(struct xrdp_mm *self, tbus param1, tbus param2,\n                             tbus param3, tbus param4)\n{\n    struct stream *s;\n    int rv;\n    int length;\n    int total_length;\n    int flags;\n    int id;\n    char *data;\n\n    rv = 0;\n\n    if ((self->chan_trans != 0) && self->chan_trans->status == TRANS_STATUS_UP)\n    {\n        s = trans_get_out_s(self->chan_trans, 8192);\n\n        if (s != 0)\n        {\n            id = LOWORD(param1);\n            flags = HIWORD(param1);\n            length = param2;\n            data = (char *)param3;\n            total_length = param4;\n\n            if (total_length < length)\n            {\n                LOG(LOG_LEVEL_WARNING, \"WARNING in xrdp_mm_process_channel_data(): total_len < length\");\n                total_length = length;\n            }\n\n            out_uint32_le(s, 0); /* version */\n            out_uint32_le(s, 8 + 8 + 2 + 2 + 2 + 4 + length);\n            out_uint32_le(s, 5); /* msg id */\n            out_uint32_le(s, 8 + 2 + 2 + 2 + 4 + length);\n            out_uint16_le(s, id);\n            out_uint16_le(s, flags);\n            out_uint16_le(s, length);\n            out_uint32_le(s, total_length);\n            out_uint8a(s, data, length);\n            s_mark_end(s);\n            rv = trans_force_write(self->chan_trans);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_process_login_response(struct xrdp_mm *self)\n{\n    enum scp_login_status login_result;\n    int rv;\n    int server_closed;\n\n    self->mmcs_expecting_msg = 0;\n\n    rv = scp_get_login_response(self->sesman_trans, &login_result,\n                                &server_closed, &self->uid);\n    if (rv == 0)\n    {\n        if (login_result != E_SCP_LOGIN_OK)\n        {\n            char buff[128];\n            scp_login_status_to_str(login_result, buff, sizeof(buff));\n            xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO, \"%s\", buff);\n\n            if (login_result == E_SCP_LOGIN_NOT_AUTHENTICATED &&\n                    self->wm->pamerrortxt[0] != '\\0')\n            {\n                xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO, \"%s\",\n                                self->wm->pamerrortxt);\n            }\n\n            if (self->wm->client_info->require_credentials)\n            {\n                /* Credentials had to be specified, but were invalid */\n                LOG(LOG_LEVEL_ERROR, \"require_credentials is set, \"\n                    \"but the user could not be logged in\");\n                xrdp_mm_set_fatal(self, ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES);\n            }\n\n            if (server_closed)\n            {\n                if (login_result == E_SCP_LOGIN_NOT_AUTHENTICATED)\n                {\n                    xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO, \"%s\",\n                                    \"Login retry limit reached\");\n                }\n                xrdp_mm_logwnd_fatal(self,\n                                     ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES);\n                /* Transport can be deleted now */\n                self->delete_sesman_trans = 1;\n            }\n            /* If the server hasn't closed, inform the window manager\n             * of the fail, but leave the sesman connection open for\n             * further login attempts */\n            xrdp_wm_mod_connect_done(self->wm, 1);\n        }\n        else\n        {\n            /* login successful */\n            xrdp_mm_connect_sm(self);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_process_create_session_response(struct xrdp_mm *self)\n{\n    enum scp_screate_status status;\n    const char *display;\n    struct guid guid;\n\n    int rv;\n\n    self->mmcs_expecting_msg = 0;\n\n    rv = scp_get_create_session_response(self->sesman_trans, &status,\n                                         &display, &guid);\n    if (rv == 0)\n    {\n        const char *username;\n\n        /* Sort out some logging information */\n        if ((username = xrdp_mm_get_value(self, \"username\")) == NULL)\n        {\n            username = \"???\";\n        }\n\n        if (status == E_SCP_SCREATE_OK)\n        {\n            xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                            \"session is available on display %s for user %s\",\n                            display, username);\n\n            /* Carry on with the connect state machine */\n            strlcpy(self->display, display, sizeof(self->display));\n            self->guid = guid;\n            xrdp_mm_connect_sm(self);\n        }\n        else\n        {\n            char buff[128];\n            scp_screate_status_to_str(status, buff, sizeof(buff));\n            xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                            \"Can't create session for user %s - %s\",\n                            username, buff);\n            /* Leave the sesman connection open for further login attenpts */\n            xrdp_wm_mod_connect_done(self->wm, 1);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_process_connect_session_response(struct xrdp_mm *self)\n{\n    enum scp_sconnect_status status;\n\n    int rv;\n\n    self->mmcs_expecting_msg = 0;\n\n    rv = scp_get_connect_session_response(self->sesman_trans, &status,\n                                          &self->sesman_display_fd,\n                                          &self->sesman_chansrv_fd);\n    if (rv != 0)\n    {\n        self->delete_sesman_trans = 1;\n    }\n    else\n    {\n        if (status == E_SCP_SCONNECT_OK)\n        {\n            xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                            \"Got connection details for session\");\n\n            /* Convert the sesman transport fron an SCP transport\n             * to a CCP transport */\n            ccp_trans_from_scp_trans(self->sesman_trans,\n                                     xrdp_mm_ccp_data_in,\n                                     self);\n            self->sesman_trans_is_ccp = 1;\n\n            /* Carry on with the connect state machine */\n            xrdp_mm_connect_sm(self);\n        }\n        else\n        {\n            char buff[128];\n            const char *username;\n\n            /* Sort out some logging information */\n            scp_sconnect_status_to_str(status, buff, sizeof(buff));\n            if ((username = xrdp_mm_get_value(self, \"username\")) == NULL)\n            {\n                username = \"???\";\n            }\n\n            xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                            \"Can't create session for user %s - %s\",\n                            username, buff);\n            xrdp_mm_logwnd_fatal(self,\n                                 ERRINFO_SERVER_DWM_CRASH);\n            xrdp_wm_mod_connect_done(self->wm, 1);\n            // The sesman tranport is now useless to us.\n            self->delete_sesman_trans = 1;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* This is the callback registered for sesman communication replies over SCP */\nstatic int\nxrdp_mm_scp_data_in(struct trans *trans)\n{\n    int rv = 0;\n    int available;\n\n    rv = scp_msg_in_check_available(trans, &available);\n    if (rv == 0 && available)\n    {\n        struct xrdp_mm *self = (struct xrdp_mm *)(trans->callback_data);\n        enum scp_msg_code msgno;\n\n        switch ((msgno = scp_msg_in_get_msgno(trans)))\n        {\n            case E_SCP_LOGIN_RESPONSE:\n                rv = xrdp_mm_process_login_response(self);\n                break;\n\n            case E_SCP_CREATE_SESSION_RESPONSE:\n                rv = xrdp_mm_process_create_session_response(self);\n                break;\n\n            case E_SCP_CONNECT_SESSION_RESPONSE:\n                rv = xrdp_mm_process_connect_session_response(self);\n                break;\n\n            default:\n            {\n                char buff[64];\n                scp_msgno_to_str(msgno, buff, sizeof(buff));\n                LOG(LOG_LEVEL_ERROR, \"Ignored SCP message %s from sesman\",\n                    buff);\n            }\n        }\n\n        scp_msg_in_reset(trans);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* This routine clears all states to make sure that our next login will be\n * as expected. If the user does not press ok on the log window and try to\n * connect again we must make sure that no previous information is stored.\n *\n * This routine does not clear a sesman_trans if it is allocated, as this\n * would break the password retry limit mechanism */\nstatic void\ncleanup_states(struct xrdp_mm *self)\n{\n    if (self != NULL)\n    {\n        self->connect_state = MMCS_CONNECT_TO_SESMAN;\n        self->use_sesman = 0; /* true if this is a sesman session */\n        self->use_chansrv = 0; /* true if chansrvport is set in xrdp.ini or using sesman */\n        self->use_gw_login = 0; /* true if we're to use the gateway login facility */\n        //self->sesman_trans = NULL; /* connection to sesman */\n        self->chan_trans = NULL; /* connection to chansrv */\n        self->delete_sesman_trans = 0;\n        memset(self->display, '\\0', sizeof(self->display));\n        guid_clear(&self->guid);\n        self->code = 0; /* ???_SESSION_CODE value */\n        close_sesman_file_descriptors(self);\n    }\n}\n\n/*************************************************************************//**\n * Parses a chansrvport string\n *\n * This will be in one of the following formats:-\n * <path>         UNIX path to a domain socket\n * DISPLAY(<num>) Use chansrv on X Display <num>\n *\n * @param value assigned to chansrvport\n * @param dest Output buffer\n * @param dest_size Total size of output buffer, including terminator space\n * @param uid of destination\n *\n * Pass in dest of NULL, dest_size of 0 and uid of -1 to simply see if\n * the string parses OK.\n *\n * @return 0 for success\n */\n\nstatic int\nparse_chansrvport(const char *value, char dest[], int dest_size, int uid)\n{\n    int rv = 0;\n    char dstr[MAX_DISPLAY_NAME_SIZE];\n\n    if (value == NULL)\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"unexpectedly empty chansrvport string encountered\");\n        rv = -1;\n    }\n    else if (g_strncmp(value, \"DISPLAY(\", 8) == 0)\n    {\n        const char *p = value + 8;\n        const char *end = p;\n        int is_numeric = 1;\n        /* Look for a ',' or ')' or '\\0' */\n        while (*end != ',' && *end != ')' && *end != '\\0')\n        {\n            if (!isdigit(*end))\n            {\n                is_numeric = 0;\n            }\n            ++end;\n        }\n\n        if (end == p || (unsigned int)(end - p) > (sizeof(dstr) - 1))\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"Ignoring chansrvport string with bad display string '%s'\",\n                value);\n            return -1;\n        }\n\n        memcpy(dstr, p, end - p);\n        dstr[end - p] = '\\0';\n        if (is_numeric)\n        {\n            // X11 compatibility\n            int dnum = g_atoi(dstr);\n            if (g_get_display_string_from_x11_display(\n                        dnum, dstr, sizeof(dstr)) < 0)\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Ignoring chansrvport string \"\n                    \"with bad X11 display number '%s'\", value);\n                return -1;\n            }\n        }\n\n        if (*end == ',')\n        {\n            /* User has specified a UID override\n             * Check next chars are digits */\n            p = end + 1;\n            end = p;\n\n            while (isdigit(*end))\n            {\n                ++end;\n            }\n\n            if (end == p)\n            {\n                LOG(LOG_LEVEL_WARNING,\n                    \"Ignoring chansrvport string with bad uid '%s'\",\n                    value);\n                return -1;\n            }\n            uid = g_atoi(p);\n        }\n\n        if (*end != ')')\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"Ignoring badly-terminated chansrvport string '%s'\",\n                value);\n            return -1;\n        }\n\n        g_snprintf(dest, dest_size, XRDP_CHANSRV_STR, uid, dstr);\n    }\n    else\n    {\n        strlcpy(dest, value, dest_size);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic struct trans *\nxrdp_mm_scp_connect(struct xrdp_mm *self)\n{\n    char port[128];\n    char port_description[128];\n    struct trans *t;\n\n    xrdp_mm_get_sesman_port(port, sizeof(port));\n    scp_port_to_display_string(port,\n                               port_description, sizeof(port_description));\n\n    xrdp_wm_log_msg(self->wm, LOG_LEVEL_DEBUG,\n                    \"connecting to sesman on %s\", port_description);\n    t = scp_connect(port, \"xrdp\", g_is_term);\n    if (t != NULL)\n    {\n        /* fully connected */\n        t->trans_data_in = xrdp_mm_scp_data_in;\n        t->callback_data = self;\n\n        xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO, \"sesman connect ok\");\n    }\n    else\n    {\n        xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                        \"Error connecting to sesman on %s\", port_description);\n        trans_delete(t);\n        t = NULL;\n    }\n    return t;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_sesman_connect(struct xrdp_mm *self)\n{\n    trans_delete(self->sesman_trans);\n    self->sesman_trans = xrdp_mm_scp_connect(self);\n\n    return (self->sesman_trans == NULL); /* 0 for success */\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_chansrv_connect(struct xrdp_mm *self)\n{\n    char port[XRDP_SOCKETS_MAXPATH];\n\n    port[0] = '\\0';\n\n    // Before we create the transport, make sure we know\n    // what we're connecting to.\n    //\n    // If we're using sesman, sesman should already have sent us a file\n    // descriptor for chansrv. If we're not, we need to look at\n    // the 'chansrvport' parameter to get the path to the socket.\n    if (self->use_sesman)\n    {\n        if (self->sesman_chansrv_fd >= 0)\n        {\n            xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                            \"Connecting to chansrv via sesman\");\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING, \"xrdp_mm_chansrv_connect: \"\n                \"No chansrv connection was passed by sesman\");\n            return 0;\n        }\n    }\n    else\n    {\n        const char *cp = xrdp_mm_get_value(self, \"chansrvport\");\n        if (parse_chansrvport(cp, port, sizeof(port),\n                              self->uid) == 0)\n        {\n            xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                            \"Connecting to chansrv on %s\",\n                            port);\n        }\n        else\n        {\n            // An error has already been logged\n            return 0;\n        }\n    }\n\n    /* connect channel redir */\n    self->chan_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);\n\n    self->chan_trans->is_term = g_is_term;\n    self->chan_trans->si = &(self->wm->session->si);\n    self->chan_trans->my_source = XRDP_SOURCE_CHANSRV;\n    self->chan_trans->trans_data_in = xrdp_mm_chan_data_in;\n    self->chan_trans->header_size = 8;\n    self->chan_trans->callback_data = self;\n    self->chan_trans->no_stream_init_on_data_in = 1;\n    self->chan_trans->extra_flags = 0;\n\n    if (self->use_sesman)\n    {\n        // Pass ownership of the file descriptor to\n        // self->chan_trans\n        self->chan_trans->sck = self->sesman_chansrv_fd;\n        self->sesman_chansrv_fd = -1;\n        self->chan_trans->status = TRANS_STATUS_UP; /* ok */\n        self->chan_trans->type1 = TRANS_TYPE_CLIENT; /* client */\n    }\n    else\n    {\n        /* try to connect for up to 10 seconds */\n        if (trans_connect(self->chan_trans, NULL, port, 10 * 1000) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_mm_chansrv_connect: error in \"\n                \"trans_connect chan\");\n        }\n    }\n    if (self->chan_trans->status != TRANS_STATUS_UP)\n    {\n        /* Nothing more to do */\n    }\n    else if (xrdp_mm_trans_send_channel_setup(self, self->chan_trans) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_mm_chansrv_connect: error in \"\n            \"xrdp_mm_trans_send_channel_setup\");\n        trans_delete(self->chan_trans);\n        self->chan_trans = NULL;\n    }\n    else if (xrdp_mm_send_unicode_setup(self, self->chan_trans) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_mm_chansrv_connect: error in \"\n            \"xrdp_mm_send_unicode_setup\");\n        trans_delete(self->chan_trans);\n        self->chan_trans = NULL;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_mm_chansrv_connect: chansrv \"\n            \"connect successful\");\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_display_server_connect(struct xrdp_mm *self)\n{\n    int rv = 0;\n\n    if (xrdp_mm_setup_mod1(self) != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"Failure setting up module\");\n        xrdp_mm_module_cleanup(self);\n        rv = 1;\n    }\n    else if (xrdp_mm_setup_mod2(self) != 0)\n    {\n        /* connect error */\n        xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                        \"Error connecting to user session\");\n        xrdp_mm_module_cleanup(self);\n        rv = 1; /* failure */\n    }\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"return value from %s %d\", __func__, rv);\n\n    return rv;\n}\n\n/**************************************************************************//**\n * Initialise and start the connect sequence\n *\n * @param self This object\n */\nvoid\nxrdp_mm_connect(struct xrdp_mm *self)\n{\n    const char *p;\n    const char *port = xrdp_mm_get_value(self, \"port\");\n    const char *gw_username = xrdp_mm_get_value(self, \"pamusername\");\n\n    /* make sure we start in correct state */\n    cleanup_states(self);\n\n    /*\n     * Standard VNC sessions cannot be supported in FIPS mode, so\n     * don't default to this session type */\n    if ((p = xrdp_mm_get_value(self, \"code\")) != NULL)\n    {\n        self->code = g_atoi(p);\n    }\n    else if (g_fips_mode_enabled())\n    {\n        LOG(LOG_LEVEL_INFO, \"FIPS: defaulting to a VNC session over UDS\");\n        self->code = XVNC_UDS_SESSION_CODE;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO, \"non-FIPS: defaulting to a VNC session over TCP\");\n        self->code = XVNC_SESSION_CODE;\n    }\n\n    /* Look at our module parameters to decide if we need to connect\n     * to sesman or not */\n\n    if (port != NULL && g_strcmp(port, \"-1\") == 0)\n    {\n        self->use_sesman = 1;\n        /* Connecting to a remote sesman is no longer supported. For purely\n         * local session types, this setting could be removed.\n         * The 'ip' value is still used for non-UDS Xvnc sessions, to find\n         * the TCP address that the X server is listening on */\n        if (xrdp_mm_get_value(self, \"ip\") != NULL)\n        {\n            if (self->code != XVNC_SESSION_CODE)\n            {\n                xrdp_wm_log_msg(self->wm,\n                                LOG_LEVEL_WARNING,\n                                \"'ip' is not needed for this connection\"\n                                \" - please remove\");\n            }\n        }\n    }\n\n    if (gw_username != NULL)\n    {\n        /* Connecting to a remote sesman is no longer supported */\n        if (xrdp_mm_get_value(self, \"pamsessionmng\") != NULL)\n        {\n            xrdp_wm_log_msg(self->wm,\n                            LOG_LEVEL_WARNING,\n                            \"Parameter 'pamsessionmng' is obsolete.\"\n                            \" Please remove from config\");\n        }\n        self->use_gw_login = 1;\n    }\n\n    /* Will we need chansrv ? We use it unconditionally for a\n     * sesman session, but the user can also request it separately */\n    if (self->use_sesman)\n    {\n        self->use_chansrv = 1;\n    }\n    else\n    {\n        const char *csp = xrdp_mm_get_value(self, \"chansrvport\");\n        /* It's defined, but is it a valid string? */\n        if (csp != NULL && parse_chansrvport(csp, NULL, 0, -1) == 0)\n        {\n            self->use_chansrv = 1;\n        }\n    }\n\n    xrdp_mm_connect_sm(self);\n}\n\n/*****************************************************************************/\n/**\n * Start resize queue processing\n *\n * The xrdp login screen does not currently support client-side resizes. We\n * currently address this by not processing the resize queue until we are\n * able to do so.\n *\n * We implement this by not creating the resize_ready wait object until\n * we are able to process the queue. Calls made to an empty wait object\n * are simply ignored.\n *\n * @param self MM module\n */\nstatic void\nstart_processing_resize_queue(struct xrdp_mm *self)\n{\n    if (self->resize_ready == NULL_WAIT_OBJ)\n    {\n        char buf[32];\n        int outstanding =\n            (self->resize_queue != NULL) ? self->resize_queue->count : 0;\n        int pid = g_getpid();\n        g_snprintf(buf, sizeof(buf), \"xrdp_%8.8x_resize_ready\", pid);\n        self->resize_ready = g_create_wait_obj(buf);\n        LOG(LOG_LEVEL_INFO,\n            \"xrdp can now process resize requests (%d outstanding)\",\n            outstanding);\n        if (outstanding > 0)\n        {\n            g_set_wait_obj(self->resize_ready);\n        }\n    }\n}\n\n/*****************************************************************************/\nstatic void\nxrdp_mm_connect_sm(struct xrdp_mm *self)\n{\n    int status = 0;\n\n    /* we set self->mmcs_expecting_msg in the loop when we've send a\n       message to sesman, and we need to wait for a response */\n    self->mmcs_expecting_msg = 0;\n\n    while (status == 0 && !self->mmcs_expecting_msg &&\n            self->connect_state != MMCS_DONE)\n    {\n        switch (self->connect_state)\n        {\n            case MMCS_CONNECT_TO_SESMAN:\n            {\n                if (self->sesman_trans == NULL &&\n                        (self->use_sesman || self->use_gw_login))\n                {\n                    /* Synchronous call */\n                    status = xrdp_mm_sesman_connect(self);\n                }\n            }\n            break;\n\n            case MMCS_GATEWAY_LOGIN:\n            {\n                if (self->use_gw_login)\n                {\n                    const char *gw_username;\n                    const char *gw_password;\n\n                    gw_username = xrdp_mm_get_value(self, \"pamusername\");\n                    gw_password = xrdp_mm_get_value(self, \"pampassword\");\n                    // gw_username shouldn't be NULL here, but we'll\n                    // check it anyway before dereferencing.\n                    if (gw_username != NULL &&\n                            !g_strcmp(gw_username, \"same\"))\n                    {\n                        gw_username = xrdp_mm_get_value(self, \"username\");\n                    }\n\n                    // Default the password to the usual one if the\n                    // user hasn't specified one, or specified 'same'\n                    if (gw_password == NULL ||\n                            !g_strcmp(gw_password, \"same\"))\n                    {\n                        gw_password = xrdp_mm_get_value(self, \"password\");\n                    }\n\n                    if (gw_username == NULL || gw_password == NULL)\n                    {\n                        xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                                        \"Can't determine username and/or \"\n                                        \"password for gateway login\");\n                        status = 1;\n                    }\n                    else\n                    {\n                        xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                                        \"Performing access control for %s\",\n                                        gw_username);\n\n                        status = xrdp_mm_send_sys_login_request(self,\n                                                                gw_username,\n                                                                gw_password);\n                        if (status == 0)\n                        {\n                            /* Now waiting for a reply from sesman - see\n                               xrdp_mm_process_login_response() */\n                            self->mmcs_expecting_msg = 1;\n                        }\n                    }\n                }\n            }\n            break;\n\n            case MMCS_SESSION_LOGIN:\n            {\n                // Finished with the gateway login\n                // Leave the UID set in case we need it for the chansrvport\n                // string\n                if (self->use_gw_login)\n                {\n                    xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                                    \"access control check was successful\");\n                    if (self->use_sesman)\n                    {\n                        // Logout and leave the connection open\n                        status = scp_send_logout_request(self->sesman_trans);\n                    }\n                    else\n                    {\n                        // Close the connection as we don't need it now\n                        status = scp_send_close_connection_request(\n                                     self->sesman_trans);\n                        self->delete_sesman_trans = 1;\n                    }\n                }\n\n                if (status == 0 && self->use_sesman)\n                {\n                    const char *username;\n                    const char *password;\n\n                    username = xrdp_mm_get_value(self, \"username\");\n                    password = xrdp_mm_get_value(self, \"password\");\n                    if (username == NULL || username[0] == '\\0')\n                    {\n                        xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                                        \"No username is available\");\n                        status = 1;\n                    }\n                    else if (password == NULL)\n                    {\n                        /* Can't find a password definition at all - even\n                         * an empty one */\n                        xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                                        \"No password field is available\");\n                        status = 1;\n                    }\n                    else\n                    {\n                        xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                                        \"Performing login request for %s\",\n                                        username);\n                        status = xrdp_mm_send_sys_login_request(self,\n                                                                username,\n                                                                password);\n                        if (status == 0)\n                        {\n                            /* Now waiting for a reply from sesman - see\n                               xrdp_mm_process_create_session_response() */\n                            self->mmcs_expecting_msg = 1;\n                        }\n                    }\n                }\n            }\n            break;\n\n            case MMCS_CREATE_SESSION:\n                if (self->use_sesman)\n                {\n                    xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                                    \"login was successful - creating session\");\n                    if ((status = xrdp_mm_create_session(self)) == 0)\n                    {\n                        /* Now waiting for a reply from sesman */\n                        self->mmcs_expecting_msg = 1;\n                    }\n                }\n                break;\n\n            case MMCS_GET_SESSION_FILE_DESCRIPTORS:\n                if (self->use_sesman)\n                {\n                    xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                                    \"Getting session connections from sesman\");\n                    if ((status = xrdp_mm_get_session_fds(self)) == 0)\n                    {\n                        /* Now waiting for a reply from sesman. Note that\n                         * when it arrives, sesman is expecting us to\n                         * close the connection - we can do nothing else\n                         * with it */\n                        self->mmcs_expecting_msg = 1;\n                    }\n                }\n                break;\n\n            case MMCS_CONNECT_TO_DISPLAY_SERVER:\n            {\n                xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,\n                                \"Connecting to display server\");\n                /* This is synchronous - no reply message expected */\n                status = xrdp_mm_display_server_connect(self);\n                if (status == 0)\n                {\n                    // This is as good a place as any to start processing\n                    // the resize_queue\n                    start_processing_resize_queue(self);\n                }\n            }\n            break;\n\n            case MMCS_CONNECT_TO_CHANSRV:\n            {\n                if (self->use_chansrv)\n                {\n                    if (self->wm->client_info->channels_allowed == 0)\n                    {\n                        LOG(LOG_LEVEL_DEBUG, \"skip connecting to chansrv\"\n                            \" because all channels are disabled\");\n                    }\n                    else\n                    {\n                        xrdp_mm_update_allowed_channels(self);\n                        xrdp_mm_chansrv_connect(self);\n                    }\n                }\n            }\n            break;\n\n            case MMCS_DONE:\n            {\n                /* Shouldn't get here */\n                LOG(LOG_LEVEL_ERROR, \"xrdp_mm_connect_sm: state machine error\");\n                status = 1;\n            }\n            break;\n        }\n\n        /* Move to the next state */\n        if (self->connect_state < MMCS_DONE)\n        {\n            self->connect_state = (enum mm_connect_state)\n                                  (self->connect_state + 1);\n        }\n    }\n\n    if (!self->mmcs_expecting_msg)\n    {\n        /* Close any uncomsumed file descriptors from sesman */\n        close_sesman_file_descriptors(self);\n\n        xrdp_wm_mod_connect_done(self->wm, status);\n\n        /* Make sure the module is cleaned up if we weren't successful */\n        if (status != 0)\n        {\n            self->delete_sesman_trans = 1;\n            xrdp_mm_module_cleanup(self);\n        }\n    }\n}\n\n#define MIN_MS_BETWEEN_FRAMES 40\n#define MIN_MS_TO_WAIT_FOR_MORE_UPDATES 0\n/*****************************************************************************/\nint\nxrdp_mm_get_wait_objs(struct xrdp_mm *self,\n                      tbus *read_objs, int *rcount,\n                      tbus *write_objs, int *wcount, int *timeout)\n{\n    int rv = 0;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    rv = 0;\n\n    if (self->sesman_trans != 0 &&\n            self->sesman_trans->status == TRANS_STATUS_UP)\n    {\n        trans_get_wait_objs(self->sesman_trans, read_objs, rcount);\n    }\n\n    if ((self->chan_trans != 0) && self->chan_trans->status == TRANS_STATUS_UP)\n    {\n        trans_get_wait_objs_rw(self->chan_trans, read_objs, rcount,\n                               write_objs, wcount, timeout);\n    }\n\n    if (self->mod != 0)\n    {\n        if (self->mod->mod_get_wait_objs != 0)\n        {\n            rv = self->mod->mod_get_wait_objs(self->mod, read_objs, rcount,\n                                              write_objs, wcount, timeout);\n        }\n    }\n\n    if (self->encoder != 0)\n    {\n        read_objs[(*rcount)++] = self->encoder->xrdp_encoder_event_processed;\n    }\n\n    if (self->resize_queue != 0 && self->resize_ready != NULL_WAIT_OBJ)\n    {\n        read_objs[(*rcount)++] = self->resize_ready;\n    }\n\n    if (self->wm->screen_dirty_region != NULL)\n    {\n        if (xrdp_region_not_empty(self->wm->screen_dirty_region))\n        {\n            unsigned int now = g_get_elapsed_ms();\n            unsigned int next_screen_draw_time =\n                self->wm->last_screen_draw_time +\n                MIN_MS_BETWEEN_FRAMES;\n            int diff = next_screen_draw_time - now;\n            int ltimeout = *timeout;\n            diff = MAX(diff, MIN_MS_TO_WAIT_FOR_MORE_UPDATES);\n            diff = MIN(diff, MIN_MS_BETWEEN_FRAMES);\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_get_wait_objs:\"\n                      \" not empty diff %d\", diff);\n            if ((ltimeout < 0) || (ltimeout > diff))\n            {\n                *timeout = diff;\n            }\n        }\n    }\n    return rv;\n}\n\n#define DUMP_JPEG 0\n\n#if DUMP_JPEG\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_dump_jpeg(struct xrdp_mm *self, XRDP_ENC_DATA_DONE *enc_done)\n{\n    static tbus ii;\n    static int jj;\n    struct _header\n    {\n        char tag[4];\n        int width;\n        int height;\n        int bytes_follow;\n    } header;\n    tui16 *pheader_bytes;\n    int cx;\n    int cy;\n\n    pheader_bytes = (tui16 *) (enc_done->comp_pad_data + enc_done->pad_bytes);\n\n    cx = enc_done->enc->crects[enc_done->index * 4 + 2];\n    cy = enc_done->enc->crects[enc_done->index * 4 + 3];\n\n    header.tag[0] = 'B';\n    header.tag[1] = 'E';\n    header.tag[2] = 'E';\n    header.tag[3] = 'F';\n    header.width = cx;\n    header.height = cy;\n    header.bytes_follow = enc_done->comp_bytes - (2 + pheader_bytes[0]);\n    if (ii == 0)\n    {\n        ii = g_file_open_rw(\"/tmp/jpeg.beef.bin\");\n        if (ii == -1)\n        {\n            ii = 0;\n        }\n    }\n    if (ii != 0)\n    {\n        g_file_write(ii, (char *)&header, sizeof(header));\n        g_file_write(ii, enc_done->comp_pad_data +\n                     enc_done->pad_bytes + 2 + pheader_bytes[0],\n                     enc_done->comp_bytes - (2 + pheader_bytes[0]));\n        jj++;\n        LOG(LOG_LEVEL_INFO, \"dumping jpeg index %d\", jj);\n    }\n    return 0;\n}\n\n#endif\n\n/*****************************************************************************/\nint\nxrdp_mm_check_chan(struct xrdp_mm *self)\n{\n    LOG(LOG_LEVEL_TRACE, \"xrdp_mm_check_chan:\");\n    if ((self->chan_trans != 0) && self->chan_trans->status == TRANS_STATUS_UP)\n    {\n        if (trans_check_wait_objs(self->chan_trans) != 0)\n        {\n            /* This is safe to do here, as we're not in a chansrv\n             * transport callback */\n            trans_delete(self->chan_trans);\n            self->chan_trans = 0;\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_process_enc_done(struct xrdp_mm *self)\n{\n    XRDP_ENC_DATA *enc;\n    XRDP_ENC_DATA_DONE *enc_done;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int is_gfx;\n    int got_frame_id;\n    int client_ack;\n\n    LOG(LOG_LEVEL_TRACE, \"xrdp_mm_process_enc_done:\");\n\n    while (1)\n    {\n        tc_mutex_lock(self->encoder->mutex);\n        enc_done = (XRDP_ENC_DATA_DONE *)\n                   fifo_remove_item(self->encoder->fifo_processed);\n        tc_mutex_unlock(self->encoder->mutex);\n        if (enc_done == NULL)\n        {\n            break;\n        }\n        is_gfx = ENC_IS_BIT_SET(enc_done->flags, ENC_DONE_FLAGS_GFX_BIT);\n        if (is_gfx)\n        {\n            got_frame_id = ENC_IS_BIT_SET(enc_done->flags,\n                                          ENC_DONE_FLAGS_FRAME_ID_BIT);\n            client_ack = self->encoder->gfx_ack_off == 0;\n        }\n        else\n        {\n            got_frame_id = 1;\n            client_ack = self->wm->client_info->use_frame_acks;\n        }\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_process_enc_done: message back \"\n                  \"bytes %d\", enc_done->comp_bytes);\n        if (enc_done->comp_bytes > 0)\n        {\n            if (is_gfx)\n            {\n                xrdp_egfx_send_data(self->egfx,\n                                    enc_done->comp_pad_data +\n                                    enc_done->pad_bytes,\n                                    enc_done->comp_bytes);\n            }\n            else\n            {\n                x = enc_done->x;\n                y = enc_done->y;\n                cx = enc_done->cx;\n                cy = enc_done->cy;\n                if (client_ack && !enc_done->continuation)\n                {\n                    libxrdp_fastpath_send_frame_marker(self->wm->session, 0,\n                                                       enc_done->frame_id);\n                }\n                libxrdp_fastpath_send_surface(self->wm->session,\n                                              enc_done->comp_pad_data,\n                                              enc_done->pad_bytes,\n                                              enc_done->comp_bytes,\n                                              x, y, x + cx, y + cy,\n                                              32, self->encoder->codec_id,\n                                              cx, cy);\n                if (client_ack && enc_done->last)\n                {\n                    libxrdp_fastpath_send_frame_marker(self->wm->session, 1,\n                                                       enc_done->frame_id);\n                }\n            }\n        }\n        /* free enc_done */\n        if (enc_done->last)\n        {\n            enc = enc_done->enc;\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_process_enc_done: last set\");\n            if (got_frame_id)\n            {\n                if (client_ack)\n                {\n                    self->encoder->frame_id_server = enc_done->frame_id;\n                    xrdp_mm_update_module_frame_ack(self);\n                }\n                else if (self->mod != NULL)\n                {\n                    self->mod->mod_frame_ack(self->mod, 0,\n                                             enc_done->frame_id);\n                }\n            }\n            if (is_gfx)\n            {\n                g_free(enc->u.gfx.cmd);\n            }\n            else\n            {\n                g_free(enc->u.sc.drects);\n                g_free(enc->u.sc.crects);\n            }\n            if (enc->shmem_ptr != NULL)\n            {\n                g_munmap(enc->shmem_ptr, enc->shmem_bytes);\n            }\n            g_free(enc);\n        }\n        g_free(enc_done->comp_pad_data);\n        g_free(enc_done);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_mm_efgx_add_dirty_region_to_planar_list(struct xrdp_mm *self,\n        struct xrdp_region *dirty_region)\n{\n    int jndex = 0;\n    struct xrdp_rect rect;\n\n    int error = xrdp_region_get_rect(dirty_region, jndex, &rect);\n    if (error == 0)\n    {\n        if (self->wm->screen_dirty_region == NULL)\n        {\n            self->wm->screen_dirty_region = xrdp_region_create(self->wm);\n        }\n\n        do\n        {\n            xrdp_region_add_rect(self->wm->screen_dirty_region, &rect);\n            jndex++;\n            error = xrdp_region_get_rect(dirty_region, jndex, &rect);\n        }\n        while (error == 0);\n\n        if (self->mod_handle != 0)\n        {\n            // Module has been writing to WM screen using GFX\n            self->mod_uses_wm_screen_for_gfx = 1;\n        }\n    }\n\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_draw_dirty(struct xrdp_mm *self)\n{\n    struct xrdp_rect rect;\n    struct xrdp_rect mon_rect;\n    struct xrdp_region *mon_reg;\n    int error;\n    int index;\n    int jndex;\n    int count;\n    int surface_id;\n    struct monitor_info *mi;\n    int rv = 0;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_draw_dirty:\");\n    count = self->wm->client_info->display_sizes.monitorCount;\n    if (count < 1)\n    {\n        error = xrdp_region_get_bounds(self->wm->screen_dirty_region, &rect);\n        if (error == 0)\n        {\n            rv = xrdp_mm_egfx_send_planar_bitmap(self,\n                                                 self->wm->screen, &rect,\n                                                 self->egfx->surface_id, 0, 0);\n        }\n    }\n    else\n    {\n        for (index = 0; index < count; index++)\n        {\n            /* make a copy of screen_dirty_region */\n            mon_reg = xrdp_region_create(self->wm);\n            if (mon_reg == NULL)\n            {\n                return 1;\n            }\n            jndex = 0;\n            while (xrdp_region_get_rect(self->wm->screen_dirty_region,\n                                        jndex, &mon_rect) == 0)\n            {\n                LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_mm_draw_dirty: jndex %d \"\n                          \"mon_rect %d %d %d %d\",\n                          jndex, mon_rect.left, mon_rect.top,\n                          mon_rect.right, mon_rect.bottom);\n                xrdp_region_add_rect(mon_reg, &mon_rect);\n                jndex++;\n            }\n            /* intercect monitor */\n            mi = self->wm->client_info->display_sizes.minfo_wm + index;\n            mon_rect.left = mi->left;\n            mon_rect.top = mi->top;\n            mon_rect.right = mi->right + 1;\n            mon_rect.bottom = mi->bottom + 1;\n            xrdp_region_intersect_rect(mon_reg, &mon_rect);\n            if (xrdp_region_not_empty(mon_reg))\n            {\n                error = xrdp_region_get_bounds(mon_reg, &rect);\n                if (error == 0)\n                {\n                    surface_id = index;\n                    rv = xrdp_mm_egfx_send_planar_bitmap(self,\n                                                         self->wm->screen,\n                                                         &rect,\n                                                         surface_id,\n                                                         mi->left, mi->top);\n                }\n            }\n            xrdp_region_delete(mon_reg);\n        }\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nint\nxrdp_mm_check_wait_objs(struct xrdp_mm *self)\n{\n    int rv = 0;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (self->sesman_trans != NULL &&\n            !self->delete_sesman_trans &&\n            self->sesman_trans->status == TRANS_STATUS_UP)\n    {\n        if (trans_check_wait_objs(self->sesman_trans) != 0)\n        {\n            if (self->sesman_trans_is_ccp)\n            {\n                /* Comms with the sesexec has failed - we have to assume\n                 * the session has failed */\n                xrdp_mm_set_fatal(self, ERRINFO_LOGOFF_BY_USER);\n            }\n            else\n            {\n                /* We're still using the SCP transport for\n                 * pre-connection activities */\n                if (self->mmcs_expecting_msg)\n                {\n                    /* The sesman transport has failed with an\n                     * outstanding message while connecting */\n                    xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR, \"Unexpected\"\n                                    \" sesman failure - check sesman log\");\n                    xrdp_wm_mod_connect_done(self->wm, 1);\n                }\n                if (self->wm->hide_log_window)\n                {\n                    /* if hide_log_window, this is fatal */\n                    rv = 1;\n                }\n            }\n            self->delete_sesman_trans = 1;\n        }\n    }\n    if (self->delete_sesman_trans)\n    {\n        trans_delete(self->sesman_trans);\n        self->sesman_trans = NULL;\n    }\n\n    if (self->chan_trans != NULL &&\n            self->chan_trans->status == TRANS_STATUS_UP)\n    {\n        if (trans_check_wait_objs(self->chan_trans) != 0)\n        {\n            /* This is safe to do here, as we're not in a chansrv\n             * transport callback */\n            trans_delete(self->chan_trans);\n            self->chan_trans = NULL;\n        }\n    }\n\n    if (self->mod != NULL)\n    {\n        if (self->mod->mod_check_wait_objs != NULL &&\n                self->mod->mod_check_wait_objs(self->mod) != 0)\n        {\n            /* Comms with the module has failed - we have to assume\n             * the display server, and hence the session has failed */\n            xrdp_mm_set_fatal(self, ERRINFO_LOGOFF_BY_USER);\n        }\n    }\n\n    if (g_is_wait_obj_set(self->resize_ready))\n    {\n        g_reset_wait_obj(self->resize_ready);\n        dynamic_monitor_process_queue(self);\n    }\n\n    if (self->encoder != NULL)\n    {\n        if (g_is_wait_obj_set(self->encoder->xrdp_encoder_event_processed))\n        {\n            g_reset_wait_obj(self->encoder->xrdp_encoder_event_processed);\n            xrdp_mm_process_enc_done(self);\n        }\n    }\n\n    if (self->wm->screen_dirty_region != NULL)\n    {\n        if (xrdp_region_not_empty(self->wm->screen_dirty_region))\n        {\n            unsigned int now = g_get_elapsed_ms();\n            int diff = now - self->wm->last_screen_draw_time;\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_mm_check_wait_objs: not empty diff %d\", diff);\n            if ((diff < 0) || (diff >= 40))\n            {\n                if (self->egfx_up)\n                {\n                    rv |= xrdp_mm_draw_dirty(self);\n                    xrdp_region_delete(self->wm->screen_dirty_region);\n                    self->wm->screen_dirty_region = NULL;\n                    self->wm->last_screen_draw_time = now;\n                }\n                else\n                {\n                    LOG(LOG_LEVEL_TRACE, \"xrdp_mm_check_wait_objs: egfx is not up\");\n                }\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* frame ack from client */\nint\nxrdp_mm_frame_ack(struct xrdp_mm *self, int frame_id)\n{\n    struct xrdp_encoder *encoder;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_frame_ack:\");\n    if (self->wm->client_info->use_frame_acks == 0)\n    {\n        return 1;\n    }\n    if ((encoder = self->encoder) == NULL)\n    {\n        /* No encoder - Possibly a late frame ack with a resize in progress */\n        LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_mm_frame_ack: \"\n                  \"Frame ack incoming %d with no encoder!\", frame_id);\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_mm_frame_ack: \"\n                  \"incoming %d, client %d, server %d\", frame_id,\n                  encoder->frame_id_client, encoder->frame_id_server);\n        if ((frame_id < 0) || (frame_id > encoder->frame_id_server))\n        {\n            /* if frame_id is negative or bigger then what server last sent\n               just ack all sent frames */\n            /* some clients can send big number just to clear all\n               pending frames */\n            encoder->frame_id_client = encoder->frame_id_server;\n        }\n        else\n        {\n            /* frame acks can come out of order so ignore older one */\n            encoder->frame_id_client = MAX(frame_id, encoder->frame_id_client);\n        }\n    }\n    xrdp_mm_update_module_frame_ack(self);\n    return 0;\n}\n\n#if 0\n/*****************************************************************************/\nstruct xrdp_painter *\nget_painter(struct xrdp_mod *mod)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        wm = (struct xrdp_wm *)(mod->wm);\n        p = xrdp_painter_create(wm, wm->session);\n        mod->painter = (tintptr)p;\n    }\n\n    return p;\n}\n#endif\n\n/*****************************************************************************/\nstatic int\nserver_begin_update(struct xrdp_mod *mod)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_painter *p;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    p = xrdp_painter_create(wm, wm->session);\n    xrdp_painter_begin_update(p);\n    mod->painter = (long)p;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_end_update(struct xrdp_mod *mod)\n{\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    xrdp_painter_end_update(p);\n    xrdp_painter_delete(p);\n    mod->painter = 0;\n    return 0;\n}\n\n/*****************************************************************************/\n/* got bell signal... try to send to client */\nstatic int\nserver_bell_trigger(struct xrdp_mod *mod)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    xrdp_wm_send_bell(wm);\n    return 0;\n}\n\n/*****************************************************************************/\n/* Chansrv in use on this configuration? */\nstatic int\nserver_chansrv_in_use(struct xrdp_mod *mod)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return wm->mm->use_chansrv;\n}\n\n/*****************************************************************************/\n/* Init the XKB layout */\nstatic void\nserver_init_xkb_layout(struct xrdp_mod *mod,\n                       struct xrdp_client_info *client_info)\n{\n    xrdp_init_xkb_layout(client_info);\n}\n\n\n/*****************************************************************************/\nstatic int\nserver_fill_rect(struct xrdp_mod *mod, int x, int y, int cx, int cy)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    xrdp_painter_fill_rect(p, wm->target_surface, x, y, cx, cy);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_screen_blt(struct xrdp_mod *mod, int x, int y, int cx, int cy,\n                  int srcx, int srcy)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    p->rop = 0xcc;\n    xrdp_painter_copy(p, wm->screen, wm->target_surface, x, y, cx, cy, srcx, srcy);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_paint_rect(struct xrdp_mod *mod, int x, int y, int cx, int cy,\n                  char *data, int width, int height, int srcx, int srcy)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_bitmap *b;\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    b = xrdp_bitmap_create_with_data(width, height, wm->screen->bpp, data, wm);\n    xrdp_painter_copy(p, b, wm->target_surface, x, y, cx, cy, srcx, srcy);\n    xrdp_bitmap_delete(b);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_paint_rect_bpp(struct xrdp_mod *mod, int x, int y, int cx, int cy,\n                      char *data, int width, int height, int srcx, int srcy,\n                      int bpp)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_bitmap *b;\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n    if (p == 0)\n    {\n        return 0;\n    }\n    wm = (struct xrdp_wm *)(mod->wm);\n    b = xrdp_bitmap_create_with_data(width, height, bpp, data, wm);\n    xrdp_painter_copy(p, b, wm->target_surface, x, y, cx, cy, srcx, srcy);\n    xrdp_bitmap_delete(b);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_composite(struct xrdp_mod *mod, int srcidx, int srcformat,\n                 int srcwidth, int srcrepeat, int *srctransform,\n                 int mskflags, int mskidx, int mskformat, int mskwidth,\n                 int mskrepeat, int op, int srcx, int srcy,\n                 int mskx, int msky, int dstx, int dsty,\n                 int width, int height, int dstformat)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_bitmap *b;\n    struct xrdp_bitmap *msk;\n    struct xrdp_painter *p;\n    struct xrdp_os_bitmap_item *bi;\n\n    p = (struct xrdp_painter *)(mod->painter);\n    if (p == 0)\n    {\n        return 0;\n    }\n    wm = (struct xrdp_wm *)(mod->wm);\n    b = 0;\n    msk = 0;\n    bi = xrdp_cache_get_os_bitmap(wm->cache, srcidx);\n    if (bi != 0)\n    {\n        b = bi->bitmap;\n    }\n    if (mskflags & 1)\n    {\n        bi = xrdp_cache_get_os_bitmap(wm->cache, mskidx);\n        if (bi != 0)\n        {\n            msk = bi->bitmap;\n        }\n    }\n    if (b != 0)\n    {\n        xrdp_painter_composite(p, b, srcformat, srcwidth, srcrepeat,\n                               wm->target_surface, srctransform,\n                               mskflags, msk, mskformat, mskwidth, mskrepeat,\n                               op, srcx, srcy, mskx, msky, dstx, dsty,\n                               width, height, dstformat);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"server_composite: error finding id %d or %d\", srcidx, mskidx);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_paint_rects_ex(struct xrdp_mod *mod,\n                      int num_drects, short *drects,\n                      int num_crects, short *crects,\n                      char *data, int left, int top,\n                      int width, int height,\n                      int flags, int frame_id,\n                      void *shmem_ptr, int shmem_bytes)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_mm *mm;\n    struct xrdp_painter *p;\n    struct xrdp_bitmap *b;\n    short *s;\n    int index;\n    XRDP_ENC_DATA *enc_data;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    mm = wm->mm;\n\n    LOG(LOG_LEVEL_TRACE, \"server_paint_rects_ex: %p\", mm->encoder);\n\n    if (mm->encoder != 0)\n    {\n        /* copy formal params to XRDP_ENC_DATA */\n        enc_data = (XRDP_ENC_DATA *) g_malloc(sizeof(XRDP_ENC_DATA), 1);\n        if (enc_data == 0)\n        {\n            if (shmem_ptr != NULL)\n            {\n                g_munmap(shmem_ptr, shmem_bytes);\n            }\n            return 1;\n        }\n\n        enc_data->u.sc.drects = (short *)\n                                g_malloc(sizeof(short) * num_drects * 4, 0);\n        if (enc_data->u.sc.drects == 0)\n        {\n            if (shmem_ptr != NULL)\n            {\n                g_munmap(shmem_ptr, shmem_bytes);\n            }\n            g_free(enc_data);\n            return 1;\n        }\n\n        enc_data->u.sc.crects = (short *)\n                                g_malloc(sizeof(short) * num_crects * 4, 0);\n        if (enc_data->u.sc.crects == 0)\n        {\n            if (shmem_ptr != NULL)\n            {\n                g_munmap(shmem_ptr, shmem_bytes);\n            }\n            g_free(enc_data->u.sc.drects);\n            g_free(enc_data);\n            return 1;\n        }\n\n        g_memcpy(enc_data->u.sc.drects, drects, sizeof(short) * num_drects * 4);\n        g_memcpy(enc_data->u.sc.crects, crects, sizeof(short) * num_crects * 4);\n\n        enc_data->mod = mod;\n        enc_data->u.sc.num_drects = num_drects;\n        enc_data->u.sc.num_crects = num_crects;\n        enc_data->u.sc.data = data;\n        enc_data->u.sc.left = left;\n        enc_data->u.sc.top = top;\n        enc_data->u.sc.width = width;\n        enc_data->u.sc.height = height;\n        enc_data->u.sc.flags = flags;\n        enc_data->u.sc.frame_id = frame_id;\n        enc_data->shmem_ptr = shmem_ptr;\n        enc_data->shmem_bytes = shmem_bytes;\n        if (width == 0 || height == 0)\n        {\n            LOG_DEVEL(LOG_LEVEL_WARNING, \"server_paint_rects: error\");\n        }\n\n        /* insert into fifo for encoder thread to process */\n        tc_mutex_lock(mm->encoder->mutex);\n        fifo_add_item(mm->encoder->fifo_to_proc, (void *) enc_data);\n        tc_mutex_unlock(mm->encoder->mutex);\n\n        /* signal xrdp_encoder thread */\n        g_set_wait_obj(mm->encoder->xrdp_encoder_event_to_proc);\n\n        return 0;\n    }\n\n    if (wm->client_info->gfx)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"server_paint_rects: gfx session and no encoder\");\n        if (mod->mod_frame_ack != 0)\n        {\n            mod->mod_frame_ack(mod, flags, frame_id);\n        }\n        return 0;\n    }\n\n    p = (struct xrdp_painter *)(mod->painter);\n    if (p == 0)\n    {\n        return 0;\n    }\n    b = xrdp_bitmap_create_with_data(width, height, wm->screen->bpp,\n                                     data, wm);\n    s = crects;\n    for (index = 0; index < num_crects; index++)\n    {\n        xrdp_painter_copy(p, b, wm->target_surface, s[0], s[1], s[2], s[3],\n                          s[0], s[1]);\n        s += 4;\n    }\n    xrdp_bitmap_delete(b);\n    if (mod->mod_frame_ack != 0)\n    {\n        mod->mod_frame_ack(mod, flags, frame_id);\n    }\n    if (shmem_ptr != NULL)\n    {\n        g_munmap(shmem_ptr, shmem_bytes);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_paint_rects(struct xrdp_mod *mod, int num_drects, short *drects,\n                   int num_crects, short *crects, char *data, int width,\n                   int height, int flags, int frame_id)\n{\n    return server_paint_rects_ex(mod, num_drects, drects, num_crects, crects,\n                                 data, 0, 0, width, height, flags, frame_id,\n                                 NULL, 0);\n}\n\n/*****************************************************************************/\nstatic int\nserver_session_info(struct xrdp_mod *mod, const char *data, int data_bytes)\n{\n    struct xrdp_wm *wm;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"server_session_info:\");\n    wm = (struct xrdp_wm *)(mod->wm);\n    return libxrdp_send_session_info(wm->session, data, data_bytes);\n}\n\n/*****************************************************************************/\nstatic int\nserver_egfx_cmd(struct xrdp_mod *mod,\n                char *cmd, int cmd_bytes,\n                char *data, int data_bytes)\n{\n    XRDP_ENC_DATA *enc;\n    struct xrdp_wm *wm;\n    struct xrdp_mm *mm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    mm = wm->mm;\n    if (mm->encoder == NULL)\n    {\n        // This can happen when we are in the resize state machine, if\n        // there are messages queued up by the X server\n        if (data != NULL)\n        {\n            g_munmap(data, data_bytes);\n        }\n        return 0;\n    }\n    enc = g_new0(struct xrdp_enc_data, 1);\n    if (enc == NULL)\n    {\n        if (data != NULL)\n        {\n            g_munmap(data, data_bytes);\n        }\n        return 1;\n    }\n    ENC_SET_BIT(enc->flags, ENC_FLAGS_GFX_BIT);\n    enc->u.gfx.cmd = g_new(char, cmd_bytes);\n    if (enc->u.gfx.cmd == NULL)\n    {\n        if (data != NULL)\n        {\n            g_munmap(data, data_bytes);\n        }\n        g_free(enc);\n        return 1;\n    }\n    g_memcpy(enc->u.gfx.cmd, cmd, cmd_bytes);\n    enc->u.gfx.cmd_bytes = cmd_bytes;\n    enc->u.gfx.data = data;\n    enc->u.gfx.data_bytes = data_bytes;\n    enc->shmem_ptr = data;\n    enc->shmem_bytes = data_bytes;\n    /* insert into fifo for encoder thread to process */\n    tc_mutex_lock(mm->encoder->mutex);\n    fifo_add_item(mm->encoder->fifo_to_proc, enc);\n    tc_mutex_unlock(mm->encoder->mutex);\n    /* signal xrdp_encoder thread */\n    g_set_wait_obj(mm->encoder->xrdp_encoder_event_to_proc);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_pointer_system(struct xrdp_mod *mod, int pointer_type)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    xrdp_wm_send_pointer_system(wm, pointer_type);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_pointer_position(struct xrdp_mod *mod, int x, int y)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    xrdp_wm_send_pointer_position(wm, x, y);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_pointer(struct xrdp_mod *mod, int x, int y,\n                   char *data, char *mask)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    xrdp_wm_pointer(wm, data, mask, x, y, 0, 32, 32);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_pointer_ex(struct xrdp_mod *mod, int x, int y,\n                      char *data, char *mask, int bpp)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    xrdp_wm_pointer(wm, data, mask, x, y, bpp, 32, 32);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_pointer_large(struct xrdp_mod *mod, int x, int y,\n                         char *data, char *mask, int bpp,\n                         int width, int height)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    xrdp_wm_pointer(wm, data, mask, x, y, bpp, width, height);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_palette(struct xrdp_mod *mod, int *palette)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n\n    if (g_memcmp(wm->palette, palette, 255 * sizeof(int)) != 0)\n    {\n        g_memcpy(wm->palette, palette, 256 * sizeof(int));\n        xrdp_wm_send_palette(wm);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_msg(struct xrdp_mod *mod, const char *msg, int code)\n{\n    struct xrdp_wm *wm;\n\n    if (code == 1)\n    {\n        LOG(LOG_LEVEL_INFO, \"%s\", msg);\n        return 0;\n    }\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return xrdp_wm_log_msg(wm, LOG_LEVEL_DEBUG, \"%s\", msg);\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_clip(struct xrdp_mod *mod, int x, int y, int cx, int cy)\n{\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    return xrdp_painter_set_clip(p, x, y, cx, cy);\n}\n\n/*****************************************************************************/\nstatic int\nserver_reset_clip(struct xrdp_mod *mod)\n{\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    return xrdp_painter_clr_clip(p);\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_fgcolor(struct xrdp_mod *mod, int fgcolor)\n{\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    p->fg_color = fgcolor;\n    p->pen.color = p->fg_color;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_bgcolor(struct xrdp_mod *mod, int bgcolor)\n{\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    p->bg_color = bgcolor;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_opcode(struct xrdp_mod *mod, int opcode)\n{\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    p->rop = opcode;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_mixmode(struct xrdp_mod *mod, int mixmode)\n{\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    p->mix_mode = mixmode;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_brush(struct xrdp_mod *mod, int x_origin, int y_origin,\n                 int style, char *pattern)\n{\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    p->brush.x_origin = x_origin;\n    p->brush.y_origin = y_origin;\n    p->brush.style = style;\n    g_memcpy(p->brush.pattern, pattern, 8);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_pen(struct xrdp_mod *mod, int style, int width)\n{\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    p->pen.style = style;\n    p->pen.width = width;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_draw_line(struct xrdp_mod *mod, int x1, int y1, int x2, int y2)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return xrdp_painter_line(p, wm->target_surface, x1, y1, x2, y2);\n}\n\n/*****************************************************************************/\nstatic int\nserver_add_char(struct xrdp_mod *mod, int font, int character,\n                int offset, int baseline,\n                int width, int height, char *data)\n{\n    struct xrdp_font_char fi;\n\n    fi.offset = offset;\n    fi.baseline = baseline;\n    fi.width = width;\n    fi.height = height;\n    fi.incby = 0;\n    fi.data = data;\n    fi.bpp = 1;\n    return libxrdp_orders_send_font(((struct xrdp_wm *)mod->wm)->session,\n                                    &fi, font, character);\n}\n\n/*****************************************************************************/\nstatic int\nserver_draw_text(struct xrdp_mod *mod, int font,\n                 int flags, int mixmode, int clip_left, int clip_top,\n                 int clip_right, int clip_bottom,\n                 int box_left, int box_top,\n                 int box_right, int box_bottom,\n                 int x, int y, char *data, int data_len)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_painter *p;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return xrdp_painter_draw_text2(p, wm->target_surface, font, flags,\n                                   mixmode, clip_left, clip_top,\n                                   clip_right, clip_bottom,\n                                   box_left, box_top,\n                                   box_right, box_bottom,\n                                   x, y, data, data_len);\n}\n\n/*****************************************************************************/\nstatic int\nclient_monitor_resize(struct xrdp_mod *mod, int width, int height,\n                      int num_monitors, const struct monitor_info *monitors)\n{\n    int error = 0;\n    struct xrdp_wm *wm;\n    struct display_size_description description;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"client_monitor_resize:\");\n    wm = (struct xrdp_wm *)(mod->wm);\n    if (wm == 0 || wm->mm == 0 || wm->client_info == 0)\n    {\n        return 1;\n    }\n\n    if (wm->client_info->client_resize_mode == CRMODE_NONE)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Server is not allowed to resize this client\");\n        return 1;\n    }\n\n    if (wm->client_info->client_resize_mode == CRMODE_SINGLE_SCREEN &&\n            num_monitors > 1)\n    {\n        LOG(LOG_LEVEL_WARNING,\n            \"Server cannot resize this client with multiple monitors\");\n        return 1;\n    }\n\n    error = libxrdp_init_display_size_description(num_monitors,\n            monitors,\n            &description);\n    if (error)\n    {\n        LOG(LOG_LEVEL_ERROR, \"client_monitor_resize:\"\n            \" libxrdp_init_display_size_description\"\n            \" failed with error %d.\", error);\n        return error;\n    }\n    error = add_resize_request_to_queue(wm->mm, RQ_FROM_SERVER, &description);\n    if (error)\n    {\n        LOG(LOG_LEVEL_ERROR, \"client_monitor_resize:\"\n            \" out of memory adding queue item\");\n        return error;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n\n/* Note : if this is called on a multimon setup, the client is resized\n * to a single monitor */\nstatic int\nserver_monitor_resize_done(struct xrdp_mod *mod)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_mm *mm;\n\n    LOG(LOG_LEVEL_TRACE, \"server_monitor_resize_done:\");\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    if (wm == 0)\n    {\n        return 1;\n    }\n    mm = wm->mm;\n    if (mm == 0)\n    {\n        return 1;\n    }\n\n    if (wm->client_info == 0)\n    {\n        return 1;\n    }\n\n    if (mm->resize_data != NULL\n            && mm->resize_data->state\n            == WMRZ_SERVER_MONITOR_MESSAGE_PROCESSING)\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"server_monitor_resize_done: Advancing server monitor resized.\");\n        advance_resize_state_machine(\n            mm, WMRZ_SERVER_MONITOR_MESSAGE_PROCESSED);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/*return -1 if channels are controlled by chansrv */\nstatic int\nserver_get_channel_count(struct xrdp_mod *mod)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n\n    if (wm->mm->use_chansrv)\n    {\n        return -1;\n    }\n\n    return libxrdp_get_channel_count(wm->session);\n}\n\n\n/*****************************************************************************/\n/*return 0 if the index is not found*/\nstatic int\nserver_query_channel(struct xrdp_mod *mod, int index, char *channel_name,\n                     int *channel_flags)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n\n    if (wm->mm->use_chansrv)\n    {\n        return 1;\n    }\n\n    return libxrdp_query_channel(wm->session, index, channel_name,\n                                 channel_flags);\n}\n\n/*****************************************************************************/\n/* returns -1 on error */\nstatic int\nserver_get_channel_id(struct xrdp_mod *mod, const char *name)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n\n    if (wm->mm->use_chansrv)\n    {\n        return -1;\n    }\n\n    return libxrdp_get_channel_id(wm->session, name);\n}\n\n/*****************************************************************************/\nstatic int\nserver_send_to_channel(struct xrdp_mod *mod, int channel_id,\n                       char *data, int data_len,\n                       int total_data_len, int flags)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n\n    if (wm->mm->use_chansrv)\n    {\n        /* Modules should not be calling this if chansrv is running -\n         * they can use server_chansrv_in_use() to avoid doing this */\n        LOG_DEVEL(LOG_LEVEL_ERROR,\n                  \"Bad call of server_send_to_channel() detected\");\n        return 1;\n    }\n\n    return libxrdp_send_to_channel(wm->session, channel_id, data, data_len,\n                                   total_data_len, flags);\n}\n\n/*****************************************************************************/\nstatic int\nserver_create_os_surface(struct xrdp_mod *mod, int rdpindex,\n                         int width, int height)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_bitmap *bitmap;\n    int error;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    bitmap = xrdp_bitmap_create(width, height, wm->screen->bpp,\n                                WND_TYPE_OFFSCREEN, wm);\n    error = xrdp_cache_add_os_bitmap(wm->cache, bitmap, rdpindex);\n\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"server_create_os_surface: xrdp_cache_add_os_bitmap failed\");\n        return 1;\n    }\n\n    bitmap->item_index = rdpindex;\n    bitmap->id = rdpindex;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_create_os_surface_bpp(struct xrdp_mod *mod, int rdpindex,\n                             int width, int height, int bpp)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_bitmap *bitmap;\n    int error;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    bitmap = xrdp_bitmap_create(width, height, bpp,\n                                WND_TYPE_OFFSCREEN, wm);\n    error = xrdp_cache_add_os_bitmap(wm->cache, bitmap, rdpindex);\n    if (error != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"server_create_os_surface_bpp: xrdp_cache_add_os_bitmap failed\");\n        return 1;\n    }\n    bitmap->item_index = rdpindex;\n    bitmap->id = rdpindex;\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_switch_os_surface(struct xrdp_mod *mod, int rdpindex)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_os_bitmap_item *bi;\n    struct xrdp_painter *p;\n\n    LOG(LOG_LEVEL_DEBUG, \"server_switch_os_surface: id 0x%x\", rdpindex);\n    wm = (struct xrdp_wm *)(mod->wm);\n\n    if (rdpindex == -1)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"server_switch_os_surface: setting target_surface to screen\");\n        wm->target_surface = wm->screen;\n        p = (struct xrdp_painter *)(mod->painter);\n\n        if (p != 0)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"setting target\");\n            wm_painter_set_target(p);\n        }\n\n        return 0;\n    }\n\n    bi = xrdp_cache_get_os_bitmap(wm->cache, rdpindex);\n\n    if ((bi != 0) && (bi->bitmap != 0))\n    {\n        LOG(LOG_LEVEL_DEBUG, \"server_switch_os_surface: setting target_surface to rdpid %d\", rdpindex);\n        wm->target_surface = bi->bitmap;\n        p = (struct xrdp_painter *)(mod->painter);\n\n        if (p != 0)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"setting target\");\n            wm_painter_set_target(p);\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"server_switch_os_surface: error finding id %d\", rdpindex);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_delete_os_surface(struct xrdp_mod *mod, int rdpindex)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_painter *p;\n\n    LOG(LOG_LEVEL_DEBUG, \"server_delete_os_surface: id 0x%x\", rdpindex);\n    wm = (struct xrdp_wm *)(mod->wm);\n\n    if (wm->target_surface->type == WND_TYPE_OFFSCREEN)\n    {\n        if (wm->target_surface->id == rdpindex)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"server_delete_os_surface: setting target_surface to screen\");\n            wm->target_surface = wm->screen;\n            p = (struct xrdp_painter *)(mod->painter);\n\n            if (p != 0)\n            {\n                LOG(LOG_LEVEL_DEBUG, \"setting target\");\n                wm_painter_set_target(p);\n            }\n        }\n    }\n\n    xrdp_cache_remove_os_bitmap(wm->cache, rdpindex);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_paint_rect_os(struct xrdp_mod *mod, int x, int y, int cx, int cy,\n                     int rdpindex, int srcx, int srcy)\n{\n    struct xrdp_wm *wm;\n    struct xrdp_bitmap *b;\n    struct xrdp_painter *p;\n    struct xrdp_os_bitmap_item *bi;\n\n    p = (struct xrdp_painter *)(mod->painter);\n\n    if (p == 0)\n    {\n        return 0;\n    }\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    bi = xrdp_cache_get_os_bitmap(wm->cache, rdpindex);\n\n    if (bi != 0)\n    {\n        b = bi->bitmap;\n        xrdp_painter_copy(p, b, wm->target_surface, x, y, cx, cy, srcx, srcy);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"server_paint_rect_os: error finding id %d\", rdpindex);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_set_hints(struct xrdp_mod *mod, int hints, int mask)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n\n    if (mask & 1)\n    {\n        if (hints & 1)\n        {\n            wm->hints |= 1;\n        }\n        else\n        {\n            wm->hints &= ~1;\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nserver_window_new_update(struct xrdp_mod *mod, int window_id,\n                         struct rail_window_state_order *window_state,\n                         int flags)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return libxrdp_window_new_update(wm->session, window_id,\n                                     window_state, flags);\n}\n\n/*****************************************************************************/\nstatic int\nserver_window_delete(struct xrdp_mod *mod, int window_id)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return libxrdp_window_delete(wm->session, window_id);\n}\n\n/*****************************************************************************/\nstatic int\nserver_window_icon(struct xrdp_mod *mod, int window_id, int cache_entry,\n                   int cache_id, struct rail_icon_info *icon_info,\n                   int flags)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return libxrdp_window_icon(wm->session, window_id, cache_entry, cache_id,\n                               icon_info, flags);\n}\n\n/*****************************************************************************/\nstatic int\nserver_window_cached_icon(struct xrdp_mod *mod,\n                          int window_id, int cache_entry,\n                          int cache_id, int flags)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return libxrdp_window_cached_icon(wm->session, window_id, cache_entry,\n                                      cache_id, flags);\n}\n\n/*****************************************************************************/\nstatic int\nserver_notify_new_update(struct xrdp_mod *mod,\n                         int window_id, int notify_id,\n                         struct rail_notify_state_order *notify_state,\n                         int flags)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return libxrdp_notify_new_update(wm->session, window_id, notify_id,\n                                     notify_state, flags);\n}\n\n/*****************************************************************************/\nstatic int\nserver_notify_delete(struct xrdp_mod *mod, int window_id,\n                     int notify_id)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return libxrdp_notify_delete(wm->session, window_id, notify_id);\n}\n\n/*****************************************************************************/\nstatic int\nserver_monitored_desktop(struct xrdp_mod *mod,\n                         struct rail_monitored_desktop_order *mdo,\n                         int flags)\n{\n    struct xrdp_wm *wm;\n\n    wm = (struct xrdp_wm *)(mod->wm);\n    return libxrdp_monitored_desktop(wm->session, mdo, flags);\n}\n\n/*****************************************************************************/\nstatic int\nserver_add_char_alpha(struct xrdp_mod *mod, int font, int character,\n                      int offset, int baseline,\n                      int width, int height, char *data)\n{\n    struct xrdp_font_char fi;\n\n    fi.offset = offset;\n    fi.baseline = baseline;\n    fi.width = width;\n    fi.height = height;\n    fi.incby = 0;\n    fi.data = data;\n    fi.bpp = 8;\n    return libxrdp_orders_send_font(((struct xrdp_wm *)mod->wm)->session,\n                                    &fi, font, character);\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_setup_mod1(struct xrdp_mm *self)\n{\n    void *func;\n    const char *lib;\n    char text[256];\n\n    if (self == 0)\n    {\n        return 1;\n    }\n\n    if ((lib = xrdp_mm_get_value(self, \"lib\")) == NULL)\n    {\n        xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                        \"no library name specified in xrdp.ini, please add \"\n                        \"lib=libxrdp-vnc.so or similar\");\n\n        return 1;\n    }\n\n    if (lib[0] == 0)\n    {\n        xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                        \"empty library name specified in xrdp.ini, please \"\n                        \"add lib=libxrdp-vnc.so or similar\");\n\n        return 1;\n    }\n\n    if (self->mod_handle == 0)\n    {\n        g_snprintf(text, sizeof(text), \"%s/%s\", XRDP_MODULE_PATH, lib);\n        /* Let the main thread load the lib,*/\n        self->mod_handle = g_xrdp_sync(xrdp_mm_sync_load, (tintptr)text, 0);\n\n        if (self->mod_handle != 0)\n        {\n            func = g_get_proc_address(self->mod_handle, \"mod_init\");\n\n            if (func == 0)\n            {\n                func = g_get_proc_address(self->mod_handle, \"_mod_init\");\n            }\n\n            if (func == 0)\n            {\n                xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                                \"error finding proc mod_init in %s, \"\n                                \"not a valid xrdp backend\", lib);\n            }\n\n            self->mod_init = (struct xrdp_mod * ( *)(void))func;\n            func = g_get_proc_address(self->mod_handle, \"mod_exit\");\n\n            if (func == 0)\n            {\n                func = g_get_proc_address(self->mod_handle, \"_mod_exit\");\n            }\n\n            if (func == 0)\n            {\n                xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                                \"error finding proc mod_exit in %s, \"\n                                \"not a valid xrdp backend\", lib);\n            }\n\n            self->mod_exit = (int ( *)(struct xrdp_mod *))func;\n\n            if ((self->mod_init != 0) && (self->mod_exit != 0))\n            {\n                self->mod = self->mod_init();\n\n                if (self->mod != 0)\n                {\n                    LOG(LOG_LEVEL_INFO, \"loaded module '%s' ok, interface size %d, version %d\", lib,\n                        self->mod->size, self->mod->version);\n                }\n            }\n            else\n            {\n                LOG(LOG_LEVEL_ERROR, \"no mod_init or mod_exit address found\");\n            }\n        }\n        else\n        {\n            xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,\n                            \"error loading %s specified in xrdp.ini, please \"\n                            \"add a valid entry like lib=libxrdp-vnc.so or \"\n                            \"similar\", lib);\n            return 1;\n        }\n\n        if (self->mod != 0)\n        {\n            self->mod->wm = (long)(self->wm);\n            self->mod->server_begin_update = server_begin_update;\n            self->mod->server_end_update = server_end_update;\n            self->mod->server_bell_trigger = server_bell_trigger;\n            self->mod->server_chansrv_in_use = server_chansrv_in_use;\n            self->mod->server_init_xkb_layout = server_init_xkb_layout;\n            self->mod->server_fill_rect = server_fill_rect;\n            self->mod->server_screen_blt = server_screen_blt;\n            self->mod->server_paint_rect = server_paint_rect;\n            self->mod->server_set_pointer = server_set_pointer;\n            self->mod->server_set_pointer_ex = server_set_pointer_ex;\n            self->mod->server_palette = server_palette;\n            self->mod->server_msg = server_msg;\n            self->mod->server_is_term = g_is_term;\n            self->mod->server_set_clip = server_set_clip;\n            self->mod->server_reset_clip = server_reset_clip;\n            self->mod->server_set_fgcolor = server_set_fgcolor;\n            self->mod->server_set_bgcolor = server_set_bgcolor;\n            self->mod->server_set_opcode = server_set_opcode;\n            self->mod->server_set_mixmode = server_set_mixmode;\n            self->mod->server_set_brush = server_set_brush;\n            self->mod->server_set_pen = server_set_pen;\n            self->mod->server_draw_line = server_draw_line;\n            self->mod->server_add_char = server_add_char;\n            self->mod->server_draw_text = server_draw_text;\n            self->mod->client_monitor_resize = client_monitor_resize;\n            self->mod->server_monitor_resize_done = server_monitor_resize_done;\n            self->mod->server_get_channel_count = server_get_channel_count;\n            self->mod->server_query_channel = server_query_channel;\n            self->mod->server_get_channel_id = server_get_channel_id;\n            self->mod->server_send_to_channel = server_send_to_channel;\n            self->mod->server_create_os_surface = server_create_os_surface;\n            self->mod->server_switch_os_surface = server_switch_os_surface;\n            self->mod->server_delete_os_surface = server_delete_os_surface;\n            self->mod->server_paint_rect_os = server_paint_rect_os;\n            self->mod->server_set_hints = server_set_hints;\n            self->mod->server_window_new_update = server_window_new_update;\n            self->mod->server_window_delete = server_window_delete;\n            self->mod->server_window_icon = server_window_icon;\n            self->mod->server_window_cached_icon = server_window_cached_icon;\n            self->mod->server_notify_new_update = server_notify_new_update;\n            self->mod->server_notify_delete = server_notify_delete;\n            self->mod->server_monitored_desktop = server_monitored_desktop;\n            self->mod->server_add_char_alpha = server_add_char_alpha;\n            self->mod->server_create_os_surface_bpp = server_create_os_surface_bpp;\n            self->mod->server_paint_rect_bpp = server_paint_rect_bpp;\n            self->mod->server_composite = server_composite;\n            self->mod->server_paint_rects = server_paint_rects;\n            self->mod->server_session_info = server_session_info;\n            self->mod->server_egfx_cmd = server_egfx_cmd;\n            self->mod->server_set_pointer_large = server_set_pointer_large;\n            self->mod->server_paint_rects_ex = server_paint_rects_ex;\n            self->mod->server_set_pointer_system = server_set_pointer_system;\n            self->mod->server_set_pointer_position = server_set_pointer_position;\n            self->mod->si = &(self->wm->session->si);\n        }\n    }\n\n    /* id self->mod is null, there must be a problem */\n    if (self->mod == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"problem loading lib in xrdp_mm_setup_mod1\");\n        return 1;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_mm_setup_mod2(struct xrdp_mm *self)\n{\n    char text[256];\n    const char *name;\n    const char *value;\n    int i;\n    int rv;\n    int key_flags;\n    int device_flags;\n    struct xrdp_mod *mod = self->mod;\n\n    if (mod == 0)\n    {\n        return 1;\n    }\n\n    rv = 1; /* failure */\n    g_memset(text, 0, sizeof(text));\n\n    if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))\n    {\n        if (mod->mod_start(mod, self->wm->screen->width,\n                           self->wm->screen->height,\n                           self->wm->screen->bpp) != 0)\n        {\n            xrdp_mm_set_fatal(self, ERRINFO_SERVER_DWM_CRASH);\n        }\n    }\n\n    if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))\n    {\n        if (self->code == XVNC_SESSION_CODE)\n        {\n            if (self->use_sesman)\n            {\n                // We have to make assumptions about the display format for\n                // classic VNC\n                int dnum = g_get_x11_display_from_display_string(self->display);\n                if (dnum < 0)\n                {\n                    LOG(LOG_LEVEL_ERROR,\n                        \"Unexpected display value %s setting up VNC module\",\n                        self->display);\n                    xrdp_mm_set_fatal(self, ERRINFO_SERVER_DWM_CRASH);\n                }\n                else\n                {\n                    g_snprintf(text, sizeof(text), \"%d\", 5900 + dnum);\n                }\n            }\n        }\n        else if (self->code == XORG_SESSION_CODE ||\n                 self->code == XVNC_UDS_SESSION_CODE)\n        {\n            g_snprintf(text, sizeof(text), XRDP_X11RDP_STR,\n                       self->uid, self->display);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_ERROR,\n                \"Unexpected session code %d setting up module\", self->code);\n            xrdp_mm_set_fatal(self, ERRINFO_SERVER_DWM_CRASH);\n        }\n    }\n\n    if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))\n    {\n        /* this adds the port to the end of the list, it will already be in\n           the list as -1\n           the module should use the last one */\n        if (g_strlen(text) > 0)\n        {\n            list_add_strdup(self->login_names, \"port\");\n            list_add_strdup(self->login_values, text);\n        }\n\n        /* always set these */\n\n        mod->mod_set_param(mod, \"client_info\",\n                           (const char *) (self->wm->session->client_info));\n\n        name = self->wm->session->client_info->client_name;\n        mod->mod_set_param(mod, \"client_name\", name);\n        g_snprintf(text, 255, \"%d\", self->wm->session->client_info->keylayout);\n        mod->mod_set_param(mod, \"keylayout\", text);\n        if (guid_is_set(&self->guid))\n        {\n            mod->mod_set_param(mod, \"guid\", (char *) &self->guid);\n        }\n\n        for (i = 0; i < self->login_names->count; i++)\n        {\n            name = (const char *) list_get_item(self->login_names, i);\n            value = (const char *) list_get_item(self->login_values, i);\n            mod->mod_set_param(mod, name, value);\n        }\n\n        /* connect\n        *\n         * If we got an fd for the display server from sesman, this\n         * call will use it */\n        if (mod->mod_connect(mod, self->sesman_display_fd) == 0)\n        {\n            rv = 0; /* connect success */\n\n            // Ownership of the file descriptor has been\n            // passed to the module\n            self->sesman_display_fd = -1;\n\n            // If we've received a recent TS_SYNC_EVENT, pass it on to\n            // the module so (e.g.) NumLock starts in the right state.\n            if (self->last_sync_saved)\n            {\n                int key_flags = self->last_sync_key_flags;\n                int device_flags = self->last_sync_device_flags;\n                self->last_sync_saved = 0;\n                if (mod->mod_event != 0)\n                {\n                    mod->mod_event(mod, WM_KEYBRD_SYNC, key_flags,\n                                   device_flags, key_flags, device_flags);\n                }\n            }\n        }\n        else\n        {\n            xrdp_wm_show_log(self->wm);\n            if (self->wm->hide_log_window)\n            {\n                rv = 1;\n            }\n        }\n    }\n\n    if (rv == 0)\n    {\n        /* sync modifiers */\n        key_flags = 0;\n        device_flags = 0;\n\n        if (self->wm->scroll_lock)\n        {\n            key_flags |= 1;\n        }\n\n        if (self->wm->num_lock)\n        {\n            key_flags |= 2;\n        }\n\n        if (self->wm->caps_lock)\n        {\n            key_flags |= 4;\n        }\n\n        if (mod->mod_event != 0)\n        {\n            mod->mod_event(mod, WM_KEYBRD_SYNC, key_flags,\n                           device_flags, key_flags, device_flags);\n        }\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "xrdp/xrdp_mm.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2023\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * module manager\n */\n\n#ifndef _XRDP_MM_H\n#define _XRDP_MM_H\n\n#include \"arch.h\"\n#include \"trans.h\"\n#include \"list16.h\"\n#include \"libxrdpinc.h\"\n#include \"xrdp_types.h\"\n\nint\nadvance_resize_state_machine(struct xrdp_mm *mm,\n                             enum display_resize_state new_state);\n\n#endif\n"
  },
  {
    "path": "xrdp/xrdp_mm_ccp.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * module manager\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n#include \"ccp.h\"\n#include \"xrdp.h\"\n#include \"log.h\"\n\n/*****************************************************************************/\n/**\n * We've been asked by sesman/sesexec to close the connection\n */\nstatic int\nxrdp_mm_process_close_ccp_connection_request(struct xrdp_mm *self)\n{\n    enum ccp_close_reason_type reason;\n\n    int rv = ccp_get_close_connection_request(self->sesman_trans, &reason);\n    if (rv == 0)\n    {\n        int errinfo;\n        char buff[64];\n\n        switch (reason)\n        {\n            case CCP_CLOSE_RPC_INITIATED_DISCONNECT:\n                errinfo = ERRINFO_RPC_INITIATED_DISCONNECT;\n                break;\n\n            case CCP_CLOSE_DISCONNECTED_BY_OTHERCONNECTION:\n                errinfo = ERRINFO_DISCONNECTED_BY_OTHERCONNECTION;\n                break;\n\n            case CCP_CLOSE_LOGOFF_BY_USER:\n                errinfo = ERRINFO_LOGOFF_BY_USER;\n                break;\n\n            case CCP_CLOSE_SOFTWARE_FAILURE:\n                errinfo = ERRINFO_SERVER_CSRSS_CRASH;\n                break;\n\n            default:\n                LOG(LOG_LEVEL_WARNING, \"Unexpected close connection reason %d\",\n                    (int)reason);\n                errinfo = ERRINFO_LOGOFF_BY_USER;\n        }\n\n        LOG(LOG_LEVEL_INFO, \"Request to close connection : '%s'\",\n            ccp_close_reason_to_str(reason, buff, sizeof(buff)));\n        xrdp_mm_set_fatal(self, errinfo);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nxrdp_mm_ccp_data_in(struct trans *trans)\n{\n    int rv = 0;\n    int available;\n\n    rv = ccp_msg_in_check_available(trans, &available);\n    if (rv == 0 && available)\n    {\n        struct xrdp_mm *self = (struct xrdp_mm *)(trans->callback_data);\n        enum ccp_msg_code msgno;\n\n        switch ((msgno = ccp_msg_in_get_msgno(trans)))\n        {\n            case E_CCP_CLOSE_CONNECTION_REQUEST:\n                rv = xrdp_mm_process_close_ccp_connection_request(self);\n                break;\n\n            default:\n            {\n                char buff[64];\n                ccp_msgno_to_str(msgno, buff, sizeof(buff));\n                LOG(LOG_LEVEL_ERROR, \"Ignored CCP message %s from sesman\",\n                    buff);\n            }\n        }\n\n        ccp_msg_in_reset(trans);\n    }\n\n    return rv;\n}\n"
  },
  {
    "path": "xrdp/xrdp_painter.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * painter, gc\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <limits.h>\n\n#include \"xrdp.h\"\n#include \"string_calls.h\"\n\n#if defined(XRDP_PAINTER)\n#include <painter.h> /* libpainter */\n#endif\n\n\n#if defined(XRDP_PAINTER)\n\n/*****************************************************************************/\nstatic int\nxrdp_painter_add_dirty_rect(struct xrdp_painter *self, int x, int y,\n                            int cx, int cy, struct xrdp_rect *clip_rect)\n{\n    int x2;\n    int y2;\n    struct xrdp_rect rect;\n\n    if (clip_rect != 0)\n    {\n        x2 = x + cx;\n        y2 = y + cy;\n        x = MAX(x, clip_rect->left);\n        y = MAX(y, clip_rect->top);\n        x2 = MIN(x2, clip_rect->right);\n        y2 = MIN(y2, clip_rect->bottom);\n        cx = x2 - x;\n        cy = y2 - y;\n    }\n    if (cx < 1 || cy < 1)\n    {\n        return 0;\n    }\n    rect.left = x;\n    rect.top = y;\n    rect.right = x + cx;\n    rect.bottom = y + cy;\n    xrdp_region_add_rect(self->dirty_region, &rect);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_add_dirty_rect: x %d y %d cx %d cy %d\",\n              x, y, cx, cy);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_painter_send_dirty(struct xrdp_painter *self)\n{\n    int cx;\n    int cy;\n    int bpp;\n    int Bpp;\n    int index;\n    int jndex;\n    int error;\n    char *ldata;\n    char *src;\n    char *dst;\n    struct xrdp_rect rect;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_send_dirty:\");\n\n    bpp = self->wm->screen->bpp;\n    Bpp = (bpp + 7) / 8;\n    if (Bpp == 3)\n    {\n        Bpp = 4;\n    }\n\n    if (self->session->client_info->gfx)\n    {\n        xrdp_mm_efgx_add_dirty_region_to_planar_list(self->wm->mm,\n                self->dirty_region);\n    }\n    else\n    {\n        jndex = 0;\n        error = xrdp_region_get_rect(self->dirty_region, jndex, &rect);\n        while (error == 0)\n        {\n            cx = rect.right - rect.left;\n            cy = rect.bottom - rect.top;\n            ldata = (char *)g_malloc(cx * cy * Bpp, 0);\n            if (ldata == 0)\n            {\n                return 1;\n            }\n            src = self->wm->screen->data;\n            src += self->wm->screen->line_size * rect.top;\n            src += rect.left * Bpp;\n            dst = ldata;\n            for (index = 0; index < cy; index++)\n            {\n                g_memcpy(dst, src, cx * Bpp);\n                src += self->wm->screen->line_size;\n                dst += cx * Bpp;\n            }\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_send_dirty:\"\n                      \" x %d y %d cx %d cy %d\",\n                      rect.left, rect.top, cx, cy);\n            libxrdp_send_bitmap(self->session, cx, cy, bpp,\n                                ldata, rect.left, rect.top, cx, cy);\n            g_free(ldata);\n\n            jndex++;\n            error = xrdp_region_get_rect(self->dirty_region, jndex, &rect);\n        }\n    }\n\n    xrdp_region_delete(self->dirty_region);\n    self->dirty_region = xrdp_region_create(self->wm);\n\n    return 0;\n}\n\n#endif\n\n/*****************************************************************************/\nstruct xrdp_painter *\nxrdp_painter_create(struct xrdp_wm *wm, struct xrdp_session *session)\n{\n    struct xrdp_painter *self;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_create:\");\n    self = (struct xrdp_painter *)g_malloc(sizeof(struct xrdp_painter), 1);\n    self->wm = wm;\n    self->session = session;\n    self->rop = 0xcc; /* copy will use 0xcc */\n    self->clip_children = 1;\n\n    if (self->session->client_info->no_orders_supported ||\n            self->session->client_info->gfx)\n    {\n#if defined(XRDP_PAINTER)\n        if (painter_create(&(self->painter)) != PT_ERROR_NONE)\n        {\n            self->painter = 0;\n            LOG_DEVEL(LOG_LEVEL_WARNING, \"xrdp_painter_create: painter_create failed\");\n        }\n        else\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_create: painter_create success\");\n        }\n        self->dirty_region = xrdp_region_create(wm);\n#endif\n    }\n\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_painter_delete(struct xrdp_painter *self)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_delete:\");\n    if (self == 0)\n    {\n        return;\n    }\n\n#if defined(XRDP_PAINTER)\n    painter_delete(self->painter);\n    xrdp_region_delete(self->dirty_region);\n#endif\n\n    g_free(self);\n}\n\n/*****************************************************************************/\nint\nwm_painter_set_target(struct xrdp_painter *self)\n{\n    int surface_index;\n    int index;\n    struct list *del_list;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"wm_painter_set_target:\");\n\n    if (self->painter != 0)\n    {\n        return 0;\n    }\n\n    if (self->wm->target_surface->type == WND_TYPE_SCREEN)\n    {\n        if (self->wm->current_surface_index != 0xffff)\n        {\n            libxrdp_orders_send_switch_os_surface(self->session, 0xffff);\n            self->wm->current_surface_index = 0xffff;\n        }\n    }\n    else if (self->wm->target_surface->type == WND_TYPE_OFFSCREEN)\n    {\n        surface_index = self->wm->target_surface->item_index;\n\n        if (surface_index != self->wm->current_surface_index)\n        {\n            if (self->wm->target_surface->tab_stop == 0) /* tab_stop is hack */\n            {\n                del_list = self->wm->cache->xrdp_os_del_list;\n                index = list_index_of(del_list, surface_index);\n                list_remove_item(del_list, index);\n                libxrdp_orders_send_create_os_surface(self->session, surface_index,\n                                                      self->wm->target_surface->width,\n                                                      self->wm->target_surface->height,\n                                                      del_list);\n                self->wm->target_surface->tab_stop = 1;\n                list_clear(del_list);\n            }\n\n            libxrdp_orders_send_switch_os_surface(self->session, surface_index);\n            self->wm->current_surface_index = surface_index;\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"xrdp_painter_begin_update: bad target_surface\");\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_begin_update(struct xrdp_painter *self)\n{\n    int rv;\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_begin_update:\");\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    self->begin_end_level++;\n\n    if (self->painter != 0)\n    {\n        return 0;\n    }\n\n    rv = libxrdp_orders_init(self->session);\n    wm_painter_set_target(self);\n    return rv;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_end_update(struct xrdp_painter *self)\n{\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_end_update:\");\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    self->begin_end_level--;\n\n    if (self->painter != 0)\n    {\n#if defined(XRDP_PAINTER)\n        if (self->begin_end_level == 0)\n        {\n            xrdp_painter_send_dirty(self);\n            return 0;\n        }\n#endif\n    }\n\n    libxrdp_orders_send(self->session);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_font_needed(struct xrdp_painter *self)\n{\n    if (self->font == 0)\n    {\n        self->font = self->wm->default_font;\n    }\n\n    return 0;\n}\n\n#if 0\n/*****************************************************************************/\n/* returns boolean, true if there is something to draw */\nstatic int\nxrdp_painter_clip_adj(struct xrdp_painter *self, int *x, int *y,\n                      int *cx, int *cy)\n{\n    int dx;\n    int dy;\n\n    if (!self->use_clip)\n    {\n        return 1;\n    }\n\n    if (self->clip.left > *x)\n    {\n        dx = self->clip.left - *x;\n    }\n    else\n    {\n        dx = 0;\n    }\n\n    if (self->clip.top > *y)\n    {\n        dy = self->clip.top - *y;\n    }\n    else\n    {\n        dy = 0;\n    }\n\n    if (*x + *cx > self->clip.right)\n    {\n        *cx = *cx - ((*x + *cx) - self->clip.right);\n    }\n\n    if (*y + *cy > self->clip.bottom)\n    {\n        *cy = *cy - ((*y + *cy) - self->clip.bottom);\n    }\n\n    *cx = *cx - dx;\n    *cy = *cy - dy;\n\n    if (*cx <= 0)\n    {\n        return 0;\n    }\n\n    if (*cy <= 0)\n    {\n        return 0;\n    }\n\n    *x = *x + dx;\n    *y = *y + dy;\n    return 1;\n}\n#endif\n\n/*****************************************************************************/\nint\nxrdp_painter_set_clip(struct xrdp_painter *self,\n                      int x, int y, int cx, int cy)\n{\n    self->use_clip = &self->clip;\n    self->clip.left = x;\n    self->clip.top = y;\n    self->clip.right = x + cx;\n    self->clip.bottom = y + cy;\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_clr_clip(struct xrdp_painter *self)\n{\n    self->use_clip = 0;\n    return 0;\n}\n\n#if 0\n/*****************************************************************************/\nstatic int\nxrdp_painter_rop(int rop, int src, int dst)\n{\n    switch (rop & 0x0f)\n    {\n        case 0x0:\n            return 0;\n        case 0x1:\n            return ~(src | dst);\n        case 0x2:\n            return (~src) & dst;\n        case 0x3:\n            return ~src;\n        case 0x4:\n            return src & (~dst);\n        case 0x5:\n            return ~(dst);\n        case 0x6:\n            return src ^ dst;\n        case 0x7:\n            return ~(src & dst);\n        case 0x8:\n            return src & dst;\n        case 0x9:\n            return ~(src) ^ dst;\n        case 0xa:\n            return dst;\n        case 0xb:\n            return (~src) | dst;\n        case 0xc:\n            return src;\n        case 0xd:\n            return src | (~dst);\n        case 0xe:\n            return src | dst;\n        case 0xf:\n            return ~0;\n    }\n\n    return dst;\n}\n#endif\n\n/*****************************************************************************/\nint\nxrdp_painter_text_width(struct xrdp_painter *self, const char *text)\n{\n    return xrdp_painter_text_width_count(self, text, UINT_MAX);\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_text_width_count(struct xrdp_painter *self, const char *text,\n                              unsigned int c32_count)\n{\n    int rv = 0;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_text_width_count:\");\n    xrdp_painter_font_needed(self);\n\n    if (self->font != NULL && text != NULL)\n    {\n        unsigned int index;\n        for (index = 0 ; index < c32_count; ++index)\n        {\n            struct xrdp_font_char *font_item;\n            char32_t c32 = utf8_get_next_char(&text, NULL);\n            if (c32 == 0)\n            {\n                break; // Terminator\n            }\n            font_item = XRDP_FONT_GET_CHAR(self->font, c32);\n            rv += font_item->incby;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_repeated_char_width(struct xrdp_painter *self,\n                                 char32_t chr, unsigned int repeat_count)\n{\n    int rv = 0;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_repeated_char_width:\");\n    xrdp_painter_font_needed(self);\n\n    if (self->font != NULL)\n    {\n        struct xrdp_font_char *font_item = XRDP_FONT_GET_CHAR(self->font, chr);\n        rv = font_item->incby * repeat_count;\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nunsigned int\nxrdp_painter_font_body_height(const struct xrdp_painter *self)\n{\n    return (self->font == NULL) ? 0 : self->font->body_height;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_painter_setup_brush(struct xrdp_painter *self,\n                         struct xrdp_brush *out_brush,\n                         struct xrdp_brush *in_brush)\n{\n    int cache_id;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_setup_brush:\");\n\n    if (self->painter != 0)\n    {\n        return 0;\n    }\n\n    g_memcpy(out_brush, in_brush, sizeof(struct xrdp_brush));\n\n    if (in_brush->style == 3)\n    {\n        if (self->session->client_info->brush_cache_code == 1)\n        {\n            cache_id = xrdp_cache_add_brush(self->wm->cache, in_brush->pattern);\n            g_memset(out_brush->pattern, 0, 8);\n            out_brush->pattern[0] = cache_id;\n            out_brush->style = 0x81;\n        }\n    }\n\n    return 0;\n}\n\n#if defined(XRDP_PAINTER)\n\n/*****************************************************************************/\nstatic int\nget_pt_format(struct xrdp_painter *self)\n{\n    switch (self->wm->screen->bpp)\n    {\n        case 8:\n            return PT_FORMAT_r3g3b2;\n        case 15:\n            return PT_FORMAT_a1r5g5b5;\n        case 16:\n            return PT_FORMAT_r5g6b5;\n    }\n    return PT_FORMAT_a8r8g8b8;\n}\n\n/*****************************************************************************/\nstatic int\nget_rgb_from_rdp_color(struct xrdp_painter *self, int rdp_color)\n{\n    if (self->wm->screen->bpp < 24)\n    {\n        return rdp_color;\n    }\n    /* well, this is really BGR2RGB */\n    return XR_RGB2BGR(rdp_color);\n}\n\n#endif\n\n/*****************************************************************************/\n/* fill in an area of the screen with one color */\nint\nxrdp_painter_fill_rect(struct xrdp_painter *self,\n                       struct xrdp_bitmap *dst,\n                       int x, int y, int cx, int cy)\n{\n    struct xrdp_rect clip_rect;\n    struct xrdp_rect draw_rect;\n    struct xrdp_rect rect;\n    struct xrdp_region *region;\n    struct xrdp_brush brush;\n    int k;\n    int dx;\n    int dy;\n    int rop;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_fill_rect:\");\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    dx = 0;\n    dy = 0;\n\n    if (self->painter != 0)\n    {\n#if defined(XRDP_PAINTER)\n        struct painter_bitmap dst_pb;\n        struct xrdp_bitmap *ldst;\n        struct painter_bitmap pat;\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_fill_rect: dst->type %d\", dst->type);\n        if (dst->type != WND_TYPE_OFFSCREEN)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_fill_rect: using painter\");\n\n            ldst = self->wm->screen;\n\n            g_memset(&dst_pb, 0, sizeof(dst_pb));\n            dst_pb.format = get_pt_format(self);\n            dst_pb.width = ldst->width;\n            dst_pb.stride_bytes = ldst->line_size;\n            dst_pb.height = ldst->height;\n            dst_pb.data = ldst->data;\n\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_fill_rect: ldst->width %d ldst->height %d \"\n                      \"dst->data %p self->fg_color %d\",\n                      ldst->width, ldst->height, ldst->data, self->fg_color);\n\n            xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n            region = xrdp_region_create(self->wm);\n            xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy, region,\n                                   self->clip_children);\n            x += dx;\n            y += dy;\n\n            rop = self->rop;\n            switch (self->rop)\n            {\n                case 0x5a:\n                    rop = PT_ROP_DSx;\n                    break;\n                case 0xf0:\n                    rop = PT_ROP_S;\n                    break;\n                case 0xfb:\n                    rop = PT_ROP_D;\n                    break;\n                case 0xc0:\n                    rop = PT_ROP_DSa;\n                    break;\n            }\n            painter_set_rop(self->painter, rop);\n\n            if (self->mix_mode == 0)\n            {\n                painter_set_pattern_mode(self->painter, PT_PATTERN_MODE_OPAQUE);\n                painter_set_fgcolor(self->painter, get_rgb_from_rdp_color(self, self->fg_color));\n                k = 0;\n                while (xrdp_region_get_rect(region, k, &rect) == 0)\n                {\n                    if (rect_intersect(&rect, &clip_rect, &draw_rect))\n                    {\n                        painter_set_clip(self->painter,\n                                         draw_rect.left, draw_rect.top,\n                                         draw_rect.right - draw_rect.left,\n                                         draw_rect.bottom - draw_rect.top);\n                        painter_fill_rect(self->painter, &dst_pb, x, y, cx, cy);\n                        xrdp_painter_add_dirty_rect(self, x, y, cx, cy, &draw_rect);\n                    }\n                    k++;\n                }\n            }\n            else\n            {\n                painter_set_pattern_mode(self->painter, PT_PATTERN_MODE_OPAQUE);\n                painter_set_fgcolor(self->painter, get_rgb_from_rdp_color(self, self->fg_color));\n                painter_set_bgcolor(self->painter, get_rgb_from_rdp_color(self, self->bg_color));\n                painter_set_pattern_origin(self->painter, self->brush.x_origin, self->brush.y_origin);\n                g_memset(&pat, 0, sizeof(pat));\n                pat.format = PT_FORMAT_c1;\n                pat.width = 8;\n                pat.stride_bytes = 1;\n                pat.height = 8;\n                pat.data = self->brush.pattern;\n                k = 0;\n                while (xrdp_region_get_rect(region, k, &rect) == 0)\n                {\n                    if (rect_intersect(&rect, &clip_rect, &draw_rect))\n                    {\n                        painter_set_clip(self->painter,\n                                         draw_rect.left, draw_rect.top,\n                                         draw_rect.right - draw_rect.left,\n                                         draw_rect.bottom - draw_rect.top);\n                        painter_fill_pattern(self->painter, &dst_pb, &pat,\n                                             x, y, x, y, cx, cy);\n                        xrdp_painter_add_dirty_rect(self, x, y, cx, cy, &draw_rect);\n                    }\n                    k++;\n                }\n            }\n            painter_clear_clip(self->painter);\n            xrdp_region_delete(region);\n        }\n        return 0;\n#endif\n    }\n\n    /* todo data */\n\n    if (dst->type == WND_TYPE_BITMAP) /* 0 */\n    {\n        return 0;\n    }\n\n    xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n    region = xrdp_region_create(self->wm);\n\n    if (dst->type != WND_TYPE_OFFSCREEN)\n    {\n        xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy, region,\n                               self->clip_children);\n    }\n    else\n    {\n        xrdp_region_add_rect(region, &clip_rect);\n    }\n\n    x += dx;\n    y += dy;\n\n    if (self->mix_mode == 0 && self->rop == 0xcc)\n    {\n        k = 0;\n\n        while (xrdp_region_get_rect(region, k, &rect) == 0)\n        {\n            if (rect_intersect(&rect, &clip_rect, &draw_rect))\n            {\n                libxrdp_orders_rect(self->session, x, y, cx, cy,\n                                    self->fg_color, &draw_rect);\n            }\n\n            k++;\n        }\n    }\n    else if (self->mix_mode == 0 &&\n             ((self->rop & 0xf) == 0x0 || /* black */\n              (self->rop & 0xf) == 0xf || /* white */\n              (self->rop & 0xf) == 0x5))  /* DSTINVERT */\n    {\n        k = 0;\n\n        while (xrdp_region_get_rect(region, k, &rect) == 0)\n        {\n            if (rect_intersect(&rect, &clip_rect, &draw_rect))\n            {\n                libxrdp_orders_dest_blt(self->session, x, y, cx, cy,\n                                        self->rop, &draw_rect);\n            }\n\n            k++;\n        }\n    }\n    else\n    {\n        k = 0;\n        rop = self->rop;\n\n        /* if opcode is in the form 0x00, 0x11, 0x22, ... convert it */\n        if (((rop & 0xf0) >> 4) == (rop & 0xf))\n        {\n            switch (rop)\n            {\n                case 0x66: /* xor */\n                    rop = 0x5a;\n                    break;\n                case 0xaa: /* noop */\n                    rop = 0xfb;\n                    break;\n                case 0xcc: /* copy */\n                    rop = 0xf0;\n                    break;\n                case 0x88: /* and */\n                    rop = 0xc0;\n                    break;\n            }\n        }\n\n        xrdp_painter_setup_brush(self, &brush, &self->brush);\n\n        while (xrdp_region_get_rect(region, k, &rect) == 0)\n        {\n            if (rect_intersect(&rect, &clip_rect, &draw_rect))\n            {\n                libxrdp_orders_pat_blt(self->session, x, y, cx, cy,\n                                       rop, self->bg_color, self->fg_color,\n                                       &brush, &draw_rect);\n            }\n\n            k++;\n        }\n    }\n\n    xrdp_region_delete(region);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_painter_draw_utf32(struct xrdp_painter *self,\n                        struct xrdp_bitmap *dst,\n                        int x, int y,\n                        char32_t utf32[], unsigned int utf32len)\n{\n    int i;\n    int f;\n    int c;\n    int k;\n    int x1;\n    int y1;\n    int flags;\n    unsigned int index;\n    int total_width;\n    int total_height;\n    int dx;\n    int dy;\n    char *data;\n    struct xrdp_region *region;\n    struct xrdp_rect rect;\n    struct xrdp_rect clip_rect;\n    struct xrdp_rect draw_rect;\n    struct xrdp_font *font;\n    struct xrdp_font_char *font_item;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_draw_text:\");\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (utf32len < 1)\n    {\n        return 0;\n    }\n\n    /* todo data */\n\n    if (dst->type == 0)\n    {\n        return 0;\n    }\n\n    xrdp_painter_font_needed(self);\n\n    if (self->font == 0)\n    {\n        return 0;\n    }\n\n    if (self->painter != 0)\n    {\n#if defined(XRDP_PAINTER)\n        struct painter_bitmap pat;\n        struct painter_bitmap dst_pb;\n        struct xrdp_bitmap *ldst;\n\n        if (dst->type != WND_TYPE_OFFSCREEN)\n        {\n            ldst = self->wm->screen;\n            font = self->font;\n\n            // Calculate total width and height fields\n            total_width = 0;\n            total_height = 0;\n\n            for (index = 0 ; index < utf32len; ++index)\n            {\n                font_item = XRDP_FONT_GET_CHAR(font, utf32[index]);\n                k = font_item->incby;\n                total_width += k;\n                /* Use the nominal height of the font to work out the\n                 * actual height of this glyph */\n                int glyph_height =\n                    font->body_height + font_item->baseline + font_item->height;\n                total_height = MAX(total_height, glyph_height);\n            }\n\n            xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n            region = xrdp_region_create(self->wm);\n            xrdp_wm_get_vis_region(self->wm, dst, x, y,\n                                   total_width, total_height,\n                                   region, self->clip_children);\n            x += dx;\n            y += dy;\n            g_memset(&dst_pb, 0, sizeof(dst_pb));\n            dst_pb.format = get_pt_format(self);\n            dst_pb.width = ldst->width;\n            dst_pb.stride_bytes = ldst->line_size;\n            dst_pb.height = ldst->height;\n            dst_pb.data = ldst->data;\n            painter_set_rop(self->painter, PT_ROP_S);\n            painter_set_pattern_origin(self->painter, 0, 0);\n            painter_set_pattern_mode(self->painter, PT_PATTERN_MODE_NORMAL);\n            painter_set_fgcolor(self->painter,\n                                get_rgb_from_rdp_color(self, self->fg_color));\n            k = 0;\n            while (xrdp_region_get_rect(region, k, &rect) == 0)\n            {\n                if (rect_intersect(&rect, &clip_rect, &draw_rect))\n                {\n                    painter_set_clip(self->painter,\n                                     draw_rect.left, draw_rect.top,\n                                     draw_rect.right - draw_rect.left,\n                                     draw_rect.bottom - draw_rect.top);\n                    for (index = 0 ; index < utf32len; ++index)\n                    {\n                        font_item = XRDP_FONT_GET_CHAR(font, utf32[index]);\n                        g_memset(&pat, 0, sizeof(pat));\n                        pat.format = PT_FORMAT_c1;\n                        pat.width = font_item->width;\n                        pat.stride_bytes = (font_item->width + 7) / 8;\n                        pat.height = font_item->height;\n                        pat.data = font_item->data;\n                        x1 = x + font_item->offset;\n                        y1 = y + (font->body_height + font_item->baseline);\n                        painter_fill_pattern(self->painter, &dst_pb, &pat,\n                                             0, 0, x1, y1,\n                                             font_item->width,\n                                             font_item->height);\n                        xrdp_painter_add_dirty_rect(self, x1, y1,\n                                                    font_item->width,\n                                                    font_item->height,\n                                                    &draw_rect);\n                        x += font_item->incby;\n                    }\n                }\n                k++;\n            }\n            painter_clear_clip(self->painter);\n            xrdp_region_delete(region);\n        }\n        return 0;\n#endif\n    }\n\n    font = self->font;\n    f = 0;\n    k = 0;\n    total_width = 0;\n    total_height = 0;\n    index = 0;\n    data = (char *)g_malloc(utf32len * 2, 1);\n\n    for (index = 0 ; index < utf32len; ++index)\n    {\n        font_item = XRDP_FONT_GET_CHAR(font, utf32[index]);\n        i = xrdp_cache_add_char(self->wm->cache, font_item);\n        f = HIWORD(i);\n        c = LOWORD(i);\n        data[index * 2] = c;\n        data[index * 2 + 1] = k;\n        k = font_item->incby;\n        total_width += k;\n        /* Use the nominal height of the font to work out the\n         * actual height of this glyph */\n        int glyph_height =\n            font->body_height + font_item->baseline + font_item->height;\n        total_height = MAX(total_height, glyph_height);\n    }\n\n    xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n    region = xrdp_region_create(self->wm);\n\n    if (dst->type != WND_TYPE_OFFSCREEN)\n    {\n        xrdp_wm_get_vis_region(self->wm, dst, x, y, total_width, total_height,\n                               region, self->clip_children);\n    }\n    else\n    {\n        xrdp_region_add_rect(region, &clip_rect);\n    }\n\n    x += dx;\n    y += dy;\n    k = 0;\n\n    while (xrdp_region_get_rect(region, k, &rect) == 0)\n    {\n        if (rect_intersect(&rect, &clip_rect, &draw_rect))\n        {\n            x1 = x;\n            y1 = y + font->body_height;\n            flags = 0x03; /* 0x03 0x73; TEXT2_IMPLICIT_X and something else */\n            libxrdp_orders_text(self->session, f, flags, 0,\n                                self->fg_color, 0,\n                                x - 1, y - 1, x + total_width, y + total_height,\n                                0, 0, 0, 0,\n                                x1, y1, data, utf32len * 2, &draw_rect);\n        }\n\n        k++;\n    }\n\n    xrdp_region_delete(region);\n    g_free(data);\n    return 0;\n}\n\n\n/*****************************************************************************/\nint\nxrdp_painter_draw_text(struct xrdp_painter *self,\n                       struct xrdp_bitmap *dst,\n                       int x, int y, const char *text)\n{\n    int rv = 0;\n    unsigned int c32_count = utf8_char_count(text);\n\n    if (c32_count > 0)\n    {\n        char32_t *utf32 = (char32_t *)malloc(c32_count * sizeof(char32_t));\n        if (utf32 == NULL)\n        {\n            rv = 1;\n        }\n        else\n        {\n            unsigned int i = 0;\n            char32_t c32;\n\n            while ((c32 = utf8_get_next_char(&text, NULL)) != 0)\n            {\n                utf32[i++] = c32;\n            }\n\n            rv = xrdp_painter_draw_utf32(self, dst, x, y, utf32, c32_count);\n            free (utf32);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_draw_text2(struct xrdp_painter *self,\n                        struct xrdp_bitmap *dst,\n                        int font, int flags, int mixmode,\n                        int clip_left, int clip_top,\n                        int clip_right, int clip_bottom,\n                        int box_left, int box_top,\n                        int box_right, int box_bottom,\n                        int x, int y, char *data, int data_len)\n{\n    struct xrdp_rect clip_rect;\n    struct xrdp_rect draw_rect;\n    struct xrdp_rect rect;\n    struct xrdp_region *region;\n    int k;\n    int dx;\n    int dy;\n\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_painter_draw_text2:\");\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (self->painter != 0)\n    {\n        return 0;\n    }\n\n    /* todo data */\n\n    if (dst->type == WND_TYPE_BITMAP)\n    {\n        return 0;\n    }\n\n    xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n    region = xrdp_region_create(self->wm);\n\n    if (dst->type != WND_TYPE_OFFSCREEN)\n    {\n        if (box_right - box_left > 1)\n        {\n            xrdp_wm_get_vis_region(self->wm, dst, box_left, box_top,\n                                   box_right - box_left, box_bottom - box_top,\n                                   region, self->clip_children);\n        }\n        else\n        {\n            xrdp_wm_get_vis_region(self->wm, dst, clip_left, clip_top,\n                                   clip_right - clip_left, clip_bottom - clip_top,\n                                   region, self->clip_children);\n        }\n    }\n    else\n    {\n        xrdp_region_add_rect(region, &clip_rect);\n    }\n\n    clip_left += dx;\n    clip_top += dy;\n    clip_right += dx;\n    clip_bottom += dy;\n    box_left += dx;\n    box_top += dy;\n    box_right += dx;\n    box_bottom += dy;\n    x += dx;\n    y += dy;\n    k = 0;\n\n    while (xrdp_region_get_rect(region, k, &rect) == 0)\n    {\n        if (rect_intersect(&rect, &clip_rect, &draw_rect))\n        {\n            libxrdp_orders_text(self->session, font, flags, mixmode,\n                                self->fg_color, self->bg_color,\n                                clip_left, clip_top, clip_right, clip_bottom,\n                                box_left, box_top, box_right, box_bottom,\n                                x, y, data, data_len, &draw_rect);\n        }\n\n        k++;\n    }\n\n    xrdp_region_delete(region);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_draw_char(struct xrdp_painter *self,\n                       struct xrdp_bitmap *dst,\n                       int x, int y, char32_t chr,\n                       unsigned int repeat_count)\n{\n    int rv = 0;\n\n    if (repeat_count > 0)\n    {\n        char32_t *utf32 =\n            (char32_t *)malloc(repeat_count * sizeof(char32_t));\n\n        if (utf32 == NULL)\n        {\n            rv = 1;\n        }\n        else\n        {\n            unsigned int i = 0;\n            for (i = 0; i < repeat_count; ++i)\n            {\n                utf32[i] = chr;\n            }\n\n            rv = xrdp_painter_draw_utf32(self, dst, x, y, utf32, repeat_count);\n            free (utf32);\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_copy(struct xrdp_painter *self,\n                  struct xrdp_bitmap *src,\n                  struct xrdp_bitmap *dst,\n                  int x, int y, int cx, int cy,\n                  int srcx, int srcy)\n{\n    struct xrdp_rect clip_rect;\n    struct xrdp_rect draw_rect;\n    struct xrdp_rect rect1;\n    struct xrdp_rect rect2;\n    struct xrdp_region *region;\n    struct xrdp_bitmap *b;\n    int i;\n    int j;\n    int k;\n    int dx;\n    int dy;\n    int palette_id;\n    int bitmap_id;\n    int cache_id;\n    int cache_idx;\n    int dstx;\n    int dsty;\n    int w;\n    int h;\n    int index;\n    struct list *del_list;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_copy:\");\n\n    if (self == 0 || src == 0 || dst == 0)\n    {\n        return 0;\n    }\n\n    if (self->painter != 0)\n    {\n#if defined(XRDP_PAINTER)\n        struct painter_bitmap src_pb;\n        struct painter_bitmap dst_pb;\n        struct xrdp_bitmap *ldst;\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_copy: src->type %d dst->type %d\", src->type, dst->type);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_copy: self->rop 0x%2.2x\", self->rop);\n\n        if (dst->type != WND_TYPE_OFFSCREEN)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_copy: using painter\");\n            ldst = self->wm->screen;\n\n            g_memset(&dst_pb, 0, sizeof(dst_pb));\n            dst_pb.format = get_pt_format(self);\n            dst_pb.width = ldst->width;\n            dst_pb.stride_bytes = ldst->line_size;\n            dst_pb.height = ldst->height;\n            dst_pb.data = ldst->data;\n\n            g_memset(&src_pb, 0, sizeof(src_pb));\n            src_pb.format = get_pt_format(self);\n            src_pb.width = src->width;\n            src_pb.stride_bytes = src->line_size;\n            src_pb.height = src->height;\n            src_pb.data = src->data;\n\n            xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n            region = xrdp_region_create(self->wm);\n            xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy, region,\n                                   self->clip_children);\n            x += dx;\n            y += dy;\n            k = 0;\n\n            painter_set_rop(self->painter, self->rop);\n            while (xrdp_region_get_rect(region, k, &rect1) == 0)\n            {\n                if (rect_intersect(&rect1, &clip_rect, &draw_rect))\n                {\n                    painter_set_clip(self->painter,\n                                     draw_rect.left, draw_rect.top,\n                                     draw_rect.right - draw_rect.left,\n                                     draw_rect.bottom - draw_rect.top);\n                    LOG_DEVEL(LOG_LEVEL_DEBUG, \"  x %d y %d cx %d cy %d srcx %d srcy %d\",\n                              x, y, cx, cy, srcx, srcy);\n                    painter_copy(self->painter, &dst_pb, x, y, cx, cy,\n                                 &src_pb, srcx, srcy);\n                    xrdp_painter_add_dirty_rect(self, x, y, cx, cy,\n                                                &draw_rect);\n                }\n                k++;\n            }\n            painter_clear_clip(self->painter);\n            xrdp_region_delete(region);\n        }\n\n        return 0;\n#endif\n    }\n\n    /* todo data */\n\n    if (dst->type == WND_TYPE_BITMAP)\n    {\n        return 0;\n    }\n\n    if (src->type == WND_TYPE_SCREEN)\n    {\n        xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n        region = xrdp_region_create(self->wm);\n\n        if (dst->type != WND_TYPE_OFFSCREEN)\n        {\n            xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,\n                                   region, self->clip_children);\n        }\n        else\n        {\n            xrdp_region_add_rect(region, &clip_rect);\n        }\n\n        x += dx;\n        y += dy;\n        srcx += dx;\n        srcy += dy;\n        k = 0;\n\n        while (xrdp_region_get_rect(region, k, &rect1) == 0)\n        {\n            if (rect_intersect(&rect1, &clip_rect, &draw_rect))\n            {\n                libxrdp_orders_screen_blt(self->session, x, y, cx, cy,\n                                          srcx, srcy, self->rop, &draw_rect);\n            }\n\n            k++;\n        }\n\n        xrdp_region_delete(region);\n    }\n    else if (src->type == WND_TYPE_OFFSCREEN)\n    {\n        LOG(LOG_LEVEL_DEBUG, \"xrdp_painter_copy: todo\");\n\n        xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n        region = xrdp_region_create(self->wm);\n\n        if (dst->type != WND_TYPE_OFFSCREEN)\n        {\n            LOG(LOG_LEVEL_DEBUG, \"off screen to screen\");\n            xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,\n                                   region, self->clip_children);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_DEBUG, \"off screen to off screen\");\n            xrdp_region_add_rect(region, &clip_rect);\n        }\n\n        x += dx;\n        y += dy;\n\n        palette_id = 0;\n        cache_id = 255; // todo\n        cache_idx = src->item_index; // todo\n\n        if (src->tab_stop == 0)\n        {\n            LOG(LOG_LEVEL_WARNING, \"xrdp_painter_copy: warning src not created\");\n            del_list = self->wm->cache->xrdp_os_del_list;\n            index = list_index_of(del_list, cache_idx);\n            list_remove_item(del_list, index);\n            libxrdp_orders_send_create_os_surface(self->session,\n                                                  cache_idx,\n                                                  src->width,\n                                                  src->height,\n                                                  del_list);\n            src->tab_stop = 1;\n            list_clear(del_list);\n        }\n\n\n        k = 0;\n\n        while (xrdp_region_get_rect(region, k, &rect1) == 0)\n        {\n            if (rect_intersect(&rect1, &clip_rect, &rect2))\n            {\n                MAKERECT(rect1, x, y, cx, cy);\n\n                if (rect_intersect(&rect2, &rect1, &draw_rect))\n                {\n                    libxrdp_orders_mem_blt(self->session, cache_id, palette_id,\n                                           x, y, cx, cy, self->rop, srcx, srcy,\n                                           cache_idx, &draw_rect);\n                }\n            }\n\n            k++;\n        }\n\n        xrdp_region_delete(region);\n    }\n    else if (src->data != 0)\n        /* todo, the non bitmap cache part is gone, it should be put back */\n    {\n        xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n        region = xrdp_region_create(self->wm);\n\n        if (dst->type != WND_TYPE_OFFSCREEN)\n        {\n            xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,\n                                   region, self->clip_children);\n        }\n        else\n        {\n            xrdp_region_add_rect(region, &clip_rect);\n        }\n\n        x += dx;\n        y += dy;\n        palette_id = 0;\n        j = srcy;\n\n        while (j < (srcy + cy))\n        {\n            i = srcx;\n\n            while (i < (srcx + cx))\n            {\n                w = MIN(64, ((srcx + cx) - i));\n                h = MIN(64, ((srcy + cy) - j));\n                b = xrdp_bitmap_create(w, h, src->bpp, 0, self->wm);\n#if 1\n                xrdp_bitmap_copy_box_with_crc(src, b, i, j, w, h);\n#else\n                xrdp_bitmap_copy_box(src, b, i, j, w, h);\n                xrdp_bitmap_hash_crc(b);\n#endif\n                bitmap_id = xrdp_cache_add_bitmap(self->wm->cache, b, self->wm->hints);\n                cache_id = HIWORD(bitmap_id);\n                cache_idx = LOWORD(bitmap_id);\n                dstx = (x + i) - srcx;\n                dsty = (y + j) - srcy;\n                k = 0;\n\n                while (xrdp_region_get_rect(region, k, &rect1) == 0)\n                {\n                    if (rect_intersect(&rect1, &clip_rect, &rect2))\n                    {\n                        MAKERECT(rect1, dstx, dsty, w, h);\n\n                        if (rect_intersect(&rect2, &rect1, &draw_rect))\n                        {\n                            libxrdp_orders_mem_blt(self->session, cache_id, palette_id,\n                                                   dstx, dsty, w, h, self->rop, 0, 0,\n                                                   cache_idx, &draw_rect);\n                        }\n                    }\n\n                    k++;\n                }\n\n                i += 64;\n            }\n\n            j += 64;\n        }\n\n        xrdp_region_delete(region);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_composite(struct xrdp_painter *self,\n                       struct xrdp_bitmap *src,\n                       int srcformat,\n                       int srcwidth,\n                       int srcrepeat,\n                       struct xrdp_bitmap *dst,\n                       int *srctransform,\n                       int mskflags,\n                       struct xrdp_bitmap *msk,\n                       int mskformat, int mskwidth, int mskrepeat, int op,\n                       int srcx, int srcy, int mskx, int msky,\n                       int dstx, int dsty, int width, int height, int dstformat)\n{\n    struct xrdp_rect clip_rect;\n    struct xrdp_rect draw_rect;\n    struct xrdp_rect rect1;\n    struct xrdp_rect rect2;\n    struct xrdp_region *region;\n    int k;\n    int dx;\n    int dy;\n    int cache_srcidx;\n    int cache_mskidx;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_composite:\");\n\n    if (self == 0 || src == 0 || dst == 0)\n    {\n        return 0;\n    }\n\n    if (self->painter != 0)\n    {\n        return 0;\n    }\n\n    /* todo data */\n\n    if (dst->type == WND_TYPE_BITMAP)\n    {\n        return 0;\n    }\n\n    if (src->type == WND_TYPE_OFFSCREEN)\n    {\n        xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n        region = xrdp_region_create(self->wm);\n        xrdp_region_add_rect(region, &clip_rect);\n        dstx += dx;\n        dsty += dy;\n\n        cache_srcidx = src->item_index;\n        cache_mskidx = -1;\n        if (mskflags & 1)\n        {\n            if (msk != 0)\n            {\n                cache_mskidx = msk->item_index; // todo\n            }\n        }\n\n        k = 0;\n        while (xrdp_region_get_rect(region, k, &rect1) == 0)\n        {\n            if (rect_intersect(&rect1, &clip_rect, &rect2))\n            {\n                MAKERECT(rect1, dstx, dsty, width, height);\n                if (rect_intersect(&rect2, &rect1, &draw_rect))\n                {\n                    libxrdp_orders_composite_blt(self->session, cache_srcidx, srcformat, srcwidth,\n                                                 srcrepeat, srctransform, mskflags, cache_mskidx,\n                                                 mskformat, mskwidth, mskrepeat, op, srcx, srcy,\n                                                 mskx, msky, dstx, dsty, width, height, dstformat,\n                                                 &draw_rect);\n                }\n            }\n            k++;\n        }\n        xrdp_region_delete(region);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_painter_line(struct xrdp_painter *self,\n                  struct xrdp_bitmap *dst,\n                  int x1, int y1, int x2, int y2)\n{\n    struct xrdp_rect clip_rect;\n    struct xrdp_rect draw_rect;\n    struct xrdp_rect rect;\n    struct xrdp_region *region;\n    int k;\n    int dx;\n    int dy;\n    int rop;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_line:\");\n    if (self == 0)\n    {\n        return 0;\n    }\n    if (self->painter != 0)\n    {\n#if defined(XRDP_PAINTER)\n        int x;\n        int y;\n        int cx;\n        int cy;\n        struct painter_bitmap dst_pb;\n        struct xrdp_bitmap *ldst;\n\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_line: dst->type %d\", dst->type);\n        LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_line: self->rop 0x%2.2x\", self->rop);\n\n        if (dst->type != WND_TYPE_OFFSCREEN)\n        {\n            LOG_DEVEL(LOG_LEVEL_DEBUG, \"xrdp_painter_line: using painter\");\n            ldst = self->wm->screen;\n\n            g_memset(&dst_pb, 0, sizeof(dst_pb));\n            dst_pb.format = get_pt_format(self);\n            dst_pb.width = ldst->width;\n            dst_pb.stride_bytes = ldst->line_size;\n            dst_pb.height = ldst->height;\n            dst_pb.data = ldst->data;\n\n            xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n            region = xrdp_region_create(self->wm);\n            x = MIN(x1, x2);\n            y = MIN(y1, y2);\n            cx = g_abs(x1 - x2) + 1;\n            cy = g_abs(y1 - y2) + 1;\n            xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,\n                                   region, self->clip_children);\n            x1 += dx;\n            y1 += dy;\n            x2 += dx;\n            y2 += dy;\n            k = 0;\n            rop = self->rop;\n\n            painter_set_rop(self->painter, rop);\n            painter_set_fgcolor(self->painter, self->pen.color);\n            while (xrdp_region_get_rect(region, k, &rect) == 0)\n            {\n                if (rect_intersect(&rect, &clip_rect, &draw_rect))\n                {\n                    painter_set_clip(self->painter,\n                                     draw_rect.left, draw_rect.top,\n                                     draw_rect.right - draw_rect.left,\n                                     draw_rect.bottom - draw_rect.top);\n                    painter_line(self->painter, &dst_pb, x1, y1, x2, y2,\n                                 self->pen.width, 0);\n                    xrdp_painter_add_dirty_rect(self, x, y, cx, cy,\n                                                &draw_rect);\n                }\n                k++;\n            }\n            painter_clear_clip(self->painter);\n            xrdp_region_delete(region);\n        }\n\n        return 0;\n#endif\n    }\n\n    /* todo data */\n\n    if (dst->type == WND_TYPE_BITMAP)\n    {\n        return 0;\n    }\n\n    xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);\n    region = xrdp_region_create(self->wm);\n\n    if (dst->type != WND_TYPE_OFFSCREEN)\n    {\n        xrdp_wm_get_vis_region(self->wm, dst, MIN(x1, x2), MIN(y1, y2),\n                               g_abs(x1 - x2) + 1, g_abs(y1 - y2) + 1,\n                               region, self->clip_children);\n    }\n    else\n    {\n        xrdp_region_add_rect(region, &clip_rect);\n    }\n\n    x1 += dx;\n    y1 += dy;\n    x2 += dx;\n    y2 += dy;\n    k = 0;\n    rop = self->rop;\n\n    if (rop < 0x01 || rop > 0x10)\n    {\n        rop = (rop & 0xf) + 1;\n    }\n\n    while (xrdp_region_get_rect(region, k, &rect) == 0)\n    {\n        if (rect_intersect(&rect, &clip_rect, &draw_rect))\n        {\n            libxrdp_orders_line(self->session, 1, x1, y1, x2, y2,\n                                rop, self->bg_color,\n                                &self->pen, &draw_rect);\n        }\n\n        k++;\n    }\n\n    xrdp_region_delete(region);\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/xrdp_process.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * main rdp process\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp.h\"\n\nstatic int g_session_id = 0;\n\n/*****************************************************************************/\n/* always called from xrdp_listen thread */\nstruct xrdp_process *\nxrdp_process_create(struct xrdp_listen *owner, tbus done_event)\n{\n    struct xrdp_process *self;\n    char event_name[256];\n    int pid;\n\n    self = (struct xrdp_process *)g_malloc(sizeof(struct xrdp_process), 1);\n    self->lis_layer = owner;\n    self->done_event = done_event;\n    g_session_id++;\n    self->session_id = g_session_id;\n    pid = g_getpid();\n    g_snprintf(event_name, 255, \"xrdp_%8.8x_process_self_term_event_%8.8x\",\n               pid, self->session_id);\n    self->self_term_event = g_create_wait_obj(event_name);\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_process_delete(struct xrdp_process *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n\n    g_delete_wait_obj(self->self_term_event);\n    libxrdp_exit(self->session);\n    xrdp_wm_delete(self->wm);\n    trans_delete(self->server_trans);\n    g_free(self);\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_process_loop(struct xrdp_process *self, struct stream *s)\n{\n    int rv;\n\n    rv = 0;\n\n    if (self->session != 0)\n    {\n        rv = libxrdp_process_data(self->session, s);\n\n        if ((self->wm == 0) && (self->session->up_and_running) && (rv == 0))\n        {\n            LOG_DEVEL(LOG_LEVEL_TRACE, \"calling xrdp_wm_init and creating wm\");\n            self->wm = xrdp_wm_create(self, self->session->client_info);\n            /* at this point the wm(window manager) is created and\n               wm::login_state is WMLS_RESET and wm::login_state_event is set\n               so xrdp_wm_init should be called by xrdp_wm_check_wait_objs\n               */\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\n/* returns boolean */\n/* this is so libxrdp.so can known when to quit looping */\nstatic int\nxrdp_is_term(void)\n{\n    return g_is_term();\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_process_mod_end(struct xrdp_process *self)\n{\n    if (self->wm != 0)\n    {\n        if (self->wm->mm != 0)\n        {\n            if (self->wm->mm->mod != 0)\n            {\n                if (self->wm->mm->mod->mod_end != 0)\n                {\n                    return self->wm->mm->mod->mod_end(self->wm->mm->mod);\n                }\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_process_data_in(struct trans *self)\n{\n    struct xrdp_process *pro;\n    struct stream *s;\n    int len;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_process_data_in\");\n    pro = (struct xrdp_process *)(self->callback_data);\n\n    s = pro->server_trans->in_s;\n    switch (pro->server_trans->extra_flags)\n    {\n        case 0:\n            /* early in connection sequence, we're in this mode */\n            if (xrdp_process_loop(pro, 0) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"xrdp_process_data_in: \"\n                    \"xrdp_process_loop failed\");\n                return 1;\n            }\n            if (pro->session->up_and_running)\n            {\n                pro->server_trans->header_size = 2;\n                pro->server_trans->extra_flags = 1;\n                init_stream(s, 0);\n            }\n            break;\n\n        case 1:\n            /* we got 2 bytes */\n            if (s->p[0] == 3)\n            {\n                pro->server_trans->header_size = 4;\n                pro->server_trans->extra_flags = 2;\n            }\n            else\n            {\n                if (s->p[1] & 0x80)\n                {\n                    pro->server_trans->header_size = 3;\n                    pro->server_trans->extra_flags = 2;\n                }\n                else\n                {\n                    len = (tui8)(s->p[1]);\n                    pro->server_trans->header_size = len;\n                    pro->server_trans->extra_flags = 3;\n                }\n            }\n\n            len = (int) (s->end - s->data);\n            if (pro->server_trans->header_size > (unsigned int)len)\n            {\n                /* not enough data read yet */\n                break;\n            }\n        /* FALLTHROUGH */\n\n        case 2:\n            /* we have enough now to get the PDU bytes */\n            len = libxrdp_get_pdu_bytes(s->p);\n            if (len == -1)\n            {\n                LOG(LOG_LEVEL_ERROR, \"xrdp_process_data_in: \"\n                    \"xrdp_process_get_packet_bytes failed\");\n                return 1;\n            }\n            pro->server_trans->header_size = len;\n            pro->server_trans->extra_flags = 3;\n\n            len = (int) (s->end - s->data);\n            if (pro->server_trans->header_size > (unsigned int)len)\n            {\n                /* not enough data read yet */\n                break;\n            }\n        /* FALLTHROUGH */\n\n        case 3:\n            /* the whole PDU is read in now process */\n            s->p = s->data;\n            if (xrdp_process_loop(pro, s) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"xrdp_process_data_in: \"\n                    \"xrdp_process_loop failed\");\n                return 1;\n            }\n            init_stream(s, 0);\n            pro->server_trans->header_size = 2;\n            pro->server_trans->extra_flags = 1;\n            break;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_process_main_loop(struct xrdp_process *self)\n{\n    int robjs_count;\n    int wobjs_count;\n    int cont;\n    int timeout;\n    tbus robjs[32];\n    tbus wobjs[32];\n    tbus term_obj;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"xrdp_process_main_loop\");\n    self->status = 1;\n    self->server_trans->extra_flags = 0;\n    self->server_trans->header_size = 0;\n    self->server_trans->no_stream_init_on_data_in = 1;\n    self->server_trans->trans_data_in = xrdp_process_data_in;\n    self->server_trans->callback_data = self;\n    init_stream(self->server_trans->in_s, 8192 * 4);\n    self->session = libxrdp_init(self, self->server_trans,\n                                 self->lis_layer->startup_params->xrdp_ini);\n    self->server_trans->si = &(self->session->si);\n    self->server_trans->my_source = XRDP_SOURCE_CLIENT;\n    /* this callback function is in xrdp_wm.c */\n    self->session->callback = callback;\n    /* this function is just above */\n    self->session->is_term = xrdp_is_term;\n\n    if (libxrdp_process_incoming(self->session) == 0)\n    {\n        init_stream(self->server_trans->in_s, 32 * 1024);\n\n        term_obj = g_get_term();\n        cont = 1;\n\n        while (cont)\n        {\n            /* build the wait obj list */\n            timeout = -1;\n            robjs_count = 0;\n            wobjs_count = 0;\n            robjs[robjs_count++] = term_obj;\n            robjs[robjs_count++] = self->self_term_event;\n            xrdp_wm_get_wait_objs(self->wm, robjs, &robjs_count,\n                                  wobjs, &wobjs_count, &timeout);\n            trans_get_wait_objs_rw(self->server_trans, robjs, &robjs_count,\n                                   wobjs, &wobjs_count, &timeout);\n            /* wait */\n            if (g_obj_wait(robjs, robjs_count, wobjs, wobjs_count, timeout) != 0)\n            {\n                /* error, should not get here */\n                g_sleep(100);\n            }\n\n            if (g_is_wait_obj_set(term_obj)) /* term */\n            {\n                LOG(LOG_LEVEL_DEBUG,\n                    \"Received termination signal, stopping the client message \"\n                    \"processor thread\");\n                break;\n            }\n\n            if (g_is_wait_obj_set(self->self_term_event))\n            {\n                break;\n            }\n\n            if (xrdp_wm_check_wait_objs(self->wm) != 0)\n            {\n                break;\n            }\n\n            if (trans_check_wait_objs(self->server_trans) != 0)\n            {\n                break;\n            }\n        }\n        /* send disconnect message if possible */\n        libxrdp_disconnect(self->session, self->errinfo);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_process_main_loop: libxrdp_process_incoming failed\");\n        /* this will try to send a disconnect,\n           maybe should check that connection got far enough */\n        libxrdp_disconnect(self->session, self->errinfo);\n    }\n    /* Run end in module */\n    xrdp_process_mod_end(self);\n    xrdp_wm_delete(self->wm);\n    self->wm = NULL;\n    libxrdp_exit(self->session);\n    self->session = 0;\n    self->status = -1;\n    g_set_wait_obj(self->done_event);\n    return 0;\n}\n"
  },
  {
    "path": "xrdp/xrdp_region.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * region\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdp.h\"\n\n#if defined(XRDP_PIXMAN)\n#include <pixman.h>\n#else\n#include \"pixman-region.h\"\n#endif\n\n/*****************************************************************************/\nstruct xrdp_region *\nxrdp_region_create(struct xrdp_wm *wm)\n{\n    struct xrdp_region *self;\n\n    self = (struct xrdp_region *)g_malloc(sizeof(struct xrdp_region), 1);\n    self->wm = wm;\n    self->reg = (struct pixman_region16 *)\n                g_malloc(sizeof(struct pixman_region16), 1);\n    pixman_region_init(self->reg);\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_region_delete(struct xrdp_region *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n    pixman_region_fini(self->reg);\n    g_free(self->reg);\n    g_free(self);\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_region_add_rect(struct xrdp_region *self, struct xrdp_rect *rect)\n{\n    struct pixman_region16 lreg;\n\n    pixman_region_init_rect(&lreg, rect->left, rect->top,\n                            rect->right - rect->left,\n                            rect->bottom - rect->top);\n    if (!pixman_region_union(self->reg, self->reg, &lreg))\n    {\n        pixman_region_fini(&lreg);\n        return 1;\n    }\n    pixman_region_fini(&lreg);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_region_subtract_rect(struct xrdp_region *self, struct xrdp_rect *rect)\n{\n    struct pixman_region16 lreg;\n\n    pixman_region_init_rect(&lreg, rect->left, rect->top,\n                            rect->right - rect->left,\n                            rect->bottom - rect->top);\n    if (!pixman_region_subtract(self->reg, self->reg, &lreg))\n    {\n        pixman_region_fini(&lreg);\n        return 1;\n    }\n    pixman_region_fini(&lreg);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_region_intersect_rect(struct xrdp_region *self, struct xrdp_rect *rect)\n{\n    struct pixman_region16 lreg;\n\n    pixman_region_init_rect(&lreg, rect->left, rect->top,\n                            rect->right - rect->left,\n                            rect->bottom - rect->top);\n    if (!pixman_region_intersect(self->reg, self->reg, &lreg))\n    {\n        pixman_region_fini(&lreg);\n        return 1;\n    }\n    pixman_region_fini(&lreg);\n    return 0;\n}\n\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_region_get_rect(struct xrdp_region *self, int index,\n                     struct xrdp_rect *rect)\n{\n    struct pixman_box16 *box;\n    int count;\n\n    box = pixman_region_rectangles(self->reg, &count);\n    if ((box != 0) && (index >= 0) && (index < count))\n    {\n        rect->left = box[index].x1;\n        rect->top = box[index].y1;\n        rect->right = box[index].x2;\n        rect->bottom = box[index].y2;\n        return 0;\n    }\n    return 1;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_region_get_bounds(struct xrdp_region *self, struct xrdp_rect *rect)\n{\n    struct pixman_box16 *box;\n\n    box = pixman_region_extents(self->reg);\n    if (box != 0)\n    {\n        rect->left = box->x1;\n        rect->top = box->y1;\n        rect->right = box->x2;\n        rect->bottom = box->y2;\n        return 0;\n    }\n    return 1;\n}\n\n/*****************************************************************************/\n/* returns boolean */\nint\nxrdp_region_not_empty(struct xrdp_region *self)\n{\n    pixman_bool_t not_empty;\n\n    not_empty = pixman_region_not_empty(self->reg);\n    return not_empty;\n}\n"
  },
  {
    "path": "xrdp/xrdp_tconfig.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Koichiro Iwao\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file xrdp_tconfig.c\n * @brief TOML config loader\n * @author Koichiro Iwao\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"parse.h\"\n#include \"toml.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"xrdp_tconfig.h\"\n#include \"string_calls.h\"\n\n#define TCLOG(log_level, args...) LOG(log_level, \"TConfig: \" args)\n\n#define X264_DEFAULT_PRESET  \"ultrafast\"\n#define X264_DEFAULT_TUNE    \"zerolatency\"\n#define X264_DEFAULT_PROFILE \"main\"\n#define X264_DEFAULT_FPS_NUM 24\n#define X264_DEFAULT_FPS_DEN 1\n#define X264_DEFAULT_THREADS 1 /* not to exhaust CPU threads for 1 user */\n\nconst char *\ntconfig_codec_order_to_str(\n    const struct xrdp_tconfig_gfx_codec_order *codec_order,\n    char *buff,\n    unsigned int bufflen)\n{\n    if (bufflen < (8 * codec_order->codec_count))\n    {\n        snprintf(buff, bufflen, \"???\");\n    }\n    else\n    {\n        unsigned int p = 0;\n        int i;\n        for (i = 0 ; i < codec_order->codec_count; ++i)\n        {\n            if (p > 0)\n            {\n                buff[p++] = ',';\n                buff[p++] = ' ';\n            }\n\n            switch (codec_order->codecs[i])\n            {\n                case XTC_H264:\n                    buff[p++] = 'H';\n                    buff[p++] = '2';\n                    buff[p++] = '6';\n                    buff[p++] = '4';\n                    break;\n\n                case XTC_RFX:\n                    buff[p++] = 'R';\n                    buff[p++] = 'F';\n                    buff[p++] = 'X';\n                    break;\n\n                default:\n                    buff[p++] = '?';\n                    buff[p++] = '?';\n                    buff[p++] = '?';\n            }\n        }\n        buff[p++] = '\\0';\n    }\n\n    return buff;\n}\n\nstatic int\ntconfig_load_gfx_openh264_ct(toml_table_t *tfile, const int connection_type,\n                             struct xrdp_tconfig_gfx_openh264_param *param)\n{\n    TCLOG(LOG_LEVEL_TRACE, \"[OpenH264]\");\n\n    if (connection_type > NUM_CONNECTION_TYPES)\n    {\n        TCLOG(LOG_LEVEL_ERROR, \"[OpenH264] Invalid connection type is given\");\n        return 1;\n    }\n\n    toml_table_t *oh264 = toml_table_in(tfile, \"OpenH264\");\n    if (!oh264)\n    {\n        TCLOG(LOG_LEVEL_WARNING, \"[OpenH264] OpenH264 params are not defined\");\n        return 1;\n    }\n\n    toml_table_t *oh264_ct =\n        toml_table_in(oh264, rdpbcgr_connection_type_names[connection_type]);\n    toml_datum_t datum;\n\n    if (!oh264_ct)\n    {\n        TCLOG(LOG_LEVEL_WARNING, \"OpenH264 params for connection type [%s] is not defined\",\n              rdpbcgr_connection_type_names[connection_type]);\n        return 1;\n    }\n\n    /* EnableFrameSkip */\n    datum = toml_bool_in(oh264_ct, \"EnableFrameSkip\");\n    if (datum.ok)\n    {\n        param[connection_type].EnableFrameSkip = datum.u.b;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[OpenH264.%s] EnableFrameSkip is not set, adopting the default value [0]\",\n              rdpbcgr_connection_type_names[connection_type]);\n        param[connection_type].EnableFrameSkip = 0;\n    }\n\n    /* TargetBitrate */\n    datum = toml_int_in(oh264_ct, \"TargetBitrate\");\n    if (datum.ok)\n    {\n        param[connection_type].TargetBitrate = datum.u.i;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[OpenH264.%s] TargetBitrate is not set, adopting the default value [0]\",\n              rdpbcgr_connection_type_names[connection_type]);\n        param[connection_type].TargetBitrate = 0;\n    }\n\n    /* MaxBitrate */\n    datum = toml_int_in(oh264_ct, \"MaxBitrate\");\n    if (datum.ok)\n    {\n        param[connection_type].MaxBitrate = datum.u.i;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[OpenH264.%s] MaxBitrate is not set, adopting the default value [0]\",\n              rdpbcgr_connection_type_names[connection_type]);\n        param[connection_type].MaxBitrate = 0;\n    }\n\n    /* MaxFrameRate */\n    datum = toml_double_in(oh264_ct, \"MaxFrameRate\");\n    if (datum.ok)\n    {\n        param[connection_type].MaxFrameRate = (float)datum.u.d;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[OpenH264.%s] MaxFrameRate is not set, adopting the default value [0]\",\n              rdpbcgr_connection_type_names[connection_type]);\n        param[connection_type].MaxFrameRate = 0;\n    }\n\n    return 0;\n}\n\nstatic int\ntconfig_load_gfx_x264_ct(toml_table_t *tfile, const int connection_type,\n                         struct xrdp_tconfig_gfx_x264_param *param)\n{\n    TCLOG(LOG_LEVEL_TRACE, \"[x264]\");\n\n    if (connection_type > NUM_CONNECTION_TYPES)\n    {\n        TCLOG(LOG_LEVEL_ERROR, \"[x264] Invalid connection type is given\");\n        return 1;\n    }\n\n    toml_table_t *x264 = toml_table_in(tfile, \"x264\");\n    if (!x264)\n    {\n        TCLOG(LOG_LEVEL_WARNING, \"[x264] x264 params are not defined\");\n        return 1;\n    }\n\n    toml_table_t *x264_ct =\n        toml_table_in(x264, rdpbcgr_connection_type_names[connection_type]);\n    toml_datum_t datum;\n\n    if (!x264_ct)\n    {\n        TCLOG(LOG_LEVEL_WARNING, \"x264 params for connection type [%s] is not defined\",\n              rdpbcgr_connection_type_names[connection_type]);\n        return 1;\n    }\n\n    /* preset */\n    datum = toml_string_in(x264_ct, \"preset\");\n    if (datum.ok)\n    {\n        g_strncpy(param[connection_type].preset,\n                  datum.u.s,\n                  sizeof(param[connection_type].preset) - 1);\n        free(datum.u.s);\n        datum.u.s = NULL;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[x264.%s] preset is not set, adopting the default value \\\"\"\n              X264_DEFAULT_PRESET \"\\\"\",\n              rdpbcgr_connection_type_names[connection_type]);\n        g_strncpy(param[connection_type].preset,\n                  X264_DEFAULT_PRESET,\n                  sizeof(param[connection_type].preset) - 1);\n    }\n\n    /* tune */\n    datum = toml_string_in(x264_ct, \"tune\");\n    if (datum.ok)\n    {\n        g_strncpy(param[connection_type].tune,\n                  datum.u.s,\n                  sizeof(param[connection_type].tune) - 1);\n        free(datum.u.s);\n        datum.u.s = NULL;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[x264.%s] tune is not set, adopting the default value \\\"\"\n              X264_DEFAULT_TUNE\"\\\"\",\n              rdpbcgr_connection_type_names[connection_type]);\n        g_strncpy(param[connection_type].tune,\n                  X264_DEFAULT_TUNE,\n                  sizeof(param[connection_type].tune) - 1);\n    }\n\n    /* profile */\n    datum = toml_string_in(x264_ct, \"profile\");\n    if (datum.ok)\n    {\n        g_strncpy(param[connection_type].profile,\n                  datum.u.s,\n                  sizeof(param[connection_type].profile) - 1);\n        free(datum.u.s);\n        datum.u.s = NULL; // Prevent double-free warning with cppcheck 2.18.0\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[x264.%s] profile is not set, adopting the default value \\\"\"\n              X264_DEFAULT_PROFILE\"\\\"\",\n              rdpbcgr_connection_type_names[connection_type]);\n        g_strncpy(param[connection_type].profile,\n                  X264_DEFAULT_PROFILE,\n                  sizeof(param[connection_type].profile) - 1);\n    }\n\n    /* vbv_max_bitrate */\n    datum = toml_int_in(x264_ct, \"vbv_max_bitrate\");\n    if (datum.ok)\n    {\n        param[connection_type].vbv_max_bitrate = datum.u.i;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[x264.%s] vbv_max_bitrate is not set, adopting the default value [0]\",\n              rdpbcgr_connection_type_names[connection_type]);\n        param[connection_type].vbv_max_bitrate = 0;\n    }\n\n    /* vbv_buffer_size */\n    datum = toml_int_in(x264_ct, \"vbv_buffer_size\");\n    if (datum.ok)\n    {\n        param[connection_type].vbv_buffer_size = datum.u.i;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[x264.%s] vbv_buffer_size is not set, adopting the default value [0]\",\n              rdpbcgr_connection_type_names[connection_type]);\n        param[connection_type].vbv_buffer_size = 0;\n    }\n\n    /* fps_num */\n    datum = toml_int_in(x264_ct, \"fps_num\");\n    if (datum.ok)\n    {\n        param[connection_type].fps_num = datum.u.i;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[x264.%s] fps_num is not set, adopting the default value [%d]\",\n              rdpbcgr_connection_type_names[connection_type],\n              X264_DEFAULT_FPS_NUM);\n        param[connection_type].fps_num = X264_DEFAULT_FPS_NUM;\n    }\n\n    /* fps_den */\n    datum = toml_int_in(x264_ct, \"fps_den\");\n    if (datum.ok)\n    {\n        param[connection_type].fps_den = datum.u.i;\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[x264.%s] fps_den is not set, adopting the default value [%d]\",\n              rdpbcgr_connection_type_names[connection_type],\n              X264_DEFAULT_FPS_DEN);\n        param[connection_type].fps_den = X264_DEFAULT_FPS_DEN;\n    }\n\n    /* threads */\n    datum = toml_int_in(x264_ct, \"threads\");\n    if (datum.ok)\n    {\n        if (datum.u.i >= 0)\n        {\n            param[connection_type].threads = datum.u.i;\n        }\n        else\n        {\n            TCLOG(LOG_LEVEL_WARNING,\n                  \"[x264.%s] an invalid value (< 0) is specified for threads, \"\n                  \"adopting the default value [%d]\",\n                  rdpbcgr_connection_type_names[connection_type],\n                  X264_DEFAULT_THREADS);\n            param[connection_type].threads = X264_DEFAULT_THREADS;\n        }\n    }\n    else if (connection_type == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING,\n              \"[x264.%s] threads is not set, adopting the default value [%d]\",\n              rdpbcgr_connection_type_names[connection_type],\n              X264_DEFAULT_THREADS);\n        param[connection_type].threads = X264_DEFAULT_THREADS;\n    }\n\n    return 0;\n}\n\nstatic int tconfig_load_gfx_h264_encoder(toml_table_t *tfile, struct xrdp_tconfig_gfx *config)\n{\n    TCLOG(LOG_LEVEL_TRACE, \"[codec]\");\n\n    toml_table_t *codec;\n    int valid_encoder_found = 0;\n\n    if ((codec = toml_table_in(tfile, \"codec\")) != NULL)\n    {\n        toml_datum_t h264_encoder = toml_string_in(codec, \"h264_encoder\");\n\n        if (h264_encoder.ok)\n        {\n            if (g_strcasecmp(h264_encoder.u.s, \"x264\") == 0)\n            {\n                TCLOG(LOG_LEVEL_DEBUG, \"[codec] h264_encoder = x264\");\n                valid_encoder_found = 1;\n                config->h264_encoder = XTC_H264_X264;\n            }\n            if (g_strcasecmp(h264_encoder.u.s, \"OpenH264\") == 0)\n            {\n                TCLOG(LOG_LEVEL_DEBUG, \"[codec] h264_encoder = OpenH264\");\n                valid_encoder_found = 1;\n                config->h264_encoder = XTC_H264_OPENH264;\n            }\n\n            free(h264_encoder.u.s);\n        }\n    }\n\n    if (valid_encoder_found == 0)\n    {\n        TCLOG(LOG_LEVEL_WARNING, \"[codec] could not get valid H.264 encoder, \"\n              \"using default \\\"x264\\\"\");\n\n        /* default to x264 */\n        config->h264_encoder = XTC_H264_X264;\n        return 1;\n    }\n\n    return 0;\n}\n\nstatic int tconfig_load_gfx_order(toml_table_t *tfile, struct xrdp_tconfig_gfx *config)\n{\n    char buff[64];\n\n    /*\n     * This config loader is not responsible to check if xrdp is built with\n     * H264/RFX support. Just loads configurations as-is.\n     */\n\n    TCLOG(LOG_LEVEL_TRACE, \"[codec]\");\n\n    int h264_found = 0;\n    int rfx_found = 0;\n\n    config->codec.codec_count = 0;\n\n    toml_table_t *codec;\n    toml_array_t *order;\n\n    if ((codec = toml_table_in(tfile, \"codec\")) != NULL &&\n            (order = toml_array_in(codec, \"order\")) != NULL)\n    {\n        for (int i = 0; ; i++)\n        {\n            toml_datum_t datum = toml_string_at(order, i);\n\n            if (datum.ok)\n            {\n                if (h264_found == 0 &&\n                        (g_strcasecmp(datum.u.s, \"h264\") == 0 ||\n                         g_strcasecmp(datum.u.s, \"h.264\") == 0))\n                {\n                    h264_found = 1;\n                    config->codec.codecs[config->codec.codec_count] = XTC_H264;\n                    ++config->codec.codec_count;\n                }\n                if (rfx_found == 0 &&\n                        g_strcasecmp(datum.u.s, \"rfx\") == 0)\n                {\n                    rfx_found = 1;\n                    config->codec.codecs[config->codec.codec_count] = XTC_RFX;\n                    ++config->codec.codec_count;\n                }\n                free(datum.u.s);\n            }\n            else\n            {\n                break;\n            }\n        }\n    }\n\n    if (h264_found == 0 && rfx_found == 0)\n    {\n        /* prefer H264 if no priority found */\n        config->codec.codecs[0] = XTC_H264;\n        config->codec.codecs[1] = XTC_RFX;\n        config->codec.codec_count = 2;\n\n        TCLOG(LOG_LEVEL_WARNING, \"[codec] could not get GFX codec order, \"\n              \"using default order %s\",\n              tconfig_codec_order_to_str(&config->codec, buff, sizeof(buff)));\n\n        return 1;\n    }\n\n    TCLOG(LOG_LEVEL_DEBUG, \"[codec] %s\",\n          tconfig_codec_order_to_str(&config->codec, buff, sizeof(buff)));\n    return 0;\n}\n\n/**\n * Determines whether a codec is enabled\n * @param co Ordered codec list\n * @param code Code of codec to look for\n * @return boolean\n */\nstatic int\ncodec_enabled(const struct xrdp_tconfig_gfx_codec_order *co,\n              enum xrdp_tconfig_codecs code)\n{\n    for (unsigned short i = 0; i < co->codec_count; ++i)\n    {\n        if (co->codecs[i] == code)\n        {\n            return 1;\n        }\n    }\n\n    return 0;\n}\n\n/**\n * Disables a Codec by removing it from the codec list\n * @param co Ordered codec list\n * @param code Code of codec to remove from list\n *\n * The order of the passed-in codec list is preserved.\n */\nstatic void\ndisable_codec(struct xrdp_tconfig_gfx_codec_order *co,\n              enum xrdp_tconfig_codecs code)\n{\n    unsigned short j = 0;\n    for (unsigned short i = 0; i < co->codec_count; ++i)\n    {\n        if (co->codecs[i] != code)\n        {\n            co->codecs[j++] = co->codecs[i];\n        }\n    }\n    co->codec_count = j;\n}\n\nint\ntconfig_load_gfx(const char *filename, struct xrdp_tconfig_gfx *config)\n{\n    FILE *fp;\n    char errbuf[200];\n    toml_table_t *tfile;\n    int rv = 0;\n\n    /* Default to just RFX support. in case we can't load anything */\n    config->codec.codec_count = 1;\n    config->codec.codecs[0] = XTC_RFX;\n    memset(config->x264_param, 0, sizeof(config->x264_param));\n\n    if ((fp = fopen(filename, \"r\")) == NULL)\n    {\n        TCLOG(LOG_LEVEL_ERROR, \"Error loading GFX config file %s (%s)\",\n              filename, g_get_strerror());\n        return 1;\n    }\n\n    if ((tfile = toml_parse_file(fp, errbuf, sizeof(errbuf))) == NULL)\n    {\n        TCLOG(LOG_LEVEL_ERROR, \"Error in GFX config file %s - %s\", filename, errbuf);\n        fclose(fp);\n        return 1;\n    }\n\n    TCLOG(LOG_LEVEL_INFO, \"Loading GFX config file %s\", filename);\n    fclose(fp);\n\n    /* Load GFX codec order */\n    tconfig_load_gfx_order(tfile, config);\n    /* Load H.264 encoder */\n    tconfig_load_gfx_h264_encoder(tfile, config);\n\n    /* H.264 configuration */\n    if (codec_enabled(&config->codec, XTC_H264))\n    {\n        /* First of all, read the default params */\n        int x264_loaded;\n        int oh264_loaded;\n\n        x264_loaded = tconfig_load_gfx_x264_ct(tfile, 0, config->x264_param);\n        oh264_loaded = tconfig_load_gfx_openh264_ct(tfile, 0, config->openh264_param);\n\n        if (x264_loaded == 0)\n        {\n            /* Copy default params to other connection types, and\n             * then override them */\n            for (int ct = CONNECTION_TYPE_MODEM; ct < NUM_CONNECTION_TYPES;\n                    ct++)\n            {\n                config->x264_param[ct] = config->x264_param[0];\n                tconfig_load_gfx_x264_ct(tfile, ct, config->x264_param);\n            }\n        }\n\n        if (oh264_loaded == 0)\n        {\n            /* Copy default params to other connection types, and\n             * then override them */\n            for (int ct = CONNECTION_TYPE_MODEM; ct < NUM_CONNECTION_TYPES;\n                    ct++)\n            {\n                config->openh264_param[ct] = config->openh264_param[0];\n                tconfig_load_gfx_openh264_ct(tfile, ct, config->openh264_param);\n            }\n        }\n\n        if (x264_loaded != 0 && config->h264_encoder == XTC_H264_X264)\n        {\n            /* We can't get x264 defaults. Disable H.264. */\n            TCLOG(LOG_LEVEL_WARNING, \"x264 is selected as H.264 encoder but \"\n                  \"cannot load default config for x264, disabling H.264\");\n            disable_codec(&config->codec, XTC_H264);\n            rv = 1;\n        }\n\n        if (oh264_loaded != 0 && config->h264_encoder == XTC_H264_OPENH264)\n        {\n            /* We can't get OpenH264 defaults. Disable H.264. */\n            TCLOG(LOG_LEVEL_WARNING, \"OpenH264 is selected as H.264 encoder but \"\n                  \"cannot load default config for OpenH264, disabling H.264\");\n            disable_codec(&config->codec, XTC_H264);\n            rv = 1;\n        }\n    }\n    toml_free(tfile);\n\n    return rv;\n}\n\n"
  },
  {
    "path": "xrdp/xrdp_tconfig.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Koichiro Iwao\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n *\n * @file xrdp_tconfig.c\n * @brief TOML config loader and structures\n * @author Koichiro Iwao\n *\n */\n#ifndef _XRDP_TCONFIG_H_\n#define _XRDP_TCONFIG_H_\n\n#include \"arch.h\"\n\n/* The number of connection types in MS-RDPBCGR 2.2.1.3.2 */\n#define NUM_CONNECTION_TYPES 7\n#define GFX_CONF XRDP_CFG_PATH \"/gfx.toml\"\n\n/* nc stands for new config */\nstruct xrdp_tconfig_gfx_x264_param\n{\n    char preset[16];\n    char tune[16];\n    char profile[16];\n    int vbv_max_bitrate;\n    int vbv_buffer_size;\n    int fps_num;\n    int fps_den;\n    int threads;\n};\n\nstruct xrdp_tconfig_gfx_openh264_param\n{\n    bool_t EnableFrameSkip;\n    int TargetBitrate;\n    int MaxBitrate;\n    float MaxFrameRate;\n};\n\nenum xrdp_tconfig_codecs\n{\n    XTC_H264,\n    XTC_RFX\n};\n\nenum xrdp_tconfig_h264_encoders\n{\n    XTC_H264_X264,\n    XTC_H264_OPENH264\n};\n\nstruct xrdp_tconfig_gfx_codec_order\n{\n    enum xrdp_tconfig_codecs codecs[2];\n    unsigned short codec_count;\n};\n\nstruct xrdp_tconfig_gfx\n{\n    struct xrdp_tconfig_gfx_codec_order codec;\n    enum xrdp_tconfig_h264_encoders h264_encoder;\n    /* store x264 parameters for each connection type */\n    struct xrdp_tconfig_gfx_x264_param x264_param[NUM_CONNECTION_TYPES];\n    struct xrdp_tconfig_gfx_openh264_param\n        openh264_param[NUM_CONNECTION_TYPES];\n};\n\nstatic const char *const rdpbcgr_connection_type_names[] =\n{\n    \"default\", /* for xrdp internal use */\n    \"modem\",\n    \"broadband_low\",\n    \"satellite\",\n    \"broadband_high\",\n    \"wan\",\n    \"lan\",\n    \"autodetect\",\n    0\n};\n\n/**\n * Provide a string representation of a codec order\n *\n * @param codec_order Codec order struct\n * @param buff Buffer for result\n * @param bufflen Length of above\n * @return Convenience copy of buff\n */\nconst char *\ntconfig_codec_order_to_str(\n    const struct xrdp_tconfig_gfx_codec_order *codec_order,\n    char *buff,\n    unsigned int bufflen);\n\n/**\n * Loads the GFX config from the specified file\n *\n * @param filename Name of file to load\n * @param config Struct to receive result\n * @return 0 for success\n *\n * In the event of failure, an error is logged. A minimal\n * useable configuration is always returned\n */\nint\ntconfig_load_gfx(const char *filename, struct xrdp_tconfig_gfx *config);\n\n#endif\n"
  },
  {
    "path": "xrdp/xrdp_types.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * types\n */\n\n#ifndef _XRDP_TYPES_H_\n#define _XRDP_TYPES_H_\n\n#define DEFAULT_STRING_LEN 255\n#define LOG_WINDOW_CHAR_PER_LINE 60\n\n#include \"xrdp_rail.h\"\n#include \"xrdp_constants.h\"\n#include \"fifo.h\"\n#include \"guid.h\"\n#include \"scancode.h\"\n#include \"xrdp_client_info.h\"\n#include \"xrdp_tconfig.h\"\n\n#define MAX_NR_CHANNELS 16\n#define MAX_CHANNEL_NAME 16\n\n/* Code values used in 'xrdp_mm->code=' settings */\n#define XVNC_SESSION_CODE 0\n#define XVNC_UDS_SESSION_CODE 1\n#define XORG_SESSION_CODE 20\n\n/* To check whether touch events has been implemented on session type 'mm' */\n#define XRDP_MM_IMPLEMENTS_TOUCH(mm) \\\n    ((mm)->code == XORG_SESSION_CODE)\n\nstruct source_info;\nstruct list16;\n\n/* lib */\nstruct xrdp_mod\n{\n    int size; /* size of this struct */\n    int version; /* internal version */\n    /* client functions */\n    int (*mod_start)(struct xrdp_mod *v, int w, int h, int bpp);\n    int (*mod_connect)(struct xrdp_mod *v, int fd);\n    int (*mod_event)(struct xrdp_mod *v, int msg, long param1, long param2,\n                     long param3, long param4);\n    int (*mod_signal)(struct xrdp_mod *v);\n    int (*mod_end)(struct xrdp_mod *v);\n    int (*mod_set_param)(struct xrdp_mod *v, const char *name, const char *value);\n    int (*mod_session_change)(struct xrdp_mod *v, int, int);\n    int (*mod_get_wait_objs)(struct xrdp_mod *v, tbus *read_objs, int *rcount,\n                             tbus *write_objs, int *wcount, int *timeout);\n    int (*mod_check_wait_objs)(struct xrdp_mod *v);\n    int (*mod_frame_ack)(struct xrdp_mod *v, int flags, int frame_id);\n    int (*mod_suppress_output)(struct xrdp_mod *v, int suppress,\n                               int left, int top, int right, int bottom);\n    int (*mod_server_monitor_resize)(struct xrdp_mod *v,\n                                     int width, int height,\n                                     int num_monitors,\n                                     const struct monitor_info *monitors,\n                                     int *in_progress);\n    int (*mod_server_monitor_full_invalidate)(struct xrdp_mod *v,\n            int width, int height);\n    int (*mod_server_version_message)(struct xrdp_mod *v);\n    tintptr mod_dumby[100 - 14]; /* align, 100 minus the number of mod\n                                  functions above */\n    /* server functions */\n    int (*server_begin_update)(struct xrdp_mod *v);\n    int (*server_end_update)(struct xrdp_mod *v);\n    int (*server_fill_rect)(struct xrdp_mod *v, int x, int y, int cx, int cy);\n    int (*server_screen_blt)(struct xrdp_mod *v, int x, int y, int cx, int cy,\n                             int srcx, int srcy);\n    int (*server_paint_rect)(struct xrdp_mod *v, int x, int y, int cx, int cy,\n                             char *data, int width, int height,\n                             int srcx, int srcy);\n    int (*server_set_pointer)(struct xrdp_mod *v, int x, int y,\n                              char *data, char *mask);\n    int (*server_palette)(struct xrdp_mod *v, int *palette);\n    int (*server_msg)(struct xrdp_mod *v, const char *msg, int code);\n    /* This one can be assigned directly into the is_term member of\n     * a struct trans */\n    int (*server_is_term)(void);\n    int (*server_set_clip)(struct xrdp_mod *v, int x, int y, int cx, int cy);\n    int (*server_reset_clip)(struct xrdp_mod *v);\n    int (*server_set_fgcolor)(struct xrdp_mod *v, int fgcolor);\n    int (*server_set_bgcolor)(struct xrdp_mod *v, int bgcolor);\n    int (*server_set_opcode)(struct xrdp_mod *v, int opcode);\n    int (*server_set_mixmode)(struct xrdp_mod *v, int mixmode);\n    int (*server_set_brush)(struct xrdp_mod *v, int x_origin, int y_origin,\n                            int style, char *pattern);\n    int (*server_set_pen)(struct xrdp_mod *v, int style,\n                          int width);\n    int (*server_draw_line)(struct xrdp_mod *v, int x1, int y1, int x2, int y2);\n    int (*server_add_char)(struct xrdp_mod *v, int font, int character,\n                           int offset, int baseline,\n                           int width, int height, char *data);\n    int (*server_draw_text)(struct xrdp_mod *v, int font,\n                            int flags, int mixmode, int clip_left, int clip_top,\n                            int clip_right, int clip_bottom,\n                            int box_left, int box_top,\n                            int box_right, int box_bottom,\n                            int x, int y, char *data, int data_len);\n    int (*client_monitor_resize)(struct xrdp_mod *v, int width, int height,\n                                 int num_monitors,\n                                 const struct monitor_info *monitors);\n    int (*server_monitor_resize_done)(struct xrdp_mod *v);\n    int (*server_get_channel_count)(struct xrdp_mod *v);\n    int (*server_query_channel)(struct xrdp_mod *v, int index,\n                                char *channel_name,\n                                int *channel_flags);\n    int (*server_get_channel_id)(struct xrdp_mod *v, const char *name);\n    int (*server_send_to_channel)(struct xrdp_mod *v, int channel_id,\n                                  char *data, int data_len,\n                                  int total_data_len, int flags);\n    int (*server_bell_trigger)(struct xrdp_mod *v);\n    int (*server_chansrv_in_use)(struct xrdp_mod *v);\n    void (*server_init_xkb_layout)(struct xrdp_mod *v,\n                                   struct xrdp_client_info *client_info);\n    /* off screen bitmaps */\n    int (*server_create_os_surface)(struct xrdp_mod *v, int rdpindex,\n                                    int width, int height);\n    int (*server_switch_os_surface)(struct xrdp_mod *v, int rdpindex);\n    int (*server_delete_os_surface)(struct xrdp_mod *v, int rdpindex);\n    int (*server_paint_rect_os)(struct xrdp_mod *mod, int x, int y,\n                                int cx, int cy,\n                                int rdpindex, int srcx, int srcy);\n    int (*server_set_hints)(struct xrdp_mod *mod, int hints, int mask);\n    /* rail */\n    int (*server_window_new_update)(struct xrdp_mod *mod, int window_id,\n                                    struct rail_window_state_order *window_state,\n                                    int flags);\n    int (*server_window_delete)(struct xrdp_mod *mod, int window_id);\n    int (*server_window_icon)(struct xrdp_mod *mod,\n                              int window_id, int cache_entry, int cache_id,\n                              struct rail_icon_info *icon_info,\n                              int flags);\n    int (*server_window_cached_icon)(struct xrdp_mod *mod,\n                                     int window_id, int cache_entry,\n                                     int cache_id, int flags);\n    int (*server_notify_new_update)(struct xrdp_mod *mod,\n                                    int window_id, int notify_id,\n                                    struct rail_notify_state_order *notify_state,\n                                    int flags);\n    int (*server_notify_delete)(struct xrdp_mod *mod, int window_id,\n                                int notify_id);\n    int (*server_monitored_desktop)(struct xrdp_mod *mod,\n                                    struct rail_monitored_desktop_order *mdo,\n                                    int flags);\n    int (*server_set_pointer_ex)(struct xrdp_mod *v, int x, int y, char *data,\n                                 char *mask, int bpp);\n    int (*server_add_char_alpha)(struct xrdp_mod *mod, int font, int character,\n                                 int offset, int baseline,\n                                 int width, int height, char *data);\n\n    int (*server_create_os_surface_bpp)(struct xrdp_mod *v, int rdpindex,\n                                        int width, int height, int bpp);\n    int (*server_paint_rect_bpp)(struct xrdp_mod *v, int x, int y, int cx, int cy,\n                                 char *data, int width, int height,\n                                 int srcx, int srcy, int bpp);\n    int (*server_composite)(struct xrdp_mod *v, int srcidx, int srcformat,\n                            int srcwidth, int srcrepeat, int *srctransform,\n                            int mskflags, int mskidx, int mskformat,\n                            int mskwidth, int mskrepeat, int op,\n                            int srcx, int srcy, int mskx, int msky,\n                            int dstx, int dsty, int width, int height,\n                            int dstformat);\n    int (*server_paint_rects)(struct xrdp_mod *v,\n                              int num_drects, short *drects,\n                              int num_crects, short *crects,\n                              char *data, int width, int height,\n                              int flags, int frame_id);\n    int (*server_session_info)(struct xrdp_mod *v, const char *data,\n                               int data_bytes);\n    int (*server_set_pointer_large)(struct xrdp_mod *v, int x, int y,\n                                    char *data, char *mask, int bpp,\n                                    int width, int height);\n    int (*server_paint_rects_ex)(struct xrdp_mod *v,\n                                 int num_drects, short *drects,\n                                 int num_crects, short *crects,\n                                 char *data, int left, int top,\n                                 int width, int height,\n                                 int flags, int frame_id,\n                                 void *shmem_ptr, int shmem_bytes);\n    int (*server_egfx_cmd)(struct xrdp_mod *v,\n                           char *cmd, int cmd_bytes,\n                           char *data, int data_bytes);\n    int (*server_set_pointer_system)(struct xrdp_mod *v, int pointer_type);\n    int (*server_set_pointer_position)(struct xrdp_mod *v, int x, int y);\n    tintptr server_dumby[100 - 53]; /* align, 100 minus the number of server\n                                     functions above */\n    /* common */\n    tintptr handle; /* pointer to self as int */\n    tintptr wm; /* struct xrdp_wm* */\n    tintptr painter;\n    struct source_info *si;\n};\n\n/**\n * Transform to apply to loaded images\n */\nenum xrdp_bitmap_load_transform\n{\n    XBLT_NONE = 0,\n    XBLT_SCALE,\n    XBLT_ZOOM\n};\n\n/* header for bmp file */\nstruct xrdp_bmp_header\n{\n    int size;\n    int image_width;\n    int image_height;\n    short planes;\n    short bit_count;\n    int compression;\n    int image_size;\n    int x_pels_per_meter;\n    int y_pels_per_meter;\n    int clr_used;\n    int clr_important;\n};\n\nstruct xrdp_palette_item\n{\n    int stamp;\n    int palette[256];\n};\n\nstruct xrdp_bitmap_item\n{\n    int stamp;\n    int lru_index;\n    struct xrdp_bitmap *bitmap;\n};\n\nstruct xrdp_lru_item\n{\n    int next;\n    int prev;\n};\n\nstruct xrdp_os_bitmap_item\n{\n    int id;\n    struct xrdp_bitmap *bitmap;\n};\n\nstruct xrdp_char_item\n{\n    int stamp;\n    struct xrdp_font_char font_item;\n};\n\nstruct xrdp_pointer_item\n{\n    int stamp;\n    int x; /* hotspot */\n    int y;\n    int pad0;\n    char data[96 * 96 * 4];\n    char mask[96 * 96 / 8];\n    int bpp;\n    int width;\n    int height;\n    int pad1;\n};\n\nstruct xrdp_brush_item\n{\n    int stamp;\n    /* expand this to a structure to handle more complicated brushes\n       for now it's 8x8 1bpp brushes only */\n    char pattern[8];\n};\n\n/* moved to xrdp_constants.h\n#define XRDP_BITMAP_CACHE_ENTRIES 2048 */\n\n/* difference caches */\nstruct xrdp_cache\n{\n    struct xrdp_wm *wm; /* owner */\n    struct xrdp_session *session;\n    /* palette */\n    int palette_stamp;\n    struct xrdp_palette_item palette_items[6];\n    /* bitmap */\n    int bitmap_stamp;\n    struct xrdp_bitmap_item bitmap_items[XRDP_MAX_BITMAP_CACHE_ID]\n        [XRDP_MAX_BITMAP_CACHE_IDX];\n\n    /* lru optimize */\n    struct xrdp_lru_item bitmap_lrus[XRDP_MAX_BITMAP_CACHE_ID]\n        [XRDP_MAX_BITMAP_CACHE_IDX];\n    int lru_head[XRDP_MAX_BITMAP_CACHE_ID];\n    int lru_tail[XRDP_MAX_BITMAP_CACHE_ID];\n    int lru_reset[XRDP_MAX_BITMAP_CACHE_ID];\n\n    /* crc optimize */\n    struct list16 crc16[XRDP_MAX_BITMAP_CACHE_ID][64 * 1024];\n\n    int use_bitmap_comp;\n    int cache1_entries;\n    int cache1_size;\n    int cache2_entries;\n    int cache2_size;\n    int cache3_entries;\n    int cache3_size;\n    int bitmap_cache_persist_enable;\n    int bitmap_cache_version;\n    /* font */\n    int char_stamp;\n    struct xrdp_char_item char_items[12][256];\n    /* pointer */\n    int pointer_stamp;\n    struct xrdp_pointer_item pointer_items[32];\n    int pointer_cache_entries;\n    int brush_stamp;\n    struct xrdp_brush_item brush_items[64];\n    struct xrdp_os_bitmap_item os_bitmap_items[2000];\n    struct list *xrdp_os_del_list;\n};\n\n/* defined later */\nstruct xrdp_enc_data;\n\n/**\n * Stages we go through connecting to the session\n */\nenum mm_connect_state\n{\n    MMCS_CONNECT_TO_SESMAN,\n    MMCS_GATEWAY_LOGIN,\n    MMCS_SESSION_LOGIN,\n    MMCS_CREATE_SESSION,\n    MMCS_GET_SESSION_FILE_DESCRIPTORS,\n    MMCS_CONNECT_TO_DISPLAY_SERVER,\n    MMCS_CONNECT_TO_CHANSRV,\n    MMCS_DONE\n};\n\nenum display_resize_state\n{\n    WMRZ_ENCODER_DELETE = 0,\n    WMRZ_EGFX_DELETE_SURFACE,\n    WMRZ_EGFX_CONN_CLOSE,\n    WMRZ_EGFX_CONN_CLOSING,\n    WMRZ_EGFX_CONN_CLOSED,\n    WRMZ_EGFX_DELETE,\n    WMRZ_SERVER_MONITOR_RESIZE,\n    WMRZ_SERVER_MONITOR_MESSAGE_PROCESSING,\n    WMRZ_SERVER_MONITOR_MESSAGE_PROCESSED,\n    WMRZ_XRDP_CORE_RESET,\n    WMRZ_XRDP_CORE_RESET_PROCESSING,\n    WMRZ_XRDP_CORE_RESET_PROCESSED,\n    WMRZ_EGFX_INITIALIZE,\n    WMRZ_EGFX_INITALIZING,\n    WMRZ_EGFX_INITIALIZED,\n    WMRZ_ENCODER_CREATE,\n    WMRZ_SERVER_INVALIDATE,\n    WMRZ_COMPLETE,\n    WMRZ_ERROR\n};\n\n#define XRDP_DISPLAY_RESIZE_STATE_TO_STR(status) \\\n    ((status) == WMRZ_ENCODER_DELETE ? \"WMRZ_ENCODER_DELETE\" : \\\n     (status) == WMRZ_EGFX_DELETE_SURFACE ? \"WMRZ_EGFX_DELETE_SURFACE\" : \\\n     (status) == WMRZ_EGFX_CONN_CLOSE ? \"WMRZ_EGFX_CONN_CLOSE\" : \\\n     (status) == WMRZ_EGFX_CONN_CLOSING ? \"WMRZ_EGFX_CONN_CLOSING\" : \\\n     (status) == WMRZ_EGFX_CONN_CLOSED ? \"WMRZ_EGFX_CONN_CLOSED\" : \\\n     (status) == WRMZ_EGFX_DELETE ? \"WMRZ_EGFX_DELETE\" : \\\n     (status) == WMRZ_SERVER_MONITOR_RESIZE ? \"WMRZ_SERVER_MONITOR_RESIZE\" : \\\n     (status) == WMRZ_SERVER_MONITOR_MESSAGE_PROCESSING ? \\\n     \"WMRZ_SERVER_MONITOR_MESSAGE_PROCESSING\" : \\\n     (status) == WMRZ_SERVER_MONITOR_MESSAGE_PROCESSED ? \\\n     \"WMRZ_SERVER_MONITOR_MESSAGE_PROCESSED\" : \\\n     (status) == WMRZ_XRDP_CORE_RESET ? \"WMRZ_XRDP_CORE_RESET\" : \\\n     (status) == WMRZ_XRDP_CORE_RESET_PROCESSING ? \\\n     \"WMRZ_XRDP_CORE_RESET_PROCESSING\" : \\\n     (status) == WMRZ_XRDP_CORE_RESET_PROCESSED ? \\\n     \"WMRZ_XRDP_CORE_RESET_PROCESSED\" : \\\n     (status) == WMRZ_EGFX_INITIALIZE ? \"WMRZ_EGFX_INITIALIZE\" : \\\n     (status) == WMRZ_EGFX_INITALIZING ? \"WMRZ_EGFX_INITALIZING\" : \\\n     (status) == WMRZ_EGFX_INITIALIZED ? \"WMRZ_EGFX_INITIALIZED\" : \\\n     (status) == WMRZ_ENCODER_CREATE ? \"WMRZ_ENCODER_CREATE\" : \\\n     (status) == WMRZ_SERVER_INVALIDATE ? \"WMRZ_SERVER_INVALIDATE\" : \\\n     (status) == WMRZ_COMPLETE ? \"WMRZ_COMPLETE\" : \\\n     (status) == WMRZ_ERROR ? \"WMRZ_ERROR\" : \\\n     \"unknown\" \\\n    )\n\nenum xrdp_egfx_flags\n{\n    XRDP_EGFX_NONE = 0,\n    XRDP_EGFX_H264 = 1,\n    XRDP_EGFX_RFX_PRO = 2\n};\n\nstruct xrdp_mm\n{\n    struct xrdp_wm *wm; /* owner */\n    enum mm_connect_state connect_state; /* State of connection */\n    int mmcs_expecting_msg; /* Connect state machine is expecting\n                               a message from sesman */\n    /* Other processes we connect to */\n    int use_sesman; /* true if this is a sesman session */\n    int use_gw_login; /* True if we're to login using  a gateway */\n    int use_chansrv; /* true if chansrvport is set in xrdp.ini or using sesman */\n    struct trans *sesman_trans; /* connection to sesman */\n    struct trans *chan_trans; /* connection to chansrv */\n\n    int sesman_display_fd; // Session file descriptor (if use_sesman is set)\n    int sesman_chansrv_fd; // chansrv file descriptor (if use_sesman is set)\n\n    /* We can't delete transports while we're in a callback for that\n     * transport, as this causes trans.c to reference undefined memory.\n     * These flags mark transports as needing to be deleted when\n     * we are definitely not in a transport callback */\n    int delete_sesman_trans;\n\n    struct list *login_names;\n    struct list *login_values;\n    /* mod vars */\n    long mod_handle; /* returned from g_load_library */\n    struct xrdp_mod *(*mod_init)(void);\n    int (*mod_exit)(struct xrdp_mod *);\n    struct xrdp_mod *mod; /* module interface */\n    char display[MAX_DISPLAY_NAME_SIZE];\n    int uid; /* UID for a successful login, -1 otherwise */\n    struct guid guid; /* GUID for the session, or all zeros  */\n    int code; /* 0=Xvnc session, 20=xorg driver mode */\n    struct xrdp_encoder *encoder;\n    int cs2xr_cid_map[256];\n    int xr2cr_cid_map[256];\n    int dynamic_monitor_chanid;\n    struct xrdp_egfx *egfx;\n    int egfx_up;\n    enum xrdp_egfx_flags egfx_flags;\n    int gfx_delay_autologin;\n    int mod_uses_wm_screen_for_gfx;\n    /* Whether a working h.264 library is loaded.\n     * We check this at run-time, so that we can fall-back to GFX if\n     * the H.264 library is installed incorrectly */\n    int libh264_loaded;  /* != 0 => H.264 can be used */\n    /* Resize on-the-fly control */\n    struct display_control_monitor_layout_data *resize_data;\n    struct list *resize_queue;\n    /* wait obj for resize_queue\n     * Only allocated when the queue can be processed */\n    tbus resize_ready;\n    /* Last sync event if a module isn't loaded */\n    int last_sync_saved;\n    int last_sync_key_flags;\n    int last_sync_device_flags;\n    /* Whether the sesman_trans is a CCP trans or not */\n    int sesman_trans_is_ccp;\n};\n\nstruct xrdp_key_info\n{\n    int sym;\n    char32_t chr;\n};\n\nstruct xrdp_keymap\n{\n    // Are the caps lock maps populated?\n    int caps_lock_supported;\n\n    // These arrays are indexed by a return from scancode_to_index()\n    struct xrdp_key_info keys_noshift[SCANCODE_MAX_INDEX + 1];\n    struct xrdp_key_info keys_shift[SCANCODE_MAX_INDEX + 1];\n    struct xrdp_key_info keys_altgr[SCANCODE_MAX_INDEX + 1];\n    struct xrdp_key_info keys_shiftaltgr[SCANCODE_MAX_INDEX + 1];\n    struct xrdp_key_info keys_capslock[SCANCODE_MAX_INDEX + 1];\n    struct xrdp_key_info keys_capslockaltgr[SCANCODE_MAX_INDEX + 1];\n    struct xrdp_key_info keys_shiftcapslock[SCANCODE_MAX_INDEX + 1];\n    struct xrdp_key_info keys_shiftcapslockaltgr[SCANCODE_MAX_INDEX + 1];\n    // NumLock is restricted to a much smaller set of keys\n    struct xrdp_key_info keys_numlock[SCANCODE_MAX_NUMLOCK -\n                                          SCANCODE_MIN_NUMLOCK + 1];\n};\n\n/* the window manager */\n\n/***\n * Window manager login mode states\n *\n * Use with xrdp_wm_set_login_state()\n */\nenum wm_login_state\n{\n    /**\n     * Place the window manager in this state to reset it\n     */\n    WMLS_RESET = 0,\n    /**\n     * In this state, the window manager is waiting for the user to fill\n     * in the login box\n     */\n    WMLS_USER_PROMPT,\n    /**\n     * Place the window manager in this state to request xrdp connects to\n     * the X server, sesman, chansrv etc\n     */\n    WMLS_START_CONNECT,\n    /**\n     * In this state, the window manager is making required connections\n     */\n    WMLS_CONNECT_IN_PROGRESS,\n    /**\n     * Place the window manager in this state to request it finishes.\n     */\n    WMLS_CLEANUP,\n    /**\n     * In this state, the window manager is inactive\n     */\n    WMLS_INACTIVE\n};\n\nstruct xrdp_wm\n{\n    struct xrdp_process *pro_layer; /* owner */\n    struct xrdp_bitmap *screen;\n    struct xrdp_session *session;\n    struct xrdp_painter *painter;\n    struct xrdp_cache *cache;\n    int palette[256];\n    struct xrdp_bitmap *login_window;\n    /* generic colors */\n    int black;\n    int grey;\n    int dark_grey;\n    int blue;\n    int dark_blue;\n    int white;\n    int red;\n    int green;\n    int background;\n    /* dragging info */\n    int dragging;\n    int draggingx;\n    int draggingy;\n    int draggingcx;\n    int draggingcy;\n    int draggingdx;\n    int draggingdy;\n    int draggingorgx;\n    int draggingorgy;\n    int draggingxorstate;\n    struct xrdp_bitmap *dragging_window;\n    /* the down(clicked) button */\n    struct xrdp_bitmap *button_down;\n    /* popup for combo box */\n    struct xrdp_bitmap *popup_wnd;\n    /* focused window */\n    struct xrdp_bitmap *focused_window;\n    /* pointer */\n    int current_pointer;\n    int mouse_x;\n    int mouse_y;\n    /* keyboard info (indexed by a return from scancode_to_index()) */\n    int keys[SCANCODE_MAX_INDEX + 1]; /* key states 0 up 1 down*/\n    int caps_lock;\n    int scroll_lock;\n    int num_lock;\n\n    /* Unicode input */\n    int last_high_surrogate_key_up;\n    int last_high_surrogate_key_down;\n    /* client info */\n    struct xrdp_client_info *client_info;\n    /* session log */\n    struct list *log;\n    struct xrdp_bitmap *log_wnd;\n    enum wm_login_state login_state;\n    tbus login_state_event;\n    struct xrdp_mm *mm;\n    struct xrdp_font *default_font;\n    struct xrdp_keymap keymap;\n    int hide_log_window;\n    int fatal_error_in_log_window;\n    struct xrdp_bitmap *target_surface; /* either screen or os surface */\n    int current_surface_index;\n    int hints;\n    char pamerrortxt[256];\n\n    /* configuration derived from xrdp.ini */\n    struct xrdp_config *xrdp_config;\n    /* configuration derived from gfx.toml */\n    struct xrdp_tconfig_gfx *gfx_config;\n\n    struct xrdp_region *screen_dirty_region;\n    unsigned int last_screen_draw_time;\n};\n\n/* rdp process */\nstruct xrdp_process\n{\n    int status;\n    struct trans *server_trans; /* in tcp server mode */\n    tbus self_term_event;\n    int errinfo; /* Reason for self_term_event being set */\n    struct xrdp_listen *lis_layer; /* owner */\n    struct xrdp_session *session;\n    /* create these when up and running */\n    struct xrdp_wm *wm;\n    //int app_sck;\n    tbus done_event;\n    int session_id;\n};\n\n/* rdp listener */\nstruct xrdp_listen\n{\n    int status;\n    struct list *trans_list; /* list of struct trans* */\n    struct list *process_list;\n    struct list *fork_list;\n    tbus pro_done_event;\n    struct xrdp_startup_params *startup_params;\n};\n\n/* region */\nstruct xrdp_region\n{\n    struct xrdp_wm *wm; /* owner */\n    struct pixman_region16 *reg;\n};\n\n/* painter */\nstruct xrdp_painter\n{\n    int rop;\n    struct xrdp_rect *use_clip; /* nil if not using clip */\n    struct xrdp_rect clip;\n    int clip_children;\n    int bg_color;\n    int fg_color;\n    int mix_mode;\n    struct xrdp_brush brush;\n    struct xrdp_pen pen;\n    struct xrdp_session *session;\n    struct xrdp_wm *wm; /* owner */\n    struct xrdp_font *font;\n    void *painter;\n    struct xrdp_region *dirty_region;\n    int begin_end_level;\n};\n\n/* window or bitmap */\nstruct xrdp_bitmap\n{\n    /* 0 = bitmap 1 = window 2 = screen 3 = button 4 = image 5 = edit\n       6 = label 7 = combo 8 = special */\n    int type;\n    int width;\n    int height;\n    struct xrdp_wm *wm;\n    /* msg 1 = click 2 = mouse move 3 = paint 100 = modal result */\n    /* see messages in constants.h */\n    int (*notify)(struct xrdp_bitmap *wnd, struct xrdp_bitmap *sender,\n                  int msg, long param1, long param2);\n    /* for bitmap */\n    int bpp;\n    int line_size; /* in bytes */\n    int do_not_free_data;\n    char *data;\n    /* for all but bitmap */\n    int left;\n    int top;\n    int pointer;\n    int bg_color;\n    int tab_stop;\n    int id;\n    char *caption1;\n    /* for window or screen */\n    struct xrdp_bitmap *modal_dialog;\n    struct xrdp_bitmap *focused_control;\n    struct xrdp_bitmap *owner; /* window that created us */\n    struct xrdp_bitmap *parent; /* window contained in */\n    /* for modal dialog */\n    struct xrdp_bitmap *default_button; /* button when enter is pressed */\n    struct xrdp_bitmap *esc_button; /* button when esc is pressed */\n    /* list of child windows */\n    struct list *child_list;\n    /* for edit */\n    int edit_pos;\n    char32_t password_char;\n    /* for button or combo */\n    int state; /* for button 0 = normal 1 = down */\n    /* for combo */\n    struct list *string_list;\n    struct list *data_list;\n    /* for combo or popup */\n    int item_index;\n    /* for popup */\n    struct xrdp_bitmap *popped_from;\n    int item_height;\n    /* crc */\n    unsigned int crc32;\n    int crc16;\n};\n\n#define MAX_FONT_CHARS 0x4e00\n#define DEFAULT_FONT_NAME \"sans-10.fv1\"\n#define DEFAULT_FONT_PIXEL_SIZE 16\n#define DEFAULT_FV1_SELECT \"130:sans-18.fv1,0:\" DEFAULT_FONT_NAME\n\n#define DEFAULT_BUTTON_MARGIN_H 12\n#define DEFAULT_BUTTON_MARGIN_W 12\n#define DEFAULT_COMBO_MARGIN_H 6\n#define DEFAULT_EDIT_MARGIN_H  6\n#define DEFAULT_WND_LOGIN_W   425\n#define DEFAULT_WND_LOGIN_H   475\n#define DEFAULT_WND_HELP_W    340\n#define DEFAULT_WND_HELP_H    300\n#define DEFAULT_WND_LOG_W     400\n#define DEFAULT_WND_LOG_H     400\n#define DEFAULT_WND_SPECIAL_H 100\n\n/* font */\nstruct xrdp_font\n{\n    struct xrdp_wm *wm;\n    // Font characters, accessed by Unicode codepoint. The first 32\n    // entries are unused.\n    struct xrdp_font_char chars[MAX_FONT_CHARS];\n    unsigned int char_count; // # elements in above array\n    struct xrdp_font_char *default_char; // Pointer into above array\n    char name[32];\n    int size;\n    /** Body height in pixels */\n    int body_height;\n    int style;\n};\n\n/* module */\nstruct xrdp_mod_data\n{\n    struct list *names;\n    struct list *values;\n};\n\nstruct xrdp_startup_params\n{\n    /* xrdp_ini is not malloc'd and has at least the same lifetime as main() */\n    const char *xrdp_ini;\n    char port[1024];\n    char instance_name[MAX_XRDP_INSTANCE_NAMELEN];\n    int kill;\n    int no_daemon;\n    int help;\n    int version;\n    int fork;\n    int dump_config;\n    int license;\n    int tcp_send_buffer_bytes;\n    int tcp_recv_buffer_bytes;\n    int tcp_nodelay;\n    int tcp_keepalive;\n    int use_vsock;\n    // These should be local users/groups, and so we shouldn't need\n    // a lot of storage for them.\n    char runtime_user[64];\n    char runtime_group[64];\n};\n\n/*\n * For storing xrdp.ini (and other) configuration settings\n */\n\nstruct xrdp_ls_dimensions\n{\n    int  width;               /* window width */\n    int  height;              /* window height */\n    int  logo_width;          /* logo width (optional) */\n    int  logo_height;          /* logo height (optional) */\n    int  logo_x_pos;          /* logo x co-ordinate */\n    int  logo_y_pos;          /* logo y co-ordinate */\n    int  label_x_pos;         /* x pos of labels */\n    int  label_width;         /* width of labels */\n    int  input_x_pos;         /* x pos of text and combo boxes */\n    int  input_width;         /* width of input and combo boxes */\n    int  input_y_pos;         /* y pos for for first label and combo box */\n    int  btn_ok_x_pos;        /* x pos for OK button */\n    int  btn_ok_y_pos;        /* y pos for OK button */\n    int  btn_ok_width;        /* width of OK button */\n    int  btn_ok_height;       /* height of OK button */\n    int  btn_cancel_x_pos;    /* x pos for Cancel button */\n    int  btn_cancel_y_pos;    /* y pos for Cancel button */\n    int  btn_cancel_width;    /* width of Cancel button */\n    int  btn_cancel_height;   /* height of Cancel button */\n    int default_btn_height;   /* Default button height (e.g. OK on login box) */\n    int log_wnd_width;        /* Width of log window */\n    int log_wnd_height;       /* Height of log window */\n    int edit_height;          /* Height of an edit box */\n    int combo_height;         /* Height of a combo box */\n    int help_wnd_width;        /* Width of login help window */\n    int help_wnd_height;       /* Height of login help window */\n};\n\nstruct xrdp_cfg_globals\n{\n    int  ini_version;            /* xrdp.ini file version number */\n    int  use_bitmap_cache;\n    int  use_bitmap_compression;\n    int  port;\n    int  crypt_level;            /* low=1, medium=2, high=3 */\n    int  allow_channels;\n    int  max_bpp;\n    int  fork;\n    int  tcp_nodelay;\n    int  tcp_keepalive;\n    int  tcp_send_buffer_bytes;\n    int  tcp_recv_buffer_bytes;\n    char autorun[256];\n    int  hidelogwindow;\n    int  require_credentials;\n    int  bulk_compression;\n    int  new_cursors;\n    int  nego_sec_layer;\n    int  allow_multimon;\n    int  enable_token_login;\n\n    /* colors */\n\n    int  grey;\n    int  black;\n    int  dark_grey;\n    int  blue;\n    int  dark_blue;\n    int  white;\n    int  red;\n    int  green;\n    int  background;\n\n    /* login screen */\n    unsigned int  default_dpi;   /* Default DPI to use if nothing from client */\n    char fv1_select[256];        /* Selection string for fv1 font */\n    int  ls_top_window_bg_color; /* top level window background color */\n    int  ls_bg_color;            /* background color */\n    char ls_background_image[256];  /* background image file name */\n    /* transform to apply to background image */\n    enum xrdp_bitmap_load_transform ls_background_transform;\n    char ls_logo_filename[256];  /* logo filename */\n    /* transform to apply to logo */\n    enum xrdp_bitmap_load_transform ls_logo_transform;\n    char ls_title[256];          /* loginscreen window title */\n    /* Login screen dimensions, unscaled (from config) */\n    struct xrdp_ls_dimensions ls_unscaled;\n    /* Login screen dimensions, scaled (after font is loaded) */\n    struct xrdp_ls_dimensions ls_scaled;\n};\n\nstruct xrdp_cfg_logging\n{\n\n};\n\nstruct xrdp_cfg_channels\n{\n\n};\n\nstruct xrdp_config\n{\n    struct xrdp_cfg_globals   cfg_globals;\n    struct xrdp_cfg_logging   cfg_logging;\n    struct xrdp_cfg_channels  cfg_channels;\n};\n\n#endif\n"
  },
  {
    "path": "xrdp/xrdp_wm.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * simple window manager\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdarg.h>\n#include <stdio.h>\n#include \"xrdp.h\"\n#include \"ms-rdpbcgr.h\"\n#include \"log.h\"\n#include \"string_calls.h\"\n#include \"unicode_defines.h\"\n\n/*****************************************************************************/\nstatic void\nxrdp_wm_load_channel_config(struct xrdp_wm *self)\n{\n    struct list *names = list_create();\n    names->auto_free = 1;\n    struct list *values = list_create();\n    values->auto_free = 1;\n\n    if (file_by_name_read_section(self->session->xrdp_ini,\n                                  \"Channels\", names, values) == 0)\n    {\n        int chan_id;\n        int chan_count = libxrdp_get_channel_count(self->session);\n        const char *disabled_str = NULL;\n\n        for (chan_id = 0 ; chan_id < chan_count ; ++chan_id)\n        {\n            char chan_name[CHANNEL_NAME_LEN + 1];\n            if (libxrdp_query_channel(self->session, chan_id, chan_name,\n                                      NULL) == 0)\n            {\n                int disabled = 1; /* Channels disabled if not found */\n                int found = 0;\n                int index;\n\n                for (index = 0; index < names->count; index++)\n                {\n                    const char *q = (const char *)list_get_item(names, index);\n                    const char *r = (const char *)list_get_item(values, index);\n                    if (g_strcasecmp(q, chan_name) == 0)\n                    {\n                        found = 1;\n                        disabled = !g_text2bool(r);\n                        break;\n                    }\n                }\n                if (!found)\n                {\n                    LOG(LOG_LEVEL_WARNING,\n                        \"Static channel '%s' from the client\"\n                        \" is not named in the [Channels] section\",\n                        chan_name);\n                }\n                disabled_str = (disabled) ? \"disabled\" : \"enabled\";\n                LOG(LOG_LEVEL_DEBUG, \"xrdp_wm_load_channel_config: \"\n                    \"channel %s channel id %d is %s\",\n                    chan_name, chan_id, disabled_str);\n\n                libxrdp_disable_channel(self->session, chan_id, disabled);\n            }\n        }\n    }\n    list_delete(names);\n    list_delete(values);\n}\n\n/*****************************************************************************/\nstruct xrdp_wm *\nxrdp_wm_create(struct xrdp_process *owner,\n               struct xrdp_client_info *client_info)\n{\n    struct xrdp_wm *self = (struct xrdp_wm *)NULL;\n    char event_name[256];\n    int pid = 0;\n\n    /* initialize (zero out) local variables: */\n    g_memset(event_name, 0, sizeof(char) * 256);\n\n    self = (struct xrdp_wm *)g_malloc(sizeof(struct xrdp_wm), 1);\n    self->client_info = client_info;\n    self->screen = xrdp_bitmap_create(client_info->display_sizes.session_width,\n                                      client_info->display_sizes.session_height,\n                                      client_info->bpp,\n                                      WND_TYPE_SCREEN, self);\n    self->screen->wm = self;\n    self->pro_layer = owner;\n    self->session = owner->session;\n    pid = g_getpid();\n    g_snprintf(event_name, 255, \"xrdp_%8.8x_wm_login_state_event_%8.8x\",\n               pid, owner->session_id);\n    LOG(LOG_LEVEL_DEBUG, \"%s\", event_name);\n    self->login_state_event = g_create_wait_obj(event_name);\n    self->painter = xrdp_painter_create(self, self->session);\n    self->cache = xrdp_cache_create(self, self->session, self->client_info);\n    self->log = list_create();\n    self->log->auto_free = 1;\n    self->mm = xrdp_mm_create(self);\n    /* this will use built in keymap or load from file */\n    if (client_info->xrdp_keyboard_overrides.layout > 0 &&\n            client_info->xrdp_keyboard_overrides.layout != client_info->keylayout)\n    {\n        LOG(LOG_LEVEL_INFO, \"overrode keylayout %08X with %08X\",\n            client_info->keylayout,\n            client_info->xrdp_keyboard_overrides.layout);\n        get_keymaps(client_info->xrdp_keyboard_overrides.layout,\n                    &(self->keymap));\n    }\n    else\n    {\n        get_keymaps(client_info->keylayout, &(self->keymap));\n    }\n    xrdp_wm_set_login_state(self, WMLS_RESET);\n    self->target_surface = self->screen;\n    self->current_surface_index = 0xffff; /* screen */\n\n    /* to store configuration from xrdp.ini, gfx.toml */\n    self->xrdp_config = g_new0(struct xrdp_config, 1);\n    self->gfx_config = g_new0(struct xrdp_tconfig_gfx, 1);\n\n    /* Load the channel config so libxrdp can check whether\n       drdynvc is enabled or not */\n    xrdp_wm_load_channel_config(self);\n\n    // Start drdynvc if available.\n    if (libxrdp_drdynvc_start(self->session) == 0)\n    {\n        // drdynvc is started. callback() will\n        // be notified when capabilities are received.\n    }\n    else if (self->client_info->gfx)\n    {\n        LOG(LOG_LEVEL_WARNING, \"Disabling GFX as '\"\n            DRDYNVC_SVC_CHANNEL_NAME \"' isn't available\");\n        self->client_info->gfx = 0;\n    }\n\n    return self;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_wm_delete(struct xrdp_wm *self)\n{\n    if (self == 0)\n    {\n        return;\n    }\n\n    xrdp_region_delete(self->screen_dirty_region);\n    xrdp_mm_delete(self->mm);\n    xrdp_cache_delete(self->cache);\n    xrdp_painter_delete(self->painter);\n    xrdp_bitmap_delete(self->screen);\n    /* free the log */\n    list_delete(self->log);\n    /* free default font */\n    xrdp_font_delete(self->default_font);\n    g_delete_wait_obj(self->login_state_event);\n\n    if (self->xrdp_config)\n    {\n        g_free(self->xrdp_config);\n    }\n\n    if (self->gfx_config)\n    {\n        g_free(self->gfx_config);\n    }\n\n    /* free self */\n    g_free(self);\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_send_palette(struct xrdp_wm *self)\n{\n    return libxrdp_send_palette(self->session, self->palette);\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_send_bell(struct xrdp_wm *self)\n{\n    return libxrdp_send_bell(self->session);\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_send_bitmap(struct xrdp_wm *self, struct xrdp_bitmap *bitmap,\n                    int x, int y, int cx, int cy)\n{\n    return libxrdp_send_bitmap(self->session, bitmap->width, bitmap->height,\n                               bitmap->bpp, bitmap->data, x, y, cx, cy);\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_set_focused(struct xrdp_wm *self, struct xrdp_bitmap *wnd)\n{\n    struct xrdp_bitmap *focus_out_control;\n    struct xrdp_bitmap *focus_in_control;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (self->focused_window == wnd)\n    {\n        return 0;\n    }\n\n    focus_out_control = 0;\n    focus_in_control = 0;\n\n    if (self->focused_window != 0)\n    {\n        xrdp_bitmap_set_focus(self->focused_window, 0);\n        focus_out_control = self->focused_window->focused_control;\n    }\n\n    self->focused_window = wnd;\n\n    if (self->focused_window != 0)\n    {\n        xrdp_bitmap_set_focus(self->focused_window, 1);\n        focus_in_control = self->focused_window->focused_control;\n    }\n\n    xrdp_bitmap_invalidate(focus_out_control, 0);\n    xrdp_bitmap_invalidate(focus_in_control, 0);\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nxrdp_wm_get_pixel(char *data, int x, int y, int width, int bpp)\n{\n    int start;\n    int shift;\n\n    if (bpp == 1)\n    {\n        width = (width + 7) / 8;\n        start = (y * width) + x / 8;\n        shift = x % 8;\n        return (data[start] & (0x80 >> shift)) != 0;\n    }\n    else if (bpp == 4)\n    {\n        width = (width + 1) / 2;\n        start = y * width + x / 2;\n        shift = x % 2;\n\n        if (shift == 0)\n        {\n            return (data[start] & 0xf0) >> 4;\n        }\n        else\n        {\n            return data[start] & 0x0f;\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_pointer(struct xrdp_wm *self, char *data, char *mask, int x, int y,\n                int bpp, int width, int height)\n{\n    int bytes;\n    struct xrdp_pointer_item *pointer_item;\n\n    if (bpp == 0)\n    {\n        bpp = 24;\n    }\n    bytes = ((bpp + 7) / 8) * width * height;\n    pointer_item = g_new0(struct xrdp_pointer_item, 1);\n    pointer_item->x = x;\n    pointer_item->y = y;\n    pointer_item->bpp = bpp;\n    pointer_item->width = width;\n    pointer_item->height = height;\n    g_memcpy(pointer_item->data, data, bytes);\n    g_memcpy(pointer_item->mask, mask, width * height / 8);\n    self->screen->pointer = xrdp_cache_add_pointer(self->cache, pointer_item);\n    g_free(pointer_item);\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nstatic int\nxrdp_wm_load_pointer(struct xrdp_wm *self, char *file_name, char *data,\n                     char *mask, int *x, int *y)\n{\n    int fd;\n    int len;\n    int bpp;\n    int w;\n    int h;\n    int i;\n    int j;\n    int pixel;\n    int palette[16];\n    struct stream *fs;\n\n    if (!g_file_exist(file_name))\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_wm_load_pointer: error pointer file [%s] does not exist\",\n            file_name);\n        return 1;\n    }\n\n    make_stream(fs);\n    init_stream(fs, 8192);\n    fd = g_file_open_ro(file_name);\n\n    if (fd < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_wm_load_pointer: error loading pointer from file [%s]\",\n            file_name);\n        xstream_free(fs);\n        return 1;\n    }\n\n    len = g_file_read(fd, fs->data, 8192);\n    g_file_close(fd);\n    if (len <= 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_wm_load_pointer: read error from file [%s]\",\n            file_name);\n        xstream_free(fs);\n        return 1;\n    }\n    fs->end = fs->data + len;\n    in_uint8s(fs, 6);\n    in_uint8(fs, w);\n    in_uint8(fs, h);\n    in_uint8s(fs, 2);\n    in_uint16_le(fs, *x);\n    in_uint16_le(fs, *y);\n    in_uint8s(fs, 22);\n    in_uint8(fs, bpp);\n    in_uint8s(fs, 25);\n\n    if (w == 32 && h == 32)\n    {\n        if (bpp == 1)\n        {\n            for (i = 0; i < 2; i++)\n            {\n                in_uint32_le(fs, pixel);\n                palette[i] = pixel;\n            }\n            for (i = 0; i < 32; i++)\n            {\n                for (j = 0; j < 32; j++)\n                {\n                    pixel = palette[xrdp_wm_get_pixel(fs->p, j, i, 32, 1)];\n                    *data = pixel;\n                    data++;\n                    *data = pixel >> 8;\n                    data++;\n                    *data = pixel >> 16;\n                    data++;\n                }\n            }\n\n            in_uint8s(fs, 128);\n        }\n        else if (bpp == 4)\n        {\n            for (i = 0; i < 16; i++)\n            {\n                in_uint32_le(fs, pixel);\n                palette[i] = pixel;\n            }\n            for (i = 0; i < 32; i++)\n            {\n                for (j = 0; j < 32; j++)\n                {\n                    pixel = palette[xrdp_wm_get_pixel(fs->p, j, i, 32, 1)];\n                    *data = pixel;\n                    data++;\n                    *data = pixel >> 8;\n                    data++;\n                    *data = pixel >> 16;\n                    data++;\n                }\n            }\n\n            in_uint8s(fs, 512);\n        }\n\n        g_memcpy(mask, fs->p, 128); /* mask */\n    }\n\n    free_stream(fs);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_send_pointer_system(struct xrdp_wm *self, int pointer_type)\n{\n    return libxrdp_send_pointer_system(self->session, pointer_type);\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_send_pointer_position(struct xrdp_wm *self, int x, int y)\n{\n    return libxrdp_send_pointer_position(self->session, x, y);\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_send_pointer(struct xrdp_wm *self, int cache_idx,\n                     char *data, char *mask, int x, int y, int bpp,\n                     int width, int height)\n{\n    return libxrdp_send_pointer(self->session, cache_idx, data, mask,\n                                x, y, bpp, width, height);\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_set_pointer(struct xrdp_wm *self, int cache_idx)\n{\n    return libxrdp_set_pointer(self->session, cache_idx);\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_load_static_colors_plus(struct xrdp_wm *self, char *autorun_name)\n{\n    int bindex;\n    int gindex;\n    int rindex;\n\n    int fd;\n    int index;\n    char *val;\n    struct list *names;\n    struct list *values;\n\n    if (autorun_name != 0)\n    {\n        autorun_name[0] = 0;\n    }\n\n    /* initialize with defaults */\n    self->black      = HCOLOR(self->screen->bpp, 0x000000);\n    self->grey       = HCOLOR(self->screen->bpp, 0xc0c0c0);\n    self->dark_grey  = HCOLOR(self->screen->bpp, 0x808080);\n    self->blue       = HCOLOR(self->screen->bpp, 0x0000ff);\n    self->dark_blue  = HCOLOR(self->screen->bpp, 0x00007f);\n    self->white      = HCOLOR(self->screen->bpp, 0xffffff);\n    self->red        = HCOLOR(self->screen->bpp, 0xff0000);\n    self->green      = HCOLOR(self->screen->bpp, 0x00ff00);\n    self->background = HCOLOR(self->screen->bpp, 0x000000);\n\n    /* now load them from the globals in xrdp.ini if defined */\n    fd = g_file_open_ro(self->session->xrdp_ini);\n\n    if (fd >= 0)\n    {\n        names = list_create();\n        names->auto_free = 1;\n        values = list_create();\n        values->auto_free = 1;\n\n        if (file_read_section(fd, \"globals\", names, values) == 0)\n        {\n            for (index = 0; index < names->count; index++)\n            {\n                val = (char *)list_get_item(names, index);\n\n                if (val != 0)\n                {\n                    if (g_strcasecmp(val, \"black\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->black = HCOLOR(self->screen->bpp, g_htoi(val));\n                    }\n                    else if (g_strcasecmp(val, \"grey\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->grey = HCOLOR(self->screen->bpp, g_htoi(val));\n                    }\n                    else if (g_strcasecmp(val, \"dark_grey\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->dark_grey = HCOLOR(self->screen->bpp, g_htoi(val));\n                    }\n                    else if (g_strcasecmp(val, \"blue\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->blue = HCOLOR(self->screen->bpp, g_htoi(val));\n                    }\n                    else if (g_strcasecmp(val, \"dark_blue\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->dark_blue = HCOLOR(self->screen->bpp, g_htoi(val));\n                    }\n                    else if (g_strcasecmp(val, \"white\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->white = HCOLOR(self->screen->bpp, g_htoi(val));\n                    }\n                    else if (g_strcasecmp(val, \"red\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->red = HCOLOR(self->screen->bpp, g_htoi(val));\n                    }\n                    else if (g_strcasecmp(val, \"green\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->green = HCOLOR(self->screen->bpp, g_htoi(val));\n                    }\n                    else if (g_strcasecmp(val, \"background\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->background = HCOLOR(self->screen->bpp, g_htoi(val));\n                    }\n                    else if (g_strcasecmp(val, \"autorun\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n\n                        if (autorun_name != 0)\n                        {\n                            g_strncpy(autorun_name, val, 255);\n                        }\n                    }\n                    else if (g_strcasecmp(val, \"hidelogwindow\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        self->hide_log_window = g_text2bool(val);\n                    }\n                    else if (g_strcasecmp(val, \"pamerrortxt\") == 0)\n                    {\n                        val = (char *)list_get_item(values, index);\n                        g_strncpy(self->pamerrortxt, val, 255);\n                    }\n                }\n            }\n        }\n\n        list_delete(names);\n        list_delete(values);\n        g_file_close(fd);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_WARNING, \"xrdp_wm_load_static_colors: Could not read xrdp.ini file %s\", self->session->xrdp_ini);\n    }\n\n    if (self->screen->bpp == 8)\n    {\n        /* rgb332 */\n        for (bindex = 0; bindex < 4; bindex++)\n        {\n            for (gindex = 0; gindex < 8; gindex++)\n            {\n                for (rindex = 0; rindex < 8; rindex++)\n                {\n                    self->palette[(bindex << 6) | (gindex << 3) | rindex] =\n                        (((rindex << 5) | (rindex << 2) | (rindex >> 1)) << 16) |\n                        (((gindex << 5) | (gindex << 2) | (gindex >> 1)) << 8) |\n                        ((bindex << 6) | (bindex << 4) | (bindex << 2) | (bindex));\n                }\n            }\n        }\n\n        xrdp_wm_send_palette(self);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns error */\nint\nxrdp_wm_load_static_pointers(struct xrdp_wm *self)\n{\n    struct xrdp_pointer_item pointer_item;\n    char file_path[256];\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"sending cursor\");\n    g_snprintf(file_path, 255, \"%s/cursor1.cur\", XRDP_SHARE_PATH);\n    g_memset(&pointer_item, 0, sizeof(pointer_item));\n    xrdp_wm_load_pointer(self, file_path, pointer_item.data,\n                         pointer_item.mask, &pointer_item.x, &pointer_item.y);\n    xrdp_cache_add_pointer_static(self->cache, &pointer_item, 1);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"sending cursor\");\n    g_snprintf(file_path, 255, \"%s/cursor0.cur\", XRDP_SHARE_PATH);\n    g_memset(&pointer_item, 0, sizeof(pointer_item));\n    xrdp_wm_load_pointer(self, file_path, pointer_item.data,\n                         pointer_item.mask, &pointer_item.x, &pointer_item.y);\n    xrdp_cache_add_pointer_static(self->cache, &pointer_item, 0);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_init(struct xrdp_wm *self)\n{\n    int fd;\n    int index;\n    const char *q;\n    const char *r;\n    char param[256];\n    char default_section_name[256];\n    char section_name[256];\n    char autorun_name[256];\n    int dpi;\n\n    LOG(LOG_LEVEL_DEBUG, \"in xrdp_wm_init: \");\n\n    load_xrdp_config(self->xrdp_config, self->session->xrdp_ini,\n                     self->screen->bpp);\n\n    tconfig_load_gfx(XRDP_CFG_PATH \"/gfx.toml\", self->gfx_config);\n\n    /* Remove a font loaded on the previous config */\n    xrdp_font_delete(self->default_font);\n    self->painter->font = NULL; /* May be set to the default_font */\n\n    /* Load the font */\n    dpi = xrdp_login_wnd_get_monitor_dpi(self);\n    self->default_font = xrdp_font_create(self, dpi);\n\n    /* Scale the login screen values */\n    xrdp_login_wnd_scale_config_values(self);\n\n    xrdp_wm_load_static_colors_plus(self, autorun_name);\n    xrdp_wm_load_static_pointers(self);\n    self->screen->bg_color = self->xrdp_config->cfg_globals.ls_top_window_bg_color;\n\n    if (self->session->client_info->rdp_autologin)\n    {\n        /*\n         * NOTE: this should eventually be accessed from self->xrdp_config\n         */\n\n        fd = g_file_open_ro(self->session->xrdp_ini);\n        if (fd != -1)\n        {\n            struct list *names = list_create();\n            names->auto_free = 1;\n            struct list *values = list_create();\n            values->auto_free = 1;\n\n            /* pick up the first section name except for 'globals', 'Logging', 'channels'\n             * in xrdp.ini and use it as default section name */\n            file_read_sections(fd, names);\n            default_section_name[0] = '\\0';\n            for (index = 0; index < names->count; index++)\n            {\n                q = (const char *)list_get_item(names, index);\n                if ((g_strncasecmp(\"globals\", q, 8) != 0) &&\n                        (g_strncasecmp(\"Logging\", q, 8) != 0) &&\n                        (g_strncasecmp(\"LoggingPerLogger\", q, 17) != 0) &&\n                        (g_strncasecmp(\"channels\", q, 9) != 0))\n                {\n                    g_strncpy(default_section_name, q, 255);\n                    break;\n                }\n            }\n\n            /* look for module name to be loaded */\n            if (autorun_name[0] != 0)\n            {\n                /* if autorun is configured in xrdp.ini, we enforce that module to be loaded */\n                g_strncpy(section_name, autorun_name, 255);\n            }\n            else if (self->session->client_info->domain[0] != '\\0' &&\n                     self->session->client_info->domain[0] != '_')\n            {\n                /* domain names that starts with '_' are reserved for IP/DNS to\n                 * simplify for the user in a proxy setup */\n\n                /* we use the domain name as the module name to be loaded */\n                g_strncpy(section_name,\n                          self->session->client_info->domain, 255);\n            }\n            else\n            {\n                /* if no domain is given, and autorun is not specified in xrdp.ini\n                 * use default_section_name as section_name  */\n                g_strncpy(section_name, default_section_name, 255);\n            }\n\n            list_clear(names);\n\n            /* if given section name doesn't match any sections configured\n             * in xrdp.ini, fallback to default_section_name */\n            if (file_read_section(fd, section_name, names, values) != 0)\n            {\n                LOG(LOG_LEVEL_INFO,\n                    \"Module \\\"%s\\\" specified by %s from %s \"\n                    \"is not configured. Using \\\"%s\\\" instead.\",\n                    section_name,\n                    self->session->client_info->username,\n                    self->session->client_info->client_description,\n                    default_section_name);\n                list_clear(names);\n                list_clear(values);\n\n                g_strncpy(section_name, default_section_name, 255);\n            }\n\n            /* look for the required module in xrdp.ini, fetch its parameters */\n            if (file_read_section(fd, section_name, names, values) == 0)\n            {\n                for (index = 0; index < names->count; index++)\n                {\n                    q = (const char *)list_get_item(names, index);\n                    r = (const char *)list_get_item(values, index);\n\n                    if (g_strncasecmp(\"password\", q, 255) == 0)\n                    {\n                        /* if the password has been asked for by the module, use what the\n                           client says.\n                           if the password has been manually set in the config, use that\n                           instead of what the client says. */\n                        if (g_strncmp(\"ask\", r, 3) == 0)\n                        {\n                            r = self->session->client_info->password;\n                        }\n                    }\n                    else if (g_strncasecmp(\"username\", q, 255) == 0)\n                    {\n                        /* if the username has been asked for by the module, use what the\n                           client says.\n                           if the username has been manually set in the config, use that\n                           instead of what the client says. */\n                        if (g_strncmp(\"ask\", r, 3) == 0)\n                        {\n                            r = self->session->client_info->username;\n                        }\n                    }\n                    else if (g_strncasecmp(\"ip\", q, 255) == 0)\n                    {\n                        /* if the ip has been asked for by the module, use what the\n                         client says (target ip should be in 'domain' field, when starting with \"_\")\n                         if the ip has been manually set in the config, use that\n                         instead of what the client says. */\n                        if (g_strncmp(\"ask\", r, 3) == 0)\n                        {\n                            if (self->session->client_info->domain[0] == '_')\n                            {\n                                g_strncpy(param, &self->session->client_info->domain[1], 255);\n                                r = param;\n                            }\n\n                        }\n                    }\n                    else if (g_strncasecmp(\"port\", q, 255) == 0)\n                    {\n                        if (g_strncmp(\"ask3389\", r, 7) == 0)\n                        {\n                            r = \"3389\"; /* use default */\n                        }\n                    }\n\n                    list_add_strdup(self->mm->login_names, q);\n                    list_add_strdup(self->mm->login_values, r);\n                }\n\n                if (self->session->client_info->gfx && !self->mm->egfx_up)\n                {\n                    /* gfx session but have not recieved caps advertise yet,\n                       set flag so we will connect to backend later */\n                    self->mm->gfx_delay_autologin = 1;\n                }\n                else\n                {\n                    /*\n                    * Skip the login box and go straight to the connection phase\n                    */\n                    xrdp_wm_set_login_state(self, WMLS_START_CONNECT);\n                }\n            }\n            else\n            {\n                /* Hopefully, we never reach here. */\n                LOG(LOG_LEVEL_WARNING,\n                    \"Control should never reach %s:%d\", __FILE__, __LINE__);\n            }\n\n            list_delete(names);\n            list_delete(values);\n            g_file_close(fd);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING,\n                \"xrdp_wm_init: Could not read xrdp.ini file %s\",\n                self->session->xrdp_ini);\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_DEBUG, \"   xrdp_wm_init: no autologin / auto run detected, draw login window\");\n        xrdp_login_wnd_create(self);\n        /* clear screen */\n        xrdp_bitmap_invalidate(self->screen, 0);\n        xrdp_wm_set_focused(self, self->login_window);\n        xrdp_wm_set_login_state(self, WMLS_USER_PROMPT);\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"out xrdp_wm_init: \");\n    return 0;\n}\n\n/*****************************************************************************/\n/* returns the number for rects visible for an area relative to a drawable */\n/* putting the rects in region */\nint\nxrdp_wm_get_vis_region(struct xrdp_wm *self, struct xrdp_bitmap *bitmap,\n                       int x, int y, int cx, int cy,\n                       struct xrdp_region *region, int clip_children)\n{\n    int i;\n    struct xrdp_bitmap *p;\n    struct xrdp_rect a;\n    struct xrdp_rect b;\n\n    /* area we are drawing */\n    MAKERECT(a, bitmap->left + x, bitmap->top + y, cx, cy);\n    p = bitmap->parent;\n\n    while (p != 0)\n    {\n        RECTOFFSET(a, p->left, p->top);\n        p = p->parent;\n    }\n\n    a.left = MAX(self->screen->left, a.left);\n    a.top = MAX(self->screen->top, a.top);\n    a.right = MIN(self->screen->left + self->screen->width, a.right);\n    a.bottom = MIN(self->screen->top + self->screen->height, a.bottom);\n    xrdp_region_add_rect(region, &a);\n\n    if (clip_children)\n    {\n        /* loop through all windows in z order */\n        for (i = 0; i < self->screen->child_list->count; i++)\n        {\n            p = (struct xrdp_bitmap *)list_get_item(self->screen->child_list, i);\n\n            if (p == bitmap || p == bitmap->parent)\n            {\n                return 0;\n            }\n\n            MAKERECT(b, p->left, p->top, p->width, p->height);\n            xrdp_region_subtract_rect(region, &b);\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* return the window at x, y on the screen */\nstatic struct xrdp_bitmap *\nxrdp_wm_at_pos(struct xrdp_bitmap *wnd, int x, int y,\n               struct xrdp_bitmap **wnd1)\n{\n    int i;\n    struct xrdp_bitmap *p;\n    struct xrdp_bitmap *q;\n\n    /* loop through all windows in z order */\n    for (i = 0; i < wnd->child_list->count; i++)\n    {\n        p = (struct xrdp_bitmap *)list_get_item(wnd->child_list, i);\n\n        if (x >= p->left && y >= p->top && x < p->left + p->width &&\n                y < p->top + p->height)\n        {\n            if (wnd1 != 0)\n            {\n                *wnd1 = p;\n            }\n\n            q = xrdp_wm_at_pos(p, x - p->left, y - p->top, 0);\n\n            if (q == 0)\n            {\n                return p;\n            }\n            else\n            {\n                return q;\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_xor_pat(struct xrdp_wm *self, int x, int y, int cx, int cy)\n{\n    self->painter->clip_children = 0;\n    self->painter->rop = 0x5a;\n    xrdp_painter_begin_update(self->painter);\n    self->painter->use_clip = 0;\n    self->painter->mix_mode = 1;\n    self->painter->brush.pattern[0] = 0xaa;\n    self->painter->brush.pattern[1] = 0x55;\n    self->painter->brush.pattern[2] = 0xaa;\n    self->painter->brush.pattern[3] = 0x55;\n    self->painter->brush.pattern[4] = 0xaa;\n    self->painter->brush.pattern[5] = 0x55;\n    self->painter->brush.pattern[6] = 0xaa;\n    self->painter->brush.pattern[7] = 0x55;\n    self->painter->brush.x_origin = 0;\n    self->painter->brush.y_origin = 0;\n    self->painter->brush.style = 3;\n    self->painter->bg_color = self->black;\n    self->painter->fg_color = self->white;\n    /* top */\n    xrdp_painter_fill_rect(self->painter, self->screen, x, y, cx, 5);\n    /* bottom */\n    xrdp_painter_fill_rect(self->painter, self->screen, x, y + (cy - 5), cx, 5);\n    /* left */\n    xrdp_painter_fill_rect(self->painter, self->screen, x, y + 5, 5, cy - 10);\n    /* right */\n    xrdp_painter_fill_rect(self->painter, self->screen, x + (cx - 5), y + 5, 5,\n                           cy - 10);\n    xrdp_painter_end_update(self->painter);\n    self->painter->rop = 0xcc;\n    self->painter->clip_children = 1;\n    self->painter->mix_mode = 0;\n    return 0;\n}\n\n/*****************************************************************************/\n/* return true if rect is totally exposed going in reverse z order */\n/* from wnd up */\nstatic int\nxrdp_wm_is_rect_vis(struct xrdp_wm *self, struct xrdp_bitmap *wnd,\n                    struct xrdp_rect *rect)\n{\n    struct xrdp_rect wnd_rect;\n    struct xrdp_bitmap *b;\n    int i;;\n\n    /* if rect is part off screen */\n    if (rect->left < 0)\n    {\n        return 0;\n    }\n\n    if (rect->top < 0)\n    {\n        return 0;\n    }\n\n    if (rect->right >= self->screen->width)\n    {\n        return 0;\n    }\n\n    if (rect->bottom >= self->screen->height)\n    {\n        return 0;\n    }\n\n    i = list_index_of(self->screen->child_list, (long)wnd);\n    i--;\n\n    while (i >= 0)\n    {\n        b = (struct xrdp_bitmap *)list_get_item(self->screen->child_list, i);\n        MAKERECT(wnd_rect, b->left, b->top, b->width, b->height);\n\n        if (rect_intersect(rect, &wnd_rect, 0))\n        {\n            return 0;\n        }\n\n        i--;\n    }\n\n    return 1;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_move_window(struct xrdp_wm *self, struct xrdp_bitmap *wnd,\n                    int dx, int dy)\n{\n    struct xrdp_rect rect1;\n    struct xrdp_rect rect2;\n    struct xrdp_region *r;\n    int i;\n\n    MAKERECT(rect1, wnd->left, wnd->top, wnd->width, wnd->height);\n\n    self->painter->clip_children = 0;\n    if (xrdp_wm_is_rect_vis(self, wnd, &rect1))\n    {\n        rect2 = rect1;\n        RECTOFFSET(rect2, dx, dy);\n\n        if (xrdp_wm_is_rect_vis(self, wnd, &rect2))\n        {\n            xrdp_painter_begin_update(self->painter);\n            xrdp_painter_copy(self->painter, self->screen, self->screen,\n                              wnd->left + dx, wnd->top + dy,\n                              wnd->width, wnd->height,\n                              wnd->left, wnd->top);\n            xrdp_painter_end_update(self->painter);\n\n            wnd->left += dx;\n            wnd->top += dy;\n            r = xrdp_region_create(self);\n            xrdp_region_add_rect(r, &rect1);\n            xrdp_region_subtract_rect(r, &rect2);\n            i = 0;\n\n            while (xrdp_region_get_rect(r, i, &rect1) == 0)\n            {\n                xrdp_bitmap_invalidate(self->screen, &rect1);\n                i++;\n            }\n\n            xrdp_region_delete(r);\n            self->painter->clip_children = 1;\n            return 0;\n        }\n    }\n    self->painter->clip_children = 1;\n\n    wnd->left += dx;\n    wnd->top += dy;\n    xrdp_bitmap_invalidate(self->screen, &rect1);\n    xrdp_bitmap_invalidate(wnd, 0);\n    return 0;\n}\n\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_undraw_dragging_box(struct xrdp_wm *self, int do_begin_end)\n{\n    int boxx;\n    int boxy;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (self->dragging)\n    {\n        if (self->draggingxorstate)\n        {\n            if (do_begin_end)\n            {\n                xrdp_painter_begin_update(self->painter);\n            }\n\n            boxx = self->draggingx - self->draggingdx;\n            boxy = self->draggingy - self->draggingdy;\n            xrdp_wm_xor_pat(self, boxx, boxy, self->draggingcx, self->draggingcy);\n            self->draggingxorstate = 0;\n\n            if (do_begin_end)\n            {\n                xrdp_painter_end_update(self->painter);\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_draw_dragging_box(struct xrdp_wm *self, int do_begin_end)\n{\n    int boxx;\n    int boxy;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (self->dragging)\n    {\n        if (!self->draggingxorstate)\n        {\n            if (do_begin_end)\n            {\n                xrdp_painter_begin_update(self->painter);\n            }\n\n            boxx = self->draggingx - self->draggingdx;\n            boxy = self->draggingy - self->draggingdy;\n            xrdp_wm_xor_pat(self, boxx, boxy, self->draggingcx, self->draggingcy);\n            self->draggingxorstate = 1;\n\n            if (do_begin_end)\n            {\n                xrdp_painter_end_update(self->painter);\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_mouse_move(struct xrdp_wm *self, int x, int y)\n{\n    struct xrdp_bitmap *b;\n    struct xrdp_mod *m;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (x < 0)\n    {\n        x = 0;\n    }\n\n    if (y < 0)\n    {\n        y = 0;\n    }\n\n    if (x >= self->screen->width)\n    {\n        x = self->screen->width;\n    }\n\n    if (y >= self->screen->height)\n    {\n        y = self->screen->height;\n    }\n\n    self->mouse_x = x;\n    self->mouse_y = y;\n\n    if (self->dragging)\n    {\n        xrdp_painter_begin_update(self->painter);\n        xrdp_wm_undraw_dragging_box(self, 0);\n        self->draggingx = x;\n        self->draggingy = y;\n        xrdp_wm_draw_dragging_box(self, 0);\n        xrdp_painter_end_update(self->painter);\n        return 0;\n    }\n\n    b = xrdp_wm_at_pos(self->screen, x, y, 0);\n\n    if (b == 0) /* if b is null, the movement must be over the screen */\n    {\n        if (self->screen->pointer != self->current_pointer)\n        {\n            xrdp_wm_set_pointer(self, self->screen->pointer);\n            self->current_pointer = self->screen->pointer;\n        }\n\n        if (self->mm != 0)\n        {\n            m = self->mm->mod;\n            if (m != 0 && m->mod_event != 0)\n            {\n                m->mod_event(m, WM_MOUSEMOVE, x, y, 0, 0);\n            }\n        }\n    }\n\n    if (self->button_down != 0)\n    {\n        if (b == self->button_down && self->button_down->state == 0)\n        {\n            self->button_down->state = 1;\n            xrdp_bitmap_invalidate(self->button_down, 0);\n        }\n        else if (b != self->button_down)\n        {\n            self->button_down->state = 0;\n            xrdp_bitmap_invalidate(self->button_down, 0);\n        }\n    }\n\n    if (b != 0)\n    {\n        if (!self->dragging)\n        {\n            if (b->pointer != self->current_pointer)\n            {\n                xrdp_wm_set_pointer(self, b->pointer);\n                self->current_pointer = b->pointer;\n            }\n\n            xrdp_bitmap_def_proc(b, WM_MOUSEMOVE,\n                                 xrdp_bitmap_from_screenx(b, x),\n                                 xrdp_bitmap_from_screeny(b, y));\n\n            if (self->button_down == 0)\n            {\n                if (b->notify != 0)\n                {\n                    struct xrdp_bitmap *o = b->owner;\n                    if (o != 0)\n                    {\n                        b->notify(o, b, 2, x, y);\n                    }\n                }\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_clear_popup(struct xrdp_wm *self)\n{\n    int i;\n    struct xrdp_rect rect;\n    //struct xrdp_bitmap* b;\n\n    //b = 0;\n    if (self->popup_wnd != NULL)\n    {\n        //b = self->popup_wnd->popped_from;\n        i = list_index_of(self->screen->child_list, (long)self->popup_wnd);\n        list_remove_item(self->screen->child_list, i);\n        MAKERECT(rect, self->popup_wnd->left, self->popup_wnd->top,\n                 self->popup_wnd->width, self->popup_wnd->height);\n        xrdp_bitmap_invalidate(self->screen, &rect);\n        xrdp_bitmap_delete(self->popup_wnd);\n        self->popup_wnd = NULL;\n    }\n\n    //xrdp_wm_set_focused(self, b->parent);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_mouse_touch(struct xrdp_wm *self, int gesture, int param)\n{\n    struct xrdp_mod *m = NULL;\n\n    LOG(LOG_LEVEL_DEBUG, \"mouse touch event gesture %d param %d\", gesture, param);\n\n    m = (self != 0 && self->mm != 0) ? self->mm->mod : 0;\n    if (m == 0 || m->mod_event == 0)\n    {\n        return 0;\n    }\n\n    switch (gesture)\n    {\n        case TOUCH_TWO_FINGERS_UP:\n        case TOUCH_TWO_FINGERS_DOWN:\n            m->mod_event(m, WM_TOUCH_VSCROLL,\n                         self->mouse_x, self->mouse_y, param, 0);\n            break;\n        case TOUCH_TWO_FINGERS_RIGHT:\n        case TOUCH_TWO_FINGERS_LEFT:\n            m->mod_event(m, WM_TOUCH_HSCROLL,\n                         self->mouse_x, self->mouse_y, param, 0);\n            break;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_mouse_click(struct xrdp_wm *self, int x, int y, int but, int down)\n{\n    struct xrdp_bitmap *control;\n    struct xrdp_bitmap *focus_out_control;\n    struct xrdp_mod *m = NULL;\n    struct xrdp_bitmap *wnd;\n    int newx;\n    int newy;\n    int oldx;\n    int oldy;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (x < 0)\n    {\n        x = 0;\n    }\n\n    if (y < 0)\n    {\n        y = 0;\n    }\n\n    if (x >= self->screen->width)\n    {\n        x = self->screen->width;\n    }\n\n    if (y >= self->screen->height)\n    {\n        y = self->screen->height;\n    }\n\n    if (self->dragging && but == 1 && !down && self->dragging_window != 0)\n    {\n        /* if done dragging */\n        self->draggingx = x;\n        self->draggingy = y;\n        newx = self->draggingx - self->draggingdx;\n        newy = self->draggingy - self->draggingdy;\n        oldx = self->dragging_window->left;\n        oldy = self->dragging_window->top;\n\n        /* draw xor box one more time */\n        if (self->draggingxorstate)\n        {\n            xrdp_wm_xor_pat(self, newx, newy, self->draggingcx, self->draggingcy);\n        }\n\n        self->draggingxorstate = 0;\n        /* move screen to new location */\n        xrdp_wm_move_window(self, self->dragging_window, newx - oldx, newy - oldy);\n        self->dragging_window = 0;\n        self->dragging = 0;\n    }\n\n    wnd = 0;\n    control = xrdp_wm_at_pos(self->screen, x, y, &wnd);\n\n    if (control == 0)\n    {\n        if (self->mm != 0)\n        {\n            m = self->mm->mod;\n        }\n\n        if (m != 0 && m->mod_event != 0)\n        {\n            if (down)\n            {\n                m->mod_event(m, WM_MOUSEMOVE, x, y, 0, 0);\n            }\n            if (but == 1 && down)\n            {\n                m->mod_event(m, WM_LBUTTONDOWN, x, y, 0, 0);\n            }\n            else if (but == 1 && !down)\n            {\n                m->mod_event(m, WM_LBUTTONUP, x, y, 0, 0);\n            }\n\n            if (but == 2 && down)\n            {\n                m->mod_event(m, WM_RBUTTONDOWN, x, y, 0, 0);\n            }\n            else if (but == 2 && !down)\n            {\n                m->mod_event(m, WM_RBUTTONUP, x, y, 0, 0);\n            }\n\n            if (but == 3 && down)\n            {\n                m->mod_event(m, WM_BUTTON3DOWN, x, y, 0, 0);\n            }\n            else if (but == 3 && !down)\n            {\n                m->mod_event(m, WM_BUTTON3UP, x, y, 0, 0);\n            }\n\n            if (but == 8 && down)\n            {\n                m->mod_event(m, WM_BUTTON8DOWN, x, y, 0, 0);\n            }\n            else if (but == 8 && !down)\n            {\n                m->mod_event(m, WM_BUTTON8UP, x, y, 0, 0);\n            }\n            if (but == 9 && down)\n            {\n                m->mod_event(m, WM_BUTTON9DOWN, x, y, 0, 0);\n            }\n            else if (but == 9 && !down)\n            {\n                m->mod_event(m, WM_BUTTON9UP, x, y, 0, 0);\n            }\n            /* vertical scroll */\n\n            if (but == 4)\n            {\n                m->mod_event(m, WM_BUTTON4DOWN,\n                             self->mouse_x, self->mouse_y, 0, 0);\n                m->mod_event(m, WM_BUTTON4UP,\n                             self->mouse_x, self->mouse_y, 0, 0);\n            }\n\n            if (but == 5)\n            {\n                m->mod_event(m, WM_BUTTON5DOWN,\n                             self->mouse_x, self->mouse_y, 0, 0);\n                m->mod_event(m, WM_BUTTON5UP,\n                             self->mouse_x, self->mouse_y, 0, 0);\n            }\n\n            /* horizontal scroll */\n\n            if (but == 6)\n            {\n                m->mod_event(m, WM_BUTTON6DOWN,\n                             self->mouse_x, self->mouse_y, 0, 0);\n                m->mod_event(m, WM_BUTTON6UP,\n                             self->mouse_x, self->mouse_y, 0, 0);\n            }\n\n            if (but == 7)\n            {\n                m->mod_event(m, WM_BUTTON7DOWN,\n                             self->mouse_x, self->mouse_y, 0, 0);\n                m->mod_event(m, WM_BUTTON7UP,\n                             self->mouse_x, self->mouse_y, 0, 0);\n            }\n        }\n    }\n\n    if (self->popup_wnd != 0)\n    {\n        if (self->popup_wnd == control && !down)\n        {\n            xrdp_bitmap_def_proc(self->popup_wnd, WM_LBUTTONUP, x, y);\n            xrdp_wm_clear_popup(self);\n            self->button_down = 0;\n            return 0;\n        }\n        else if (self->popup_wnd != control && down)\n        {\n            xrdp_wm_clear_popup(self);\n            self->button_down = 0;\n            return 0;\n        }\n    }\n\n    if (control != 0)\n    {\n        if (wnd != 0)\n        {\n            if (wnd->modal_dialog != 0) /* if window has a modal dialog */\n            {\n                return 0;\n            }\n\n            if (control == wnd)\n            {\n            }\n            else if (control->tab_stop)\n            {\n                focus_out_control = wnd->focused_control;\n                wnd->focused_control = control;\n                xrdp_bitmap_invalidate(focus_out_control, 0);\n                xrdp_bitmap_invalidate(control, 0);\n            }\n        }\n\n        if ((control->type == WND_TYPE_BUTTON ||\n                control->type == WND_TYPE_COMBO) &&\n                but == 1 && !down && self->button_down == control)\n        {\n            /* if clicking up on a button that was clicked down */\n            self->button_down = 0;\n            control->state = 0;\n            xrdp_bitmap_invalidate(control, 0);\n\n            if (control->parent != 0)\n            {\n                if (control->parent->notify != 0)\n                {\n                    /* control can be invalid after this */\n                    control->parent->notify(control->owner, control, 1, x, y);\n                }\n            }\n        }\n        else if ((control->type == WND_TYPE_BUTTON ||\n                  control->type == WND_TYPE_COMBO) &&\n                 but == 1 && down)\n        {\n            /* if clicking down on a button or combo */\n            self->button_down = control;\n            control->state = 1;\n            xrdp_bitmap_invalidate(control, 0);\n\n            if (control->type == WND_TYPE_COMBO)\n            {\n                xrdp_wm_pu(self, control);\n            }\n        }\n        else if (but == 1 && down)\n        {\n            if (self->popup_wnd == 0)\n            {\n                xrdp_wm_set_focused(self, wnd);\n\n                if (control->type == WND_TYPE_WND && y < (control->top + 21))\n                {\n                    /* if dragging */\n                    if (self->dragging) /* rarely happens */\n                    {\n                        newx = self->draggingx - self->draggingdx;\n                        newy = self->draggingy - self->draggingdy;\n\n                        if (self->draggingxorstate)\n                        {\n                            xrdp_wm_xor_pat(self, newx, newy,\n                                            self->draggingcx, self->draggingcy);\n                        }\n\n                        self->draggingxorstate = 0;\n                    }\n\n                    self->dragging = 1;\n                    self->dragging_window = control;\n                    self->draggingorgx = control->left;\n                    self->draggingorgy = control->top;\n                    self->draggingx = x;\n                    self->draggingy = y;\n                    self->draggingdx = x - control->left;\n                    self->draggingdy = y - control->top;\n                    self->draggingcx = control->width;\n                    self->draggingcy = control->height;\n                }\n            }\n        }\n    }\n    else\n    {\n        xrdp_wm_set_focused(self, 0);\n    }\n\n    /* no matter what, mouse is up, reset button_down */\n    if (but == 1 && !down && self->button_down != 0)\n    {\n        self->button_down = 0;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_key(struct xrdp_wm *self, int keyboard_flags, int key_code)\n{\n    int msg;\n    struct xrdp_mod *m;\n    struct xrdp_key_info *ki;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG,\n              \"xrdp_wm_key: RDP key_code:0x%04x, keyboard_flags: 0x%04x\",\n              key_code, keyboard_flags);\n    int scancode = SCANCODE_FROM_KBD_EVENT(key_code, keyboard_flags);\n    int keyup = ((keyboard_flags & KBDFLAGS_RELEASE) != 0);\n\n    int sindex = scancode_to_index(scancode);\n    if (sindex < 0)\n    {\n        // The scancode doesn't map to an index, so we can't handle it here.\n        // Log this so we can investigate\n        LOG(LOG_LEVEL_WARNING, \"Ignoring unusable scancode %x (%s)\",\n            scancode, (keyup ? \"up\" : \"down\"));\n        return 0;\n    }\n\n    if (self->popup_wnd != 0)\n    {\n        xrdp_wm_clear_popup(self);\n        return 0;\n    }\n\n    if (keyup)\n    {\n        self->keys[sindex] = 0;\n        msg = WM_KEYUP;\n    }\n    else /* key down */\n    {\n        self->keys[sindex] = 1;\n        msg = WM_KEYDOWN;\n\n        switch (scancode)\n        {\n            case SCANCODE_CAPS_KEY:\n                self->caps_lock = !self->caps_lock;\n                break; /* caps lock */\n            case SCANCODE_NUMLOCK_KEY:\n                self->num_lock = !self->num_lock;\n                break; /* num lock */\n            case SCANCODE_SCROLL_KEY:\n                self->scroll_lock = !self->scroll_lock;\n                break; /* scroll lock */\n        }\n    }\n\n    m = (self->mm != 0) ? self->mm->mod : 0;\n    if (m != 0 && m->mod_event != 0)\n    {\n        // ..and able to take events. Check the scancode maps to\n        // a real key in the currently loaded keymap\n        ki = get_key_info_from_kbd_event\n             (keyboard_flags, key_code, self->keys, self->caps_lock,\n              self->num_lock, self->scroll_lock,\n              &(self->keymap));\n\n        if (ki != 0)\n        {\n            m->mod_event(m, msg, ki->chr, ki->sym,\n                         key_code, keyboard_flags);\n        }\n    }\n    else if (self->focused_window != 0)\n    {\n        // Pass keypress on to a widget in the login window\n        xrdp_bitmap_def_proc(self->focused_window,\n                             msg, key_code, keyboard_flags);\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/* happens when client gets focus and sends key modifier info */\nint\nxrdp_wm_key_sync(struct xrdp_wm *self, int device_flags, int key_flags)\n{\n    struct xrdp_mod *m;\n\n    self->num_lock = 0;\n    self->scroll_lock = 0;\n    self->caps_lock = 0;\n\n    if (key_flags & 1)\n    {\n        self->scroll_lock = 1;\n    }\n\n    if (key_flags & 2)\n    {\n        self->num_lock = 1;\n    }\n\n    if (key_flags & 4)\n    {\n        self->caps_lock = 1;\n    }\n\n    if (self->mm != 0)\n    {\n        m = self->mm->mod;\n        if (m != 0 && m->mod_event != 0)\n        {\n            m->mod_event(m, WM_KEYBRD_SYNC, key_flags,\n                         device_flags, key_flags, device_flags);\n        }\n        else\n        {\n            // Save the event for when the module is loaded\n            self->mm->last_sync_saved = 1;\n            self->mm->last_sync_key_flags = key_flags;\n            self->mm->last_sync_device_flags = device_flags;\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\n/**\n * Takes a stream of UTF-16 characters and  maps then to Unicode characters\n */\nstatic char32_t\nget_unicode_character(struct xrdp_wm *self, int device_flags, char16_t c16)\n{\n    char32_t c32 = 0;\n    int *high_ptr;\n\n    if (device_flags & KBDFLAGS_RELEASE)\n    {\n        high_ptr = &self->last_high_surrogate_key_up;\n    }\n    else\n    {\n        high_ptr = &self->last_high_surrogate_key_down;\n    }\n\n    if (IS_HIGH_SURROGATE(c16))\n    {\n        // Record high surrogate for next time\n        *high_ptr = c16;\n    }\n    else if (IS_LOW_SURROGATE(c16))\n    {\n        // If last character was a high surrogate, we can use it\n        if (*high_ptr != 0)\n        {\n            c32 = C32_FROM_SURROGATE_PAIR(c16, *high_ptr);\n            *high_ptr = 0;\n        }\n    }\n    else\n    {\n        // Character maps straight across\n        c32 = c16;\n        *high_ptr = 0;\n    }\n\n    return c32;\n}\n\n/*****************************************************************************/\n/**\n * Takes a scancode index and fakes a keyboard event to represent it\n * @param self module pointer\n * @param device_flags default flags to pass in for the keyboard event.\n * @param index scancode index\n *\n * Some of the device_flags are overridden by the scancode derived from the\n * scancode index\n */\nstatic void\nfake_kbd_event_from_scancode_index(struct xrdp_wm *self, int device_flags,\n                                   int index)\n{\n    unsigned short scancode = scancode_from_index(index);\n    int key_code = SCANCODE_TO_KBD_EVENT_KEY_CODE(scancode);\n\n    device_flags &= ~(KBDFLAGS_EXTENDED | KBDFLAGS_EXTENDED1);\n    device_flags |= SCANCODE_TO_KBD_EVENT_KBD_FLAGS(scancode);\n\n    xrdp_wm_key(self, device_flags, key_code);\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t c16)\n{\n    int index;\n    char32_t c32 = get_unicode_character(self, device_flags, c16);\n\n    if (c32 == 0)\n    {\n        return 0;\n    }\n\n    // See if we can find the character in the existing keymap,\n    // and if so, generate normal key event(s) for it\n    for (index = 0; index <= SCANCODE_MAX_INDEX; ++index)\n    {\n        if (c32 == self->keymap.keys_noshift[index].chr)\n        {\n            fake_kbd_event_from_scancode_index(self, device_flags, index);\n            return 0;\n        }\n    }\n\n    for (index = 0; index <= SCANCODE_MAX_INDEX; ++index)\n    {\n        if (c32 == self->keymap.keys_shift[index].chr)\n        {\n            if (device_flags & KBDFLAGS_RELEASE)\n            {\n                fake_kbd_event_from_scancode_index(self, device_flags, index);\n                fake_kbd_event_from_scancode_index(self, device_flags,\n                                                   SCANCODE_INDEX_LSHIFT_KEY);\n            }\n            else\n            {\n                fake_kbd_event_from_scancode_index(self, device_flags,\n                                                   SCANCODE_INDEX_LSHIFT_KEY);\n                fake_kbd_event_from_scancode_index(self, device_flags, index);\n            }\n            return 0;\n        }\n    }\n\n    for (index = 0; index <= SCANCODE_MAX_INDEX; ++index)\n    {\n        if (c32 == self->keymap.keys_altgr[index].chr)\n        {\n            if (device_flags & KBDFLAGS_RELEASE)\n            {\n                fake_kbd_event_from_scancode_index(self, device_flags, index);\n                fake_kbd_event_from_scancode_index(self, device_flags,\n                                                   SCANCODE_INDEX_RALT_KEY);\n            }\n            else\n            {\n                fake_kbd_event_from_scancode_index(self, device_flags,\n                                                   SCANCODE_INDEX_RALT_KEY);\n                fake_kbd_event_from_scancode_index(self, device_flags, index);\n            }\n            return 0;\n        }\n    }\n\n    for (index = 0; index <= SCANCODE_MAX_INDEX; ++index)\n    {\n        if (c32 == self->keymap.keys_shiftaltgr[index].chr)\n        {\n            if (device_flags & KBDFLAGS_RELEASE)\n            {\n                fake_kbd_event_from_scancode_index(self, device_flags, index);\n                fake_kbd_event_from_scancode_index(self, device_flags,\n                                                   SCANCODE_INDEX_RALT_KEY);\n                fake_kbd_event_from_scancode_index(self, device_flags,\n                                                   SCANCODE_INDEX_LSHIFT_KEY);\n            }\n            else\n            {\n                fake_kbd_event_from_scancode_index(self, device_flags,\n                                                   SCANCODE_INDEX_LSHIFT_KEY);\n                fake_kbd_event_from_scancode_index(self, device_flags,\n                                                   SCANCODE_INDEX_RALT_KEY);\n                fake_kbd_event_from_scancode_index(self, device_flags, index);\n            }\n            return 0;\n        }\n    }\n\n    // Send the character to chansrv if it's capable of doing something\n    // with it\n    if (self->mm->chan_trans != NULL &&\n            self->client_info->unicode_input_support == UIS_ACTIVE &&\n            self->mm->chan_trans->status == TRANS_STATUS_UP)\n    {\n        xrdp_mm_send_unicode_to_chansrv(self->mm,\n                                        !(device_flags & KBDFLAGS_RELEASE), c32);\n        return 0;\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_pu(struct xrdp_wm *self, struct xrdp_bitmap *control)\n{\n    int x;\n    int y;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    if (control == 0)\n    {\n        return 0;\n    }\n\n    self->popup_wnd = xrdp_bitmap_create(control->width, DEFAULT_WND_SPECIAL_H,\n                                         self->screen->bpp,\n                                         WND_TYPE_SPECIAL, self);\n    self->popup_wnd->popped_from = control;\n    self->popup_wnd->parent = self->screen;\n    self->popup_wnd->owner = self->screen;\n    x = xrdp_bitmap_to_screenx(control, 0);\n    y = xrdp_bitmap_to_screeny(control, 0);\n    self->popup_wnd->left = x;\n    self->popup_wnd->top = y + control->height;\n    self->popup_wnd->item_index = control->item_index;\n    list_insert_item(self->screen->child_list, 0, (long)self->popup_wnd);\n    xrdp_bitmap_invalidate(self->popup_wnd, 0);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_process_input_mouse(struct xrdp_wm *self, int device_flags,\n                            int x, int y)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"mouse event flags %4.4x x %d y %d\", device_flags, x, y);\n\n    if (device_flags & PTRFLAGS_MOVE)\n    {\n        xrdp_wm_mouse_move(self, x, y);\n    }\n\n    if (device_flags & PTRFLAGS_BUTTON1)\n    {\n        if (device_flags & PTRFLAGS_DOWN)\n        {\n            xrdp_wm_mouse_click(self, x, y, 1, 1);\n        }\n        else\n        {\n            xrdp_wm_mouse_click(self, x, y, 1, 0);\n        }\n    }\n\n    if (device_flags & PTRFLAGS_BUTTON2)\n    {\n        if (device_flags & PTRFLAGS_DOWN)\n        {\n            xrdp_wm_mouse_click(self, x, y, 2, 1);\n        }\n        else\n        {\n            xrdp_wm_mouse_click(self, x, y, 2, 0);\n        }\n    }\n\n    if (device_flags & PTRFLAGS_BUTTON3)\n    {\n        if (device_flags & PTRFLAGS_DOWN)\n        {\n            xrdp_wm_mouse_click(self, x, y, 3, 1);\n        }\n        else\n        {\n            xrdp_wm_mouse_click(self, x, y, 3, 0);\n        }\n    }\n\n    /* vertical mouse wheel */\n    if (device_flags & PTRFLAGS_WHEEL)\n    {\n        int delta = 0;\n        if (device_flags & PTRFLAGS_WHEEL_NEGATIVE)\n        {\n            /**\n             * [MS-RDPBCGR] 2.2.8.1.1.3.1.1.3 Mouse Event (TS_POINTER_EVENT)\n             * In negative scrolling, rotation distance is negative and the delta\n             * is represented by the lowest byte.\n             * Examples:\n             * device_flags = 0x020a, positive vertical scrolling, distance 10\n             * device_flags = 0x03f6, negative vertical scrolling, distance -10\n             *\n             * The negative number is represented by complement.\n             */\n            delta = (device_flags & WheelRotationMask) | ~WheelRotationMask;\n            if (delta != 0 && XRDP_MM_IMPLEMENTS_TOUCH(self->mm))\n            {\n                // Use nature scrolling, up direction is negative.\n                xrdp_wm_mouse_touch(self, TOUCH_TWO_FINGERS_UP, delta);\n            }\n            else\n            {\n                xrdp_wm_mouse_click(self, 0, 0, 5, 0);\n            }\n        }\n        else\n        {\n            delta = device_flags & WheelRotationMask;\n            if (delta != 0 && XRDP_MM_IMPLEMENTS_TOUCH(self->mm))\n            {\n                xrdp_wm_mouse_touch(self, TOUCH_TWO_FINGERS_DOWN, delta);\n            }\n            else\n            {\n                xrdp_wm_mouse_click(self, 0, 0, 4, 0);\n            }\n        }\n    }\n\n    /* horizontal mouse wheel */\n\n    /**\n     * As mstsc does MOUSE not MOUSEX for horizontal scrolling,\n     * PTRFLAGS_HWHEEL must be handled here.\n     */\n    if (device_flags & PTRFLAGS_HWHEEL)\n    {\n        int delta = 0;\n        if (device_flags & PTRFLAGS_WHEEL_NEGATIVE)\n        {\n            /**\n             * [MS-RDPBCGR] 2.2.8.1.1.3.1.1.3 Mouse Event (TS_POINTER_EVENT)\n             * In negative scrolling, rotation distance is negative and the delta\n             * is represented by the lowest byte.\n             * Examples:\n             * device_flags = 0x040a, positive horizontal scrolling, distance 10\n             * device_flags = 0x05f6, negative horizontal scrolling, distance -10\n             *\n             * The negative number is represented by complement.\n             */\n            delta = (device_flags & WheelRotationMask) | ~WheelRotationMask;\n            if (delta != 0 && XRDP_MM_IMPLEMENTS_TOUCH(self->mm))\n            {\n                // Use nature scrolling, right direction is negative.\n                xrdp_wm_mouse_touch(self, TOUCH_TWO_FINGERS_RIGHT, delta);\n            }\n            else\n            {\n                xrdp_wm_mouse_click(self, 0, 0, 6, 0);\n            }\n        }\n        else\n        {\n            delta = device_flags & WheelRotationMask;\n            if (delta != 0 && XRDP_MM_IMPLEMENTS_TOUCH(self->mm))\n            {\n                xrdp_wm_mouse_touch(self, TOUCH_TWO_FINGERS_LEFT, delta);\n            }\n            else\n            {\n                xrdp_wm_mouse_click(self, 0, 0, 7, 0);\n            }\n        }\n    }\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_wm_process_input_mousex(struct xrdp_wm *self, int device_flags,\n                             int x, int y)\n{\n    if (device_flags & PTRXFLAGS_DOWN)\n    {\n        if (device_flags & PTRXFLAGS_BUTTON1)\n        {\n            xrdp_wm_mouse_click(self, x, y, 8, 1);\n        }\n        else if (device_flags & PTRXFLAGS_BUTTON2)\n        {\n            xrdp_wm_mouse_click(self, x, y, 9, 1);\n        }\n    }\n    else\n    {\n        if (device_flags & PTRXFLAGS_BUTTON1)\n        {\n            xrdp_wm_mouse_click(self, x, y, 8, 0);\n        }\n        else if (device_flags & PTRXFLAGS_BUTTON2)\n        {\n            xrdp_wm_mouse_click(self, x, y, 9, 0);\n        }\n    }\n    return 0;\n}\n\n/******************************************************************************/\n/* param1 = MAKELONG(channel_id, flags)\n   param2 = size\n   param3 = pointer to data\n   param4 = total size */\nstatic int\nxrdp_wm_process_channel_data(struct xrdp_wm *self,\n                             tbus param1, tbus param2,\n                             tbus param3, tbus param4)\n{\n    int rv;\n    struct xrdp_mod *m;\n    rv = 1;\n\n    if (self->mm != 0)\n    {\n        if (self->mm->use_chansrv)\n        {\n            rv = xrdp_mm_process_channel_data(self->mm, param1, param2,\n                                              param3, param4);\n        }\n        else\n        {\n            m = self->mm->mod;\n            if (m != 0 && m->mod_event != 0)\n            {\n                rv = m->mod_event(m, WM_CHANNEL_DATA,\n                                  param1, param2, param3, param4);\n            }\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/* this is the callbacks coming from libxrdp.so */\nint\ncallback(struct xrdp_process *id, int msg, intptr_t param1, intptr_t param2,\n         intptr_t param3, intptr_t param4)\n{\n    int rv;\n    struct xrdp_wm *wm;\n    struct xrdp_rect rect;\n\n    if (id == NULL)\n    {\n        return 0;\n    }\n\n    wm = ((struct xrdp_process *)id)->wm;\n\n    if (wm == 0)\n    {\n        return 0;\n    }\n\n    rv = 0;\n\n    switch (msg)\n    {\n        case RDP_INPUT_SYNCHRONIZE:\n            rv = xrdp_wm_key_sync(wm, param3, param1);\n            break;\n        case RDP_INPUT_SCANCODE:\n            rv = xrdp_wm_key(wm, param3, param1);\n            break;\n        case RDP_INPUT_UNICODE:\n            rv = xrdp_wm_key_unicode(wm, param3, param1);\n            break;\n        case RDP_INPUT_MOUSE:\n            rv = xrdp_wm_process_input_mouse(wm, param3, param1, param2);\n            break;\n        case RDP_INPUT_MOUSEX:\n            rv = xrdp_wm_process_input_mousex(wm, param3, param1, param2);\n            break;\n        case 0x4444: /* invalidate, this is not from RDP_DATA_PDU_INPUT */\n            /* like the rest, it's from RDP_PDU_DATA with code 33 */\n            /* it's the rdp client asking for a screen update */\n            MAKERECT(rect, param1, param2, param3, param4);\n            rv = xrdp_bitmap_invalidate(wm->screen, &rect);\n            break;\n        case 0x5555: /* called from xrdp_channel.c, channel data has come in,\n                    pass it to module if there is one */\n            rv = xrdp_wm_process_channel_data(wm, param1, param2, param3, param4);\n            break;\n        case 0x5556:\n            rv = xrdp_mm_check_chan(wm->mm);\n            break;\n        case 0x5557:\n            LOG(LOG_LEVEL_TRACE, \"callback: frame ack %p\", (void *) param1);\n            xrdp_mm_frame_ack(wm->mm, param1);\n            break;\n        case 0x5558:\n            xrdp_mm_drdynvc_up(wm->mm);\n            break;\n        case 0x5559:\n            xrdp_mm_suppress_output(wm->mm, param1,\n                                    LOWORD(param2), HIWORD(param2),\n                                    LOWORD(param3), HIWORD(param3));\n            break;\n        case 0x555a:\n            // \"yeah, up_and_running\"\n            xrdp_mm_up_and_running(wm->mm);\n            break;\n    }\n    return rv;\n}\n\n/******************************************************************************/\n/* returns error */\n/* this gets called when there is nothing on any socket */\nstatic int\nxrdp_wm_login_state_changed(struct xrdp_wm *self)\n{\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    LOG(LOG_LEVEL_DEBUG, \"Login state has changed to %s\",\n        xrdp_wm_login_state_to_str(self->login_state));\n    if (self->login_state == WMLS_RESET)\n    {\n        list_clear(self->log);\n        xrdp_wm_delete_all_children(self);\n        self->dragging = 0;\n\n        if (self->fatal_error_in_log_window)\n        {\n            /* We've got here after OK is pressed in the log\n             * window, so the user has read the message(s) in it */\n            g_set_wait_obj(self->pro_layer->self_term_event);\n        }\n        else\n        {\n            /* this is the initial state of the login window */\n            xrdp_wm_set_login_state(self, WMLS_USER_PROMPT);\n            xrdp_wm_init(self);\n        }\n    }\n    else if (self->login_state == WMLS_START_CONNECT)\n    {\n        xrdp_wm_delete_all_children(self);\n        self->dragging = 0;\n        xrdp_wm_set_login_state(self, WMLS_CONNECT_IN_PROGRESS);\n\n        /* This calls back to xrdp_wm_mod_connect_done() when the\n         * connect is finished*/\n        xrdp_mm_connect(self->mm);\n    }\n    else if (self->login_state == WMLS_CLEANUP)\n    {\n        xrdp_wm_delete_all_children(self);\n        self->dragging = 0;\n        xrdp_wm_set_login_state(self, WMLS_INACTIVE);\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\n/* this gets called when the module manager finishes a connect\n * which was initiated by xrdp_mm_connect()\n */\nvoid\nxrdp_wm_mod_connect_done(struct xrdp_wm *self, int status)\n{\n    LOG(LOG_LEVEL_DEBUG, \"status from xrdp_mm_connect() : %d\", status);\n    if (status == 0)\n    {\n        xrdp_wm_set_login_state(self, WMLS_CLEANUP);\n        self->dragging = 0;\n    }\n    else\n    {\n        xrdp_wm_set_login_state(self, WMLS_INACTIVE);\n        xrdp_wm_show_log(self);\n    }\n}\n\n/*****************************************************************************/\n/* this is the log windows notify function */\nstatic int\nxrdp_wm_log_wnd_notify(struct xrdp_bitmap *wnd,\n                       struct xrdp_bitmap *sender,\n                       int msg, long param1, long param2)\n{\n    struct xrdp_painter *painter;\n    struct xrdp_wm *wm;\n    struct xrdp_rect rect;\n    int index;\n    char *text;\n\n    if (wnd == 0)\n    {\n        return 0;\n    }\n\n    if (sender == 0)\n    {\n        return 0;\n    }\n\n    if (wnd->owner == 0)\n    {\n        return 0;\n    }\n\n    wm = wnd->wm;\n\n    if (msg == 1) /* click */\n    {\n        if (sender->id == 1) /* ok button */\n        {\n            /* close the log window */\n            MAKERECT(rect, wnd->left, wnd->top, wnd->width, wnd->height);\n            xrdp_bitmap_delete(wnd);\n            xrdp_bitmap_invalidate(wm->screen, &rect);\n\n            /* if module is gone, reset the session when ok is clicked */\n            if (wm->mm->mod_handle == 0)\n            {\n                /* make sure autologin is off */\n                wm->session->client_info->rdp_autologin = 0;\n                xrdp_wm_set_login_state(wm, WMLS_RESET); /* reset session */\n            }\n        }\n    }\n    else if (msg == WM_PAINT) /* 3 */\n    {\n        painter = (struct xrdp_painter *)param1;\n\n        if (painter != 0)\n        {\n            unsigned int row_height = xrdp_painter_font_body_height(painter);\n            painter->fg_color = wnd->wm->black;\n\n            for (index = 0; index < wnd->wm->log->count; index++)\n            {\n                text = (char *)list_get_item(wnd->wm->log, index);\n                xrdp_painter_draw_text(painter, wnd, 10,\n                                       (index  + 2) * row_height, text);\n            }\n        }\n    }\n\n    return 0;\n}\n\nstatic void\nadd_string_to_logwindow(const char *msg, struct list *log)\n{\n    const char *new_part_message;\n    const char *current_pointer = msg;\n    int len_done = 0;\n\n    do\n    {\n        new_part_message = g_strndup(current_pointer, LOG_WINDOW_CHAR_PER_LINE);\n        list_add_item(log, (tintptr) new_part_message);\n        len_done += g_strlen(new_part_message);\n        current_pointer += g_strlen(new_part_message);\n    }\n    while ((len_done < g_strlen(msg)) && (len_done < DEFAULT_STRING_LEN));\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_show_log(struct xrdp_wm *self)\n{\n    struct xrdp_bitmap *but;\n    int w;\n    int h;\n    int xoffset;\n    int yoffset;\n    uint32_t index;\n    int primary_x_offset;\n    int primary_y_offset;\n\n\n    if (self->hide_log_window)\n    {\n        /* make sure autologin is off */\n        self->session->client_info->rdp_autologin = 0;\n        xrdp_wm_set_login_state(self, WMLS_RESET); /* reset session */\n        return 0;\n    }\n\n    if (self->log_wnd == 0)\n    {\n        w = self->xrdp_config->cfg_globals.ls_scaled.log_wnd_width;\n        h = self->xrdp_config->cfg_globals.ls_scaled.log_wnd_height;\n\n        xoffset = 10;\n        yoffset = 10;\n\n        if (self->screen->width < w)\n        {\n            w = self->screen->width - 4;\n            xoffset = 2;\n        }\n\n        if (self->screen->height < h)\n        {\n            h = self->screen->height - 4;\n            yoffset = 2;\n        }\n\n        primary_x_offset = 0;\n        primary_y_offset = 0;\n\n        /* multimon scenario, draw log window on primary monitor */\n        if (self->client_info->display_sizes.monitorCount > 1)\n        {\n            for (index = 0; index < self->client_info->display_sizes.monitorCount; index++)\n            {\n                if (self->client_info->display_sizes.minfo_wm[index].is_primary)\n                {\n                    primary_x_offset = self->client_info->display_sizes.minfo_wm[index].left;\n                    primary_y_offset = self->client_info->display_sizes.minfo_wm[index].top;\n                    break;\n                }\n            }\n        }\n\n        /* log window */\n        self->log_wnd = xrdp_bitmap_create(w, h, self->screen->bpp,\n                                           WND_TYPE_WND, self);\n        list_add_item(self->screen->child_list, (long)self->log_wnd);\n        self->log_wnd->parent = self->screen;\n        self->log_wnd->owner = self->screen;\n        self->log_wnd->bg_color = self->grey;\n        self->log_wnd->left = primary_x_offset + xoffset;\n        self->log_wnd->top = primary_y_offset + yoffset;\n        set_string(&(self->log_wnd->caption1), \"Connection Log\");\n        /* ok button */\n        const char *ok_string = \"OK\";\n        const int ok_height =\n            self->xrdp_config->cfg_globals.ls_scaled.default_btn_height;\n        const int ok_width = xrdp_painter_text_width(self->painter, ok_string) +\n                             DEFAULT_BUTTON_MARGIN_W;\n\n        but = xrdp_bitmap_create(ok_width, ok_height, self->screen->bpp,\n                                 WND_TYPE_BUTTON, self);\n        list_insert_item(self->log_wnd->child_list, 0, (long)but);\n        but->parent = self->log_wnd;\n        but->owner = self->log_wnd;\n        but->left = (w - ok_width) - xoffset;\n        but->top = (h - ok_height) - yoffset;\n        but->id = 1;\n        but->tab_stop = 1;\n        set_string(&but->caption1, \"OK\");\n        self->log_wnd->focused_control = but;\n        /* set notify function */\n        self->log_wnd->notify = xrdp_wm_log_wnd_notify;\n    }\n\n    xrdp_wm_set_focused(self, self->log_wnd);\n    xrdp_bitmap_invalidate(self->log_wnd, 0);\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_log_msg(struct xrdp_wm *self, enum logLevels loglevel,\n                const char *fmt, ...)\n{\n    va_list ap;\n    char msg[256];\n\n    va_start(ap, fmt);\n    vsnprintf(msg, sizeof(msg), fmt, ap);\n    va_end(ap);\n\n    LOG(loglevel, \"xrdp_wm_log_msg: %s\", msg);\n    add_string_to_logwindow(msg, self->log);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_get_wait_objs(struct xrdp_wm *self, tbus *robjs, int *rc,\n                      tbus *wobjs, int *wc, int *timeout)\n{\n    int i;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    i = *rc;\n    robjs[i++] = self->login_state_event;\n    *rc = i;\n    return xrdp_mm_get_wait_objs(self->mm, robjs, rc, wobjs, wc, timeout);\n}\n\n/******************************************************************************/\nint\nxrdp_wm_check_wait_objs(struct xrdp_wm *self)\n{\n    int rv;\n\n    if (self == 0)\n    {\n        return 0;\n    }\n\n    rv = 0;\n\n    if (g_is_wait_obj_set(self->login_state_event))\n    {\n        g_reset_wait_obj(self->login_state_event);\n        xrdp_wm_login_state_changed(self);\n    }\n\n    if (rv == 0)\n    {\n        rv = xrdp_mm_check_wait_objs(self->mm);\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nconst char *\nxrdp_wm_login_state_to_str(enum wm_login_state login_state)\n{\n    const char *result = \"unknown\";\n    /* Use a switch for this, as some compilers will warn about missing states\n     */\n    switch (login_state)\n    {\n        case WMLS_RESET:\n            result = \"WMLS_RESET\";\n            break;\n        case WMLS_USER_PROMPT:\n            result = \"WMLS_USER_PROMPT\";\n            break;\n        case WMLS_START_CONNECT:\n            result = \"WMLS_START_CONNECT\";\n            break;\n        case WMLS_CONNECT_IN_PROGRESS:\n            result = \"WMLS_CONNECT_IN_PROGRESS\";\n            break;\n        case WMLS_CLEANUP:\n            result = \"WMLS_CLEANUP\";\n            break;\n        case WMLS_INACTIVE:\n            result = \"WMLS_INACTIVE\";\n    }\n\n    return result;\n}\n\n/*****************************************************************************/\nint\nxrdp_wm_set_login_state(struct xrdp_wm *self, enum wm_login_state login_state)\n{\n    LOG(LOG_LEVEL_DEBUG, \"Login state change request %s -> %s\",\n        xrdp_wm_login_state_to_str(self->login_state),\n        xrdp_wm_login_state_to_str(login_state));\n\n    self->login_state = login_state;\n    g_set_wait_obj(self->login_state_event);\n    return 0;\n}\n\nint\nxrdp_wm_can_resize(struct xrdp_wm *self)\n{\n    if (self->login_state != WMLS_CLEANUP\n            && self->login_state != WMLS_INACTIVE)\n    {\n        LOG(LOG_LEVEL_INFO, \"Not allowing resize. Login in progress.\");\n        LOG_DEVEL(LOG_LEVEL_INFO,\n                  \"State is %s\", xrdp_wm_login_state_to_str(self->login_state));\n        return 0;\n    }\n    return 1;\n}\n"
  },
  {
    "path": "xrdp/xrdpwin.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2014\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * main program\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#if defined(_WIN32)\n#include <windows.h>\n#endif\n#include \"xrdp.h\"\n\nstatic struct xrdp_listen *g_listen = 0;\nstatic long g_threadid = 0; /* main threadid */\n\n#if defined(_WIN32)\nstatic SERVICE_STATUS_HANDLE g_ssh = 0;\nstatic SERVICE_STATUS g_service_status;\n#endif\nstatic long g_sync_mutex = 0;\nstatic long g_sync1_mutex = 0;\nstatic tbus g_term_event = 0;\nstatic tbus g_sync_event = 0;\n/* synchronize stuff */\nstatic int g_sync_command = 0;\nstatic long g_sync_result = 0;\nstatic long g_sync_param1 = 0;\nstatic long g_sync_param2 = 0;\nstatic long (*g_sync_func)(long param1, long param2);\n\n/*****************************************************************************/\nlong\ng_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1,\n            long sync_param2)\n{\n    long sync_result;\n    int sync_command;\n\n    if (tc_threadid_equal(tc_get_threadid(), g_threadid))\n    {\n        /* this is the main thread, call the function directly */\n        sync_result = sync_func(sync_param1, sync_param2);\n    }\n    else\n    {\n        tc_mutex_lock(g_sync1_mutex);\n        tc_mutex_lock(g_sync_mutex);\n        g_sync_param1 = sync_param1;\n        g_sync_param2 = sync_param2;\n        g_sync_func = sync_func;\n        g_sync_command = 100;\n        tc_mutex_unlock(g_sync_mutex);\n        g_set_wait_obj(g_sync_event);\n\n        do\n        {\n            g_sleep(100);\n            tc_mutex_lock(g_sync_mutex);\n            sync_command = g_sync_command;\n            sync_result = g_sync_result;\n            tc_mutex_unlock(g_sync_mutex);\n        }\n        while (sync_command != 0);\n\n        tc_mutex_unlock(g_sync1_mutex);\n    }\n\n    return sync_result;\n}\n\n/*****************************************************************************/\nvoid\nxrdp_shutdown(int sig)\n{\n    tbus threadid;\n\n    threadid = tc_get_threadid();\n    g_writeln(\"shutting down\");\n    g_writeln(\"signal %d threadid %p\", sig, threadid);\n\n    if (!g_is_wait_obj_set(g_term_event))\n    {\n        g_set_wait_obj(g_term_event);\n    }\n}\n\n/*****************************************************************************/\nint\ng_is_term(void)\n{\n    return g_is_wait_obj_set(g_term_event);\n}\n\n/*****************************************************************************/\nvoid\ng_set_term(int in_val)\n{\n    if (in_val)\n    {\n        g_set_wait_obj(g_term_event);\n    }\n    else\n    {\n        g_reset_wait_obj(g_term_event);\n    }\n}\n\n/*****************************************************************************/\ntbus\ng_get_sync_event(void)\n{\n    return g_sync_event;\n}\n\n/*****************************************************************************/\nvoid\npipe_sig(int sig_num)\n{\n    /* do nothing */\n    g_writeln(\"got XRDP WIN SIGPIPE(%d)\", sig_num);\n}\n\n/*****************************************************************************/\nvoid\ng_process_waiting_function(void)\n{\n    tc_mutex_lock(g_sync_mutex);\n\n    if (g_sync_command != 0)\n    {\n        if (g_sync_func != 0)\n        {\n            if (g_sync_command == 100)\n            {\n                g_sync_result = g_sync_func(g_sync_param1, g_sync_param2);\n            }\n        }\n\n        g_sync_command = 0;\n    }\n\n    tc_mutex_unlock(g_sync_mutex);\n}\n\n/* win32 service control functions */\n#if defined(_WIN32)\n\n/*****************************************************************************/\nVOID WINAPI\nMyHandler(DWORD fdwControl)\n{\n    if (g_ssh == 0)\n    {\n        return;\n    }\n\n    if (fdwControl == SERVICE_CONTROL_STOP)\n    {\n        g_service_status.dwCurrentState = SERVICE_STOP_PENDING;\n        g_set_term(1);\n    }\n    else if (fdwControl == SERVICE_CONTROL_PAUSE)\n    {\n        /* shouldn't happen */\n    }\n    else if (fdwControl == SERVICE_CONTROL_CONTINUE)\n    {\n        /* shouldn't happen */\n    }\n    else if (fdwControl == SERVICE_CONTROL_INTERROGATE)\n    {\n    }\n    else if (fdwControl == SERVICE_CONTROL_SHUTDOWN)\n    {\n        g_service_status.dwCurrentState = SERVICE_STOP_PENDING;\n        g_set_term(1);\n    }\n\n    SetServiceStatus(g_ssh, &g_service_status);\n}\n\n/*****************************************************************************/\nstatic void\nlog_event(HANDLE han, char *msg)\n{\n    ReportEvent(han, EVENTLOG_INFORMATION_TYPE, 0, 0, 0, 1, 0, &msg, 0);\n}\n\n/*****************************************************************************/\nVOID WINAPI\nMyServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)\n{\n    WSADATA w;\n    char text[256];\n    int pid;\n    //HANDLE event_han;\n    //  int fd;\n    //  char text[256];\n\n    //  fd = g_file_open_rw(\"c:\\\\temp\\\\xrdp\\\\log.txt\");\n    //  g_file_write(fd, \"hi\\r\\n\", 4);\n    //event_han = RegisterEventSource(0, \"xrdp\");\n    //log_event(event_han, \"hi xrdp log\");\n    g_threadid = tc_get_threadid();\n    g_set_current_dir(\"c:\\\\temp\\\\xrdp\");\n    g_listen = 0;\n    WSAStartup(2, &w);\n    g_sync_mutex = tc_mutex_create();\n    g_sync1_mutex = tc_mutex_create();\n    pid = g_getpid();\n    g_snprintf(text, 255, \"xrdp_%8.8x_main_term\", pid);\n    g_term_event = g_create_wait_obj(text);\n    g_snprintf(text, 255, \"xrdp_%8.8x_main_sync\", pid);\n    g_sync_event = g_create_wait_obj(text);\n    g_memset(&g_service_status, 0, sizeof(SERVICE_STATUS));\n    g_service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;\n    g_service_status.dwCurrentState = SERVICE_RUNNING;\n    g_service_status.dwControlsAccepted = SERVICE_CONTROL_INTERROGATE |\n                                          SERVICE_ACCEPT_STOP |\n                                          SERVICE_ACCEPT_SHUTDOWN;\n    g_service_status.dwWin32ExitCode = NO_ERROR;\n    g_service_status.dwServiceSpecificExitCode = 0;\n    g_service_status.dwCheckPoint = 0;\n    g_service_status.dwWaitHint = 0;\n    //  g_sprintf(text, \"calling RegisterServiceCtrlHandler\\r\\n\");\n    //  g_file_write(fd, text, g_strlen(text));\n    g_ssh = RegisterServiceCtrlHandler(\"xrdp\", MyHandler);\n\n    if (g_ssh != 0)\n    {\n        //    g_sprintf(text, \"ok\\r\\n\");\n        //    g_file_write(fd, text, g_strlen(text));\n        SetServiceStatus(g_ssh, &g_service_status);\n        g_listen = xrdp_listen_create();\n        xrdp_listen_main_loop(g_listen);\n        g_sleep(100);\n        g_service_status.dwCurrentState = SERVICE_STOPPED;\n        SetServiceStatus(g_ssh, &g_service_status);\n    }\n    else\n    {\n        //g_sprintf(text, \"RegisterServiceCtrlHandler failed\\r\\n\");\n        //g_file_write(fd, text, g_strlen(text));\n    }\n\n    xrdp_listen_delete(g_listen);\n    tc_mutex_delete(g_sync_mutex);\n    tc_mutex_delete(g_sync1_mutex);\n    g_destroy_wait_obj(g_term_event);\n    g_destroy_wait_obj(g_sync_event);\n    WSACleanup();\n    //CloseHandle(event_han);\n}\n\n#endif\n/*****************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    int test;\n    int host_be;\n#if defined(_WIN32)\n    WSADATA w;\n    SC_HANDLE sc_man;\n    SC_HANDLE sc_ser;\n    int run_as_service;\n    SERVICE_TABLE_ENTRY te[2];\n#else\n    int pid;\n    int fd;\n    int no_daemon;\n    char text[256];\n    char pid_file[256];\n#endif\n\n    g_init();\n    ssl_init();\n    /* check compiled endian with actual endian */\n    test = 1;\n    host_be = !((int)(*(unsigned char *)(&test)));\n#if defined(B_ENDIAN)\n\n    if (!host_be)\n#endif\n#if defined(L_ENDIAN)\n        if (host_be)\n#endif\n        {\n            g_writeln(\"endian wrong, edit arch.h\");\n            return 0;\n        }\n\n    /* check long, int and void* sizes */\n#if SIZEOF_INT != 4\n#   error unusable int size, must be 4\n#endif\n\n#if SIZEOF_LONG != SIZEOF_VOID_P\n#   error sizeof(long) must match sizeof(void*)\n#endif\n\n#if SIZEOF_LONG != 4 && SIZEOF_LONG != 8\n#   error sizeof(long), must be 4 or 8\n#endif\n\n    if (sizeof(tui64) != 8)\n    {\n        g_writeln(\"unusable tui64 size, must be 8\");\n        return 0;\n    }\n\n#if defined(_WIN32)\n    run_as_service = 1;\n\n    if (argc == 2)\n    {\n        if (g_strncasecmp(argv[1], \"-help\", 255) == 0 ||\n                g_strncasecmp(argv[1], \"--help\", 255) == 0 ||\n                g_strncasecmp(argv[1], \"-h\", 255) == 0)\n        {\n            g_writeln(\"%s\", \"\");\n            g_writeln(\"xrdp: A Remote Desktop Protocol server.\");\n            g_writeln(\"Copyright (C) Jay Sorg 2004-2011\");\n            g_writeln(\"See http://www.xrdp.org for more information.\");\n            g_writeln(\"%s\", \"\");\n            g_writeln(\"Usage: xrdp [options]\");\n            g_writeln(\"   -h: show help\");\n            g_writeln(\"   -install: install service\");\n            g_writeln(\"   -remove: remove service\");\n            g_writeln(\"%s\", \"\");\n            g_exit(0);\n        }\n        else if (g_strncasecmp(argv[1], \"-install\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"--install\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"-i\", 255) == 0)\n        {\n            /* open service manager */\n            sc_man = OpenSCManager(0, 0, GENERIC_WRITE);\n\n            if (sc_man == 0)\n            {\n                g_writeln(\"error OpenSCManager, do you have rights?\");\n                g_exit(0);\n            }\n\n            /* check if service is already installed */\n            sc_ser = OpenService(sc_man, \"xrdp\", SERVICE_ALL_ACCESS);\n\n            if (sc_ser == 0)\n            {\n                /* install service */\n                CreateService(sc_man, \"xrdp\", \"xrdp\", SERVICE_ALL_ACCESS,\n                              SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,\n                              SERVICE_ERROR_IGNORE, \"c:\\\\temp\\\\xrdp\\\\xrdp.exe\",\n                              0, 0, 0, 0, 0);\n\n            }\n            else\n            {\n                g_writeln(\"error service is already installed\");\n                CloseServiceHandle(sc_ser);\n                CloseServiceHandle(sc_man);\n                g_exit(0);\n            }\n\n            CloseServiceHandle(sc_man);\n            g_exit(0);\n        }\n        else if (g_strncasecmp(argv[1], \"-remove\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"--remove\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"-r\", 255) == 0)\n        {\n            /* open service manager */\n            sc_man = OpenSCManager(0, 0, GENERIC_WRITE);\n\n            if (sc_man == 0)\n            {\n                g_writeln(\"error OpenSCManager, do you have rights?\");\n                g_exit(0);\n            }\n\n            /* check if service is already installed */\n            sc_ser = OpenService(sc_man, \"xrdp\", SERVICE_ALL_ACCESS);\n\n            if (sc_ser == 0)\n            {\n                g_writeln(\"error service is not installed\");\n                CloseServiceHandle(sc_man);\n                g_exit(0);\n            }\n\n            DeleteService(sc_ser);\n            CloseServiceHandle(sc_man);\n            g_exit(0);\n        }\n        else\n        {\n            g_writeln(\"Unknown Parameter\");\n            g_writeln(\"xrdp -h for help\");\n            g_writeln(\"%s\", \"\");\n            g_exit(0);\n        }\n    }\n    else if (argc > 1)\n    {\n        g_writeln(\"Unknown Parameter\");\n        g_writeln(\"xrdp -h for help\");\n        g_writeln(\"%s\", \"\");\n        g_exit(0);\n    }\n\n    if (run_as_service)\n    {\n        g_memset(&te, 0, sizeof(te));\n        te[0].lpServiceName = \"xrdp\";\n        te[0].lpServiceProc = MyServiceMain;\n        StartServiceCtrlDispatcher(&te);\n        g_exit(0);\n    }\n\n    WSAStartup(2, &w);\n#else /* _WIN32 */\n    g_snprintf(pid_file, 255, \"%s/xrdp.pid\", XRDP_PID_PATH);\n    no_daemon = 0;\n\n    if (argc == 2)\n    {\n        if ((g_strncasecmp(argv[1], \"-kill\", 255) == 0) ||\n                (g_strncasecmp(argv[1], \"--kill\", 255) == 0) ||\n                (g_strncasecmp(argv[1], \"-k\", 255) == 0))\n        {\n            g_writeln(\"stopping xrdp\");\n            /* read the xrdp.pid file */\n            fd = -1;\n\n            if (g_file_exist(pid_file)) /* xrdp.pid */\n            {\n                fd = g_file_open_ro(pid_file); /* xrdp.pid */\n            }\n\n            if (fd == -1)\n            {\n                g_writeln(\"cannot open %s, maybe xrdp is not running\",\n                          pid_file);\n            }\n            else\n            {\n                g_memset(text, 0, 32);\n                g_file_read(fd, text, 31);\n                pid = g_atoi(text);\n                g_writeln(\"stopping process id %d\", pid);\n\n                if (pid > 0)\n                {\n                    g_sigterm(pid);\n                }\n\n                g_file_close(fd);\n            }\n\n            g_exit(0);\n        }\n        else if (g_strncasecmp(argv[1], \"-nodaemon\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"--nodaemon\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"-nd\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"--nd\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"-ns\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"--ns\", 255) == 0)\n        {\n            no_daemon = 1;\n        }\n        else if (g_strncasecmp(argv[1], \"-help\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"--help\", 255) == 0 ||\n                 g_strncasecmp(argv[1], \"-h\", 255) == 0)\n        {\n            g_writeln(\"%s\", \"\");\n            g_writeln(\"xrdp: A Remote Desktop Protocol server.\");\n            g_writeln(\"Copyright (C) Jay Sorg 2004-2011\");\n            g_writeln(\"See http://www.xrdp.org for more information.\");\n            g_writeln(\"%s\", \"\");\n            g_writeln(\"Usage: xrdp [options]\");\n            g_writeln(\"   -h: show help\");\n            g_writeln(\"   -nodaemon: don't fork into background\");\n            g_writeln(\"   -kill: shut down xrdp\");\n            g_writeln(\"%s\", \"\");\n            g_exit(0);\n        }\n        else if ((g_strncasecmp(argv[1], \"-v\", 255) == 0) ||\n                 (g_strncasecmp(argv[1], \"--version\", 255) == 0))\n        {\n            g_writeln(\"%s\", \"\");\n            g_writeln(\"xrdp: A Remote Desktop Protocol server.\");\n            g_writeln(\"Copyright (C) Jay Sorg 2004-2011\");\n            g_writeln(\"See http://www.xrdp.org for more information.\");\n            g_writeln(\"Version %s\", PACKAGE_VERSION);\n            g_writeln(\"%s\", \"\");\n            g_exit(0);\n        }\n        else\n        {\n            g_writeln(\"Unknown Parameter\");\n            g_writeln(\"xrdp -h for help\");\n            g_writeln(\"%s\", \"\");\n            g_exit(0);\n        }\n    }\n    else if (argc > 1)\n    {\n        g_writeln(\"Unknown Parameter\");\n        g_writeln(\"xrdp -h for help\");\n        g_writeln(\"%s\", \"\");\n        g_exit(0);\n    }\n\n    if (g_file_exist(pid_file)) /* xrdp.pid */\n    {\n        g_writeln(\"It looks like xrdp is already running.\");\n        g_writeln(\"If not, delete %s and try again.\", pid_file);\n        g_exit(0);\n    }\n\n    if (!no_daemon)\n    {\n        /* make sure we can write to pid file */\n        fd = g_file_open_rw(pid_file); /* xrdp.pid */\n\n        if (fd == -1)\n        {\n            g_writeln(\"running in daemon mode with no access to pid files, quitting\");\n            g_exit(0);\n        }\n\n        if (g_file_write(fd, \"0\", 1) == -1)\n        {\n            g_writeln(\"running in daemon mode with no access to pid files, quitting\");\n            g_exit(0);\n        }\n\n        g_file_close(fd);\n        g_file_delete(pid_file);\n    }\n\n    if (!no_daemon)\n    {\n        /* start of daemonizing code */\n        pid = g_fork();\n\n        if (pid == -1)\n        {\n            g_writeln(\"problem forking\");\n            g_exit(1);\n        }\n\n        if (0 != pid)\n        {\n            g_writeln(\"process %d started ok\", pid);\n            /* exit, this is the main process */\n            g_exit(0);\n        }\n\n        g_sleep(1000);\n        g_file_close(0);\n        g_file_close(1);\n        g_file_close(2);\n        g_file_open_rw(\"/dev/null\");\n        g_file_open_rw(\"/dev/null\");\n        g_file_open_rw(\"/dev/null\");\n        /* end of daemonizing code */\n    }\n\n    if (!no_daemon)\n    {\n        /* write the pid to file */\n        pid = g_getpid();\n        fd = g_file_open_rw(pid_file); /* xrdp.pid */\n\n        if (fd == -1)\n        {\n            g_writeln(\"trying to write process id to xrdp.pid\");\n            g_writeln(\"problem opening xrdp.pid\");\n            g_writeln(\"maybe no rights\");\n        }\n        else\n        {\n            g_sprintf(text, \"%d\", pid);\n            g_file_write(fd, text, g_strlen(text));\n            g_file_close(fd);\n        }\n    }\n\n#endif\n    g_threadid = tc_get_threadid();\n    g_listen = xrdp_listen_create();\n    g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */\n    g_signal_pipe(pipe_sig); /* SIGPIPE */\n    g_signal_terminate(xrdp_shutdown); /* SIGTERM */\n    g_sync_mutex = tc_mutex_create();\n    g_sync1_mutex = tc_mutex_create();\n    pid = g_getpid();\n    g_snprintf(text, 255, \"xrdp_%8.8x_main_term\", pid);\n    g_term_event = g_create_wait_obj(text);\n    g_snprintf(text, 255, \"xrdp_%8.8x_main_sync\", pid);\n    g_sync_event = g_create_wait_obj(text);\n\n    if (g_term_event == 0)\n    {\n        g_writeln(\"error creating g_term_event\");\n    }\n\n    xrdp_listen_main_loop(g_listen);\n    xrdp_listen_delete(g_listen);\n    tc_mutex_delete(g_sync_mutex);\n    tc_mutex_delete(g_sync1_mutex);\n    g_delete_wait_obj(g_term_event);\n    g_delete_wait_obj(g_sync_event);\n#if defined(_WIN32)\n    /* I don't think it ever gets here */\n    /* when running in win32 app mode, control c exits right away */\n    WSACleanup();\n#else\n    /* delete the xrdp.pid file */\n    g_file_delete(pid_file);\n#endif\n    return 0;\n}\n"
  },
  {
    "path": "xrdp_accel_assist/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n  -I$(top_srcdir)/common\n\nEXTRA_DIST = xrdp_accel_assist_shaders.c\n\nXRDP_EXTRA_LIBS =\nXRDP_EXTRA_SOURCES =\n\nif XRDP_NVENC\nAM_CPPFLAGS += -DXRDP_NVENC\nAM_CPPFLAGS += $(XRDP_NVENC_CFLAGS)\nXRDP_EXTRA_LIBS += $(XRDP_NVENC_LIBS)\nXRDP_EXTRA_SOURCES += xrdp_accel_assist_nvenc.c xrdp_accel_assist_nvenc.h encoder_headers/nvEncodeAPI_11_1.h\nendif\n\npkglibexec_PROGRAMS = \\\n  xrdp-accel-assist\n\nxrdp_accel_assist_SOURCES = \\\n  xrdp_accel_assist.c \\\n  xrdp_accel_assist.h \\\n  xrdp_accel_assist_x11.c \\\n  xrdp_accel_assist_x11.h \\\n  xrdp_accel_assist_egl.c \\\n  xrdp_accel_assist_egl.h \\\n  xrdp_accel_assist_glx.c \\\n  xrdp_accel_assist_glx.h \\\n  $(XRDP_EXTRA_SOURCES)\n\nxrdp_accel_assist_LDADD = \\\n  $(top_builddir)/common/libcommon.la \\\n  $(XRDP_EXTRA_LIBS) \\\n  -lX11 -lepoxy\n\n"
  },
  {
    "path": "xrdp_accel_assist/encoder_headers/nvEncodeAPI_11_0.h",
    "content": "/*\n * This copyright notice applies to this header file only:\n *\n * Copyright (c) 2010-2020 NVIDIA Corporation\n *\n * Permission is hereby granted, free of charge, to any person\n * obtaining a copy of this software and associated documentation\n * files (the \"Software\"), to deal in the Software without\n * restriction, including without limitation the rights to use,\n * copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the software, and to permit persons to whom the\n * software is furnished to do so, subject to the following\n * conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n * OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/**\n * \\file nvEncodeAPI.h\n *   NVIDIA GPUs - beginning with the Kepler generation - contain a hardware-based encoder\n *   (referred to as NVENC) which provides fully-accelerated hardware-based video encoding.\n *   NvEncodeAPI provides the interface for NVIDIA video encoder (NVENC).\n * \\date 2011-2020\n *  This file contains the interface constants, structure definitions and function prototypes.\n */\n\n#ifndef _NV_ENCODEAPI_H_\n#define _NV_ENCODEAPI_H_\n\n#include <stdlib.h>\n\n#ifdef _WIN32\n#include <windows.h>\n#endif\n\n#ifdef _MSC_VER\n#ifndef _STDINT\ntypedef __int32 int32_t;\ntypedef unsigned __int32 uint32_t;\ntypedef __int64 int64_t;\ntypedef unsigned __int64 uint64_t;\ntypedef signed char int8_t;\ntypedef unsigned char uint8_t;\ntypedef short int16_t;\ntypedef unsigned short uint16_t;\n#endif\n#else\n#include <stdint.h>\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/**\n * \\addtogroup ENCODER_STRUCTURE NvEncodeAPI Data structures\n * @{\n */\n\n#ifdef _WIN32\n#define NVENCAPI     __stdcall\ntypedef RECT NVENC_RECT;\n#else\n#define NVENCAPI\n// =========================================================================================\n#if !defined(GUID) && !defined(GUID_DEFINED)\n/*!\n * \\struct GUID\n * Abstracts the GUID structure for non-windows platforms.\n */\n// =========================================================================================\ntypedef struct\n{\n    uint32_t Data1;                                      /**< [in]: Specifies the first 8 hexadecimal digits of the GUID.                                */\n    uint16_t Data2;                                      /**< [in]: Specifies the first group of 4 hexadecimal digits.                                   */\n    uint16_t Data3;                                      /**< [in]: Specifies the second group of 4 hexadecimal digits.                                  */\n    uint8_t  Data4[8];                                   /**< [in]: Array of 8 bytes. The first 2 bytes contain the third group of 4 hexadecimal digits.\n                                                                    The remaining 6 bytes contain the final 12 hexadecimal digits.                       */\n} GUID;\n#endif // GUID\n\n/**\n * \\struct _NVENC_RECT\n * Defines a Rectangle. Used in ::NV_ENC_PREPROCESS_FRAME.\n */\ntypedef struct _NVENC_RECT\n{\n    uint32_t left;                                        /**< [in]: X coordinate of the upper left corner of rectangular area to be specified.       */\n    uint32_t top;                                         /**< [in]: Y coordinate of the upper left corner of the rectangular area to be specified.   */\n    uint32_t right;                                       /**< [in]: X coordinate of the bottom right corner of the rectangular area to be specified. */\n    uint32_t bottom;                                      /**< [in]: Y coordinate of the bottom right corner of the rectangular area to be specified. */\n} NVENC_RECT;\n\n#endif // _WIN32\n\n/** @} */ /* End of GUID and NVENC_RECT structure grouping*/\n\ntypedef void *NV_ENC_INPUT_PTR;             /**< NVENCODE API input buffer                              */\ntypedef void *NV_ENC_OUTPUT_PTR;            /**< NVENCODE API output buffer*/\ntypedef void *NV_ENC_REGISTERED_PTR;        /**< A Resource that has been registered with NVENCODE API*/\ntypedef void *NV_ENC_CUSTREAM_PTR;          /**< Pointer to CUstream*/\n\n#define NVENCAPI_MAJOR_VERSION 11\n#define NVENCAPI_MINOR_VERSION 0\n\n#define NVENCAPI_VERSION (NVENCAPI_MAJOR_VERSION | (NVENCAPI_MINOR_VERSION << 24))\n\n/**\n * Macro to generate per-structure version for use with API.\n */\n#define NVENCAPI_STRUCT_VERSION(ver) ((uint32_t)NVENCAPI_VERSION | ((ver)<<16) | (0x7 << 28))\n\n\n#define NVENC_INFINITE_GOPLENGTH  0xffffffff\n\n#define NV_MAX_SEQ_HDR_LEN  (512)\n\n#ifdef __GNUC__\n#define NV_ENC_DEPRECATED __attribute__ ((deprecated(\"WILL BE REMOVED IN A FUTURE VIDEO CODEC SDK VERSION\")))\n#elif defined(_MSC_VER)\n#define NV_ENC_DEPRECATED __declspec(deprecated(\"WILL BE REMOVED IN A FUTURE VIDEO CODEC SDK VERSION\"))\n#endif\n\n// =========================================================================================\n// Encode Codec GUIDS supported by the NvEncodeAPI interface.\n// =========================================================================================\n\n// {6BC82762-4E63-4ca4-AA85-1E50F321F6BF}\nstatic const GUID NV_ENC_CODEC_H264_GUID =\n{ 0x6bc82762, 0x4e63, 0x4ca4, { 0xaa, 0x85, 0x1e, 0x50, 0xf3, 0x21, 0xf6, 0xbf } };\n\n// {790CDC88-4522-4d7b-9425-BDA9975F7603}\nstatic const GUID NV_ENC_CODEC_HEVC_GUID =\n{ 0x790cdc88, 0x4522, 0x4d7b, { 0x94, 0x25, 0xbd, 0xa9, 0x97, 0x5f, 0x76, 0x3 } };\n\n\n\n// =========================================================================================\n// *   Encode Profile GUIDS supported by the NvEncodeAPI interface.\n// =========================================================================================\n\n// {BFD6F8E7-233C-4341-8B3E-4818523803F4}\nstatic const GUID NV_ENC_CODEC_PROFILE_AUTOSELECT_GUID =\n{ 0xbfd6f8e7, 0x233c, 0x4341, { 0x8b, 0x3e, 0x48, 0x18, 0x52, 0x38, 0x3, 0xf4 } };\n\n// {0727BCAA-78C4-4c83-8C2F-EF3DFF267C6A}\nstatic const GUID  NV_ENC_H264_PROFILE_BASELINE_GUID =\n{ 0x727bcaa, 0x78c4, 0x4c83, { 0x8c, 0x2f, 0xef, 0x3d, 0xff, 0x26, 0x7c, 0x6a } };\n\n// {60B5C1D4-67FE-4790-94D5-C4726D7B6E6D}\nstatic const GUID  NV_ENC_H264_PROFILE_MAIN_GUID =\n{ 0x60b5c1d4, 0x67fe, 0x4790, { 0x94, 0xd5, 0xc4, 0x72, 0x6d, 0x7b, 0x6e, 0x6d } };\n\n// {E7CBC309-4F7A-4b89-AF2A-D537C92BE310}\nstatic const GUID NV_ENC_H264_PROFILE_HIGH_GUID =\n{ 0xe7cbc309, 0x4f7a, 0x4b89, { 0xaf, 0x2a, 0xd5, 0x37, 0xc9, 0x2b, 0xe3, 0x10 } };\n\n// {7AC663CB-A598-4960-B844-339B261A7D52}\nstatic const GUID  NV_ENC_H264_PROFILE_HIGH_444_GUID =\n{ 0x7ac663cb, 0xa598, 0x4960, { 0xb8, 0x44, 0x33, 0x9b, 0x26, 0x1a, 0x7d, 0x52 } };\n\n// {40847BF5-33F7-4601-9084-E8FE3C1DB8B7}\nstatic const GUID NV_ENC_H264_PROFILE_STEREO_GUID =\n{ 0x40847bf5, 0x33f7, 0x4601, { 0x90, 0x84, 0xe8, 0xfe, 0x3c, 0x1d, 0xb8, 0xb7 } };\n\n// {B405AFAC-F32B-417B-89C4-9ABEED3E5978}\nstatic const GUID NV_ENC_H264_PROFILE_PROGRESSIVE_HIGH_GUID =\n{ 0xb405afac, 0xf32b, 0x417b, { 0x89, 0xc4, 0x9a, 0xbe, 0xed, 0x3e, 0x59, 0x78 } };\n\n// {AEC1BD87-E85B-48f2-84C3-98BCA6285072}\nstatic const GUID NV_ENC_H264_PROFILE_CONSTRAINED_HIGH_GUID =\n{ 0xaec1bd87, 0xe85b, 0x48f2, { 0x84, 0xc3, 0x98, 0xbc, 0xa6, 0x28, 0x50, 0x72 } };\n\n// {B514C39A-B55B-40fa-878F-F1253B4DFDEC}\nstatic const GUID NV_ENC_HEVC_PROFILE_MAIN_GUID =\n{ 0xb514c39a, 0xb55b, 0x40fa, { 0x87, 0x8f, 0xf1, 0x25, 0x3b, 0x4d, 0xfd, 0xec } };\n\n// {fa4d2b6c-3a5b-411a-8018-0a3f5e3c9be5}\nstatic const GUID NV_ENC_HEVC_PROFILE_MAIN10_GUID =\n{ 0xfa4d2b6c, 0x3a5b, 0x411a, { 0x80, 0x18, 0x0a, 0x3f, 0x5e, 0x3c, 0x9b, 0xe5 } };\n\n// For HEVC Main 444 8 bit and HEVC Main 444 10 bit profiles only\n// {51ec32b5-1b4c-453c-9cbd-b616bd621341}\nstatic const GUID NV_ENC_HEVC_PROFILE_FREXT_GUID =\n{ 0x51ec32b5, 0x1b4c, 0x453c, { 0x9c, 0xbd, 0xb6, 0x16, 0xbd, 0x62, 0x13, 0x41 } };\n\n// =========================================================================================\n// *   Preset GUIDS supported by the NvEncodeAPI interface.\n// =========================================================================================\n// {B2DFB705-4EBD-4C49-9B5F-24A777D3E587}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_DEFAULT_GUID =\n{ 0xb2dfb705, 0x4ebd, 0x4c49, { 0x9b, 0x5f, 0x24, 0xa7, 0x77, 0xd3, 0xe5, 0x87 } };\n\n// {60E4C59F-E846-4484-A56D-CD45BE9FDDF6}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_HP_GUID =\n{ 0x60e4c59f, 0xe846, 0x4484, { 0xa5, 0x6d, 0xcd, 0x45, 0xbe, 0x9f, 0xdd, 0xf6 } };\n\n// {34DBA71D-A77B-4B8F-9C3E-B6D5DA24C012}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_HQ_GUID =\n{ 0x34dba71d, 0xa77b, 0x4b8f, { 0x9c, 0x3e, 0xb6, 0xd5, 0xda, 0x24, 0xc0, 0x12 } };\n\n// {82E3E450-BDBB-4e40-989C-82A90DF9EF32}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_BD_GUID  =\n{ 0x82e3e450, 0xbdbb, 0x4e40, { 0x98, 0x9c, 0x82, 0xa9, 0xd, 0xf9, 0xef, 0x32 } };\n\n// {49DF21C5-6DFA-4feb-9787-6ACC9EFFB726}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOW_LATENCY_DEFAULT_GUID  =\n{ 0x49df21c5, 0x6dfa, 0x4feb, { 0x97, 0x87, 0x6a, 0xcc, 0x9e, 0xff, 0xb7, 0x26 } };\n\n// {C5F733B9-EA97-4cf9-BEC2-BF78A74FD105}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOW_LATENCY_HQ_GUID  =\n{ 0xc5f733b9, 0xea97, 0x4cf9, { 0xbe, 0xc2, 0xbf, 0x78, 0xa7, 0x4f, 0xd1, 0x5 } };\n\n// {67082A44-4BAD-48FA-98EA-93056D150A58}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOW_LATENCY_HP_GUID =\n{ 0x67082a44, 0x4bad, 0x48fa, { 0x98, 0xea, 0x93, 0x5, 0x6d, 0x15, 0xa, 0x58 } };\n\n// {D5BFB716-C604-44e7-9BB8-DEA5510FC3AC}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOSSLESS_DEFAULT_GUID =\n{ 0xd5bfb716, 0xc604, 0x44e7, { 0x9b, 0xb8, 0xde, 0xa5, 0x51, 0xf, 0xc3, 0xac } };\n\n// {149998E7-2364-411d-82EF-179888093409}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOSSLESS_HP_GUID =\n{ 0x149998e7, 0x2364, 0x411d, { 0x82, 0xef, 0x17, 0x98, 0x88, 0x9, 0x34, 0x9 } };\n\n// Performance degrades and quality improves as we move from P1 to P7. Presets P3 to P7 for H264 and Presets P2 to P7 for HEVC have B frames enabled by default\n// for HIGH_QUALITY and LOSSLESS tuning info, and will not work with Weighted Prediction enabled. In case Weighted Prediction is required, disable B frames by\n// setting frameIntervalP = 1\n// {FC0A8D3E-45F8-4CF8-80C7-298871590EBF}\nstatic const GUID NV_ENC_PRESET_P1_GUID   =\n{ 0xfc0a8d3e, 0x45f8, 0x4cf8, { 0x80, 0xc7, 0x29, 0x88, 0x71, 0x59, 0xe, 0xbf } };\n\n// {F581CFB8-88D6-4381-93F0-DF13F9C27DAB}\nstatic const GUID NV_ENC_PRESET_P2_GUID   =\n{ 0xf581cfb8, 0x88d6, 0x4381, { 0x93, 0xf0, 0xdf, 0x13, 0xf9, 0xc2, 0x7d, 0xab } };\n\n// {36850110-3A07-441F-94D5-3670631F91F6}\nstatic const GUID NV_ENC_PRESET_P3_GUID   =\n{ 0x36850110, 0x3a07, 0x441f, { 0x94, 0xd5, 0x36, 0x70, 0x63, 0x1f, 0x91, 0xf6 } };\n\n// {90A7B826-DF06-4862-B9D2-CD6D73A08681}\nstatic const GUID NV_ENC_PRESET_P4_GUID   =\n{ 0x90a7b826, 0xdf06, 0x4862, { 0xb9, 0xd2, 0xcd, 0x6d, 0x73, 0xa0, 0x86, 0x81 } };\n\n// {21C6E6B4-297A-4CBA-998F-B6CBDE72ADE3}\nstatic const GUID NV_ENC_PRESET_P5_GUID   =\n{ 0x21c6e6b4, 0x297a, 0x4cba, { 0x99, 0x8f, 0xb6, 0xcb, 0xde, 0x72, 0xad, 0xe3 } };\n\n// {8E75C279-6299-4AB6-8302-0B215A335CF5}\nstatic const GUID NV_ENC_PRESET_P6_GUID   =\n{ 0x8e75c279, 0x6299, 0x4ab6, { 0x83, 0x2, 0xb, 0x21, 0x5a, 0x33, 0x5c, 0xf5 } };\n\n// {84848C12-6F71-4C13-931B-53E283F57974}\nstatic const GUID NV_ENC_PRESET_P7_GUID   =\n{ 0x84848c12, 0x6f71, 0x4c13, { 0x93, 0x1b, 0x53, 0xe2, 0x83, 0xf5, 0x79, 0x74 } };\n\n/**\n * \\addtogroup ENCODER_STRUCTURE NvEncodeAPI Data structures\n * @{\n */\n\n/**\n * Input frame encode modes\n */\ntypedef enum _NV_ENC_PARAMS_FRAME_FIELD_MODE\n{\n    NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME = 0x01,  /**< Frame mode */\n    NV_ENC_PARAMS_FRAME_FIELD_MODE_FIELD = 0x02,  /**< Field mode */\n    NV_ENC_PARAMS_FRAME_FIELD_MODE_MBAFF = 0x03   /**< MB adaptive frame/field */\n} NV_ENC_PARAMS_FRAME_FIELD_MODE;\n\n/**\n * Rate Control Modes\n */\ntypedef enum _NV_ENC_PARAMS_RC_MODE\n{\n    NV_ENC_PARAMS_RC_CONSTQP                = 0x0,       /**< Constant QP mode */\n    NV_ENC_PARAMS_RC_VBR                    = 0x1,       /**< Variable bitrate mode */\n    NV_ENC_PARAMS_RC_CBR                    = 0x2,       /**< Constant bitrate mode */\n    NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ        = 0x8,       /**< Deprecated, use NV_ENC_PARAMS_RC_CBR + NV_ENC_TWO_PASS_QUARTER_RESOLUTION / NV_ENC_TWO_PASS_FULL_RESOLUTION +\n                                                              lowDelayKeyFrameScale=1 */\n    NV_ENC_PARAMS_RC_CBR_HQ                 = 0x10,      /**< Deprecated, use NV_ENC_PARAMS_RC_CBR + NV_ENC_TWO_PASS_QUARTER_RESOLUTION / NV_ENC_TWO_PASS_FULL_RESOLUTION */\n    NV_ENC_PARAMS_RC_VBR_HQ                 = 0x20       /**< Deprecated, use NV_ENC_PARAMS_RC_VBR + NV_ENC_TWO_PASS_QUARTER_RESOLUTION / NV_ENC_TWO_PASS_FULL_RESOLUTION */\n} NV_ENC_PARAMS_RC_MODE;\n\n/**\n * Multi Pass encoding\n */\ntypedef enum _NV_ENC_MULTI_PASS\n{\n    NV_ENC_MULTI_PASS_DISABLED              = 0x0,        /**< Single Pass */\n    NV_ENC_TWO_PASS_QUARTER_RESOLUTION      = 0x1,        /**< Two Pass encoding is enabled where first Pass is quarter resolution */\n    NV_ENC_TWO_PASS_FULL_RESOLUTION         = 0x2,        /**< Two Pass encoding is enabled where first Pass is full resolution */\n} NV_ENC_MULTI_PASS;\n\n/**\n * Emphasis Levels\n */\ntypedef enum _NV_ENC_EMPHASIS_MAP_LEVEL\n{\n    NV_ENC_EMPHASIS_MAP_LEVEL_0               = 0x0,       /**< Emphasis Map Level 0, for zero Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_1               = 0x1,       /**< Emphasis Map Level 1, for very low Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_2               = 0x2,       /**< Emphasis Map Level 2, for low Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_3               = 0x3,       /**< Emphasis Map Level 3, for medium Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_4               = 0x4,       /**< Emphasis Map Level 4, for high Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_5               = 0x5        /**< Emphasis Map Level 5, for very high Delta QP value */\n} NV_ENC_EMPHASIS_MAP_LEVEL;\n\n/**\n * QP MAP MODE\n */\ntypedef enum _NV_ENC_QP_MAP_MODE\n{\n    NV_ENC_QP_MAP_DISABLED               = 0x0,             /**< Value in NV_ENC_PIC_PARAMS::qpDeltaMap have no effect. */\n    NV_ENC_QP_MAP_EMPHASIS               = 0x1,             /**< Value in NV_ENC_PIC_PARAMS::qpDeltaMap will be treated as Emphasis level. Currently this is only supported for H264 */\n    NV_ENC_QP_MAP_DELTA                  = 0x2,             /**< Value in NV_ENC_PIC_PARAMS::qpDeltaMap will be treated as QP delta map. */\n    NV_ENC_QP_MAP                        = 0x3,             /**< Currently This is not supported. Value in NV_ENC_PIC_PARAMS::qpDeltaMap will be treated as QP value.   */\n} NV_ENC_QP_MAP_MODE;\n\n#define NV_ENC_PARAMS_RC_VBR_MINQP              (NV_ENC_PARAMS_RC_MODE)0x4          /**< Deprecated */\n#define NV_ENC_PARAMS_RC_2_PASS_QUALITY         NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ    /**< Deprecated */\n#define NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP   NV_ENC_PARAMS_RC_CBR_HQ             /**< Deprecated */\n#define NV_ENC_PARAMS_RC_2_PASS_VBR             NV_ENC_PARAMS_RC_VBR_HQ             /**< Deprecated */\n#define NV_ENC_PARAMS_RC_CBR2                   NV_ENC_PARAMS_RC_CBR                /**< Deprecated */\n\n/**\n * Input picture structure\n */\ntypedef enum _NV_ENC_PIC_STRUCT\n{\n    NV_ENC_PIC_STRUCT_FRAME             = 0x01,                 /**< Progressive frame */\n    NV_ENC_PIC_STRUCT_FIELD_TOP_BOTTOM  = 0x02,                 /**< Field encoding top field first */\n    NV_ENC_PIC_STRUCT_FIELD_BOTTOM_TOP  = 0x03                  /**< Field encoding bottom field first */\n} NV_ENC_PIC_STRUCT;\n\n/**\n * Input picture type\n */\ntypedef enum _NV_ENC_PIC_TYPE\n{\n    NV_ENC_PIC_TYPE_P               = 0x0,     /**< Forward predicted */\n    NV_ENC_PIC_TYPE_B               = 0x01,    /**< Bi-directionally predicted picture */\n    NV_ENC_PIC_TYPE_I               = 0x02,    /**< Intra predicted picture */\n    NV_ENC_PIC_TYPE_IDR             = 0x03,    /**< IDR picture */\n    NV_ENC_PIC_TYPE_BI              = 0x04,    /**< Bi-directionally predicted with only Intra MBs */\n    NV_ENC_PIC_TYPE_SKIPPED         = 0x05,    /**< Picture is skipped */\n    NV_ENC_PIC_TYPE_INTRA_REFRESH   = 0x06,    /**< First picture in intra refresh cycle */\n    NV_ENC_PIC_TYPE_NONREF_P        = 0x07,    /**< Non reference P picture */\n    NV_ENC_PIC_TYPE_UNKNOWN         = 0xFF     /**< Picture type unknown */\n} NV_ENC_PIC_TYPE;\n\n/**\n * Motion vector precisions\n */\ntypedef enum _NV_ENC_MV_PRECISION\n{\n    NV_ENC_MV_PRECISION_DEFAULT     = 0x0,     /**< Driver selects Quarter-Pel motion vector precision by default */\n    NV_ENC_MV_PRECISION_FULL_PEL    = 0x01,    /**< Full-Pel motion vector precision */\n    NV_ENC_MV_PRECISION_HALF_PEL    = 0x02,    /**< Half-Pel motion vector precision */\n    NV_ENC_MV_PRECISION_QUARTER_PEL = 0x03     /**< Quarter-Pel motion vector precision */\n} NV_ENC_MV_PRECISION;\n\n\n/**\n * Input buffer formats\n */\ntypedef enum _NV_ENC_BUFFER_FORMAT\n{\n    NV_ENC_BUFFER_FORMAT_UNDEFINED                       = 0x00000000,  /**< Undefined buffer format */\n\n    NV_ENC_BUFFER_FORMAT_NV12                            = 0x00000001,  /**< Semi-Planar YUV [Y plane followed by interleaved UV plane] */\n    NV_ENC_BUFFER_FORMAT_YV12                            = 0x00000010,  /**< Planar YUV [Y plane followed by V and U planes] */\n    NV_ENC_BUFFER_FORMAT_IYUV                            = 0x00000100,  /**< Planar YUV [Y plane followed by U and V planes] */\n    NV_ENC_BUFFER_FORMAT_YUV444                          = 0x00001000,  /**< Planar YUV [Y plane followed by U and V planes] */\n    NV_ENC_BUFFER_FORMAT_YUV420_10BIT                    = 0x00010000,  /**< 10 bit Semi-Planar YUV [Y plane followed by interleaved UV plane]. Each pixel of size 2 bytes. Most Significant 10 bits contain pixel data. */\n    NV_ENC_BUFFER_FORMAT_YUV444_10BIT                    = 0x00100000,  /**< 10 bit Planar YUV444 [Y plane followed by U and V planes]. Each pixel of size 2 bytes. Most Significant 10 bits contain pixel data.  */\n    NV_ENC_BUFFER_FORMAT_ARGB                            = 0x01000000,  /**< 8 bit Packed A8R8G8B8. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with B\n                                                                             in the lowest 8 bits, G in the next 8 bits, R in the\n                                                                             8 bits after that and A in the highest 8 bits. */\n    NV_ENC_BUFFER_FORMAT_ARGB10                          = 0x02000000,  /**< 10 bit Packed A2R10G10B10. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with B\n                                                                             in the lowest 10 bits, G in the next 10 bits, R in the\n                                                                             10 bits after that and A in the highest 2 bits. */\n    NV_ENC_BUFFER_FORMAT_AYUV                            = 0x04000000,  /**< 8 bit Packed A8Y8U8V8. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with V\n                                                                             in the lowest 8 bits, U in the next 8 bits, Y in the\n                                                                             8 bits after that and A in the highest 8 bits. */\n    NV_ENC_BUFFER_FORMAT_ABGR                            = 0x10000000,  /**< 8 bit Packed A8B8G8R8. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with R\n                                                                             in the lowest 8 bits, G in the next 8 bits, B in the\n                                                                             8 bits after that and A in the highest 8 bits. */\n    NV_ENC_BUFFER_FORMAT_ABGR10                          = 0x20000000,  /**< 10 bit Packed A2B10G10R10. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with R\n                                                                             in the lowest 10 bits, G in the next 10 bits, B in the\n                                                                             10 bits after that and A in the highest 2 bits. */\n    NV_ENC_BUFFER_FORMAT_U8                              = 0x40000000,  /**< Buffer format representing one-dimensional buffer.\n                                                                             This format should be used only when registering the\n                                                                             resource as output buffer, which will be used to write\n                                                                             the encoded bit stream or H.264 ME only mode output. */\n} NV_ENC_BUFFER_FORMAT;\n\n#define NV_ENC_BUFFER_FORMAT_NV12_PL NV_ENC_BUFFER_FORMAT_NV12\n#define NV_ENC_BUFFER_FORMAT_YV12_PL NV_ENC_BUFFER_FORMAT_YV12\n#define NV_ENC_BUFFER_FORMAT_IYUV_PL NV_ENC_BUFFER_FORMAT_IYUV\n#define NV_ENC_BUFFER_FORMAT_YUV444_PL NV_ENC_BUFFER_FORMAT_YUV444\n\n/**\n * Encoding levels\n */\ntypedef enum _NV_ENC_LEVEL\n{\n    NV_ENC_LEVEL_AUTOSELECT         = 0,\n\n    NV_ENC_LEVEL_H264_1             = 10,\n    NV_ENC_LEVEL_H264_1b            = 9,\n    NV_ENC_LEVEL_H264_11            = 11,\n    NV_ENC_LEVEL_H264_12            = 12,\n    NV_ENC_LEVEL_H264_13            = 13,\n    NV_ENC_LEVEL_H264_2             = 20,\n    NV_ENC_LEVEL_H264_21            = 21,\n    NV_ENC_LEVEL_H264_22            = 22,\n    NV_ENC_LEVEL_H264_3             = 30,\n    NV_ENC_LEVEL_H264_31            = 31,\n    NV_ENC_LEVEL_H264_32            = 32,\n    NV_ENC_LEVEL_H264_4             = 40,\n    NV_ENC_LEVEL_H264_41            = 41,\n    NV_ENC_LEVEL_H264_42            = 42,\n    NV_ENC_LEVEL_H264_5             = 50,\n    NV_ENC_LEVEL_H264_51            = 51,\n    NV_ENC_LEVEL_H264_52            = 52,\n    NV_ENC_LEVEL_H264_60            = 60,\n    NV_ENC_LEVEL_H264_61            = 61,\n    NV_ENC_LEVEL_H264_62            = 62,\n\n    NV_ENC_LEVEL_HEVC_1             = 30,\n    NV_ENC_LEVEL_HEVC_2             = 60,\n    NV_ENC_LEVEL_HEVC_21            = 63,\n    NV_ENC_LEVEL_HEVC_3             = 90,\n    NV_ENC_LEVEL_HEVC_31            = 93,\n    NV_ENC_LEVEL_HEVC_4             = 120,\n    NV_ENC_LEVEL_HEVC_41            = 123,\n    NV_ENC_LEVEL_HEVC_5             = 150,\n    NV_ENC_LEVEL_HEVC_51            = 153,\n    NV_ENC_LEVEL_HEVC_52            = 156,\n    NV_ENC_LEVEL_HEVC_6             = 180,\n    NV_ENC_LEVEL_HEVC_61            = 183,\n    NV_ENC_LEVEL_HEVC_62            = 186,\n\n    NV_ENC_TIER_HEVC_MAIN           = 0,\n    NV_ENC_TIER_HEVC_HIGH           = 1\n} NV_ENC_LEVEL;\n\n/**\n * Error Codes\n */\ntypedef enum _NVENCSTATUS\n{\n    /**\n     * This indicates that API call returned with no errors.\n     */\n    NV_ENC_SUCCESS,\n\n    /**\n     * This indicates that no encode capable devices were detected.\n     */\n    NV_ENC_ERR_NO_ENCODE_DEVICE,\n\n    /**\n     * This indicates that devices pass by the client is not supported.\n     */\n    NV_ENC_ERR_UNSUPPORTED_DEVICE,\n\n    /**\n     * This indicates that the encoder device supplied by the client is not\n     * valid.\n     */\n    NV_ENC_ERR_INVALID_ENCODERDEVICE,\n\n    /**\n     * This indicates that device passed to the API call is invalid.\n     */\n    NV_ENC_ERR_INVALID_DEVICE,\n\n    /**\n     * This indicates that device passed to the API call is no longer available and\n     * needs to be reinitialized. The clients need to destroy the current encoder\n     * session by freeing the allocated input output buffers and destroying the device\n     * and create a new encoding session.\n     */\n    NV_ENC_ERR_DEVICE_NOT_EXIST,\n\n    /**\n     * This indicates that one or more of the pointers passed to the API call\n     * is invalid.\n     */\n    NV_ENC_ERR_INVALID_PTR,\n\n    /**\n     * This indicates that completion event passed in ::NvEncEncodePicture() call\n     * is invalid.\n     */\n    NV_ENC_ERR_INVALID_EVENT,\n\n    /**\n     * This indicates that one or more of the parameter passed to the API call\n     * is invalid.\n     */\n    NV_ENC_ERR_INVALID_PARAM,\n\n    /**\n     * This indicates that an API call was made in wrong sequence/order.\n     */\n    NV_ENC_ERR_INVALID_CALL,\n\n    /**\n     * This indicates that the API call failed because it was unable to allocate\n     * enough memory to perform the requested operation.\n     */\n    NV_ENC_ERR_OUT_OF_MEMORY,\n\n    /**\n     * This indicates that the encoder has not been initialized with\n     * ::NvEncInitializeEncoder() or that initialization has failed.\n     * The client cannot allocate input or output buffers or do any encoding\n     * related operation before successfully initializing the encoder.\n     */\n    NV_ENC_ERR_ENCODER_NOT_INITIALIZED,\n\n    /**\n     * This indicates that an unsupported parameter was passed by the client.\n     */\n    NV_ENC_ERR_UNSUPPORTED_PARAM,\n\n    /**\n     * This indicates that the ::NvEncLockBitstream() failed to lock the output\n     * buffer. This happens when the client makes a non blocking lock call to\n     * access the output bitstream by passing NV_ENC_LOCK_BITSTREAM::doNotWait flag.\n     * This is not a fatal error and client should retry the same operation after\n     * few milliseconds.\n     */\n    NV_ENC_ERR_LOCK_BUSY,\n\n    /**\n     * This indicates that the size of the user buffer passed by the client is\n     * insufficient for the requested operation.\n     */\n    NV_ENC_ERR_NOT_ENOUGH_BUFFER,\n\n    /**\n     * This indicates that an invalid struct version was used by the client.\n     */\n    NV_ENC_ERR_INVALID_VERSION,\n\n    /**\n     * This indicates that ::NvEncMapInputResource() API failed to map the client\n     * provided input resource.\n     */\n    NV_ENC_ERR_MAP_FAILED,\n\n    /**\n     * This indicates encode driver requires more input buffers to produce an output\n     * bitstream. If this error is returned from ::NvEncEncodePicture() API, this\n     * is not a fatal error. If the client is encoding with B frames then,\n     * ::NvEncEncodePicture() API might be buffering the input frame for re-ordering.\n     *\n     * A client operating in synchronous mode cannot call ::NvEncLockBitstream()\n     * API on the output bitstream buffer if ::NvEncEncodePicture() returned the\n     * ::NV_ENC_ERR_NEED_MORE_INPUT error code.\n     * The client must continue providing input frames until encode driver returns\n     * ::NV_ENC_SUCCESS. After receiving ::NV_ENC_SUCCESS status the client can call\n     * ::NvEncLockBitstream() API on the output buffers in the same order in which\n     * it has called ::NvEncEncodePicture().\n     */\n    NV_ENC_ERR_NEED_MORE_INPUT,\n\n    /**\n     * This indicates that the HW encoder is busy encoding and is unable to encode\n     * the input. The client should call ::NvEncEncodePicture() again after few\n     * milliseconds.\n     */\n    NV_ENC_ERR_ENCODER_BUSY,\n\n    /**\n     * This indicates that the completion event passed in ::NvEncEncodePicture()\n     * API has not been registered with encoder driver using ::NvEncRegisterAsyncEvent().\n     */\n    NV_ENC_ERR_EVENT_NOT_REGISTERD,\n\n    /**\n     * This indicates that an unknown internal error has occurred.\n     */\n    NV_ENC_ERR_GENERIC,\n\n    /**\n     * This indicates that the client is attempting to use a feature\n     * that is not available for the license type for the current system.\n     */\n    NV_ENC_ERR_INCOMPATIBLE_CLIENT_KEY,\n\n    /**\n     * This indicates that the client is attempting to use a feature\n     * that is not implemented for the current version.\n     */\n    NV_ENC_ERR_UNIMPLEMENTED,\n\n    /**\n     * This indicates that the ::NvEncRegisterResource API failed to register the resource.\n     */\n    NV_ENC_ERR_RESOURCE_REGISTER_FAILED,\n\n    /**\n     * This indicates that the client is attempting to unregister a resource\n     * that has not been successfully registered.\n     */\n    NV_ENC_ERR_RESOURCE_NOT_REGISTERED,\n\n    /**\n     * This indicates that the client is attempting to unmap a resource\n     * that has not been successfully mapped.\n     */\n    NV_ENC_ERR_RESOURCE_NOT_MAPPED,\n\n} NVENCSTATUS;\n\n/**\n * Encode Picture encode flags.\n */\ntypedef enum _NV_ENC_PIC_FLAGS\n{\n    NV_ENC_PIC_FLAG_FORCEINTRA         = 0x1,   /**< Encode the current picture as an Intra picture */\n    NV_ENC_PIC_FLAG_FORCEIDR           = 0x2,   /**< Encode the current picture as an IDR picture.\n                                                     This flag is only valid when Picture type decision is taken by the Encoder\n                                                     [_NV_ENC_INITIALIZE_PARAMS::enablePTD == 1]. */\n    NV_ENC_PIC_FLAG_OUTPUT_SPSPPS      = 0x4,   /**< Write the sequence and picture header in encoded bitstream of the current picture */\n    NV_ENC_PIC_FLAG_EOS                = 0x8,   /**< Indicates end of the input stream */\n} NV_ENC_PIC_FLAGS;\n\n/**\n * Memory heap to allocate input and output buffers.\n */\ntypedef enum _NV_ENC_MEMORY_HEAP\n{\n    NV_ENC_MEMORY_HEAP_AUTOSELECT      = 0, /**< Memory heap to be decided by the encoder driver based on the usage */\n    NV_ENC_MEMORY_HEAP_VID             = 1, /**< Memory heap is in local video memory */\n    NV_ENC_MEMORY_HEAP_SYSMEM_CACHED   = 2, /**< Memory heap is in cached system memory */\n    NV_ENC_MEMORY_HEAP_SYSMEM_UNCACHED = 3  /**< Memory heap is in uncached system memory */\n} NV_ENC_MEMORY_HEAP;\n\n/**\n * B-frame used as reference modes\n */\ntypedef enum _NV_ENC_BFRAME_REF_MODE\n{\n    NV_ENC_BFRAME_REF_MODE_DISABLED = 0x0,          /**< B frame is not used for reference */\n    NV_ENC_BFRAME_REF_MODE_EACH     = 0x1,          /**< Each B-frame will be used for reference. currently not supported for H.264 */\n    NV_ENC_BFRAME_REF_MODE_MIDDLE   = 0x2,          /**< Only(Number of B-frame)/2 th B-frame will be used for reference */\n} NV_ENC_BFRAME_REF_MODE;\n\n/**\n * H.264 entropy coding modes.\n */\ntypedef enum _NV_ENC_H264_ENTROPY_CODING_MODE\n{\n    NV_ENC_H264_ENTROPY_CODING_MODE_AUTOSELECT = 0x0,   /**< Entropy coding mode is auto selected by the encoder driver */\n    NV_ENC_H264_ENTROPY_CODING_MODE_CABAC      = 0x1,   /**< Entropy coding mode is CABAC */\n    NV_ENC_H264_ENTROPY_CODING_MODE_CAVLC      = 0x2    /**< Entropy coding mode is CAVLC */\n} NV_ENC_H264_ENTROPY_CODING_MODE;\n\n/**\n * H.264 specific BDirect modes\n */\ntypedef enum _NV_ENC_H264_BDIRECT_MODE\n{\n    NV_ENC_H264_BDIRECT_MODE_AUTOSELECT = 0x0,          /**< BDirect mode is auto selected by the encoder driver */\n    NV_ENC_H264_BDIRECT_MODE_DISABLE    = 0x1,          /**< Disable BDirect mode */\n    NV_ENC_H264_BDIRECT_MODE_TEMPORAL   = 0x2,          /**< Temporal BDirect mode */\n    NV_ENC_H264_BDIRECT_MODE_SPATIAL    = 0x3           /**< Spatial BDirect mode */\n} NV_ENC_H264_BDIRECT_MODE;\n\n/**\n * H.264 specific FMO usage\n */\ntypedef enum _NV_ENC_H264_FMO_MODE\n{\n    NV_ENC_H264_FMO_AUTOSELECT          = 0x0,          /**< FMO usage is auto selected by the encoder driver */\n    NV_ENC_H264_FMO_ENABLE              = 0x1,          /**< Enable FMO */\n    NV_ENC_H264_FMO_DISABLE             = 0x2,          /**< Disable FMO */\n} NV_ENC_H264_FMO_MODE;\n\n/**\n * H.264 specific Adaptive Transform modes\n */\ntypedef enum _NV_ENC_H264_ADAPTIVE_TRANSFORM_MODE\n{\n    NV_ENC_H264_ADAPTIVE_TRANSFORM_AUTOSELECT = 0x0,   /**< Adaptive Transform 8x8 mode is auto selected by the encoder driver*/\n    NV_ENC_H264_ADAPTIVE_TRANSFORM_DISABLE    = 0x1,   /**< Adaptive Transform 8x8 mode disabled */\n    NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE     = 0x2,   /**< Adaptive Transform 8x8 mode should be used */\n} NV_ENC_H264_ADAPTIVE_TRANSFORM_MODE;\n\n/**\n * Stereo frame packing modes.\n */\ntypedef enum _NV_ENC_STEREO_PACKING_MODE\n{\n    NV_ENC_STEREO_PACKING_MODE_NONE             = 0x0,  /**< No Stereo packing required */\n    NV_ENC_STEREO_PACKING_MODE_CHECKERBOARD     = 0x1,  /**< Checkerboard mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_COLINTERLEAVE    = 0x2,  /**< Column Interleave mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_ROWINTERLEAVE    = 0x3,  /**< Row Interleave mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_SIDEBYSIDE       = 0x4,  /**< Side-by-side mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_TOPBOTTOM        = 0x5,  /**< Top-Bottom mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_FRAMESEQ         = 0x6   /**< Frame Sequential mode for packing stereo frames */\n} NV_ENC_STEREO_PACKING_MODE;\n\n/**\n *  Input Resource type\n */\ntypedef enum _NV_ENC_INPUT_RESOURCE_TYPE\n{\n    NV_ENC_INPUT_RESOURCE_TYPE_DIRECTX          = 0x0,   /**< input resource type is a directx9 surface*/\n    NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR    = 0x1,   /**< input resource type is a cuda device pointer surface*/\n    NV_ENC_INPUT_RESOURCE_TYPE_CUDAARRAY        = 0x2,   /**< input resource type is a cuda array surface.\n                                                              This array must be a 2D array and the CUDA_ARRAY3D_SURFACE_LDST\n                                                              flag must have been specified when creating it. */\n    NV_ENC_INPUT_RESOURCE_TYPE_OPENGL_TEX       = 0x3    /**< input resource type is an OpenGL texture */\n} NV_ENC_INPUT_RESOURCE_TYPE;\n\n/**\n *  Buffer usage\n */\ntypedef enum _NV_ENC_BUFFER_USAGE\n{\n    NV_ENC_INPUT_IMAGE              = 0x0,          /**< Registered surface will be used for input image */\n    NV_ENC_OUTPUT_MOTION_VECTOR     = 0x1,          /**< Registered surface will be used for output of H.264 ME only mode.\n                                                         This buffer usage type is not supported for HEVC ME only mode. */\n    NV_ENC_OUTPUT_BITSTREAM         = 0x2           /**< Registered surface will be used for output bitstream in encoding */\n} NV_ENC_BUFFER_USAGE;\n\n/**\n *  Encoder Device type\n */\ntypedef enum _NV_ENC_DEVICE_TYPE\n{\n    NV_ENC_DEVICE_TYPE_DIRECTX          = 0x0,   /**< encode device type is a directx9 device */\n    NV_ENC_DEVICE_TYPE_CUDA             = 0x1,   /**< encode device type is a cuda device */\n    NV_ENC_DEVICE_TYPE_OPENGL           = 0x2    /**< encode device type is an OpenGL device.\n                                                      Use of this device type is supported only on Linux */\n} NV_ENC_DEVICE_TYPE;\n\n/**\n * Number of reference frames\n */\ntypedef enum _NV_ENC_NUM_REF_FRAMES\n{\n    NV_ENC_NUM_REF_FRAMES_AUTOSELECT       = 0x0,          /**< Number of reference frames is auto selected by the encoder driver */\n    NV_ENC_NUM_REF_FRAMES_1                = 0x1,          /**< Number of reference frames equal to 1 */\n    NV_ENC_NUM_REF_FRAMES_2                = 0x2,          /**< Number of reference frames equal to 2 */\n    NV_ENC_NUM_REF_FRAMES_3                = 0x3,          /**< Number of reference frames equal to 3 */\n    NV_ENC_NUM_REF_FRAMES_4                = 0x4,          /**< Number of reference frames equal to 4 */\n    NV_ENC_NUM_REF_FRAMES_5                = 0x5,          /**< Number of reference frames equal to 5 */\n    NV_ENC_NUM_REF_FRAMES_6                = 0x6,          /**< Number of reference frames equal to 6 */\n    NV_ENC_NUM_REF_FRAMES_7                = 0x7           /**< Number of reference frames equal to 7 */\n} NV_ENC_NUM_REF_FRAMES;\n\n/**\n * Encoder capabilities enumeration.\n */\ntypedef enum _NV_ENC_CAPS\n{\n    /**\n     * Maximum number of B-Frames supported.\n     */\n    NV_ENC_CAPS_NUM_MAX_BFRAMES,\n\n    /**\n     * Rate control modes supported.\n     * \\n The API return value is a bitmask of the values in NV_ENC_PARAMS_RC_MODE.\n     */\n    NV_ENC_CAPS_SUPPORTED_RATECONTROL_MODES,\n\n    /**\n     * Indicates HW support for field mode encoding.\n     * \\n 0 : Interlaced mode encoding is not supported.\n     * \\n 1 : Interlaced field mode encoding is supported.\n     * \\n 2 : Interlaced frame encoding and field mode encoding are both supported.\n     */\n    NV_ENC_CAPS_SUPPORT_FIELD_ENCODING,\n\n    /**\n     * Indicates HW support for monochrome mode encoding.\n     * \\n 0 : Monochrome mode not supported.\n     * \\n 1 : Monochrome mode supported.\n     */\n    NV_ENC_CAPS_SUPPORT_MONOCHROME,\n\n    /**\n     * Indicates HW support for FMO.\n     * \\n 0 : FMO not supported.\n     * \\n 1 : FMO supported.\n     */\n    NV_ENC_CAPS_SUPPORT_FMO,\n\n    /**\n     * Indicates HW capability for Quarter pel motion estimation.\n     * \\n 0 : Quarter-Pel Motion Estimation not supported.\n     * \\n 1 : Quarter-Pel Motion Estimation supported.\n     */\n    NV_ENC_CAPS_SUPPORT_QPELMV,\n\n    /**\n     * H.264 specific. Indicates HW support for BDirect modes.\n     * \\n 0 : BDirect mode encoding not supported.\n     * \\n 1 : BDirect mode encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_BDIRECT_MODE,\n\n    /**\n     * H264 specific. Indicates HW support for CABAC entropy coding mode.\n     * \\n 0 : CABAC entropy coding not supported.\n     * \\n 1 : CABAC entropy coding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_CABAC,\n\n    /**\n     * Indicates HW support for Adaptive Transform.\n     * \\n 0 : Adaptive Transform not supported.\n     * \\n 1 : Adaptive Transform supported.\n     */\n    NV_ENC_CAPS_SUPPORT_ADAPTIVE_TRANSFORM,\n\n    /**\n     * Indicates HW support for Multi View Coding.\n     * \\n 0 : Multi View Coding not supported.\n     * \\n 1 : Multi View Coding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_STEREO_MVC,\n\n    /**\n     * Indicates HW support for encoding Temporal layers.\n     * \\n 0 : Encoding Temporal layers not supported.\n     * \\n 1 : Encoding Temporal layers supported.\n     */\n    NV_ENC_CAPS_NUM_MAX_TEMPORAL_LAYERS,\n\n    /**\n     * Indicates HW support for Hierarchical P frames.\n     * \\n 0 : Hierarchical P frames not supported.\n     * \\n 1 : Hierarchical P frames supported.\n     */\n    NV_ENC_CAPS_SUPPORT_HIERARCHICAL_PFRAMES,\n\n    /**\n     * Indicates HW support for Hierarchical B frames.\n     * \\n 0 : Hierarchical B frames not supported.\n     * \\n 1 : Hierarchical B frames supported.\n     */\n    NV_ENC_CAPS_SUPPORT_HIERARCHICAL_BFRAMES,\n\n    /**\n     * Maximum Encoding level supported (See ::NV_ENC_LEVEL for details).\n     */\n    NV_ENC_CAPS_LEVEL_MAX,\n\n    /**\n     * Minimum Encoding level supported (See ::NV_ENC_LEVEL for details).\n     */\n    NV_ENC_CAPS_LEVEL_MIN,\n\n    /**\n     * Indicates HW support for separate colour plane encoding.\n     * \\n 0 : Separate colour plane encoding not supported.\n     * \\n 1 : Separate colour plane encoding supported.\n     */\n    NV_ENC_CAPS_SEPARATE_COLOUR_PLANE,\n\n    /**\n     * Maximum output width supported.\n     */\n    NV_ENC_CAPS_WIDTH_MAX,\n\n    /**\n     * Maximum output height supported.\n     */\n    NV_ENC_CAPS_HEIGHT_MAX,\n\n    /**\n     * Indicates Temporal Scalability Support.\n     * \\n 0 : Temporal SVC encoding not supported.\n     * \\n 1 : Temporal SVC encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_TEMPORAL_SVC,\n\n    /**\n     * Indicates Dynamic Encode Resolution Change Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Dynamic Encode Resolution Change not supported.\n     * \\n 1 : Dynamic Encode Resolution Change supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYN_RES_CHANGE,\n\n    /**\n     * Indicates Dynamic Encode Bitrate Change Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Dynamic Encode bitrate change not supported.\n     * \\n 1 : Dynamic Encode bitrate change supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE,\n\n    /**\n     * Indicates Forcing Constant QP On The Fly Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Forcing constant QP on the fly not supported.\n     * \\n 1 : Forcing constant QP on the fly supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYN_FORCE_CONSTQP,\n\n    /**\n     * Indicates Dynamic rate control mode Change Support.\n     * \\n 0 : Dynamic rate control mode change not supported.\n     * \\n 1 : Dynamic rate control mode change supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYN_RCMODE_CHANGE,\n\n    /**\n     * Indicates Subframe readback support for slice-based encoding. If this feature is supported, it can be enabled by setting enableSubFrameWrite = 1.\n     * \\n 0 : Subframe readback not supported.\n     * \\n 1 : Subframe readback supported.\n     */\n    NV_ENC_CAPS_SUPPORT_SUBFRAME_READBACK,\n\n    /**\n     * Indicates Constrained Encoding mode support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Constrained encoding mode not supported.\n     * \\n 1 : Constrained encoding mode supported.\n     * If this mode is supported client can enable this during initialization.\n     * Client can then force a picture to be coded as constrained picture where\n     * in-loop filtering is disabled across slice boundaries and prediction vectors for inter\n     * macroblocks in each slice will be restricted to the slice region.\n     */\n    NV_ENC_CAPS_SUPPORT_CONSTRAINED_ENCODING,\n\n    /**\n     * Indicates Intra Refresh Mode Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Intra Refresh Mode not supported.\n     * \\n 1 : Intra Refresh Mode supported.\n     */\n    NV_ENC_CAPS_SUPPORT_INTRA_REFRESH,\n\n    /**\n     * Indicates Custom VBV Buffer Size support. It can be used for capping frame size.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Custom VBV buffer size specification from client, not supported.\n     * \\n 1 : Custom VBV buffer size specification from client, supported.\n     */\n    NV_ENC_CAPS_SUPPORT_CUSTOM_VBV_BUF_SIZE,\n\n    /**\n     * Indicates Dynamic Slice Mode Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Dynamic Slice Mode not supported.\n     * \\n 1 : Dynamic Slice Mode supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYNAMIC_SLICE_MODE,\n\n    /**\n     * Indicates Reference Picture Invalidation Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Reference Picture Invalidation not supported.\n     * \\n 1 : Reference Picture Invalidation supported.\n     */\n    NV_ENC_CAPS_SUPPORT_REF_PIC_INVALIDATION,\n\n    /**\n     * Indicates support for Pre-Processing.\n     * The API return value is a bitmask of the values defined in ::NV_ENC_PREPROC_FLAGS\n     */\n    NV_ENC_CAPS_PREPROC_SUPPORT,\n\n    /**\n    * Indicates support Async mode.\n    * \\n 0 : Async Encode mode not supported.\n    * \\n 1 : Async Encode mode supported.\n    */\n    NV_ENC_CAPS_ASYNC_ENCODE_SUPPORT,\n\n    /**\n     * Maximum MBs per frame supported.\n     */\n    NV_ENC_CAPS_MB_NUM_MAX,\n\n    /**\n     * Maximum aggregate throughput in MBs per sec.\n     */\n    NV_ENC_CAPS_MB_PER_SEC_MAX,\n\n    /**\n     * Indicates HW support for YUV444 mode encoding.\n     * \\n 0 : YUV444 mode encoding not supported.\n     * \\n 1 : YUV444 mode encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_YUV444_ENCODE,\n\n    /**\n     * Indicates HW support for lossless encoding.\n     * \\n 0 : lossless encoding not supported.\n     * \\n 1 : lossless encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_LOSSLESS_ENCODE,\n\n    /**\n    * Indicates HW support for Sample Adaptive Offset.\n    * \\n 0 : SAO not supported.\n    * \\n 1 : SAO encoding supported.\n    */\n    NV_ENC_CAPS_SUPPORT_SAO,\n\n    /**\n     * Indicates HW support for Motion Estimation Only Mode.\n     * \\n 0 : MEOnly Mode not supported.\n     * \\n 1 : MEOnly Mode supported for I and P frames.\n     * \\n 2 : MEOnly Mode supported for I, P and B frames.\n     */\n    NV_ENC_CAPS_SUPPORT_MEONLY_MODE,\n\n    /**\n     * Indicates HW support for lookahead encoding (enableLookahead=1).\n     * \\n 0 : Lookahead not supported.\n     * \\n 1 : Lookahead supported.\n     */\n    NV_ENC_CAPS_SUPPORT_LOOKAHEAD,\n\n    /**\n     * Indicates HW support for temporal AQ encoding (enableTemporalAQ=1).\n     * \\n 0 : Temporal AQ not supported.\n     * \\n 1 : Temporal AQ supported.\n     */\n    NV_ENC_CAPS_SUPPORT_TEMPORAL_AQ,\n    /**\n     * Indicates HW support for 10 bit encoding.\n     * \\n 0 : 10 bit encoding not supported.\n     * \\n 1 : 10 bit encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_10BIT_ENCODE,\n    /**\n     * Maximum number of Long Term Reference frames supported\n     */\n    NV_ENC_CAPS_NUM_MAX_LTR_FRAMES,\n\n    /**\n     * Indicates HW support for Weighted Prediction.\n     * \\n 0 : Weighted Prediction not supported.\n     * \\n 1 : Weighted Prediction supported.\n     */\n    NV_ENC_CAPS_SUPPORT_WEIGHTED_PREDICTION,\n\n\n    /**\n     * On managed (vGPU) platforms (Windows only), this API, in conjunction with other GRID Management APIs, can be used\n     * to estimate the residual capacity of the hardware encoder on the GPU as a percentage of the total available encoder capacity.\n     * This API can be called at any time; i.e. during the encode session or before opening the encode session.\n     * If the available encoder capacity is returned as zero, applications may choose to switch to software encoding\n     * and continue to call this API (e.g. polling once per second) until capacity becomes available.\n     *\n     * On bare metal (non-virtualized GPU) and linux platforms, this API always returns 100.\n     */\n    NV_ENC_CAPS_DYNAMIC_QUERY_ENCODER_CAPACITY,\n\n    /**\n    * Indicates B as reference support.\n    * \\n 0 : B as reference is not supported.\n    * \\n 1 : each B-Frame as reference is supported.\n    * \\n 2 : only Middle B-frame as reference is supported.\n    */\n    NV_ENC_CAPS_SUPPORT_BFRAME_REF_MODE,\n\n    /**\n     * Indicates HW support for Emphasis Level Map based delta QP computation.\n     * \\n 0 : Emphasis Level Map based delta QP not supported.\n     * \\n 1 : Emphasis Level Map based delta QP is supported.\n     */\n    NV_ENC_CAPS_SUPPORT_EMPHASIS_LEVEL_MAP,\n\n    /**\n     * Minimum input width supported.\n     */\n    NV_ENC_CAPS_WIDTH_MIN,\n\n    /**\n     * Minimum input height supported.\n     */\n    NV_ENC_CAPS_HEIGHT_MIN,\n\n    /**\n     * Indicates HW support for multiple reference frames.\n     */\n    NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES,\n\n    /**\n     * Indicates HW support for HEVC with alpha encoding.\n     * \\n 0 : HEVC with alpha encoding not supported.\n     * \\n 1 : HEVC with alpha encoding is supported.\n     */\n    NV_ENC_CAPS_SUPPORT_ALPHA_LAYER_ENCODING,\n\n    /**\n     * Indicates number of Encoding engines present on GPU.\n     */\n    NV_ENC_CAPS_NUM_ENCODER_ENGINES,\n\n    /**\n    * Reserved - Not to be used by clients.\n    */\n    NV_ENC_CAPS_EXPOSED_COUNT\n} NV_ENC_CAPS;\n\n/**\n *  HEVC CU SIZE\n */\ntypedef enum _NV_ENC_HEVC_CUSIZE\n{\n    NV_ENC_HEVC_CUSIZE_AUTOSELECT = 0,\n    NV_ENC_HEVC_CUSIZE_8x8        = 1,\n    NV_ENC_HEVC_CUSIZE_16x16      = 2,\n    NV_ENC_HEVC_CUSIZE_32x32      = 3,\n    NV_ENC_HEVC_CUSIZE_64x64      = 4,\n} NV_ENC_HEVC_CUSIZE;\n\n/**\n * Input struct for querying Encoding capabilities.\n */\ntypedef struct _NV_ENC_CAPS_PARAM\n{\n    uint32_t version;                                  /**< [in]: Struct version. Must be set to ::NV_ENC_CAPS_PARAM_VER */\n    NV_ENC_CAPS  capsToQuery;                          /**< [in]: Specifies the encode capability to be queried. Client should pass a member for ::NV_ENC_CAPS enum. */\n    uint32_t reserved[62];                             /**< [in]: Reserved and must be set to 0 */\n} NV_ENC_CAPS_PARAM;\n\n/** NV_ENC_CAPS_PARAM struct version. */\n#define NV_ENC_CAPS_PARAM_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * Encoder Output parameters\n */\ntypedef struct _NV_ENC_ENCODE_OUT_PARAMS\n{\n    uint32_t                  version;                 /**< [out]: Struct version. */\n    uint32_t                  bitstreamSizeInBytes;    /**< [out]: Encoded bitstream size in bytes */\n    uint32_t                  reserved[62];            /**< [out]: Reserved and must be set to 0 */\n} NV_ENC_ENCODE_OUT_PARAMS;\n\n/** NV_ENC_ENCODE_OUT_PARAMS struct version. */\n#define NV_ENC_ENCODE_OUT_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * Creation parameters for input buffer.\n */\ntypedef struct _NV_ENC_CREATE_INPUT_BUFFER\n{\n    uint32_t                  version;                 /**< [in]: Struct version. Must be set to ::NV_ENC_CREATE_INPUT_BUFFER_VER */\n    uint32_t                  width;                   /**< [in]: Input frame width */\n    uint32_t                  height;                  /**< [in]: Input frame height */\n    NV_ENC_MEMORY_HEAP        memoryHeap;              /**< [in]: Deprecated. Do not use */\n    NV_ENC_BUFFER_FORMAT      bufferFmt;               /**< [in]: Input buffer format */\n    uint32_t                  reserved;                /**< [in]: Reserved and must be set to 0 */\n    NV_ENC_INPUT_PTR          inputBuffer;             /**< [out]: Pointer to input buffer */\n    void                     *pSysMemBuffer;           /**< [in]: Pointer to existing system memory buffer */\n    uint32_t                  reserved1[57];           /**< [in]: Reserved and must be set to 0 */\n    void                     *reserved2[63];           /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CREATE_INPUT_BUFFER;\n\n/** NV_ENC_CREATE_INPUT_BUFFER struct version. */\n#define NV_ENC_CREATE_INPUT_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * Creation parameters for output bitstream buffer.\n */\ntypedef struct _NV_ENC_CREATE_BITSTREAM_BUFFER\n{\n    uint32_t              version;                     /**< [in]: Struct version. Must be set to ::NV_ENC_CREATE_BITSTREAM_BUFFER_VER */\n    uint32_t              size;                        /**< [in]: Deprecated. Do not use */\n    NV_ENC_MEMORY_HEAP    memoryHeap;                  /**< [in]: Deprecated. Do not use */\n    uint32_t              reserved;                    /**< [in]: Reserved and must be set to 0 */\n    NV_ENC_OUTPUT_PTR     bitstreamBuffer;             /**< [out]: Pointer to the output bitstream buffer */\n    void                 *bitstreamBufferPtr;          /**< [out]: Reserved and should not be used */\n    uint32_t              reserved1[58];               /**< [in]: Reserved and should be set to 0 */\n    void                 *reserved2[64];               /**< [in]: Reserved and should be set to NULL */\n} NV_ENC_CREATE_BITSTREAM_BUFFER;\n\n/** NV_ENC_CREATE_BITSTREAM_BUFFER struct version. */\n#define NV_ENC_CREATE_BITSTREAM_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * Structs needed for ME only mode.\n */\ntypedef struct _NV_ENC_MVECTOR\n{\n    int16_t             mvx;               /**< the x component of MV in quarter-pel units */\n    int16_t             mvy;               /**< the y component of MV in quarter-pel units */\n} NV_ENC_MVECTOR;\n\n/**\n * Motion vector structure per macroblock for H264 motion estimation.\n */\ntypedef struct _NV_ENC_H264_MV_DATA\n{\n    NV_ENC_MVECTOR      mv[4];             /**< up to 4 vectors for 8x8 partition */\n    uint8_t             mbType;            /**< 0 (I), 1 (P), 2 (IPCM), 3 (B) */\n    uint8_t             partitionType;     /**< Specifies the block partition type. 0:16x16, 1:8x8, 2:16x8, 3:8x16 */\n    uint16_t            reserved;          /**< reserved padding for alignment */\n    uint32_t            mbCost;\n} NV_ENC_H264_MV_DATA;\n\n/**\n * Motion vector structure per CU for HEVC motion estimation.\n */\ntypedef struct _NV_ENC_HEVC_MV_DATA\n{\n    NV_ENC_MVECTOR    mv[4];               /**< up to 4 vectors within a CU */\n    uint8_t           cuType;              /**< 0 (I), 1(P) */\n    uint8_t           cuSize;              /**< 0: 8x8, 1: 16x16, 2: 32x32, 3: 64x64 */\n    uint8_t           partitionMode;       /**< The CU partition mode\n                                                0 (2Nx2N), 1 (2NxN), 2(Nx2N), 3 (NxN),\n                                                4 (2NxnU), 5 (2NxnD), 6(nLx2N), 7 (nRx2N) */\n    uint8_t           lastCUInCTB;         /**< Marker to separate CUs in the current CTB from CUs in the next CTB */\n} NV_ENC_HEVC_MV_DATA;\n\n/**\n * Creation parameters for output motion vector buffer for ME only mode.\n */\ntypedef struct _NV_ENC_CREATE_MV_BUFFER\n{\n    uint32_t            version;           /**< [in]: Struct version. Must be set to NV_ENC_CREATE_MV_BUFFER_VER */\n    NV_ENC_OUTPUT_PTR   mvBuffer;          /**< [out]: Pointer to the output motion vector buffer */\n    uint32_t            reserved1[255];    /**< [in]: Reserved and should be set to 0 */\n    void               *reserved2[63];     /**< [in]: Reserved and should be set to NULL */\n} NV_ENC_CREATE_MV_BUFFER;\n\n/** NV_ENC_CREATE_MV_BUFFER struct version*/\n#define NV_ENC_CREATE_MV_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * QP value for frames\n */\ntypedef struct _NV_ENC_QP\n{\n    uint32_t        qpInterP;     /**< [in]: Specifies QP value for P-frame. Even though this field is uint32_t for legacy reasons, the client should treat this as a signed parameter(int32_t) for cases in which negative QP values are to be specified. */\n    uint32_t        qpInterB;     /**< [in]: Specifies QP value for B-frame. Even though this field is uint32_t for legacy reasons, the client should treat this as a signed parameter(int32_t) for cases in which negative QP values are to be specified. */\n    uint32_t        qpIntra;      /**< [in]: Specifies QP value for Intra Frame. Even though this field is uint32_t for legacy reasons, the client should treat this as a signed parameter(int32_t) for cases in which negative QP values are to be specified. */\n} NV_ENC_QP;\n\n/**\n * Rate Control Configuration Parameters\n */\ntypedef struct _NV_ENC_RC_PARAMS\n{\n    uint32_t                        version;\n    NV_ENC_PARAMS_RC_MODE           rateControlMode;                             /**< [in]: Specifies the rate control mode. Check support for various rate control modes using ::NV_ENC_CAPS_SUPPORTED_RATECONTROL_MODES caps. */\n    NV_ENC_QP                       constQP;                                     /**< [in]: Specifies the initial QP to be used for encoding, these values would be used for all frames if in Constant QP mode. */\n    uint32_t                        averageBitRate;                              /**< [in]: Specifies the average bitrate(in bits/sec) used for encoding. */\n    uint32_t                        maxBitRate;                                  /**< [in]: Specifies the maximum bitrate for the encoded output. This is used for VBR and ignored for CBR mode. */\n    uint32_t                        vbvBufferSize;                               /**< [in]: Specifies the VBV(HRD) buffer size. in bits. Set 0 to use the default VBV  buffer size. */\n    uint32_t                        vbvInitialDelay;                             /**< [in]: Specifies the VBV(HRD) initial delay in bits. Set 0 to use the default VBV  initial delay .*/\n    uint32_t                        enableMinQP          : 1;                    /**< [in]: Set this to 1 if minimum QP used for rate control. */\n    uint32_t                        enableMaxQP          : 1;                    /**< [in]: Set this to 1 if maximum QP used for rate control. */\n    uint32_t                        enableInitialRCQP    : 1;                    /**< [in]: Set this to 1 if user supplied initial QP is used for rate control. */\n    uint32_t                        enableAQ             : 1;                    /**< [in]: Set this to 1 to enable adaptive quantization (Spatial). */\n    uint32_t                        reservedBitField1    : 1;                    /**< [in]: Reserved bitfields and must be set to 0. */\n    uint32_t                        enableLookahead      : 1;                    /**< [in]: Set this to 1 to enable lookahead with depth <lookaheadDepth> (if lookahead is enabled, input frames must remain available to the encoder until encode completion) */\n    uint32_t                        disableIadapt        : 1;                    /**< [in]: Set this to 1 to disable adaptive I-frame insertion at scene cuts (only has an effect when lookahead is enabled) */\n    uint32_t                        disableBadapt        : 1;                    /**< [in]: Set this to 1 to disable adaptive B-frame decision (only has an effect when lookahead is enabled) */\n    uint32_t                        enableTemporalAQ     : 1;                    /**< [in]: Set this to 1 to enable temporal AQ */\n    uint32_t                        zeroReorderDelay     : 1;                    /**< [in]: Set this to 1 to indicate zero latency operation (no reordering delay, num_reorder_frames=0) */\n    uint32_t                        enableNonRefP        : 1;                    /**< [in]: Set this to 1 to enable automatic insertion of non-reference P-frames (no effect if enablePTD=0) */\n    uint32_t                        strictGOPTarget      : 1;                    /**< [in]: Set this to 1 to minimize GOP-to-GOP rate fluctuations */\n    uint32_t                        aqStrength           : 4;                     /**< [in]: When AQ (Spatial) is enabled (i.e. NV_ENC_RC_PARAMS::enableAQ is set), this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive).\n                                                                                            If not set, strength is auto selected by driver. */\n    uint32_t                        reservedBitFields    : 16;                   /**< [in]: Reserved bitfields and must be set to 0 */\n    NV_ENC_QP                       minQP;                                       /**< [in]: Specifies the minimum QP used for rate control. Client must set NV_ENC_CONFIG::enableMinQP to 1. */\n    NV_ENC_QP                       maxQP;                                       /**< [in]: Specifies the maximum QP used for rate control. Client must set NV_ENC_CONFIG::enableMaxQP to 1. */\n    NV_ENC_QP                       initialRCQP;                                 /**< [in]: Specifies the initial QP used for rate control. Client must set NV_ENC_CONFIG::enableInitialRCQP to 1. */\n    uint32_t                        temporallayerIdxMask;                        /**< [in]: Specifies the temporal layers (as a bitmask) whose QPs have changed. Valid max bitmask is [2^NV_ENC_CAPS_NUM_MAX_TEMPORAL_LAYERS - 1].\n                                                                                            Applicable only for constant QP mode (NV_ENC_RC_PARAMS::rateControlMode = NV_ENC_PARAMS_RC_CONSTQP). */\n    uint8_t                         temporalLayerQP[8];                          /**< [in]: Specifies the temporal layer QPs used for rate control. Temporal layer index is used as the array index.\n                                                                                            Applicable only for constant QP mode (NV_ENC_RC_PARAMS::rateControlMode = NV_ENC_PARAMS_RC_CONSTQP). */\n    uint8_t                         targetQuality;                               /**< [in]: Target CQ (Constant Quality) level for VBR mode (range 0-51 with 0-automatic)  */\n    uint8_t                         targetQualityLSB;                            /**< [in]: Fractional part of target quality (as 8.8 fixed point format) */\n    uint16_t                        lookaheadDepth;                              /**< [in]: Maximum depth of lookahead with range 0-(31 - number of B frames).\n                                                                                            lookaheadDepth is only used if enableLookahead=1.*/\n    uint8_t                         lowDelayKeyFrameScale;                       /**< [in]: Specifies the ratio of I frame bits to P frame bits in case of single frame VBV and CBR rate control mode,\n                                                                                            is set to 2 by default for low latency tuning info and 1 by default for ultra low latency tuning info  */\n    uint8_t                         reserved1[3];\n    NV_ENC_QP_MAP_MODE              qpMapMode;                                   /**< [in]: This flag is used to interpret values in array specified by NV_ENC_PIC_PARAMS::qpDeltaMap.\n                                                                                            Set this to NV_ENC_QP_MAP_EMPHASIS to treat values specified by NV_ENC_PIC_PARAMS::qpDeltaMap as Emphasis Level Map.\n                                                                                            Emphasis Level can be assigned any value specified in enum NV_ENC_EMPHASIS_MAP_LEVEL.\n                                                                                            Emphasis Level Map is used to specify regions to be encoded at varying levels of quality.\n                                                                                            The hardware encoder adjusts the quantization within the image as per the provided emphasis map,\n                                                                                            by adjusting the quantization parameter (QP) assigned to each macroblock. This adjustment is commonly called \u001cDelta QP\u001d.\n                                                                                            The adjustment depends on the absolute QP decided by the rate control algorithm, and is applied after the rate control has decided each macroblock\u0019s QP.\n                                                                                            Since the Delta QP overrides rate control, enabling Emphasis Level Map may violate bitrate and VBV buffer size constraints.\n                                                                                            Emphasis Level Map is useful in situations where client has a priori knowledge of the image complexity (e.g. via use of NVFBC's Classification feature) and encoding those high-complexity areas at higher quality (lower QP) is important, even at the possible cost of violating bitrate/VBV buffer size constraints\n                                                                                            This feature is not supported when AQ( Spatial/Temporal) is enabled.\n                                                                                            This feature is only supported for H264 codec currently.\n\n                                                                                            Set this to NV_ENC_QP_MAP_DELTA to treat values specified by NV_ENC_PIC_PARAMS::qpDeltaMap as QP Delta. This specifies QP modifier to be applied on top of the QP chosen by rate control\n\n                                                                                            Set this to NV_ENC_QP_MAP_DISABLED to ignore NV_ENC_PIC_PARAMS::qpDeltaMap values. In this case, qpDeltaMap should be set to NULL.\n\n                                                                                            Other values are reserved for future use.*/\n    NV_ENC_MULTI_PASS               multiPass;                                    /**< [in]: This flag is used to enable multi-pass encoding for a given ::NV_ENC_PARAMS_RC_MODE. This flag is not valid for H264 and HEVC MEOnly mode */\n    uint32_t                        alphaLayerBitrateRatio;                       /**< [in]: Specifies the ratio in which bitrate should be split between base and alpha layer. A value 'x' for this field will split the target bitrate in a ratio of x : 1 between base and alpha layer.\n                                                                                             The default split ratio is 15.*/\n    uint32_t                        reserved[5];\n} NV_ENC_RC_PARAMS;\n\n/** macro for constructing the version field of ::_NV_ENC_RC_PARAMS */\n#define NV_ENC_RC_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n\n/**\n * \\struct _NV_ENC_CONFIG_H264_VUI_PARAMETERS\n * H264 Video Usability Info parameters\n */\ntypedef struct _NV_ENC_CONFIG_H264_VUI_PARAMETERS\n{\n    uint32_t    overscanInfoPresentFlag;              /**< [in]: if set to 1 , it specifies that the overscanInfo is present */\n    uint32_t    overscanInfo;                         /**< [in]: Specifies the overscan info(as defined in Annex E of the ITU-T Specification). */\n    uint32_t    videoSignalTypePresentFlag;           /**< [in]: If set to 1, it specifies  that the videoFormat, videoFullRangeFlag and colourDescriptionPresentFlag are present. */\n    uint32_t    videoFormat;                          /**< [in]: Specifies the source video format(as defined in Annex E of the ITU-T Specification).*/\n    uint32_t    videoFullRangeFlag;                   /**< [in]: Specifies the output range of the luma and chroma samples(as defined in Annex E of the ITU-T Specification). */\n    uint32_t    colourDescriptionPresentFlag;         /**< [in]: If set to 1, it specifies that the colourPrimaries, transferCharacteristics and colourMatrix are present. */\n    uint32_t    colourPrimaries;                      /**< [in]: Specifies color primaries for converting to RGB(as defined in Annex E of the ITU-T Specification) */\n    uint32_t    transferCharacteristics;              /**< [in]: Specifies the opto-electronic transfer characteristics to use (as defined in Annex E of the ITU-T Specification) */\n    uint32_t    colourMatrix;                         /**< [in]: Specifies the matrix coefficients used in deriving the luma and chroma from the RGB primaries (as defined in Annex E of the ITU-T Specification). */\n    uint32_t    chromaSampleLocationFlag;             /**< [in]: if set to 1 , it specifies that the chromaSampleLocationTop and chromaSampleLocationBot are present.*/\n    uint32_t    chromaSampleLocationTop;              /**< [in]: Specifies the chroma sample location for top field(as defined in Annex E of the ITU-T Specification) */\n    uint32_t    chromaSampleLocationBot;              /**< [in]: Specifies the chroma sample location for bottom field(as defined in Annex E of the ITU-T Specification) */\n    uint32_t    bitstreamRestrictionFlag;             /**< [in]: if set to 1, it specifies the bitstream restriction parameters are present in the bitstream.*/\n    uint32_t    reserved[15];\n} NV_ENC_CONFIG_H264_VUI_PARAMETERS;\n\ntypedef NV_ENC_CONFIG_H264_VUI_PARAMETERS NV_ENC_CONFIG_HEVC_VUI_PARAMETERS;\n\n/**\n * \\struct _NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE\n * External motion vector hint counts per block type.\n * H264 supports multiple hint while HEVC supports one hint for each valid candidate.\n */\ntypedef struct _NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE\n{\n    uint32_t   numCandsPerBlk16x16                   : 4;   /**< [in]: Supported for H264, HEVC. It Specifies the number of candidates per 16x16 block. */\n    uint32_t   numCandsPerBlk16x8                    : 4;   /**< [in]: Supported for H264 only. Specifies the number of candidates per 16x8 block. */\n    uint32_t   numCandsPerBlk8x16                    : 4;   /**< [in]: Supported for H264 only. Specifies the number of candidates per 8x16 block. */\n    uint32_t   numCandsPerBlk8x8                     : 4;   /**< [in]: Supported for H264, HEVC. Specifies the number of candidates per 8x8 block. */\n    uint32_t   reserved                              : 16;  /**< [in]: Reserved for padding. */\n    uint32_t   reserved1[3];                                /**< [in]: Reserved for future use. */\n} NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE;\n\n\n/**\n * \\struct _NVENC_EXTERNAL_ME_HINT\n * External Motion Vector hint structure.\n */\ntypedef struct _NVENC_EXTERNAL_ME_HINT\n{\n    int32_t    mvx         : 12;                        /**< [in]: Specifies the x component of integer pixel MV (relative to current MB) S12.0. */\n    int32_t    mvy         : 10;                        /**< [in]: Specifies the y component of integer pixel MV (relative to current MB) S10.0 .*/\n    int32_t    refidx      : 5;                         /**< [in]: Specifies the reference index (31=invalid). Current we support only 1 reference frame per direction for external hints, so \\p refidx must be 0. */\n    int32_t    dir         : 1;                         /**< [in]: Specifies the direction of motion estimation . 0=L0 1=L1.*/\n    int32_t    partType    : 2;                         /**< [in]: Specifies the block partition type.0=16x16 1=16x8 2=8x16 3=8x8 (blocks in partition must be consecutive).*/\n    int32_t    lastofPart  : 1;                         /**< [in]: Set to 1 for the last MV of (sub) partition  */\n    int32_t    lastOfMB    : 1;                         /**< [in]: Set to 1 for the last MV of macroblock. */\n} NVENC_EXTERNAL_ME_HINT;\n\n\n/**\n * \\struct _NV_ENC_CONFIG_H264\n * H264 encoder configuration parameters\n */\ntypedef struct _NV_ENC_CONFIG_H264\n{\n    uint32_t enableTemporalSVC         : 1;                         /**< [in]: Set to 1 to enable SVC temporal*/\n    uint32_t enableStereoMVC           : 1;                         /**< [in]: Set to 1 to enable stereo MVC*/\n    uint32_t hierarchicalPFrames       : 1;                         /**< [in]: Set to 1 to enable hierarchical P Frames */\n    uint32_t hierarchicalBFrames       : 1;                         /**< [in]: Set to 1 to enable hierarchical B Frames */\n    uint32_t outputBufferingPeriodSEI  : 1;                         /**< [in]: Set to 1 to write SEI buffering period syntax in the bitstream */\n    uint32_t outputPictureTimingSEI    : 1;                          /**< [in]: Set to 1 to write SEI picture timing syntax in the bitstream.  When set for following rateControlMode : NV_ENC_PARAMS_RC_CBR, NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ,\n                                                                               NV_ENC_PARAMS_RC_CBR_HQ, filler data is inserted if needed to achieve HRD bitrate */\n    uint32_t outputAUD                 : 1;                         /**< [in]: Set to 1 to write access unit delimiter syntax in bitstream */\n    uint32_t disableSPSPPS             : 1;                         /**< [in]: Set to 1 to disable writing of Sequence and Picture parameter info in bitstream */\n    uint32_t outputFramePackingSEI     : 1;                         /**< [in]: Set to 1 to enable writing of frame packing arrangement SEI messages to bitstream */\n    uint32_t outputRecoveryPointSEI    : 1;                         /**< [in]: Set to 1 to enable writing of recovery point SEI message */\n    uint32_t enableIntraRefresh        : 1;                         /**< [in]: Set to 1 to enable gradual decoder refresh or intra refresh. If the GOP structure uses B frames this will be ignored */\n    uint32_t enableConstrainedEncoding : 1;                          /**< [in]: Set this to 1 to enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices.\n                                                                               Constrained encoding works only with rectangular slices.\n                                                                               Check support for constrained encoding using ::NV_ENC_CAPS_SUPPORT_CONSTRAINED_ENCODING caps. */\n    uint32_t repeatSPSPPS              : 1;                         /**< [in]: Set to 1 to enable writing of Sequence and Picture parameter for every IDR frame */\n    uint32_t enableVFR                 : 1;                          /**< [in]: Setting enableVFR=1 currently only sets the fixed_frame_rate_flag=0 in the VUI but otherwise\n                                                                               has no impact on the encoder behavior. For more details please refer to E.1 VUI syntax of H.264 standard. Note, however, that NVENC does not support VFR encoding and rate control. */\n    uint32_t enableLTR                 : 1;                          /**< [in]: Set to 1 to enable LTR (Long Term Reference) frame support. LTR can be used in two modes: \"LTR Trust\" mode and \"LTR Per Picture\" mode.\n                                                                               LTR Trust mode: In this mode, ltrNumFrames pictures after IDR are automatically marked as LTR. This mode is enabled by setting ltrTrustMode = 1.\n                                                                                               Use of LTR Trust mode is strongly discouraged as this mode may be deprecated in future.\n                                                                               LTR Per Picture mode: In this mode, client can control whether the current picture should be marked as LTR. Enable this mode by setting\n                                                                                                     ltrTrustMode = 0 and ltrMarkFrame = 1 for the picture to be marked as LTR. This is the preferred mode\n                                                                                                     for using LTR.\n                                                                               Note that LTRs are not supported if encoding session is configured with B-frames */\n    uint32_t qpPrimeYZeroTransformBypassFlag : 1;                    /**< [in]: To enable lossless encode set this to 1, set QP to 0 and RC_mode to NV_ENC_PARAMS_RC_CONSTQP and profile to HIGH_444_PREDICTIVE_PROFILE.\n                                                                               Check support for lossless encoding using ::NV_ENC_CAPS_SUPPORT_LOSSLESS_ENCODE caps.  */\n    uint32_t useConstrainedIntraPred   : 1;                         /**< [in]: Set 1 to enable constrained intra prediction. */\n    uint32_t enableFillerDataInsertion : 1;                          /**< [in]: Set to 1 to enable insertion of filler data in the bitstream.\n                                                                               This flag will take effect only when one of the CBR rate\n                                                                               control modes (NV_ENC_PARAMS_RC_CBR, NV_ENC_PARAMS_RC_CBR_HQ,\n                                                                               NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ) is in use and both\n                                                                               NV_ENC_INITIALIZE_PARAMS::frameRateNum and\n                                                                               NV_ENC_INITIALIZE_PARAMS::frameRateDen are set to non-zero\n                                                                               values. Setting this field when\n                                                                               NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is also set\n                                                                               is currently not supported and will make ::NvEncInitializeEncoder()\n                                                                               return an error. */\n    uint32_t disableSVCPrefixNalu      : 1;                          /**< [in]: Set to 1 to disable writing of SVC Prefix NALU preceding each slice in bitstream.\n                                                                               Applicable only when temporal SVC is enabled (NV_ENC_CONFIG_H264::enableTemporalSVC = 1). */\n    uint32_t enableScalabilityInfoSEI  : 1;                          /**< [in]: Set to 1 to enable writing of Scalability Information SEI message preceding each IDR picture in bitstream\n                                                                               Applicable only when temporal SVC is enabled (NV_ENC_CONFIG_H264::enableTemporalSVC = 1). */\n    uint32_t reservedBitFields         : 12;                        /**< [in]: Reserved bitfields and must be set to 0 */\n    uint32_t level;                                                 /**< [in]: Specifies the encoding level. Client is recommended to set this to NV_ENC_LEVEL_AUTOSELECT in order to enable the NvEncodeAPI interface to select the correct level. */\n    uint32_t idrPeriod;                                             /**< [in]: Specifies the IDR interval. If not set, this is made equal to gopLength in NV_ENC_CONFIG.Low latency application client can set IDR interval to NVENC_INFINITE_GOPLENGTH so that IDR frames are not inserted automatically. */\n    uint32_t separateColourPlaneFlag;                               /**< [in]: Set to 1 to enable 4:4:4 separate colour planes */\n    uint32_t disableDeblockingFilterIDC;                            /**< [in]: Specifies the deblocking filter mode. Permissible value range: [0,2]. This flag corresponds\n                                                                               to the flag disable_deblocking_filter_idc specified in section 7.4.3 of H.264 specification,\n                                                                               which specifies whether the operation of the deblocking filter shall be disabled across some\n                                                                               block edges of the slice and specifies for which edges the filtering is disabled. See section\n                                                                               7.4.3 of H.264 specification for more details.*/\n    uint32_t numTemporalLayers;                                     /**< [in]: Specifies number of temporal layers to be used for hierarchical coding / temporal SVC. Valid value range is [1,::NV_ENC_CAPS_NUM_MAX_TEMPORAL_LAYERS] */\n    uint32_t spsId;                                                 /**< [in]: Specifies the SPS id of the sequence header */\n    uint32_t ppsId;                                                 /**< [in]: Specifies the PPS id of the picture header */\n    NV_ENC_H264_ADAPTIVE_TRANSFORM_MODE adaptiveTransformMode;      /**< [in]: Specifies the AdaptiveTransform Mode. Check support for AdaptiveTransform mode using ::NV_ENC_CAPS_SUPPORT_ADAPTIVE_TRANSFORM caps. */\n    NV_ENC_H264_FMO_MODE                fmoMode;                    /**< [in]: Specified the FMO Mode. Check support for FMO using ::NV_ENC_CAPS_SUPPORT_FMO caps. */\n    NV_ENC_H264_BDIRECT_MODE            bdirectMode;                /**< [in]: Specifies the BDirect mode. Check support for BDirect mode using ::NV_ENC_CAPS_SUPPORT_BDIRECT_MODE caps.*/\n    NV_ENC_H264_ENTROPY_CODING_MODE     entropyCodingMode;          /**< [in]: Specifies the entropy coding mode. Check support for CABAC mode using ::NV_ENC_CAPS_SUPPORT_CABAC caps. */\n    NV_ENC_STEREO_PACKING_MODE          stereoMode;                 /**< [in]: Specifies the stereo frame packing mode which is to be signaled in frame packing arrangement SEI */\n    uint32_t                            intraRefreshPeriod;         /**< [in]: Specifies the interval between successive intra refresh if enableIntrarefresh is set. Requires enableIntraRefresh to be set.\n                                                                               Will be disabled if NV_ENC_CONFIG::gopLength is not set to NVENC_INFINITE_GOPLENGTH. */\n    uint32_t                            intraRefreshCnt;            /**< [in]: Specifies the length of intra refresh in number of frames for periodic intra refresh. This value should be smaller than intraRefreshPeriod */\n    uint32_t                            maxNumRefFrames;            /**< [in]: Specifies the DPB size used for encoding. Setting it to 0 will let driver use the default DPB size.\n                                                                               The low latency application which wants to invalidate reference frame as an error resilience tool\n                                                                               is recommended to use a large DPB size so that the encoder can keep old reference frames which can be used if recent\n                                                                               frames are invalidated. */\n    uint32_t                            sliceMode;                  /**< [in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divided into slices\n                                                                               sliceMode = 0 MB based slices, sliceMode = 1 Byte based slices, sliceMode = 2 MB row based slices, sliceMode = 3 numSlices in Picture.\n                                                                               When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting\n                                                                               When sliceMode == 0 and sliceModeData == 0 whole picture will be coded with one slice */\n    uint32_t                            sliceModeData;              /**< [in]: Specifies the parameter needed for sliceMode. For:\n                                                                               sliceMode = 0, sliceModeData specifies # of MBs in each slice (except last slice)\n                                                                               sliceMode = 1, sliceModeData specifies maximum # of bytes in each slice (except last slice)\n                                                                               sliceMode = 2, sliceModeData specifies # of MB rows in each slice (except last slice)\n                                                                               sliceMode = 3, sliceModeData specifies number of slices in the picture. Driver will divide picture into slices optimally */\n    NV_ENC_CONFIG_H264_VUI_PARAMETERS   h264VUIParameters;          /**< [in]: Specifies the H264 video usability info parameters */\n    uint32_t                            ltrNumFrames;               /**< [in]: Specifies the number of LTR frames. This parameter has different meaning in two LTR modes.\n                                                                               In \"LTR Trust\" mode (ltrTrustMode = 1), encoder will mark the first ltrNumFrames base layer reference frames within each IDR interval as LTR.\n                                                                               In \"LTR Per Picture\" mode (ltrTrustMode = 0 and ltrMarkFrame = 1), ltrNumFrames specifies maximum number of LTR frames in DPB. */\n    uint32_t                            ltrTrustMode;               /**< [in]: Specifies the LTR operating mode. See comments near NV_ENC_CONFIG_H264::enableLTR for description of the two modes.\n                                                                               Set to 1 to use \"LTR Trust\" mode of LTR operation. Clients are discouraged to use \"LTR Trust\" mode as this mode may\n                                                                               be deprecated in future releases.\n                                                                               Set to 0 when using \"LTR Per Picture\" mode of LTR operation. */\n    uint32_t                            chromaFormatIDC;            /**< [in]: Specifies the chroma format. Should be set to 1 for yuv420 input, 3 for yuv444 input.\n                                                                               Check support for YUV444 encoding using ::NV_ENC_CAPS_SUPPORT_YUV444_ENCODE caps.*/\n    uint32_t                            maxTemporalLayers;          /**< [in]: Specifies the maximum temporal layer used for temporal SVC / hierarchical coding.\n                                                                               Defaut value of this field is NV_ENC_CAPS::NV_ENC_CAPS_NUM_MAX_TEMPORAL_LAYERS. Note that the value NV_ENC_CONFIG_H264::maxNumRefFrames should\n                                                                               be greater than or equal to (NV_ENC_CONFIG_H264::maxTemporalLayers - 2) * 2, for NV_ENC_CONFIG_H264::maxTemporalLayers >= 2.*/\n    NV_ENC_BFRAME_REF_MODE              useBFramesAsRef;            /**< [in]: Specifies the B-Frame as reference mode. Check support for useBFramesAsRef mode using ::NV_ENC_CAPS_SUPPORT_BFRAME_REF_MODE caps.*/\n    NV_ENC_NUM_REF_FRAMES               numRefL0;                   /**< [in]: Specifies max number of reference frames in reference picture list L0, that can be used by hardware for prediction of a frame.\n                                                                               Check support for numRefL0 using ::NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES caps. */\n    NV_ENC_NUM_REF_FRAMES               numRefL1;                   /**< [in]: Specifies max number of reference frames in reference picture list L1, that can be used by hardware for prediction of a frame.\n                                                                               Check support for numRefL1 using ::NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES caps. */\n    uint32_t                            reserved1[267];             /**< [in]: Reserved and must be set to 0 */\n    void                               *reserved2[64];              /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG_H264;\n\n/**\n * \\struct _NV_ENC_CONFIG_HEVC\n * HEVC encoder configuration parameters to be set during initialization.\n */\ntypedef struct _NV_ENC_CONFIG_HEVC\n{\n    uint32_t level;                                                 /**< [in]: Specifies the level of the encoded bitstream.*/\n    uint32_t tier;                                                  /**< [in]: Specifies the level tier of the encoded bitstream.*/\n    NV_ENC_HEVC_CUSIZE minCUSize;                                   /**< [in]: Specifies the minimum size of luma coding unit.*/\n    NV_ENC_HEVC_CUSIZE maxCUSize;                                   /**< [in]: Specifies the maximum size of luma coding unit. Currently NVENC SDK only supports maxCUSize equal to NV_ENC_HEVC_CUSIZE_32x32.*/\n    uint32_t useConstrainedIntraPred               : 1;             /**< [in]: Set 1 to enable constrained intra prediction. */\n    uint32_t disableDeblockAcrossSliceBoundary     : 1;             /**< [in]: Set 1 to disable in loop filtering across slice boundary.*/\n    uint32_t outputBufferingPeriodSEI              : 1;             /**< [in]: Set 1 to write SEI buffering period syntax in the bitstream */\n    uint32_t outputPictureTimingSEI                : 1;             /**< [in]: Set 1 to write SEI picture timing syntax in the bitstream */\n    uint32_t outputAUD                             : 1;             /**< [in]: Set 1 to write Access Unit Delimiter syntax. */\n    uint32_t enableLTR                             : 1;              /**< [in]: Set to 1 to enable LTR (Long Term Reference) frame support. LTR can be used in two modes: \"LTR Trust\" mode and \"LTR Per Picture\" mode.\n                                                                               LTR Trust mode: In this mode, ltrNumFrames pictures after IDR are automatically marked as LTR. This mode is enabled by setting ltrTrustMode = 1.\n                                                                                               Use of LTR Trust mode is strongly discouraged as this mode may be deprecated in future releases.\n                                                                               LTR Per Picture mode: In this mode, client can control whether the current picture should be marked as LTR. Enable this mode by setting\n                                                                                                     ltrTrustMode = 0 and ltrMarkFrame = 1 for the picture to be marked as LTR. This is the preferred mode\n                                                                                                     for using LTR.\n                                                                               Note that LTRs are not supported if encoding session is configured with B-frames */\n    uint32_t disableSPSPPS                         : 1;             /**< [in]: Set 1 to disable VPS, SPS and PPS signaling in the bitstream. */\n    uint32_t repeatSPSPPS                          : 1;             /**< [in]: Set 1 to output VPS,SPS and PPS for every IDR frame.*/\n    uint32_t enableIntraRefresh                    : 1;             /**< [in]: Set 1 to enable gradual decoder refresh or intra refresh. If the GOP structure uses B frames this will be ignored */\n    uint32_t chromaFormatIDC                       : 2;             /**< [in]: Specifies the chroma format. Should be set to 1 for yuv420 input, 3 for yuv444 input.*/\n    uint32_t pixelBitDepthMinus8                   : 3;             /**< [in]: Specifies pixel bit depth minus 8. Should be set to 0 for 8 bit input, 2 for 10 bit input.*/\n    uint32_t enableFillerDataInsertion             : 1;              /**< [in]: Set to 1 to enable insertion of filler data in the bitstream.\n                                                                               This flag will take effect only when one of the CBR rate\n                                                                               control modes (NV_ENC_PARAMS_RC_CBR, NV_ENC_PARAMS_RC_CBR_HQ,\n                                                                               NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ) is in use and both\n                                                                               NV_ENC_INITIALIZE_PARAMS::frameRateNum and\n                                                                               NV_ENC_INITIALIZE_PARAMS::frameRateDen are set to non-zero\n                                                                               values. Setting this field when\n                                                                               NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is also set\n                                                                               is currently not supported and will make ::NvEncInitializeEncoder()\n                                                                               return an error. */\n    uint32_t enableConstrainedEncoding             : 1;              /**< [in]: Set this to 1 to enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices.\n                                                                               Constrained encoding works only with rectangular slices.\n                                                                               Check support for constrained encoding using ::NV_ENC_CAPS_SUPPORT_CONSTRAINED_ENCODING caps. */\n    uint32_t enableAlphaLayerEncoding              : 1;             /**< [in]: Set this to 1 to enable HEVC encode with alpha layer. */\n    uint32_t reserved                              : 15;            /**< [in]: Reserved bitfields.*/\n    uint32_t idrPeriod;                                             /**< [in]: Specifies the IDR interval. If not set, this is made equal to gopLength in NV_ENC_CONFIG. Low latency application client can set IDR interval to NVENC_INFINITE_GOPLENGTH so that IDR frames are not inserted automatically. */\n    uint32_t intraRefreshPeriod;                                    /**< [in]: Specifies the interval between successive intra refresh if enableIntrarefresh is set. Requires enableIntraRefresh to be set.\n                                                                    Will be disabled if NV_ENC_CONFIG::gopLength is not set to NVENC_INFINITE_GOPLENGTH. */\n    uint32_t intraRefreshCnt;                                       /**< [in]: Specifies the length of intra refresh in number of frames for periodic intra refresh. This value should be smaller than intraRefreshPeriod */\n    uint32_t maxNumRefFramesInDPB;                                  /**< [in]: Specifies the maximum number of references frames in the DPB.*/\n    uint32_t ltrNumFrames;                                          /**< [in]: This parameter has different meaning in two LTR modes.\n                                                                               In \"LTR Trust\" mode (ltrTrustMode = 1), encoder will mark the first ltrNumFrames base layer reference frames within each IDR interval as LTR.\n                                                                               In \"LTR Per Picture\" mode (ltrTrustMode = 0 and ltrMarkFrame = 1), ltrNumFrames specifies maximum number of LTR frames in DPB. */\n    uint32_t vpsId;                                                 /**< [in]: Specifies the VPS id of the video parameter set */\n    uint32_t spsId;                                                 /**< [in]: Specifies the SPS id of the sequence header */\n    uint32_t ppsId;                                                 /**< [in]: Specifies the PPS id of the picture header */\n    uint32_t sliceMode;                                             /**< [in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divided into slices\n                                                                                sliceMode = 0 CTU based slices, sliceMode = 1 Byte based slices, sliceMode = 2 CTU row based slices, sliceMode = 3, numSlices in Picture\n                                                                                When sliceMode == 0 and sliceModeData == 0 whole picture will be coded with one slice */\n    uint32_t sliceModeData;                                         /**< [in]: Specifies the parameter needed for sliceMode. For:\n                                                                                sliceMode = 0, sliceModeData specifies # of CTUs in each slice (except last slice)\n                                                                                sliceMode = 1, sliceModeData specifies maximum # of bytes in each slice (except last slice)\n                                                                                sliceMode = 2, sliceModeData specifies # of CTU rows in each slice (except last slice)\n                                                                                sliceMode = 3, sliceModeData specifies number of slices in the picture. Driver will divide picture into slices optimally */\n    uint32_t maxTemporalLayersMinus1;                               /**< [in]: Specifies the max temporal layer used for hierarchical coding. */\n    NV_ENC_CONFIG_HEVC_VUI_PARAMETERS   hevcVUIParameters;          /**< [in]: Specifies the HEVC video usability info parameters */\n    uint32_t ltrTrustMode;                                          /**< [in]: Specifies the LTR operating mode. See comments near NV_ENC_CONFIG_HEVC::enableLTR for description of the two modes.\n                                                                               Set to 1 to use \"LTR Trust\" mode of LTR operation. Clients are discouraged to use \"LTR Trust\" mode as this mode may\n                                                                               be deprecated in future releases.\n                                                                               Set to 0 when using \"LTR Per Picture\" mode of LTR operation. */\n    NV_ENC_BFRAME_REF_MODE              useBFramesAsRef;            /**< [in]: Specifies the B-Frame as reference mode. Check support for useBFramesAsRef mode using  ::NV_ENC_CAPS_SUPPORT_BFRAME_REF_MODE caps.*/\n    NV_ENC_NUM_REF_FRAMES               numRefL0;                   /**< [in]: Specifies max number of reference frames in reference picture list L0, that can be used by hardware for prediction of a frame.\n                                                                               Check support for numRefL0 using ::NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES caps. */\n    NV_ENC_NUM_REF_FRAMES               numRefL1;                   /**< [in]: Specifies max number of reference frames in reference picture list L1, that can be used by hardware for prediction of a frame.\n                                                                               Check support for numRefL1 using ::NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES caps. */\n    uint32_t                            reserved1[214];             /**< [in]: Reserved and must be set to 0.*/\n    void                               *reserved2[64];              /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG_HEVC;\n\n/**\n * \\struct _NV_ENC_CONFIG_H264_MEONLY\n * H264 encoder configuration parameters for ME only Mode\n *\n */\ntypedef struct _NV_ENC_CONFIG_H264_MEONLY\n{\n    uint32_t disablePartition16x16 : 1;                         /**< [in]: Disable Motion Estimation on 16x16 blocks*/\n    uint32_t disablePartition8x16  : 1;                         /**< [in]: Disable Motion Estimation on 8x16 blocks*/\n    uint32_t disablePartition16x8  : 1;                         /**< [in]: Disable Motion Estimation on 16x8 blocks*/\n    uint32_t disablePartition8x8   : 1;                         /**< [in]: Disable Motion Estimation on 8x8 blocks*/\n    uint32_t disableIntraSearch    : 1;                         /**< [in]: Disable Intra search during Motion Estimation*/\n    uint32_t bStereoEnable         : 1;                         /**< [in]: Enable Stereo Mode for Motion Estimation where each view is independently executed*/\n    uint32_t reserved              : 26;                        /**< [in]: Reserved and must be set to 0 */\n    uint32_t reserved1 [255];                                   /**< [in]: Reserved and must be set to 0 */\n    void    *reserved2[64];                                     /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG_H264_MEONLY;\n\n\n/**\n * \\struct _NV_ENC_CONFIG_HEVC_MEONLY\n * HEVC encoder configuration parameters for ME only Mode\n *\n */\ntypedef struct _NV_ENC_CONFIG_HEVC_MEONLY\n{\n    uint32_t reserved [256];                                   /**< [in]: Reserved and must be set to 0 */\n    void    *reserved1[64];                                     /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG_HEVC_MEONLY;\n\n/**\n * \\struct _NV_ENC_CODEC_CONFIG\n * Codec-specific encoder configuration parameters to be set during initialization.\n */\ntypedef union _NV_ENC_CODEC_CONFIG\n{\n    NV_ENC_CONFIG_H264        h264Config;                /**< [in]: Specifies the H.264-specific encoder configuration. */\n    NV_ENC_CONFIG_HEVC        hevcConfig;                /**< [in]: Specifies the HEVC-specific encoder configuration. */\n    NV_ENC_CONFIG_H264_MEONLY h264MeOnlyConfig;          /**< [in]: Specifies the H.264-specific ME only encoder configuration. */\n    NV_ENC_CONFIG_HEVC_MEONLY hevcMeOnlyConfig;          /**< [in]: Specifies the HEVC-specific ME only encoder configuration. */\n    uint32_t                reserved[320];               /**< [in]: Reserved and must be set to 0 */\n} NV_ENC_CODEC_CONFIG;\n\n\n/**\n * \\struct _NV_ENC_CONFIG\n * Encoder configuration parameters to be set during initialization.\n */\ntypedef struct _NV_ENC_CONFIG\n{\n    uint32_t                        version;                                     /**< [in]: Struct version. Must be set to ::NV_ENC_CONFIG_VER. */\n    GUID                            profileGUID;                                 /**< [in]: Specifies the codec profile GUID. If client specifies \\p NV_ENC_CODEC_PROFILE_AUTOSELECT_GUID the NvEncodeAPI interface will select the appropriate codec profile. */\n    uint32_t                        gopLength;                                   /**< [in]: Specifies the number of pictures in one GOP. Low latency application client can set goplength to NVENC_INFINITE_GOPLENGTH so that keyframes are not inserted automatically. */\n    int32_t                         frameIntervalP;                              /**< [in]: Specifies the GOP pattern as follows: \\p frameIntervalP = 0: I, 1: IPP, 2: IBP, 3: IBBP  If goplength is set to NVENC_INFINITE_GOPLENGTH \\p frameIntervalP should be set to 1. */\n    uint32_t                        monoChromeEncoding;                          /**< [in]: Set this to 1 to enable monochrome encoding for this session. */\n    NV_ENC_PARAMS_FRAME_FIELD_MODE  frameFieldMode;                              /**< [in]: Specifies the frame/field mode.\n                                                                                            Check support for field encoding using ::NV_ENC_CAPS_SUPPORT_FIELD_ENCODING caps.\n                                                                                            Using a frameFieldMode other than NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME for RGB input is not supported. */\n    NV_ENC_MV_PRECISION             mvPrecision;                                 /**< [in]: Specifies the desired motion vector prediction precision. */\n    NV_ENC_RC_PARAMS                rcParams;                                    /**< [in]: Specifies the rate control parameters for the current encoding session. */\n    NV_ENC_CODEC_CONFIG             encodeCodecConfig;                           /**< [in]: Specifies the codec specific config parameters through this union. */\n    uint32_t                        reserved [278];                              /**< [in]: Reserved and must be set to 0 */\n    void                           *reserved2[64];                               /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG;\n\n/** macro for constructing the version field of ::_NV_ENC_CONFIG */\n#define NV_ENC_CONFIG_VER (NVENCAPI_STRUCT_VERSION(7) | ( 1U<<31 ))\n\n/**\n *  Tuning information of NVENC encoding (TuningInfo is not applicable to H264 and HEVC MEOnly mode).\n */\ntypedef enum NV_ENC_TUNING_INFO\n{\n    NV_ENC_TUNING_INFO_UNDEFINED         = 0,                                     /**< Undefined tuningInfo. Invalid value for encoding. */\n    NV_ENC_TUNING_INFO_HIGH_QUALITY      = 1,                                     /**< Tune presets for latency tolerant encoding.*/\n    NV_ENC_TUNING_INFO_LOW_LATENCY       = 2,                                     /**< Tune presets for low latency streaming.*/\n    NV_ENC_TUNING_INFO_ULTRA_LOW_LATENCY = 3,                                     /**< Tune presets for ultra low latency streaming.*/\n    NV_ENC_TUNING_INFO_LOSSLESS          = 4,                                     /**< Tune presets for lossless encoding.*/\n    NV_ENC_TUNING_INFO_COUNT                                                      /**< Count number of tuningInfos. Invalid value. */\n} NV_ENC_TUNING_INFO;\n\n/**\n * \\struct _NV_ENC_INITIALIZE_PARAMS\n * Encode Session Initialization parameters.\n */\ntypedef struct _NV_ENC_INITIALIZE_PARAMS\n{\n    uint32_t                                   version;                         /**< [in]: Struct version. Must be set to ::NV_ENC_INITIALIZE_PARAMS_VER. */\n    GUID                                       encodeGUID;                      /**< [in]: Specifies the Encode GUID for which the encoder is being created. ::NvEncInitializeEncoder() API will fail if this is not set, or set to unsupported value. */\n    GUID                                       presetGUID;                      /**< [in]: Specifies the preset for encoding. If the preset GUID is set then , the preset configuration will be applied before any other parameter. */\n    uint32_t                                   encodeWidth;                     /**< [in]: Specifies the encode width. If not set ::NvEncInitializeEncoder() API will fail. */\n    uint32_t                                   encodeHeight;                    /**< [in]: Specifies the encode height. If not set ::NvEncInitializeEncoder() API will fail. */\n    uint32_t                                   darWidth;                        /**< [in]: Specifies the display aspect ratio Width. */\n    uint32_t                                   darHeight;                       /**< [in]: Specifies the display aspect ratio height. */\n    uint32_t                                   frameRateNum;                    /**< [in]: Specifies the numerator for frame rate used for encoding in frames per second ( Frame rate = frameRateNum / frameRateDen ). */\n    uint32_t                                   frameRateDen;                    /**< [in]: Specifies the denominator for frame rate used for encoding in frames per second ( Frame rate = frameRateNum / frameRateDen ). */\n    uint32_t                                   enableEncodeAsync;               /**< [in]: Set this to 1 to enable asynchronous mode and is expected to use events to get picture completion notification. */\n    uint32_t                                   enablePTD;                       /**< [in]: Set this to 1 to enable the Picture Type Decision is be taken by the NvEncodeAPI interface. */\n    uint32_t                                   reportSliceOffsets        : 1;   /**< [in]: Set this to 1 to enable reporting slice offsets in ::_NV_ENC_LOCK_BITSTREAM. NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync must be set to 0 to use this feature. Client must set this to 0 if NV_ENC_CONFIG_H264::sliceMode is 1 on Kepler GPUs */\n    uint32_t                                   enableSubFrameWrite       : 1;    /**< [in]: Set this to 1 to write out available bitstream to memory at subframe intervals.\n                                                                                           If enableSubFrameWrite = 1, then the hardware encoder returns data as soon as a slice has completed encoding.\n                                                                                           This results in better encoding latency, but the downside is that the application has to keep polling via a call to nvEncLockBitstream API continuously to see if any encoded slice data is available.\n                                                                                           Use this mode if you feel that the marginal reduction in latency from sub-frame encoding is worth the increase in complexity due to CPU-based polling. */\n    uint32_t                                   enableExternalMEHints     : 1;    /**< [in]: Set to 1 to enable external ME hints for the current frame. For NV_ENC_INITIALIZE_PARAMS::enablePTD=1 with B frames, programming L1 hints is optional for B frames since Client doesn't know internal GOP structure.\n                                                                                           NV_ENC_PIC_PARAMS::meHintRefPicDist should preferably be set with enablePTD=1. */\n    uint32_t                                   enableMEOnlyMode          : 1;   /**< [in]: Set to 1 to enable ME Only Mode .*/\n    uint32_t                                   enableWeightedPrediction  : 1;    /**< [in]: Set this to 1 to enable weighted prediction. Not supported if encode session is configured for B-Frames (i.e. NV_ENC_CONFIG::frameIntervalP > 1 or preset >=P3 when tuningInfo = ::NV_ENC_TUNING_INFO_HIGH_QUALITY or\n                                                                                           tuningInfo = ::NV_ENC_TUNING_INFO_LOSSLESS. This is because preset >=p3 internally enables B frames when tuningInfo = ::NV_ENC_TUNING_INFO_HIGH_QUALITY or ::NV_ENC_TUNING_INFO_LOSSLESS). */\n    uint32_t                                   enableOutputInVidmem      : 1;   /**< [in]: Set this to 1 to enable output of NVENC in video memory buffer created by application. This feature is not supported for HEVC ME only mode. */\n    uint32_t                                   reservedBitFields         : 26;  /**< [in]: Reserved bitfields and must be set to 0 */\n    uint32_t                                   privDataSize;                    /**< [in]: Reserved private data buffer size and must be set to 0 */\n    void                                      *privData;                        /**< [in]: Reserved private data buffer and must be set to NULL */\n    NV_ENC_CONFIG                             *encodeConfig;                    /**< [in]: Specifies the advanced codec specific structure. If client has sent a valid codec config structure, it will override parameters set by the NV_ENC_INITIALIZE_PARAMS::presetGUID parameter. If set to NULL the NvEncodeAPI interface will use the NV_ENC_INITIALIZE_PARAMS::presetGUID to set the codec specific parameters.\n                                                                                           Client can also optionally query the NvEncodeAPI interface to get codec specific parameters for a presetGUID using ::NvEncGetEncodePresetConfig() API. It can then modify (if required) some of the codec config parameters and send down a custom config structure as part of ::_NV_ENC_INITIALIZE_PARAMS.\n                                                                                           Even in this case client is recommended to pass the same preset guid it has used in ::NvEncGetEncodePresetConfig() API to query the config structure; as NV_ENC_INITIALIZE_PARAMS::presetGUID. This will not override the custom config structure but will be used to determine other Encoder HW specific parameters not exposed in the API. */\n    uint32_t                                   maxEncodeWidth;                  /**< [in]: Maximum encode width to be used for current Encode session.\n                                                                                           Client should allocate output buffers according to this dimension for dynamic resolution change. If set to 0, Encoder will not allow dynamic resolution change. */\n    uint32_t                                   maxEncodeHeight;                 /**< [in]: Maximum encode height to be allowed for current Encode session.\n                                                                                           Client should allocate output buffers according to this dimension for dynamic resolution change. If set to 0, Encode will not allow dynamic resolution change. */\n    NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE maxMEHintCountsPerBlock[2];      /**< [in]: If Client wants to pass external motion vectors in NV_ENC_PIC_PARAMS::meExternalHints buffer it must specify the maximum number of hint candidates per block per direction for the encode session.\n                                                                                           The NV_ENC_INITIALIZE_PARAMS::maxMEHintCountsPerBlock[0] is for L0 predictors and NV_ENC_INITIALIZE_PARAMS::maxMEHintCountsPerBlock[1] is for L1 predictors.\n                                                                                           This client must also set NV_ENC_INITIALIZE_PARAMS::enableExternalMEHints to 1. */\n    NV_ENC_TUNING_INFO                         tuningInfo;                      /**< [in]: Tuning Info of NVENC encoding(TuningInfo is not applicable to H264 and HEVC meonly mode). */\n    uint32_t                                   reserved [288];                  /**< [in]: Reserved and must be set to 0 */\n    void                                      *reserved2[64];                   /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_INITIALIZE_PARAMS;\n\n/** macro for constructing the version field of ::_NV_ENC_INITIALIZE_PARAMS */\n#define NV_ENC_INITIALIZE_PARAMS_VER (NVENCAPI_STRUCT_VERSION(5) | ( 1U<<31 ))\n\n\n/**\n * \\struct _NV_ENC_RECONFIGURE_PARAMS\n * Encode Session Reconfigured parameters.\n */\ntypedef struct _NV_ENC_RECONFIGURE_PARAMS\n{\n    uint32_t                                    version;                        /**< [in]: Struct version. Must be set to ::NV_ENC_RECONFIGURE_PARAMS_VER. */\n    NV_ENC_INITIALIZE_PARAMS                    reInitEncodeParams;             /**< [in]: Encoder session re-initialization parameters.\n                                                                                           If reInitEncodeParams.encodeConfig is NULL and\n                                                                                           reInitEncodeParams.presetGUID is the same as the preset\n                                                                                           GUID specified on the call to NvEncInitializeEncoder(),\n                                                                                           EncodeAPI will continue to use the existing encode\n                                                                                           configuration.\n                                                                                           If reInitEncodeParams.encodeConfig is NULL and\n                                                                                           reInitEncodeParams.presetGUID is different from the preset\n                                                                                           GUID specified on the call to NvEncInitializeEncoder(),\n                                                                                           EncodeAPI will try to use the default configuration for\n                                                                                           the preset specified by reInitEncodeParams.presetGUID.\n                                                                                           In this case, reconfiguration may fail if the new\n                                                                                           configuration is incompatible with the existing\n                                                                                           configuration (e.g. the new configuration results in\n                                                                                           a change in the GOP structure). */\n    uint32_t                                    resetEncoder            : 1;     /**< [in]: This resets the rate control states and other internal encoder states. This should be used only with an IDR frame.\n                                                                                           If NV_ENC_INITIALIZE_PARAMS::enablePTD is set to 1, encoder will force the frame type to IDR */\n    uint32_t                                    forceIDR                : 1;     /**< [in]: Encode the current picture as an IDR picture. This flag is only valid when Picture type decision is taken by the Encoder\n                                                                                           [_NV_ENC_INITIALIZE_PARAMS::enablePTD == 1]. */\n    uint32_t                                    reserved                : 30;\n\n} NV_ENC_RECONFIGURE_PARAMS;\n\n/** macro for constructing the version field of ::_NV_ENC_RECONFIGURE_PARAMS */\n#define NV_ENC_RECONFIGURE_PARAMS_VER (NVENCAPI_STRUCT_VERSION(1) | ( 1<<31 ))\n\n/**\n * \\struct _NV_ENC_PRESET_CONFIG\n * Encoder preset config\n */\ntypedef struct _NV_ENC_PRESET_CONFIG\n{\n    uint32_t      version;                               /**< [in]:  Struct version. Must be set to ::NV_ENC_PRESET_CONFIG_VER. */\n    NV_ENC_CONFIG presetCfg;                             /**< [out]: preset config returned by the Nvidia Video Encoder interface. */\n    uint32_t      reserved1[255];                        /**< [in]: Reserved and must be set to 0 */\n    void         *reserved2[64];                         /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_PRESET_CONFIG;\n\n/** macro for constructing the version field of ::_NV_ENC_PRESET_CONFIG */\n#define NV_ENC_PRESET_CONFIG_VER (NVENCAPI_STRUCT_VERSION(4) | ( 1<<31 ))\n\n\n/**\n * \\struct _NV_ENC_PIC_PARAMS_MVC\n * MVC-specific parameters to be sent on a per-frame basis.\n */\ntypedef struct _NV_ENC_PIC_PARAMS_MVC\n{\n    uint32_t version;                                    /**< [in]: Struct version. Must be set to ::NV_ENC_PIC_PARAMS_MVC_VER. */\n    uint32_t viewID;                                     /**< [in]: Specifies the view ID associated with the current input view. */\n    uint32_t temporalID;                                 /**< [in]: Specifies the temporal ID associated with the current input view. */\n    uint32_t priorityID;                                 /**< [in]: Specifies the priority ID associated with the current input view. Reserved and ignored by the NvEncodeAPI interface. */\n    uint32_t reserved1[12];                              /**< [in]: Reserved and must be set to 0. */\n    void    *reserved2[8];                              /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_PIC_PARAMS_MVC;\n\n/** macro for constructing the version field of ::_NV_ENC_PIC_PARAMS_MVC */\n#define NV_ENC_PIC_PARAMS_MVC_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * \\union _NV_ENC_PIC_PARAMS_H264_EXT\n * H264 extension  picture parameters\n */\ntypedef union _NV_ENC_PIC_PARAMS_H264_EXT\n{\n    NV_ENC_PIC_PARAMS_MVC mvcPicParams;                  /**< [in]: Specifies the MVC picture parameters. */\n    uint32_t reserved1[32];                              /**< [in]: Reserved and must be set to 0.        */\n} NV_ENC_PIC_PARAMS_H264_EXT;\n\n/**\n * \\struct _NV_ENC_SEI_PAYLOAD\n *  User SEI message\n */\ntypedef struct _NV_ENC_SEI_PAYLOAD\n{\n    uint32_t payloadSize;            /**< [in] SEI payload size in bytes. SEI payload must be byte aligned, as described in Annex D */\n    uint32_t payloadType;            /**< [in] SEI payload types and syntax can be found in Annex D of the H.264 Specification. */\n    uint8_t *payload;                /**< [in] pointer to user data */\n} NV_ENC_SEI_PAYLOAD;\n\n#define NV_ENC_H264_SEI_PAYLOAD NV_ENC_SEI_PAYLOAD\n\n/**\n * \\struct _NV_ENC_PIC_PARAMS_H264\n * H264 specific enc pic params. sent on a per frame basis.\n */\ntypedef struct _NV_ENC_PIC_PARAMS_H264\n{\n    uint32_t displayPOCSyntax;                           /**< [in]: Specifies the display POC syntax This is required to be set if client is handling the picture type decision. */\n    uint32_t reserved3;                                  /**< [in]: Reserved and must be set to 0 */\n    uint32_t refPicFlag;                                 /**< [in]: Set to 1 for a reference picture. This is ignored if NV_ENC_INITIALIZE_PARAMS::enablePTD is set to 1. */\n    uint32_t colourPlaneId;                              /**< [in]: Specifies the colour plane ID associated with the current input. */\n    uint32_t forceIntraRefreshWithFrameCnt;              /**< [in]: Forces an intra refresh with duration equal to intraRefreshFrameCnt.\n                                                                    When outputRecoveryPointSEI is set this is value is used for recovery_frame_cnt in recovery point SEI message\n                                                                    forceIntraRefreshWithFrameCnt cannot be used if B frames are used in the GOP structure specified */\n    uint32_t constrainedFrame           : 1;              /**< [in]: Set to 1 if client wants to encode this frame with each slice completely independent of other slices in the frame.\n                                                                    NV_ENC_INITIALIZE_PARAMS::enableConstrainedEncoding should be set to 1 */\n    uint32_t sliceModeDataUpdate        : 1;              /**< [in]: Set to 1 if client wants to change the sliceModeData field to specify new sliceSize Parameter\n                                                                    When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting */\n    uint32_t ltrMarkFrame               : 1;             /**< [in]: Set to 1 if client wants to mark this frame as LTR */\n    uint32_t ltrUseFrames               : 1;             /**< [in]: Set to 1 if client allows encoding this frame using the LTR frames specified in ltrFrameBitmap */\n    uint32_t reservedBitFields          : 28;            /**< [in]: Reserved bit fields and must be set to 0 */\n    uint8_t *sliceTypeData;                              /**< [in]: Deprecated. */\n    uint32_t sliceTypeArrayCnt;                          /**< [in]: Deprecated. */\n    uint32_t seiPayloadArrayCnt;                         /**< [in]: Specifies the number of elements allocated in  seiPayloadArray array. */\n    NV_ENC_SEI_PAYLOAD *seiPayloadArray;                 /**< [in]: Array of SEI payloads which will be inserted for this frame. */\n    uint32_t sliceMode;                                  /**< [in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divided into slices\n                                                                    sliceMode = 0 MB based slices, sliceMode = 1 Byte based slices, sliceMode = 2 MB row based slices, sliceMode = 3, numSlices in Picture\n                                                                    When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting\n                                                                    When sliceMode == 0 and sliceModeData == 0 whole picture will be coded with one slice */\n    uint32_t sliceModeData;                              /**< [in]: Specifies the parameter needed for sliceMode. For:\n                                                                    sliceMode = 0, sliceModeData specifies # of MBs in each slice (except last slice)\n                                                                    sliceMode = 1, sliceModeData specifies maximum # of bytes in each slice (except last slice)\n                                                                    sliceMode = 2, sliceModeData specifies # of MB rows in each slice (except last slice)\n                                                                    sliceMode = 3, sliceModeData specifies number of slices in the picture. Driver will divide picture into slices optimally */\n    uint32_t ltrMarkFrameIdx;                            /**< [in]: Specifies the long term referenceframe index to use for marking this frame as LTR.*/\n    uint32_t ltrUseFrameBitmap;                          /**< [in]: Specifies the associated bitmap of LTR frame indices to use when encoding this frame. */\n    uint32_t ltrUsageMode;                               /**< [in]: Not supported. Reserved for future use and must be set to 0. */\n    uint32_t forceIntraSliceCount;                       /**< [in]: Specifies the number of slices to be forced to Intra in the current picture.\n                                                                    This option along with forceIntraSliceIdx[] array needs to be used with sliceMode = 3 only */\n    uint32_t *forceIntraSliceIdx;                        /**< [in]: Slice indices to be forced to intra in the current picture. Each slice index should be <= num_slices_in_picture -1. Index starts from 0 for first slice.\n                                                                    The number of entries in this array should be equal to forceIntraSliceCount */\n    NV_ENC_PIC_PARAMS_H264_EXT h264ExtPicParams;         /**< [in]: Specifies the H264 extension config parameters using this config. */\n    uint32_t reserved [210];                             /**< [in]: Reserved and must be set to 0. */\n    void    *reserved2[61];                              /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_PIC_PARAMS_H264;\n\n/**\n * \\struct _NV_ENC_PIC_PARAMS_HEVC\n * HEVC specific enc pic params. sent on a per frame basis.\n */\ntypedef struct _NV_ENC_PIC_PARAMS_HEVC\n{\n    uint32_t displayPOCSyntax;                           /**< [in]: Specifies the display POC syntax This is required to be set if client is handling the picture type decision. */\n    uint32_t refPicFlag;                                 /**< [in]: Set to 1 for a reference picture. This is ignored if NV_ENC_INITIALIZE_PARAMS::enablePTD is set to 1. */\n    uint32_t temporalId;                                 /**< [in]: Specifies the temporal id of the picture */\n    uint32_t forceIntraRefreshWithFrameCnt;              /**< [in]: Forces an intra refresh with duration equal to intraRefreshFrameCnt.\n                                                                    When outputRecoveryPointSEI is set this is value is used for recovery_frame_cnt in recovery point SEI message\n                                                                    forceIntraRefreshWithFrameCnt cannot be used if B frames are used in the GOP structure specified */\n    uint32_t constrainedFrame           : 1;              /**< [in]: Set to 1 if client wants to encode this frame with each slice completely independent of other slices in the frame.\n                                                                    NV_ENC_INITIALIZE_PARAMS::enableConstrainedEncoding should be set to 1 */\n    uint32_t sliceModeDataUpdate        : 1;              /**< [in]: Set to 1 if client wants to change the sliceModeData field to specify new sliceSize Parameter\n                                                                    When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting */\n    uint32_t ltrMarkFrame               : 1;             /**< [in]: Set to 1 if client wants to mark this frame as LTR */\n    uint32_t ltrUseFrames               : 1;             /**< [in]: Set to 1 if client allows encoding this frame using the LTR frames specified in ltrFrameBitmap */\n    uint32_t reservedBitFields          : 28;            /**< [in]: Reserved bit fields and must be set to 0 */\n    uint8_t *sliceTypeData;                              /**< [in]: Array which specifies the slice type used to force intra slice for a particular slice. Currently supported only for NV_ENC_CONFIG_H264::sliceMode == 3.\n                                                                    Client should allocate array of size sliceModeData where sliceModeData is specified in field of ::_NV_ENC_CONFIG_H264\n                                                                    Array element with index n corresponds to nth slice. To force a particular slice to intra client should set corresponding array element to NV_ENC_SLICE_TYPE_I\n                                                                    all other array elements should be set to NV_ENC_SLICE_TYPE_DEFAULT */\n    uint32_t sliceTypeArrayCnt;                          /**< [in]: Client should set this to the number of elements allocated in sliceTypeData array. If sliceTypeData is NULL then this should be set to 0 */\n    uint32_t sliceMode;                                  /**< [in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divided into slices\n                                                                    sliceMode = 0 CTU based slices, sliceMode = 1 Byte based slices, sliceMode = 2 CTU row based slices, sliceMode = 3, numSlices in Picture\n                                                                    When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting\n                                                                    When sliceMode == 0 and sliceModeData == 0 whole picture will be coded with one slice */\n    uint32_t sliceModeData;                              /**< [in]: Specifies the parameter needed for sliceMode. For:\n                                                                    sliceMode = 0, sliceModeData specifies # of CTUs in each slice (except last slice)\n                                                                    sliceMode = 1, sliceModeData specifies maximum # of bytes in each slice (except last slice)\n                                                                    sliceMode = 2, sliceModeData specifies # of CTU rows in each slice (except last slice)\n                                                                    sliceMode = 3, sliceModeData specifies number of slices in the picture. Driver will divide picture into slices optimally */\n    uint32_t ltrMarkFrameIdx;                            /**< [in]: Specifies the long term reference frame index to use for marking this frame as LTR.*/\n    uint32_t ltrUseFrameBitmap;                          /**< [in]: Specifies the associated bitmap of LTR frame indices to use when encoding this frame. */\n    uint32_t ltrUsageMode;                               /**< [in]: Not supported. Reserved for future use and must be set to 0. */\n    uint32_t seiPayloadArrayCnt;                         /**< [in]: Specifies the number of elements allocated in  seiPayloadArray array. */\n    uint32_t reserved;                                   /**< [in]: Reserved and must be set to 0. */\n    NV_ENC_SEI_PAYLOAD *seiPayloadArray;                 /**< [in]: Array of SEI payloads which will be inserted for this frame. */\n    uint32_t reserved2 [244];                             /**< [in]: Reserved and must be set to 0. */\n    void    *reserved3[61];                              /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_PIC_PARAMS_HEVC;\n\n/**\n * Codec specific per-picture encoding parameters.\n */\ntypedef union _NV_ENC_CODEC_PIC_PARAMS\n{\n    NV_ENC_PIC_PARAMS_H264 h264PicParams;                /**< [in]: H264 encode picture params. */\n    NV_ENC_PIC_PARAMS_HEVC hevcPicParams;                /**< [in]: HEVC encode picture params. */\n    uint32_t               reserved[256];                /**< [in]: Reserved and must be set to 0. */\n} NV_ENC_CODEC_PIC_PARAMS;\n\n/**\n * \\struct _NV_ENC_PIC_PARAMS\n * Encoding parameters that need to be sent on a per frame basis.\n */\ntypedef struct _NV_ENC_PIC_PARAMS\n{\n    uint32_t                                    version;                        /**< [in]: Struct version. Must be set to ::NV_ENC_PIC_PARAMS_VER. */\n    uint32_t                                    inputWidth;                     /**< [in]: Specifies the input frame width */\n    uint32_t                                    inputHeight;                    /**< [in]: Specifies the input frame height */\n    uint32_t                                    inputPitch;                     /**< [in]: Specifies the input buffer pitch. If pitch value is not known, set this to inputWidth. */\n    uint32_t                                    encodePicFlags;                 /**< [in]: Specifies bit-wise OR of encode picture flags. See ::NV_ENC_PIC_FLAGS enum. */\n    uint32_t                                    frameIdx;                       /**< [in]: Specifies the frame index associated with the input frame [optional]. */\n    uint64_t                                    inputTimeStamp;                 /**< [in]: Specifies opaque data which is associated with the encoded frame, but not actually encoded in the output bitstream.\n                                                                                           This opaque data can be used later to uniquely refer to the corresponding encoded frame. For example, it can be used\n                                                                                           for identifying the frame to be invalidated in the reference picture buffer, if lost at the client. */\n    uint64_t                                    inputDuration;                  /**< [in]: Specifies duration of the input picture */\n    NV_ENC_INPUT_PTR                            inputBuffer;                    /**< [in]: Specifies the input buffer pointer. Client must use a pointer obtained from ::NvEncCreateInputBuffer() or ::NvEncMapInputResource() APIs.*/\n    NV_ENC_OUTPUT_PTR                           outputBitstream;                /**< [in]: Specifies the output buffer pointer.\n                                                                                           If NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is set to 0, specifies the pointer to output buffer. Client should use a pointer obtained from ::NvEncCreateBitstreamBuffer() API.\n                                                                                           If NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is set to 1, client should allocate buffer in video memory for NV_ENC_ENCODE_OUT_PARAMS struct and encoded bitstream data. Client\n                                                                                           should use a pointer obtained from ::NvEncMapInputResource() API, when mapping this output buffer and assign it to NV_ENC_PIC_PARAMS::outputBitstream.\n                                                                                           First 256 bytes of this buffer should be interpreted as NV_ENC_ENCODE_OUT_PARAMS struct followed by encoded bitstream data. Recommended size for output buffer is sum of size of\n                                                                                           NV_ENC_ENCODE_OUT_PARAMS struct and twice the input frame size for lower resolution eg. CIF and 1.5 times the input frame size for higher resolutions. If encoded bitstream size is\n                                                                                           greater than the allocated buffer size for encoded bitstream, then the output buffer will have encoded bitstream data equal to buffer size. All CUDA operations on this buffer must use\n                                                                                           the default stream. */\n    void                                       *completionEvent;                /**< [in]: Specifies an event to be signaled on completion of encoding of this Frame [only if operating in Asynchronous mode]. Each output buffer should be associated with a distinct event pointer. */\n    NV_ENC_BUFFER_FORMAT                        bufferFmt;                      /**< [in]: Specifies the input buffer format. */\n    NV_ENC_PIC_STRUCT                           pictureStruct;                  /**< [in]: Specifies structure of the input picture. */\n    NV_ENC_PIC_TYPE                             pictureType;                    /**< [in]: Specifies input picture type. Client required to be set explicitly by the client if the client has not set NV_ENC_INITALIZE_PARAMS::enablePTD to 1 while calling NvInitializeEncoder. */\n    NV_ENC_CODEC_PIC_PARAMS                     codecPicParams;                 /**< [in]: Specifies the codec specific per-picture encoding parameters. */\n    NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE meHintCountsPerBlock[2];        /**< [in]: Specifies the number of hint candidates per block per direction for the current frame. meHintCountsPerBlock[0] is for L0 predictors and meHintCountsPerBlock[1] is for L1 predictors.\n                                                                                           The candidate count in NV_ENC_PIC_PARAMS::meHintCountsPerBlock[lx] must never exceed NV_ENC_INITIALIZE_PARAMS::maxMEHintCountsPerBlock[lx] provided during encoder initialization. */\n    NVENC_EXTERNAL_ME_HINT                     *meExternalHints;                /**< [in]: Specifies the pointer to ME external hints for the current frame. The size of ME hint buffer should be equal to number of macroblocks * the total number of candidates per macroblock.\n                                                                                           The total number of candidates per MB per direction = 1*meHintCountsPerBlock[Lx].numCandsPerBlk16x16 + 2*meHintCountsPerBlock[Lx].numCandsPerBlk16x8 + 2*meHintCountsPerBlock[Lx].numCandsPerBlk8x8\n                                                                                           + 4*meHintCountsPerBlock[Lx].numCandsPerBlk8x8. For frames using bidirectional ME , the total number of candidates for single macroblock is sum of total number of candidates per MB for each direction (L0 and L1) */\n    uint32_t                                    reserved1[6];                    /**< [in]: Reserved and must be set to 0 */\n    void                                       *reserved2[2];                    /**< [in]: Reserved and must be set to NULL */\n    int8_t                                     *qpDeltaMap;                      /**< [in]: Specifies the pointer to signed byte array containing value per MB for H264 and per CTB for HEVC in raster scan order for the current picture, which will be interpreted depending on NV_ENC_RC_PARAMS::qpMapMode.\n                                                                                            If NV_ENC_RC_PARAMS::qpMapMode is NV_ENC_QP_MAP_DELTA, qpDeltaMap specifies QP modifier per MB for H264 and per CTB for HEVC. This QP modifier will be applied on top of the QP chosen by rate control.\n                                                                                            If NV_ENC_RC_PARAMS::qpMapMode is NV_ENC_QP_MAP_EMPHASIS, qpDeltaMap specifies Emphasis Level Map per MB for H264. This level value along with QP chosen by rate control is used to\n                                                                                            compute the QP modifier, which in turn is applied on top of QP chosen by rate control.\n                                                                                            If NV_ENC_RC_PARAMS::qpMapMode is NV_ENC_QP_MAP_DISABLED, value in qpDeltaMap will be ignored.*/\n    uint32_t                                    qpDeltaMapSize;                  /**< [in]: Specifies the size in bytes of qpDeltaMap surface allocated by client and pointed to by NV_ENC_PIC_PARAMS::qpDeltaMap. Surface (array) should be picWidthInMbs * picHeightInMbs for H264 and picWidthInCtbs * picHeightInCtbs for HEVC */\n    uint32_t                                    reservedBitFields;               /**< [in]: Reserved bitfields and must be set to 0 */\n    uint16_t                                    meHintRefPicDist[2];             /**< [in]: Specifies temporal distance for reference picture (NVENC_EXTERNAL_ME_HINT::refidx = 0) used during external ME with NV_ENC_INITALIZE_PARAMS::enablePTD = 1 . meHintRefPicDist[0] is for L0 hints and meHintRefPicDist[1] is for L1 hints.\n                                                                                            If not set, will internally infer distance of 1. Ignored for NV_ENC_INITALIZE_PARAMS::enablePTD = 0 */\n    NV_ENC_INPUT_PTR                            alphaBuffer;                     /**< [in]: Specifies the input alpha buffer pointer. Client must use a pointer obtained from ::NvEncCreateInputBuffer() or ::NvEncMapInputResource() APIs.\n                                                                                            Applicable only when encoding hevc with alpha layer is enabled. */\n    uint32_t                                    reserved3[286];                  /**< [in]: Reserved and must be set to 0 */\n    void                                       *reserved4[59];                   /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_PIC_PARAMS;\n\n/** Macro for constructing the version field of ::_NV_ENC_PIC_PARAMS */\n#define NV_ENC_PIC_PARAMS_VER (NVENCAPI_STRUCT_VERSION(4) | ( 1U<<31 ))\n\n\n/**\n * \\struct _NV_ENC_MEONLY_PARAMS\n * MEOnly parameters that need to be sent on a per motion estimation basis.\n * NV_ENC_MEONLY_PARAMS::meExternalHints is supported for H264 only.\n */\ntypedef struct _NV_ENC_MEONLY_PARAMS\n{\n    uint32_t                version;                            /**< [in]: Struct version. Must be set to NV_ENC_MEONLY_PARAMS_VER.*/\n    uint32_t                inputWidth;                         /**< [in]: Specifies the input frame width */\n    uint32_t                inputHeight;                        /**< [in]: Specifies the input frame height */\n    NV_ENC_INPUT_PTR        inputBuffer;                        /**< [in]: Specifies the input buffer pointer. Client must use a pointer obtained from NvEncCreateInputBuffer() or NvEncMapInputResource() APIs. */\n    NV_ENC_INPUT_PTR        referenceFrame;                     /**< [in]: Specifies the reference frame pointer */\n    NV_ENC_OUTPUT_PTR       mvBuffer;                           /**< [in]: Specifies the output buffer pointer.\n                                                                           If NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is set to 0, specifies the pointer to motion vector data buffer allocated by NvEncCreateMVBuffer.\n                                                                           Client must lock mvBuffer using ::NvEncLockBitstream() API to get the motion vector data.\n                                                                           If NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is set to 1, client should allocate buffer in video memory for storing the motion vector data. The size of this buffer must\n                                                                           be equal to total number of macroblocks multiplied by size of NV_ENC_H264_MV_DATA struct. Client should use a pointer obtained from ::NvEncMapInputResource() API, when mapping this\n                                                                           output buffer and assign it to NV_ENC_MEONLY_PARAMS::mvBuffer. All CUDA operations on this buffer must use the default stream. */\n    NV_ENC_BUFFER_FORMAT    bufferFmt;                          /**< [in]: Specifies the input buffer format. */\n    void                   *completionEvent;                    /**< [in]: Specifies an event to be signaled on completion of motion estimation\n                                                                           of this Frame [only if operating in Asynchronous mode].\n                                                                           Each output buffer should be associated with a distinct event pointer. */\n    uint32_t                viewID;                             /**< [in]: Specifies left or right viewID if NV_ENC_CONFIG_H264_MEONLY::bStereoEnable is set.\n                                                                            viewID can be 0,1 if bStereoEnable is set, 0 otherwise. */\n    NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE\n    meHintCountsPerBlock[2];            /**< [in]: Specifies the number of hint candidates per block for the current frame. meHintCountsPerBlock[0] is for L0 predictors.\n                                                                            The candidate count in NV_ENC_PIC_PARAMS::meHintCountsPerBlock[lx] must never exceed NV_ENC_INITIALIZE_PARAMS::maxMEHintCountsPerBlock[lx] provided during encoder initialization. */\n    NVENC_EXTERNAL_ME_HINT  *meExternalHints;                   /**< [in]: Specifies the pointer to ME external hints for the current frame. The size of ME hint buffer should be equal to number of macroblocks * the total number of candidates per macroblock.\n                                                                            The total number of candidates per MB per direction = 1*meHintCountsPerBlock[Lx].numCandsPerBlk16x16 + 2*meHintCountsPerBlock[Lx].numCandsPerBlk16x8 + 2*meHintCountsPerBlock[Lx].numCandsPerBlk8x8\n                                                                            + 4*meHintCountsPerBlock[Lx].numCandsPerBlk8x8. For frames using bidirectional ME , the total number of candidates for single macroblock is sum of total number of candidates per MB for each direction (L0 and L1) */\n    uint32_t                reserved1[243];                     /**< [in]: Reserved and must be set to 0 */\n    void                   *reserved2[59];                      /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_MEONLY_PARAMS;\n\n/** NV_ENC_MEONLY_PARAMS struct version*/\n#define NV_ENC_MEONLY_PARAMS_VER NVENCAPI_STRUCT_VERSION(3)\n\n\n/**\n * \\struct _NV_ENC_LOCK_BITSTREAM\n * Bitstream buffer lock parameters.\n */\ntypedef struct _NV_ENC_LOCK_BITSTREAM\n{\n    uint32_t                version;                     /**< [in]: Struct version. Must be set to ::NV_ENC_LOCK_BITSTREAM_VER. */\n    uint32_t                doNotWait         : 1;       /**< [in]: If this flag is set, the NvEncodeAPI interface will return buffer pointer even if operation is not completed. If not set, the call will block until operation completes. */\n    uint32_t                ltrFrame          : 1;       /**< [out]: Flag indicating this frame is marked as LTR frame */\n    uint32_t                getRCStats        : 1;       /**< [in]: If this flag is set then lockBitstream call will add additional intra-inter MB count and average MVX, MVY */\n    uint32_t                reservedBitFields : 29;      /**< [in]: Reserved bit fields and must be set to 0 */\n    void                   *outputBitstream;             /**< [in]: Pointer to the bitstream buffer being locked. */\n    uint32_t               *sliceOffsets;                /**< [in, out]: Array which receives the slice offsets. This is not supported if NV_ENC_CONFIG_H264::sliceMode is 1 on Kepler GPUs. Array size must be equal to size of frame in MBs. */\n    uint32_t                frameIdx;                    /**< [out]: Frame no. for which the bitstream is being retrieved. */\n    uint32_t                hwEncodeStatus;              /**< [out]: The NvEncodeAPI interface status for the locked picture. */\n    uint32_t                numSlices;                   /**< [out]: Number of slices in the encoded picture. Will be reported only if NV_ENC_INITIALIZE_PARAMS::reportSliceOffsets set to 1. */\n    uint32_t                bitstreamSizeInBytes;        /**< [out]: Actual number of bytes generated and copied to the memory pointed by bitstreamBufferPtr.\n                                                                     When HEVC alpha layer encoding is enabled, this field reports the total encoded size in bytes i.e it is the encoded size of the base plus the alpha layer. */\n    uint64_t                outputTimeStamp;             /**< [out]: Presentation timestamp associated with the encoded output. */\n    uint64_t                outputDuration;              /**< [out]: Presentation duration associates with the encoded output. */\n    void                   *bitstreamBufferPtr;          /**< [out]: Pointer to the generated output bitstream.\n                                                                     For MEOnly mode _NV_ENC_LOCK_BITSTREAM::bitstreamBufferPtr should be typecast to\n                                                                     NV_ENC_H264_MV_DATA/NV_ENC_HEVC_MV_DATA pointer respectively for H264/HEVC  */\n    NV_ENC_PIC_TYPE         pictureType;                 /**< [out]: Picture type of the encoded picture. */\n    NV_ENC_PIC_STRUCT       pictureStruct;               /**< [out]: Structure of the generated output picture. */\n    uint32_t                frameAvgQP;                  /**< [out]: Average QP of the frame. */\n    uint32_t                frameSatd;                   /**< [out]: Total SATD cost for whole frame. */\n    uint32_t                ltrFrameIdx;                 /**< [out]: Frame index associated with this LTR frame. */\n    uint32_t                ltrFrameBitmap;              /**< [out]: Bitmap of LTR frames indices which were used for encoding this frame. Value of 0 if no LTR frames were used. */\n    uint32_t                reserved[13];                /**< [in]: Reserved and must be set to 0 */\n    uint32_t                intraMBCount;                /**< [out]: For H264, Number of Intra MBs in the encoded frame. For HEVC, Number of Intra CTBs in the encoded frame. Supported only if _NV_ENC_LOCK_BITSTREAM::getRCStats set to 1. */\n    uint32_t                interMBCount;                /**< [out]: For H264, Number of Inter MBs in the encoded frame, includes skip MBs. For HEVC, Number of Inter CTBs in the encoded frame. Supported only if _NV_ENC_LOCK_BITSTREAM::getRCStats set to 1. */\n    int32_t                 averageMVX;                  /**< [out]: Average Motion Vector in X direction for the encoded frame. Supported only if _NV_ENC_LOCK_BITSTREAM::getRCStats set to 1. */\n    int32_t                 averageMVY;                  /**< [out]: Average Motion Vector in y direction for the encoded frame. Supported only if _NV_ENC_LOCK_BITSTREAM::getRCStats set to 1. */\n    uint32_t                alphaLayerSizeInBytes;       /**< [out]: Number of bytes generated for the alpha layer in the encoded output. Applicable only when HEVC with alpha encoding is enabled. */\n\n    uint32_t                reserved1[218];              /**< [in]: Reserved and must be set to 0 */\n    void                   *reserved2[64];               /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_LOCK_BITSTREAM;\n\n/** Macro for constructing the version field of ::_NV_ENC_LOCK_BITSTREAM */\n#define NV_ENC_LOCK_BITSTREAM_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * \\struct _NV_ENC_LOCK_INPUT_BUFFER\n * Uncompressed Input Buffer lock parameters.\n */\ntypedef struct _NV_ENC_LOCK_INPUT_BUFFER\n{\n    uint32_t                  version;                   /**< [in]:  Struct version. Must be set to ::NV_ENC_LOCK_INPUT_BUFFER_VER. */\n    uint32_t                  doNotWait         : 1;     /**< [in]:  Set to 1 to make ::NvEncLockInputBuffer() a unblocking call. If the encoding is not completed, driver will return ::NV_ENC_ERR_ENCODER_BUSY error code. */\n    uint32_t                  reservedBitFields : 31;    /**< [in]:  Reserved bitfields and must be set to 0 */\n    NV_ENC_INPUT_PTR          inputBuffer;               /**< [in]:  Pointer to the input buffer to be locked, client should pass the pointer obtained from ::NvEncCreateInputBuffer() or ::NvEncMapInputResource API. */\n    void                     *bufferDataPtr;             /**< [out]: Pointed to the locked input buffer data. Client can only access input buffer using the \\p bufferDataPtr. */\n    uint32_t                  pitch;                     /**< [out]: Pitch of the locked input buffer. */\n    uint32_t                  reserved1[251];            /**< [in]:  Reserved and must be set to 0  */\n    void                     *reserved2[64];             /**< [in]:  Reserved and must be set to NULL  */\n} NV_ENC_LOCK_INPUT_BUFFER;\n\n/** Macro for constructing the version field of ::_NV_ENC_LOCK_INPUT_BUFFER */\n#define NV_ENC_LOCK_INPUT_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * \\struct _NV_ENC_MAP_INPUT_RESOURCE\n * Map an input resource to a Nvidia Encoder Input Buffer\n */\ntypedef struct _NV_ENC_MAP_INPUT_RESOURCE\n{\n    uint32_t                   version;                   /**< [in]:  Struct version. Must be set to ::NV_ENC_MAP_INPUT_RESOURCE_VER. */\n    uint32_t                   subResourceIndex;          /**< [in]:  Deprecated. Do not use. */\n    void                      *inputResource;             /**< [in]:  Deprecated. Do not use. */\n    NV_ENC_REGISTERED_PTR      registeredResource;        /**< [in]:  The Registered resource handle obtained by calling NvEncRegisterInputResource. */\n    NV_ENC_INPUT_PTR           mappedResource;            /**< [out]: Mapped pointer corresponding to the registeredResource. This pointer must be used in NV_ENC_PIC_PARAMS::inputBuffer parameter in ::NvEncEncodePicture() API. */\n    NV_ENC_BUFFER_FORMAT       mappedBufferFmt;           /**< [out]: Buffer format of the outputResource. This buffer format must be used in NV_ENC_PIC_PARAMS::bufferFmt if client using the above mapped resource pointer. */\n    uint32_t                   reserved1[251];            /**< [in]:  Reserved and must be set to 0. */\n    void                      *reserved2[63];             /**< [in]:  Reserved and must be set to NULL */\n} NV_ENC_MAP_INPUT_RESOURCE;\n\n/** Macro for constructing the version field of ::_NV_ENC_MAP_INPUT_RESOURCE */\n#define NV_ENC_MAP_INPUT_RESOURCE_VER NVENCAPI_STRUCT_VERSION(4)\n\n/**\n * \\struct _NV_ENC_INPUT_RESOURCE_OPENGL_TEX\n * NV_ENC_REGISTER_RESOURCE::resourceToRegister must be a pointer to a variable of this type,\n * when NV_ENC_REGISTER_RESOURCE::resourceType is NV_ENC_INPUT_RESOURCE_TYPE_OPENGL_TEX\n */\ntypedef struct _NV_ENC_INPUT_RESOURCE_OPENGL_TEX\n{\n    uint32_t texture;                                     /**< [in]: The name of the texture to be used. */\n    uint32_t target;                                      /**< [in]: Accepted values are GL_TEXTURE_RECTANGLE and GL_TEXTURE_2D. */\n} NV_ENC_INPUT_RESOURCE_OPENGL_TEX;\n\n/**\n * \\struct _NV_ENC_REGISTER_RESOURCE\n * Register a resource for future use with the Nvidia Video Encoder Interface.\n */\ntypedef struct _NV_ENC_REGISTER_RESOURCE\n{\n    uint32_t                    version;                        /**< [in]: Struct version. Must be set to ::NV_ENC_REGISTER_RESOURCE_VER. */\n    NV_ENC_INPUT_RESOURCE_TYPE  resourceType;                   /**< [in]: Specifies the type of resource to be registered.\n                                                                           Supported values are\n                                                                           ::NV_ENC_INPUT_RESOURCE_TYPE_DIRECTX,\n                                                                           ::NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR,\n                                                                           ::NV_ENC_INPUT_RESOURCE_TYPE_OPENGL_TEX */\n    uint32_t                    width;                          /**< [in]: Input frame width. */\n    uint32_t                    height;                         /**< [in]: Input frame height. */\n    uint32_t                    pitch;                          /**< [in]: Input buffer pitch.\n                                                                           For ::NV_ENC_INPUT_RESOURCE_TYPE_DIRECTX resources, set this to 0.\n                                                                           For ::NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR resources, set this to\n                                                                             the pitch as obtained from cuMemAllocPitch(), or to the width in\n                                                                             bytes (if this resource was created by using cuMemAlloc()). This\n                                                                             value must be a multiple of 4.\n                                                                           For ::NV_ENC_INPUT_RESOURCE_TYPE_CUDAARRAY resources, set this to the\n                                                                             width of the allocation in bytes (i.e.\n                                                                             CUDA_ARRAY3D_DESCRIPTOR::Width * CUDA_ARRAY3D_DESCRIPTOR::NumChannels).\n                                                                           For ::NV_ENC_INPUT_RESOURCE_TYPE_OPENGL_TEX resources, set this to the\n                                                                             texture width multiplied by the number of components in the texture\n                                                                             format. */\n    uint32_t                    subResourceIndex;               /**< [in]: Subresource Index of the DirectX resource to be registered. Should be set to 0 for other interfaces. */\n    void                       *resourceToRegister;             /**< [in]: Handle to the resource that is being registered. */\n    NV_ENC_REGISTERED_PTR       registeredResource;             /**< [out]: Registered resource handle. This should be used in future interactions with the Nvidia Video Encoder Interface. */\n    NV_ENC_BUFFER_FORMAT        bufferFormat;                   /**< [in]: Buffer format of resource to be registered. */\n    NV_ENC_BUFFER_USAGE         bufferUsage;                    /**< [in]: Usage of resource to be registered. */\n    uint32_t                    reserved1[247];                 /**< [in]: Reserved and must be set to 0. */\n    void                       *reserved2[62];                  /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_REGISTER_RESOURCE;\n\n/** Macro for constructing the version field of ::_NV_ENC_REGISTER_RESOURCE */\n#define NV_ENC_REGISTER_RESOURCE_VER NVENCAPI_STRUCT_VERSION(3)\n\n/**\n * \\struct _NV_ENC_STAT\n * Encode Stats structure.\n */\ntypedef struct _NV_ENC_STAT\n{\n    uint32_t            version;                         /**< [in]:  Struct version. Must be set to ::NV_ENC_STAT_VER. */\n    uint32_t            reserved;                        /**< [in]:  Reserved and must be set to 0 */\n    NV_ENC_OUTPUT_PTR   outputBitStream;                 /**< [out]: Specifies the pointer to output bitstream. */\n    uint32_t            bitStreamSize;                   /**< [out]: Size of generated bitstream in bytes. */\n    uint32_t            picType;                         /**< [out]: Picture type of encoded picture. See ::NV_ENC_PIC_TYPE. */\n    uint32_t            lastValidByteOffset;             /**< [out]: Offset of last valid bytes of completed bitstream */\n    uint32_t            sliceOffsets[16];                /**< [out]: Offsets of each slice */\n    uint32_t            picIdx;                          /**< [out]: Picture number */\n    uint32_t            frameAvgQP;                      /**< [out]: Average QP of the frame. */\n    uint32_t            ltrFrame          : 1;           /**< [out]: Flag indicating this frame is marked as LTR frame */\n    uint32_t            reservedBitFields : 31;          /**< [in]:  Reserved bit fields and must be set to 0 */\n    uint32_t            ltrFrameIdx;                     /**< [out]: Frame index associated with this LTR frame. */\n    uint32_t            intraMBCount;                    /**< [out]: For H264, Number of Intra MBs in the encoded frame. For HEVC, Number of Intra CTBs in the encoded frame. */\n    uint32_t            interMBCount;                    /**< [out]: For H264, Number of Inter MBs in the encoded frame, includes skip MBs. For HEVC, Number of Inter CTBs in the encoded frame. */\n    int32_t             averageMVX;                      /**< [out]: Average Motion Vector in X direction for the encoded frame. */\n    int32_t             averageMVY;                      /**< [out]: Average Motion Vector in y direction for the encoded frame. */\n    uint32_t            reserved1[226];                  /**< [in]:  Reserved and must be set to 0 */\n    void               *reserved2[64];                   /**< [in]:  Reserved and must be set to NULL */\n} NV_ENC_STAT;\n\n/** Macro for constructing the version field of ::_NV_ENC_STAT */\n#define NV_ENC_STAT_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * \\struct _NV_ENC_SEQUENCE_PARAM_PAYLOAD\n * Sequence and picture paramaters payload.\n */\ntypedef struct _NV_ENC_SEQUENCE_PARAM_PAYLOAD\n{\n    uint32_t            version;                         /**< [in]:  Struct version. Must be set to ::NV_ENC_INITIALIZE_PARAMS_VER. */\n    uint32_t            inBufferSize;                    /**< [in]:  Specifies the size of the spsppsBuffer provided by the client */\n    uint32_t            spsId;                           /**< [in]:  Specifies the SPS id to be used in sequence header. Default value is 0.  */\n    uint32_t            ppsId;                           /**< [in]:  Specifies the PPS id to be used in picture header. Default value is 0.  */\n    void               *spsppsBuffer;                    /**< [in]:  Specifies bitstream header pointer of size NV_ENC_SEQUENCE_PARAM_PAYLOAD::inBufferSize.\n                                                                     It is the client's responsibility to manage this memory. */\n    uint32_t           *outSPSPPSPayloadSize;            /**< [out]: Size of the sequence and picture header in bytes. */\n    uint32_t            reserved [250];                  /**< [in]:  Reserved and must be set to 0 */\n    void               *reserved2[64];                   /**< [in]:  Reserved and must be set to NULL */\n} NV_ENC_SEQUENCE_PARAM_PAYLOAD;\n\n/** Macro for constructing the version field of ::_NV_ENC_SEQUENCE_PARAM_PAYLOAD */\n#define NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * Event registration/unregistration parameters.\n */\ntypedef struct _NV_ENC_EVENT_PARAMS\n{\n    uint32_t            version;                          /**< [in]: Struct version. Must be set to ::NV_ENC_EVENT_PARAMS_VER. */\n    uint32_t            reserved;                         /**< [in]: Reserved and must be set to 0 */\n    void               *completionEvent;                  /**< [in]: Handle to event to be registered/unregistered with the NvEncodeAPI interface. */\n    uint32_t            reserved1[253];                   /**< [in]: Reserved and must be set to 0    */\n    void               *reserved2[64];                    /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_EVENT_PARAMS;\n\n/** Macro for constructing the version field of ::_NV_ENC_EVENT_PARAMS */\n#define NV_ENC_EVENT_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * Encoder Session Creation parameters\n */\ntypedef struct _NV_ENC_OPEN_ENCODE_SESSIONEX_PARAMS\n{\n    uint32_t            version;                          /**< [in]: Struct version. Must be set to ::NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER. */\n    NV_ENC_DEVICE_TYPE  deviceType;                       /**< [in]: Specified the device Type */\n    void               *device;                           /**< [in]: Pointer to client device. */\n    void               *reserved;                         /**< [in]: Reserved and must be set to 0. */\n    uint32_t            apiVersion;                       /**< [in]: API version. Should be set to NVENCAPI_VERSION. */\n    uint32_t            reserved1[253];                   /**< [in]: Reserved and must be set to 0    */\n    void               *reserved2[64];                    /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS;\n/** Macro for constructing the version field of ::_NV_ENC_OPEN_ENCODE_SESSIONEX_PARAMS */\n#define NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)\n\n/** @} */ /* END ENCODER_STRUCTURE */\n\n\n/**\n * \\addtogroup ENCODE_FUNC NvEncodeAPI Functions\n * @{\n */\n\n// NvEncOpenEncodeSession\n/**\n * \\brief Opens an encoding session.\n *\n * Deprecated.\n *\n * \\return\n * ::NV_ENC_ERR_INVALID_CALL\\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncOpenEncodeSession                     (void *device, uint32_t deviceType, void **encoder);\n\n// NvEncGetEncodeGuidCount\n/**\n * \\brief Retrieves the number of supported encode GUIDs.\n *\n * The function returns the number of codec GUIDs supported by the NvEncodeAPI\n * interface.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [out] encodeGUIDCount\n *   Number of supported encode GUIDs.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeGUIDCount                    (void *encoder, uint32_t *encodeGUIDCount);\n\n\n// NvEncGetEncodeGUIDs\n/**\n * \\brief Retrieves an array of supported encoder codec GUIDs.\n *\n * The function returns an array of codec GUIDs supported by the NvEncodeAPI interface.\n * The client must allocate an array where the NvEncodeAPI interface can\n * fill the supported GUIDs and pass the pointer in \\p *GUIDs parameter.\n * The size of the array can be determined by using ::NvEncGetEncodeGUIDCount() API.\n * The Nvidia Encoding interface returns the number of codec GUIDs it has actually\n * filled in the GUID array in the \\p GUIDCount parameter.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] guidArraySize\n *   Number of GUIDs to retrieved. Should be set to the number retrieved using\n *   ::NvEncGetEncodeGUIDCount.\n * \\param [out] GUIDs\n *   Array of supported Encode GUIDs.\n * \\param [out] GUIDCount\n *   Number of supported Encode GUIDs.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeGUIDs                        (void *encoder, GUID *GUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);\n\n\n// NvEncGetEncodeProfileGuidCount\n/**\n * \\brief Retrieves the number of supported profile GUIDs.\n *\n * The function returns the number of profile GUIDs supported for a given codec.\n * The client must first enumerate the codec GUIDs supported by the NvEncodeAPI\n * interface. After determining the codec GUID, it can query the NvEncodeAPI\n * interface to determine the number of profile GUIDs supported for a particular\n * codec GUID.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   The codec GUID for which the profile GUIDs are being enumerated.\n * \\param [out] encodeProfileGUIDCount\n *   Number of encode profiles supported for the given encodeGUID.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeProfileGUIDCount                    (void *encoder, GUID encodeGUID, uint32_t *encodeProfileGUIDCount);\n\n\n// NvEncGetEncodeProfileGUIDs\n/**\n * \\brief Retrieves an array of supported encode profile GUIDs.\n *\n * The function returns an array of supported profile GUIDs for a particular\n * codec GUID. The client must allocate an array where the NvEncodeAPI interface\n * can populate the profile GUIDs. The client can determine the array size using\n * ::NvEncGetEncodeProfileGUIDCount() API. The client must also validiate that the\n * NvEncodeAPI interface supports the GUID the client wants to pass as \\p encodeGUID\n * parameter.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   The encode GUID whose profile GUIDs are being enumerated.\n * \\param [in] guidArraySize\n *   Number of GUIDs to be retrieved. Should be set to the number retrieved using\n *   ::NvEncGetEncodeProfileGUIDCount.\n * \\param [out] profileGUIDs\n *   Array of supported Encode Profile GUIDs\n * \\param [out] GUIDCount\n *   Number of valid encode profile GUIDs in \\p profileGUIDs array.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeProfileGUIDs                               (void *encoder, GUID encodeGUID, GUID *profileGUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);\n\n// NvEncGetInputFormatCount\n/**\n * \\brief Retrieve the number of supported Input formats.\n *\n * The function returns the number of supported input formats. The client must\n * query the NvEncodeAPI interface to determine the supported input formats\n * before creating the input surfaces.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the number of supported input formats\n *   is to be retrieved.\n * \\param [out] inputFmtCount\n *   Number of input formats supported for specified Encode GUID.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncGetInputFormatCount                   (void *encoder, GUID encodeGUID, uint32_t *inputFmtCount);\n\n\n// NvEncGetInputFormats\n/**\n * \\brief Retrieves an array of supported Input formats\n *\n * Returns an array of supported input formats  The client must use the input\n * format to create input surface using ::NvEncCreateInputBuffer() API.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the number of supported input formats\n *   is to be retrieved.\n *\\param [in] inputFmtArraySize\n *   Size input format count array passed in \\p inputFmts.\n *\\param [out] inputFmts\n *   Array of input formats supported for this Encode GUID.\n *\\param [out] inputFmtCount\n *   The number of valid input format types returned by the NvEncodeAPI\n *   interface in \\p inputFmts array.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetInputFormats                       (void *encoder, GUID encodeGUID, NV_ENC_BUFFER_FORMAT *inputFmts, uint32_t inputFmtArraySize, uint32_t *inputFmtCount);\n\n\n// NvEncGetEncodeCaps\n/**\n * \\brief Retrieves the capability value for a specified encoder attribute.\n *\n * The function returns the capability value for a given encoder attribute. The\n * client must validate the encodeGUID using ::NvEncGetEncodeGUIDs() API before\n * calling this function. The encoder attribute being queried are enumerated in\n * ::NV_ENC_CAPS_PARAM enum.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the capability attribute is to be retrieved.\n * \\param [in] capsParam\n *   Used to specify attribute being queried. Refer ::NV_ENC_CAPS_PARAM for  more\n * details.\n * \\param [out] capsVal\n *   The value corresponding to the capability attribute being queried.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeCaps                     (void *encoder, GUID encodeGUID, NV_ENC_CAPS_PARAM *capsParam, int *capsVal);\n\n\n// NvEncGetEncodePresetCount\n/**\n * \\brief Retrieves the number of supported preset GUIDs.\n *\n * The function returns the number of preset GUIDs available for a given codec.\n * The client must validate the codec GUID using ::NvEncGetEncodeGUIDs() API\n * before calling this function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the number of supported presets is to\n *   be retrieved.\n * \\param [out] encodePresetGUIDCount\n *   Receives the number of supported preset GUIDs.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodePresetCount              (void *encoder, GUID encodeGUID, uint32_t *encodePresetGUIDCount);\n\n\n// NvEncGetEncodePresetGUIDs\n/**\n * \\brief Receives an array of supported encoder preset GUIDs.\n *\n * The function returns an array of encode preset GUIDs available for a given codec.\n * The client can directly use one of the preset GUIDs based upon the use case\n * or target device. The preset GUID chosen can be directly used in\n * NV_ENC_INITIALIZE_PARAMS::presetGUID parameter to ::NvEncEncodePicture() API.\n * Alternately client can  also use the preset GUID to retrieve the encoding config\n * parameters being used by NvEncodeAPI interface for that given preset, using\n * ::NvEncGetEncodePresetConfig() API. It can then modify preset config parameters\n * as per its use case and send it to NvEncodeAPI interface as part of\n * NV_ENC_INITIALIZE_PARAMS::encodeConfig parameter for NvEncInitializeEncoder()\n * API.\n *\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the list of supported presets is to be\n *   retrieved.\n * \\param [in] guidArraySize\n *   Size of array of preset GUIDs passed in \\p preset GUIDs\n * \\param [out] presetGUIDs\n *   Array of supported Encode preset GUIDs from the NvEncodeAPI interface\n *   to client.\n * \\param [out] encodePresetGUIDCount\n *   Receives the number of preset GUIDs returned by the NvEncodeAPI\n *   interface.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodePresetGUIDs                  (void *encoder, GUID encodeGUID, GUID *presetGUIDs, uint32_t guidArraySize, uint32_t *encodePresetGUIDCount);\n\n\n// NvEncGetEncodePresetConfig\n/**\n * \\brief Returns a preset config structure supported for given preset GUID.\n *\n * The function returns a preset config structure for a given preset GUID. Before\n * using this function the client must enumerate the preset GUIDs available for\n * a given codec. The preset config structure can be modified by the client depending\n * upon its use case and can be then used to initialize the encoder using\n * ::NvEncInitializeEncoder() API. The client can use this function only if it\n * wants to modify the NvEncodeAPI preset configuration, otherwise it can\n * directly use the preset GUID.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the list of supported presets is to be\n *   retrieved.\n * \\param [in] presetGUID\n *   Preset GUID, corresponding to which the Encoding configurations is to be\n *   retrieved.\n * \\param [out] presetConfig\n *   The requested Preset Encoder Attribute set. Refer ::_NV_ENC_CONFIG for\n*    more details.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodePresetConfig               (void *encoder, GUID encodeGUID, GUID  presetGUID, NV_ENC_PRESET_CONFIG *presetConfig);\n\n// NvEncGetEncodePresetConfigEx\n/**\n * \\brief Returns a preset config structure supported for given preset GUID.\n *\n * The function returns a preset config structure for a given preset GUID and tuning info.\n * NvEncGetEncodePresetConfigEx() API is not applicable to H264 and HEVC meonly mode.\n * Before using this function the client must enumerate the preset GUIDs available for\n * a given codec. The preset config structure can be modified by the client depending\n * upon its use case and can be then used to initialize the encoder using\n * ::NvEncInitializeEncoder() API. The client can use this function only if it\n * wants to modify the NvEncodeAPI preset configuration, otherwise it can\n * directly use the preset GUID.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the list of supported presets is to be\n *   retrieved.\n * \\param [in] presetGUID\n *   Preset GUID, corresponding to which the Encoding configurations is to be\n *   retrieved.\n * \\param [in] tuningInfo\n *   tuning info, corresponding to which the Encoding configurations is to be\n *   retrieved.\n * \\param [out] presetConfig\n *   The requested Preset Encoder Attribute set. Refer ::_NV_ENC_CONFIG for\n *    more details.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodePresetConfigEx               (void *encoder, GUID encodeGUID, GUID  presetGUID, NV_ENC_TUNING_INFO tuningInfo, NV_ENC_PRESET_CONFIG *presetConfig);\n\n// NvEncInitializeEncoder\n/**\n * \\brief Initialize the encoder.\n *\n * This API must be used to initialize the encoder. The initialization parameter\n * is passed using \\p *createEncodeParams  The client must send the following\n * fields of the _NV_ENC_INITIALIZE_PARAMS structure with a valid value.\n * - NV_ENC_INITIALIZE_PARAMS::encodeGUID\n * - NV_ENC_INITIALIZE_PARAMS::encodeWidth\n * - NV_ENC_INITIALIZE_PARAMS::encodeHeight\n *\n * The client can pass a preset GUID directly to the NvEncodeAPI interface using\n * NV_ENC_INITIALIZE_PARAMS::presetGUID field. If the client doesn't pass\n * NV_ENC_INITIALIZE_PARAMS::encodeConfig structure, the codec specific parameters\n * will be selected based on the preset GUID. The preset GUID must have been\n * validated by the client using ::NvEncGetEncodePresetGUIDs() API.\n * If the client passes a custom ::_NV_ENC_CONFIG structure through\n * NV_ENC_INITIALIZE_PARAMS::encodeConfig , it will override the codec specific parameters\n * based on the preset GUID. It is recommended that even if the client passes a custom config,\n * it should also send a preset GUID. In this case, the preset GUID passed by the client\n * will not override any of the custom config parameters programmed by the client,\n * it is only used as a hint by the NvEncodeAPI interface to determine certain encoder parameters\n * which are not exposed to the client.\n *\n * There are two modes of operation for the encoder namely:\n * - Asynchronous mode\n * - Synchronous mode\n *\n * The client can select asynchronous or synchronous mode by setting the \\p\n * enableEncodeAsync field in ::_NV_ENC_INITIALIZE_PARAMS to 1 or 0 respectively.\n *\\par Asynchronous mode of operation:\n * The Asynchronous mode can be enabled by setting NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync to 1.\n * The client operating in asynchronous mode must allocate completion event object\n * for each output buffer and pass the completion event object in the\n * ::NvEncEncodePicture() API. The client can create another thread and wait on\n * the event object to be signaled by NvEncodeAPI interface on completion of the\n * encoding process for the output frame. This should unblock the main thread from\n * submitting work to the encoder. When the event is signaled the client can call\n * NvEncodeAPI interfaces to copy the bitstream data using ::NvEncLockBitstream()\n * API. This is the preferred mode of operation.\n *\n * NOTE: Asynchronous mode is not supported on Linux.\n *\n *\\par Synchronous mode of operation:\n * The client can select synchronous mode by setting NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync to 0.\n * The client working in synchronous mode can work in a single threaded or multi\n * threaded mode. The client need not allocate any event objects. The client can\n * only lock the bitstream data after NvEncodeAPI interface has returned\n * ::NV_ENC_SUCCESS from encode picture. The NvEncodeAPI interface can return\n * ::NV_ENC_ERR_NEED_MORE_INPUT error code from ::NvEncEncodePicture() API. The\n * client must not lock the output buffer in such case but should send the next\n * frame for encoding. The client must keep on calling ::NvEncEncodePicture() API\n * until it returns ::NV_ENC_SUCCESS. \\n\n * The client must always lock the bitstream data in order in which it has submitted.\n * This is true for both asynchronous and synchronous mode.\n *\n *\\par Picture type decision:\n * If the client is taking the picture type decision and it must disable the picture\n * type decision module in NvEncodeAPI by setting NV_ENC_INITIALIZE_PARAMS::enablePTD\n * to 0. In this case the client is  required to send the picture in encoding\n * order to NvEncodeAPI by doing the re-ordering for B frames. \\n\n * If the client doesn't want to take the picture type decision it can enable\n * picture type decision module in the NvEncodeAPI interface by setting\n * NV_ENC_INITIALIZE_PARAMS::enablePTD to 1 and send the input pictures in display\n * order.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] createEncodeParams\n *   Refer ::_NV_ENC_INITIALIZE_PARAMS for details.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncInitializeEncoder                     (void *encoder, NV_ENC_INITIALIZE_PARAMS *createEncodeParams);\n\n\n// NvEncCreateInputBuffer\n/**\n * \\brief Allocates Input buffer.\n *\n * This function is used to allocate an input buffer. The client must enumerate\n * the input buffer format before allocating the input buffer resources. The\n * NV_ENC_INPUT_PTR returned by the NvEncodeAPI interface in the\n * NV_ENC_CREATE_INPUT_BUFFER::inputBuffer field can be directly used in\n * ::NvEncEncodePicture() API. The number of input buffers to be allocated by the\n * client must be at least 4 more than the number of B frames being used for encoding.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] createInputBufferParams\n *  Pointer to the ::NV_ENC_CREATE_INPUT_BUFFER structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncCreateInputBuffer                     (void *encoder, NV_ENC_CREATE_INPUT_BUFFER *createInputBufferParams);\n\n\n// NvEncDestroyInputBuffer\n/**\n * \\brief Release an input buffers.\n *\n * This function is used to free an input buffer. If the client has allocated\n * any input buffer using ::NvEncCreateInputBuffer() API, it must free those\n * input buffers by calling this function. The client must release the input\n * buffers before destroying the encoder using ::NvEncDestroyEncoder() API.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] inputBuffer\n *   Pointer to the input buffer to be released.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncDestroyInputBuffer                    (void *encoder, NV_ENC_INPUT_PTR inputBuffer);\n\n// NvEncSetIOCudaStreams\n/**\n * \\brief Set input and output CUDA stream for specified encoder attribute.\n *\n * Encoding may involve CUDA pre-processing on the input and post-processing on encoded output.\n * This function is used to set input and output CUDA streams to pipeline the CUDA pre-processing\n * and post-processing tasks. Clients should call this function before the call to\n * NvEncUnlockInputBuffer(). If this function is not called, the default CUDA stream is used for\n * input and output processing. After a successful call to this function, the streams specified\n * in that call will replace the previously-used streams.\n * This API is supported for NVCUVID interface only.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] inputStream\n *   Pointer to CUstream which is used to process ::NV_ENC_PIC_PARAMS::inputFrame for encode.\n *   In case of ME-only mode, inputStream is used to process ::NV_ENC_MEONLY_PARAMS::inputBuffer and\n *   ::NV_ENC_MEONLY_PARAMS::referenceFrame\n * \\param [in] outputStream\n *  Pointer to CUstream which is used to process ::NV_ENC_PIC_PARAMS::outputBuffer for encode.\n *  In case of ME-only mode, outputStream is used to process ::NV_ENC_MEONLY_PARAMS::mvBuffer\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncSetIOCudaStreams                     (void *encoder, NV_ENC_CUSTREAM_PTR inputStream, NV_ENC_CUSTREAM_PTR outputStream);\n\n\n// NvEncCreateBitstreamBuffer\n/**\n * \\brief Allocates an output bitstream buffer\n *\n * This function is used to allocate an output bitstream buffer and returns a\n * NV_ENC_OUTPUT_PTR to bitstream  buffer to the client in the\n * NV_ENC_CREATE_BITSTREAM_BUFFER::bitstreamBuffer field.\n * The client can only call this function after the encoder session has been\n * initialized using ::NvEncInitializeEncoder() API. The minimum number of output\n * buffers allocated by the client must be at least 4 more than the number of B\n * B frames being used for encoding. The client can only access the output\n * bitstream data by locking the \\p bitstreamBuffer using the ::NvEncLockBitstream()\n * function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] createBitstreamBufferParams\n *   Pointer ::NV_ENC_CREATE_BITSTREAM_BUFFER for details.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncCreateBitstreamBuffer                 (void *encoder, NV_ENC_CREATE_BITSTREAM_BUFFER *createBitstreamBufferParams);\n\n\n// NvEncDestroyBitstreamBuffer\n/**\n * \\brief Release a bitstream buffer.\n *\n * This function is used to release the output bitstream buffer allocated using\n * the ::NvEncCreateBitstreamBuffer() function. The client must release the output\n * bitstreamBuffer using this function before destroying the encoder session.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] bitstreamBuffer\n *   Pointer to the bitstream buffer being released.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncDestroyBitstreamBuffer                (void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);\n\n// NvEncEncodePicture\n/**\n * \\brief Submit an input picture for encoding.\n *\n * This function is used to submit an input picture buffer for encoding. The\n * encoding parameters are passed using \\p *encodePicParams which is a pointer\n * to the ::_NV_ENC_PIC_PARAMS structure.\n *\n * If the client has set NV_ENC_INITIALIZE_PARAMS::enablePTD to 0, then it must\n * send a valid value for the following fields.\n * - NV_ENC_PIC_PARAMS::pictureType\n * - NV_ENC_PIC_PARAMS_H264::displayPOCSyntax (H264 only)\n * - NV_ENC_PIC_PARAMS_H264::frameNumSyntax(H264 only)\n * - NV_ENC_PIC_PARAMS_H264::refPicFlag(H264 only)\n *\n *\\par MVC Encoding:\n * For MVC encoding the client must call encode picture API for each view separately\n * and must pass valid view id in NV_ENC_PIC_PARAMS_MVC::viewID field. Currently\n * NvEncodeAPI only support stereo MVC so client must send viewID as 0 for base\n * view and view ID as 1 for dependent view.\n *\n *\\par Asynchronous Encoding\n * If the client has enabled asynchronous mode of encoding by setting\n * NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync to 1 in the ::NvEncInitializeEncoder()\n * API ,then the client must send a valid NV_ENC_PIC_PARAMS::completionEvent.\n * Incase of asynchronous mode of operation, client can queue the ::NvEncEncodePicture()\n * API commands from the main thread and then queue output buffers to be processed\n * to a secondary worker thread. Before the locking the output buffers in the\n * secondary thread , the client must wait on NV_ENC_PIC_PARAMS::completionEvent\n * it has queued in ::NvEncEncodePicture() API call. The client must always process\n * completion event and the output buffer in the same order in which they have been\n * submitted for encoding. The NvEncodeAPI interface is responsible for any\n * re-ordering required for B frames and will always ensure that encoded bitstream\n * data is written in the same order in which output buffer is submitted.\n * The NvEncodeAPI interface may return ::NV_ENC_ERR_NEED_MORE_INPUT error code for\n * some ::NvEncEncodePicture() API calls but the client must not treat it as a fatal error.\n * The NvEncodeAPI interface might not be able to submit an input picture buffer for encoding\n * immediately due to re-ordering for B frames.\n *\\code\n  The below example shows how  asynchronous encoding in case of 1 B frames\n  ------------------------------------------------------------------------\n  Suppose the client allocated 4 input buffers(I1,I2..), 4 output buffers(O1,O2..)\n  and 4 completion events(E1, E2, ...). The NvEncodeAPI interface will need to\n  keep a copy of the input buffers for re-ordering and it allocates following\n  internal buffers (NvI1, NvI2...). These internal buffers are managed by NvEncodeAPI\n  and the client is not responsible for the allocating or freeing the memory of\n  the internal buffers.\n\n  a) The client main thread will queue the following encode frame calls.\n  Note the picture type is unknown to the client, the decision is being taken by\n  NvEncodeAPI interface. The client should pass ::_NV_ENC_PIC_PARAMS parameter\n  consisting of allocated input buffer, output buffer and output events in successive\n  ::NvEncEncodePicture() API calls along with other required encode picture params.\n  For example:\n  1st EncodePicture parameters - (I1, O1, E1)\n  2nd EncodePicture parameters - (I2, O2, E2)\n  3rd EncodePicture parameters - (I3, O3, E3)\n\n  b) NvEncodeAPI SW will receive the following encode Commands from the client.\n  The left side shows input from client in the form (Input buffer, Output Buffer,\n  Output Event). The right hand side shows a possible picture type decision take by\n  the NvEncodeAPI interface.\n  (I1, O1, E1)    ---P1 Frame\n  (I2, O2, E2)    ---B2 Frame\n  (I3, O3, E3)    ---P3 Frame\n\n  c) NvEncodeAPI interface will make a copy of the input buffers to its internal\n   buffers for re-ordering. These copies are done as part of nvEncEncodePicture\n   function call from the client and NvEncodeAPI interface is responsible for\n   synchronization of copy operation with the actual encoding operation.\n   I1 --> NvI1\n   I2 --> NvI2\n   I3 --> NvI3\n\n   d) The NvEncodeAPI encodes I1 as P frame and submits I1 to encoder HW and returns ::NV_ENC_SUCCESS.\n   The NvEncodeAPI tries to encode I2 as B frame and fails with ::NV_ENC_ERR_NEED_MORE_INPUT error code.\n   The error is not fatal and it notifies client that I2 is not submitted to encoder immediately.\n   The NvEncodeAPI encodes I3 as P frame and submits I3 for encoding which will be used as  backward\n   reference frame for I2. The NvEncodeAPI then submits I2 for encoding and returns ::NV_ENC_SUCESS.\n   Both the submission are part of the same ::NvEncEncodePicture() function call.\n\n  e) After returning from ::NvEncEncodePicture() call , the client must queue the output\n   bitstream  processing work to the secondary thread. The output bitstream processing\n   for asynchronous mode consist of first waiting on completion event(E1, E2..)\n   and then locking the output bitstream buffer(O1, O2..) for reading the encoded\n   data. The work queued to the secondary thread by the client is in the following order\n   (I1, O1, E1)\n   (I2, O2, E2)\n   (I3, O3, E3)\n   Note they are in the same order in which client calls ::NvEncEncodePicture() API\n   in \\p step a).\n\n  f) NvEncodeAPI interface  will do the re-ordering such that Encoder HW will receive\n  the following encode commands:\n  (NvI1, O1, E1)   ---P1 Frame\n  (NvI3, O2, E2)   ---P3 Frame\n  (NvI2, O3, E3)   ---B2 frame\n\n  g) After the encoding operations are completed, the events will be signaled\n  by NvEncodeAPI interface in the following order :\n  (O1, E1) ---P1 Frame ,output bitstream copied to O1 and event E1 signaled.\n  (O2, E2) ---P3 Frame ,output bitstream copied to O2 and event E2 signaled.\n  (O3, E3) ---B2 Frame ,output bitstream copied to O3 and event E3 signaled.\n\n  h) The client must lock the bitstream data using ::NvEncLockBitstream() API in\n   the order O1,O2,O3  to read the encoded data, after waiting for the events\n   to be signaled in the same order i.e E1, E2 and E3.The output processing is\n   done in the secondary thread in the following order:\n   Waits on E1, copies encoded bitstream from O1\n   Waits on E2, copies encoded bitstream from O2\n   Waits on E3, copies encoded bitstream from O3\n\n  -Note the client will receive the events signaling and output buffer in the\n   same order in which they have submitted for encoding.\n  -Note the LockBitstream will have picture type field which will notify the\n   output picture type to the clients.\n  -Note the input, output buffer and the output completion event are free to be\n   reused once NvEncodeAPI interfaced has signaled the event and the client has\n   copied the data from the output buffer.\n\n * \\endcode\n *\n *\\par Synchronous Encoding\n * The client can enable synchronous mode of encoding by setting\n * NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync to 0 in ::NvEncInitializeEncoder() API.\n * The NvEncodeAPI interface may return ::NV_ENC_ERR_NEED_MORE_INPUT error code for\n * some ::NvEncEncodePicture() API calls when NV_ENC_INITIALIZE_PARAMS::enablePTD\n * is set to 1, but the client must not treat it as a fatal error. The NvEncodeAPI\n * interface might not be able to submit an input picture buffer for encoding\n * immediately due to re-ordering for B frames. The NvEncodeAPI interface cannot\n * submit the input picture which is decided to be encoded as B frame as it waits\n * for backward reference from  temporally subsequent frames. This input picture\n * is buffered internally and waits for more input picture to arrive. The client\n * must not call ::NvEncLockBitstream() API on the output buffers whose\n * ::NvEncEncodePicture() API returns ::NV_ENC_ERR_NEED_MORE_INPUT. The client must\n * wait for the NvEncodeAPI interface to return ::NV_ENC_SUCCESS before locking the\n * output bitstreams to read the encoded bitstream data. The following example\n * explains the scenario with synchronous encoding with 2 B frames.\n *\\code\n The below example shows how  synchronous encoding works in case of 1 B frames\n -----------------------------------------------------------------------------\n Suppose the client allocated 4 input buffers(I1,I2..), 4 output buffers(O1,O2..)\n and 4 completion events(E1, E2, ...). The NvEncodeAPI interface will need to\n keep a copy of the input buffers for re-ordering and it allocates following\n internal buffers (NvI1, NvI2...). These internal buffers are managed by NvEncodeAPI\n and the client is not responsible for the allocating or freeing the memory of\n the internal buffers.\n\n The client calls ::NvEncEncodePicture() API with input buffer I1 and output buffer O1.\n The NvEncodeAPI decides to encode I1 as P frame and submits it to encoder\n HW and returns ::NV_ENC_SUCCESS.\n The client can now read the encoded data by locking the output O1 by calling\n NvEncLockBitstream API.\n\n The client calls ::NvEncEncodePicture() API with input buffer I2 and output buffer O2.\n The NvEncodeAPI decides to encode I2 as B frame and buffers I2 by copying it\n to internal buffer and returns ::NV_ENC_ERR_NEED_MORE_INPUT.\n The error is not fatal and it notifies client that it cannot read the encoded\n data by locking the output O2 by calling ::NvEncLockBitstream() API without submitting\n more work to the NvEncodeAPI interface.\n\n The client calls ::NvEncEncodePicture() with input buffer I3 and output buffer O3.\n The NvEncodeAPI decides to encode I3 as P frame and it first submits I3 for\n encoding which will be used as backward reference frame for I2.\n The NvEncodeAPI then submits I2 for encoding and returns ::NV_ENC_SUCESS. Both\n the submission are part of the same ::NvEncEncodePicture() function call.\n The client can now read the encoded data for both the frames by locking the output\n O2 followed by  O3 ,by calling ::NvEncLockBitstream() API.\n\n The client must always lock the output in the same order in which it has submitted\n to receive the encoded bitstream in correct encoding order.\n\n * \\endcode\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] encodePicParams\n *   Pointer to the ::_NV_ENC_PIC_PARAMS structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_ENCODER_BUSY \\n\n * ::NV_ENC_ERR_NEED_MORE_INPUT \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncEncodePicture                         (void *encoder, NV_ENC_PIC_PARAMS *encodePicParams);\n\n\n// NvEncLockBitstream\n/**\n * \\brief Lock output bitstream buffer\n *\n * This function is used to lock the bitstream buffer to read the encoded data.\n * The client can only access the encoded data by calling this function.\n * The pointer to client accessible encoded data is returned in the\n * NV_ENC_LOCK_BITSTREAM::bitstreamBufferPtr field. The size of the encoded data\n * in the output buffer is returned in the NV_ENC_LOCK_BITSTREAM::bitstreamSizeInBytes\n * The NvEncodeAPI interface also returns the output picture type and picture structure\n * of the encoded frame in NV_ENC_LOCK_BITSTREAM::pictureType and\n * NV_ENC_LOCK_BITSTREAM::pictureStruct fields respectively. If the client has\n * set NV_ENC_LOCK_BITSTREAM::doNotWait to 1, the function might return\n * ::NV_ENC_ERR_LOCK_BUSY if client is operating in synchronous mode. This is not\n * a fatal failure if NV_ENC_LOCK_BITSTREAM::doNotWait is set to 1. In the above case the client can\n * retry the function after few milliseconds.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] lockBitstreamBufferParams\n *   Pointer to the ::_NV_ENC_LOCK_BITSTREAM structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_LOCK_BUSY \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncLockBitstream                         (void *encoder, NV_ENC_LOCK_BITSTREAM *lockBitstreamBufferParams);\n\n\n// NvEncUnlockBitstream\n/**\n * \\brief Unlock the output bitstream buffer\n *\n * This function is used to unlock the output bitstream buffer after the client\n * has read the encoded data from output buffer. The client must call this function\n * to unlock the output buffer which it has previously locked using ::NvEncLockBitstream()\n * function. Using a locked bitstream buffer in ::NvEncEncodePicture() API will cause\n * the function to fail.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] bitstreamBuffer\n *   bitstream buffer pointer being unlocked\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnlockBitstream                       (void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);\n\n\n// NvLockInputBuffer\n/**\n * \\brief Locks an input buffer\n *\n * This function is used to lock the input buffer to load the uncompressed YUV\n * pixel data into input buffer memory. The client must pass the NV_ENC_INPUT_PTR\n * it had previously allocated using ::NvEncCreateInputBuffer()in the\n * NV_ENC_LOCK_INPUT_BUFFER::inputBuffer field.\n * The NvEncodeAPI interface returns pointer to client accessible input buffer\n * memory in NV_ENC_LOCK_INPUT_BUFFER::bufferDataPtr field.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] lockInputBufferParams\n *   Pointer to the ::_NV_ENC_LOCK_INPUT_BUFFER structure\n *\n * \\return\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_LOCK_BUSY \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncLockInputBuffer                      (void *encoder, NV_ENC_LOCK_INPUT_BUFFER *lockInputBufferParams);\n\n\n// NvUnlockInputBuffer\n/**\n * \\brief Unlocks the input buffer\n *\n * This function is used to unlock the input buffer memory previously locked for\n * uploading YUV pixel data. The input buffer must be unlocked before being used\n * again for encoding, otherwise NvEncodeAPI will fail the ::NvEncEncodePicture()\n *\n  * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] inputBuffer\n *   Pointer to the input buffer that is being unlocked.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnlockInputBuffer                     (void *encoder, NV_ENC_INPUT_PTR inputBuffer);\n\n\n// NvEncGetEncodeStats\n/**\n * \\brief Get encoding statistics.\n *\n * This function is used to retrieve the encoding statistics.\n * This API is not supported when encode device type is CUDA.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] encodeStats\n *   Pointer to the ::_NV_ENC_STAT structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeStats                        (void *encoder, NV_ENC_STAT *encodeStats);\n\n\n// NvEncGetSequenceParams\n/**\n * \\brief Get encoded sequence and picture header.\n *\n * This function can be used to retrieve the sequence and picture header out of\n * band. The client must call this function only after the encoder has been\n * initialized using ::NvEncInitializeEncoder() function. The client must\n * allocate the memory where the NvEncodeAPI interface can copy the bitstream\n * header and pass the pointer to the memory in NV_ENC_SEQUENCE_PARAM_PAYLOAD::spsppsBuffer.\n * The size of buffer is passed in the field  NV_ENC_SEQUENCE_PARAM_PAYLOAD::inBufferSize.\n * The NvEncodeAPI interface will copy the bitstream header payload and returns\n * the actual size of the bitstream header in the field\n * NV_ENC_SEQUENCE_PARAM_PAYLOAD::outSPSPPSPayloadSize.\n * The client must call  ::NvEncGetSequenceParams() function from the same thread which is\n * being used to call ::NvEncEncodePicture() function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] sequenceParamPayload\n *   Pointer to the ::_NV_ENC_SEQUENCE_PARAM_PAYLOAD structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetSequenceParams                     (void *encoder, NV_ENC_SEQUENCE_PARAM_PAYLOAD *sequenceParamPayload);\n\n// NvEncGetSequenceParamEx\n/**\n * \\brief Get sequence and picture header.\n *\n * This function can be used to retrieve the sequence and picture header out of band, even when\n * encoder has not been initialized using ::NvEncInitializeEncoder() function.\n * The client must allocate the memory where the NvEncodeAPI interface can copy the bitstream\n * header and pass the pointer to the memory in NV_ENC_SEQUENCE_PARAM_PAYLOAD::spsppsBuffer.\n * The size of buffer is passed in the field  NV_ENC_SEQUENCE_PARAM_PAYLOAD::inBufferSize.\n * If encoder has not been initialized using ::NvEncInitializeEncoder() function, client must\n * send NV_ENC_INITIALIZE_PARAMS as input. The NV_ENC_INITIALIZE_PARAMS passed must be same as the\n * one which will be used for initializing encoder using ::NvEncInitializeEncoder() function later.\n * If encoder is already initialized using ::NvEncInitializeEncoder() function, the provided\n * NV_ENC_INITIALIZE_PARAMS structure is ignored. The NvEncodeAPI interface will copy the bitstream\n * header payload and returns the actual size of the bitstream header in the field\n * NV_ENC_SEQUENCE_PARAM_PAYLOAD::outSPSPPSPayloadSize. The client must call  ::NvEncGetSequenceParamsEx()\n * function from the same thread which is being used to call ::NvEncEncodePicture() function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encInitParams\n *   Pointer to the _NV_ENC_INITIALIZE_PARAMS structure.\n * \\param [in,out] sequenceParamPayload\n *   Pointer to the ::_NV_ENC_SEQUENCE_PARAM_PAYLOAD structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetSequenceParamEx                     (void *encoder, NV_ENC_INITIALIZE_PARAMS *encInitParams, NV_ENC_SEQUENCE_PARAM_PAYLOAD *sequenceParamPayload);\n\n// NvEncRegisterAsyncEvent\n/**\n * \\brief Register event for notification to encoding completion.\n *\n * This function is used to register the completion event with NvEncodeAPI\n * interface. The event is required when the client has configured the encoder to\n * work in asynchronous mode. In this mode the client needs to send a completion\n * event with every output buffer. The NvEncodeAPI interface will signal the\n * completion of the encoding process using this event. Only after the event is\n * signaled the client can get the encoded data using ::NvEncLockBitstream() function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] eventParams\n *   Pointer to the ::_NV_ENC_EVENT_PARAMS structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncRegisterAsyncEvent                    (void *encoder, NV_ENC_EVENT_PARAMS *eventParams);\n\n\n// NvEncUnregisterAsyncEvent\n/**\n * \\brief Unregister completion event.\n *\n * This function is used to unregister completion event which has been previously\n * registered using ::NvEncRegisterAsyncEvent() function. The client must unregister\n * all events before destroying the encoder using ::NvEncDestroyEncoder() function.\n *\n  * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] eventParams\n *   Pointer to the ::_NV_ENC_EVENT_PARAMS structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnregisterAsyncEvent                  (void *encoder, NV_ENC_EVENT_PARAMS *eventParams);\n\n\n// NvEncMapInputResource\n/**\n * \\brief Map an externally created input resource pointer for encoding.\n *\n * Maps an externally allocated input resource [using and returns a NV_ENC_INPUT_PTR\n * which can be used for encoding in the ::NvEncEncodePicture() function. The\n * mapped resource is returned in the field NV_ENC_MAP_INPUT_RESOURCE::outputResourcePtr.\n * The NvEncodeAPI interface also returns the buffer format of the mapped resource\n * in the field NV_ENC_MAP_INPUT_RESOURCE::outbufferFmt.\n * This function provides synchronization guarantee that any graphics work submitted\n * on the input buffer is completed before the buffer is used for encoding. This is\n * also true for compute (i.e. CUDA) work, provided that the previous workload using\n * the input resource was submitted to the default stream.\n * The client should not access any input buffer while they are mapped by the encoder.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] mapInputResParams\n *   Pointer to the ::_NV_ENC_MAP_INPUT_RESOURCE structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_RESOURCE_NOT_REGISTERED \\n\n * ::NV_ENC_ERR_MAP_FAILED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncMapInputResource                         (void *encoder, NV_ENC_MAP_INPUT_RESOURCE *mapInputResParams);\n\n\n// NvEncUnmapInputResource\n/**\n * \\brief  UnMaps a NV_ENC_INPUT_PTR  which was mapped for encoding\n *\n *\n * UnMaps an input buffer which was previously mapped using ::NvEncMapInputResource()\n * API. The mapping created using ::NvEncMapInputResource() should be invalidated\n * using this API before the external resource is destroyed by the client. The client\n * must unmap the buffer after ::NvEncLockBitstream() API returns successfully for encode\n * work submitted using the mapped input buffer.\n *\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] mappedInputBuffer\n *   Pointer to the NV_ENC_INPUT_PTR\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_RESOURCE_NOT_REGISTERED \\n\n * ::NV_ENC_ERR_RESOURCE_NOT_MAPPED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnmapInputResource                         (void *encoder, NV_ENC_INPUT_PTR mappedInputBuffer);\n\n// NvEncDestroyEncoder\n/**\n * \\brief Destroy Encoding Session\n *\n * Destroys the encoder session previously created using ::NvEncOpenEncodeSession()\n * function. The client must flush the encoder before freeing any resources. In order\n * to flush the encoder the client must pass a NULL encode picture packet and either\n * wait for the ::NvEncEncodePicture() function to return in synchronous mode or wait\n * for the flush event to be signaled by the encoder in asynchronous mode.\n * The client must free all the input and output resources created using the\n * NvEncodeAPI interface before destroying the encoder. If the client is operating\n * in asynchronous mode, it must also unregister the completion events previously\n * registered.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncDestroyEncoder                        (void *encoder);\n\n// NvEncInvalidateRefFrames\n/**\n * \\brief Invalidate reference frames\n *\n * Invalidates reference frame based on the time stamp provided by the client.\n * The encoder marks any reference frames or any frames which have been reconstructed\n * using the corrupt frame as invalid for motion estimation and uses older reference\n * frames for motion estimation. The encoded forces the current frame to be encoded\n * as an intra frame if no reference frames are left after invalidation process.\n * This is useful for low latency application for error resiliency. The client\n * is recommended to set NV_ENC_CONFIG_H264::maxNumRefFrames to a large value so\n * that encoder can keep a backup of older reference frames in the DPB and can use them\n * for motion estimation when the newer reference frames have been invalidated.\n * This API can be called multiple times.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] invalidRefFrameTimeStamp\n *   Timestamp of the invalid reference frames which needs to be invalidated.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncInvalidateRefFrames(void *encoder, uint64_t invalidRefFrameTimeStamp);\n\n// NvEncOpenEncodeSessionEx\n/**\n * \\brief Opens an encoding session.\n *\n * Opens an encoding session and returns a pointer to the encoder interface in\n * the \\p **encoder parameter. The client should start encoding process by calling\n * this API first.\n * The client must pass a pointer to IDirect3DDevice9 device or CUDA context in the \\p *device parameter.\n * For the OpenGL interface, \\p device must be NULL. An OpenGL context must be current when\n * calling all NvEncodeAPI functions.\n * If the creation of encoder session fails, the client must call ::NvEncDestroyEncoder API\n * before exiting.\n *\n * \\param [in] openSessionExParams\n *    Pointer to a ::NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS structure.\n * \\param [out] encoder\n *    Encode Session pointer to the NvEncodeAPI interface.\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_NO_ENCODE_DEVICE \\n\n * ::NV_ENC_ERR_UNSUPPORTED_DEVICE \\n\n * ::NV_ENC_ERR_INVALID_DEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncOpenEncodeSessionEx                   (NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS *openSessionExParams, void **encoder);\n\n// NvEncRegisterResource\n/**\n * \\brief Registers a resource with the Nvidia Video Encoder Interface.\n *\n * Registers a resource with the Nvidia Video Encoder Interface for book keeping.\n * The client is expected to pass the registered resource handle as well, while calling ::NvEncMapInputResource API.\n *\n * \\param [in] encoder\n *   Pointer to the NVEncodeAPI interface.\n *\n * \\param [in] registerResParams\n *   Pointer to a ::_NV_ENC_REGISTER_RESOURCE structure\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_RESOURCE_REGISTER_FAILED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n * ::NV_ENC_ERR_UNIMPLEMENTED \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncRegisterResource                      (void *encoder, NV_ENC_REGISTER_RESOURCE *registerResParams);\n\n// NvEncUnregisterResource\n/**\n * \\brief Unregisters a resource previously registered with the Nvidia Video Encoder Interface.\n *\n * Unregisters a resource previously registered with the Nvidia Video Encoder Interface.\n * The client is expected to unregister any resource that it has registered with the\n * Nvidia Video Encoder Interface before destroying the resource.\n *\n * \\param [in] encoder\n *   Pointer to the NVEncodeAPI interface.\n *\n * \\param [in] registeredResource\n *   The registered resource pointer that was returned in ::NvEncRegisterResource.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_RESOURCE_NOT_REGISTERED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n * ::NV_ENC_ERR_UNIMPLEMENTED \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnregisterResource                    (void *encoder, NV_ENC_REGISTERED_PTR registeredResource);\n\n// NvEncReconfigureEncoder\n/**\n * \\brief Reconfigure an existing encoding session.\n *\n * Reconfigure an existing encoding session.\n * The client should call this API to change/reconfigure the parameter passed during\n * NvEncInitializeEncoder API call.\n * Currently Reconfiguration of following are not supported.\n * Change in GOP structure.\n * Change in sync-Async mode.\n * Change in MaxWidth & MaxHeight.\n * Change in PTD mode.\n *\n * Resolution change is possible only if maxEncodeWidth & maxEncodeHeight of NV_ENC_INITIALIZE_PARAMS\n * is set while creating encoder session.\n *\n * \\param [in] encoder\n *   Pointer to the NVEncodeAPI interface.\n *\n * \\param [in] reInitEncodeParams\n *    Pointer to a ::NV_ENC_RECONFIGURE_PARAMS structure.\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_NO_ENCODE_DEVICE \\n\n * ::NV_ENC_ERR_UNSUPPORTED_DEVICE \\n\n * ::NV_ENC_ERR_INVALID_DEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncReconfigureEncoder                   (void *encoder, NV_ENC_RECONFIGURE_PARAMS *reInitEncodeParams);\n\n\n\n// NvEncCreateMVBuffer\n/**\n * \\brief Allocates output MV buffer for ME only mode.\n *\n * This function is used to allocate an output MV buffer. The size of the mvBuffer is\n * dependent on the frame height and width of the last ::NvEncCreateInputBuffer() call.\n * The NV_ENC_OUTPUT_PTR returned by the NvEncodeAPI interface in the\n * ::NV_ENC_CREATE_MV_BUFFER::mvBuffer field should be used in\n * ::NvEncRunMotionEstimationOnly() API.\n * Client must lock ::NV_ENC_CREATE_MV_BUFFER::mvBuffer using ::NvEncLockBitstream() API to get the motion vector data.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] createMVBufferParams\n *  Pointer to the ::NV_ENC_CREATE_MV_BUFFER structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncCreateMVBuffer                        (void *encoder, NV_ENC_CREATE_MV_BUFFER *createMVBufferParams);\n\n\n// NvEncDestroyMVBuffer\n/**\n * \\brief Release an output MV buffer for ME only mode.\n *\n * This function is used to release the output MV buffer allocated using\n * the ::NvEncCreateMVBuffer() function. The client must release the output\n * mvBuffer using this function before destroying the encoder session.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] mvBuffer\n *   Pointer to the mvBuffer being released.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncDestroyMVBuffer                       (void *encoder, NV_ENC_OUTPUT_PTR mvBuffer);\n\n\n// NvEncRunMotionEstimationOnly\n/**\n * \\brief Submit an input picture and reference frame for motion estimation in ME only mode.\n *\n * This function is used to submit the input frame and reference frame for motion\n * estimation. The ME parameters are passed using *meOnlyParams which is a pointer\n * to ::_NV_ENC_MEONLY_PARAMS structure.\n * Client must lock ::NV_ENC_CREATE_MV_BUFFER::mvBuffer using ::NvEncLockBitstream() API to get the motion vector data.\n * to get motion vector data.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] meOnlyParams\n *   Pointer to the ::_NV_ENC_MEONLY_PARAMS structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_NEED_MORE_INPUT \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncRunMotionEstimationOnly               (void *encoder, NV_ENC_MEONLY_PARAMS *meOnlyParams);\n\n// NvEncodeAPIGetMaxSupportedVersion\n/**\n * \\brief Get the largest NvEncodeAPI version supported by the driver.\n *\n * This function can be used by clients to determine if the driver supports\n * the NvEncodeAPI header the application was compiled with.\n *\n * \\param [out] version\n *   Pointer to the requested value. The 4 least significant bits in the returned\n *   indicate the minor version and the rest of the bits indicate the major\n *   version of the largest supported version.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n */\nNVENCSTATUS NVENCAPI NvEncodeAPIGetMaxSupportedVersion          (uint32_t *version);\n\n\n// NvEncGetLastErrorString\n/**\n * \\brief Get the description of the last error reported by the API.\n *\n * This function returns a null-terminated string that can be used by clients to better understand the reason\n * for failure of a previous API call.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n *\n * \\return\n *   Pointer to buffer containing the details of the last error encountered by the API.\n */\nconst char *NVENCAPI NvEncGetLastErrorString          (void *encoder);\n\n\n/// \\cond API PFN\n/*\n *  Defines API function pointers\n */\ntypedef NVENCSTATUS (NVENCAPI *PNVENCOPENENCODESESSION)         (void *device, uint32_t deviceType, void **encoder);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEGUIDCOUNT)        (void *encoder, uint32_t *encodeGUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEGUIDS)            (void *encoder, GUID *GUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPROFILEGUIDCOUNT) (void *encoder, GUID encodeGUID, uint32_t *encodeProfileGUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPROFILEGUIDS)     (void *encoder, GUID encodeGUID, GUID *profileGUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETINPUTFORMATCOUNT)       (void *encoder, GUID encodeGUID, uint32_t *inputFmtCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETINPUTFORMATS)           (void *encoder, GUID encodeGUID, NV_ENC_BUFFER_FORMAT *inputFmts, uint32_t inputFmtArraySize, uint32_t *inputFmtCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODECAPS)             (void *encoder, GUID encodeGUID, NV_ENC_CAPS_PARAM *capsParam, int *capsVal);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPRESETCOUNT)      (void *encoder, GUID encodeGUID, uint32_t *encodePresetGUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPRESETGUIDS)      (void *encoder, GUID encodeGUID, GUID *presetGUIDs, uint32_t guidArraySize, uint32_t *encodePresetGUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPRESETCONFIG)     (void *encoder, GUID encodeGUID, GUID  presetGUID, NV_ENC_PRESET_CONFIG *presetConfig);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPRESETCONFIGEX)   (void *encoder, GUID encodeGUID, GUID  presetGUID, NV_ENC_TUNING_INFO tuningInfo, NV_ENC_PRESET_CONFIG *presetConfig);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCINITIALIZEENCODER)         (void *encoder, NV_ENC_INITIALIZE_PARAMS *createEncodeParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCCREATEINPUTBUFFER)         (void *encoder, NV_ENC_CREATE_INPUT_BUFFER *createInputBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCDESTROYINPUTBUFFER)        (void *encoder, NV_ENC_INPUT_PTR inputBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCCREATEBITSTREAMBUFFER)     (void *encoder, NV_ENC_CREATE_BITSTREAM_BUFFER *createBitstreamBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCDESTROYBITSTREAMBUFFER)    (void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCENCODEPICTURE)             (void *encoder, NV_ENC_PIC_PARAMS *encodePicParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCLOCKBITSTREAM)             (void *encoder, NV_ENC_LOCK_BITSTREAM *lockBitstreamBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNLOCKBITSTREAM)           (void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCLOCKINPUTBUFFER)           (void *encoder, NV_ENC_LOCK_INPUT_BUFFER *lockInputBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNLOCKINPUTBUFFER)         (void *encoder, NV_ENC_INPUT_PTR inputBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODESTATS)            (void *encoder, NV_ENC_STAT *encodeStats);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETSEQUENCEPARAMS)         (void *encoder, NV_ENC_SEQUENCE_PARAM_PAYLOAD *sequenceParamPayload);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCREGISTERASYNCEVENT)        (void *encoder, NV_ENC_EVENT_PARAMS *eventParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNREGISTERASYNCEVENT)      (void *encoder, NV_ENC_EVENT_PARAMS *eventParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCMAPINPUTRESOURCE)          (void *encoder, NV_ENC_MAP_INPUT_RESOURCE *mapInputResParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNMAPINPUTRESOURCE)        (void *encoder, NV_ENC_INPUT_PTR mappedInputBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCDESTROYENCODER)            (void *encoder);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCINVALIDATEREFFRAMES)       (void *encoder, uint64_t invalidRefFrameTimeStamp);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCOPENENCODESESSIONEX)       (NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS *openSessionExParams, void **encoder);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCREGISTERRESOURCE)          (void *encoder, NV_ENC_REGISTER_RESOURCE *registerResParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNREGISTERRESOURCE)        (void *encoder, NV_ENC_REGISTERED_PTR registeredRes);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCRECONFIGUREENCODER)        (void *encoder, NV_ENC_RECONFIGURE_PARAMS *reInitEncodeParams);\n\ntypedef NVENCSTATUS (NVENCAPI *PNVENCCREATEMVBUFFER)            (void *encoder, NV_ENC_CREATE_MV_BUFFER *createMVBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCDESTROYMVBUFFER)           (void *encoder, NV_ENC_OUTPUT_PTR mvBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCRUNMOTIONESTIMATIONONLY)   (void *encoder, NV_ENC_MEONLY_PARAMS *meOnlyParams);\ntypedef const char *(NVENCAPI *PNVENCGETLASTERROR)             (void *encoder);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCSETIOCUDASTREAMS)          (void *encoder, NV_ENC_CUSTREAM_PTR inputStream, NV_ENC_CUSTREAM_PTR outputStream);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETSEQUENCEPARAMEX)        (void *encoder, NV_ENC_INITIALIZE_PARAMS *encInitParams, NV_ENC_SEQUENCE_PARAM_PAYLOAD *sequenceParamPayload);\n\n\n/// \\endcond\n\n\n/** @} */ /* END ENCODE_FUNC */\n\n/**\n * \\ingroup ENCODER_STRUCTURE\n * NV_ENCODE_API_FUNCTION_LIST\n */\ntypedef struct _NV_ENCODE_API_FUNCTION_LIST\n{\n    uint32_t                        version;                           /**< [in]: Client should pass NV_ENCODE_API_FUNCTION_LIST_VER.                               */\n    uint32_t                        reserved;                          /**< [in]: Reserved and should be set to 0.                                                  */\n    PNVENCOPENENCODESESSION         nvEncOpenEncodeSession;            /**< [out]: Client should access ::NvEncOpenEncodeSession() API through this pointer.        */\n    PNVENCGETENCODEGUIDCOUNT        nvEncGetEncodeGUIDCount;           /**< [out]: Client should access ::NvEncGetEncodeGUIDCount() API through this pointer.       */\n    PNVENCGETENCODEPRESETCOUNT      nvEncGetEncodeProfileGUIDCount;    /**< [out]: Client should access ::NvEncGetEncodeProfileGUIDCount() API through this pointer.*/\n    PNVENCGETENCODEPRESETGUIDS      nvEncGetEncodeProfileGUIDs;        /**< [out]: Client should access ::NvEncGetEncodeProfileGUIDs() API through this pointer.    */\n    PNVENCGETENCODEGUIDS            nvEncGetEncodeGUIDs;               /**< [out]: Client should access ::NvEncGetEncodeGUIDs() API through this pointer.           */\n    PNVENCGETINPUTFORMATCOUNT       nvEncGetInputFormatCount;          /**< [out]: Client should access ::NvEncGetInputFormatCount() API through this pointer.      */\n    PNVENCGETINPUTFORMATS           nvEncGetInputFormats;              /**< [out]: Client should access ::NvEncGetInputFormats() API through this pointer.          */\n    PNVENCGETENCODECAPS             nvEncGetEncodeCaps;                /**< [out]: Client should access ::NvEncGetEncodeCaps() API through this pointer.            */\n    PNVENCGETENCODEPRESETCOUNT      nvEncGetEncodePresetCount;         /**< [out]: Client should access ::NvEncGetEncodePresetCount() API through this pointer.     */\n    PNVENCGETENCODEPRESETGUIDS      nvEncGetEncodePresetGUIDs;         /**< [out]: Client should access ::NvEncGetEncodePresetGUIDs() API through this pointer.     */\n    PNVENCGETENCODEPRESETCONFIG     nvEncGetEncodePresetConfig;        /**< [out]: Client should access ::NvEncGetEncodePresetConfig() API through this pointer.    */\n    PNVENCINITIALIZEENCODER         nvEncInitializeEncoder;            /**< [out]: Client should access ::NvEncInitializeEncoder() API through this pointer.        */\n    PNVENCCREATEINPUTBUFFER         nvEncCreateInputBuffer;            /**< [out]: Client should access ::NvEncCreateInputBuffer() API through this pointer.        */\n    PNVENCDESTROYINPUTBUFFER        nvEncDestroyInputBuffer;           /**< [out]: Client should access ::NvEncDestroyInputBuffer() API through this pointer.       */\n    PNVENCCREATEBITSTREAMBUFFER     nvEncCreateBitstreamBuffer;        /**< [out]: Client should access ::NvEncCreateBitstreamBuffer() API through this pointer.    */\n    PNVENCDESTROYBITSTREAMBUFFER    nvEncDestroyBitstreamBuffer;       /**< [out]: Client should access ::NvEncDestroyBitstreamBuffer() API through this pointer.   */\n    PNVENCENCODEPICTURE             nvEncEncodePicture;                /**< [out]: Client should access ::NvEncEncodePicture() API through this pointer.            */\n    PNVENCLOCKBITSTREAM             nvEncLockBitstream;                /**< [out]: Client should access ::NvEncLockBitstream() API through this pointer.            */\n    PNVENCUNLOCKBITSTREAM           nvEncUnlockBitstream;              /**< [out]: Client should access ::NvEncUnlockBitstream() API through this pointer.          */\n    PNVENCLOCKINPUTBUFFER           nvEncLockInputBuffer;              /**< [out]: Client should access ::NvEncLockInputBuffer() API through this pointer.          */\n    PNVENCUNLOCKINPUTBUFFER         nvEncUnlockInputBuffer;            /**< [out]: Client should access ::NvEncUnlockInputBuffer() API through this pointer.        */\n    PNVENCGETENCODESTATS            nvEncGetEncodeStats;               /**< [out]: Client should access ::NvEncGetEncodeStats() API through this pointer.           */\n    PNVENCGETSEQUENCEPARAMS         nvEncGetSequenceParams;            /**< [out]: Client should access ::NvEncGetSequenceParams() API through this pointer.        */\n    PNVENCREGISTERASYNCEVENT        nvEncRegisterAsyncEvent;           /**< [out]: Client should access ::NvEncRegisterAsyncEvent() API through this pointer.       */\n    PNVENCUNREGISTERASYNCEVENT      nvEncUnregisterAsyncEvent;         /**< [out]: Client should access ::NvEncUnregisterAsyncEvent() API through this pointer.     */\n    PNVENCMAPINPUTRESOURCE          nvEncMapInputResource;             /**< [out]: Client should access ::NvEncMapInputResource() API through this pointer.         */\n    PNVENCUNMAPINPUTRESOURCE        nvEncUnmapInputResource;           /**< [out]: Client should access ::NvEncUnmapInputResource() API through this pointer.       */\n    PNVENCDESTROYENCODER            nvEncDestroyEncoder;               /**< [out]: Client should access ::NvEncDestroyEncoder() API through this pointer.           */\n    PNVENCINVALIDATEREFFRAMES       nvEncInvalidateRefFrames;          /**< [out]: Client should access ::NvEncInvalidateRefFrames() API through this pointer.      */\n    PNVENCOPENENCODESESSIONEX       nvEncOpenEncodeSessionEx;          /**< [out]: Client should access ::NvEncOpenEncodeSession() API through this pointer.        */\n    PNVENCREGISTERRESOURCE          nvEncRegisterResource;             /**< [out]: Client should access ::NvEncRegisterResource() API through this pointer.         */\n    PNVENCUNREGISTERRESOURCE        nvEncUnregisterResource;           /**< [out]: Client should access ::NvEncUnregisterResource() API through this pointer.       */\n    PNVENCRECONFIGUREENCODER        nvEncReconfigureEncoder;           /**< [out]: Client should access ::NvEncReconfigureEncoder() API through this pointer.       */\n    void                           *reserved1;\n    PNVENCCREATEMVBUFFER            nvEncCreateMVBuffer;               /**< [out]: Client should access ::NvEncCreateMVBuffer API through this pointer.             */\n    PNVENCDESTROYMVBUFFER           nvEncDestroyMVBuffer;              /**< [out]: Client should access ::NvEncDestroyMVBuffer API through this pointer.            */\n    PNVENCRUNMOTIONESTIMATIONONLY   nvEncRunMotionEstimationOnly;      /**< [out]: Client should access ::NvEncRunMotionEstimationOnly API through this pointer.    */\n    PNVENCGETLASTERROR              nvEncGetLastErrorString;           /**< [out]: Client should access ::nvEncGetLastErrorString API through this pointer.         */\n    PNVENCSETIOCUDASTREAMS          nvEncSetIOCudaStreams;             /**< [out]: Client should access ::nvEncSetIOCudaStreams API through this pointer.           */\n    PNVENCGETENCODEPRESETCONFIGEX   nvEncGetEncodePresetConfigEx;      /**< [out]: Client should access ::NvEncGetEncodePresetConfigEx() API through this pointer.  */\n    PNVENCGETSEQUENCEPARAMEX        nvEncGetSequenceParamEx;           /**< [out]: Client should access ::NvEncGetSequenceParamEx() API through this pointer.       */\n    void                           *reserved2[277];                    /**< [in]:  Reserved and must be set to NULL                                                 */\n} NV_ENCODE_API_FUNCTION_LIST;\n\n/** Macro for constructing the version field of ::_NV_ENCODEAPI_FUNCTION_LIST. */\n#define NV_ENCODE_API_FUNCTION_LIST_VER NVENCAPI_STRUCT_VERSION(2)\n\n// NvEncodeAPICreateInstance\n/**\n * \\ingroup ENCODE_FUNC\n * Entry Point to the NvEncodeAPI interface.\n *\n * Creates an instance of the NvEncodeAPI interface, and populates the\n * pFunctionList with function pointers to the API routines implemented by the\n * NvEncodeAPI interface.\n *\n * \\param [out] functionList\n *\n * \\return\n * ::NV_ENC_SUCCESS\n * ::NV_ENC_ERR_INVALID_PTR\n */\nNVENCSTATUS NVENCAPI NvEncodeAPICreateInstance(NV_ENCODE_API_FUNCTION_LIST *functionList);\n\n#ifdef __cplusplus\n}\n#endif\n\n\n#endif\n"
  },
  {
    "path": "xrdp_accel_assist/encoder_headers/nvEncodeAPI_11_1.h",
    "content": "/*\n * This copyright notice applies to this header file only:\n *\n * Copyright (c) 2010-2021 NVIDIA Corporation\n *\n * Permission is hereby granted, free of charge, to any person\n * obtaining a copy of this software and associated documentation\n * files (the \"Software\"), to deal in the Software without\n * restriction, including without limitation the rights to use,\n * copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the software, and to permit persons to whom the\n * software is furnished to do so, subject to the following\n * conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n * OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/**\n * \\file nvEncodeAPI.h\n *   NVIDIA GPUs - beginning with the Kepler generation - contain a hardware-based encoder\n *   (referred to as NVENC) which provides fully-accelerated hardware-based video encoding.\n *   NvEncodeAPI provides the interface for NVIDIA video encoder (NVENC).\n * \\date 2011-2020\n *  This file contains the interface constants, structure definitions and function prototypes.\n */\n\n#ifndef _NV_ENCODEAPI_H_\n#define _NV_ENCODEAPI_H_\n\n#include <stdlib.h>\n\n#ifdef _WIN32\n#include <windows.h>\n#endif\n\n#ifdef _MSC_VER\n#ifndef _STDINT\ntypedef __int32 int32_t;\ntypedef unsigned __int32 uint32_t;\ntypedef __int64 int64_t;\ntypedef unsigned __int64 uint64_t;\ntypedef signed char int8_t;\ntypedef unsigned char uint8_t;\ntypedef short int16_t;\ntypedef unsigned short uint16_t;\n#endif\n#else\n#include <stdint.h>\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/**\n * \\addtogroup ENCODER_STRUCTURE NvEncodeAPI Data structures\n * @{\n */\n\n#ifdef _WIN32\n#define NVENCAPI     __stdcall\ntypedef RECT NVENC_RECT;\n#else\n#define NVENCAPI\n// =========================================================================================\n#if !defined(GUID) && !defined(GUID_DEFINED)\n/*!\n * \\struct GUID\n * Abstracts the GUID structure for non-windows platforms.\n */\n// =========================================================================================\ntypedef struct\n{\n    uint32_t Data1;                                      /**< [in]: Specifies the first 8 hexadecimal digits of the GUID.                                */\n    uint16_t Data2;                                      /**< [in]: Specifies the first group of 4 hexadecimal digits.                                   */\n    uint16_t Data3;                                      /**< [in]: Specifies the second group of 4 hexadecimal digits.                                  */\n    uint8_t  Data4[8];                                   /**< [in]: Array of 8 bytes. The first 2 bytes contain the third group of 4 hexadecimal digits.\n                                                                    The remaining 6 bytes contain the final 12 hexadecimal digits.                       */\n} GUID;\n#endif // GUID\n\n/**\n * \\struct _NVENC_RECT\n * Defines a Rectangle. Used in ::NV_ENC_PREPROCESS_FRAME.\n */\ntypedef struct _NVENC_RECT\n{\n    uint32_t left;                                        /**< [in]: X coordinate of the upper left corner of rectangular area to be specified.       */\n    uint32_t top;                                         /**< [in]: Y coordinate of the upper left corner of the rectangular area to be specified.   */\n    uint32_t right;                                       /**< [in]: X coordinate of the bottom right corner of the rectangular area to be specified. */\n    uint32_t bottom;                                      /**< [in]: Y coordinate of the bottom right corner of the rectangular area to be specified. */\n} NVENC_RECT;\n\n#endif // _WIN32\n\n/** @} */ /* End of GUID and NVENC_RECT structure grouping*/\n\ntypedef void *NV_ENC_INPUT_PTR;             /**< NVENCODE API input buffer                              */\ntypedef void *NV_ENC_OUTPUT_PTR;            /**< NVENCODE API output buffer*/\ntypedef void *NV_ENC_REGISTERED_PTR;        /**< A Resource that has been registered with NVENCODE API*/\ntypedef void *NV_ENC_CUSTREAM_PTR;          /**< Pointer to CUstream*/\n\n#define NVENCAPI_MAJOR_VERSION 11\n#define NVENCAPI_MINOR_VERSION 1\n\n#define NVENCAPI_VERSION (NVENCAPI_MAJOR_VERSION | (NVENCAPI_MINOR_VERSION << 24))\n\n/**\n * Macro to generate per-structure version for use with API.\n */\n#define NVENCAPI_STRUCT_VERSION(ver) ((uint32_t)NVENCAPI_VERSION | ((ver)<<16) | (0x7 << 28))\n\n\n#define NVENC_INFINITE_GOPLENGTH  0xffffffff\n\n#define NV_MAX_SEQ_HDR_LEN  (512)\n\n#ifdef __GNUC__\n#define NV_ENC_DEPRECATED __attribute__ ((deprecated(\"WILL BE REMOVED IN A FUTURE VIDEO CODEC SDK VERSION\")))\n#elif defined(_MSC_VER)\n#define NV_ENC_DEPRECATED __declspec(deprecated(\"WILL BE REMOVED IN A FUTURE VIDEO CODEC SDK VERSION\"))\n#endif\n\n// =========================================================================================\n// Encode Codec GUIDS supported by the NvEncodeAPI interface.\n// =========================================================================================\n\n// {6BC82762-4E63-4ca4-AA85-1E50F321F6BF}\nstatic const GUID NV_ENC_CODEC_H264_GUID =\n{ 0x6bc82762, 0x4e63, 0x4ca4, { 0xaa, 0x85, 0x1e, 0x50, 0xf3, 0x21, 0xf6, 0xbf } };\n\n// {790CDC88-4522-4d7b-9425-BDA9975F7603}\nstatic const GUID NV_ENC_CODEC_HEVC_GUID =\n{ 0x790cdc88, 0x4522, 0x4d7b, { 0x94, 0x25, 0xbd, 0xa9, 0x97, 0x5f, 0x76, 0x3 } };\n\n\n\n// =========================================================================================\n// *   Encode Profile GUIDS supported by the NvEncodeAPI interface.\n// =========================================================================================\n\n// {BFD6F8E7-233C-4341-8B3E-4818523803F4}\nstatic const GUID NV_ENC_CODEC_PROFILE_AUTOSELECT_GUID =\n{ 0xbfd6f8e7, 0x233c, 0x4341, { 0x8b, 0x3e, 0x48, 0x18, 0x52, 0x38, 0x3, 0xf4 } };\n\n// {0727BCAA-78C4-4c83-8C2F-EF3DFF267C6A}\nstatic const GUID  NV_ENC_H264_PROFILE_BASELINE_GUID =\n{ 0x727bcaa, 0x78c4, 0x4c83, { 0x8c, 0x2f, 0xef, 0x3d, 0xff, 0x26, 0x7c, 0x6a } };\n\n// {60B5C1D4-67FE-4790-94D5-C4726D7B6E6D}\nstatic const GUID  NV_ENC_H264_PROFILE_MAIN_GUID =\n{ 0x60b5c1d4, 0x67fe, 0x4790, { 0x94, 0xd5, 0xc4, 0x72, 0x6d, 0x7b, 0x6e, 0x6d } };\n\n// {E7CBC309-4F7A-4b89-AF2A-D537C92BE310}\nstatic const GUID NV_ENC_H264_PROFILE_HIGH_GUID =\n{ 0xe7cbc309, 0x4f7a, 0x4b89, { 0xaf, 0x2a, 0xd5, 0x37, 0xc9, 0x2b, 0xe3, 0x10 } };\n\n// {7AC663CB-A598-4960-B844-339B261A7D52}\nstatic const GUID  NV_ENC_H264_PROFILE_HIGH_444_GUID =\n{ 0x7ac663cb, 0xa598, 0x4960, { 0xb8, 0x44, 0x33, 0x9b, 0x26, 0x1a, 0x7d, 0x52 } };\n\n// {40847BF5-33F7-4601-9084-E8FE3C1DB8B7}\nstatic const GUID NV_ENC_H264_PROFILE_STEREO_GUID =\n{ 0x40847bf5, 0x33f7, 0x4601, { 0x90, 0x84, 0xe8, 0xfe, 0x3c, 0x1d, 0xb8, 0xb7 } };\n\n// {B405AFAC-F32B-417B-89C4-9ABEED3E5978}\nstatic const GUID NV_ENC_H264_PROFILE_PROGRESSIVE_HIGH_GUID =\n{ 0xb405afac, 0xf32b, 0x417b, { 0x89, 0xc4, 0x9a, 0xbe, 0xed, 0x3e, 0x59, 0x78 } };\n\n// {AEC1BD87-E85B-48f2-84C3-98BCA6285072}\nstatic const GUID NV_ENC_H264_PROFILE_CONSTRAINED_HIGH_GUID =\n{ 0xaec1bd87, 0xe85b, 0x48f2, { 0x84, 0xc3, 0x98, 0xbc, 0xa6, 0x28, 0x50, 0x72 } };\n\n// {B514C39A-B55B-40fa-878F-F1253B4DFDEC}\nstatic const GUID NV_ENC_HEVC_PROFILE_MAIN_GUID =\n{ 0xb514c39a, 0xb55b, 0x40fa, { 0x87, 0x8f, 0xf1, 0x25, 0x3b, 0x4d, 0xfd, 0xec } };\n\n// {fa4d2b6c-3a5b-411a-8018-0a3f5e3c9be5}\nstatic const GUID NV_ENC_HEVC_PROFILE_MAIN10_GUID =\n{ 0xfa4d2b6c, 0x3a5b, 0x411a, { 0x80, 0x18, 0x0a, 0x3f, 0x5e, 0x3c, 0x9b, 0xe5 } };\n\n// For HEVC Main 444 8 bit and HEVC Main 444 10 bit profiles only\n// {51ec32b5-1b4c-453c-9cbd-b616bd621341}\nstatic const GUID NV_ENC_HEVC_PROFILE_FREXT_GUID =\n{ 0x51ec32b5, 0x1b4c, 0x453c, { 0x9c, 0xbd, 0xb6, 0x16, 0xbd, 0x62, 0x13, 0x41 } };\n\n// =========================================================================================\n// *   Preset GUIDS supported by the NvEncodeAPI interface.\n// =========================================================================================\n// {B2DFB705-4EBD-4C49-9B5F-24A777D3E587}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_DEFAULT_GUID =\n{ 0xb2dfb705, 0x4ebd, 0x4c49, { 0x9b, 0x5f, 0x24, 0xa7, 0x77, 0xd3, 0xe5, 0x87 } };\n\n// {60E4C59F-E846-4484-A56D-CD45BE9FDDF6}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_HP_GUID =\n{ 0x60e4c59f, 0xe846, 0x4484, { 0xa5, 0x6d, 0xcd, 0x45, 0xbe, 0x9f, 0xdd, 0xf6 } };\n\n// {34DBA71D-A77B-4B8F-9C3E-B6D5DA24C012}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_HQ_GUID =\n{ 0x34dba71d, 0xa77b, 0x4b8f, { 0x9c, 0x3e, 0xb6, 0xd5, 0xda, 0x24, 0xc0, 0x12 } };\n\n// {82E3E450-BDBB-4e40-989C-82A90DF9EF32}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_BD_GUID  =\n{ 0x82e3e450, 0xbdbb, 0x4e40, { 0x98, 0x9c, 0x82, 0xa9, 0xd, 0xf9, 0xef, 0x32 } };\n\n// {49DF21C5-6DFA-4feb-9787-6ACC9EFFB726}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOW_LATENCY_DEFAULT_GUID  =\n{ 0x49df21c5, 0x6dfa, 0x4feb, { 0x97, 0x87, 0x6a, 0xcc, 0x9e, 0xff, 0xb7, 0x26 } };\n\n// {C5F733B9-EA97-4cf9-BEC2-BF78A74FD105}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOW_LATENCY_HQ_GUID  =\n{ 0xc5f733b9, 0xea97, 0x4cf9, { 0xbe, 0xc2, 0xbf, 0x78, 0xa7, 0x4f, 0xd1, 0x5 } };\n\n// {67082A44-4BAD-48FA-98EA-93056D150A58}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOW_LATENCY_HP_GUID =\n{ 0x67082a44, 0x4bad, 0x48fa, { 0x98, 0xea, 0x93, 0x5, 0x6d, 0x15, 0xa, 0x58 } };\n\n// {D5BFB716-C604-44e7-9BB8-DEA5510FC3AC}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOSSLESS_DEFAULT_GUID =\n{ 0xd5bfb716, 0xc604, 0x44e7, { 0x9b, 0xb8, 0xde, 0xa5, 0x51, 0xf, 0xc3, 0xac } };\n\n// {149998E7-2364-411d-82EF-179888093409}\nNV_ENC_DEPRECATED static const GUID NV_ENC_PRESET_LOSSLESS_HP_GUID =\n{ 0x149998e7, 0x2364, 0x411d, { 0x82, 0xef, 0x17, 0x98, 0x88, 0x9, 0x34, 0x9 } };\n\n// Performance degrades and quality improves as we move from P1 to P7. Presets P3 to P7 for H264 and Presets P2 to P7 for HEVC have B frames enabled by default\n// for HIGH_QUALITY and LOSSLESS tuning info, and will not work with Weighted Prediction enabled. In case Weighted Prediction is required, disable B frames by\n// setting frameIntervalP = 1\n// {FC0A8D3E-45F8-4CF8-80C7-298871590EBF}\nstatic const GUID NV_ENC_PRESET_P1_GUID   =\n{ 0xfc0a8d3e, 0x45f8, 0x4cf8, { 0x80, 0xc7, 0x29, 0x88, 0x71, 0x59, 0xe, 0xbf } };\n\n// {F581CFB8-88D6-4381-93F0-DF13F9C27DAB}\nstatic const GUID NV_ENC_PRESET_P2_GUID   =\n{ 0xf581cfb8, 0x88d6, 0x4381, { 0x93, 0xf0, 0xdf, 0x13, 0xf9, 0xc2, 0x7d, 0xab } };\n\n// {36850110-3A07-441F-94D5-3670631F91F6}\nstatic const GUID NV_ENC_PRESET_P3_GUID   =\n{ 0x36850110, 0x3a07, 0x441f, { 0x94, 0xd5, 0x36, 0x70, 0x63, 0x1f, 0x91, 0xf6 } };\n\n// {90A7B826-DF06-4862-B9D2-CD6D73A08681}\nstatic const GUID NV_ENC_PRESET_P4_GUID   =\n{ 0x90a7b826, 0xdf06, 0x4862, { 0xb9, 0xd2, 0xcd, 0x6d, 0x73, 0xa0, 0x86, 0x81 } };\n\n// {21C6E6B4-297A-4CBA-998F-B6CBDE72ADE3}\nstatic const GUID NV_ENC_PRESET_P5_GUID   =\n{ 0x21c6e6b4, 0x297a, 0x4cba, { 0x99, 0x8f, 0xb6, 0xcb, 0xde, 0x72, 0xad, 0xe3 } };\n\n// {8E75C279-6299-4AB6-8302-0B215A335CF5}\nstatic const GUID NV_ENC_PRESET_P6_GUID   =\n{ 0x8e75c279, 0x6299, 0x4ab6, { 0x83, 0x2, 0xb, 0x21, 0x5a, 0x33, 0x5c, 0xf5 } };\n\n// {84848C12-6F71-4C13-931B-53E283F57974}\nstatic const GUID NV_ENC_PRESET_P7_GUID   =\n{ 0x84848c12, 0x6f71, 0x4c13, { 0x93, 0x1b, 0x53, 0xe2, 0x83, 0xf5, 0x79, 0x74 } };\n\n/**\n * \\addtogroup ENCODER_STRUCTURE NvEncodeAPI Data structures\n * @{\n */\n\n/**\n * Input frame encode modes\n */\ntypedef enum _NV_ENC_PARAMS_FRAME_FIELD_MODE\n{\n    NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME = 0x01,  /**< Frame mode */\n    NV_ENC_PARAMS_FRAME_FIELD_MODE_FIELD = 0x02,  /**< Field mode */\n    NV_ENC_PARAMS_FRAME_FIELD_MODE_MBAFF = 0x03   /**< MB adaptive frame/field */\n} NV_ENC_PARAMS_FRAME_FIELD_MODE;\n\n/**\n * Rate Control Modes\n */\ntypedef enum _NV_ENC_PARAMS_RC_MODE\n{\n    NV_ENC_PARAMS_RC_CONSTQP                = 0x0,       /**< Constant QP mode */\n    NV_ENC_PARAMS_RC_VBR                    = 0x1,       /**< Variable bitrate mode */\n    NV_ENC_PARAMS_RC_CBR                    = 0x2,       /**< Constant bitrate mode */\n    NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ        = 0x8,       /**< Deprecated, use NV_ENC_PARAMS_RC_CBR + NV_ENC_TWO_PASS_QUARTER_RESOLUTION / NV_ENC_TWO_PASS_FULL_RESOLUTION +\n                                                              lowDelayKeyFrameScale=1 */\n    NV_ENC_PARAMS_RC_CBR_HQ                 = 0x10,      /**< Deprecated, use NV_ENC_PARAMS_RC_CBR + NV_ENC_TWO_PASS_QUARTER_RESOLUTION / NV_ENC_TWO_PASS_FULL_RESOLUTION */\n    NV_ENC_PARAMS_RC_VBR_HQ                 = 0x20       /**< Deprecated, use NV_ENC_PARAMS_RC_VBR + NV_ENC_TWO_PASS_QUARTER_RESOLUTION / NV_ENC_TWO_PASS_FULL_RESOLUTION */\n} NV_ENC_PARAMS_RC_MODE;\n\n/**\n * Multi Pass encoding\n */\ntypedef enum _NV_ENC_MULTI_PASS\n{\n    NV_ENC_MULTI_PASS_DISABLED              = 0x0,        /**< Single Pass */\n    NV_ENC_TWO_PASS_QUARTER_RESOLUTION      = 0x1,        /**< Two Pass encoding is enabled where first Pass is quarter resolution */\n    NV_ENC_TWO_PASS_FULL_RESOLUTION         = 0x2,        /**< Two Pass encoding is enabled where first Pass is full resolution */\n} NV_ENC_MULTI_PASS;\n\n/**\n * Emphasis Levels\n */\ntypedef enum _NV_ENC_EMPHASIS_MAP_LEVEL\n{\n    NV_ENC_EMPHASIS_MAP_LEVEL_0               = 0x0,       /**< Emphasis Map Level 0, for zero Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_1               = 0x1,       /**< Emphasis Map Level 1, for very low Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_2               = 0x2,       /**< Emphasis Map Level 2, for low Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_3               = 0x3,       /**< Emphasis Map Level 3, for medium Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_4               = 0x4,       /**< Emphasis Map Level 4, for high Delta QP value */\n    NV_ENC_EMPHASIS_MAP_LEVEL_5               = 0x5        /**< Emphasis Map Level 5, for very high Delta QP value */\n} NV_ENC_EMPHASIS_MAP_LEVEL;\n\n/**\n * QP MAP MODE\n */\ntypedef enum _NV_ENC_QP_MAP_MODE\n{\n    NV_ENC_QP_MAP_DISABLED               = 0x0,             /**< Value in NV_ENC_PIC_PARAMS::qpDeltaMap have no effect. */\n    NV_ENC_QP_MAP_EMPHASIS               = 0x1,             /**< Value in NV_ENC_PIC_PARAMS::qpDeltaMap will be treated as Emphasis level. Currently this is only supported for H264 */\n    NV_ENC_QP_MAP_DELTA                  = 0x2,             /**< Value in NV_ENC_PIC_PARAMS::qpDeltaMap will be treated as QP delta map. */\n    NV_ENC_QP_MAP                        = 0x3,             /**< Currently This is not supported. Value in NV_ENC_PIC_PARAMS::qpDeltaMap will be treated as QP value.   */\n} NV_ENC_QP_MAP_MODE;\n\n#define NV_ENC_PARAMS_RC_VBR_MINQP              (NV_ENC_PARAMS_RC_MODE)0x4          /**< Deprecated */\n#define NV_ENC_PARAMS_RC_2_PASS_QUALITY         NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ    /**< Deprecated */\n#define NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP   NV_ENC_PARAMS_RC_CBR_HQ             /**< Deprecated */\n#define NV_ENC_PARAMS_RC_2_PASS_VBR             NV_ENC_PARAMS_RC_VBR_HQ             /**< Deprecated */\n#define NV_ENC_PARAMS_RC_CBR2                   NV_ENC_PARAMS_RC_CBR                /**< Deprecated */\n\n/**\n * Input picture structure\n */\ntypedef enum _NV_ENC_PIC_STRUCT\n{\n    NV_ENC_PIC_STRUCT_FRAME             = 0x01,                 /**< Progressive frame */\n    NV_ENC_PIC_STRUCT_FIELD_TOP_BOTTOM  = 0x02,                 /**< Field encoding top field first */\n    NV_ENC_PIC_STRUCT_FIELD_BOTTOM_TOP  = 0x03                  /**< Field encoding bottom field first */\n} NV_ENC_PIC_STRUCT;\n\n/**\n * Input picture type\n */\ntypedef enum _NV_ENC_PIC_TYPE\n{\n    NV_ENC_PIC_TYPE_P               = 0x0,     /**< Forward predicted */\n    NV_ENC_PIC_TYPE_B               = 0x01,    /**< Bi-directionally predicted picture */\n    NV_ENC_PIC_TYPE_I               = 0x02,    /**< Intra predicted picture */\n    NV_ENC_PIC_TYPE_IDR             = 0x03,    /**< IDR picture */\n    NV_ENC_PIC_TYPE_BI              = 0x04,    /**< Bi-directionally predicted with only Intra MBs */\n    NV_ENC_PIC_TYPE_SKIPPED         = 0x05,    /**< Picture is skipped */\n    NV_ENC_PIC_TYPE_INTRA_REFRESH   = 0x06,    /**< First picture in intra refresh cycle */\n    NV_ENC_PIC_TYPE_NONREF_P        = 0x07,    /**< Non reference P picture */\n    NV_ENC_PIC_TYPE_UNKNOWN         = 0xFF     /**< Picture type unknown */\n} NV_ENC_PIC_TYPE;\n\n/**\n * Motion vector precisions\n */\ntypedef enum _NV_ENC_MV_PRECISION\n{\n    NV_ENC_MV_PRECISION_DEFAULT     = 0x0,     /**< Driver selects Quarter-Pel motion vector precision by default */\n    NV_ENC_MV_PRECISION_FULL_PEL    = 0x01,    /**< Full-Pel motion vector precision */\n    NV_ENC_MV_PRECISION_HALF_PEL    = 0x02,    /**< Half-Pel motion vector precision */\n    NV_ENC_MV_PRECISION_QUARTER_PEL = 0x03     /**< Quarter-Pel motion vector precision */\n} NV_ENC_MV_PRECISION;\n\n\n/**\n * Input buffer formats\n */\ntypedef enum _NV_ENC_BUFFER_FORMAT\n{\n    NV_ENC_BUFFER_FORMAT_UNDEFINED                       = 0x00000000,  /**< Undefined buffer format */\n\n    NV_ENC_BUFFER_FORMAT_NV12                            = 0x00000001,  /**< Semi-Planar YUV [Y plane followed by interleaved UV plane] */\n    NV_ENC_BUFFER_FORMAT_YV12                            = 0x00000010,  /**< Planar YUV [Y plane followed by V and U planes] */\n    NV_ENC_BUFFER_FORMAT_IYUV                            = 0x00000100,  /**< Planar YUV [Y plane followed by U and V planes] */\n    NV_ENC_BUFFER_FORMAT_YUV444                          = 0x00001000,  /**< Planar YUV [Y plane followed by U and V planes] */\n    NV_ENC_BUFFER_FORMAT_YUV420_10BIT                    = 0x00010000,  /**< 10 bit Semi-Planar YUV [Y plane followed by interleaved UV plane]. Each pixel of size 2 bytes. Most Significant 10 bits contain pixel data. */\n    NV_ENC_BUFFER_FORMAT_YUV444_10BIT                    = 0x00100000,  /**< 10 bit Planar YUV444 [Y plane followed by U and V planes]. Each pixel of size 2 bytes. Most Significant 10 bits contain pixel data.  */\n    NV_ENC_BUFFER_FORMAT_ARGB                            = 0x01000000,  /**< 8 bit Packed A8R8G8B8. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with B\n                                                                             in the lowest 8 bits, G in the next 8 bits, R in the\n                                                                             8 bits after that and A in the highest 8 bits. */\n    NV_ENC_BUFFER_FORMAT_ARGB10                          = 0x02000000,  /**< 10 bit Packed A2R10G10B10. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with B\n                                                                             in the lowest 10 bits, G in the next 10 bits, R in the\n                                                                             10 bits after that and A in the highest 2 bits. */\n    NV_ENC_BUFFER_FORMAT_AYUV                            = 0x04000000,  /**< 8 bit Packed A8Y8U8V8. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with V\n                                                                             in the lowest 8 bits, U in the next 8 bits, Y in the\n                                                                             8 bits after that and A in the highest 8 bits. */\n    NV_ENC_BUFFER_FORMAT_ABGR                            = 0x10000000,  /**< 8 bit Packed A8B8G8R8. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with R\n                                                                             in the lowest 8 bits, G in the next 8 bits, B in the\n                                                                             8 bits after that and A in the highest 8 bits. */\n    NV_ENC_BUFFER_FORMAT_ABGR10                          = 0x20000000,  /**< 10 bit Packed A2B10G10R10. This is a word-ordered format\n                                                                             where a pixel is represented by a 32-bit word with R\n                                                                             in the lowest 10 bits, G in the next 10 bits, B in the\n                                                                             10 bits after that and A in the highest 2 bits. */\n    NV_ENC_BUFFER_FORMAT_U8                              = 0x40000000,  /**< Buffer format representing one-dimensional buffer.\n                                                                             This format should be used only when registering the\n                                                                             resource as output buffer, which will be used to write\n                                                                             the encoded bit stream or H.264 ME only mode output. */\n} NV_ENC_BUFFER_FORMAT;\n\n#define NV_ENC_BUFFER_FORMAT_NV12_PL NV_ENC_BUFFER_FORMAT_NV12\n#define NV_ENC_BUFFER_FORMAT_YV12_PL NV_ENC_BUFFER_FORMAT_YV12\n#define NV_ENC_BUFFER_FORMAT_IYUV_PL NV_ENC_BUFFER_FORMAT_IYUV\n#define NV_ENC_BUFFER_FORMAT_YUV444_PL NV_ENC_BUFFER_FORMAT_YUV444\n\n/**\n * Encoding levels\n */\ntypedef enum _NV_ENC_LEVEL\n{\n    NV_ENC_LEVEL_AUTOSELECT         = 0,\n\n    NV_ENC_LEVEL_H264_1             = 10,\n    NV_ENC_LEVEL_H264_1b            = 9,\n    NV_ENC_LEVEL_H264_11            = 11,\n    NV_ENC_LEVEL_H264_12            = 12,\n    NV_ENC_LEVEL_H264_13            = 13,\n    NV_ENC_LEVEL_H264_2             = 20,\n    NV_ENC_LEVEL_H264_21            = 21,\n    NV_ENC_LEVEL_H264_22            = 22,\n    NV_ENC_LEVEL_H264_3             = 30,\n    NV_ENC_LEVEL_H264_31            = 31,\n    NV_ENC_LEVEL_H264_32            = 32,\n    NV_ENC_LEVEL_H264_4             = 40,\n    NV_ENC_LEVEL_H264_41            = 41,\n    NV_ENC_LEVEL_H264_42            = 42,\n    NV_ENC_LEVEL_H264_5             = 50,\n    NV_ENC_LEVEL_H264_51            = 51,\n    NV_ENC_LEVEL_H264_52            = 52,\n    NV_ENC_LEVEL_H264_60            = 60,\n    NV_ENC_LEVEL_H264_61            = 61,\n    NV_ENC_LEVEL_H264_62            = 62,\n\n    NV_ENC_LEVEL_HEVC_1             = 30,\n    NV_ENC_LEVEL_HEVC_2             = 60,\n    NV_ENC_LEVEL_HEVC_21            = 63,\n    NV_ENC_LEVEL_HEVC_3             = 90,\n    NV_ENC_LEVEL_HEVC_31            = 93,\n    NV_ENC_LEVEL_HEVC_4             = 120,\n    NV_ENC_LEVEL_HEVC_41            = 123,\n    NV_ENC_LEVEL_HEVC_5             = 150,\n    NV_ENC_LEVEL_HEVC_51            = 153,\n    NV_ENC_LEVEL_HEVC_52            = 156,\n    NV_ENC_LEVEL_HEVC_6             = 180,\n    NV_ENC_LEVEL_HEVC_61            = 183,\n    NV_ENC_LEVEL_HEVC_62            = 186,\n\n    NV_ENC_TIER_HEVC_MAIN           = 0,\n    NV_ENC_TIER_HEVC_HIGH           = 1\n} NV_ENC_LEVEL;\n\n/**\n * Error Codes\n */\ntypedef enum _NVENCSTATUS\n{\n    /**\n     * This indicates that API call returned with no errors.\n     */\n    NV_ENC_SUCCESS,\n\n    /**\n     * This indicates that no encode capable devices were detected.\n     */\n    NV_ENC_ERR_NO_ENCODE_DEVICE,\n\n    /**\n     * This indicates that devices pass by the client is not supported.\n     */\n    NV_ENC_ERR_UNSUPPORTED_DEVICE,\n\n    /**\n     * This indicates that the encoder device supplied by the client is not\n     * valid.\n     */\n    NV_ENC_ERR_INVALID_ENCODERDEVICE,\n\n    /**\n     * This indicates that device passed to the API call is invalid.\n     */\n    NV_ENC_ERR_INVALID_DEVICE,\n\n    /**\n     * This indicates that device passed to the API call is no longer available and\n     * needs to be reinitialized. The clients need to destroy the current encoder\n     * session by freeing the allocated input output buffers and destroying the device\n     * and create a new encoding session.\n     */\n    NV_ENC_ERR_DEVICE_NOT_EXIST,\n\n    /**\n     * This indicates that one or more of the pointers passed to the API call\n     * is invalid.\n     */\n    NV_ENC_ERR_INVALID_PTR,\n\n    /**\n     * This indicates that completion event passed in ::NvEncEncodePicture() call\n     * is invalid.\n     */\n    NV_ENC_ERR_INVALID_EVENT,\n\n    /**\n     * This indicates that one or more of the parameter passed to the API call\n     * is invalid.\n     */\n    NV_ENC_ERR_INVALID_PARAM,\n\n    /**\n     * This indicates that an API call was made in wrong sequence/order.\n     */\n    NV_ENC_ERR_INVALID_CALL,\n\n    /**\n     * This indicates that the API call failed because it was unable to allocate\n     * enough memory to perform the requested operation.\n     */\n    NV_ENC_ERR_OUT_OF_MEMORY,\n\n    /**\n     * This indicates that the encoder has not been initialized with\n     * ::NvEncInitializeEncoder() or that initialization has failed.\n     * The client cannot allocate input or output buffers or do any encoding\n     * related operation before successfully initializing the encoder.\n     */\n    NV_ENC_ERR_ENCODER_NOT_INITIALIZED,\n\n    /**\n     * This indicates that an unsupported parameter was passed by the client.\n     */\n    NV_ENC_ERR_UNSUPPORTED_PARAM,\n\n    /**\n     * This indicates that the ::NvEncLockBitstream() failed to lock the output\n     * buffer. This happens when the client makes a non blocking lock call to\n     * access the output bitstream by passing NV_ENC_LOCK_BITSTREAM::doNotWait flag.\n     * This is not a fatal error and client should retry the same operation after\n     * few milliseconds.\n     */\n    NV_ENC_ERR_LOCK_BUSY,\n\n    /**\n     * This indicates that the size of the user buffer passed by the client is\n     * insufficient for the requested operation.\n     */\n    NV_ENC_ERR_NOT_ENOUGH_BUFFER,\n\n    /**\n     * This indicates that an invalid struct version was used by the client.\n     */\n    NV_ENC_ERR_INVALID_VERSION,\n\n    /**\n     * This indicates that ::NvEncMapInputResource() API failed to map the client\n     * provided input resource.\n     */\n    NV_ENC_ERR_MAP_FAILED,\n\n    /**\n     * This indicates encode driver requires more input buffers to produce an output\n     * bitstream. If this error is returned from ::NvEncEncodePicture() API, this\n     * is not a fatal error. If the client is encoding with B frames then,\n     * ::NvEncEncodePicture() API might be buffering the input frame for re-ordering.\n     *\n     * A client operating in synchronous mode cannot call ::NvEncLockBitstream()\n     * API on the output bitstream buffer if ::NvEncEncodePicture() returned the\n     * ::NV_ENC_ERR_NEED_MORE_INPUT error code.\n     * The client must continue providing input frames until encode driver returns\n     * ::NV_ENC_SUCCESS. After receiving ::NV_ENC_SUCCESS status the client can call\n     * ::NvEncLockBitstream() API on the output buffers in the same order in which\n     * it has called ::NvEncEncodePicture().\n     */\n    NV_ENC_ERR_NEED_MORE_INPUT,\n\n    /**\n     * This indicates that the HW encoder is busy encoding and is unable to encode\n     * the input. The client should call ::NvEncEncodePicture() again after few\n     * milliseconds.\n     */\n    NV_ENC_ERR_ENCODER_BUSY,\n\n    /**\n     * This indicates that the completion event passed in ::NvEncEncodePicture()\n     * API has not been registered with encoder driver using ::NvEncRegisterAsyncEvent().\n     */\n    NV_ENC_ERR_EVENT_NOT_REGISTERD,\n\n    /**\n     * This indicates that an unknown internal error has occurred.\n     */\n    NV_ENC_ERR_GENERIC,\n\n    /**\n     * This indicates that the client is attempting to use a feature\n     * that is not available for the license type for the current system.\n     */\n    NV_ENC_ERR_INCOMPATIBLE_CLIENT_KEY,\n\n    /**\n     * This indicates that the client is attempting to use a feature\n     * that is not implemented for the current version.\n     */\n    NV_ENC_ERR_UNIMPLEMENTED,\n\n    /**\n     * This indicates that the ::NvEncRegisterResource API failed to register the resource.\n     */\n    NV_ENC_ERR_RESOURCE_REGISTER_FAILED,\n\n    /**\n     * This indicates that the client is attempting to unregister a resource\n     * that has not been successfully registered.\n     */\n    NV_ENC_ERR_RESOURCE_NOT_REGISTERED,\n\n    /**\n     * This indicates that the client is attempting to unmap a resource\n     * that has not been successfully mapped.\n     */\n    NV_ENC_ERR_RESOURCE_NOT_MAPPED,\n\n} NVENCSTATUS;\n\n/**\n * Encode Picture encode flags.\n */\ntypedef enum _NV_ENC_PIC_FLAGS\n{\n    NV_ENC_PIC_FLAG_FORCEINTRA         = 0x1,   /**< Encode the current picture as an Intra picture */\n    NV_ENC_PIC_FLAG_FORCEIDR           = 0x2,   /**< Encode the current picture as an IDR picture.\n                                                     This flag is only valid when Picture type decision is taken by the Encoder\n                                                     [_NV_ENC_INITIALIZE_PARAMS::enablePTD == 1]. */\n    NV_ENC_PIC_FLAG_OUTPUT_SPSPPS      = 0x4,   /**< Write the sequence and picture header in encoded bitstream of the current picture */\n    NV_ENC_PIC_FLAG_EOS                = 0x8,   /**< Indicates end of the input stream */\n} NV_ENC_PIC_FLAGS;\n\n/**\n * Memory heap to allocate input and output buffers.\n */\ntypedef enum _NV_ENC_MEMORY_HEAP\n{\n    NV_ENC_MEMORY_HEAP_AUTOSELECT      = 0, /**< Memory heap to be decided by the encoder driver based on the usage */\n    NV_ENC_MEMORY_HEAP_VID             = 1, /**< Memory heap is in local video memory */\n    NV_ENC_MEMORY_HEAP_SYSMEM_CACHED   = 2, /**< Memory heap is in cached system memory */\n    NV_ENC_MEMORY_HEAP_SYSMEM_UNCACHED = 3  /**< Memory heap is in uncached system memory */\n} NV_ENC_MEMORY_HEAP;\n\n/**\n * B-frame used as reference modes\n */\ntypedef enum _NV_ENC_BFRAME_REF_MODE\n{\n    NV_ENC_BFRAME_REF_MODE_DISABLED = 0x0,          /**< B frame is not used for reference */\n    NV_ENC_BFRAME_REF_MODE_EACH     = 0x1,          /**< Each B-frame will be used for reference. currently not supported for H.264 */\n    NV_ENC_BFRAME_REF_MODE_MIDDLE   = 0x2,          /**< Only(Number of B-frame)/2 th B-frame will be used for reference */\n} NV_ENC_BFRAME_REF_MODE;\n\n/**\n * H.264 entropy coding modes.\n */\ntypedef enum _NV_ENC_H264_ENTROPY_CODING_MODE\n{\n    NV_ENC_H264_ENTROPY_CODING_MODE_AUTOSELECT = 0x0,   /**< Entropy coding mode is auto selected by the encoder driver */\n    NV_ENC_H264_ENTROPY_CODING_MODE_CABAC      = 0x1,   /**< Entropy coding mode is CABAC */\n    NV_ENC_H264_ENTROPY_CODING_MODE_CAVLC      = 0x2    /**< Entropy coding mode is CAVLC */\n} NV_ENC_H264_ENTROPY_CODING_MODE;\n\n/**\n * H.264 specific BDirect modes\n */\ntypedef enum _NV_ENC_H264_BDIRECT_MODE\n{\n    NV_ENC_H264_BDIRECT_MODE_AUTOSELECT = 0x0,          /**< BDirect mode is auto selected by the encoder driver */\n    NV_ENC_H264_BDIRECT_MODE_DISABLE    = 0x1,          /**< Disable BDirect mode */\n    NV_ENC_H264_BDIRECT_MODE_TEMPORAL   = 0x2,          /**< Temporal BDirect mode */\n    NV_ENC_H264_BDIRECT_MODE_SPATIAL    = 0x3           /**< Spatial BDirect mode */\n} NV_ENC_H264_BDIRECT_MODE;\n\n/**\n * H.264 specific FMO usage\n */\ntypedef enum _NV_ENC_H264_FMO_MODE\n{\n    NV_ENC_H264_FMO_AUTOSELECT          = 0x0,          /**< FMO usage is auto selected by the encoder driver */\n    NV_ENC_H264_FMO_ENABLE              = 0x1,          /**< Enable FMO */\n    NV_ENC_H264_FMO_DISABLE             = 0x2,          /**< Disable FMO */\n} NV_ENC_H264_FMO_MODE;\n\n/**\n * H.264 specific Adaptive Transform modes\n */\ntypedef enum _NV_ENC_H264_ADAPTIVE_TRANSFORM_MODE\n{\n    NV_ENC_H264_ADAPTIVE_TRANSFORM_AUTOSELECT = 0x0,   /**< Adaptive Transform 8x8 mode is auto selected by the encoder driver*/\n    NV_ENC_H264_ADAPTIVE_TRANSFORM_DISABLE    = 0x1,   /**< Adaptive Transform 8x8 mode disabled */\n    NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE     = 0x2,   /**< Adaptive Transform 8x8 mode should be used */\n} NV_ENC_H264_ADAPTIVE_TRANSFORM_MODE;\n\n/**\n * Stereo frame packing modes.\n */\ntypedef enum _NV_ENC_STEREO_PACKING_MODE\n{\n    NV_ENC_STEREO_PACKING_MODE_NONE             = 0x0,  /**< No Stereo packing required */\n    NV_ENC_STEREO_PACKING_MODE_CHECKERBOARD     = 0x1,  /**< Checkerboard mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_COLINTERLEAVE    = 0x2,  /**< Column Interleave mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_ROWINTERLEAVE    = 0x3,  /**< Row Interleave mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_SIDEBYSIDE       = 0x4,  /**< Side-by-side mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_TOPBOTTOM        = 0x5,  /**< Top-Bottom mode for packing stereo frames */\n    NV_ENC_STEREO_PACKING_MODE_FRAMESEQ         = 0x6   /**< Frame Sequential mode for packing stereo frames */\n} NV_ENC_STEREO_PACKING_MODE;\n\n/**\n *  Input Resource type\n */\ntypedef enum _NV_ENC_INPUT_RESOURCE_TYPE\n{\n    NV_ENC_INPUT_RESOURCE_TYPE_DIRECTX          = 0x0,   /**< input resource type is a directx9 surface*/\n    NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR    = 0x1,   /**< input resource type is a cuda device pointer surface*/\n    NV_ENC_INPUT_RESOURCE_TYPE_CUDAARRAY        = 0x2,   /**< input resource type is a cuda array surface.\n                                                              This array must be a 2D array and the CUDA_ARRAY3D_SURFACE_LDST\n                                                              flag must have been specified when creating it. */\n    NV_ENC_INPUT_RESOURCE_TYPE_OPENGL_TEX       = 0x3    /**< input resource type is an OpenGL texture */\n} NV_ENC_INPUT_RESOURCE_TYPE;\n\n/**\n *  Buffer usage\n */\ntypedef enum _NV_ENC_BUFFER_USAGE\n{\n    NV_ENC_INPUT_IMAGE              = 0x0,          /**< Registered surface will be used for input image */\n    NV_ENC_OUTPUT_MOTION_VECTOR     = 0x1,          /**< Registered surface will be used for output of H.264 ME only mode.\n                                                         This buffer usage type is not supported for HEVC ME only mode. */\n    NV_ENC_OUTPUT_BITSTREAM         = 0x2           /**< Registered surface will be used for output bitstream in encoding */\n} NV_ENC_BUFFER_USAGE;\n\n/**\n *  Encoder Device type\n */\ntypedef enum _NV_ENC_DEVICE_TYPE\n{\n    NV_ENC_DEVICE_TYPE_DIRECTX          = 0x0,   /**< encode device type is a directx9 device */\n    NV_ENC_DEVICE_TYPE_CUDA             = 0x1,   /**< encode device type is a cuda device */\n    NV_ENC_DEVICE_TYPE_OPENGL           = 0x2    /**< encode device type is an OpenGL device.\n                                                      Use of this device type is supported only on Linux */\n} NV_ENC_DEVICE_TYPE;\n\n/**\n * Number of reference frames\n */\ntypedef enum _NV_ENC_NUM_REF_FRAMES\n{\n    NV_ENC_NUM_REF_FRAMES_AUTOSELECT       = 0x0,          /**< Number of reference frames is auto selected by the encoder driver */\n    NV_ENC_NUM_REF_FRAMES_1                = 0x1,          /**< Number of reference frames equal to 1 */\n    NV_ENC_NUM_REF_FRAMES_2                = 0x2,          /**< Number of reference frames equal to 2 */\n    NV_ENC_NUM_REF_FRAMES_3                = 0x3,          /**< Number of reference frames equal to 3 */\n    NV_ENC_NUM_REF_FRAMES_4                = 0x4,          /**< Number of reference frames equal to 4 */\n    NV_ENC_NUM_REF_FRAMES_5                = 0x5,          /**< Number of reference frames equal to 5 */\n    NV_ENC_NUM_REF_FRAMES_6                = 0x6,          /**< Number of reference frames equal to 6 */\n    NV_ENC_NUM_REF_FRAMES_7                = 0x7           /**< Number of reference frames equal to 7 */\n} NV_ENC_NUM_REF_FRAMES;\n\n/**\n * Encoder capabilities enumeration.\n */\ntypedef enum _NV_ENC_CAPS\n{\n    /**\n     * Maximum number of B-Frames supported.\n     */\n    NV_ENC_CAPS_NUM_MAX_BFRAMES,\n\n    /**\n     * Rate control modes supported.\n     * \\n The API return value is a bitmask of the values in NV_ENC_PARAMS_RC_MODE.\n     */\n    NV_ENC_CAPS_SUPPORTED_RATECONTROL_MODES,\n\n    /**\n     * Indicates HW support for field mode encoding.\n     * \\n 0 : Interlaced mode encoding is not supported.\n     * \\n 1 : Interlaced field mode encoding is supported.\n     * \\n 2 : Interlaced frame encoding and field mode encoding are both supported.\n     */\n    NV_ENC_CAPS_SUPPORT_FIELD_ENCODING,\n\n    /**\n     * Indicates HW support for monochrome mode encoding.\n     * \\n 0 : Monochrome mode not supported.\n     * \\n 1 : Monochrome mode supported.\n     */\n    NV_ENC_CAPS_SUPPORT_MONOCHROME,\n\n    /**\n     * Indicates HW support for FMO.\n     * \\n 0 : FMO not supported.\n     * \\n 1 : FMO supported.\n     */\n    NV_ENC_CAPS_SUPPORT_FMO,\n\n    /**\n     * Indicates HW capability for Quarter pel motion estimation.\n     * \\n 0 : Quarter-Pel Motion Estimation not supported.\n     * \\n 1 : Quarter-Pel Motion Estimation supported.\n     */\n    NV_ENC_CAPS_SUPPORT_QPELMV,\n\n    /**\n     * H.264 specific. Indicates HW support for BDirect modes.\n     * \\n 0 : BDirect mode encoding not supported.\n     * \\n 1 : BDirect mode encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_BDIRECT_MODE,\n\n    /**\n     * H264 specific. Indicates HW support for CABAC entropy coding mode.\n     * \\n 0 : CABAC entropy coding not supported.\n     * \\n 1 : CABAC entropy coding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_CABAC,\n\n    /**\n     * Indicates HW support for Adaptive Transform.\n     * \\n 0 : Adaptive Transform not supported.\n     * \\n 1 : Adaptive Transform supported.\n     */\n    NV_ENC_CAPS_SUPPORT_ADAPTIVE_TRANSFORM,\n\n    /**\n     * Indicates HW support for Multi View Coding.\n     * \\n 0 : Multi View Coding not supported.\n     * \\n 1 : Multi View Coding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_STEREO_MVC,\n\n    /**\n     * Indicates HW support for encoding Temporal layers.\n     * \\n 0 : Encoding Temporal layers not supported.\n     * \\n 1 : Encoding Temporal layers supported.\n     */\n    NV_ENC_CAPS_NUM_MAX_TEMPORAL_LAYERS,\n\n    /**\n     * Indicates HW support for Hierarchical P frames.\n     * \\n 0 : Hierarchical P frames not supported.\n     * \\n 1 : Hierarchical P frames supported.\n     */\n    NV_ENC_CAPS_SUPPORT_HIERARCHICAL_PFRAMES,\n\n    /**\n     * Indicates HW support for Hierarchical B frames.\n     * \\n 0 : Hierarchical B frames not supported.\n     * \\n 1 : Hierarchical B frames supported.\n     */\n    NV_ENC_CAPS_SUPPORT_HIERARCHICAL_BFRAMES,\n\n    /**\n     * Maximum Encoding level supported (See ::NV_ENC_LEVEL for details).\n     */\n    NV_ENC_CAPS_LEVEL_MAX,\n\n    /**\n     * Minimum Encoding level supported (See ::NV_ENC_LEVEL for details).\n     */\n    NV_ENC_CAPS_LEVEL_MIN,\n\n    /**\n     * Indicates HW support for separate colour plane encoding.\n     * \\n 0 : Separate colour plane encoding not supported.\n     * \\n 1 : Separate colour plane encoding supported.\n     */\n    NV_ENC_CAPS_SEPARATE_COLOUR_PLANE,\n\n    /**\n     * Maximum output width supported.\n     */\n    NV_ENC_CAPS_WIDTH_MAX,\n\n    /**\n     * Maximum output height supported.\n     */\n    NV_ENC_CAPS_HEIGHT_MAX,\n\n    /**\n     * Indicates Temporal Scalability Support.\n     * \\n 0 : Temporal SVC encoding not supported.\n     * \\n 1 : Temporal SVC encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_TEMPORAL_SVC,\n\n    /**\n     * Indicates Dynamic Encode Resolution Change Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Dynamic Encode Resolution Change not supported.\n     * \\n 1 : Dynamic Encode Resolution Change supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYN_RES_CHANGE,\n\n    /**\n     * Indicates Dynamic Encode Bitrate Change Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Dynamic Encode bitrate change not supported.\n     * \\n 1 : Dynamic Encode bitrate change supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE,\n\n    /**\n     * Indicates Forcing Constant QP On The Fly Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Forcing constant QP on the fly not supported.\n     * \\n 1 : Forcing constant QP on the fly supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYN_FORCE_CONSTQP,\n\n    /**\n     * Indicates Dynamic rate control mode Change Support.\n     * \\n 0 : Dynamic rate control mode change not supported.\n     * \\n 1 : Dynamic rate control mode change supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYN_RCMODE_CHANGE,\n\n    /**\n     * Indicates Subframe readback support for slice-based encoding. If this feature is supported, it can be enabled by setting enableSubFrameWrite = 1.\n     * \\n 0 : Subframe readback not supported.\n     * \\n 1 : Subframe readback supported.\n     */\n    NV_ENC_CAPS_SUPPORT_SUBFRAME_READBACK,\n\n    /**\n     * Indicates Constrained Encoding mode support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Constrained encoding mode not supported.\n     * \\n 1 : Constrained encoding mode supported.\n     * If this mode is supported client can enable this during initialization.\n     * Client can then force a picture to be coded as constrained picture where\n     * in-loop filtering is disabled across slice boundaries and prediction vectors for inter\n     * macroblocks in each slice will be restricted to the slice region.\n     */\n    NV_ENC_CAPS_SUPPORT_CONSTRAINED_ENCODING,\n\n    /**\n     * Indicates Intra Refresh Mode Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Intra Refresh Mode not supported.\n     * \\n 1 : Intra Refresh Mode supported.\n     */\n    NV_ENC_CAPS_SUPPORT_INTRA_REFRESH,\n\n    /**\n     * Indicates Custom VBV Buffer Size support. It can be used for capping frame size.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Custom VBV buffer size specification from client, not supported.\n     * \\n 1 : Custom VBV buffer size specification from client, supported.\n     */\n    NV_ENC_CAPS_SUPPORT_CUSTOM_VBV_BUF_SIZE,\n\n    /**\n     * Indicates Dynamic Slice Mode Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Dynamic Slice Mode not supported.\n     * \\n 1 : Dynamic Slice Mode supported.\n     */\n    NV_ENC_CAPS_SUPPORT_DYNAMIC_SLICE_MODE,\n\n    /**\n     * Indicates Reference Picture Invalidation Support.\n     * Support added from NvEncodeAPI version 2.0.\n     * \\n 0 : Reference Picture Invalidation not supported.\n     * \\n 1 : Reference Picture Invalidation supported.\n     */\n    NV_ENC_CAPS_SUPPORT_REF_PIC_INVALIDATION,\n\n    /**\n     * Indicates support for Pre-Processing.\n     * The API return value is a bitmask of the values defined in ::NV_ENC_PREPROC_FLAGS\n     */\n    NV_ENC_CAPS_PREPROC_SUPPORT,\n\n    /**\n    * Indicates support Async mode.\n    * \\n 0 : Async Encode mode not supported.\n    * \\n 1 : Async Encode mode supported.\n    */\n    NV_ENC_CAPS_ASYNC_ENCODE_SUPPORT,\n\n    /**\n     * Maximum MBs per frame supported.\n     */\n    NV_ENC_CAPS_MB_NUM_MAX,\n\n    /**\n     * Maximum aggregate throughput in MBs per sec.\n     */\n    NV_ENC_CAPS_MB_PER_SEC_MAX,\n\n    /**\n     * Indicates HW support for YUV444 mode encoding.\n     * \\n 0 : YUV444 mode encoding not supported.\n     * \\n 1 : YUV444 mode encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_YUV444_ENCODE,\n\n    /**\n     * Indicates HW support for lossless encoding.\n     * \\n 0 : lossless encoding not supported.\n     * \\n 1 : lossless encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_LOSSLESS_ENCODE,\n\n    /**\n    * Indicates HW support for Sample Adaptive Offset.\n    * \\n 0 : SAO not supported.\n    * \\n 1 : SAO encoding supported.\n    */\n    NV_ENC_CAPS_SUPPORT_SAO,\n\n    /**\n     * Indicates HW support for Motion Estimation Only Mode.\n     * \\n 0 : MEOnly Mode not supported.\n     * \\n 1 : MEOnly Mode supported for I and P frames.\n     * \\n 2 : MEOnly Mode supported for I, P and B frames.\n     */\n    NV_ENC_CAPS_SUPPORT_MEONLY_MODE,\n\n    /**\n     * Indicates HW support for lookahead encoding (enableLookahead=1).\n     * \\n 0 : Lookahead not supported.\n     * \\n 1 : Lookahead supported.\n     */\n    NV_ENC_CAPS_SUPPORT_LOOKAHEAD,\n\n    /**\n     * Indicates HW support for temporal AQ encoding (enableTemporalAQ=1).\n     * \\n 0 : Temporal AQ not supported.\n     * \\n 1 : Temporal AQ supported.\n     */\n    NV_ENC_CAPS_SUPPORT_TEMPORAL_AQ,\n    /**\n     * Indicates HW support for 10 bit encoding.\n     * \\n 0 : 10 bit encoding not supported.\n     * \\n 1 : 10 bit encoding supported.\n     */\n    NV_ENC_CAPS_SUPPORT_10BIT_ENCODE,\n    /**\n     * Maximum number of Long Term Reference frames supported\n     */\n    NV_ENC_CAPS_NUM_MAX_LTR_FRAMES,\n\n    /**\n     * Indicates HW support for Weighted Prediction.\n     * \\n 0 : Weighted Prediction not supported.\n     * \\n 1 : Weighted Prediction supported.\n     */\n    NV_ENC_CAPS_SUPPORT_WEIGHTED_PREDICTION,\n\n\n    /**\n     * On managed (vGPU) platforms (Windows only), this API, in conjunction with other GRID Management APIs, can be used\n     * to estimate the residual capacity of the hardware encoder on the GPU as a percentage of the total available encoder capacity.\n     * This API can be called at any time; i.e. during the encode session or before opening the encode session.\n     * If the available encoder capacity is returned as zero, applications may choose to switch to software encoding\n     * and continue to call this API (e.g. polling once per second) until capacity becomes available.\n     *\n     * On bare metal (non-virtualized GPU) and linux platforms, this API always returns 100.\n     */\n    NV_ENC_CAPS_DYNAMIC_QUERY_ENCODER_CAPACITY,\n\n    /**\n    * Indicates B as reference support.\n    * \\n 0 : B as reference is not supported.\n    * \\n 1 : each B-Frame as reference is supported.\n    * \\n 2 : only Middle B-frame as reference is supported.\n    */\n    NV_ENC_CAPS_SUPPORT_BFRAME_REF_MODE,\n\n    /**\n     * Indicates HW support for Emphasis Level Map based delta QP computation.\n     * \\n 0 : Emphasis Level Map based delta QP not supported.\n     * \\n 1 : Emphasis Level Map based delta QP is supported.\n     */\n    NV_ENC_CAPS_SUPPORT_EMPHASIS_LEVEL_MAP,\n\n    /**\n     * Minimum input width supported.\n     */\n    NV_ENC_CAPS_WIDTH_MIN,\n\n    /**\n     * Minimum input height supported.\n     */\n    NV_ENC_CAPS_HEIGHT_MIN,\n\n    /**\n     * Indicates HW support for multiple reference frames.\n     */\n    NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES,\n\n    /**\n     * Indicates HW support for HEVC with alpha encoding.\n     * \\n 0 : HEVC with alpha encoding not supported.\n     * \\n 1 : HEVC with alpha encoding is supported.\n     */\n    NV_ENC_CAPS_SUPPORT_ALPHA_LAYER_ENCODING,\n\n    /**\n    * Indicates number of Encoding engines present on GPU.\n    */\n    NV_ENC_CAPS_NUM_ENCODER_ENGINES,\n\n    /**\n     * Indicates single slice intra refresh support.\n     */\n    NV_ENC_CAPS_SINGLE_SLICE_INTRA_REFRESH,\n\n    /**\n    * Reserved - Not to be used by clients.\n    */\n    NV_ENC_CAPS_EXPOSED_COUNT\n} NV_ENC_CAPS;\n\n/**\n *  HEVC CU SIZE\n */\ntypedef enum _NV_ENC_HEVC_CUSIZE\n{\n    NV_ENC_HEVC_CUSIZE_AUTOSELECT = 0,\n    NV_ENC_HEVC_CUSIZE_8x8        = 1,\n    NV_ENC_HEVC_CUSIZE_16x16      = 2,\n    NV_ENC_HEVC_CUSIZE_32x32      = 3,\n    NV_ENC_HEVC_CUSIZE_64x64      = 4,\n} NV_ENC_HEVC_CUSIZE;\n\n/**\n * Input struct for querying Encoding capabilities.\n */\ntypedef struct _NV_ENC_CAPS_PARAM\n{\n    uint32_t version;                                  /**< [in]: Struct version. Must be set to ::NV_ENC_CAPS_PARAM_VER */\n    NV_ENC_CAPS  capsToQuery;                          /**< [in]: Specifies the encode capability to be queried. Client should pass a member for ::NV_ENC_CAPS enum. */\n    uint32_t reserved[62];                             /**< [in]: Reserved and must be set to 0 */\n} NV_ENC_CAPS_PARAM;\n\n/** NV_ENC_CAPS_PARAM struct version. */\n#define NV_ENC_CAPS_PARAM_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * Encoder Output parameters\n */\ntypedef struct _NV_ENC_ENCODE_OUT_PARAMS\n{\n    uint32_t                  version;                 /**< [out]: Struct version. */\n    uint32_t                  bitstreamSizeInBytes;    /**< [out]: Encoded bitstream size in bytes */\n    uint32_t                  reserved[62];            /**< [out]: Reserved and must be set to 0 */\n} NV_ENC_ENCODE_OUT_PARAMS;\n\n/** NV_ENC_ENCODE_OUT_PARAMS struct version. */\n#define NV_ENC_ENCODE_OUT_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * Creation parameters for input buffer.\n */\ntypedef struct _NV_ENC_CREATE_INPUT_BUFFER\n{\n    uint32_t                  version;                 /**< [in]: Struct version. Must be set to ::NV_ENC_CREATE_INPUT_BUFFER_VER */\n    uint32_t                  width;                   /**< [in]: Input frame width */\n    uint32_t                  height;                  /**< [in]: Input frame height */\n    NV_ENC_MEMORY_HEAP        memoryHeap;              /**< [in]: Deprecated. Do not use */\n    NV_ENC_BUFFER_FORMAT      bufferFmt;               /**< [in]: Input buffer format */\n    uint32_t                  reserved;                /**< [in]: Reserved and must be set to 0 */\n    NV_ENC_INPUT_PTR          inputBuffer;             /**< [out]: Pointer to input buffer */\n    void                     *pSysMemBuffer;           /**< [in]: Pointer to existing system memory buffer */\n    uint32_t                  reserved1[57];           /**< [in]: Reserved and must be set to 0 */\n    void                     *reserved2[63];           /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CREATE_INPUT_BUFFER;\n\n/** NV_ENC_CREATE_INPUT_BUFFER struct version. */\n#define NV_ENC_CREATE_INPUT_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * Creation parameters for output bitstream buffer.\n */\ntypedef struct _NV_ENC_CREATE_BITSTREAM_BUFFER\n{\n    uint32_t              version;                     /**< [in]: Struct version. Must be set to ::NV_ENC_CREATE_BITSTREAM_BUFFER_VER */\n    uint32_t              size;                        /**< [in]: Deprecated. Do not use */\n    NV_ENC_MEMORY_HEAP    memoryHeap;                  /**< [in]: Deprecated. Do not use */\n    uint32_t              reserved;                    /**< [in]: Reserved and must be set to 0 */\n    NV_ENC_OUTPUT_PTR     bitstreamBuffer;             /**< [out]: Pointer to the output bitstream buffer */\n    void                 *bitstreamBufferPtr;          /**< [out]: Reserved and should not be used */\n    uint32_t              reserved1[58];               /**< [in]: Reserved and should be set to 0 */\n    void                 *reserved2[64];               /**< [in]: Reserved and should be set to NULL */\n} NV_ENC_CREATE_BITSTREAM_BUFFER;\n\n/** NV_ENC_CREATE_BITSTREAM_BUFFER struct version. */\n#define NV_ENC_CREATE_BITSTREAM_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * Structs needed for ME only mode.\n */\ntypedef struct _NV_ENC_MVECTOR\n{\n    int16_t             mvx;               /**< the x component of MV in quarter-pel units */\n    int16_t             mvy;               /**< the y component of MV in quarter-pel units */\n} NV_ENC_MVECTOR;\n\n/**\n * Motion vector structure per macroblock for H264 motion estimation.\n */\ntypedef struct _NV_ENC_H264_MV_DATA\n{\n    NV_ENC_MVECTOR      mv[4];             /**< up to 4 vectors for 8x8 partition */\n    uint8_t             mbType;            /**< 0 (I), 1 (P), 2 (IPCM), 3 (B) */\n    uint8_t             partitionType;     /**< Specifies the block partition type. 0:16x16, 1:8x8, 2:16x8, 3:8x16 */\n    uint16_t            reserved;          /**< reserved padding for alignment */\n    uint32_t            mbCost;\n} NV_ENC_H264_MV_DATA;\n\n/**\n * Motion vector structure per CU for HEVC motion estimation.\n */\ntypedef struct _NV_ENC_HEVC_MV_DATA\n{\n    NV_ENC_MVECTOR    mv[4];               /**< up to 4 vectors within a CU */\n    uint8_t           cuType;              /**< 0 (I), 1(P) */\n    uint8_t           cuSize;              /**< 0: 8x8, 1: 16x16, 2: 32x32, 3: 64x64 */\n    uint8_t           partitionMode;       /**< The CU partition mode\n                                                0 (2Nx2N), 1 (2NxN), 2(Nx2N), 3 (NxN),\n                                                4 (2NxnU), 5 (2NxnD), 6(nLx2N), 7 (nRx2N) */\n    uint8_t           lastCUInCTB;         /**< Marker to separate CUs in the current CTB from CUs in the next CTB */\n} NV_ENC_HEVC_MV_DATA;\n\n/**\n * Creation parameters for output motion vector buffer for ME only mode.\n */\ntypedef struct _NV_ENC_CREATE_MV_BUFFER\n{\n    uint32_t            version;           /**< [in]: Struct version. Must be set to NV_ENC_CREATE_MV_BUFFER_VER */\n    NV_ENC_OUTPUT_PTR   mvBuffer;          /**< [out]: Pointer to the output motion vector buffer */\n    uint32_t            reserved1[255];    /**< [in]: Reserved and should be set to 0 */\n    void               *reserved2[63];     /**< [in]: Reserved and should be set to NULL */\n} NV_ENC_CREATE_MV_BUFFER;\n\n/** NV_ENC_CREATE_MV_BUFFER struct version*/\n#define NV_ENC_CREATE_MV_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * QP value for frames\n */\ntypedef struct _NV_ENC_QP\n{\n    uint32_t        qpInterP;     /**< [in]: Specifies QP value for P-frame. Even though this field is uint32_t for legacy reasons, the client should treat this as a signed parameter(int32_t) for cases in which negative QP values are to be specified. */\n    uint32_t        qpInterB;     /**< [in]: Specifies QP value for B-frame. Even though this field is uint32_t for legacy reasons, the client should treat this as a signed parameter(int32_t) for cases in which negative QP values are to be specified. */\n    uint32_t        qpIntra;      /**< [in]: Specifies QP value for Intra Frame. Even though this field is uint32_t for legacy reasons, the client should treat this as a signed parameter(int32_t) for cases in which negative QP values are to be specified. */\n} NV_ENC_QP;\n\n/**\n * Rate Control Configuration Parameters\n */\ntypedef struct _NV_ENC_RC_PARAMS\n{\n    uint32_t                        version;\n    NV_ENC_PARAMS_RC_MODE           rateControlMode;                             /**< [in]: Specifies the rate control mode. Check support for various rate control modes using ::NV_ENC_CAPS_SUPPORTED_RATECONTROL_MODES caps. */\n    NV_ENC_QP                       constQP;                                     /**< [in]: Specifies the initial QP to be used for encoding, these values would be used for all frames if in Constant QP mode. */\n    uint32_t                        averageBitRate;                              /**< [in]: Specifies the average bitrate(in bits/sec) used for encoding. */\n    uint32_t                        maxBitRate;                                  /**< [in]: Specifies the maximum bitrate for the encoded output. This is used for VBR and ignored for CBR mode. */\n    uint32_t                        vbvBufferSize;                               /**< [in]: Specifies the VBV(HRD) buffer size. in bits. Set 0 to use the default VBV  buffer size. */\n    uint32_t                        vbvInitialDelay;                             /**< [in]: Specifies the VBV(HRD) initial delay in bits. Set 0 to use the default VBV  initial delay .*/\n    uint32_t                        enableMinQP          : 1;                    /**< [in]: Set this to 1 if minimum QP used for rate control. */\n    uint32_t                        enableMaxQP          : 1;                    /**< [in]: Set this to 1 if maximum QP used for rate control. */\n    uint32_t                        enableInitialRCQP    : 1;                    /**< [in]: Set this to 1 if user supplied initial QP is used for rate control. */\n    uint32_t                        enableAQ             : 1;                    /**< [in]: Set this to 1 to enable adaptive quantization (Spatial). */\n    uint32_t                        reservedBitField1    : 1;                    /**< [in]: Reserved bitfields and must be set to 0. */\n    uint32_t                        enableLookahead      : 1;                    /**< [in]: Set this to 1 to enable lookahead with depth <lookaheadDepth> (if lookahead is enabled, input frames must remain available to the encoder until encode completion) */\n    uint32_t                        disableIadapt        : 1;                    /**< [in]: Set this to 1 to disable adaptive I-frame insertion at scene cuts (only has an effect when lookahead is enabled) */\n    uint32_t                        disableBadapt        : 1;                    /**< [in]: Set this to 1 to disable adaptive B-frame decision (only has an effect when lookahead is enabled) */\n    uint32_t                        enableTemporalAQ     : 1;                    /**< [in]: Set this to 1 to enable temporal AQ */\n    uint32_t                        zeroReorderDelay     : 1;                    /**< [in]: Set this to 1 to indicate zero latency operation (no reordering delay, num_reorder_frames=0) */\n    uint32_t                        enableNonRefP        : 1;                    /**< [in]: Set this to 1 to enable automatic insertion of non-reference P-frames (no effect if enablePTD=0) */\n    uint32_t                        strictGOPTarget      : 1;                    /**< [in]: Set this to 1 to minimize GOP-to-GOP rate fluctuations */\n    uint32_t                        aqStrength           : 4;                     /**< [in]: When AQ (Spatial) is enabled (i.e. NV_ENC_RC_PARAMS::enableAQ is set), this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive).\n                                                                                            If not set, strength is auto selected by driver. */\n    uint32_t                        reservedBitFields    : 16;                   /**< [in]: Reserved bitfields and must be set to 0 */\n    NV_ENC_QP                       minQP;                                       /**< [in]: Specifies the minimum QP used for rate control. Client must set NV_ENC_CONFIG::enableMinQP to 1. */\n    NV_ENC_QP                       maxQP;                                       /**< [in]: Specifies the maximum QP used for rate control. Client must set NV_ENC_CONFIG::enableMaxQP to 1. */\n    NV_ENC_QP                       initialRCQP;                                 /**< [in]: Specifies the initial QP used for rate control. Client must set NV_ENC_CONFIG::enableInitialRCQP to 1. */\n    uint32_t                        temporallayerIdxMask;                        /**< [in]: Specifies the temporal layers (as a bitmask) whose QPs have changed. Valid max bitmask is [2^NV_ENC_CAPS_NUM_MAX_TEMPORAL_LAYERS - 1].\n                                                                                            Applicable only for constant QP mode (NV_ENC_RC_PARAMS::rateControlMode = NV_ENC_PARAMS_RC_CONSTQP). */\n    uint8_t                         temporalLayerQP[8];                          /**< [in]: Specifies the temporal layer QPs used for rate control. Temporal layer index is used as the array index.\n                                                                                            Applicable only for constant QP mode (NV_ENC_RC_PARAMS::rateControlMode = NV_ENC_PARAMS_RC_CONSTQP). */\n    uint8_t                         targetQuality;                               /**< [in]: Target CQ (Constant Quality) level for VBR mode (range 0-51 with 0-automatic)  */\n    uint8_t                         targetQualityLSB;                            /**< [in]: Fractional part of target quality (as 8.8 fixed point format) */\n    uint16_t                        lookaheadDepth;                              /**< [in]: Maximum depth of lookahead with range 0-(31 - number of B frames).\n                                                                                            lookaheadDepth is only used if enableLookahead=1.*/\n    uint8_t                         lowDelayKeyFrameScale;                       /**< [in]: Specifies the ratio of I frame bits to P frame bits in case of single frame VBV and CBR rate control mode,\n                                                                                            is set to 2 by default for low latency tuning info and 1 by default for ultra low latency tuning info  */\n    uint8_t                         reserved1[3];\n    NV_ENC_QP_MAP_MODE              qpMapMode;                                   /**< [in]: This flag is used to interpret values in array specified by NV_ENC_PIC_PARAMS::qpDeltaMap.\n                                                                                            Set this to NV_ENC_QP_MAP_EMPHASIS to treat values specified by NV_ENC_PIC_PARAMS::qpDeltaMap as Emphasis Level Map.\n                                                                                            Emphasis Level can be assigned any value specified in enum NV_ENC_EMPHASIS_MAP_LEVEL.\n                                                                                            Emphasis Level Map is used to specify regions to be encoded at varying levels of quality.\n                                                                                            The hardware encoder adjusts the quantization within the image as per the provided emphasis map,\n                                                                                            by adjusting the quantization parameter (QP) assigned to each macroblock. This adjustment is commonly called \u001cDelta QP\u001d.\n                                                                                            The adjustment depends on the absolute QP decided by the rate control algorithm, and is applied after the rate control has decided each macroblock\u0019s QP.\n                                                                                            Since the Delta QP overrides rate control, enabling Emphasis Level Map may violate bitrate and VBV buffer size constraints.\n                                                                                            Emphasis Level Map is useful in situations where client has a priori knowledge of the image complexity (e.g. via use of NVFBC's Classification feature) and encoding those high-complexity areas at higher quality (lower QP) is important, even at the possible cost of violating bitrate/VBV buffer size constraints\n                                                                                            This feature is not supported when AQ( Spatial/Temporal) is enabled.\n                                                                                            This feature is only supported for H264 codec currently.\n\n                                                                                            Set this to NV_ENC_QP_MAP_DELTA to treat values specified by NV_ENC_PIC_PARAMS::qpDeltaMap as QP Delta. This specifies QP modifier to be applied on top of the QP chosen by rate control\n\n                                                                                            Set this to NV_ENC_QP_MAP_DISABLED to ignore NV_ENC_PIC_PARAMS::qpDeltaMap values. In this case, qpDeltaMap should be set to NULL.\n\n                                                                                            Other values are reserved for future use.*/\n    NV_ENC_MULTI_PASS               multiPass;                                    /**< [in]: This flag is used to enable multi-pass encoding for a given ::NV_ENC_PARAMS_RC_MODE. This flag is not valid for H264 and HEVC MEOnly mode */\n    uint32_t                        alphaLayerBitrateRatio;                       /**< [in]: Specifies the ratio in which bitrate should be split between base and alpha layer. A value 'x' for this field will split the target bitrate in a ratio of x : 1 between base and alpha layer.\n                                                                                             The default split ratio is 15.*/\n    int8_t                          cbQPIndexOffset;                              /**< [in]: Specifies the value of 'chroma_qp_index_offset' in H264 / 'pps_cb_qp_offset' in HEVC.*/\n    int8_t                          crQPIndexOffset;                              /**< [in]: Specifies the value of 'second_chroma_qp_index_offset' in H264 / 'pps_cr_qp_offset' in HEVC.*/\n    uint16_t                        reserved2;\n    uint32_t                        reserved[4];\n} NV_ENC_RC_PARAMS;\n\n/** macro for constructing the version field of ::_NV_ENC_RC_PARAMS */\n#define NV_ENC_RC_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n\n/**\n * \\struct _NV_ENC_CONFIG_H264_VUI_PARAMETERS\n * H264 Video Usability Info parameters\n */\ntypedef struct _NV_ENC_CONFIG_H264_VUI_PARAMETERS\n{\n    uint32_t    overscanInfoPresentFlag;              /**< [in]: if set to 1 , it specifies that the overscanInfo is present */\n    uint32_t    overscanInfo;                         /**< [in]: Specifies the overscan info(as defined in Annex E of the ITU-T Specification). */\n    uint32_t    videoSignalTypePresentFlag;           /**< [in]: If set to 1, it specifies  that the videoFormat, videoFullRangeFlag and colourDescriptionPresentFlag are present. */\n    uint32_t    videoFormat;                          /**< [in]: Specifies the source video format(as defined in Annex E of the ITU-T Specification).*/\n    uint32_t    videoFullRangeFlag;                   /**< [in]: Specifies the output range of the luma and chroma samples(as defined in Annex E of the ITU-T Specification). */\n    uint32_t    colourDescriptionPresentFlag;         /**< [in]: If set to 1, it specifies that the colourPrimaries, transferCharacteristics and colourMatrix are present. */\n    uint32_t    colourPrimaries;                      /**< [in]: Specifies color primaries for converting to RGB(as defined in Annex E of the ITU-T Specification) */\n    uint32_t    transferCharacteristics;              /**< [in]: Specifies the opto-electronic transfer characteristics to use (as defined in Annex E of the ITU-T Specification) */\n    uint32_t    colourMatrix;                         /**< [in]: Specifies the matrix coefficients used in deriving the luma and chroma from the RGB primaries (as defined in Annex E of the ITU-T Specification). */\n    uint32_t    chromaSampleLocationFlag;             /**< [in]: if set to 1 , it specifies that the chromaSampleLocationTop and chromaSampleLocationBot are present.*/\n    uint32_t    chromaSampleLocationTop;              /**< [in]: Specifies the chroma sample location for top field(as defined in Annex E of the ITU-T Specification) */\n    uint32_t    chromaSampleLocationBot;              /**< [in]: Specifies the chroma sample location for bottom field(as defined in Annex E of the ITU-T Specification) */\n    uint32_t    bitstreamRestrictionFlag;             /**< [in]: if set to 1, it specifies the bitstream restriction parameters are present in the bitstream.*/\n    uint32_t    reserved[15];\n} NV_ENC_CONFIG_H264_VUI_PARAMETERS;\n\ntypedef NV_ENC_CONFIG_H264_VUI_PARAMETERS NV_ENC_CONFIG_HEVC_VUI_PARAMETERS;\n\n/**\n * \\struct _NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE\n * External motion vector hint counts per block type.\n * H264 supports multiple hint while HEVC supports one hint for each valid candidate.\n */\ntypedef struct _NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE\n{\n    uint32_t   numCandsPerBlk16x16                   : 4;   /**< [in]: Supported for H264, HEVC. It Specifies the number of candidates per 16x16 block. */\n    uint32_t   numCandsPerBlk16x8                    : 4;   /**< [in]: Supported for H264 only. Specifies the number of candidates per 16x8 block. */\n    uint32_t   numCandsPerBlk8x16                    : 4;   /**< [in]: Supported for H264 only. Specifies the number of candidates per 8x16 block. */\n    uint32_t   numCandsPerBlk8x8                     : 4;   /**< [in]: Supported for H264, HEVC. Specifies the number of candidates per 8x8 block. */\n    uint32_t   reserved                              : 16;  /**< [in]: Reserved for padding. */\n    uint32_t   reserved1[3];                                /**< [in]: Reserved for future use. */\n} NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE;\n\n\n/**\n * \\struct _NVENC_EXTERNAL_ME_HINT\n * External Motion Vector hint structure for H264 and HEVC.\n */\ntypedef struct _NVENC_EXTERNAL_ME_HINT\n{\n    int32_t    mvx         : 12;                        /**< [in]: Specifies the x component of integer pixel MV (relative to current MB) S12.0. */\n    int32_t    mvy         : 10;                        /**< [in]: Specifies the y component of integer pixel MV (relative to current MB) S10.0 .*/\n    int32_t    refidx      : 5;                         /**< [in]: Specifies the reference index (31=invalid). Current we support only 1 reference frame per direction for external hints, so \\p refidx must be 0. */\n    int32_t    dir         : 1;                         /**< [in]: Specifies the direction of motion estimation . 0=L0 1=L1.*/\n    int32_t    partType    : 2;                         /**< [in]: Specifies the block partition type.0=16x16 1=16x8 2=8x16 3=8x8 (blocks in partition must be consecutive).*/\n    int32_t    lastofPart  : 1;                         /**< [in]: Set to 1 for the last MV of (sub) partition  */\n    int32_t    lastOfMB    : 1;                         /**< [in]: Set to 1 for the last MV of macroblock. */\n} NVENC_EXTERNAL_ME_HINT;\n\n\n/**\n * \\struct _NV_ENC_CONFIG_H264\n * H264 encoder configuration parameters\n */\ntypedef struct _NV_ENC_CONFIG_H264\n{\n    uint32_t enableTemporalSVC         : 1;                         /**< [in]: Set to 1 to enable SVC temporal*/\n    uint32_t enableStereoMVC           : 1;                         /**< [in]: Set to 1 to enable stereo MVC*/\n    uint32_t hierarchicalPFrames       : 1;                         /**< [in]: Set to 1 to enable hierarchical P Frames */\n    uint32_t hierarchicalBFrames       : 1;                         /**< [in]: Set to 1 to enable hierarchical B Frames */\n    uint32_t outputBufferingPeriodSEI  : 1;                         /**< [in]: Set to 1 to write SEI buffering period syntax in the bitstream */\n    uint32_t outputPictureTimingSEI    : 1;                          /**< [in]: Set to 1 to write SEI picture timing syntax in the bitstream.  When set for following rateControlMode : NV_ENC_PARAMS_RC_CBR, NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ,\n                                                                               NV_ENC_PARAMS_RC_CBR_HQ, filler data is inserted if needed to achieve HRD bitrate */\n    uint32_t outputAUD                 : 1;                         /**< [in]: Set to 1 to write access unit delimiter syntax in bitstream */\n    uint32_t disableSPSPPS             : 1;                         /**< [in]: Set to 1 to disable writing of Sequence and Picture parameter info in bitstream */\n    uint32_t outputFramePackingSEI     : 1;                         /**< [in]: Set to 1 to enable writing of frame packing arrangement SEI messages to bitstream */\n    uint32_t outputRecoveryPointSEI    : 1;                         /**< [in]: Set to 1 to enable writing of recovery point SEI message */\n    uint32_t enableIntraRefresh        : 1;                         /**< [in]: Set to 1 to enable gradual decoder refresh or intra refresh. If the GOP structure uses B frames this will be ignored */\n    uint32_t enableConstrainedEncoding : 1;                          /**< [in]: Set this to 1 to enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices.\n                                                                               Constrained encoding works only with rectangular slices.\n                                                                               Check support for constrained encoding using ::NV_ENC_CAPS_SUPPORT_CONSTRAINED_ENCODING caps. */\n    uint32_t repeatSPSPPS              : 1;                         /**< [in]: Set to 1 to enable writing of Sequence and Picture parameter for every IDR frame */\n    uint32_t enableVFR                 : 1;                          /**< [in]: Setting enableVFR=1 currently only sets the fixed_frame_rate_flag=0 in the VUI but otherwise\n                                                                               has no impact on the encoder behavior. For more details please refer to E.1 VUI syntax of H.264 standard. Note, however, that NVENC does not support VFR encoding and rate control. */\n    uint32_t enableLTR                 : 1;                          /**< [in]: Set to 1 to enable LTR (Long Term Reference) frame support. LTR can be used in two modes: \"LTR Trust\" mode and \"LTR Per Picture\" mode.\n                                                                               LTR Trust mode: In this mode, ltrNumFrames pictures after IDR are automatically marked as LTR. This mode is enabled by setting ltrTrustMode = 1.\n                                                                                               Use of LTR Trust mode is strongly discouraged as this mode may be deprecated in future.\n                                                                               LTR Per Picture mode: In this mode, client can control whether the current picture should be marked as LTR. Enable this mode by setting\n                                                                                                     ltrTrustMode = 0 and ltrMarkFrame = 1 for the picture to be marked as LTR. This is the preferred mode\n                                                                                                     for using LTR.\n                                                                               Note that LTRs are not supported if encoding session is configured with B-frames */\n    uint32_t qpPrimeYZeroTransformBypassFlag : 1;                    /**< [in]: To enable lossless encode set this to 1, set QP to 0 and RC_mode to NV_ENC_PARAMS_RC_CONSTQP and profile to HIGH_444_PREDICTIVE_PROFILE.\n                                                                               Check support for lossless encoding using ::NV_ENC_CAPS_SUPPORT_LOSSLESS_ENCODE caps.  */\n    uint32_t useConstrainedIntraPred   : 1;                         /**< [in]: Set 1 to enable constrained intra prediction. */\n    uint32_t enableFillerDataInsertion : 1;                          /**< [in]: Set to 1 to enable insertion of filler data in the bitstream.\n                                                                               This flag will take effect only when one of the CBR rate\n                                                                               control modes (NV_ENC_PARAMS_RC_CBR, NV_ENC_PARAMS_RC_CBR_HQ,\n                                                                               NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ) is in use and both\n                                                                               NV_ENC_INITIALIZE_PARAMS::frameRateNum and\n                                                                               NV_ENC_INITIALIZE_PARAMS::frameRateDen are set to non-zero\n                                                                               values. Setting this field when\n                                                                               NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is also set\n                                                                               is currently not supported and will make ::NvEncInitializeEncoder()\n                                                                               return an error. */\n    uint32_t disableSVCPrefixNalu      : 1;                          /**< [in]: Set to 1 to disable writing of SVC Prefix NALU preceding each slice in bitstream.\n                                                                               Applicable only when temporal SVC is enabled (NV_ENC_CONFIG_H264::enableTemporalSVC = 1). */\n    uint32_t enableScalabilityInfoSEI  : 1;                          /**< [in]: Set to 1 to enable writing of Scalability Information SEI message preceding each IDR picture in bitstream\n                                                                               Applicable only when temporal SVC is enabled (NV_ENC_CONFIG_H264::enableTemporalSVC = 1). */\n    uint32_t singleSliceIntraRefresh : 1;                           /**< [in]: Set to 1 to maintain single slice in frames during intra refresh.\n                                                                               Check support for single slice intra refresh using ::NV_ENC_CAPS_SINGLE_SLICE_INTRA_REFRESH caps.\n                                                                               This flag will be ignored if the value returned for ::NV_ENC_CAPS_SINGLE_SLICE_INTRA_REFRESH caps is false. */\n    uint32_t reservedBitFields : 11;                                /**< [in]: Reserved bitfields and must be set to 0 */\n    uint32_t level;                                                 /**< [in]: Specifies the encoding level. Client is recommended to set this to NV_ENC_LEVEL_AUTOSELECT in order to enable the NvEncodeAPI interface to select the correct level. */\n    uint32_t idrPeriod;                                             /**< [in]: Specifies the IDR interval. If not set, this is made equal to gopLength in NV_ENC_CONFIG.Low latency application client can set IDR interval to NVENC_INFINITE_GOPLENGTH so that IDR frames are not inserted automatically. */\n    uint32_t separateColourPlaneFlag;                               /**< [in]: Set to 1 to enable 4:4:4 separate colour planes */\n    uint32_t disableDeblockingFilterIDC;                            /**< [in]: Specifies the deblocking filter mode. Permissible value range: [0,2]. This flag corresponds\n                                                                               to the flag disable_deblocking_filter_idc specified in section 7.4.3 of H.264 specification,\n                                                                               which specifies whether the operation of the deblocking filter shall be disabled across some\n                                                                               block edges of the slice and specifies for which edges the filtering is disabled. See section\n                                                                               7.4.3 of H.264 specification for more details.*/\n    uint32_t numTemporalLayers;                                     /**< [in]: Specifies number of temporal layers to be used for hierarchical coding / temporal SVC. Valid value range is [1,::NV_ENC_CAPS_NUM_MAX_TEMPORAL_LAYERS] */\n    uint32_t spsId;                                                 /**< [in]: Specifies the SPS id of the sequence header */\n    uint32_t ppsId;                                                 /**< [in]: Specifies the PPS id of the picture header */\n    NV_ENC_H264_ADAPTIVE_TRANSFORM_MODE adaptiveTransformMode;      /**< [in]: Specifies the AdaptiveTransform Mode. Check support for AdaptiveTransform mode using ::NV_ENC_CAPS_SUPPORT_ADAPTIVE_TRANSFORM caps. */\n    NV_ENC_H264_FMO_MODE                fmoMode;                    /**< [in]: Specified the FMO Mode. Check support for FMO using ::NV_ENC_CAPS_SUPPORT_FMO caps. */\n    NV_ENC_H264_BDIRECT_MODE            bdirectMode;                /**< [in]: Specifies the BDirect mode. Check support for BDirect mode using ::NV_ENC_CAPS_SUPPORT_BDIRECT_MODE caps.*/\n    NV_ENC_H264_ENTROPY_CODING_MODE     entropyCodingMode;          /**< [in]: Specifies the entropy coding mode. Check support for CABAC mode using ::NV_ENC_CAPS_SUPPORT_CABAC caps. */\n    NV_ENC_STEREO_PACKING_MODE          stereoMode;                 /**< [in]: Specifies the stereo frame packing mode which is to be signaled in frame packing arrangement SEI */\n    uint32_t                            intraRefreshPeriod;         /**< [in]: Specifies the interval between successive intra refresh if enableIntrarefresh is set. Requires enableIntraRefresh to be set.\n                                                                               Will be disabled if NV_ENC_CONFIG::gopLength is not set to NVENC_INFINITE_GOPLENGTH. */\n    uint32_t                            intraRefreshCnt;            /**< [in]: Specifies the length of intra refresh in number of frames for periodic intra refresh. This value should be smaller than intraRefreshPeriod */\n    uint32_t                            maxNumRefFrames;            /**< [in]: Specifies the DPB size used for encoding. Setting it to 0 will let driver use the default DPB size.\n                                                                               The low latency application which wants to invalidate reference frame as an error resilience tool\n                                                                               is recommended to use a large DPB size so that the encoder can keep old reference frames which can be used if recent\n                                                                               frames are invalidated. */\n    uint32_t                            sliceMode;                  /**< [in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divided into slices\n                                                                               sliceMode = 0 MB based slices, sliceMode = 1 Byte based slices, sliceMode = 2 MB row based slices, sliceMode = 3 numSlices in Picture.\n                                                                               When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting\n                                                                               When sliceMode == 0 and sliceModeData == 0 whole picture will be coded with one slice */\n    uint32_t                            sliceModeData;              /**< [in]: Specifies the parameter needed for sliceMode. For:\n                                                                               sliceMode = 0, sliceModeData specifies # of MBs in each slice (except last slice)\n                                                                               sliceMode = 1, sliceModeData specifies maximum # of bytes in each slice (except last slice)\n                                                                               sliceMode = 2, sliceModeData specifies # of MB rows in each slice (except last slice)\n                                                                               sliceMode = 3, sliceModeData specifies number of slices in the picture. Driver will divide picture into slices optimally */\n    NV_ENC_CONFIG_H264_VUI_PARAMETERS   h264VUIParameters;          /**< [in]: Specifies the H264 video usability info parameters */\n    uint32_t                            ltrNumFrames;               /**< [in]: Specifies the number of LTR frames. This parameter has different meaning in two LTR modes.\n                                                                               In \"LTR Trust\" mode (ltrTrustMode = 1), encoder will mark the first ltrNumFrames base layer reference frames within each IDR interval as LTR.\n                                                                               In \"LTR Per Picture\" mode (ltrTrustMode = 0 and ltrMarkFrame = 1), ltrNumFrames specifies maximum number of LTR frames in DPB. */\n    uint32_t                            ltrTrustMode;               /**< [in]: Specifies the LTR operating mode. See comments near NV_ENC_CONFIG_H264::enableLTR for description of the two modes.\n                                                                               Set to 1 to use \"LTR Trust\" mode of LTR operation. Clients are discouraged to use \"LTR Trust\" mode as this mode may\n                                                                               be deprecated in future releases.\n                                                                               Set to 0 when using \"LTR Per Picture\" mode of LTR operation. */\n    uint32_t                            chromaFormatIDC;            /**< [in]: Specifies the chroma format. Should be set to 1 for yuv420 input, 3 for yuv444 input.\n                                                                               Check support for YUV444 encoding using ::NV_ENC_CAPS_SUPPORT_YUV444_ENCODE caps.*/\n    uint32_t                            maxTemporalLayers;          /**< [in]: Specifies the maximum temporal layer used for temporal SVC / hierarchical coding.\n                                                                               Defaut value of this field is NV_ENC_CAPS::NV_ENC_CAPS_NUM_MAX_TEMPORAL_LAYERS. Note that the value NV_ENC_CONFIG_H264::maxNumRefFrames should\n                                                                               be greater than or equal to (NV_ENC_CONFIG_H264::maxTemporalLayers - 2) * 2, for NV_ENC_CONFIG_H264::maxTemporalLayers >= 2.*/\n    NV_ENC_BFRAME_REF_MODE              useBFramesAsRef;            /**< [in]: Specifies the B-Frame as reference mode. Check support for useBFramesAsRef mode using ::NV_ENC_CAPS_SUPPORT_BFRAME_REF_MODE caps.*/\n    NV_ENC_NUM_REF_FRAMES               numRefL0;                   /**< [in]: Specifies max number of reference frames in reference picture list L0, that can be used by hardware for prediction of a frame.\n                                                                               Check support for numRefL0 using ::NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES caps. */\n    NV_ENC_NUM_REF_FRAMES               numRefL1;                   /**< [in]: Specifies max number of reference frames in reference picture list L1, that can be used by hardware for prediction of a frame.\n                                                                               Check support for numRefL1 using ::NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES caps. */\n    uint32_t                            reserved1[267];             /**< [in]: Reserved and must be set to 0 */\n    void                               *reserved2[64];              /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG_H264;\n\n/**\n * \\struct _NV_ENC_CONFIG_HEVC\n * HEVC encoder configuration parameters to be set during initialization.\n */\ntypedef struct _NV_ENC_CONFIG_HEVC\n{\n    uint32_t level;                                                 /**< [in]: Specifies the level of the encoded bitstream.*/\n    uint32_t tier;                                                  /**< [in]: Specifies the level tier of the encoded bitstream.*/\n    NV_ENC_HEVC_CUSIZE minCUSize;                                   /**< [in]: Specifies the minimum size of luma coding unit.*/\n    NV_ENC_HEVC_CUSIZE maxCUSize;                                   /**< [in]: Specifies the maximum size of luma coding unit. Currently NVENC SDK only supports maxCUSize equal to NV_ENC_HEVC_CUSIZE_32x32.*/\n    uint32_t useConstrainedIntraPred               : 1;             /**< [in]: Set 1 to enable constrained intra prediction. */\n    uint32_t disableDeblockAcrossSliceBoundary     : 1;             /**< [in]: Set 1 to disable in loop filtering across slice boundary.*/\n    uint32_t outputBufferingPeriodSEI              : 1;             /**< [in]: Set 1 to write SEI buffering period syntax in the bitstream */\n    uint32_t outputPictureTimingSEI                : 1;             /**< [in]: Set 1 to write SEI picture timing syntax in the bitstream */\n    uint32_t outputAUD                             : 1;             /**< [in]: Set 1 to write Access Unit Delimiter syntax. */\n    uint32_t enableLTR                             : 1;              /**< [in]: Set to 1 to enable LTR (Long Term Reference) frame support. LTR can be used in two modes: \"LTR Trust\" mode and \"LTR Per Picture\" mode.\n                                                                               LTR Trust mode: In this mode, ltrNumFrames pictures after IDR are automatically marked as LTR. This mode is enabled by setting ltrTrustMode = 1.\n                                                                                               Use of LTR Trust mode is strongly discouraged as this mode may be deprecated in future releases.\n                                                                               LTR Per Picture mode: In this mode, client can control whether the current picture should be marked as LTR. Enable this mode by setting\n                                                                                                     ltrTrustMode = 0 and ltrMarkFrame = 1 for the picture to be marked as LTR. This is the preferred mode\n                                                                                                     for using LTR.\n                                                                               Note that LTRs are not supported if encoding session is configured with B-frames */\n    uint32_t disableSPSPPS                         : 1;             /**< [in]: Set 1 to disable VPS, SPS and PPS signaling in the bitstream. */\n    uint32_t repeatSPSPPS                          : 1;             /**< [in]: Set 1 to output VPS,SPS and PPS for every IDR frame.*/\n    uint32_t enableIntraRefresh                    : 1;             /**< [in]: Set 1 to enable gradual decoder refresh or intra refresh. If the GOP structure uses B frames this will be ignored */\n    uint32_t chromaFormatIDC                       : 2;             /**< [in]: Specifies the chroma format. Should be set to 1 for yuv420 input, 3 for yuv444 input.*/\n    uint32_t pixelBitDepthMinus8                   : 3;             /**< [in]: Specifies pixel bit depth minus 8. Should be set to 0 for 8 bit input, 2 for 10 bit input.*/\n    uint32_t enableFillerDataInsertion             : 1;              /**< [in]: Set to 1 to enable insertion of filler data in the bitstream.\n                                                                               This flag will take effect only when one of the CBR rate\n                                                                               control modes (NV_ENC_PARAMS_RC_CBR, NV_ENC_PARAMS_RC_CBR_HQ,\n                                                                               NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ) is in use and both\n                                                                               NV_ENC_INITIALIZE_PARAMS::frameRateNum and\n                                                                               NV_ENC_INITIALIZE_PARAMS::frameRateDen are set to non-zero\n                                                                               values. Setting this field when\n                                                                               NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is also set\n                                                                               is currently not supported and will make ::NvEncInitializeEncoder()\n                                                                               return an error. */\n    uint32_t enableConstrainedEncoding             : 1;              /**< [in]: Set this to 1 to enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices.\n                                                                               Constrained encoding works only with rectangular slices.\n                                                                               Check support for constrained encoding using ::NV_ENC_CAPS_SUPPORT_CONSTRAINED_ENCODING caps. */\n    uint32_t enableAlphaLayerEncoding              : 1;             /**< [in]: Set this to 1 to enable HEVC encode with alpha layer. */\n    uint32_t singleSliceIntraRefresh : 1;                           /**< [in]: Set this to 1 to maintain single slice frames during intra refresh.\n                                                                               Check support for single slice intra refresh using ::NV_ENC_CAPS_SINGLE_SLICE_INTRA_REFRESH caps.\n                                                                               This flag will be ignored if the value returned for ::NV_ENC_CAPS_SINGLE_SLICE_INTRA_REFRESH caps is false. */\n    uint32_t reserved : 14;                                         /**< [in]: Reserved bitfields.*/\n    uint32_t idrPeriod;                                             /**< [in]: Specifies the IDR interval. If not set, this is made equal to gopLength in NV_ENC_CONFIG. Low latency application client can set IDR interval to NVENC_INFINITE_GOPLENGTH so that IDR frames are not inserted automatically. */\n    uint32_t intraRefreshPeriod;                                    /**< [in]: Specifies the interval between successive intra refresh if enableIntrarefresh is set. Requires enableIntraRefresh to be set.\n                                                                    Will be disabled if NV_ENC_CONFIG::gopLength is not set to NVENC_INFINITE_GOPLENGTH. */\n    uint32_t intraRefreshCnt;                                       /**< [in]: Specifies the length of intra refresh in number of frames for periodic intra refresh. This value should be smaller than intraRefreshPeriod */\n    uint32_t maxNumRefFramesInDPB;                                  /**< [in]: Specifies the maximum number of references frames in the DPB.*/\n    uint32_t ltrNumFrames;                                          /**< [in]: This parameter has different meaning in two LTR modes.\n                                                                               In \"LTR Trust\" mode (ltrTrustMode = 1), encoder will mark the first ltrNumFrames base layer reference frames within each IDR interval as LTR.\n                                                                               In \"LTR Per Picture\" mode (ltrTrustMode = 0 and ltrMarkFrame = 1), ltrNumFrames specifies maximum number of LTR frames in DPB. */\n    uint32_t vpsId;                                                 /**< [in]: Specifies the VPS id of the video parameter set */\n    uint32_t spsId;                                                 /**< [in]: Specifies the SPS id of the sequence header */\n    uint32_t ppsId;                                                 /**< [in]: Specifies the PPS id of the picture header */\n    uint32_t sliceMode;                                             /**< [in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divided into slices\n                                                                                sliceMode = 0 CTU based slices, sliceMode = 1 Byte based slices, sliceMode = 2 CTU row based slices, sliceMode = 3, numSlices in Picture\n                                                                                When sliceMode == 0 and sliceModeData == 0 whole picture will be coded with one slice */\n    uint32_t sliceModeData;                                         /**< [in]: Specifies the parameter needed for sliceMode. For:\n                                                                                sliceMode = 0, sliceModeData specifies # of CTUs in each slice (except last slice)\n                                                                                sliceMode = 1, sliceModeData specifies maximum # of bytes in each slice (except last slice)\n                                                                                sliceMode = 2, sliceModeData specifies # of CTU rows in each slice (except last slice)\n                                                                                sliceMode = 3, sliceModeData specifies number of slices in the picture. Driver will divide picture into slices optimally */\n    uint32_t maxTemporalLayersMinus1;                               /**< [in]: Specifies the max temporal layer used for hierarchical coding. */\n    NV_ENC_CONFIG_HEVC_VUI_PARAMETERS   hevcVUIParameters;          /**< [in]: Specifies the HEVC video usability info parameters */\n    uint32_t ltrTrustMode;                                          /**< [in]: Specifies the LTR operating mode. See comments near NV_ENC_CONFIG_HEVC::enableLTR for description of the two modes.\n                                                                               Set to 1 to use \"LTR Trust\" mode of LTR operation. Clients are discouraged to use \"LTR Trust\" mode as this mode may\n                                                                               be deprecated in future releases.\n                                                                               Set to 0 when using \"LTR Per Picture\" mode of LTR operation. */\n    NV_ENC_BFRAME_REF_MODE              useBFramesAsRef;            /**< [in]: Specifies the B-Frame as reference mode. Check support for useBFramesAsRef mode using  ::NV_ENC_CAPS_SUPPORT_BFRAME_REF_MODE caps.*/\n    NV_ENC_NUM_REF_FRAMES               numRefL0;                   /**< [in]: Specifies max number of reference frames in reference picture list L0, that can be used by hardware for prediction of a frame.\n                                                                               Check support for numRefL0 using ::NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES caps. */\n    NV_ENC_NUM_REF_FRAMES               numRefL1;                   /**< [in]: Specifies max number of reference frames in reference picture list L1, that can be used by hardware for prediction of a frame.\n                                                                               Check support for numRefL1 using ::NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES caps. */\n    uint32_t                            reserved1[214];             /**< [in]: Reserved and must be set to 0.*/\n    void                               *reserved2[64];              /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG_HEVC;\n\n/**\n * \\struct _NV_ENC_CONFIG_H264_MEONLY\n * H264 encoder configuration parameters for ME only Mode\n *\n */\ntypedef struct _NV_ENC_CONFIG_H264_MEONLY\n{\n    uint32_t disablePartition16x16 : 1;                         /**< [in]: Disable Motion Estimation on 16x16 blocks*/\n    uint32_t disablePartition8x16  : 1;                         /**< [in]: Disable Motion Estimation on 8x16 blocks*/\n    uint32_t disablePartition16x8  : 1;                         /**< [in]: Disable Motion Estimation on 16x8 blocks*/\n    uint32_t disablePartition8x8   : 1;                         /**< [in]: Disable Motion Estimation on 8x8 blocks*/\n    uint32_t disableIntraSearch    : 1;                         /**< [in]: Disable Intra search during Motion Estimation*/\n    uint32_t bStereoEnable         : 1;                         /**< [in]: Enable Stereo Mode for Motion Estimation where each view is independently executed*/\n    uint32_t reserved              : 26;                        /**< [in]: Reserved and must be set to 0 */\n    uint32_t reserved1 [255];                                   /**< [in]: Reserved and must be set to 0 */\n    void    *reserved2[64];                                     /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG_H264_MEONLY;\n\n\n/**\n * \\struct _NV_ENC_CONFIG_HEVC_MEONLY\n * HEVC encoder configuration parameters for ME only Mode\n *\n */\ntypedef struct _NV_ENC_CONFIG_HEVC_MEONLY\n{\n    uint32_t reserved [256];                                   /**< [in]: Reserved and must be set to 0 */\n    void    *reserved1[64];                                     /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG_HEVC_MEONLY;\n\n/**\n * \\struct _NV_ENC_CODEC_CONFIG\n * Codec-specific encoder configuration parameters to be set during initialization.\n */\ntypedef union _NV_ENC_CODEC_CONFIG\n{\n    NV_ENC_CONFIG_H264        h264Config;                /**< [in]: Specifies the H.264-specific encoder configuration. */\n    NV_ENC_CONFIG_HEVC        hevcConfig;                /**< [in]: Specifies the HEVC-specific encoder configuration. */\n    NV_ENC_CONFIG_H264_MEONLY h264MeOnlyConfig;          /**< [in]: Specifies the H.264-specific ME only encoder configuration. */\n    NV_ENC_CONFIG_HEVC_MEONLY hevcMeOnlyConfig;          /**< [in]: Specifies the HEVC-specific ME only encoder configuration. */\n    uint32_t                reserved[320];               /**< [in]: Reserved and must be set to 0 */\n} NV_ENC_CODEC_CONFIG;\n\n\n/**\n * \\struct _NV_ENC_CONFIG\n * Encoder configuration parameters to be set during initialization.\n */\ntypedef struct _NV_ENC_CONFIG\n{\n    uint32_t                        version;                                     /**< [in]: Struct version. Must be set to ::NV_ENC_CONFIG_VER. */\n    GUID                            profileGUID;                                 /**< [in]: Specifies the codec profile GUID. If client specifies \\p NV_ENC_CODEC_PROFILE_AUTOSELECT_GUID the NvEncodeAPI interface will select the appropriate codec profile. */\n    uint32_t                        gopLength;                                   /**< [in]: Specifies the number of pictures in one GOP. Low latency application client can set goplength to NVENC_INFINITE_GOPLENGTH so that keyframes are not inserted automatically. */\n    int32_t                         frameIntervalP;                              /**< [in]: Specifies the GOP pattern as follows: \\p frameIntervalP = 0: I, 1: IPP, 2: IBP, 3: IBBP  If goplength is set to NVENC_INFINITE_GOPLENGTH \\p frameIntervalP should be set to 1. */\n    uint32_t                        monoChromeEncoding;                          /**< [in]: Set this to 1 to enable monochrome encoding for this session. */\n    NV_ENC_PARAMS_FRAME_FIELD_MODE  frameFieldMode;                              /**< [in]: Specifies the frame/field mode.\n                                                                                            Check support for field encoding using ::NV_ENC_CAPS_SUPPORT_FIELD_ENCODING caps.\n                                                                                            Using a frameFieldMode other than NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME for RGB input is not supported. */\n    NV_ENC_MV_PRECISION             mvPrecision;                                 /**< [in]: Specifies the desired motion vector prediction precision. */\n    NV_ENC_RC_PARAMS                rcParams;                                    /**< [in]: Specifies the rate control parameters for the current encoding session. */\n    NV_ENC_CODEC_CONFIG             encodeCodecConfig;                           /**< [in]: Specifies the codec specific config parameters through this union. */\n    uint32_t                        reserved [278];                              /**< [in]: Reserved and must be set to 0 */\n    void                           *reserved2[64];                               /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_CONFIG;\n\n/** macro for constructing the version field of ::_NV_ENC_CONFIG */\n#define NV_ENC_CONFIG_VER (NVENCAPI_STRUCT_VERSION(7) | ( 1U<<31 ))\n\n/**\n *  Tuning information of NVENC encoding (TuningInfo is not applicable to H264 and HEVC MEOnly mode).\n */\ntypedef enum NV_ENC_TUNING_INFO\n{\n    NV_ENC_TUNING_INFO_UNDEFINED         = 0,                                     /**< Undefined tuningInfo. Invalid value for encoding. */\n    NV_ENC_TUNING_INFO_HIGH_QUALITY      = 1,                                     /**< Tune presets for latency tolerant encoding.*/\n    NV_ENC_TUNING_INFO_LOW_LATENCY       = 2,                                     /**< Tune presets for low latency streaming.*/\n    NV_ENC_TUNING_INFO_ULTRA_LOW_LATENCY = 3,                                     /**< Tune presets for ultra low latency streaming.*/\n    NV_ENC_TUNING_INFO_LOSSLESS          = 4,                                     /**< Tune presets for lossless encoding.*/\n    NV_ENC_TUNING_INFO_COUNT                                                      /**< Count number of tuningInfos. Invalid value. */\n} NV_ENC_TUNING_INFO;\n\n/**\n * \\struct _NV_ENC_INITIALIZE_PARAMS\n * Encode Session Initialization parameters.\n */\ntypedef struct _NV_ENC_INITIALIZE_PARAMS\n{\n    uint32_t                                   version;                         /**< [in]: Struct version. Must be set to ::NV_ENC_INITIALIZE_PARAMS_VER. */\n    GUID                                       encodeGUID;                      /**< [in]: Specifies the Encode GUID for which the encoder is being created. ::NvEncInitializeEncoder() API will fail if this is not set, or set to unsupported value. */\n    GUID                                       presetGUID;                      /**< [in]: Specifies the preset for encoding. If the preset GUID is set then , the preset configuration will be applied before any other parameter. */\n    uint32_t                                   encodeWidth;                     /**< [in]: Specifies the encode width. If not set ::NvEncInitializeEncoder() API will fail. */\n    uint32_t                                   encodeHeight;                    /**< [in]: Specifies the encode height. If not set ::NvEncInitializeEncoder() API will fail. */\n    uint32_t                                   darWidth;                        /**< [in]: Specifies the display aspect ratio Width. */\n    uint32_t                                   darHeight;                       /**< [in]: Specifies the display aspect ratio height. */\n    uint32_t                                   frameRateNum;                    /**< [in]: Specifies the numerator for frame rate used for encoding in frames per second ( Frame rate = frameRateNum / frameRateDen ). */\n    uint32_t                                   frameRateDen;                    /**< [in]: Specifies the denominator for frame rate used for encoding in frames per second ( Frame rate = frameRateNum / frameRateDen ). */\n    uint32_t                                   enableEncodeAsync;               /**< [in]: Set this to 1 to enable asynchronous mode and is expected to use events to get picture completion notification. */\n    uint32_t                                   enablePTD;                       /**< [in]: Set this to 1 to enable the Picture Type Decision is be taken by the NvEncodeAPI interface. */\n    uint32_t                                   reportSliceOffsets        : 1;   /**< [in]: Set this to 1 to enable reporting slice offsets in ::_NV_ENC_LOCK_BITSTREAM. NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync must be set to 0 to use this feature. Client must set this to 0 if NV_ENC_CONFIG_H264::sliceMode is 1 on Kepler GPUs */\n    uint32_t                                   enableSubFrameWrite       : 1;    /**< [in]: Set this to 1 to write out available bitstream to memory at subframe intervals.\n                                                                                           If enableSubFrameWrite = 1, then the hardware encoder returns data as soon as a slice has completed encoding.\n                                                                                           This results in better encoding latency, but the downside is that the application has to keep polling via a call to nvEncLockBitstream API continuously to see if any encoded slice data is available.\n                                                                                           Use this mode if you feel that the marginal reduction in latency from sub-frame encoding is worth the increase in complexity due to CPU-based polling. */\n    uint32_t                                   enableExternalMEHints     : 1;    /**< [in]: Set to 1 to enable external ME hints for the current frame. For NV_ENC_INITIALIZE_PARAMS::enablePTD=1 with B frames, programming L1 hints is optional for B frames since Client doesn't know internal GOP structure.\n                                                                                           NV_ENC_PIC_PARAMS::meHintRefPicDist should preferably be set with enablePTD=1. */\n    uint32_t                                   enableMEOnlyMode          : 1;   /**< [in]: Set to 1 to enable ME Only Mode .*/\n    uint32_t                                   enableWeightedPrediction  : 1;    /**< [in]: Set this to 1 to enable weighted prediction. Not supported if encode session is configured for B-Frames (i.e. NV_ENC_CONFIG::frameIntervalP > 1 or preset >=P3 when tuningInfo = ::NV_ENC_TUNING_INFO_HIGH_QUALITY or\n                                                                                           tuningInfo = ::NV_ENC_TUNING_INFO_LOSSLESS. This is because preset >=p3 internally enables B frames when tuningInfo = ::NV_ENC_TUNING_INFO_HIGH_QUALITY or ::NV_ENC_TUNING_INFO_LOSSLESS). */\n    uint32_t                                   enableOutputInVidmem      : 1;   /**< [in]: Set this to 1 to enable output of NVENC in video memory buffer created by application. This feature is not supported for HEVC ME only mode. */\n    uint32_t                                   reservedBitFields         : 26;  /**< [in]: Reserved bitfields and must be set to 0 */\n    uint32_t                                   privDataSize;                    /**< [in]: Reserved private data buffer size and must be set to 0 */\n    void                                      *privData;                        /**< [in]: Reserved private data buffer and must be set to NULL */\n    NV_ENC_CONFIG                             *encodeConfig;                    /**< [in]: Specifies the advanced codec specific structure. If client has sent a valid codec config structure, it will override parameters set by the NV_ENC_INITIALIZE_PARAMS::presetGUID parameter. If set to NULL the NvEncodeAPI interface will use the NV_ENC_INITIALIZE_PARAMS::presetGUID to set the codec specific parameters.\n                                                                                           Client can also optionally query the NvEncodeAPI interface to get codec specific parameters for a presetGUID using ::NvEncGetEncodePresetConfig() API. It can then modify (if required) some of the codec config parameters and send down a custom config structure as part of ::_NV_ENC_INITIALIZE_PARAMS.\n                                                                                           Even in this case client is recommended to pass the same preset guid it has used in ::NvEncGetEncodePresetConfig() API to query the config structure; as NV_ENC_INITIALIZE_PARAMS::presetGUID. This will not override the custom config structure but will be used to determine other Encoder HW specific parameters not exposed in the API. */\n    uint32_t                                   maxEncodeWidth;                  /**< [in]: Maximum encode width to be used for current Encode session.\n                                                                                           Client should allocate output buffers according to this dimension for dynamic resolution change. If set to 0, Encoder will not allow dynamic resolution change. */\n    uint32_t                                   maxEncodeHeight;                 /**< [in]: Maximum encode height to be allowed for current Encode session.\n                                                                                           Client should allocate output buffers according to this dimension for dynamic resolution change. If set to 0, Encode will not allow dynamic resolution change. */\n    NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE maxMEHintCountsPerBlock[2];      /**< [in]: If Client wants to pass external motion vectors in NV_ENC_PIC_PARAMS::meExternalHints buffer it must specify the maximum number of hint candidates per block per direction for the encode session.\n                                                                                           The NV_ENC_INITIALIZE_PARAMS::maxMEHintCountsPerBlock[0] is for L0 predictors and NV_ENC_INITIALIZE_PARAMS::maxMEHintCountsPerBlock[1] is for L1 predictors.\n                                                                                           This client must also set NV_ENC_INITIALIZE_PARAMS::enableExternalMEHints to 1. */\n    NV_ENC_TUNING_INFO                         tuningInfo;                      /**< [in]: Tuning Info of NVENC encoding(TuningInfo is not applicable to H264 and HEVC meonly mode). */\n    NV_ENC_BUFFER_FORMAT                       bufferFormat;                    /**< [in]: Specifies input buffer format. Client should set input buffer format only when D3D12 interface type is used. */\n    uint32_t                                   reserved[287];                   /**< [in]: Reserved and must be set to 0 */\n    void                                      *reserved2[64];                   /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_INITIALIZE_PARAMS;\n\n/** macro for constructing the version field of ::_NV_ENC_INITIALIZE_PARAMS */\n#define NV_ENC_INITIALIZE_PARAMS_VER (NVENCAPI_STRUCT_VERSION(5) | ( 1U<<31 ))\n\n\n/**\n * \\struct _NV_ENC_RECONFIGURE_PARAMS\n * Encode Session Reconfigured parameters.\n */\ntypedef struct _NV_ENC_RECONFIGURE_PARAMS\n{\n    uint32_t                                    version;                        /**< [in]: Struct version. Must be set to ::NV_ENC_RECONFIGURE_PARAMS_VER. */\n    NV_ENC_INITIALIZE_PARAMS                    reInitEncodeParams;             /**< [in]: Encoder session re-initialization parameters.\n                                                                                           If reInitEncodeParams.encodeConfig is NULL and\n                                                                                           reInitEncodeParams.presetGUID is the same as the preset\n                                                                                           GUID specified on the call to NvEncInitializeEncoder(),\n                                                                                           EncodeAPI will continue to use the existing encode\n                                                                                           configuration.\n                                                                                           If reInitEncodeParams.encodeConfig is NULL and\n                                                                                           reInitEncodeParams.presetGUID is different from the preset\n                                                                                           GUID specified on the call to NvEncInitializeEncoder(),\n                                                                                           EncodeAPI will try to use the default configuration for\n                                                                                           the preset specified by reInitEncodeParams.presetGUID.\n                                                                                           In this case, reconfiguration may fail if the new\n                                                                                           configuration is incompatible with the existing\n                                                                                           configuration (e.g. the new configuration results in\n                                                                                           a change in the GOP structure). */\n    uint32_t                                    resetEncoder            : 1;     /**< [in]: This resets the rate control states and other internal encoder states. This should be used only with an IDR frame.\n                                                                                           If NV_ENC_INITIALIZE_PARAMS::enablePTD is set to 1, encoder will force the frame type to IDR */\n    uint32_t                                    forceIDR                : 1;     /**< [in]: Encode the current picture as an IDR picture. This flag is only valid when Picture type decision is taken by the Encoder\n                                                                                           [_NV_ENC_INITIALIZE_PARAMS::enablePTD == 1]. */\n    uint32_t                                    reserved                : 30;\n\n} NV_ENC_RECONFIGURE_PARAMS;\n\n/** macro for constructing the version field of ::_NV_ENC_RECONFIGURE_PARAMS */\n#define NV_ENC_RECONFIGURE_PARAMS_VER (NVENCAPI_STRUCT_VERSION(1) | ( 1<<31 ))\n\n/**\n * \\struct _NV_ENC_PRESET_CONFIG\n * Encoder preset config\n */\ntypedef struct _NV_ENC_PRESET_CONFIG\n{\n    uint32_t      version;                               /**< [in]:  Struct version. Must be set to ::NV_ENC_PRESET_CONFIG_VER. */\n    NV_ENC_CONFIG presetCfg;                             /**< [out]: preset config returned by the Nvidia Video Encoder interface. */\n    uint32_t      reserved1[255];                        /**< [in]: Reserved and must be set to 0 */\n    void         *reserved2[64];                         /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_PRESET_CONFIG;\n\n/** macro for constructing the version field of ::_NV_ENC_PRESET_CONFIG */\n#define NV_ENC_PRESET_CONFIG_VER (NVENCAPI_STRUCT_VERSION(4) | ( 1<<31 ))\n\n\n/**\n * \\struct _NV_ENC_PIC_PARAMS_MVC\n * MVC-specific parameters to be sent on a per-frame basis.\n */\ntypedef struct _NV_ENC_PIC_PARAMS_MVC\n{\n    uint32_t version;                                    /**< [in]: Struct version. Must be set to ::NV_ENC_PIC_PARAMS_MVC_VER. */\n    uint32_t viewID;                                     /**< [in]: Specifies the view ID associated with the current input view. */\n    uint32_t temporalID;                                 /**< [in]: Specifies the temporal ID associated with the current input view. */\n    uint32_t priorityID;                                 /**< [in]: Specifies the priority ID associated with the current input view. Reserved and ignored by the NvEncodeAPI interface. */\n    uint32_t reserved1[12];                              /**< [in]: Reserved and must be set to 0. */\n    void    *reserved2[8];                              /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_PIC_PARAMS_MVC;\n\n/** macro for constructing the version field of ::_NV_ENC_PIC_PARAMS_MVC */\n#define NV_ENC_PIC_PARAMS_MVC_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * \\union _NV_ENC_PIC_PARAMS_H264_EXT\n * H264 extension  picture parameters\n */\ntypedef union _NV_ENC_PIC_PARAMS_H264_EXT\n{\n    NV_ENC_PIC_PARAMS_MVC mvcPicParams;                  /**< [in]: Specifies the MVC picture parameters. */\n    uint32_t reserved1[32];                              /**< [in]: Reserved and must be set to 0.        */\n} NV_ENC_PIC_PARAMS_H264_EXT;\n\n/**\n * \\struct _NV_ENC_SEI_PAYLOAD\n *  User SEI message\n */\ntypedef struct _NV_ENC_SEI_PAYLOAD\n{\n    uint32_t payloadSize;            /**< [in] SEI payload size in bytes. SEI payload must be byte aligned, as described in Annex D */\n    uint32_t payloadType;            /**< [in] SEI payload types and syntax can be found in Annex D of the H.264 Specification. */\n    uint8_t *payload;                /**< [in] pointer to user data */\n} NV_ENC_SEI_PAYLOAD;\n\n#define NV_ENC_H264_SEI_PAYLOAD NV_ENC_SEI_PAYLOAD\n\n/**\n * \\struct _NV_ENC_PIC_PARAMS_H264\n * H264 specific enc pic params. sent on a per frame basis.\n */\ntypedef struct _NV_ENC_PIC_PARAMS_H264\n{\n    uint32_t displayPOCSyntax;                           /**< [in]: Specifies the display POC syntax This is required to be set if client is handling the picture type decision. */\n    uint32_t reserved3;                                  /**< [in]: Reserved and must be set to 0 */\n    uint32_t refPicFlag;                                 /**< [in]: Set to 1 for a reference picture. This is ignored if NV_ENC_INITIALIZE_PARAMS::enablePTD is set to 1. */\n    uint32_t colourPlaneId;                              /**< [in]: Specifies the colour plane ID associated with the current input. */\n    uint32_t forceIntraRefreshWithFrameCnt;              /**< [in]: Forces an intra refresh with duration equal to intraRefreshFrameCnt.\n                                                                    When outputRecoveryPointSEI is set this is value is used for recovery_frame_cnt in recovery point SEI message\n                                                                    forceIntraRefreshWithFrameCnt cannot be used if B frames are used in the GOP structure specified */\n    uint32_t constrainedFrame           : 1;              /**< [in]: Set to 1 if client wants to encode this frame with each slice completely independent of other slices in the frame.\n                                                                    NV_ENC_INITIALIZE_PARAMS::enableConstrainedEncoding should be set to 1 */\n    uint32_t sliceModeDataUpdate        : 1;              /**< [in]: Set to 1 if client wants to change the sliceModeData field to specify new sliceSize Parameter\n                                                                    When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting */\n    uint32_t ltrMarkFrame               : 1;             /**< [in]: Set to 1 if client wants to mark this frame as LTR */\n    uint32_t ltrUseFrames               : 1;             /**< [in]: Set to 1 if client allows encoding this frame using the LTR frames specified in ltrFrameBitmap */\n    uint32_t reservedBitFields          : 28;            /**< [in]: Reserved bit fields and must be set to 0 */\n    uint8_t *sliceTypeData;                              /**< [in]: Deprecated. */\n    uint32_t sliceTypeArrayCnt;                          /**< [in]: Deprecated. */\n    uint32_t seiPayloadArrayCnt;                         /**< [in]: Specifies the number of elements allocated in  seiPayloadArray array. */\n    NV_ENC_SEI_PAYLOAD *seiPayloadArray;                 /**< [in]: Array of SEI payloads which will be inserted for this frame. */\n    uint32_t sliceMode;                                  /**< [in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divided into slices\n                                                                    sliceMode = 0 MB based slices, sliceMode = 1 Byte based slices, sliceMode = 2 MB row based slices, sliceMode = 3, numSlices in Picture\n                                                                    When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting\n                                                                    When sliceMode == 0 and sliceModeData == 0 whole picture will be coded with one slice */\n    uint32_t sliceModeData;                              /**< [in]: Specifies the parameter needed for sliceMode. For:\n                                                                    sliceMode = 0, sliceModeData specifies # of MBs in each slice (except last slice)\n                                                                    sliceMode = 1, sliceModeData specifies maximum # of bytes in each slice (except last slice)\n                                                                    sliceMode = 2, sliceModeData specifies # of MB rows in each slice (except last slice)\n                                                                    sliceMode = 3, sliceModeData specifies number of slices in the picture. Driver will divide picture into slices optimally */\n    uint32_t ltrMarkFrameIdx;                            /**< [in]: Specifies the long term referenceframe index to use for marking this frame as LTR.*/\n    uint32_t ltrUseFrameBitmap;                          /**< [in]: Specifies the associated bitmap of LTR frame indices to use when encoding this frame. */\n    uint32_t ltrUsageMode;                               /**< [in]: Not supported. Reserved for future use and must be set to 0. */\n    uint32_t forceIntraSliceCount;                       /**< [in]: Specifies the number of slices to be forced to Intra in the current picture.\n                                                                    This option along with forceIntraSliceIdx[] array needs to be used with sliceMode = 3 only */\n    uint32_t *forceIntraSliceIdx;                        /**< [in]: Slice indices to be forced to intra in the current picture. Each slice index should be <= num_slices_in_picture -1. Index starts from 0 for first slice.\n                                                                    The number of entries in this array should be equal to forceIntraSliceCount */\n    NV_ENC_PIC_PARAMS_H264_EXT h264ExtPicParams;         /**< [in]: Specifies the H264 extension config parameters using this config. */\n    uint32_t reserved [210];                             /**< [in]: Reserved and must be set to 0. */\n    void    *reserved2[61];                              /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_PIC_PARAMS_H264;\n\n/**\n * \\struct _NV_ENC_PIC_PARAMS_HEVC\n * HEVC specific enc pic params. sent on a per frame basis.\n */\ntypedef struct _NV_ENC_PIC_PARAMS_HEVC\n{\n    uint32_t displayPOCSyntax;                           /**< [in]: Specifies the display POC syntax This is required to be set if client is handling the picture type decision. */\n    uint32_t refPicFlag;                                 /**< [in]: Set to 1 for a reference picture. This is ignored if NV_ENC_INITIALIZE_PARAMS::enablePTD is set to 1. */\n    uint32_t temporalId;                                 /**< [in]: Specifies the temporal id of the picture */\n    uint32_t forceIntraRefreshWithFrameCnt;              /**< [in]: Forces an intra refresh with duration equal to intraRefreshFrameCnt.\n                                                                    When outputRecoveryPointSEI is set this is value is used for recovery_frame_cnt in recovery point SEI message\n                                                                    forceIntraRefreshWithFrameCnt cannot be used if B frames are used in the GOP structure specified */\n    uint32_t constrainedFrame           : 1;              /**< [in]: Set to 1 if client wants to encode this frame with each slice completely independent of other slices in the frame.\n                                                                    NV_ENC_INITIALIZE_PARAMS::enableConstrainedEncoding should be set to 1 */\n    uint32_t sliceModeDataUpdate        : 1;              /**< [in]: Set to 1 if client wants to change the sliceModeData field to specify new sliceSize Parameter\n                                                                    When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting */\n    uint32_t ltrMarkFrame               : 1;             /**< [in]: Set to 1 if client wants to mark this frame as LTR */\n    uint32_t ltrUseFrames               : 1;             /**< [in]: Set to 1 if client allows encoding this frame using the LTR frames specified in ltrFrameBitmap */\n    uint32_t reservedBitFields          : 28;            /**< [in]: Reserved bit fields and must be set to 0 */\n    uint8_t *sliceTypeData;                              /**< [in]: Array which specifies the slice type used to force intra slice for a particular slice. Currently supported only for NV_ENC_CONFIG_H264::sliceMode == 3.\n                                                                    Client should allocate array of size sliceModeData where sliceModeData is specified in field of ::_NV_ENC_CONFIG_H264\n                                                                    Array element with index n corresponds to nth slice. To force a particular slice to intra client should set corresponding array element to NV_ENC_SLICE_TYPE_I\n                                                                    all other array elements should be set to NV_ENC_SLICE_TYPE_DEFAULT */\n    uint32_t sliceTypeArrayCnt;                          /**< [in]: Client should set this to the number of elements allocated in sliceTypeData array. If sliceTypeData is NULL then this should be set to 0 */\n    uint32_t sliceMode;                                  /**< [in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divided into slices\n                                                                    sliceMode = 0 CTU based slices, sliceMode = 1 Byte based slices, sliceMode = 2 CTU row based slices, sliceMode = 3, numSlices in Picture\n                                                                    When forceIntraRefreshWithFrameCnt is set it will have priority over sliceMode setting\n                                                                    When sliceMode == 0 and sliceModeData == 0 whole picture will be coded with one slice */\n    uint32_t sliceModeData;                              /**< [in]: Specifies the parameter needed for sliceMode. For:\n                                                                    sliceMode = 0, sliceModeData specifies # of CTUs in each slice (except last slice)\n                                                                    sliceMode = 1, sliceModeData specifies maximum # of bytes in each slice (except last slice)\n                                                                    sliceMode = 2, sliceModeData specifies # of CTU rows in each slice (except last slice)\n                                                                    sliceMode = 3, sliceModeData specifies number of slices in the picture. Driver will divide picture into slices optimally */\n    uint32_t ltrMarkFrameIdx;                            /**< [in]: Specifies the long term reference frame index to use for marking this frame as LTR.*/\n    uint32_t ltrUseFrameBitmap;                          /**< [in]: Specifies the associated bitmap of LTR frame indices to use when encoding this frame. */\n    uint32_t ltrUsageMode;                               /**< [in]: Not supported. Reserved for future use and must be set to 0. */\n    uint32_t seiPayloadArrayCnt;                         /**< [in]: Specifies the number of elements allocated in  seiPayloadArray array. */\n    uint32_t reserved;                                   /**< [in]: Reserved and must be set to 0. */\n    NV_ENC_SEI_PAYLOAD *seiPayloadArray;                 /**< [in]: Array of SEI payloads which will be inserted for this frame. */\n    uint32_t reserved2 [244];                             /**< [in]: Reserved and must be set to 0. */\n    void    *reserved3[61];                              /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_PIC_PARAMS_HEVC;\n\n/**\n * Codec specific per-picture encoding parameters.\n */\ntypedef union _NV_ENC_CODEC_PIC_PARAMS\n{\n    NV_ENC_PIC_PARAMS_H264 h264PicParams;                /**< [in]: H264 encode picture params. */\n    NV_ENC_PIC_PARAMS_HEVC hevcPicParams;                /**< [in]: HEVC encode picture params. */\n    uint32_t               reserved[256];                /**< [in]: Reserved and must be set to 0. */\n} NV_ENC_CODEC_PIC_PARAMS;\n\n/**\n * \\struct _NV_ENC_PIC_PARAMS\n * Encoding parameters that need to be sent on a per frame basis.\n */\ntypedef struct _NV_ENC_PIC_PARAMS\n{\n    uint32_t                                    version;                        /**< [in]: Struct version. Must be set to ::NV_ENC_PIC_PARAMS_VER. */\n    uint32_t                                    inputWidth;                     /**< [in]: Specifies the input frame width */\n    uint32_t                                    inputHeight;                    /**< [in]: Specifies the input frame height */\n    uint32_t                                    inputPitch;                     /**< [in]: Specifies the input buffer pitch. If pitch value is not known, set this to inputWidth. */\n    uint32_t                                    encodePicFlags;                 /**< [in]: Specifies bit-wise OR of encode picture flags. See ::NV_ENC_PIC_FLAGS enum. */\n    uint32_t                                    frameIdx;                       /**< [in]: Specifies the frame index associated with the input frame [optional]. */\n    uint64_t                                    inputTimeStamp;                 /**< [in]: Specifies opaque data which is associated with the encoded frame, but not actually encoded in the output bitstream.\n                                                                                           This opaque data can be used later to uniquely refer to the corresponding encoded frame. For example, it can be used\n                                                                                           for identifying the frame to be invalidated in the reference picture buffer, if lost at the client. */\n    uint64_t                                    inputDuration;                  /**< [in]: Specifies duration of the input picture */\n    NV_ENC_INPUT_PTR                            inputBuffer;                    /**< [in]: Specifies the input buffer pointer. Client must use a pointer obtained from ::NvEncCreateInputBuffer() or ::NvEncMapInputResource() APIs.*/\n    NV_ENC_OUTPUT_PTR                           outputBitstream;                /**< [in]: Specifies the output buffer pointer.\n                                                                                           If NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is set to 0, specifies the pointer to output buffer. Client should use a pointer obtained from ::NvEncCreateBitstreamBuffer() API.\n                                                                                           If NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is set to 1, client should allocate buffer in video memory for NV_ENC_ENCODE_OUT_PARAMS struct and encoded bitstream data. Client\n                                                                                           should use a pointer obtained from ::NvEncMapInputResource() API, when mapping this output buffer and assign it to NV_ENC_PIC_PARAMS::outputBitstream.\n                                                                                           First 256 bytes of this buffer should be interpreted as NV_ENC_ENCODE_OUT_PARAMS struct followed by encoded bitstream data. Recommended size for output buffer is sum of size of\n                                                                                           NV_ENC_ENCODE_OUT_PARAMS struct and twice the input frame size for lower resolution eg. CIF and 1.5 times the input frame size for higher resolutions. If encoded bitstream size is\n                                                                                           greater than the allocated buffer size for encoded bitstream, then the output buffer will have encoded bitstream data equal to buffer size. All CUDA operations on this buffer must use\n                                                                                           the default stream. */\n    void                                       *completionEvent;                /**< [in]: Specifies an event to be signaled on completion of encoding of this Frame [only if operating in Asynchronous mode]. Each output buffer should be associated with a distinct event pointer. */\n    NV_ENC_BUFFER_FORMAT                        bufferFmt;                      /**< [in]: Specifies the input buffer format. */\n    NV_ENC_PIC_STRUCT                           pictureStruct;                  /**< [in]: Specifies structure of the input picture. */\n    NV_ENC_PIC_TYPE                             pictureType;                    /**< [in]: Specifies input picture type. Client required to be set explicitly by the client if the client has not set NV_ENC_INITALIZE_PARAMS::enablePTD to 1 while calling NvInitializeEncoder. */\n    NV_ENC_CODEC_PIC_PARAMS                     codecPicParams;                 /**< [in]: Specifies the codec specific per-picture encoding parameters. */\n    NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE meHintCountsPerBlock[2];        /**< [in]: For H264 and Hevc, specifies the number of hint candidates per block per direction for the current frame. meHintCountsPerBlock[0] is for L0 predictors and meHintCountsPerBlock[1] is for L1 predictors.\n                                                                                           The candidate count in NV_ENC_PIC_PARAMS::meHintCountsPerBlock[lx] must never exceed NV_ENC_INITIALIZE_PARAMS::maxMEHintCountsPerBlock[lx] provided during encoder initialization. */\n    NVENC_EXTERNAL_ME_HINT                     *meExternalHints;                /**< [in]: For H264 and Hevc, Specifies the pointer to ME external hints for the current frame. The size of ME hint buffer should be equal to number of macroblocks * the total number of candidates per macroblock.\n                                                                                           The total number of candidates per MB per direction = 1*meHintCountsPerBlock[Lx].numCandsPerBlk16x16 + 2*meHintCountsPerBlock[Lx].numCandsPerBlk16x8 + 2*meHintCountsPerBlock[Lx].numCandsPerBlk8x8\n                                                                                           + 4*meHintCountsPerBlock[Lx].numCandsPerBlk8x8. For frames using bidirectional ME , the total number of candidates for single macroblock is sum of total number of candidates per MB for each direction (L0 and L1) */\n    uint32_t                                    reserved1[6];                    /**< [in]: Reserved and must be set to 0 */\n    void                                       *reserved2[2];                    /**< [in]: Reserved and must be set to NULL */\n    int8_t                                     *qpDeltaMap;                      /**< [in]: Specifies the pointer to signed byte array containing value per MB for H264 and per CTB for HEVC in raster scan order for the current picture, which will be interpreted depending on NV_ENC_RC_PARAMS::qpMapMode.\n                                                                                            If NV_ENC_RC_PARAMS::qpMapMode is NV_ENC_QP_MAP_DELTA, qpDeltaMap specifies QP modifier per MB for H264 and per CTB for HEVC. This QP modifier will be applied on top of the QP chosen by rate control.\n                                                                                            If NV_ENC_RC_PARAMS::qpMapMode is NV_ENC_QP_MAP_EMPHASIS, qpDeltaMap specifies Emphasis Level Map per MB for H264. This level value along with QP chosen by rate control is used to\n                                                                                            compute the QP modifier, which in turn is applied on top of QP chosen by rate control.\n                                                                                            If NV_ENC_RC_PARAMS::qpMapMode is NV_ENC_QP_MAP_DISABLED, value in qpDeltaMap will be ignored.*/\n    uint32_t                                    qpDeltaMapSize;                  /**< [in]: Specifies the size in bytes of qpDeltaMap surface allocated by client and pointed to by NV_ENC_PIC_PARAMS::qpDeltaMap. Surface (array) should be picWidthInMbs * picHeightInMbs for H264 and picWidthInCtbs * picHeightInCtbs for HEVC */\n    uint32_t                                    reservedBitFields;               /**< [in]: Reserved bitfields and must be set to 0 */\n    uint16_t                                    meHintRefPicDist[2];             /**< [in]: Specifies temporal distance for reference picture (NVENC_EXTERNAL_ME_HINT::refidx = 0) used during external ME with NV_ENC_INITALIZE_PARAMS::enablePTD = 1 . meHintRefPicDist[0] is for L0 hints and meHintRefPicDist[1] is for L1 hints.\n                                                                                            If not set, will internally infer distance of 1. Ignored for NV_ENC_INITALIZE_PARAMS::enablePTD = 0 */\n    NV_ENC_INPUT_PTR                            alphaBuffer;                     /**< [in]: Specifies the input alpha buffer pointer. Client must use a pointer obtained from ::NvEncCreateInputBuffer() or ::NvEncMapInputResource() APIs.\n                                                                                            Applicable only when encoding hevc with alpha layer is enabled. */\n    uint32_t                                    reserved3[286];                  /**< [in]: Reserved and must be set to 0 */\n    void                                       *reserved4[59];                   /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_PIC_PARAMS;\n\n/** Macro for constructing the version field of ::_NV_ENC_PIC_PARAMS */\n#define NV_ENC_PIC_PARAMS_VER (NVENCAPI_STRUCT_VERSION(4) | ( 1U<<31 ))\n\n\n/**\n * \\struct _NV_ENC_MEONLY_PARAMS\n * MEOnly parameters that need to be sent on a per motion estimation basis.\n * NV_ENC_MEONLY_PARAMS::meExternalHints is supported for H264 only.\n */\ntypedef struct _NV_ENC_MEONLY_PARAMS\n{\n    uint32_t                version;                            /**< [in]: Struct version. Must be set to NV_ENC_MEONLY_PARAMS_VER.*/\n    uint32_t                inputWidth;                         /**< [in]: Specifies the input frame width */\n    uint32_t                inputHeight;                        /**< [in]: Specifies the input frame height */\n    NV_ENC_INPUT_PTR        inputBuffer;                        /**< [in]: Specifies the input buffer pointer. Client must use a pointer obtained from NvEncCreateInputBuffer() or NvEncMapInputResource() APIs. */\n    NV_ENC_INPUT_PTR        referenceFrame;                     /**< [in]: Specifies the reference frame pointer */\n    NV_ENC_OUTPUT_PTR       mvBuffer;                           /**< [in]: Specifies the output buffer pointer.\n                                                                           If NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is set to 0, specifies the pointer to motion vector data buffer allocated by NvEncCreateMVBuffer.\n                                                                           Client must lock mvBuffer using ::NvEncLockBitstream() API to get the motion vector data.\n                                                                           If NV_ENC_INITIALIZE_PARAMS::enableOutputInVidmem is set to 1, client should allocate buffer in video memory for storing the motion vector data. The size of this buffer must\n                                                                           be equal to total number of macroblocks multiplied by size of NV_ENC_H264_MV_DATA struct. Client should use a pointer obtained from ::NvEncMapInputResource() API, when mapping this\n                                                                           output buffer and assign it to NV_ENC_MEONLY_PARAMS::mvBuffer. All CUDA operations on this buffer must use the default stream. */\n    NV_ENC_BUFFER_FORMAT    bufferFmt;                          /**< [in]: Specifies the input buffer format. */\n    void                   *completionEvent;                    /**< [in]: Specifies an event to be signaled on completion of motion estimation\n                                                                           of this Frame [only if operating in Asynchronous mode].\n                                                                           Each output buffer should be associated with a distinct event pointer. */\n    uint32_t                viewID;                             /**< [in]: Specifies left or right viewID if NV_ENC_CONFIG_H264_MEONLY::bStereoEnable is set.\n                                                                            viewID can be 0,1 if bStereoEnable is set, 0 otherwise. */\n    NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE\n    meHintCountsPerBlock[2];            /**< [in]: Specifies the number of hint candidates per block for the current frame. meHintCountsPerBlock[0] is for L0 predictors.\n                                                                            The candidate count in NV_ENC_PIC_PARAMS::meHintCountsPerBlock[lx] must never exceed NV_ENC_INITIALIZE_PARAMS::maxMEHintCountsPerBlock[lx] provided during encoder initialization. */\n    NVENC_EXTERNAL_ME_HINT  *meExternalHints;                   /**< [in]: Specifies the pointer to ME external hints for the current frame. The size of ME hint buffer should be equal to number of macroblocks * the total number of candidates per macroblock.\n                                                                            The total number of candidates per MB per direction = 1*meHintCountsPerBlock[Lx].numCandsPerBlk16x16 + 2*meHintCountsPerBlock[Lx].numCandsPerBlk16x8 + 2*meHintCountsPerBlock[Lx].numCandsPerBlk8x8\n                                                                            + 4*meHintCountsPerBlock[Lx].numCandsPerBlk8x8. For frames using bidirectional ME , the total number of candidates for single macroblock is sum of total number of candidates per MB for each direction (L0 and L1) */\n    uint32_t                reserved1[243];                     /**< [in]: Reserved and must be set to 0 */\n    void                   *reserved2[59];                      /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_MEONLY_PARAMS;\n\n/** NV_ENC_MEONLY_PARAMS struct version*/\n#define NV_ENC_MEONLY_PARAMS_VER NVENCAPI_STRUCT_VERSION(3)\n\n\n/**\n * \\struct _NV_ENC_LOCK_BITSTREAM\n * Bitstream buffer lock parameters.\n */\ntypedef struct _NV_ENC_LOCK_BITSTREAM\n{\n    uint32_t                version;                     /**< [in]: Struct version. Must be set to ::NV_ENC_LOCK_BITSTREAM_VER. */\n    uint32_t                doNotWait         : 1;       /**< [in]: If this flag is set, the NvEncodeAPI interface will return buffer pointer even if operation is not completed. If not set, the call will block until operation completes. */\n    uint32_t                ltrFrame          : 1;       /**< [out]: Flag indicating this frame is marked as LTR frame */\n    uint32_t                getRCStats        : 1;       /**< [in]: If this flag is set then lockBitstream call will add additional intra-inter MB count and average MVX, MVY */\n    uint32_t                reservedBitFields : 29;      /**< [in]: Reserved bit fields and must be set to 0 */\n    void                   *outputBitstream;             /**< [in]: Pointer to the bitstream buffer being locked. */\n    uint32_t               *sliceOffsets;                /**< [in, out]: Array which receives the slice offsets. This is not supported if NV_ENC_CONFIG_H264::sliceMode is 1 on Kepler GPUs. Array size must be equal to size of frame in MBs. */\n    uint32_t                frameIdx;                    /**< [out]: Frame no. for which the bitstream is being retrieved. */\n    uint32_t                hwEncodeStatus;              /**< [out]: The NvEncodeAPI interface status for the locked picture. */\n    uint32_t                numSlices;                   /**< [out]: Number of slices in the encoded picture. Will be reported only if NV_ENC_INITIALIZE_PARAMS::reportSliceOffsets set to 1. */\n    uint32_t                bitstreamSizeInBytes;        /**< [out]: Actual number of bytes generated and copied to the memory pointed by bitstreamBufferPtr.\n                                                                     When HEVC alpha layer encoding is enabled, this field reports the total encoded size in bytes i.e it is the encoded size of the base plus the alpha layer. */\n    uint64_t                outputTimeStamp;             /**< [out]: Presentation timestamp associated with the encoded output. */\n    uint64_t                outputDuration;              /**< [out]: Presentation duration associates with the encoded output. */\n    void                   *bitstreamBufferPtr;          /**< [out]: Pointer to the generated output bitstream.\n                                                                     For MEOnly mode _NV_ENC_LOCK_BITSTREAM::bitstreamBufferPtr should be typecast to\n                                                                     NV_ENC_H264_MV_DATA/NV_ENC_HEVC_MV_DATA pointer respectively for H264/HEVC  */\n    NV_ENC_PIC_TYPE         pictureType;                 /**< [out]: Picture type of the encoded picture. */\n    NV_ENC_PIC_STRUCT       pictureStruct;               /**< [out]: Structure of the generated output picture. */\n    uint32_t                frameAvgQP;                  /**< [out]: Average QP of the frame. */\n    uint32_t                frameSatd;                   /**< [out]: Total SATD cost for whole frame. */\n    uint32_t                ltrFrameIdx;                 /**< [out]: Frame index associated with this LTR frame. */\n    uint32_t                ltrFrameBitmap;              /**< [out]: Bitmap of LTR frames indices which were used for encoding this frame. Value of 0 if no LTR frames were used. */\n    uint32_t                temporalId;                  /**< [out]: TemporalId value of the frame when using temporalSVC encoding */\n    uint32_t                reserved[12];                /**< [in]:  Reserved and must be set to 0 */\n    uint32_t                intraMBCount;                /**< [out]: For H264, Number of Intra MBs in the encoded frame. For HEVC, Number of Intra CTBs in the encoded frame. Supported only if _NV_ENC_LOCK_BITSTREAM::getRCStats set to 1. */\n    uint32_t                interMBCount;                /**< [out]: For H264, Number of Inter MBs in the encoded frame, includes skip MBs. For HEVC, Number of Inter CTBs in the encoded frame. Supported only if _NV_ENC_LOCK_BITSTREAM::getRCStats set to 1. */\n    int32_t                 averageMVX;                  /**< [out]: Average Motion Vector in X direction for the encoded frame. Supported only if _NV_ENC_LOCK_BITSTREAM::getRCStats set to 1. */\n    int32_t                 averageMVY;                  /**< [out]: Average Motion Vector in y direction for the encoded frame. Supported only if _NV_ENC_LOCK_BITSTREAM::getRCStats set to 1. */\n    uint32_t                alphaLayerSizeInBytes;       /**< [out]: Number of bytes generated for the alpha layer in the encoded output. Applicable only when HEVC with alpha encoding is enabled. */\n\n    uint32_t                reserved1[218];              /**< [in]: Reserved and must be set to 0 */\n    void                   *reserved2[64];               /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_LOCK_BITSTREAM;\n\n/** Macro for constructing the version field of ::_NV_ENC_LOCK_BITSTREAM */\n#define NV_ENC_LOCK_BITSTREAM_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * \\struct _NV_ENC_LOCK_INPUT_BUFFER\n * Uncompressed Input Buffer lock parameters.\n */\ntypedef struct _NV_ENC_LOCK_INPUT_BUFFER\n{\n    uint32_t                  version;                   /**< [in]:  Struct version. Must be set to ::NV_ENC_LOCK_INPUT_BUFFER_VER. */\n    uint32_t                  doNotWait         : 1;     /**< [in]:  Set to 1 to make ::NvEncLockInputBuffer() a unblocking call. If the encoding is not completed, driver will return ::NV_ENC_ERR_ENCODER_BUSY error code. */\n    uint32_t                  reservedBitFields : 31;    /**< [in]:  Reserved bitfields and must be set to 0 */\n    NV_ENC_INPUT_PTR          inputBuffer;               /**< [in]:  Pointer to the input buffer to be locked, client should pass the pointer obtained from ::NvEncCreateInputBuffer() or ::NvEncMapInputResource API. */\n    void                     *bufferDataPtr;             /**< [out]: Pointed to the locked input buffer data. Client can only access input buffer using the \\p bufferDataPtr. */\n    uint32_t                  pitch;                     /**< [out]: Pitch of the locked input buffer. */\n    uint32_t                  reserved1[251];            /**< [in]:  Reserved and must be set to 0  */\n    void                     *reserved2[64];             /**< [in]:  Reserved and must be set to NULL  */\n} NV_ENC_LOCK_INPUT_BUFFER;\n\n/** Macro for constructing the version field of ::_NV_ENC_LOCK_INPUT_BUFFER */\n#define NV_ENC_LOCK_INPUT_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * \\struct _NV_ENC_MAP_INPUT_RESOURCE\n * Map an input resource to a Nvidia Encoder Input Buffer\n */\ntypedef struct _NV_ENC_MAP_INPUT_RESOURCE\n{\n    uint32_t                   version;                   /**< [in]:  Struct version. Must be set to ::NV_ENC_MAP_INPUT_RESOURCE_VER. */\n    uint32_t                   subResourceIndex;          /**< [in]:  Deprecated. Do not use. */\n    void                      *inputResource;             /**< [in]:  Deprecated. Do not use. */\n    NV_ENC_REGISTERED_PTR      registeredResource;        /**< [in]:  The Registered resource handle obtained by calling NvEncRegisterInputResource. */\n    NV_ENC_INPUT_PTR           mappedResource;            /**< [out]: Mapped pointer corresponding to the registeredResource. This pointer must be used in NV_ENC_PIC_PARAMS::inputBuffer parameter in ::NvEncEncodePicture() API. */\n    NV_ENC_BUFFER_FORMAT       mappedBufferFmt;           /**< [out]: Buffer format of the outputResource. This buffer format must be used in NV_ENC_PIC_PARAMS::bufferFmt if client using the above mapped resource pointer. */\n    uint32_t                   reserved1[251];            /**< [in]:  Reserved and must be set to 0. */\n    void                      *reserved2[63];             /**< [in]:  Reserved and must be set to NULL */\n} NV_ENC_MAP_INPUT_RESOURCE;\n\n/** Macro for constructing the version field of ::_NV_ENC_MAP_INPUT_RESOURCE */\n#define NV_ENC_MAP_INPUT_RESOURCE_VER NVENCAPI_STRUCT_VERSION(4)\n\n/**\n * \\struct _NV_ENC_INPUT_RESOURCE_OPENGL_TEX\n * NV_ENC_REGISTER_RESOURCE::resourceToRegister must be a pointer to a variable of this type,\n * when NV_ENC_REGISTER_RESOURCE::resourceType is NV_ENC_INPUT_RESOURCE_TYPE_OPENGL_TEX\n */\ntypedef struct _NV_ENC_INPUT_RESOURCE_OPENGL_TEX\n{\n    uint32_t texture;                                     /**< [in]: The name of the texture to be used. */\n    uint32_t target;                                      /**< [in]: Accepted values are GL_TEXTURE_RECTANGLE and GL_TEXTURE_2D. */\n} NV_ENC_INPUT_RESOURCE_OPENGL_TEX;\n\n/** \\struct NV_ENC_FENCE_POINT_D3D12\n  * Fence and fence value for synchronization.\n  */\ntypedef struct _NV_ENC_FENCE_POINT_D3D12\n{\n    void                   *pFence;                    /**< [in]: Pointer to ID3D12Fence. This fence object is used for synchronization. */\n    uint64_t                value;                     /**< [in]: Fence value to reach or exceed before the GPU operation or\n                                                                  fence value to set the fence to, after the GPU operation. */\n} NV_ENC_FENCE_POINT_D3D12;\n\n/**\n  * \\struct _NV_ENC_INPUT_RESOURCE_D3D12\n  * NV_ENC_PIC_PARAMS::inputBuffer and NV_ENC_PIC_PARAMS::alphaBuffer must be a pointer to a struct of this type,\n  * when D3D12 interface is used\n  */\ntypedef struct _NV_ENC_INPUT_RESOURCE_D3D12\n{\n    NV_ENC_REGISTERED_PTR       pInputBuffer;          /**< [in]: Specifies the input surface pointer. Client must use a pointer obtained from NvEncRegisterResource() in NV_ENC_REGISTER_RESOURCE::registeredResource\n                                                                  when registering input surface. */\n    NV_ENC_FENCE_POINT_D3D12    inputFencePoint;       /**< [in]: Specifies the input fence and corresponding fence value to do GPU wait.\n                                                                  This fence will be used to do GPU wait until the specified fence reaches or exceeds the specified value. */\n    uint32_t                    reserved1[16];         /**< [in]: Reserved and must be set to 0. */\n    void                       *reserved2[16];         /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_INPUT_RESOURCE_D3D12;\n\n/**\n  * \\struct _NV_ENC_OUTPUT_RESOURCE_D3D12\n  * NV_ENC_PIC_PARAMS::outputBitstream and NV_ENC_LOCK_BITSTREAM::outputBitstream must be a pointer to a struct of this type,\n  * when D3D12 interface is used\n  */\ntypedef struct _NV_ENC_OUTPUT_RESOURCE_D3D12\n{\n    NV_ENC_REGISTERED_PTR      pOutputBuffer;          /**< [in]: Specifies the output buffer pointer. Client must use a pointer obtained from NvEncRegisterResource() in NV_ENC_REGISTER_RESOURCE::registeredResource\n                                                                  when registering output bitstream buffer */\n    NV_ENC_FENCE_POINT_D3D12   outputFencePoint;       /**< [in]: Specifies the output fence and corresponding fence value to set after GPU operation is finished.*/\n    uint32_t                   reserved1[16];          /**< [in]: Reserved and must be set to 0. */\n    void                      *reserved2[16];          /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_OUTPUT_RESOURCE_D3D12;\n\n/**\n * \\struct _NV_ENC_REGISTER_RESOURCE\n * Register a resource for future use with the Nvidia Video Encoder Interface.\n */\ntypedef struct _NV_ENC_REGISTER_RESOURCE\n{\n    uint32_t                    version;                        /**< [in]: Struct version. Must be set to ::NV_ENC_REGISTER_RESOURCE_VER. */\n    NV_ENC_INPUT_RESOURCE_TYPE  resourceType;                   /**< [in]: Specifies the type of resource to be registered.\n                                                                           Supported values are\n                                                                           ::NV_ENC_INPUT_RESOURCE_TYPE_DIRECTX,\n                                                                           ::NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR,\n                                                                           ::NV_ENC_INPUT_RESOURCE_TYPE_OPENGL_TEX */\n    uint32_t                    width;                          /**< [in]: Input frame width. */\n    uint32_t                    height;                         /**< [in]: Input frame height. */\n    uint32_t                    pitch;                          /**< [in]: Input buffer pitch.\n                                                                           For ::NV_ENC_INPUT_RESOURCE_TYPE_DIRECTX resources, set this to 0.\n                                                                           For ::NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR resources, set this to\n                                                                             the pitch as obtained from cuMemAllocPitch(), or to the width in\n                                                                             bytes (if this resource was created by using cuMemAlloc()). This\n                                                                             value must be a multiple of 4.\n                                                                           For ::NV_ENC_INPUT_RESOURCE_TYPE_CUDAARRAY resources, set this to the\n                                                                             width of the allocation in bytes (i.e.\n                                                                             CUDA_ARRAY3D_DESCRIPTOR::Width * CUDA_ARRAY3D_DESCRIPTOR::NumChannels).\n                                                                           For ::NV_ENC_INPUT_RESOURCE_TYPE_OPENGL_TEX resources, set this to the\n                                                                             texture width multiplied by the number of components in the texture\n                                                                             format. */\n    uint32_t                    subResourceIndex;               /**< [in]: Subresource Index of the DirectX resource to be registered. Should be set to 0 for other interfaces. */\n    void                       *resourceToRegister;             /**< [in]: Handle to the resource that is being registered. */\n    NV_ENC_REGISTERED_PTR       registeredResource;             /**< [out]: Registered resource handle. This should be used in future interactions with the Nvidia Video Encoder Interface. */\n    NV_ENC_BUFFER_FORMAT        bufferFormat;                   /**< [in]: Buffer format of resource to be registered. */\n    NV_ENC_BUFFER_USAGE         bufferUsage;                    /**< [in]: Usage of resource to be registered. */\n    NV_ENC_FENCE_POINT_D3D12   *pInputFencePoint;               /**< [in]: Specifies the pointer to input fence and corresponding fence value to do GPU wait.\n                                                                           To be used only when NV_ENC_REGISTER_RESOURCE::resourceToRegister represents D3D12 surface and\n                                                                           NV_ENC_BUFFER_USAGE::bufferUsage is NV_ENC_INPUT_IMAGE.\n                                                                           This fence will be used to do GPU wait until the specified fence reaches or exceeds the specified value. */\n    NV_ENC_FENCE_POINT_D3D12   *pOutputFencePoint;              /**< [in]: Specifies the pointer to output fence and corresponding fence value to set after GPU operation is finished.\n                                                                           To be used only when NV_ENC_REGISTER_RESOURCE::resourceToRegister represents D3D12 surface and\n                                                                           NV_ENC_BUFFER_USAGE::bufferUsage is NV_ENC_INPUT_IMAGE. */\n    uint32_t                    reserved1[247];                 /**< [in]: Reserved and must be set to 0. */\n    void                       *reserved2[60];                  /**< [in]: Reserved and must be set to NULL. */\n} NV_ENC_REGISTER_RESOURCE;\n\n/** Macro for constructing the version field of ::_NV_ENC_REGISTER_RESOURCE */\n#define NV_ENC_REGISTER_RESOURCE_VER NVENCAPI_STRUCT_VERSION(3)\n\n/**\n * \\struct _NV_ENC_STAT\n * Encode Stats structure.\n */\ntypedef struct _NV_ENC_STAT\n{\n    uint32_t            version;                         /**< [in]:  Struct version. Must be set to ::NV_ENC_STAT_VER. */\n    uint32_t            reserved;                        /**< [in]:  Reserved and must be set to 0 */\n    NV_ENC_OUTPUT_PTR   outputBitStream;                 /**< [out]: Specifies the pointer to output bitstream. */\n    uint32_t            bitStreamSize;                   /**< [out]: Size of generated bitstream in bytes. */\n    uint32_t            picType;                         /**< [out]: Picture type of encoded picture. See ::NV_ENC_PIC_TYPE. */\n    uint32_t            lastValidByteOffset;             /**< [out]: Offset of last valid bytes of completed bitstream */\n    uint32_t            sliceOffsets[16];                /**< [out]: Offsets of each slice */\n    uint32_t            picIdx;                          /**< [out]: Picture number */\n    uint32_t            frameAvgQP;                      /**< [out]: Average QP of the frame. */\n    uint32_t            ltrFrame          : 1;           /**< [out]: Flag indicating this frame is marked as LTR frame */\n    uint32_t            reservedBitFields : 31;          /**< [in]:  Reserved bit fields and must be set to 0 */\n    uint32_t            ltrFrameIdx;                     /**< [out]: Frame index associated with this LTR frame. */\n    uint32_t            intraMBCount;                    /**< [out]: For H264, Number of Intra MBs in the encoded frame. For HEVC, Number of Intra CTBs in the encoded frame. */\n    uint32_t            interMBCount;                    /**< [out]: For H264, Number of Inter MBs in the encoded frame, includes skip MBs. For HEVC, Number of Inter CTBs in the encoded frame. */\n    int32_t             averageMVX;                      /**< [out]: Average Motion Vector in X direction for the encoded frame. */\n    int32_t             averageMVY;                      /**< [out]: Average Motion Vector in y direction for the encoded frame. */\n    uint32_t            reserved1[226];                  /**< [in]:  Reserved and must be set to 0 */\n    void               *reserved2[64];                   /**< [in]:  Reserved and must be set to NULL */\n} NV_ENC_STAT;\n\n/** Macro for constructing the version field of ::_NV_ENC_STAT */\n#define NV_ENC_STAT_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * \\struct _NV_ENC_SEQUENCE_PARAM_PAYLOAD\n * Sequence and picture paramaters payload.\n */\ntypedef struct _NV_ENC_SEQUENCE_PARAM_PAYLOAD\n{\n    uint32_t            version;                         /**< [in]:  Struct version. Must be set to ::NV_ENC_INITIALIZE_PARAMS_VER. */\n    uint32_t            inBufferSize;                    /**< [in]:  Specifies the size of the spsppsBuffer provided by the client */\n    uint32_t            spsId;                           /**< [in]:  Specifies the SPS id to be used in sequence header. Default value is 0.  */\n    uint32_t            ppsId;                           /**< [in]:  Specifies the PPS id to be used in picture header. Default value is 0.  */\n    void               *spsppsBuffer;                    /**< [in]:  Specifies bitstream header pointer of size NV_ENC_SEQUENCE_PARAM_PAYLOAD::inBufferSize.\n                                                                     It is the client's responsibility to manage this memory. */\n    uint32_t           *outSPSPPSPayloadSize;            /**< [out]: Size of the sequence and picture header in bytes. */\n    uint32_t            reserved [250];                  /**< [in]:  Reserved and must be set to 0 */\n    void               *reserved2[64];                   /**< [in]:  Reserved and must be set to NULL */\n} NV_ENC_SEQUENCE_PARAM_PAYLOAD;\n\n/** Macro for constructing the version field of ::_NV_ENC_SEQUENCE_PARAM_PAYLOAD */\n#define NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER NVENCAPI_STRUCT_VERSION(1)\n\n\n/**\n * Event registration/unregistration parameters.\n */\ntypedef struct _NV_ENC_EVENT_PARAMS\n{\n    uint32_t            version;                          /**< [in]: Struct version. Must be set to ::NV_ENC_EVENT_PARAMS_VER. */\n    uint32_t            reserved;                         /**< [in]: Reserved and must be set to 0 */\n    void               *completionEvent;                  /**< [in]: Handle to event to be registered/unregistered with the NvEncodeAPI interface. */\n    uint32_t            reserved1[253];                   /**< [in]: Reserved and must be set to 0    */\n    void               *reserved2[64];                    /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_EVENT_PARAMS;\n\n/** Macro for constructing the version field of ::_NV_ENC_EVENT_PARAMS */\n#define NV_ENC_EVENT_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)\n\n/**\n * Encoder Session Creation parameters\n */\ntypedef struct _NV_ENC_OPEN_ENCODE_SESSIONEX_PARAMS\n{\n    uint32_t            version;                          /**< [in]: Struct version. Must be set to ::NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER. */\n    NV_ENC_DEVICE_TYPE  deviceType;                       /**< [in]: Specified the device Type */\n    void               *device;                           /**< [in]: Pointer to client device. */\n    void               *reserved;                         /**< [in]: Reserved and must be set to 0. */\n    uint32_t            apiVersion;                       /**< [in]: API version. Should be set to NVENCAPI_VERSION. */\n    uint32_t            reserved1[253];                   /**< [in]: Reserved and must be set to 0    */\n    void               *reserved2[64];                    /**< [in]: Reserved and must be set to NULL */\n} NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS;\n/** Macro for constructing the version field of ::_NV_ENC_OPEN_ENCODE_SESSIONEX_PARAMS */\n#define NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)\n\n/** @} */ /* END ENCODER_STRUCTURE */\n\n\n/**\n * \\addtogroup ENCODE_FUNC NvEncodeAPI Functions\n * @{\n */\n\n// NvEncOpenEncodeSession\n/**\n * \\brief Opens an encoding session.\n *\n * Deprecated.\n *\n * \\return\n * ::NV_ENC_ERR_INVALID_CALL\\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncOpenEncodeSession                     (void *device, uint32_t deviceType, void **encoder);\n\n// NvEncGetEncodeGuidCount\n/**\n * \\brief Retrieves the number of supported encode GUIDs.\n *\n * The function returns the number of codec GUIDs supported by the NvEncodeAPI\n * interface.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [out] encodeGUIDCount\n *   Number of supported encode GUIDs.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeGUIDCount                    (void *encoder, uint32_t *encodeGUIDCount);\n\n\n// NvEncGetEncodeGUIDs\n/**\n * \\brief Retrieves an array of supported encoder codec GUIDs.\n *\n * The function returns an array of codec GUIDs supported by the NvEncodeAPI interface.\n * The client must allocate an array where the NvEncodeAPI interface can\n * fill the supported GUIDs and pass the pointer in \\p *GUIDs parameter.\n * The size of the array can be determined by using ::NvEncGetEncodeGUIDCount() API.\n * The Nvidia Encoding interface returns the number of codec GUIDs it has actually\n * filled in the GUID array in the \\p GUIDCount parameter.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] guidArraySize\n *   Number of GUIDs to retrieved. Should be set to the number retrieved using\n *   ::NvEncGetEncodeGUIDCount.\n * \\param [out] GUIDs\n *   Array of supported Encode GUIDs.\n * \\param [out] GUIDCount\n *   Number of supported Encode GUIDs.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeGUIDs                        (void *encoder, GUID *GUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);\n\n\n// NvEncGetEncodeProfileGuidCount\n/**\n * \\brief Retrieves the number of supported profile GUIDs.\n *\n * The function returns the number of profile GUIDs supported for a given codec.\n * The client must first enumerate the codec GUIDs supported by the NvEncodeAPI\n * interface. After determining the codec GUID, it can query the NvEncodeAPI\n * interface to determine the number of profile GUIDs supported for a particular\n * codec GUID.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   The codec GUID for which the profile GUIDs are being enumerated.\n * \\param [out] encodeProfileGUIDCount\n *   Number of encode profiles supported for the given encodeGUID.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeProfileGUIDCount                    (void *encoder, GUID encodeGUID, uint32_t *encodeProfileGUIDCount);\n\n\n// NvEncGetEncodeProfileGUIDs\n/**\n * \\brief Retrieves an array of supported encode profile GUIDs.\n *\n * The function returns an array of supported profile GUIDs for a particular\n * codec GUID. The client must allocate an array where the NvEncodeAPI interface\n * can populate the profile GUIDs. The client can determine the array size using\n * ::NvEncGetEncodeProfileGUIDCount() API. The client must also validiate that the\n * NvEncodeAPI interface supports the GUID the client wants to pass as \\p encodeGUID\n * parameter.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   The encode GUID whose profile GUIDs are being enumerated.\n * \\param [in] guidArraySize\n *   Number of GUIDs to be retrieved. Should be set to the number retrieved using\n *   ::NvEncGetEncodeProfileGUIDCount.\n * \\param [out] profileGUIDs\n *   Array of supported Encode Profile GUIDs\n * \\param [out] GUIDCount\n *   Number of valid encode profile GUIDs in \\p profileGUIDs array.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeProfileGUIDs                               (void *encoder, GUID encodeGUID, GUID *profileGUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);\n\n// NvEncGetInputFormatCount\n/**\n * \\brief Retrieve the number of supported Input formats.\n *\n * The function returns the number of supported input formats. The client must\n * query the NvEncodeAPI interface to determine the supported input formats\n * before creating the input surfaces.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the number of supported input formats\n *   is to be retrieved.\n * \\param [out] inputFmtCount\n *   Number of input formats supported for specified Encode GUID.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncGetInputFormatCount                   (void *encoder, GUID encodeGUID, uint32_t *inputFmtCount);\n\n\n// NvEncGetInputFormats\n/**\n * \\brief Retrieves an array of supported Input formats\n *\n * Returns an array of supported input formats  The client must use the input\n * format to create input surface using ::NvEncCreateInputBuffer() API.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the number of supported input formats\n *   is to be retrieved.\n *\\param [in] inputFmtArraySize\n *   Size input format count array passed in \\p inputFmts.\n *\\param [out] inputFmts\n *   Array of input formats supported for this Encode GUID.\n *\\param [out] inputFmtCount\n *   The number of valid input format types returned by the NvEncodeAPI\n *   interface in \\p inputFmts array.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetInputFormats                       (void *encoder, GUID encodeGUID, NV_ENC_BUFFER_FORMAT *inputFmts, uint32_t inputFmtArraySize, uint32_t *inputFmtCount);\n\n\n// NvEncGetEncodeCaps\n/**\n * \\brief Retrieves the capability value for a specified encoder attribute.\n *\n * The function returns the capability value for a given encoder attribute. The\n * client must validate the encodeGUID using ::NvEncGetEncodeGUIDs() API before\n * calling this function. The encoder attribute being queried are enumerated in\n * ::NV_ENC_CAPS_PARAM enum.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the capability attribute is to be retrieved.\n * \\param [in] capsParam\n *   Used to specify attribute being queried. Refer ::NV_ENC_CAPS_PARAM for  more\n * details.\n * \\param [out] capsVal\n *   The value corresponding to the capability attribute being queried.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeCaps                     (void *encoder, GUID encodeGUID, NV_ENC_CAPS_PARAM *capsParam, int *capsVal);\n\n\n// NvEncGetEncodePresetCount\n/**\n * \\brief Retrieves the number of supported preset GUIDs.\n *\n * The function returns the number of preset GUIDs available for a given codec.\n * The client must validate the codec GUID using ::NvEncGetEncodeGUIDs() API\n * before calling this function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the number of supported presets is to\n *   be retrieved.\n * \\param [out] encodePresetGUIDCount\n *   Receives the number of supported preset GUIDs.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodePresetCount              (void *encoder, GUID encodeGUID, uint32_t *encodePresetGUIDCount);\n\n\n// NvEncGetEncodePresetGUIDs\n/**\n * \\brief Receives an array of supported encoder preset GUIDs.\n *\n * The function returns an array of encode preset GUIDs available for a given codec.\n * The client can directly use one of the preset GUIDs based upon the use case\n * or target device. The preset GUID chosen can be directly used in\n * NV_ENC_INITIALIZE_PARAMS::presetGUID parameter to ::NvEncEncodePicture() API.\n * Alternately client can  also use the preset GUID to retrieve the encoding config\n * parameters being used by NvEncodeAPI interface for that given preset, using\n * ::NvEncGetEncodePresetConfig() API. It can then modify preset config parameters\n * as per its use case and send it to NvEncodeAPI interface as part of\n * NV_ENC_INITIALIZE_PARAMS::encodeConfig parameter for NvEncInitializeEncoder()\n * API.\n *\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the list of supported presets is to be\n *   retrieved.\n * \\param [in] guidArraySize\n *   Size of array of preset GUIDs passed in \\p preset GUIDs\n * \\param [out] presetGUIDs\n *   Array of supported Encode preset GUIDs from the NvEncodeAPI interface\n *   to client.\n * \\param [out] encodePresetGUIDCount\n *   Receives the number of preset GUIDs returned by the NvEncodeAPI\n *   interface.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodePresetGUIDs                  (void *encoder, GUID encodeGUID, GUID *presetGUIDs, uint32_t guidArraySize, uint32_t *encodePresetGUIDCount);\n\n\n// NvEncGetEncodePresetConfig\n/**\n * \\brief Returns a preset config structure supported for given preset GUID.\n *\n * The function returns a preset config structure for a given preset GUID. Before\n * using this function the client must enumerate the preset GUIDs available for\n * a given codec. The preset config structure can be modified by the client depending\n * upon its use case and can be then used to initialize the encoder using\n * ::NvEncInitializeEncoder() API. The client can use this function only if it\n * wants to modify the NvEncodeAPI preset configuration, otherwise it can\n * directly use the preset GUID.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the list of supported presets is to be\n *   retrieved.\n * \\param [in] presetGUID\n *   Preset GUID, corresponding to which the Encoding configurations is to be\n *   retrieved.\n * \\param [out] presetConfig\n *   The requested Preset Encoder Attribute set. Refer ::_NV_ENC_CONFIG for\n*    more details.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodePresetConfig               (void *encoder, GUID encodeGUID, GUID  presetGUID, NV_ENC_PRESET_CONFIG *presetConfig);\n\n// NvEncGetEncodePresetConfigEx\n/**\n * \\brief Returns a preset config structure supported for given preset GUID.\n *\n * The function returns a preset config structure for a given preset GUID and tuning info.\n * NvEncGetEncodePresetConfigEx() API is not applicable to H264 and HEVC meonly mode.\n * Before using this function the client must enumerate the preset GUIDs available for\n * a given codec. The preset config structure can be modified by the client depending\n * upon its use case and can be then used to initialize the encoder using\n * ::NvEncInitializeEncoder() API. The client can use this function only if it\n * wants to modify the NvEncodeAPI preset configuration, otherwise it can\n * directly use the preset GUID.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encodeGUID\n *   Encode GUID, corresponding to which the list of supported presets is to be\n *   retrieved.\n * \\param [in] presetGUID\n *   Preset GUID, corresponding to which the Encoding configurations is to be\n *   retrieved.\n * \\param [in] tuningInfo\n *   tuning info, corresponding to which the Encoding configurations is to be\n *   retrieved.\n * \\param [out] presetConfig\n *   The requested Preset Encoder Attribute set. Refer ::_NV_ENC_CONFIG for\n *    more details.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodePresetConfigEx               (void *encoder, GUID encodeGUID, GUID  presetGUID, NV_ENC_TUNING_INFO tuningInfo, NV_ENC_PRESET_CONFIG *presetConfig);\n\n// NvEncInitializeEncoder\n/**\n * \\brief Initialize the encoder.\n *\n * This API must be used to initialize the encoder. The initialization parameter\n * is passed using \\p *createEncodeParams  The client must send the following\n * fields of the _NV_ENC_INITIALIZE_PARAMS structure with a valid value.\n * - NV_ENC_INITIALIZE_PARAMS::encodeGUID\n * - NV_ENC_INITIALIZE_PARAMS::encodeWidth\n * - NV_ENC_INITIALIZE_PARAMS::encodeHeight\n *\n * The client can pass a preset GUID directly to the NvEncodeAPI interface using\n * NV_ENC_INITIALIZE_PARAMS::presetGUID field. If the client doesn't pass\n * NV_ENC_INITIALIZE_PARAMS::encodeConfig structure, the codec specific parameters\n * will be selected based on the preset GUID. The preset GUID must have been\n * validated by the client using ::NvEncGetEncodePresetGUIDs() API.\n * If the client passes a custom ::_NV_ENC_CONFIG structure through\n * NV_ENC_INITIALIZE_PARAMS::encodeConfig , it will override the codec specific parameters\n * based on the preset GUID. It is recommended that even if the client passes a custom config,\n * it should also send a preset GUID. In this case, the preset GUID passed by the client\n * will not override any of the custom config parameters programmed by the client,\n * it is only used as a hint by the NvEncodeAPI interface to determine certain encoder parameters\n * which are not exposed to the client.\n *\n * There are two modes of operation for the encoder namely:\n * - Asynchronous mode\n * - Synchronous mode\n *\n * The client can select asynchronous or synchronous mode by setting the \\p\n * enableEncodeAsync field in ::_NV_ENC_INITIALIZE_PARAMS to 1 or 0 respectively.\n *\\par Asynchronous mode of operation:\n * The Asynchronous mode can be enabled by setting NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync to 1.\n * The client operating in asynchronous mode must allocate completion event object\n * for each output buffer and pass the completion event object in the\n * ::NvEncEncodePicture() API. The client can create another thread and wait on\n * the event object to be signaled by NvEncodeAPI interface on completion of the\n * encoding process for the output frame. This should unblock the main thread from\n * submitting work to the encoder. When the event is signaled the client can call\n * NvEncodeAPI interfaces to copy the bitstream data using ::NvEncLockBitstream()\n * API. This is the preferred mode of operation.\n *\n * NOTE: Asynchronous mode is not supported on Linux.\n *\n *\\par Synchronous mode of operation:\n * The client can select synchronous mode by setting NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync to 0.\n * The client working in synchronous mode can work in a single threaded or multi\n * threaded mode. The client need not allocate any event objects. The client can\n * only lock the bitstream data after NvEncodeAPI interface has returned\n * ::NV_ENC_SUCCESS from encode picture. The NvEncodeAPI interface can return\n * ::NV_ENC_ERR_NEED_MORE_INPUT error code from ::NvEncEncodePicture() API. The\n * client must not lock the output buffer in such case but should send the next\n * frame for encoding. The client must keep on calling ::NvEncEncodePicture() API\n * until it returns ::NV_ENC_SUCCESS. \\n\n * The client must always lock the bitstream data in order in which it has submitted.\n * This is true for both asynchronous and synchronous mode.\n *\n *\\par Picture type decision:\n * If the client is taking the picture type decision and it must disable the picture\n * type decision module in NvEncodeAPI by setting NV_ENC_INITIALIZE_PARAMS::enablePTD\n * to 0. In this case the client is  required to send the picture in encoding\n * order to NvEncodeAPI by doing the re-ordering for B frames. \\n\n * If the client doesn't want to take the picture type decision it can enable\n * picture type decision module in the NvEncodeAPI interface by setting\n * NV_ENC_INITIALIZE_PARAMS::enablePTD to 1 and send the input pictures in display\n * order.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] createEncodeParams\n *   Refer ::_NV_ENC_INITIALIZE_PARAMS for details.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncInitializeEncoder                     (void *encoder, NV_ENC_INITIALIZE_PARAMS *createEncodeParams);\n\n\n// NvEncCreateInputBuffer\n/**\n * \\brief Allocates Input buffer.\n *\n * This function is used to allocate an input buffer. The client must enumerate\n * the input buffer format before allocating the input buffer resources. The\n * NV_ENC_INPUT_PTR returned by the NvEncodeAPI interface in the\n * NV_ENC_CREATE_INPUT_BUFFER::inputBuffer field can be directly used in\n * ::NvEncEncodePicture() API. The number of input buffers to be allocated by the\n * client must be at least 4 more than the number of B frames being used for encoding.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] createInputBufferParams\n *  Pointer to the ::NV_ENC_CREATE_INPUT_BUFFER structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncCreateInputBuffer                     (void *encoder, NV_ENC_CREATE_INPUT_BUFFER *createInputBufferParams);\n\n\n// NvEncDestroyInputBuffer\n/**\n * \\brief Release an input buffers.\n *\n * This function is used to free an input buffer. If the client has allocated\n * any input buffer using ::NvEncCreateInputBuffer() API, it must free those\n * input buffers by calling this function. The client must release the input\n * buffers before destroying the encoder using ::NvEncDestroyEncoder() API.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] inputBuffer\n *   Pointer to the input buffer to be released.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncDestroyInputBuffer                    (void *encoder, NV_ENC_INPUT_PTR inputBuffer);\n\n// NvEncSetIOCudaStreams\n/**\n * \\brief Set input and output CUDA stream for specified encoder attribute.\n *\n * Encoding may involve CUDA pre-processing on the input and post-processing on encoded output.\n * This function is used to set input and output CUDA streams to pipeline the CUDA pre-processing\n * and post-processing tasks. Clients should call this function before the call to\n * NvEncUnlockInputBuffer(). If this function is not called, the default CUDA stream is used for\n * input and output processing. After a successful call to this function, the streams specified\n * in that call will replace the previously-used streams.\n * This API is supported for NVCUVID interface only.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] inputStream\n *   Pointer to CUstream which is used to process ::NV_ENC_PIC_PARAMS::inputFrame for encode.\n *   In case of ME-only mode, inputStream is used to process ::NV_ENC_MEONLY_PARAMS::inputBuffer and\n *   ::NV_ENC_MEONLY_PARAMS::referenceFrame\n * \\param [in] outputStream\n *  Pointer to CUstream which is used to process ::NV_ENC_PIC_PARAMS::outputBuffer for encode.\n *  In case of ME-only mode, outputStream is used to process ::NV_ENC_MEONLY_PARAMS::mvBuffer\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncSetIOCudaStreams                     (void *encoder, NV_ENC_CUSTREAM_PTR inputStream, NV_ENC_CUSTREAM_PTR outputStream);\n\n\n// NvEncCreateBitstreamBuffer\n/**\n * \\brief Allocates an output bitstream buffer\n *\n * This function is used to allocate an output bitstream buffer and returns a\n * NV_ENC_OUTPUT_PTR to bitstream  buffer to the client in the\n * NV_ENC_CREATE_BITSTREAM_BUFFER::bitstreamBuffer field.\n * The client can only call this function after the encoder session has been\n * initialized using ::NvEncInitializeEncoder() API. The minimum number of output\n * buffers allocated by the client must be at least 4 more than the number of B\n * B frames being used for encoding. The client can only access the output\n * bitstream data by locking the \\p bitstreamBuffer using the ::NvEncLockBitstream()\n * function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] createBitstreamBufferParams\n *   Pointer ::NV_ENC_CREATE_BITSTREAM_BUFFER for details.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncCreateBitstreamBuffer                 (void *encoder, NV_ENC_CREATE_BITSTREAM_BUFFER *createBitstreamBufferParams);\n\n\n// NvEncDestroyBitstreamBuffer\n/**\n * \\brief Release a bitstream buffer.\n *\n * This function is used to release the output bitstream buffer allocated using\n * the ::NvEncCreateBitstreamBuffer() function. The client must release the output\n * bitstreamBuffer using this function before destroying the encoder session.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] bitstreamBuffer\n *   Pointer to the bitstream buffer being released.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncDestroyBitstreamBuffer                (void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);\n\n// NvEncEncodePicture\n/**\n * \\brief Submit an input picture for encoding.\n *\n * This function is used to submit an input picture buffer for encoding. The\n * encoding parameters are passed using \\p *encodePicParams which is a pointer\n * to the ::_NV_ENC_PIC_PARAMS structure.\n *\n * If the client has set NV_ENC_INITIALIZE_PARAMS::enablePTD to 0, then it must\n * send a valid value for the following fields.\n * - NV_ENC_PIC_PARAMS::pictureType\n * - NV_ENC_PIC_PARAMS_H264::displayPOCSyntax (H264 only)\n * - NV_ENC_PIC_PARAMS_H264::frameNumSyntax(H264 only)\n * - NV_ENC_PIC_PARAMS_H264::refPicFlag(H264 only)\n *\n *\\par MVC Encoding:\n * For MVC encoding the client must call encode picture API for each view separately\n * and must pass valid view id in NV_ENC_PIC_PARAMS_MVC::viewID field. Currently\n * NvEncodeAPI only support stereo MVC so client must send viewID as 0 for base\n * view and view ID as 1 for dependent view.\n *\n *\\par Asynchronous Encoding\n * If the client has enabled asynchronous mode of encoding by setting\n * NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync to 1 in the ::NvEncInitializeEncoder()\n * API ,then the client must send a valid NV_ENC_PIC_PARAMS::completionEvent.\n * Incase of asynchronous mode of operation, client can queue the ::NvEncEncodePicture()\n * API commands from the main thread and then queue output buffers to be processed\n * to a secondary worker thread. Before the locking the output buffers in the\n * secondary thread , the client must wait on NV_ENC_PIC_PARAMS::completionEvent\n * it has queued in ::NvEncEncodePicture() API call. The client must always process\n * completion event and the output buffer in the same order in which they have been\n * submitted for encoding. The NvEncodeAPI interface is responsible for any\n * re-ordering required for B frames and will always ensure that encoded bitstream\n * data is written in the same order in which output buffer is submitted.\n * The NvEncodeAPI interface may return ::NV_ENC_ERR_NEED_MORE_INPUT error code for\n * some ::NvEncEncodePicture() API calls but the client must not treat it as a fatal error.\n * The NvEncodeAPI interface might not be able to submit an input picture buffer for encoding\n * immediately due to re-ordering for B frames.\n *\\code\n  The below example shows how  asynchronous encoding in case of 1 B frames\n  ------------------------------------------------------------------------\n  Suppose the client allocated 4 input buffers(I1,I2..), 4 output buffers(O1,O2..)\n  and 4 completion events(E1, E2, ...). The NvEncodeAPI interface will need to\n  keep a copy of the input buffers for re-ordering and it allocates following\n  internal buffers (NvI1, NvI2...). These internal buffers are managed by NvEncodeAPI\n  and the client is not responsible for the allocating or freeing the memory of\n  the internal buffers.\n\n  a) The client main thread will queue the following encode frame calls.\n  Note the picture type is unknown to the client, the decision is being taken by\n  NvEncodeAPI interface. The client should pass ::_NV_ENC_PIC_PARAMS parameter\n  consisting of allocated input buffer, output buffer and output events in successive\n  ::NvEncEncodePicture() API calls along with other required encode picture params.\n  For example:\n  1st EncodePicture parameters - (I1, O1, E1)\n  2nd EncodePicture parameters - (I2, O2, E2)\n  3rd EncodePicture parameters - (I3, O3, E3)\n\n  b) NvEncodeAPI SW will receive the following encode Commands from the client.\n  The left side shows input from client in the form (Input buffer, Output Buffer,\n  Output Event). The right hand side shows a possible picture type decision take by\n  the NvEncodeAPI interface.\n  (I1, O1, E1)    ---P1 Frame\n  (I2, O2, E2)    ---B2 Frame\n  (I3, O3, E3)    ---P3 Frame\n\n  c) NvEncodeAPI interface will make a copy of the input buffers to its internal\n   buffers for re-ordering. These copies are done as part of nvEncEncodePicture\n   function call from the client and NvEncodeAPI interface is responsible for\n   synchronization of copy operation with the actual encoding operation.\n   I1 --> NvI1\n   I2 --> NvI2\n   I3 --> NvI3\n\n   d) The NvEncodeAPI encodes I1 as P frame and submits I1 to encoder HW and returns ::NV_ENC_SUCCESS.\n   The NvEncodeAPI tries to encode I2 as B frame and fails with ::NV_ENC_ERR_NEED_MORE_INPUT error code.\n   The error is not fatal and it notifies client that I2 is not submitted to encoder immediately.\n   The NvEncodeAPI encodes I3 as P frame and submits I3 for encoding which will be used as  backward\n   reference frame for I2. The NvEncodeAPI then submits I2 for encoding and returns ::NV_ENC_SUCESS.\n   Both the submission are part of the same ::NvEncEncodePicture() function call.\n\n  e) After returning from ::NvEncEncodePicture() call , the client must queue the output\n   bitstream  processing work to the secondary thread. The output bitstream processing\n   for asynchronous mode consist of first waiting on completion event(E1, E2..)\n   and then locking the output bitstream buffer(O1, O2..) for reading the encoded\n   data. The work queued to the secondary thread by the client is in the following order\n   (I1, O1, E1)\n   (I2, O2, E2)\n   (I3, O3, E3)\n   Note they are in the same order in which client calls ::NvEncEncodePicture() API\n   in \\p step a).\n\n  f) NvEncodeAPI interface  will do the re-ordering such that Encoder HW will receive\n  the following encode commands:\n  (NvI1, O1, E1)   ---P1 Frame\n  (NvI3, O2, E2)   ---P3 Frame\n  (NvI2, O3, E3)   ---B2 frame\n\n  g) After the encoding operations are completed, the events will be signaled\n  by NvEncodeAPI interface in the following order :\n  (O1, E1) ---P1 Frame ,output bitstream copied to O1 and event E1 signaled.\n  (O2, E2) ---P3 Frame ,output bitstream copied to O2 and event E2 signaled.\n  (O3, E3) ---B2 Frame ,output bitstream copied to O3 and event E3 signaled.\n\n  h) The client must lock the bitstream data using ::NvEncLockBitstream() API in\n   the order O1,O2,O3  to read the encoded data, after waiting for the events\n   to be signaled in the same order i.e E1, E2 and E3.The output processing is\n   done in the secondary thread in the following order:\n   Waits on E1, copies encoded bitstream from O1\n   Waits on E2, copies encoded bitstream from O2\n   Waits on E3, copies encoded bitstream from O3\n\n  -Note the client will receive the events signaling and output buffer in the\n   same order in which they have submitted for encoding.\n  -Note the LockBitstream will have picture type field which will notify the\n   output picture type to the clients.\n  -Note the input, output buffer and the output completion event are free to be\n   reused once NvEncodeAPI interfaced has signaled the event and the client has\n   copied the data from the output buffer.\n\n * \\endcode\n *\n *\\par Synchronous Encoding\n * The client can enable synchronous mode of encoding by setting\n * NV_ENC_INITIALIZE_PARAMS::enableEncodeAsync to 0 in ::NvEncInitializeEncoder() API.\n * The NvEncodeAPI interface may return ::NV_ENC_ERR_NEED_MORE_INPUT error code for\n * some ::NvEncEncodePicture() API calls when NV_ENC_INITIALIZE_PARAMS::enablePTD\n * is set to 1, but the client must not treat it as a fatal error. The NvEncodeAPI\n * interface might not be able to submit an input picture buffer for encoding\n * immediately due to re-ordering for B frames. The NvEncodeAPI interface cannot\n * submit the input picture which is decided to be encoded as B frame as it waits\n * for backward reference from  temporally subsequent frames. This input picture\n * is buffered internally and waits for more input picture to arrive. The client\n * must not call ::NvEncLockBitstream() API on the output buffers whose\n * ::NvEncEncodePicture() API returns ::NV_ENC_ERR_NEED_MORE_INPUT. The client must\n * wait for the NvEncodeAPI interface to return ::NV_ENC_SUCCESS before locking the\n * output bitstreams to read the encoded bitstream data. The following example\n * explains the scenario with synchronous encoding with 2 B frames.\n *\\code\n The below example shows how  synchronous encoding works in case of 1 B frames\n -----------------------------------------------------------------------------\n Suppose the client allocated 4 input buffers(I1,I2..), 4 output buffers(O1,O2..)\n and 4 completion events(E1, E2, ...). The NvEncodeAPI interface will need to\n keep a copy of the input buffers for re-ordering and it allocates following\n internal buffers (NvI1, NvI2...). These internal buffers are managed by NvEncodeAPI\n and the client is not responsible for the allocating or freeing the memory of\n the internal buffers.\n\n The client calls ::NvEncEncodePicture() API with input buffer I1 and output buffer O1.\n The NvEncodeAPI decides to encode I1 as P frame and submits it to encoder\n HW and returns ::NV_ENC_SUCCESS.\n The client can now read the encoded data by locking the output O1 by calling\n NvEncLockBitstream API.\n\n The client calls ::NvEncEncodePicture() API with input buffer I2 and output buffer O2.\n The NvEncodeAPI decides to encode I2 as B frame and buffers I2 by copying it\n to internal buffer and returns ::NV_ENC_ERR_NEED_MORE_INPUT.\n The error is not fatal and it notifies client that it cannot read the encoded\n data by locking the output O2 by calling ::NvEncLockBitstream() API without submitting\n more work to the NvEncodeAPI interface.\n\n The client calls ::NvEncEncodePicture() with input buffer I3 and output buffer O3.\n The NvEncodeAPI decides to encode I3 as P frame and it first submits I3 for\n encoding which will be used as backward reference frame for I2.\n The NvEncodeAPI then submits I2 for encoding and returns ::NV_ENC_SUCESS. Both\n the submission are part of the same ::NvEncEncodePicture() function call.\n The client can now read the encoded data for both the frames by locking the output\n O2 followed by  O3 ,by calling ::NvEncLockBitstream() API.\n\n The client must always lock the output in the same order in which it has submitted\n to receive the encoded bitstream in correct encoding order.\n\n * \\endcode\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] encodePicParams\n *   Pointer to the ::_NV_ENC_PIC_PARAMS structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_ENCODER_BUSY \\n\n * ::NV_ENC_ERR_NEED_MORE_INPUT \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncEncodePicture                         (void *encoder, NV_ENC_PIC_PARAMS *encodePicParams);\n\n\n// NvEncLockBitstream\n/**\n * \\brief Lock output bitstream buffer\n *\n * This function is used to lock the bitstream buffer to read the encoded data.\n * The client can only access the encoded data by calling this function.\n * The pointer to client accessible encoded data is returned in the\n * NV_ENC_LOCK_BITSTREAM::bitstreamBufferPtr field. The size of the encoded data\n * in the output buffer is returned in the NV_ENC_LOCK_BITSTREAM::bitstreamSizeInBytes\n * The NvEncodeAPI interface also returns the output picture type and picture structure\n * of the encoded frame in NV_ENC_LOCK_BITSTREAM::pictureType and\n * NV_ENC_LOCK_BITSTREAM::pictureStruct fields respectively. If the client has\n * set NV_ENC_LOCK_BITSTREAM::doNotWait to 1, the function might return\n * ::NV_ENC_ERR_LOCK_BUSY if client is operating in synchronous mode. This is not\n * a fatal failure if NV_ENC_LOCK_BITSTREAM::doNotWait is set to 1. In the above case the client can\n * retry the function after few milliseconds.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] lockBitstreamBufferParams\n *   Pointer to the ::_NV_ENC_LOCK_BITSTREAM structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_LOCK_BUSY \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncLockBitstream                         (void *encoder, NV_ENC_LOCK_BITSTREAM *lockBitstreamBufferParams);\n\n\n// NvEncUnlockBitstream\n/**\n * \\brief Unlock the output bitstream buffer\n *\n * This function is used to unlock the output bitstream buffer after the client\n * has read the encoded data from output buffer. The client must call this function\n * to unlock the output buffer which it has previously locked using ::NvEncLockBitstream()\n * function. Using a locked bitstream buffer in ::NvEncEncodePicture() API will cause\n * the function to fail.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] bitstreamBuffer\n *   bitstream buffer pointer being unlocked\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnlockBitstream                       (void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);\n\n\n// NvLockInputBuffer\n/**\n * \\brief Locks an input buffer\n *\n * This function is used to lock the input buffer to load the uncompressed YUV\n * pixel data into input buffer memory. The client must pass the NV_ENC_INPUT_PTR\n * it had previously allocated using ::NvEncCreateInputBuffer()in the\n * NV_ENC_LOCK_INPUT_BUFFER::inputBuffer field.\n * The NvEncodeAPI interface returns pointer to client accessible input buffer\n * memory in NV_ENC_LOCK_INPUT_BUFFER::bufferDataPtr field.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] lockInputBufferParams\n *   Pointer to the ::_NV_ENC_LOCK_INPUT_BUFFER structure\n *\n * \\return\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_LOCK_BUSY \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncLockInputBuffer                      (void *encoder, NV_ENC_LOCK_INPUT_BUFFER *lockInputBufferParams);\n\n\n// NvUnlockInputBuffer\n/**\n * \\brief Unlocks the input buffer\n *\n * This function is used to unlock the input buffer memory previously locked for\n * uploading YUV pixel data. The input buffer must be unlocked before being used\n * again for encoding, otherwise NvEncodeAPI will fail the ::NvEncEncodePicture()\n *\n  * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] inputBuffer\n *   Pointer to the input buffer that is being unlocked.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnlockInputBuffer                     (void *encoder, NV_ENC_INPUT_PTR inputBuffer);\n\n\n// NvEncGetEncodeStats\n/**\n * \\brief Get encoding statistics.\n *\n * This function is used to retrieve the encoding statistics.\n * This API is not supported when encode device type is CUDA.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] encodeStats\n *   Pointer to the ::_NV_ENC_STAT structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetEncodeStats                        (void *encoder, NV_ENC_STAT *encodeStats);\n\n\n// NvEncGetSequenceParams\n/**\n * \\brief Get encoded sequence and picture header.\n *\n * This function can be used to retrieve the sequence and picture header out of\n * band. The client must call this function only after the encoder has been\n * initialized using ::NvEncInitializeEncoder() function. The client must\n * allocate the memory where the NvEncodeAPI interface can copy the bitstream\n * header and pass the pointer to the memory in NV_ENC_SEQUENCE_PARAM_PAYLOAD::spsppsBuffer.\n * The size of buffer is passed in the field  NV_ENC_SEQUENCE_PARAM_PAYLOAD::inBufferSize.\n * The NvEncodeAPI interface will copy the bitstream header payload and returns\n * the actual size of the bitstream header in the field\n * NV_ENC_SEQUENCE_PARAM_PAYLOAD::outSPSPPSPayloadSize.\n * The client must call  ::NvEncGetSequenceParams() function from the same thread which is\n * being used to call ::NvEncEncodePicture() function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] sequenceParamPayload\n *   Pointer to the ::_NV_ENC_SEQUENCE_PARAM_PAYLOAD structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetSequenceParams                     (void *encoder, NV_ENC_SEQUENCE_PARAM_PAYLOAD *sequenceParamPayload);\n\n// NvEncGetSequenceParamEx\n/**\n * \\brief Get sequence and picture header.\n *\n * This function can be used to retrieve the sequence and picture header out of band, even when\n * encoder has not been initialized using ::NvEncInitializeEncoder() function.\n * The client must allocate the memory where the NvEncodeAPI interface can copy the bitstream\n * header and pass the pointer to the memory in NV_ENC_SEQUENCE_PARAM_PAYLOAD::spsppsBuffer.\n * The size of buffer is passed in the field  NV_ENC_SEQUENCE_PARAM_PAYLOAD::inBufferSize.\n * If encoder has not been initialized using ::NvEncInitializeEncoder() function, client must\n * send NV_ENC_INITIALIZE_PARAMS as input. The NV_ENC_INITIALIZE_PARAMS passed must be same as the\n * one which will be used for initializing encoder using ::NvEncInitializeEncoder() function later.\n * If encoder is already initialized using ::NvEncInitializeEncoder() function, the provided\n * NV_ENC_INITIALIZE_PARAMS structure is ignored. The NvEncodeAPI interface will copy the bitstream\n * header payload and returns the actual size of the bitstream header in the field\n * NV_ENC_SEQUENCE_PARAM_PAYLOAD::outSPSPPSPayloadSize. The client must call  ::NvEncGetSequenceParamsEx()\n * function from the same thread which is being used to call ::NvEncEncodePicture() function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] encInitParams\n *   Pointer to the _NV_ENC_INITIALIZE_PARAMS structure.\n * \\param [in,out] sequenceParamPayload\n *   Pointer to the ::_NV_ENC_SEQUENCE_PARAM_PAYLOAD structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncGetSequenceParamEx                     (void *encoder, NV_ENC_INITIALIZE_PARAMS *encInitParams, NV_ENC_SEQUENCE_PARAM_PAYLOAD *sequenceParamPayload);\n\n// NvEncRegisterAsyncEvent\n/**\n * \\brief Register event for notification to encoding completion.\n *\n * This function is used to register the completion event with NvEncodeAPI\n * interface. The event is required when the client has configured the encoder to\n * work in asynchronous mode. In this mode the client needs to send a completion\n * event with every output buffer. The NvEncodeAPI interface will signal the\n * completion of the encoding process using this event. Only after the event is\n * signaled the client can get the encoded data using ::NvEncLockBitstream() function.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] eventParams\n *   Pointer to the ::_NV_ENC_EVENT_PARAMS structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncRegisterAsyncEvent                    (void *encoder, NV_ENC_EVENT_PARAMS *eventParams);\n\n\n// NvEncUnregisterAsyncEvent\n/**\n * \\brief Unregister completion event.\n *\n * This function is used to unregister completion event which has been previously\n * registered using ::NvEncRegisterAsyncEvent() function. The client must unregister\n * all events before destroying the encoder using ::NvEncDestroyEncoder() function.\n *\n  * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] eventParams\n *   Pointer to the ::_NV_ENC_EVENT_PARAMS structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnregisterAsyncEvent                  (void *encoder, NV_ENC_EVENT_PARAMS *eventParams);\n\n\n// NvEncMapInputResource\n/**\n * \\brief Map an externally created input resource pointer for encoding.\n *\n * Maps an externally allocated input resource [using and returns a NV_ENC_INPUT_PTR\n * which can be used for encoding in the ::NvEncEncodePicture() function. The\n * mapped resource is returned in the field NV_ENC_MAP_INPUT_RESOURCE::outputResourcePtr.\n * The NvEncodeAPI interface also returns the buffer format of the mapped resource\n * in the field NV_ENC_MAP_INPUT_RESOURCE::outbufferFmt.\n * This function provides synchronization guarantee that any graphics work submitted\n * on the input buffer is completed before the buffer is used for encoding. This is\n * also true for compute (i.e. CUDA) work, provided that the previous workload using\n * the input resource was submitted to the default stream.\n * The client should not access any input buffer while they are mapped by the encoder.\n * For D3D12 interface type, this function does not provide synchronization guarantee.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] mapInputResParams\n *   Pointer to the ::_NV_ENC_MAP_INPUT_RESOURCE structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_RESOURCE_NOT_REGISTERED \\n\n * ::NV_ENC_ERR_MAP_FAILED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncMapInputResource                         (void *encoder, NV_ENC_MAP_INPUT_RESOURCE *mapInputResParams);\n\n\n// NvEncUnmapInputResource\n/**\n * \\brief  UnMaps a NV_ENC_INPUT_PTR  which was mapped for encoding\n *\n *\n * UnMaps an input buffer which was previously mapped using ::NvEncMapInputResource()\n * API. The mapping created using ::NvEncMapInputResource() should be invalidated\n * using this API before the external resource is destroyed by the client. The client\n * must unmap the buffer after ::NvEncLockBitstream() API returns successfully for encode\n * work submitted using the mapped input buffer.\n *\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] mappedInputBuffer\n *   Pointer to the NV_ENC_INPUT_PTR\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_RESOURCE_NOT_REGISTERED \\n\n * ::NV_ENC_ERR_RESOURCE_NOT_MAPPED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnmapInputResource                         (void *encoder, NV_ENC_INPUT_PTR mappedInputBuffer);\n\n// NvEncDestroyEncoder\n/**\n * \\brief Destroy Encoding Session\n *\n * Destroys the encoder session previously created using ::NvEncOpenEncodeSession()\n * function. The client must flush the encoder before freeing any resources. In order\n * to flush the encoder the client must pass a NULL encode picture packet and either\n * wait for the ::NvEncEncodePicture() function to return in synchronous mode or wait\n * for the flush event to be signaled by the encoder in asynchronous mode.\n * The client must free all the input and output resources created using the\n * NvEncodeAPI interface before destroying the encoder. If the client is operating\n * in asynchronous mode, it must also unregister the completion events previously\n * registered.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncDestroyEncoder                        (void *encoder);\n\n// NvEncInvalidateRefFrames\n/**\n * \\brief Invalidate reference frames\n *\n * Invalidates reference frame based on the time stamp provided by the client.\n * The encoder marks any reference frames or any frames which have been reconstructed\n * using the corrupt frame as invalid for motion estimation and uses older reference\n * frames for motion estimation. The encoded forces the current frame to be encoded\n * as an intra frame if no reference frames are left after invalidation process.\n * This is useful for low latency application for error resiliency. The client\n * is recommended to set NV_ENC_CONFIG_H264::maxNumRefFrames to a large value so\n * that encoder can keep a backup of older reference frames in the DPB and can use them\n * for motion estimation when the newer reference frames have been invalidated.\n * This API can be called multiple times.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] invalidRefFrameTimeStamp\n *   Timestamp of the invalid reference frames which needs to be invalidated.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncInvalidateRefFrames(void *encoder, uint64_t invalidRefFrameTimeStamp);\n\n// NvEncOpenEncodeSessionEx\n/**\n * \\brief Opens an encoding session.\n *\n * Opens an encoding session and returns a pointer to the encoder interface in\n * the \\p **encoder parameter. The client should start encoding process by calling\n * this API first.\n * The client must pass a pointer to IDirect3DDevice9 device or CUDA context in the \\p *device parameter.\n * For the OpenGL interface, \\p device must be NULL. An OpenGL context must be current when\n * calling all NvEncodeAPI functions.\n * If the creation of encoder session fails, the client must call ::NvEncDestroyEncoder API\n * before exiting.\n *\n * \\param [in] openSessionExParams\n *    Pointer to a ::NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS structure.\n * \\param [out] encoder\n *    Encode Session pointer to the NvEncodeAPI interface.\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_NO_ENCODE_DEVICE \\n\n * ::NV_ENC_ERR_UNSUPPORTED_DEVICE \\n\n * ::NV_ENC_ERR_INVALID_DEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncOpenEncodeSessionEx                   (NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS *openSessionExParams, void **encoder);\n\n// NvEncRegisterResource\n/**\n * \\brief Registers a resource with the Nvidia Video Encoder Interface.\n *\n * Registers a resource with the Nvidia Video Encoder Interface for book keeping.\n * The client is expected to pass the registered resource handle as well, while calling ::NvEncMapInputResource API.\n *\n * \\param [in] encoder\n *   Pointer to the NVEncodeAPI interface.\n *\n * \\param [in] registerResParams\n *   Pointer to a ::_NV_ENC_REGISTER_RESOURCE structure\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_RESOURCE_REGISTER_FAILED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n * ::NV_ENC_ERR_UNIMPLEMENTED \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncRegisterResource                      (void *encoder, NV_ENC_REGISTER_RESOURCE *registerResParams);\n\n// NvEncUnregisterResource\n/**\n * \\brief Unregisters a resource previously registered with the Nvidia Video Encoder Interface.\n *\n * Unregisters a resource previously registered with the Nvidia Video Encoder Interface.\n * The client is expected to unregister any resource that it has registered with the\n * Nvidia Video Encoder Interface before destroying the resource.\n *\n * \\param [in] encoder\n *   Pointer to the NVEncodeAPI interface.\n *\n * \\param [in] registeredResource\n *   The registered resource pointer that was returned in ::NvEncRegisterResource.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_RESOURCE_NOT_REGISTERED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n * ::NV_ENC_ERR_UNIMPLEMENTED \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncUnregisterResource                    (void *encoder, NV_ENC_REGISTERED_PTR registeredResource);\n\n// NvEncReconfigureEncoder\n/**\n * \\brief Reconfigure an existing encoding session.\n *\n * Reconfigure an existing encoding session.\n * The client should call this API to change/reconfigure the parameter passed during\n * NvEncInitializeEncoder API call.\n * Currently Reconfiguration of following are not supported.\n * Change in GOP structure.\n * Change in sync-Async mode.\n * Change in MaxWidth & MaxHeight.\n * Change in PTD mode.\n *\n * Resolution change is possible only if maxEncodeWidth & maxEncodeHeight of NV_ENC_INITIALIZE_PARAMS\n * is set while creating encoder session.\n *\n * \\param [in] encoder\n *   Pointer to the NVEncodeAPI interface.\n *\n * \\param [in] reInitEncodeParams\n *    Pointer to a ::NV_ENC_RECONFIGURE_PARAMS structure.\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_NO_ENCODE_DEVICE \\n\n * ::NV_ENC_ERR_UNSUPPORTED_DEVICE \\n\n * ::NV_ENC_ERR_INVALID_DEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_GENERIC \\n\n *\n */\nNVENCSTATUS NVENCAPI NvEncReconfigureEncoder                   (void *encoder, NV_ENC_RECONFIGURE_PARAMS *reInitEncodeParams);\n\n\n\n// NvEncCreateMVBuffer\n/**\n * \\brief Allocates output MV buffer for ME only mode.\n *\n * This function is used to allocate an output MV buffer. The size of the mvBuffer is\n * dependent on the frame height and width of the last ::NvEncCreateInputBuffer() call.\n * The NV_ENC_OUTPUT_PTR returned by the NvEncodeAPI interface in the\n * ::NV_ENC_CREATE_MV_BUFFER::mvBuffer field should be used in\n * ::NvEncRunMotionEstimationOnly() API.\n * Client must lock ::NV_ENC_CREATE_MV_BUFFER::mvBuffer using ::NvEncLockBitstream() API to get the motion vector data.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in,out] createMVBufferParams\n *  Pointer to the ::NV_ENC_CREATE_MV_BUFFER structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncCreateMVBuffer                        (void *encoder, NV_ENC_CREATE_MV_BUFFER *createMVBufferParams);\n\n\n// NvEncDestroyMVBuffer\n/**\n * \\brief Release an output MV buffer for ME only mode.\n *\n * This function is used to release the output MV buffer allocated using\n * the ::NvEncCreateMVBuffer() function. The client must release the output\n * mvBuffer using this function before destroying the encoder session.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] mvBuffer\n *   Pointer to the mvBuffer being released.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncDestroyMVBuffer                       (void *encoder, NV_ENC_OUTPUT_PTR mvBuffer);\n\n\n// NvEncRunMotionEstimationOnly\n/**\n * \\brief Submit an input picture and reference frame for motion estimation in ME only mode.\n *\n * This function is used to submit the input frame and reference frame for motion\n * estimation. The ME parameters are passed using *meOnlyParams which is a pointer\n * to ::_NV_ENC_MEONLY_PARAMS structure.\n * Client must lock ::NV_ENC_CREATE_MV_BUFFER::mvBuffer using ::NvEncLockBitstream() API to get the motion vector data.\n * to get motion vector data.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n * \\param [in] meOnlyParams\n *   Pointer to the ::_NV_ENC_MEONLY_PARAMS structure.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n * ::NV_ENC_ERR_INVALID_ENCODERDEVICE \\n\n * ::NV_ENC_ERR_DEVICE_NOT_EXIST \\n\n * ::NV_ENC_ERR_UNSUPPORTED_PARAM \\n\n * ::NV_ENC_ERR_OUT_OF_MEMORY \\n\n * ::NV_ENC_ERR_INVALID_PARAM \\n\n * ::NV_ENC_ERR_INVALID_VERSION \\n\n * ::NV_ENC_ERR_NEED_MORE_INPUT \\n\n * ::NV_ENC_ERR_ENCODER_NOT_INITIALIZED \\n\n * ::NV_ENC_ERR_GENERIC \\n\n */\nNVENCSTATUS NVENCAPI NvEncRunMotionEstimationOnly               (void *encoder, NV_ENC_MEONLY_PARAMS *meOnlyParams);\n\n// NvEncodeAPIGetMaxSupportedVersion\n/**\n * \\brief Get the largest NvEncodeAPI version supported by the driver.\n *\n * This function can be used by clients to determine if the driver supports\n * the NvEncodeAPI header the application was compiled with.\n *\n * \\param [out] version\n *   Pointer to the requested value. The 4 least significant bits in the returned\n *   indicate the minor version and the rest of the bits indicate the major\n *   version of the largest supported version.\n *\n * \\return\n * ::NV_ENC_SUCCESS \\n\n * ::NV_ENC_ERR_INVALID_PTR \\n\n */\nNVENCSTATUS NVENCAPI NvEncodeAPIGetMaxSupportedVersion          (uint32_t *version);\n\n\n// NvEncGetLastErrorString\n/**\n * \\brief Get the description of the last error reported by the API.\n *\n * This function returns a null-terminated string that can be used by clients to better understand the reason\n * for failure of a previous API call.\n *\n * \\param [in] encoder\n *   Pointer to the NvEncodeAPI interface.\n *\n * \\return\n *   Pointer to buffer containing the details of the last error encountered by the API.\n */\nconst char *NVENCAPI NvEncGetLastErrorString          (void *encoder);\n\n\n/// \\cond API PFN\n/*\n *  Defines API function pointers\n */\ntypedef NVENCSTATUS (NVENCAPI *PNVENCOPENENCODESESSION)         (void *device, uint32_t deviceType, void **encoder);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEGUIDCOUNT)        (void *encoder, uint32_t *encodeGUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEGUIDS)            (void *encoder, GUID *GUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPROFILEGUIDCOUNT) (void *encoder, GUID encodeGUID, uint32_t *encodeProfileGUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPROFILEGUIDS)     (void *encoder, GUID encodeGUID, GUID *profileGUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETINPUTFORMATCOUNT)       (void *encoder, GUID encodeGUID, uint32_t *inputFmtCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETINPUTFORMATS)           (void *encoder, GUID encodeGUID, NV_ENC_BUFFER_FORMAT *inputFmts, uint32_t inputFmtArraySize, uint32_t *inputFmtCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODECAPS)             (void *encoder, GUID encodeGUID, NV_ENC_CAPS_PARAM *capsParam, int *capsVal);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPRESETCOUNT)      (void *encoder, GUID encodeGUID, uint32_t *encodePresetGUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPRESETGUIDS)      (void *encoder, GUID encodeGUID, GUID *presetGUIDs, uint32_t guidArraySize, uint32_t *encodePresetGUIDCount);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPRESETCONFIG)     (void *encoder, GUID encodeGUID, GUID  presetGUID, NV_ENC_PRESET_CONFIG *presetConfig);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODEPRESETCONFIGEX)   (void *encoder, GUID encodeGUID, GUID  presetGUID, NV_ENC_TUNING_INFO tuningInfo, NV_ENC_PRESET_CONFIG *presetConfig);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCINITIALIZEENCODER)         (void *encoder, NV_ENC_INITIALIZE_PARAMS *createEncodeParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCCREATEINPUTBUFFER)         (void *encoder, NV_ENC_CREATE_INPUT_BUFFER *createInputBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCDESTROYINPUTBUFFER)        (void *encoder, NV_ENC_INPUT_PTR inputBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCCREATEBITSTREAMBUFFER)     (void *encoder, NV_ENC_CREATE_BITSTREAM_BUFFER *createBitstreamBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCDESTROYBITSTREAMBUFFER)    (void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCENCODEPICTURE)             (void *encoder, NV_ENC_PIC_PARAMS *encodePicParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCLOCKBITSTREAM)             (void *encoder, NV_ENC_LOCK_BITSTREAM *lockBitstreamBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNLOCKBITSTREAM)           (void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCLOCKINPUTBUFFER)           (void *encoder, NV_ENC_LOCK_INPUT_BUFFER *lockInputBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNLOCKINPUTBUFFER)         (void *encoder, NV_ENC_INPUT_PTR inputBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETENCODESTATS)            (void *encoder, NV_ENC_STAT *encodeStats);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETSEQUENCEPARAMS)         (void *encoder, NV_ENC_SEQUENCE_PARAM_PAYLOAD *sequenceParamPayload);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCREGISTERASYNCEVENT)        (void *encoder, NV_ENC_EVENT_PARAMS *eventParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNREGISTERASYNCEVENT)      (void *encoder, NV_ENC_EVENT_PARAMS *eventParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCMAPINPUTRESOURCE)          (void *encoder, NV_ENC_MAP_INPUT_RESOURCE *mapInputResParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNMAPINPUTRESOURCE)        (void *encoder, NV_ENC_INPUT_PTR mappedInputBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCDESTROYENCODER)            (void *encoder);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCINVALIDATEREFFRAMES)       (void *encoder, uint64_t invalidRefFrameTimeStamp);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCOPENENCODESESSIONEX)       (NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS *openSessionExParams, void **encoder);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCREGISTERRESOURCE)          (void *encoder, NV_ENC_REGISTER_RESOURCE *registerResParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCUNREGISTERRESOURCE)        (void *encoder, NV_ENC_REGISTERED_PTR registeredRes);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCRECONFIGUREENCODER)        (void *encoder, NV_ENC_RECONFIGURE_PARAMS *reInitEncodeParams);\n\ntypedef NVENCSTATUS (NVENCAPI *PNVENCCREATEMVBUFFER)            (void *encoder, NV_ENC_CREATE_MV_BUFFER *createMVBufferParams);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCDESTROYMVBUFFER)           (void *encoder, NV_ENC_OUTPUT_PTR mvBuffer);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCRUNMOTIONESTIMATIONONLY)   (void *encoder, NV_ENC_MEONLY_PARAMS *meOnlyParams);\ntypedef const char *(NVENCAPI *PNVENCGETLASTERROR)             (void *encoder);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCSETIOCUDASTREAMS)          (void *encoder, NV_ENC_CUSTREAM_PTR inputStream, NV_ENC_CUSTREAM_PTR outputStream);\ntypedef NVENCSTATUS (NVENCAPI *PNVENCGETSEQUENCEPARAMEX)        (void *encoder, NV_ENC_INITIALIZE_PARAMS *encInitParams, NV_ENC_SEQUENCE_PARAM_PAYLOAD *sequenceParamPayload);\n\n\n/// \\endcond\n\n\n/** @} */ /* END ENCODE_FUNC */\n\n/**\n * \\ingroup ENCODER_STRUCTURE\n * NV_ENCODE_API_FUNCTION_LIST\n */\ntypedef struct _NV_ENCODE_API_FUNCTION_LIST\n{\n    uint32_t                        version;                           /**< [in]: Client should pass NV_ENCODE_API_FUNCTION_LIST_VER.                               */\n    uint32_t                        reserved;                          /**< [in]: Reserved and should be set to 0.                                                  */\n    PNVENCOPENENCODESESSION         nvEncOpenEncodeSession;            /**< [out]: Client should access ::NvEncOpenEncodeSession() API through this pointer.        */\n    PNVENCGETENCODEGUIDCOUNT        nvEncGetEncodeGUIDCount;           /**< [out]: Client should access ::NvEncGetEncodeGUIDCount() API through this pointer.       */\n    PNVENCGETENCODEPRESETCOUNT      nvEncGetEncodeProfileGUIDCount;    /**< [out]: Client should access ::NvEncGetEncodeProfileGUIDCount() API through this pointer.*/\n    PNVENCGETENCODEPRESETGUIDS      nvEncGetEncodeProfileGUIDs;        /**< [out]: Client should access ::NvEncGetEncodeProfileGUIDs() API through this pointer.    */\n    PNVENCGETENCODEGUIDS            nvEncGetEncodeGUIDs;               /**< [out]: Client should access ::NvEncGetEncodeGUIDs() API through this pointer.           */\n    PNVENCGETINPUTFORMATCOUNT       nvEncGetInputFormatCount;          /**< [out]: Client should access ::NvEncGetInputFormatCount() API through this pointer.      */\n    PNVENCGETINPUTFORMATS           nvEncGetInputFormats;              /**< [out]: Client should access ::NvEncGetInputFormats() API through this pointer.          */\n    PNVENCGETENCODECAPS             nvEncGetEncodeCaps;                /**< [out]: Client should access ::NvEncGetEncodeCaps() API through this pointer.            */\n    PNVENCGETENCODEPRESETCOUNT      nvEncGetEncodePresetCount;         /**< [out]: Client should access ::NvEncGetEncodePresetCount() API through this pointer.     */\n    PNVENCGETENCODEPRESETGUIDS      nvEncGetEncodePresetGUIDs;         /**< [out]: Client should access ::NvEncGetEncodePresetGUIDs() API through this pointer.     */\n    PNVENCGETENCODEPRESETCONFIG     nvEncGetEncodePresetConfig;        /**< [out]: Client should access ::NvEncGetEncodePresetConfig() API through this pointer.    */\n    PNVENCINITIALIZEENCODER         nvEncInitializeEncoder;            /**< [out]: Client should access ::NvEncInitializeEncoder() API through this pointer.        */\n    PNVENCCREATEINPUTBUFFER         nvEncCreateInputBuffer;            /**< [out]: Client should access ::NvEncCreateInputBuffer() API through this pointer.        */\n    PNVENCDESTROYINPUTBUFFER        nvEncDestroyInputBuffer;           /**< [out]: Client should access ::NvEncDestroyInputBuffer() API through this pointer.       */\n    PNVENCCREATEBITSTREAMBUFFER     nvEncCreateBitstreamBuffer;        /**< [out]: Client should access ::NvEncCreateBitstreamBuffer() API through this pointer.    */\n    PNVENCDESTROYBITSTREAMBUFFER    nvEncDestroyBitstreamBuffer;       /**< [out]: Client should access ::NvEncDestroyBitstreamBuffer() API through this pointer.   */\n    PNVENCENCODEPICTURE             nvEncEncodePicture;                /**< [out]: Client should access ::NvEncEncodePicture() API through this pointer.            */\n    PNVENCLOCKBITSTREAM             nvEncLockBitstream;                /**< [out]: Client should access ::NvEncLockBitstream() API through this pointer.            */\n    PNVENCUNLOCKBITSTREAM           nvEncUnlockBitstream;              /**< [out]: Client should access ::NvEncUnlockBitstream() API through this pointer.          */\n    PNVENCLOCKINPUTBUFFER           nvEncLockInputBuffer;              /**< [out]: Client should access ::NvEncLockInputBuffer() API through this pointer.          */\n    PNVENCUNLOCKINPUTBUFFER         nvEncUnlockInputBuffer;            /**< [out]: Client should access ::NvEncUnlockInputBuffer() API through this pointer.        */\n    PNVENCGETENCODESTATS            nvEncGetEncodeStats;               /**< [out]: Client should access ::NvEncGetEncodeStats() API through this pointer.           */\n    PNVENCGETSEQUENCEPARAMS         nvEncGetSequenceParams;            /**< [out]: Client should access ::NvEncGetSequenceParams() API through this pointer.        */\n    PNVENCREGISTERASYNCEVENT        nvEncRegisterAsyncEvent;           /**< [out]: Client should access ::NvEncRegisterAsyncEvent() API through this pointer.       */\n    PNVENCUNREGISTERASYNCEVENT      nvEncUnregisterAsyncEvent;         /**< [out]: Client should access ::NvEncUnregisterAsyncEvent() API through this pointer.     */\n    PNVENCMAPINPUTRESOURCE          nvEncMapInputResource;             /**< [out]: Client should access ::NvEncMapInputResource() API through this pointer.         */\n    PNVENCUNMAPINPUTRESOURCE        nvEncUnmapInputResource;           /**< [out]: Client should access ::NvEncUnmapInputResource() API through this pointer.       */\n    PNVENCDESTROYENCODER            nvEncDestroyEncoder;               /**< [out]: Client should access ::NvEncDestroyEncoder() API through this pointer.           */\n    PNVENCINVALIDATEREFFRAMES       nvEncInvalidateRefFrames;          /**< [out]: Client should access ::NvEncInvalidateRefFrames() API through this pointer.      */\n    PNVENCOPENENCODESESSIONEX       nvEncOpenEncodeSessionEx;          /**< [out]: Client should access ::NvEncOpenEncodeSession() API through this pointer.        */\n    PNVENCREGISTERRESOURCE          nvEncRegisterResource;             /**< [out]: Client should access ::NvEncRegisterResource() API through this pointer.         */\n    PNVENCUNREGISTERRESOURCE        nvEncUnregisterResource;           /**< [out]: Client should access ::NvEncUnregisterResource() API through this pointer.       */\n    PNVENCRECONFIGUREENCODER        nvEncReconfigureEncoder;           /**< [out]: Client should access ::NvEncReconfigureEncoder() API through this pointer.       */\n    void                           *reserved1;\n    PNVENCCREATEMVBUFFER            nvEncCreateMVBuffer;               /**< [out]: Client should access ::NvEncCreateMVBuffer API through this pointer.             */\n    PNVENCDESTROYMVBUFFER           nvEncDestroyMVBuffer;              /**< [out]: Client should access ::NvEncDestroyMVBuffer API through this pointer.            */\n    PNVENCRUNMOTIONESTIMATIONONLY   nvEncRunMotionEstimationOnly;      /**< [out]: Client should access ::NvEncRunMotionEstimationOnly API through this pointer.    */\n    PNVENCGETLASTERROR              nvEncGetLastErrorString;           /**< [out]: Client should access ::nvEncGetLastErrorString API through this pointer.         */\n    PNVENCSETIOCUDASTREAMS          nvEncSetIOCudaStreams;             /**< [out]: Client should access ::nvEncSetIOCudaStreams API through this pointer.           */\n    PNVENCGETENCODEPRESETCONFIGEX   nvEncGetEncodePresetConfigEx;      /**< [out]: Client should access ::NvEncGetEncodePresetConfigEx() API through this pointer.  */\n    PNVENCGETSEQUENCEPARAMEX        nvEncGetSequenceParamEx;           /**< [out]: Client should access ::NvEncGetSequenceParamEx() API through this pointer.       */\n    void                           *reserved2[277];                    /**< [in]:  Reserved and must be set to NULL                                                 */\n} NV_ENCODE_API_FUNCTION_LIST;\n\n/** Macro for constructing the version field of ::_NV_ENCODEAPI_FUNCTION_LIST. */\n#define NV_ENCODE_API_FUNCTION_LIST_VER NVENCAPI_STRUCT_VERSION(2)\n\n// NvEncodeAPICreateInstance\n/**\n * \\ingroup ENCODE_FUNC\n * Entry Point to the NvEncodeAPI interface.\n *\n * Creates an instance of the NvEncodeAPI interface, and populates the\n * pFunctionList with function pointers to the API routines implemented by the\n * NvEncodeAPI interface.\n *\n * \\param [out] functionList\n *\n * \\return\n * ::NV_ENC_SUCCESS\n * ::NV_ENC_ERR_INVALID_PTR\n */\nNVENCSTATUS NVENCAPI NvEncodeAPICreateInstance(NV_ENCODE_API_FUNCTION_LIST *functionList);\n\n#ifdef __cplusplus\n}\n#endif\n\n\n#endif\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2020-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"trans.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"log.h\"\n\n#include \"xrdp_accel_assist.h\"\n#include \"xrdp_accel_assist_x11.h\"\n\n#define ARRAYSIZE(x) (sizeof(x)/sizeof(*(x)))\n\n#define GFX_MAP_SIZE 3145728\n\nstruct xorgxrdp_info\n{\n    struct trans *xorg_trans;\n    struct trans *xrdp_trans;\n    struct source_info si;\n    int shmem_fd_ret;\n    int shmem_bytes_ret;\n    int idr_count;\n    int pad0;\n};\n\nstatic int g_display_num = 0;\n\n/*****************************************************************************/\nstatic int\ngfx_wiretosurface1(struct xorgxrdp_info *xi, struct stream *s)\n{\n    void *addr;\n    int surface_id;\n    int codec_id;\n    int pixel_format;\n    int flags;\n    int num_rects_c;\n    struct xh_rect *crects;\n    int num_rects_d;\n    int index;\n    int left;\n    int top;\n    int width;\n    int height;\n    int cdata_bytes;\n    int rv;\n    int encoder_flags;\n    char *flags_pointer;\n    char *final_pointer;\n\n    (void)pixel_format;\n    (void)codec_id;\n    (void)surface_id;\n    (void)rv;\n\n    if (xi->shmem_fd_ret != -1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"gfx_wiretosurface1: xi->shmem_fd_ret \"\n            \"should be -1, it is %d\", xi->shmem_fd_ret);\n    }\n    if (g_alloc_shm_map_fd(&addr, &(xi->shmem_fd_ret), GFX_MAP_SIZE) != 0)\n    {\n        return 1;\n    }\n    LOG_DEVEL(LOG_LEVEL_INFO, \"gfx_wiretosurface1: addr %p fd %d\",\n              addr, xi->shmem_fd_ret);\n\n    if (!s_check_rem(s, 11))\n    {\n        g_munmap(addr, GFX_MAP_SIZE);\n        g_file_close(xi->shmem_fd_ret);\n        xi->shmem_fd_ret = -1;\n        return 1;\n    }\n    in_uint16_le(s, surface_id);\n    in_uint16_le(s, codec_id);\n    in_uint8(s, pixel_format);\n    flags_pointer = s->p;\n    in_uint32_le(s, flags);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"gfx_wiretosurface1: surface_id %d codec_id %d \"\n              \"pixel_format %d flags %d\",\n              surface_id, codec_id, pixel_format, flags);\n    in_uint16_le(s, num_rects_d);\n    if ((num_rects_d < 1) || (num_rects_d > 16 * 1024) ||\n            (!s_check_rem(s, num_rects_d * 8)))\n    {\n        g_munmap(addr, GFX_MAP_SIZE);\n        g_file_close(xi->shmem_fd_ret);\n        xi->shmem_fd_ret = -1;\n        return 1;\n    }\n    in_uint8s(s, num_rects_d * 8);\n    if (!s_check_rem(s, 2))\n    {\n        g_munmap(addr, GFX_MAP_SIZE);\n        g_file_close(xi->shmem_fd_ret);\n        xi->shmem_fd_ret = -1;\n        return 1;\n    }\n\n    in_uint16_le(s, num_rects_c);\n    if ((num_rects_c < 1) || (num_rects_c > 16 * 1024) ||\n            (!s_check_rem(s, num_rects_c * 8)))\n    {\n        g_munmap(addr, GFX_MAP_SIZE);\n        g_file_close(xi->shmem_fd_ret);\n        xi->shmem_fd_ret = -1;\n        return 1;\n    }\n    crects = g_new0(struct xh_rect, num_rects_c);\n    if (crects == NULL)\n    {\n        g_munmap(addr, GFX_MAP_SIZE);\n        g_file_close(xi->shmem_fd_ret);\n        xi->shmem_fd_ret = -1;\n        return 1;\n    }\n    for (index = 0; index < num_rects_c; index++)\n    {\n        in_uint16_le(s, crects[index].x);\n        in_uint16_le(s, crects[index].y);\n        in_uint16_le(s, crects[index].w);\n        in_uint16_le(s, crects[index].h);\n    }\n    if (!s_check_rem(s, 8))\n    {\n        g_munmap(addr, GFX_MAP_SIZE);\n        g_file_close(xi->shmem_fd_ret);\n        xi->shmem_fd_ret = -1;\n        g_free(crects);\n        return 1;\n    }\n    in_uint16_le(s, left);\n    in_uint16_le(s, top);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n    final_pointer = s->p;\n\n    (void)left;\n    (void)top;\n\n    cdata_bytes = GFX_MAP_SIZE;\n    encoder_flags = 0;\n    if (xi->idr_count > 0)\n    {\n        encoder_flags = XH_ENC_FLAGS_FORCEIDR;\n        xi->idr_count--;\n    }\n    rv = xrdp_accel_assist_x11_encode_pixmap(0, 0,\n         width, height, surface_id,\n         num_rects_c, crects,\n         addr, &cdata_bytes,\n         encoder_flags);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"gfx_wiretosurface1: rv %d cdata_bytes %d\",\n              rv, cdata_bytes);\n\n    s->p = flags_pointer;\n    flags |= 1;\n    out_uint32_le(s, flags); /* set already encoded bit */\n    s->p = final_pointer;\n\n    xi->shmem_bytes_ret = cdata_bytes;\n\n    g_free(crects);\n    g_munmap(addr, GFX_MAP_SIZE);\n    /* do not close xi->shmem_fd_ret here, it will get closed after sent */\n\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxorg_process_message_62(struct xorgxrdp_info *xi, struct stream *s)\n{\n    int recv_bytes;\n    int total_cmd_bytes;\n    int total_shm_bytes;\n    int cmd_bytes;\n    int cmd_id;\n    int fd;\n    unsigned int num_fds;\n    char msg[4];\n    char *total_holdp;\n    char *total_holdend;\n    char *holdp;\n    char *holdend;\n\n    if (!s_check_rem(s, 4))\n    {\n        return 1;\n    }\n    in_uint32_le(s, total_cmd_bytes);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xorg_process_message_62: \"\n              \"total_cmd_bytes %d\",\n              total_cmd_bytes);\n    if ((total_cmd_bytes < 1) || (total_cmd_bytes > 32 * 1024) ||\n            (!s_check_rem(s, total_cmd_bytes)))\n    {\n        return 1;\n    }\n    total_holdp = s->p;\n    total_holdend = s->end;\n    s->end = s->p + total_cmd_bytes;\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xorg_process_message_62: \"\n              \"rem %d\",\n              (int)(s->end - s->p));\n    while (s_check_rem(s, 8))\n    {\n        holdp = s->p;\n        in_uint16_le(s, cmd_id);\n        in_uint8s(s, 2); /* flags */\n        in_uint32_le(s, cmd_bytes);\n        LOG_DEVEL(LOG_LEVEL_INFO, \"xorg_process_message_62: \"\n                  \"cmd_id %d cmd_bytes %d\",\n                  cmd_id, cmd_bytes);\n        if ((cmd_bytes < 8) || (cmd_bytes > 32 * 1024) ||\n                (!s_check_rem(s, cmd_bytes - 8)))\n        {\n            return 1;\n        }\n        holdend = s->end;\n        s->end = holdp + cmd_bytes;\n        switch (cmd_id)\n        {\n            case 0x0001: /* XR_RDPGFX_CMDID_WIRETOSURFACE_1 */\n                if (gfx_wiretosurface1(xi, s) != 0)\n                {\n                    return 1;\n                }\n                break;\n            case 0x000E: /* XR_RDPGFX_CMDID_RESETGRAPHICS */\n                LOG(LOG_LEVEL_INFO, \"xorg_process_message_62: \"\n                    \"XR_RDPGFX_CMDID_RESETGRAPHICS detected\");\n                break;\n        }\n        /* setup for next cmd */\n        s->p = holdp + cmd_bytes;\n        s->end = holdend;\n        LOG_DEVEL(LOG_LEVEL_INFO, \"xorg_process_message_62: \"\n                  \"rem %d\",\n                  (int)(s->end - s->p));\n    }\n    s->p = total_holdp + total_cmd_bytes;\n    s->end = total_holdend;\n    if (!s_check_rem(s, 4))\n    {\n        return 1;\n    }\n    in_uint32_le(s, total_shm_bytes);\n    s->p -= 4;\n    out_uint32_le(s, xi->shmem_bytes_ret);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xorg_process_message_62: \"\n              \"total_shm_bytes %d\",\n              total_shm_bytes);\n    if (total_shm_bytes < 1)\n    {\n        /* return no error */\n        return 0;\n    }\n    num_fds = 0;\n    if (g_tcp_can_recv(xi->xorg_trans->sck, 5000) == 0)\n    {\n        return 1;\n    }\n    recv_bytes = g_sck_recv_fd_set(xi->xorg_trans->sck, msg, 4,\n                                   &fd, 1, &num_fds);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xorg_process_message_62: \"\n              \"g_sck_recv_fd_set rv %d fd %d, num_fds %d\",\n              recv_bytes, fd, num_fds);\n    if (recv_bytes == 4)\n    {\n        if (num_fds == 1)\n        {\n            g_file_close(fd);\n            /* return no error */\n            return 0;\n        }\n    }\n    return 1;\n}\n\n/*****************************************************************************/\nstatic int\nxorg_process_message_63(struct xorgxrdp_info *xi, struct stream *s)\n{\n    int recv_bytes;\n    unsigned int num_fds;\n    char msg[4];\n\n    if (xi->shmem_fd_ret != -1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xorg_process_message_63: xi->shmem_fd_ret \"\n            \"should be -1, it is %d\", xi->shmem_fd_ret);\n    }\n    num_fds = -1;\n    if (g_tcp_can_recv(xi->xorg_trans->sck, 5000) == 0)\n    {\n        return 1;\n    }\n    recv_bytes = g_sck_recv_fd_set(xi->xorg_trans->sck, msg, 4,\n                                   &(xi->shmem_fd_ret), 1, &num_fds);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xorg_process_message_63: \"\n              \"g_sck_recv_fd_set rv %d fd %d, num_fds %d\",\n              recv_bytes, xi->shmem_fd_ret, num_fds);\n    if (recv_bytes == 4)\n    {\n        if (num_fds == 1)\n        {\n            return 0;\n        }\n    }\n    return 1;\n}\n\n/*****************************************************************************/\nstatic int\nxorg_process_message_64(struct xorgxrdp_info *xi, struct stream *s)\n{\n    int num_drects;\n    int num_crects;\n    int flags;\n    int shmem_bytes;\n    int shmem_offset;\n    int frame_id;\n    int left;\n    int top;\n    int width;\n    int height;\n    int twidth;\n    int theight;\n    int cdata_bytes;\n    int index;\n    int recv_bytes;\n    int encoder_flags;\n    enum encoder_result rv;\n    struct xh_rect *crects;\n    char *bmpdata;\n    char msg[4];\n    unsigned int num_fds;\n    void *shmem_ptr;\n\n    (void)twidth;\n    (void)theight;\n    (void)frame_id;\n\n    /* dirty pixels */\n    in_uint16_le(s, num_drects);\n    in_uint8s(s, 8 * num_drects);\n    /* copied pixels */\n    in_uint16_le(s, num_crects);\n    crects = g_new(struct xh_rect, num_crects);\n    for (index = 0; index < num_crects; index++)\n    {\n        in_uint16_le(s, crects[index].x);\n        in_uint16_le(s, crects[index].y);\n        in_uint16_le(s, crects[index].w);\n        in_uint16_le(s, crects[index].h);\n    }\n    char *flag_pointer = s->p;\n    in_uint32_le(s, flags);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xorg_process_message_64: flags 0x%8.8X\", flags);\n    in_uint32_le(s, frame_id);\n    in_uint32_le(s, shmem_bytes);\n    in_uint32_le(s, shmem_offset);\n\n    in_uint16_le(s, left);\n    in_uint16_le(s, top);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n    in_uint16_le(s, twidth);\n    in_uint16_le(s, theight);\n    char *final_pointer = s->p;\n\n    if (xi->shmem_fd_ret != -1)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xorg_process_message_64: xi->shmem_fd_ret \"\n            \"should be -1, it is %d\", xi->shmem_fd_ret);\n    }\n\n    num_fds = -1;\n    if (g_tcp_can_recv(xi->xorg_trans->sck, 5000) == 0)\n    {\n        g_free(crects);\n        return 1;\n    }\n    recv_bytes = g_sck_recv_fd_set(xi->xorg_trans->sck, msg, 4,\n                                   &(xi->shmem_fd_ret), 1, &num_fds);\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xorg_process_message_64: \"\n              \"g_sck_recv_fd_set rv %d fd %d, num_fds %d\",\n              recv_bytes, xi->shmem_fd_ret, num_fds);\n\n    shmem_ptr = NULL;\n    if (recv_bytes == 4)\n    {\n        if (num_fds == 1)\n        {\n            if (g_file_map(xi->shmem_fd_ret, 1, 1, shmem_bytes,\n                           &shmem_ptr) == 0)\n            {\n                bmpdata = (char *)shmem_ptr;\n                bmpdata += shmem_offset;\n\n                if ((bmpdata != NULL) && (flags & 1))\n                {\n                    cdata_bytes = 16 * 1024 * 1024;\n                    encoder_flags = 0;\n                    if (xi->idr_count > 0)\n                    {\n                        encoder_flags = XH_ENC_FLAGS_FORCEIDR;\n                        xi->idr_count--;\n                    }\n                    rv = xrdp_accel_assist_x11_encode_pixmap(left, top,\n                         width, height,\n                         (flags >> 28) & 0xF,\n                         num_crects, crects,\n                         bmpdata + 4,\n                         &cdata_bytes, encoder_flags);\n                    if (rv == ENCODER_ERROR)\n                    {\n                        LOG(LOG_LEVEL_ERROR, \"error %d\", rv);\n                    }\n                    if (rv == KEY_FRAME_ENCODED)\n                    {\n                        s->p = flag_pointer;\n                        out_uint32_le(s, flags | 1 | 2);\n                        s->p = final_pointer;\n                    }\n\n                    bmpdata[0] = cdata_bytes;\n                    bmpdata[1] = cdata_bytes >> 8;\n                    bmpdata[2] = cdata_bytes >> 16;\n                    bmpdata[3] = cdata_bytes >> 24;\n                    LOG_DEVEL(LOG_LEVEL_INFO, \"cdata_bytes %d\", cdata_bytes);\n                }\n            }\n        }\n        else\n        {\n            LOG(LOG_LEVEL_INFO,\n                \"xorg_process_message_64: num_fds %d\", num_fds);\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"xorg_process_message_64: recv_bytes %d\", recv_bytes);\n    }\n\n    if (shmem_ptr != NULL)\n    {\n        g_munmap(shmem_ptr, shmem_bytes);\n    }\n    g_free(crects);\n    return 0;\n}\n\n/*****************************************************************************/\n/* data going from xorg to xrdp */\nstatic int\nxorg_process_message(struct xorgxrdp_info *xi, struct stream *s)\n{\n    int type;\n    int num;\n    int size;\n    int index;\n    char *phold;\n    char *endhold;\n    int width;\n    int height;\n    int magic;\n    int con_id;\n    int mon_id;\n    int ret;\n\n    xi->shmem_fd_ret = -1;\n    in_uint16_le(s, type);\n    in_uint16_le(s, num);\n    in_uint32_le(s, size);\n    if (type == 3)\n    {\n        for (index = 0; index < num; index++)\n        {\n            phold = s->p;\n            in_uint16_le(s, type);\n            in_uint16_le(s, size);\n            endhold = s->end;\n            s->end = phold + size;\n            switch (type)\n            {\n                case 62:\n                    /* process_server_egfx_shmfd */\n                    if (xorg_process_message_62(xi, s) != 0)\n                    {\n                        LOG(LOG_LEVEL_ERROR, \"xorg_process_message: \"\n                            \"xorg_process_message_62 failed\");\n                        return 1;\n                    }\n                    break;\n                case 63:\n                    /* process_server_set_pointer_shmfd */\n                    if (xorg_process_message_63(xi, s) != 0)\n                    {\n                        LOG(LOG_LEVEL_ERROR, \"xorg_process_message: \"\n                            \"xorg_process_message_63 failed\");\n                        return 1;\n                    }\n                    break;\n                case 64:\n                    /* process_server_paint_rect_shmfd */\n                    if (xorg_process_message_64(xi, s) != 0)\n                    {\n                        LOG(LOG_LEVEL_ERROR, \"xorg_process_message: \"\n                            \"xorg_process_message_64 failed\");\n                        return 1;\n                    }\n                    break;\n            }\n            s->p = phold + size;\n            s->end = endhold;\n        }\n    }\n    else if (type == 100)\n    {\n        for (index = 0; index < num; index++)\n        {\n            phold = s->p;\n            in_uint16_le(s, type);\n            in_uint16_le(s, size);\n            LOG(LOG_LEVEL_DEBUG, \"100 type %d size %d\", type, size);\n            switch (type)\n            {\n                case 1:\n                    LOG(LOG_LEVEL_DEBUG, \"calling xrdp_accel_assist_x11_delete_all_pixmaps\");\n                    xrdp_accel_assist_x11_delete_all_pixmaps();\n                    break;\n                case 2:\n                    in_uint16_le(s, width);\n                    in_uint16_le(s, height);\n                    in_uint32_le(s, magic);\n                    in_uint32_le(s, con_id);\n                    in_uint32_le(s, mon_id);\n                    LOG(LOG_LEVEL_DEBUG, \"calling xrdp_accel_assist_x11_create_pixmap\");\n                    xrdp_accel_assist_x11_create_pixmap(width, height, magic,\n                                                        con_id, mon_id);\n                    break;\n            }\n            s->p = phold + size;\n        }\n        /* this will force I frames for 10 frames */\n        xi->idr_count = 10;\n        LOG(LOG_LEVEL_INFO, \"setting idr_count to %d\", xi->idr_count);\n    }\n    s->p = s->data;\n    if (xi->shmem_fd_ret == -1)\n    {\n        /* no shared memory, ok */\n        ret = trans_write_copy_s(xi->xrdp_trans, s);\n        return ret;\n    }\n    /* using posix shared memory, got to pass fd on to xrdp */\n    ret = trans_force_write_s(xi->xrdp_trans, s);\n    if (ret)\n    {\n        return ret;\n    }\n    ret = g_sck_send_fd_set(xi->xrdp_trans->sck, \"int\", 4,\n                            &(xi->shmem_fd_ret), 1);\n    if (ret < 0)\n    {\n        return 1;\n    }\n    g_file_close(xi->shmem_fd_ret);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxorg_data_in(struct trans *trans)\n{\n    struct stream *s;\n    int len;\n    struct xorgxrdp_info *xi;\n\n    xi = (struct xorgxrdp_info *) (trans->callback_data);\n    s = trans_get_in_s(trans);\n    switch (trans->extra_flags)\n    {\n        case 1:\n            s->p = s->data;\n            in_uint8s(s, 4);\n            in_uint32_le(s, len);\n            if ((len < 0) || (len > 128 * 1024))\n            {\n                LOG(LOG_LEVEL_ERROR, \"bad size %d\", len);\n                return 1;\n            }\n            if (len > 0)\n            {\n                trans->header_size = len + 8;\n                trans->extra_flags = 2;\n                break;\n            }\n        /* fall through */\n        case 2:\n            s->p = s->data;\n            if (xorg_process_message(xi, s) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"xorg_process_message failed\");\n                return 1;\n            }\n            init_stream(s, 0);\n            trans->header_size = 8;\n            trans->extra_flags = 1;\n            break;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\n/* data going from xrdp to xorg */\nstatic int\nxrdp_process_message(struct xorgxrdp_info *xi, struct stream *s)\n{\n    int len;\n    int msg_type1;\n    int msg_type2;\n\n    in_uint32_le(s, len);\n    in_uint16_le(s, msg_type1);\n    if (msg_type1 == 103) /* client message */\n    {\n        in_uint32_le(s, msg_type2);\n        if (msg_type2 == 200) /* invalidate */\n        {\n            LOG(LOG_LEVEL_DEBUG, \"Invalidate found (len: %d, msg1: %d, msg2: %d)\", len, msg_type1, msg_type2);\n        }\n        else if (msg_type2 == 300) /* resize */\n        {\n            LOG(LOG_LEVEL_DEBUG, \"Resize 300 found (len: %d, msg1: %d, msg2: %d)\", len, msg_type1, msg_type2);\n        }\n        else if (msg_type2 == 302) /* resize */\n        {\n            LOG(LOG_LEVEL_DEBUG, \"Resize 302 found (len: %d, msg1: %d, msg2: %d)\", len, msg_type1, msg_type2);\n        }\n    }\n    /* Reset read pointer */\n    s->p = s->data;\n    return trans_write_copy_s(xi->xorg_trans, s);\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_data_in(struct trans *trans)\n{\n    struct stream *s;\n    int len;\n    struct xorgxrdp_info *xi;\n\n    xi = (struct xorgxrdp_info *) (trans->callback_data);\n    s = trans_get_in_s(trans);\n    switch (trans->extra_flags)\n    {\n        case 1:\n            s->p = s->data;\n            in_uint32_le(s, len);\n            if ((len < 0) || (len > 128 * 1024))\n            {\n                LOG(LOG_LEVEL_ERROR, \"bad size %d\", len);\n                return 1;\n            }\n            if (len > 0)\n            {\n                trans->header_size = len;\n                trans->extra_flags = 2;\n                break;\n            }\n        /* fall through */\n        case 2:\n            s->p = s->data;\n            if (xrdp_process_message(xi, s) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"xrdp_process_message failed\");\n                return 1;\n            }\n            init_stream(s, 0);\n            trans->header_size = 4;\n            trans->extra_flags = 1;\n            break;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic void\nsigpipe_func(int sig)\n{\n    (void) sig;\n}\n\n/*****************************************************************************/\nstatic int\nget_log_path(char *path, int bytes)\n{\n    char *log_path;\n    int rv;\n\n    rv = 1;\n    log_path = g_getenv(\"XRDP_ACCEL_ASSIST_LOG_PATH\");\n    if (log_path == 0)\n    {\n        log_path = g_getenv(\"XDG_DATA_HOME\");\n        if (log_path != 0)\n        {\n            g_snprintf(path, bytes, \"%s%s\", log_path, \"/xrdp\");\n            if (g_directory_exist(path) || (g_mkdir(path) == 0))\n            {\n                rv = 0;\n            }\n        }\n    }\n    else\n    {\n        g_snprintf(path, bytes, \"%s\", log_path);\n        if (g_directory_exist(path) || (g_mkdir(path) == 0))\n        {\n            rv = 0;\n        }\n    }\n    if (rv != 0)\n    {\n        log_path = g_getenv(\"HOME\");\n        if (log_path != 0)\n        {\n            g_snprintf(path, bytes, \"%s%s\", log_path, \"/.local\");\n            if (g_directory_exist(path) || (g_mkdir(path) == 0))\n            {\n                g_snprintf(path, bytes, \"%s%s\", log_path, \"/.local/share\");\n                if (g_directory_exist(path) || (g_mkdir(path) == 0))\n                {\n                    g_snprintf(path, bytes, \"%s%s\", log_path, \"/.local/share/xrdp\");\n                    if (g_directory_exist(path) || (g_mkdir(path) == 0))\n                    {\n                        rv = 0;\n                    }\n                }\n            }\n        }\n    }\n    return rv;\n}\n\n/*****************************************************************************/\nstatic enum logLevels\nget_log_level(const char *level_str, enum logLevels default_level)\n{\n    static const char *levels[] = {\n        \"LOG_LEVEL_ALWAYS\",\n        \"LOG_LEVEL_ERROR\",\n        \"LOG_LEVEL_WARNING\",\n        \"LOG_LEVEL_INFO\",\n        \"LOG_LEVEL_DEBUG\",\n        \"LOG_LEVEL_TRACE\"\n    };\n    unsigned int i;\n\n    if (level_str == NULL || level_str[0] == 0)\n    {\n        return default_level;\n    }\n    for (i = 0; i < ARRAYSIZE(levels); ++i)\n    {\n        if (g_strcasecmp(levels[i], level_str) == 0)\n        {\n            return (enum logLevels) i;\n        }\n    }\n    return default_level;\n}\n\n/*****************************************************************************/\nstatic int\nget_display_num_from_display(char *display_text)\n{\n    int index;\n    int mode;\n    int host_index;\n    int disp_index;\n    int scre_index;\n    char host[256];\n    char disp[256];\n    char scre[256];\n\n    g_memset(host, 0, 256);\n    g_memset(disp, 0, 256);\n    g_memset(scre, 0, 256);\n\n    index = 0;\n    host_index = 0;\n    disp_index = 0;\n    scre_index = 0;\n    mode = 0;\n\n    while (display_text[index] != 0)\n    {\n        if (display_text[index] == ':')\n        {\n            mode = 1;\n        }\n        else if (display_text[index] == '.')\n        {\n            mode = 2;\n        }\n        else if (mode == 0)\n        {\n            host[host_index] = display_text[index];\n            host_index++;\n        }\n        else if (mode == 1)\n        {\n            disp[disp_index] = display_text[index];\n            disp_index++;\n        }\n        else if (mode == 2)\n        {\n            scre[scre_index] = display_text[index];\n            scre_index++;\n        }\n\n        index++;\n    }\n\n    host[host_index] = 0;\n    disp[disp_index] = 0;\n    scre[scre_index] = 0;\n    g_display_num = g_atoi(disp);\n    return 0;\n}\n\n/*****************************************************************************/\nstatic int\nxrdp_accel_assist_setup_log(void)\n{\n    struct log_config logconfig;\n    enum logLevels log_level;\n    char log_path[256];\n    char log_file[256];\n    char *display_text;\n    int error;\n\n    if (get_log_path(log_path, 255) != 0)\n    {\n        g_writeln(\"error reading XRDP_ACCEL_ASSIST_LOG_PATH and HOME \"\n                  \"environment variable\");\n        g_deinit();\n        return 1;\n    }\n    display_text = g_getenv(\"DISPLAY\");\n    if (display_text != NULL)\n    {\n        get_display_num_from_display(display_text);\n    }\n    g_snprintf(log_file, 255, \"%s/xrdp-accel-assist.%d.log\", log_path,\n               g_display_num);\n    g_writeln(\"xrdp-accel-assist::xrdp_accel_assist_setup_log: using \"\n              \"log file [%s]\", log_file);\n    if (g_file_exist(log_file))\n    {\n        g_file_delete(log_file);\n    }\n    log_level = get_log_level(g_getenv(\"XRDP_ACCEL_ASSIST_LOG_LEVEL\"),\n                              LOG_LEVEL_INFO);\n    logconfig.log_file = log_file;\n    logconfig.fd = -1;\n    logconfig.log_level = log_level;\n    logconfig.enable_syslog = 0;\n    logconfig.syslog_level = LOG_LEVEL_ALWAYS;\n    logconfig.program_name = \"xrdp_accel_assist\";\n    logconfig.enable_console = 0;\n    logconfig.enable_pid = 1;\n#ifdef LOG_PER_LOGGER_LEVEL\n    logconfig.per_logger_level = NULL;\n#endif\n    error = log_start_from_param(&logconfig);\n\n    return error;\n}\n\n/*****************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    int xorg_fd;\n    int xrdp_fd;\n    int error;\n    intptr_t robjs[16];\n    int robj_count;\n    intptr_t wobjs[16];\n    int wobj_count;\n    int timeout;\n    struct xorgxrdp_info xi;\n\n    if (argc < 2)\n    {\n        g_writeln(\"need to pass -d\");\n        return 0;\n    }\n    if (strcmp(argv[1], \"-d\") != 0)\n    {\n        g_writeln(\"need to pass -d\");\n        return 0;\n    }\n    g_init(\"xrdp_accel_assist\");\n\n    if (xrdp_accel_assist_setup_log() != 0)\n    {\n        return 1;\n    }\n    LOG(LOG_LEVEL_INFO, \"startup\");\n    g_memset(&xi, 0, sizeof(xi));\n    g_signal_pipe(sigpipe_func);\n    if (xrdp_accel_assist_x11_init() != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_accel_assist_x11_init failed\");\n        return 1;\n    }\n    xorg_fd = g_atoi(g_getenv(\"XORGXRDP_XORG_FD\"));\n    LOG(LOG_LEVEL_INFO, \"xorg_fd: %d\", xorg_fd);\n    xrdp_fd = g_atoi(g_getenv(\"XORGXRDP_XRDP_FD\"));\n    LOG(LOG_LEVEL_INFO, \"xrdp_fd: %d\", xrdp_fd);\n\n    xi.xorg_trans = trans_create(TRANS_MODE_UNIX, 128 * 1024, 128 * 1024);\n    xi.xorg_trans->sck = xorg_fd;\n    xi.xorg_trans->status = TRANS_STATUS_UP;\n    xi.xorg_trans->trans_data_in = xorg_data_in;\n    xi.xorg_trans->header_size = 8;\n    xi.xorg_trans->no_stream_init_on_data_in = 1;\n    xi.xorg_trans->extra_flags = 1;\n    xi.xorg_trans->callback_data = &xi;\n    xi.xorg_trans->si = &(xi.si);\n    xi.xorg_trans->my_source = XORGXRDP_SOURCE_XORG;\n\n    xi.xrdp_trans = trans_create(TRANS_MODE_UNIX, 128 * 1024, 128 * 1024);\n    xi.xrdp_trans->sck = xrdp_fd;\n    xi.xrdp_trans->status = TRANS_STATUS_UP;\n    xi.xrdp_trans->trans_data_in = xrdp_data_in;\n    xi.xrdp_trans->no_stream_init_on_data_in = 1;\n    xi.xrdp_trans->header_size = 4;\n    xi.xrdp_trans->extra_flags = 1;\n    xi.xrdp_trans->callback_data = &xi;\n    xi.xrdp_trans->si = &(xi.si);\n    xi.xrdp_trans->my_source = XORGXRDP_SOURCE_XRDP;\n\n    for (;;)\n    {\n        robj_count = 0;\n        wobj_count = 0;\n        timeout = -1;\n        error = trans_get_wait_objs_rw(xi.xorg_trans, robjs, &robj_count,\n                                       wobjs, &wobj_count, &timeout);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"trans_get_wait_objs_rw failed\");\n            break;\n        }\n        error = trans_get_wait_objs_rw(xi.xrdp_trans, robjs, &robj_count,\n                                       wobjs, &wobj_count, &timeout);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"trans_get_wait_objs_rw failed\");\n            break;\n        }\n        error = xrdp_accel_assist_x11_get_wait_objs(robjs, &robj_count);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_get_wait_objs failed\");\n            break;\n        }\n        error = g_obj_wait(robjs, robj_count, wobjs, wobj_count, timeout);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"g_obj_wait failed\");\n            break;\n        }\n        error = trans_check_wait_objs(xi.xorg_trans);\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"xorg_trans trans_check_wait_objs failed\");\n            break;\n        }\n        error = trans_check_wait_objs(xi.xrdp_trans);\n        if (error != 0 && error != 10)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_trans trans_check_wait_objs failed\");\n            break;\n        }\n        error = xrdp_accel_assist_x11_check_wait_objs();\n        if (error != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_accel_assist_x11_check_wait_objs failed\");\n            break;\n        }\n    }\n    LOG(LOG_LEVEL_INFO, \"exit\");\n    return 0;\n}\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2020-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _XRDP_ACCEL_ASSIST_H\n#define _XRDP_ACCEL_ASSIST_H\n\n#define XH_YUV420   1\n#define XH_YUV422   2\n#define XH_YUV444   3\n\n#define XH_BT601    0\n#define XH_BT709FR  1\n#define XH_BTRFX    2\n\nstruct xh_rect\n{\n    short x;\n    short y;\n    short w;\n    short h;\n};\n\n#define XH_ENC_FLAGS_FORCEIDR (1 << 0)\n\nenum encoder_result\n{\n    INCREMENTAL_FRAME_ENCODED,  /* P frame */\n    KEY_FRAME_ENCODED,          /* IDR frame */\n    ENCODER_ERROR\n};\n\n#endif\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist_egl.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2022-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n#include <X11/Xlib.h>\n\n#include <epoxy/gl.h>\n#include <epoxy/egl.h>\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"xrdp_accel_assist.h\"\n#include \"xrdp_accel_assist_x11.h\"\n#include \"xrdp_accel_assist_egl.h\"\n#include \"log.h\"\n\nEGLDisplay g_egl_display;\nEGLContext g_egl_context;\nstatic EGLSurface g_egl_surface;\nstatic EGLConfig g_ecfg;\nstatic EGLint g_num_config;\n\n/* X11 */\nextern Display *g_display; /* in xrdp_accel_assist_x11.c */\nextern Window g_root_window; /* in xrdp_accel_assist_x11.c */\n\nstatic EGLint g_choose_config_attr[] =\n{\n    EGL_RED_SIZE, 8,\n    EGL_GREEN_SIZE, 8,\n    EGL_BLUE_SIZE, 8,\n    EGL_NONE\n};\n\nstatic EGLint g_create_context_attr[] =\n{\n    EGL_CONTEXT_MAJOR_VERSION, 3,\n    EGL_CONTEXT_MINOR_VERSION, 3,\n    EGL_NONE\n};\n\nstatic const EGLint g_create_surface_attr[] =\n{\n    EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,\n    EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,\n    EGL_NONE\n};\n\n/*****************************************************************************/\nstatic EGLBoolean\nxrdp_accel_assist_check_ext(const char *ext_name)\n{\n    if (!epoxy_has_egl_extension(g_egl_display, ext_name))\n    {\n        LOG(LOG_LEVEL_INFO, \"%s not present\", ext_name);\n        return EGL_FALSE;\n    }\n    LOG(LOG_LEVEL_INFO, \"%s present\", ext_name);\n    return EGL_TRUE;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_egl_init(void)\n{\n    int egl_ver;\n    int ok;\n\n    ok = eglBindAPI(EGL_OPENGL_API);\n    LOG(LOG_LEVEL_INFO, \"eglBindAPI ok %d\", ok);\n    g_egl_display = eglGetDisplay((EGLNativeDisplayType) g_display);\n    LOG(LOG_LEVEL_INFO, \"g_egl_display %p\", g_egl_display);\n    eglInitialize(g_egl_display, NULL, NULL);\n    egl_ver = epoxy_egl_version(g_egl_display);\n    LOG(LOG_LEVEL_INFO, \"egl_ver %d\", egl_ver);\n    if (egl_ver < 11) /* EGL version 1.1 */\n    {\n        LOG(LOG_LEVEL_INFO, \"egl_ver too old %d\", egl_ver);\n        eglTerminate(g_egl_display);\n        return 1;\n    }\n    if ((!xrdp_accel_assist_check_ext(\"EGL_NOK_texture_from_pixmap\")) ||\n            (!xrdp_accel_assist_check_ext(\"EGL_MESA_image_dma_buf_export\")) ||\n            (!xrdp_accel_assist_check_ext(\"EGL_KHR_image_base\")))\n    {\n        LOG(LOG_LEVEL_INFO, \"missing ext\");\n        eglTerminate(g_egl_display);\n        return 1;\n    }\n    eglChooseConfig(g_egl_display, g_choose_config_attr, &g_ecfg,\n                    1, &g_num_config);\n    LOG(LOG_LEVEL_INFO, \"g_ecfg %p g_num_config %d\", g_ecfg, g_num_config);\n    g_egl_surface = eglCreateWindowSurface(g_egl_display, g_ecfg,\n                                           g_root_window, NULL);\n    LOG(LOG_LEVEL_INFO, \"g_egl_surface %p\", g_egl_surface);\n    g_egl_context = eglCreateContext(g_egl_display, g_ecfg,\n                                     EGL_NO_CONTEXT, g_create_context_attr);\n    LOG(LOG_LEVEL_INFO, \"g_egl_context %p\", g_egl_context);\n    ok = eglMakeCurrent(g_egl_display, g_egl_surface, g_egl_surface,\n                        g_egl_context);\n    LOG(LOG_LEVEL_INFO, \"eglMakeCurrent ok %d\", ok);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_egl_create_image(Pixmap pixmap, inf_image_t *inf_image)\n{\n    *inf_image = (inf_image_t)eglCreatePixmapSurface(g_egl_display,\n                 g_ecfg, pixmap, g_create_surface_attr);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_egl_destroy_image(inf_image_t inf_image)\n{\n    eglDestroySurface(g_egl_display, (EGLSurface)inf_image);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_egl_bind_tex_image(inf_image_t inf_image)\n{\n    eglBindTexImage(g_egl_display, (EGLSurface)inf_image, EGL_BACK_BUFFER);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_egl_release_tex_image(inf_image_t inf_image)\n{\n    eglReleaseTexImage(g_egl_display, (EGLSurface)inf_image, EGL_BACK_BUFFER);\n    return 0;\n}\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist_egl.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2022-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _XRDP_ACCEL_ASSIST_EGL_H\n#define _XRDP_ACCEL_ASSIST_EGL_H\n\nint\nxrdp_accel_assist_inf_egl_init(void);\nint\nxrdp_accel_assist_inf_egl_create_image(Pixmap pixmap, inf_image_t *inf_image);\nint\nxrdp_accel_assist_inf_egl_destroy_image(inf_image_t inf_image);\nint\nxrdp_accel_assist_inf_egl_bind_tex_image(inf_image_t inf_image);\nint\nxrdp_accel_assist_inf_egl_release_tex_image(inf_image_t inf_image);\n\n#endif\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist_glx.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2022-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n#include <X11/Xlib.h>\n\n#include <epoxy/gl.h>\n#include <epoxy/glx.h>\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"xrdp_accel_assist.h\"\n#include \"xrdp_accel_assist_x11.h\"\n#include \"xrdp_accel_assist_glx.h\"\n#include \"log.h\"\n\nstatic int g_n_fbconfigs = 0;\nstatic int g_n_pixconfigs = 0;\nstatic GLXFBConfig *g_fbconfigs = NULL;\nstatic GLXFBConfig *g_pixconfigs = NULL;\nstatic GLXContext g_gl_context = 0;\n\n/* X11 */\nextern Display *g_display; /* in xrdp_accel_assist_x11.c */\nextern Window g_root_window; /* in xrdp_accel_assist_x11.c */\nextern int g_screen_num; /* in xrdp_accel_assist_x11.c */\n\nstatic const int g_fbconfig_attrs[] =\n{\n    GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,\n    GLX_RENDER_TYPE,   GLX_RGBA_BIT,\n    GLX_DOUBLEBUFFER,  True,\n    GLX_RED_SIZE,      8,\n    GLX_GREEN_SIZE,    8,\n    GLX_BLUE_SIZE,     8,\n    None\n};\n\nstatic const int g_pixconfig_attrs[] =\n{\n    GLX_BIND_TO_TEXTURE_RGBA_EXT,       True,\n    GLX_DRAWABLE_TYPE,                  GLX_PIXMAP_BIT,\n    GLX_BIND_TO_TEXTURE_TARGETS_EXT,    GLX_TEXTURE_2D_BIT_EXT,\n    GLX_DOUBLEBUFFER,                   False,\n    GLX_Y_INVERTED_EXT,                 True,\n    None\n};\n\nstatic const int g_pixmap_attribs[] =\n{\n    GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,\n    GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,\n    None\n};\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_glx_init(void)\n{\n    const char *ext_str;\n    int glx_ver;\n    int ok;\n\n    glx_ver = epoxy_glx_version(g_display, g_screen_num);\n    LOG(LOG_LEVEL_INFO, \"glx_ver %d\", glx_ver);\n    if (glx_ver < 11) /* GLX version 1.1 */\n    {\n        LOG(LOG_LEVEL_INFO, \"glx_ver too old %d\", glx_ver);\n        return 1;\n    }\n    if (!epoxy_has_glx_extension(g_display, g_screen_num,\n                                 \"GLX_EXT_texture_from_pixmap\"))\n    {\n        ext_str = glXQueryExtensionsString(g_display, g_screen_num);\n        LOG(LOG_LEVEL_INFO, \"GLX_EXT_texture_from_pixmap not present [%s]\",\n            ext_str);\n        return 1;\n    }\n    LOG(LOG_LEVEL_INFO, \"GLX_EXT_texture_from_pixmap present\");\n    g_fbconfigs = glXChooseFBConfig(g_display, g_screen_num,\n                                    g_fbconfig_attrs, &g_n_fbconfigs);\n    LOG(LOG_LEVEL_INFO, \"g_fbconfigs %p\", g_fbconfigs);\n    g_gl_context = glXCreateNewContext(g_display, g_fbconfigs[0],\n                                       GLX_RGBA_TYPE, NULL, 1);\n    LOG(LOG_LEVEL_INFO, \"g_gl_context %p\", g_gl_context);\n    ok = glXMakeCurrent(g_display, g_root_window, g_gl_context);\n    LOG(LOG_LEVEL_INFO, \"ok %d\", ok);\n    g_pixconfigs = glXChooseFBConfig(g_display, g_screen_num,\n                                     g_pixconfig_attrs, &g_n_pixconfigs);\n    LOG(LOG_LEVEL_INFO, \"g_pixconfigs %p g_n_pixconfigs %d\",\n        g_pixconfigs, g_n_pixconfigs);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_glx_create_image(Pixmap pixmap, inf_image_t *inf_image)\n{\n    *inf_image = (inf_image_t)glXCreatePixmap(g_display, g_pixconfigs[0],\n                 pixmap, g_pixmap_attribs);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_glx_destroy_image(inf_image_t inf_image)\n{\n    glXDestroyPixmap(g_display, (GLXPixmap)inf_image);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_glx_bind_tex_image(inf_image_t inf_image)\n{\n    glXBindTexImageEXT(g_display, (GLXPixmap)inf_image, GLX_FRONT_EXT, NULL);\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_inf_glx_release_tex_image(inf_image_t inf_image)\n{\n    glXReleaseTexImageEXT(g_display, (GLXPixmap)inf_image, GLX_FRONT_EXT);\n    return 0;\n}\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist_glx.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2022-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _XRDP_ACCEL_ASSIST_GLX_H\n#define _XRDP_ACCEL_ASSIST_GLX_H\n\nint\nxrdp_accel_assist_inf_glx_init(void);\nint\nxrdp_accel_assist_inf_glx_create_image(Pixmap pixmap, inf_image_t *inf_image);\nint\nxrdp_accel_assist_inf_glx_destroy_image(inf_image_t inf_image);\nint\nxrdp_accel_assist_inf_glx_bind_tex_image(inf_image_t inf_image);\nint\nxrdp_accel_assist_inf_glx_release_tex_image(inf_image_t inf_image);\n\n#endif\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist_nvenc.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2022-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#include \"string_calls.h\"\n\n#include <epoxy/gl.h>\n\n#include \"encoder_headers/nvEncodeAPI_11_1.h\"\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"xrdp_accel_assist.h\"\n#include \"xrdp_accel_assist_x11.h\"\n#include \"xrdp_accel_assist_nvenc.h\"\n#include \"log.h\"\n\n#define XH_NVENV_DEFAULT_QP 28\n\ntypedef NVENCSTATUS\n(NVENCAPI *NvEncodeAPICreateInstanceProc)\n(NV_ENCODE_API_FUNCTION_LIST *functionList);\n\nstatic char g_lib_name[] = \"libnvidia-encode.so\";\nstatic char g_lib_name1[] = \"libnvidia-encode.so.1\";\nstatic char g_func_name[] = \"NvEncodeAPICreateInstance\";\n\nstatic NvEncodeAPICreateInstanceProc g_NvEncodeAPICreateInstance = NULL;\n\nstatic NV_ENCODE_API_FUNCTION_LIST g_enc_funcs;\n\nstatic long g_lib = 0;\n\nstruct enc_info\n{\n    int width;\n    int height;\n    int frameCount;\n    int pad0;\n    void *enc;\n    NV_ENC_OUTPUT_PTR bitstreamBuffer;\n    NV_ENC_INPUT_PTR mappedResource;\n    NV_ENC_BUFFER_FORMAT mappedBufferFmt;\n    NV_ENC_REGISTERED_PTR registeredResource;\n};\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_nvenc_init(void)\n{\n    NVENCSTATUS nv_error;\n\n    g_lib = g_load_library(g_lib_name);\n    if (g_lib == 0)\n    {\n        g_lib = g_load_library(g_lib_name1);\n        if (g_lib == 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"load library for %s/%s failed\", g_lib_name, g_lib_name1);\n            return 1;\n        }\n    }\n    g_NvEncodeAPICreateInstance = g_get_proc_address(g_lib, g_func_name);\n    if (g_NvEncodeAPICreateInstance == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"get proc address for %s failed\", g_func_name);\n        return 1;\n    }\n    g_memset(&g_enc_funcs, 0, sizeof(g_enc_funcs));\n    g_enc_funcs.version = NV_ENCODE_API_FUNCTION_LIST_VER;\n    nv_error = g_NvEncodeAPICreateInstance(&g_enc_funcs);\n    LOG(LOG_LEVEL_INFO, \"NvEncodeAPICreateInstance rv %d\", nv_error);\n    if (nv_error != NV_ENC_SUCCESS)\n    {\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_nvenc_create_encoder(int width, int height, int tex,\n                                       int tex_format, struct enc_info **ei)\n{\n    NV_ENC_CREATE_BITSTREAM_BUFFER bitstreamParams;\n    NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS params;\n    NV_ENC_INITIALIZE_PARAMS createEncodeParams;\n    NV_ENC_MAP_INPUT_RESOURCE mapInputResource;\n    NV_ENC_INPUT_RESOURCE_OPENGL_TEX res;\n    NV_ENC_REGISTER_RESOURCE reg_res;\n    NV_ENC_CONFIG encCfg;\n    NVENCSTATUS nv_error;\n    struct enc_info *lei;\n    char *rateControlMode_str;\n    char *averageBitRate_str;\n    char *qp_str;\n    int qp_int;\n    int averageBitRate_int;\n    int rc_set;\n\n    lei = g_new0(struct enc_info, 1);\n    if (lei == NULL)\n    {\n        return 1;\n    }\n\n    g_memset(&params, 0, sizeof(params));\n    params.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;\n    params.deviceType = NV_ENC_DEVICE_TYPE_OPENGL;\n    params.apiVersion = NVENCAPI_VERSION;\n    nv_error = g_enc_funcs.nvEncOpenEncodeSessionEx(&params, &(lei->enc));\n    LOG(LOG_LEVEL_INFO, \"nvEncOpenEncodeSessionEx rv %d enc %p\", nv_error, lei->enc);\n    if (nv_error != NV_ENC_SUCCESS)\n    {\n        g_free(lei);\n        return 1;\n    }\n\n    g_memset(&encCfg, 0, sizeof(encCfg));\n    encCfg.version = NV_ENC_CONFIG_VER;\n    encCfg.profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID;\n    encCfg.gopLength = NVENC_INFINITE_GOPLENGTH;\n    encCfg.frameIntervalP = 1;  /* 1 + B_Frame_Count */\n    encCfg.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME;\n    encCfg.mvPrecision = NV_ENC_MV_PRECISION_QUARTER_PEL;\n\n    /* these env vars can be added / changed in sesman.ini SessionVariables\n       example\n       XRDP_NVENC_RATE_CONTROL_MODE=NV_ENC_PARAMS_RC_CONSTQP\n       XRDP_NVENC_QP=30\n       or\n       XRDP_NVENC_RATE_CONTROL_MODE=NV_ENC_PARAMS_RC_VBR\n       XRDP_NVENC_AVERAGE_BITRATE=2000000 */\n    rateControlMode_str = g_getenv(\"XRDP_NVENC_RATE_CONTROL_MODE\");\n    averageBitRate_str = g_getenv(\"XRDP_NVENC_AVERAGE_BITRATE\");\n    qp_str = g_getenv(\"XRDP_NVENC_QP\");\n    rc_set = 0;\n    if (rateControlMode_str != NULL)\n    {\n        if (g_strcmp(rateControlMode_str, \"NV_ENC_PARAMS_RC_CONSTQP\") == 0)\n        {\n            if (qp_str != NULL)\n            {\n                qp_int = g_atoi(qp_str);\n                if ((qp_int >= 0) && (qp_int <= 51))\n                {\n                    LOG(LOG_LEVEL_INFO,\n                        \"using NV_ENC_PARAMS_RC_CONSTQP qp %d\",\n                        qp_int);\n                    encCfg.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;\n                    encCfg.rcParams.constQP.qpInterP = qp_int;\n                    encCfg.rcParams.constQP.qpInterB = qp_int;\n                    encCfg.rcParams.constQP.qpIntra = qp_int;\n                    rc_set = 1;\n                }\n            }\n        }\n        else if (g_strcmp(rateControlMode_str, \"NV_ENC_PARAMS_RC_VBR\") == 0)\n        {\n            if (averageBitRate_str != NULL)\n            {\n                averageBitRate_int = g_atoi(averageBitRate_str);\n                if ((averageBitRate_int >= 5000) &&\n                        (averageBitRate_int <= 1000000000))\n                {\n                    LOG(LOG_LEVEL_INFO,\n                        \"using NV_ENC_PARAMS_RC_VBR averageBitRate %d\",\n                        averageBitRate_int);\n                    encCfg.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;\n                    encCfg.rcParams.averageBitRate = averageBitRate_int;\n                    rc_set = 1;\n                }\n            }\n        }\n    }\n    if (!rc_set)\n    {\n        LOG(LOG_LEVEL_INFO,\n            \"using default NV_ENC_PARAMS_RC_CONSTQP qp %d\",\n            XH_NVENV_DEFAULT_QP);\n        encCfg.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;\n        encCfg.rcParams.constQP.qpInterP = XH_NVENV_DEFAULT_QP;\n        encCfg.rcParams.constQP.qpInterB = XH_NVENV_DEFAULT_QP;\n        encCfg.rcParams.constQP.qpIntra = XH_NVENV_DEFAULT_QP;\n        rc_set = 1;\n    }\n\n    encCfg.encodeCodecConfig.h264Config.chromaFormatIDC = 1;\n    encCfg.encodeCodecConfig.h264Config.idrPeriod = NVENC_INFINITE_GOPLENGTH;\n    encCfg.encodeCodecConfig.h264Config.repeatSPSPPS = 1;\n    encCfg.encodeCodecConfig.h264Config.disableSPSPPS = 0;\n\n    g_memset(&createEncodeParams, 0, sizeof(createEncodeParams));\n    createEncodeParams.version = NV_ENC_INITIALIZE_PARAMS_VER;\n    createEncodeParams.encodeGUID = NV_ENC_CODEC_H264_GUID;\n    createEncodeParams.encodeWidth = width;\n    createEncodeParams.encodeHeight = height;\n    createEncodeParams.darWidth = width;\n    createEncodeParams.darHeight = height;\n    createEncodeParams.frameRateNum = 30;\n    createEncodeParams.frameRateDen = 1;\n    createEncodeParams.enablePTD = 1;\n    createEncodeParams.encodeConfig = &encCfg;\n    nv_error = g_enc_funcs.nvEncInitializeEncoder(lei->enc,\n               &createEncodeParams);\n    LOG(LOG_LEVEL_INFO, \"nvEncInitializeEncoder rv %d\", nv_error);\n    if (nv_error != NV_ENC_SUCCESS)\n    {\n        g_free(lei);\n        return 1;\n    }\n\n    g_memset(&res, 0, sizeof(res));\n    res.texture = tex;\n    res.target = GL_TEXTURE_2D;\n\n    g_memset(&reg_res, 0, sizeof(reg_res));\n    reg_res.version = NV_ENC_REGISTER_RESOURCE_VER;\n    reg_res.resourceType = NV_ENC_INPUT_RESOURCE_TYPE_OPENGL_TEX;\n    reg_res.width = width;\n    reg_res.height = height;\n    if (tex_format == XH_YUV420)\n    {\n        reg_res.pitch = width;\n        reg_res.bufferFormat = NV_ENC_BUFFER_FORMAT_NV12;\n    }\n    else\n    {\n        reg_res.pitch = width * 4;\n        reg_res.bufferFormat = NV_ENC_BUFFER_FORMAT_AYUV;\n    }\n    reg_res.resourceToRegister = &res;\n    reg_res.bufferUsage = NV_ENC_INPUT_IMAGE;\n    nv_error = g_enc_funcs.nvEncRegisterResource(lei->enc, &reg_res);\n    LOG(LOG_LEVEL_INFO, \"nvEncRegisterResource rv %d\", nv_error);\n    if (nv_error != NV_ENC_SUCCESS)\n    {\n        g_free(lei);\n        return 1;\n    }\n\n    g_memset(&mapInputResource, 0, sizeof(mapInputResource));\n    mapInputResource.version = NV_ENC_LOCK_INPUT_BUFFER_VER;\n    mapInputResource.registeredResource = reg_res.registeredResource;\n    nv_error = g_enc_funcs.nvEncMapInputResource(lei->enc, &mapInputResource);\n    LOG(LOG_LEVEL_INFO, \"nvEncMapInputResource rv %d\", nv_error);\n    if (nv_error != NV_ENC_SUCCESS)\n    {\n        g_free(lei);\n        return 1;\n    }\n\n    g_memset(&bitstreamParams, 0, sizeof(bitstreamParams));\n    bitstreamParams.version = NV_ENC_CREATE_BITSTREAM_BUFFER_VER;\n    nv_error = g_enc_funcs.nvEncCreateBitstreamBuffer(lei->enc,\n               &bitstreamParams);\n    LOG(LOG_LEVEL_INFO, \"nvEncCreateBitstreamBuffer rv %d\", nv_error);\n    if (nv_error != NV_ENC_SUCCESS)\n    {\n        g_free(lei);\n        return 1;\n    }\n\n    lei->bitstreamBuffer = bitstreamParams.bitstreamBuffer;\n    lei->mappedResource = mapInputResource.mappedResource;\n    lei->mappedBufferFmt = mapInputResource.mappedBufferFmt;\n    lei->registeredResource = reg_res.registeredResource;\n    lei->width = width;\n    lei->height = height;\n\n    *ei = lei;\n\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_nvenc_delete_encoder(struct enc_info *ei)\n{\n    g_enc_funcs.nvEncUnmapInputResource(ei->enc, ei->mappedResource);\n    g_enc_funcs.nvEncUnregisterResource(ei->enc, ei->registeredResource);\n    g_enc_funcs.nvEncDestroyBitstreamBuffer(ei->enc, ei->bitstreamBuffer);\n    g_enc_funcs.nvEncDestroyEncoder(ei->enc);\n    g_free(ei);\n    return 0;\n}\n\n/*****************************************************************************/\nenum encoder_result\nxrdp_accel_assist_nvenc_encode(struct enc_info *ei, int tex,\n                               void *cdata, int *cdata_bytes,\n                               int flags)\n{\n    NV_ENC_PIC_PARAMS picParams;\n    NV_ENC_LOCK_BITSTREAM lockBitstream;\n    NVENCSTATUS nv_error;\n    enum encoder_result rv;\n\n    /* sync before encoding */\n    glFinish();\n\n    g_memset(&picParams, 0, sizeof(picParams));\n    picParams.version = NV_ENC_PIC_PARAMS_VER;\n    picParams.inputBuffer = ei->mappedResource;\n    picParams.bufferFmt = ei->mappedBufferFmt;\n    picParams.inputWidth = ei->width;\n    picParams.inputHeight = ei->height;\n    picParams.outputBitstream = ei->bitstreamBuffer;\n    picParams.inputTimeStamp = ei->frameCount;\n    picParams.pictureStruct = NV_ENC_PIC_STRUCT_FRAME;\n    picParams.encodePicFlags = NV_ENC_PIC_FLAG_OUTPUT_SPSPPS;\n    if ((flags & XH_ENC_FLAGS_FORCEIDR) || (ei->frameCount < 1))\n    {\n        picParams.encodePicFlags |= NV_ENC_PIC_FLAG_FORCEIDR;\n        LOG(LOG_LEVEL_INFO, \"Forcing NVENC H264 IDR SPSPPS for frame id: %d\",\n            ei->frameCount);\n    }\n    nv_error = g_enc_funcs.nvEncEncodePicture(ei->enc, &picParams);\n    rv = ENCODER_ERROR;\n    if (nv_error == NV_ENC_SUCCESS)\n    {\n        g_memset(&lockBitstream, 0, sizeof(lockBitstream));\n        lockBitstream.version = NV_ENC_LOCK_BITSTREAM_VER;\n        lockBitstream.outputBitstream = ei->bitstreamBuffer;\n        lockBitstream.doNotWait = 0;\n        nv_error = g_enc_funcs.nvEncLockBitstream(ei->enc, &lockBitstream);\n        if (nv_error == NV_ENC_SUCCESS)\n        {\n            if (*cdata_bytes >= ((int) (lockBitstream.bitstreamSizeInBytes)))\n            {\n                g_memcpy(cdata, lockBitstream.bitstreamBufferPtr,\n                         lockBitstream.bitstreamSizeInBytes);\n                *cdata_bytes = lockBitstream.bitstreamSizeInBytes;\n                rv = INCREMENTAL_FRAME_ENCODED;\n            }\n            else\n            {\n                LOG(LOG_LEVEL_ERROR, \"error not enough room %d %d\",\n                    *cdata_bytes,\n                    (int) (lockBitstream.bitstreamSizeInBytes));\n            }\n            g_enc_funcs.nvEncUnlockBitstream(ei->enc,\n                                             lockBitstream.outputBitstream);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_ERROR, \"error nvEncLockBitstream %d\",\n                nv_error);\n        }\n        ei->frameCount++;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"error nvEncEncodePicture %d\", nv_error);\n    }\n    if (rv == INCREMENTAL_FRAME_ENCODED\n            && (picParams.encodePicFlags & NV_ENC_PIC_FLAG_FORCEIDR))\n    {\n        return KEY_FRAME_ENCODED;\n    }\n    return rv;\n}\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist_nvenc.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2022-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _XRDP_ACCEL_ASSIST_NVENC_H\n#define _XRDP_ACCEL_ASSIST_NVENC_H\n\nint\nxrdp_accel_assist_nvenc_init(void);\nint\nxrdp_accel_assist_nvenc_create_encoder(int width, int height, int tex,\n                                       int tex_format, struct enc_info **ei);\nint\nxrdp_accel_assist_nvenc_delete_encoder(struct enc_info *ei);\nenum encoder_result\nxrdp_accel_assist_nvenc_encode(struct enc_info *ei, int tex,\n                               void *cdata, int *cdata_bytes,\n                               int flags);\n\n#endif\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist_shaders.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2022-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/* GLSL shaders\n * this file is not compiled directly, it is included in\n * xrdp_accel_assist_x11.c */\n\nstatic const GLchar g_vs[] = \"\\\nattribute vec4 position;\\n\\\nvoid main(void)\\n\\\n{\\n\\\n    gl_Position = vec4(position.xy, 0.0, 1.0);\\n\\\n}\\n\";\n\nstatic const GLchar g_fs_copy[] = \"\\\nuniform sampler2D tex;\\n\\\nuniform vec2 tex_size;\\n\\\nvoid main(void)\\n\\\n{\\n\\\n    gl_FragColor = texture2D(tex, gl_FragCoord.xy / tex_size);\\n\\\n}\\n\";\n\nstatic const GLchar g_fs_rgb_to_yuv420[] = \"\\\nuniform sampler2D tex;\\n\\\nuniform vec2 tex_size;\\n\\\nuniform vec4 ymath;\\n\\\nuniform vec4 umath;\\n\\\nuniform vec4 vmath;\\n\\\nvoid main(void)\\n\\\n{\\n\\\n    vec4 pix;\\n\\\n    float x;\\n\\\n    float y;\\n\\\n    x = gl_FragCoord.x;\\n\\\n    y = gl_FragCoord.y;\\n\\\n    if (y < tex_size.y)\\n\\\n    {\\n\\\n        pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n        pix.a = 1.0;\\n\\\n        pix = vec4(clamp(dot(ymath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n        gl_FragColor = pix;\\n\\\n    }\\n\\\n    else\\n\\\n    {\\n\\\n        y = floor(y - tex_size.y) * 2.0 + 0.5;\\n\\\n        if (mod(x, 2.0) < 1.0)\\n\\\n        {\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix += texture2D(tex, vec2(x + 1.0, y) / tex_size);\\n\\\n            pix += texture2D(tex, vec2(x, y + 1.0) / tex_size);\\n\\\n            pix += texture2D(tex, vec2(x + 1.0, y + 1.0) / tex_size);\\n\\\n            pix /= 4.0;\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(umath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n        else\\n\\\n        {\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix += texture2D(tex, vec2(x - 1.0, y) / tex_size);\\n\\\n            pix += texture2D(tex, vec2(x, y + 1.0) / tex_size);\\n\\\n            pix += texture2D(tex, vec2(x - 1.0, y + 1.0) / tex_size);\\n\\\n            pix /= 4.0;\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(vmath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n    }\\n\\\n}\\n\";\n\nstatic const GLchar g_fs_rgb_to_yuv422[] = \"\\\nuniform sampler2D tex;\\n\\\nuniform vec2 tex_size;\\n\\\nuniform vec4 ymath;\\n\\\nuniform vec4 umath;\\n\\\nuniform vec4 vmath;\\n\\\nvoid main(void)\\n\\\n{\\n\\\n    vec4 pix;\\n\\\n    vec4 pix1;\\n\\\n    vec4 pixs;\\n\\\n    float x;\\n\\\n    float y;\\n\\\n    x = gl_FragCoord.x;\\n\\\n    x = floor(x) * 2.0 + 0.5;\\n\\\n    y = gl_FragCoord.y;\\n\\\n    pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n    pix1 = texture2D(tex, vec2(x + 1.0, y) / tex_size);\\n\\\n    pixs = (pix + pix1) / 2.0;\\n\\\n    pix.a = 1.0;\\n\\\n    pix1.a = 1.0;\\n\\\n    pixs.a = 1.0;\\n\\\n    pix.r = dot(ymath, pix);\\n\\\n    pix.g = dot(umath, pixs);\\n\\\n    pix.b = dot(ymath, pix1);\\n\\\n    pix.a = dot(vmath, pixs);\\n\\\n    gl_FragColor = clamp(pix, 0.0, 1.0);\\n\\\n}\\n\";\n\nstatic const GLchar g_fs_rgb_to_yuv444[] = \"\\\nuniform sampler2D tex;\\n\\\nuniform vec2 tex_size;\\n\\\nuniform vec4 ymath;\\n\\\nuniform vec4 umath;\\n\\\nuniform vec4 vmath;\\n\\\nvoid main(void)\\n\\\n{\\n\\\n    vec4 pix;\\n\\\n    pix = texture2D(tex, gl_FragCoord.xy / tex_size);\\n\\\n    pix.a = 1.0;\\n\\\n    pix = vec4(dot(vmath, pix), dot(umath, pix), dot(ymath, pix), 1.0);\\n\\\n    gl_FragColor = clamp(pix, 0.0, 1.0);\\n\\\n}\\n\";\n\n/*\nRGB\n    00 10 20 30 40 50 60 70 80 90 A0 B0 C0 D0 E0 F0\n    01 11 21 31 41 51 61 71 81 91 A1 B1 C1 D1 E1 F1\n    02 12 22 32 42 52 62 72 82 92 A2 B2 C2 D2 E2 F2\n    03 13 23 33 43 53 63 73 83 93 A3 B3 C3 D3 E3 F3\n    04 14 24 34 44 54 64 74 84 94 A4 B4 C4 D4 E4 F4\n    05 15 25 35 45 55 65 75 85 95 A5 B5 C5 D5 E5 F5\n    06 16 26 36 46 56 66 76 86 96 A6 B6 C6 D6 E6 F6\n    07 17 27 37 47 57 67 77 87 97 A7 B7 C7 D7 E7 F7\n    08 18 28 38 48 58 68 78 88 98 A8 B8 C8 D8 E8 F8\n    09 19 29 39 49 59 69 79 89 99 A9 B9 C9 D9 E9 F9\n    0A 1A 2A 3A 4A 5A 6A 7A 8A 9A AA BA CA DA EA FA\n    0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AB BB CB DB EB FB\n    0C 1C 2C 3C 4C 5C 6C 7C 8C 9C AC BC CC DC EC FC\n    0D 1D 2D 3D 4D 5D 6D 7D 8D 9D AD BD CD DD ED FD\n    0E 1E 2E 3E 4E 5E 6E 7E 8E 9E AE BE CE DE EE FE\n    0F 1F 2F 3F 4F 5F 6F 7F 8F 9F AF BF CF DF EF FF\n\nMAIN VIEW - NV12\n\n    /---------------------Y-----------------------\\\n    00 10 20 30 40 50 60 70 80 90 A0 B0 C0 D0 E0 F0\n    01 11 21 31 41 51 61 71 81 91 A1 B1 C1 D1 E1 F1\n    ...\n    0F 1F 2F 3F 4F 5F 6F 7F 8F 9F AF BF CF DF EF FF\n\n    /U /V /U /V /U /V /U /V /U /V /U /V /U /V /U /V\n    00 00 20 20 40 40 60 60 80 80 A0 A0 C0 C0 E0 E0\n    02 02 22 22 42 42 62 62 82 82 A2 A2 C2 C2 E2 E2\n    ...\n    0E 0E 2E 2E 4E 4E 6E 6E 8E 8E AE AE CE CE EE EE\n*/\nstatic const GLchar g_fs_rgb_to_yuv420_mv[] = \"\\\nuniform sampler2D tex;\\n\\\nuniform vec2 tex_size;\\n\\\nuniform vec4 ymath;\\n\\\nuniform vec4 umath;\\n\\\nuniform vec4 vmath;\\n\\\nvoid main(void)\\n\\\n{\\n\\\n    vec4 pix;\\n\\\n    float x;\\n\\\n    float y;\\n\\\n    x = gl_FragCoord.x;\\n\\\n    y = gl_FragCoord.y;\\n\\\n    if (y < tex_size.y)\\n\\\n    {\\n\\\n        pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n        pix.a = 1.0;\\n\\\n        pix = vec4(clamp(dot(ymath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n        gl_FragColor = pix;\\n\\\n    }\\n\\\n    else\\n\\\n    {\\n\\\n        y = floor(y - tex_size.y) * 2.0 + 0.5;\\n\\\n        if (mod(x, 2.0) < 1.0)\\n\\\n        {\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(umath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n        else\\n\\\n        {\\n\\\n            pix = texture2D(tex, vec2(x - 1.0, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(vmath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n    }\\n\\\n}\\n\";\n\n/*\nAUXILIARY VIEW - NV12\n\n    /---------------------U-----------------------\\\n    01 11 21 31 41 51 61 71 81 91 A1 B1 C1 D1 E1 F1\n    03 13 23 33 43 53 63 73 83 93 A3 B3 C3 D3 E3 F4\n    ...\n    0F 1F 2F 3F 4F 5F 6F 7F 8F 9F AF BF CF DF EF FF\n    /---------------------V-----------------------\\\n    01 11 21 31 41 51 61 71 81 91 A1 B1 C1 D1 E1 F1\n    03 13 23 33 43 53 63 73 83 93 A3 B3 C3 D3 E3 F4\n    ...\n    0F 1F 2F 3F 4F 5F 6F 7F 8F 9F AF BF CF DF EF FF\n    ... (8 LINES U, 8 LINES V, REPEAT)\n\n    /U /V /U /V /U /V /U /V /U /V /U /V /U /V /U /V\n    10 10 30 30 50 50 70 70 90 90 B0 B0 D0 D0 F0 F0\n    12 12 32 32 52 52 72 72 92 92 B2 B2 D2 D2 F2 F2\n    ...\n    1E 1E 3E 3E 5E 5E 7E 7E 9E 9E BE BE DE DE FE FE\n*/\nstatic const GLchar g_fs_rgb_to_yuv420_av[] = \"\\\nuniform sampler2D tex;\\n\\\nuniform vec2 tex_size;\\n\\\nuniform vec4 umath;\\n\\\nuniform vec4 vmath;\\n\\\nvoid main(void)\\n\\\n{\\n\\\n    vec4 pix;\\n\\\n    float x;\\n\\\n    float y;\\n\\\n    float y1;\\n\\\n    x = gl_FragCoord.x;\\n\\\n    y = gl_FragCoord.y;\\n\\\n    if (y < tex_size.y)\\n\\\n    {\\n\\\n        y1 = mod(y, 16.0);\\n\\\n        if (y1 < 8.0)\\n\\\n        {\\n\\\n            y = floor(y / 16.0) * 8.0 + y1;\\n\\\n            y = floor(y) * 2.0 + 1.5;\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(umath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n        else\\n\\\n        {\\n\\\n            y = floor(y / 16.0) * 8.0 + (y1 - 8.0);\\n\\\n            y = floor(y) * 2.0 + 1.5;\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(vmath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n    }\\n\\\n    else\\n\\\n    {\\n\\\n        y = floor(y - tex_size.y) * 2.0 + 0.5;\\n\\\n        if (mod(x, 2.0) < 1.0)\\n\\\n        {\\n\\\n            pix = texture2D(tex, vec2(x + 1.0, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(umath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n        else\\n\\\n        {\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(vmath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n    }\\n\\\n}\\n\";\n\n/*\nAUXILIARY VIEW V2 - NV12\n\n    /----------U----------\\ /----------V----------\\\n    10 30 50 70 90 B0 D0 F0 10 30 50 70 90 B0 D0 F0\n    11 31 51 71 91 B1 D1 F1 11 31 51 71 91 B1 D1 F1\n    ...\n    1F 3F 5F 7F 9F BF DF FF 1F 3F 5F 7F 9F BF DF FF\n\n    /----------U----------\\ /----------V----------\\\n    01 21 41 61 81 A1 C1 E1 01 21 41 61 81 A1 C1 E1\n    03 23 43 63 83 A3 C3 E3 03 23 43 63 83 A3 C3 E3\n    ...\n    0F 2F 4F 6F 8F AF CF EF 0F 2F 4F 6F 8F AF CF EF\n*/\nstatic const GLchar g_fs_rgb_to_yuv420_av_v2[] = \"\\\nuniform sampler2D tex;\\n\\\nuniform vec2 tex_size;\\n\\\nuniform vec4 umath;\\n\\\nuniform vec4 vmath;\\n\\\nvoid main(void)\\n\\\n{\\n\\\n    vec4 pix;\\n\\\n    float x;\\n\\\n    float y;\\n\\\n    float x1;\\n\\\n    x = gl_FragCoord.x;\\n\\\n    y = gl_FragCoord.y;\\n\\\n    x1 = tex_size.x / 2.0;\\n\\\n    if (y < tex_size.y)\\n\\\n    {\\n\\\n        if (x < x1)\\n\\\n        {\\n\\\n            x = floor(x) * 2.0 + 1.5;\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(umath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n        else\\n\\\n        {\\n\\\n            x = floor(x - x1) * 2.0 + 1.5;\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(vmath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n    }\\n\\\n    else\\n\\\n    {\\n\\\n        y = floor(y - tex_size.y) * 2.0 + 1.5;\\n\\\n        if (x < x1)\\n\\\n        {\\n\\\n            x = floor(x) * 2.0 + 0.5;\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(umath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n        else\\n\\\n        {\\n\\\n            x = floor(x - x1) * 2.0 + 0.5;\\n\\\n            pix = texture2D(tex, vec2(x, y) / tex_size);\\n\\\n            pix.a = 1.0;\\n\\\n            pix = vec4(clamp(dot(vmath, pix), 0.0, 1.0), 0.0, 0.0, 1.0);\\n\\\n            gl_FragColor = pix;\\n\\\n        }\\n\\\n    }\\n\\\n}\\n\";\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist_x11.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2020-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/* Currently nvenc requires GLX because NVidia's EGL does not have\n * EGL_NOK_texture_from_pixmap extension but NVidia's GLX does have\n * GLX_EXT_texture_from_pixmap.  We require one if those,\n * also, va required EGL because it used dma bufs.\n * I do not think any vendor's GLX support dma bufs */\n/* Things like render on one GPU and encode with another is possible\n * but not supported now. */\n/* One suggestion about dma bufs and GLX, one can use the DRI3\n * extension to get dma buffs for pixmaps */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n#include <X11/Xlib.h>\n\n#include <epoxy/gl.h>\n\n#include \"arch.h\"\n#include \"os_calls.h\"\n#include \"string_calls.h\"\n#include \"xrdp_accel_assist.h\"\n#include \"xrdp_accel_assist_x11.h\"\n#include \"xrdp_accel_assist_glx.h\"\n#include \"xrdp_accel_assist_egl.h\"\n#include \"log.h\"\n\n/* set to 1 to dump bmp files into /tmp */\n#define XR_DUMP_FRAMEBUFFER 0\n\n/* set to 1 to dump bmp files into /tmp */\n#define XR_DUMP_PIXMAP 0\n\n#if defined(XRDP_NVENC)\n#include \"xrdp_accel_assist_nvenc.h\"\n#endif\n\n/* X11 */\nDisplay *g_display = NULL;\nstatic int g_x_socket = 0;\nint g_screen_num = 0;\nstatic Screen *g_screen = NULL;\nWindow g_root_window = None;\nstatic Visual *g_vis = NULL;\nstatic GC g_gc;\n\n/* encoders: nvenc or va */\nstruct enc_funcs\n{\n    int (*init)(void);\n    int (*create_enc)(int width, int height, int tex, int tex_format,\n                      struct enc_info **ei);\n    int (*destroy_enc)(struct enc_info *ei);\n    enum encoder_result (*encode)(struct enc_info *ei, int tex,\n                                  void *cdata, int *cdata_bytes,\n                                  int flags);\n};\n\nstatic struct enc_funcs g_enc_funcs[] =\n{\n    {\n        NULL, NULL, NULL, NULL\n    },\n    {\n#if defined(XRDP_NVENC)\n        xrdp_accel_assist_nvenc_init,\n        xrdp_accel_assist_nvenc_create_encoder,\n        xrdp_accel_assist_nvenc_delete_encoder,\n        xrdp_accel_assist_nvenc_encode\n#else\n        NULL, NULL, NULL, NULL\n#endif\n    }\n};\n\n/* GL interface: EGL or GLX */\nstruct inf_funcs\n{\n    int (*init)(void);\n    int (*create_image)(Pixmap pixmap, inf_image_t *inf_image);\n    int (*destroy_image)(inf_image_t inf_image);\n    int (*bind_tex_image)(inf_image_t inf_image);\n    int (*release_tex_image)(inf_image_t inf_image);\n};\n\nstatic struct inf_funcs g_inf_funcs[] =\n{\n    {\n        xrdp_accel_assist_inf_egl_init,\n        xrdp_accel_assist_inf_egl_create_image,\n        xrdp_accel_assist_inf_egl_destroy_image,\n        xrdp_accel_assist_inf_egl_bind_tex_image,\n        xrdp_accel_assist_inf_egl_release_tex_image\n    },\n    {\n        xrdp_accel_assist_inf_glx_init,\n        xrdp_accel_assist_inf_glx_create_image,\n        xrdp_accel_assist_inf_glx_destroy_image,\n        xrdp_accel_assist_inf_glx_bind_tex_image,\n        xrdp_accel_assist_inf_glx_release_tex_image\n    }\n};\n\n/* 0 = EGL, 1 = GLX */\n/* 0 = va, 1 = nvenc */\n#define INF_EGL     0\n#define INF_GLX     1\n#define ENC_VA      0\n#define ENC_NVENC   1\nstatic int g_inf = INF_EGL;\nstatic int g_enc = ENC_VA;\n\nstruct mon_info\n{\n    int width;\n    int height;\n    Pixmap pixmap;\n    inf_image_t inf_image;\n    GLuint bmp_texture;\n    GLuint enc_texture;\n    int tex_format;\n    GLfloat *(*get_vertices)(GLuint *vertices_bytes,\n                             GLuint *vertices_pointes,\n                             int num_crects, struct xh_rect *crects,\n                             int left, int top, int width, int height);\n    struct xh_rect viewport;\n    struct enc_info *ei;\n};\n\n#define MAX_MON 16\nstatic struct mon_info g_mons[MAX_MON];\n\nstatic GLuint g_quad_vao = 0;\nstatic GLuint g_fb = 0;\n\n#define XH_SHADERCOPY           0\n#define XH_SHADERRGB2YUV420     1\n#define XH_SHADERRGB2YUV422     2\n#define XH_SHADERRGB2YUV444     3\n#define XH_SHADERRGB2YUV420MV   4\n#define XH_SHADERRGB2YUV420AV   5\n#define XH_SHADERRGB2YUV420AVV2 6\n\n#define XH_NUM_SHADERS 7\n\nstruct shader_info\n{\n    GLuint vertex_shader;\n    GLuint fragment_shader;\n    GLuint program;\n    GLint tex_loc;\n    GLint tex_size_loc;\n    GLint ymath_loc;\n    GLint umath_loc;\n    GLint vmath_loc;\n    int current_matrix;\n};\nstatic struct shader_info g_si[XH_NUM_SHADERS];\n\n/* *INDENT-OFF* */\nstatic const GLfloat g_vertices[] =\n{\n    -1.0f,  1.0f,\n    -1.0f, -1.0f,\n     1.0f,  1.0f,\n     1.0f, -1.0f\n};\n/* *INDENT-ON* */\n\nstruct rgb2yuv_matrix\n{\n    GLfloat ymath[4];\n    GLfloat umath[4];\n    GLfloat vmath[4];\n};\n\nstatic struct rgb2yuv_matrix g_rgb2yux_matrix[3] =\n{\n    {\n        /* yuv bt601 lagecy */\n        {  66.0 / 256.0,  129.0 / 256.0,   25.0 / 256.0,   16.0 / 256.0 },\n        { -38.0 / 256.0,  -74.0 / 256.0,  112.0 / 256.0,  128.0 / 256.0 },\n        { 112.0 / 256.0,  -94.0 / 256.0,  -18.0 / 256.0,  128.0 / 256.0 }\n    },\n    {\n        /* yuv bt709 full range, used in gfx h264 */\n        {  54.0 / 256.0,  183.0 / 256.0,   18.0 / 256.0,    0.0 / 256.0 },\n        { -29.0 / 256.0,  -99.0 / 256.0,  128.0 / 256.0,  128.0 / 256.0 },\n        { 128.0 / 256.0, -116.0 / 256.0,  -12.0 / 256.0,  128.0 / 256.0 }\n    },\n    {\n        /* yuv remotefx and gfx progressive remotefx */\n        {   0.299000,       0.587000,       0.114000,       0.0 },\n        {  -0.168935,      -0.331665,       0.500590,       0.5 },\n        {   0.499830,      -0.418531,      -0.081282,       0.5 }\n    }\n};\n\n#include \"xrdp_accel_assist_shaders.c\"\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_x11_init(void)\n{\n    const GLchar *vsource[XH_NUM_SHADERS];\n    const GLchar *fsource[XH_NUM_SHADERS];\n    GLint linked;\n    GLint compiled;\n    GLint vlength;\n    GLint flength;\n    GLuint quad_vbo;\n    int index;\n    int gl_ver;\n    int major_opcode, first_event, first_error;\n\n    /* x11 */\n    g_display = XOpenDisplay(0);\n    if (g_display == NULL)\n    {\n        return 1;\n    }\n    g_x_socket = XConnectionNumber(g_display);\n    g_screen_num = DefaultScreen(g_display);\n    g_screen = ScreenOfDisplay(g_display, g_screen_num);\n    g_root_window = RootWindowOfScreen(g_screen);\n    g_vis = XDefaultVisual(g_display, g_screen_num);\n    g_gc = DefaultGC(g_display, 0);\n    if (XQueryExtension(g_display, \"NV-CONTROL\", &major_opcode, &first_event,\n                        &first_error))\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_init: \"\n            \"detected NVIDIA XServer\");\n        g_inf = INF_GLX;\n        g_enc = ENC_NVENC;\n        if (g_inf_funcs[g_inf].init() != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_accel_assist_x11_init: \"\n                \"GLX init failed\");\n            return 1;\n        }\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_init: using GLX\");\n    }\n    else\n    {\n        g_inf = INF_EGL;\n        g_enc = ENC_VA;\n        if (g_inf_funcs[g_inf].init() != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"xrdp_accel_assist_x11_init: \"\n                \"EGL init failed\");\n            return 1;\n        }\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_init: using EGL\");\n    }\n    gl_ver = epoxy_gl_version();\n    LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_init: gl_ver %d\", gl_ver);\n    if (gl_ver < 30)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_accel_assist_x11_init: \"\n            \"gl_ver too old %d\", gl_ver);\n        return 1;\n    }\n    LOG(LOG_LEVEL_INFO, \"vendor: %s\",\n        (const char *) glGetString(GL_VENDOR));\n    LOG(LOG_LEVEL_INFO, \"version: %s\",\n        (const char *) glGetString(GL_VERSION));\n    /* create vertex array */\n    glGenVertexArrays(1, &g_quad_vao);\n    glBindVertexArray(g_quad_vao);\n    glGenBuffers(1, &quad_vbo);\n    glBindBuffer(GL_ARRAY_BUFFER, quad_vbo);\n    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertices), g_vertices,\n                 GL_STATIC_DRAW);\n    glEnableVertexAttribArray(0);\n    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, NULL);\n    glGenFramebuffers(1, &g_fb);\n    glBindBuffer(GL_ARRAY_BUFFER, 0);\n    glBindVertexArray(0);\n    glDeleteBuffers(1, &quad_vbo);\n\n    /* create copy shader */\n    vsource[XH_SHADERCOPY] = g_vs;\n    fsource[XH_SHADERCOPY] = g_fs_copy;\n    /* create rgb2yuv shader */\n    vsource[XH_SHADERRGB2YUV420] = g_vs;\n    fsource[XH_SHADERRGB2YUV420] = g_fs_rgb_to_yuv420;\n    /* create rgb2yuv shader */\n    vsource[XH_SHADERRGB2YUV422] = g_vs;\n    fsource[XH_SHADERRGB2YUV422] = g_fs_rgb_to_yuv422;\n    /* create rgb2yuv shader */\n    vsource[XH_SHADERRGB2YUV444] = g_vs;\n    fsource[XH_SHADERRGB2YUV444] = g_fs_rgb_to_yuv444;\n\n    vsource[XH_SHADERRGB2YUV420MV] = g_vs;\n    fsource[XH_SHADERRGB2YUV420MV] = g_fs_rgb_to_yuv420_mv;\n\n    vsource[XH_SHADERRGB2YUV420AV] = g_vs;\n    fsource[XH_SHADERRGB2YUV420AV] = g_fs_rgb_to_yuv420_av;\n\n    vsource[XH_SHADERRGB2YUV420AVV2] = g_vs;\n    fsource[XH_SHADERRGB2YUV420AVV2] = g_fs_rgb_to_yuv420_av_v2;\n\n    for (index = 0; index < XH_NUM_SHADERS; index++)\n    {\n        g_si[index].vertex_shader = glCreateShader(GL_VERTEX_SHADER);\n        g_si[index].fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);\n        vlength = g_strlen(vsource[index]);\n        flength = g_strlen(fsource[index]);\n        glShaderSource(g_si[index].vertex_shader, 1,\n                       &(vsource[index]), &vlength);\n        glShaderSource(g_si[index].fragment_shader, 1,\n                       &(fsource[index]), &flength);\n        glCompileShader(g_si[index].vertex_shader);\n        glGetShaderiv(g_si[index].vertex_shader, GL_COMPILE_STATUS,\n                      &compiled);\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_init: \"\n            \"vertex_shader compiled %d\", compiled);\n        glCompileShader(g_si[index].fragment_shader);\n        glGetShaderiv(g_si[index].fragment_shader, GL_COMPILE_STATUS,\n                      &compiled);\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_init: \"\n            \"fragment_shader compiled %d\", compiled);\n        g_si[index].program = glCreateProgram();\n        glAttachShader(g_si[index].program, g_si[index].vertex_shader);\n        glAttachShader(g_si[index].program, g_si[index].fragment_shader);\n        glLinkProgram(g_si[index].program);\n        glGetProgramiv(g_si[index].program, GL_LINK_STATUS, &linked);\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_init: linked %d\", linked);\n        g_si[index].tex_loc =\n            glGetUniformLocation(g_si[index].program, \"tex\");\n        g_si[index].tex_size_loc =\n            glGetUniformLocation(g_si[index].program, \"tex_size\");\n        g_si[index].ymath_loc =\n            glGetUniformLocation(g_si[index].program, \"ymath\");\n        g_si[index].umath_loc =\n            glGetUniformLocation(g_si[index].program, \"umath\");\n        g_si[index].vmath_loc =\n            glGetUniformLocation(g_si[index].program, \"vmath\");\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_init: tex_loc %d \"\n            \"tex_size_loc %d ymath_loc %d umath_loc %d vmath_loc %d\",\n            g_si[index].tex_loc, g_si[index].tex_size_loc,\n            g_si[index].ymath_loc, g_si[index].umath_loc,\n            g_si[index].vmath_loc);\n        /* set default matrix */\n        glUseProgram(g_si[index].program);\n        if (g_si[index].ymath_loc >= 0)\n        {\n            glUniform4fv(g_si[index].ymath_loc, 1, g_rgb2yux_matrix[1].ymath);\n        }\n        if (g_si[index].umath_loc >= 0)\n        {\n            glUniform4fv(g_si[index].umath_loc, 1, g_rgb2yux_matrix[1].umath);\n        }\n        if (g_si[index].vmath_loc >= 0)\n        {\n            glUniform4fv(g_si[index].vmath_loc, 1, g_rgb2yux_matrix[1].vmath);\n        }\n        glUseProgram(0);\n    }\n    g_memset(g_mons, 0, sizeof(g_mons));\n    if (g_enc_funcs[g_enc].init() != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_accel_assist_x11_init: \"\n            \"encoder init failed\");\n        return 1;\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_x11_get_wait_objs(intptr_t *objs, int *obj_count)\n{\n    objs[*obj_count] = g_x_socket;\n    (*obj_count)++;\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_x11_check_wait_objs(void)\n{\n    XEvent xevent;\n\n    while (XPending(g_display) > 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_check_wait_objs: \"\n                  \"loop\");\n        XNextEvent(g_display, &xevent);\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_x11_delete_all_pixmaps(void)\n{\n    int index;\n    struct mon_info *mi;\n\n    for (index = 0; index < MAX_MON; index++)\n    {\n        mi = g_mons + index;\n        if (mi->pixmap != 0)\n        {\n            g_enc_funcs[g_enc].destroy_enc(mi->ei);\n            glDeleteTextures(1, &(mi->bmp_texture));\n            glDeleteTextures(1, &(mi->enc_texture));\n            g_inf_funcs[g_inf].destroy_image(mi->inf_image);\n            XFreePixmap(g_display, mi->pixmap);\n            mi->pixmap = 0;\n        }\n    }\n    return 0;\n}\n\n/*****************************************************************************/\nstatic GLfloat *\nget_vertices_all(GLuint *vertices_bytes, GLuint *vertices_pointes,\n                 int num_crects, struct xh_rect *crects,\n                 int left, int top, int width, int height)\n{\n    GLfloat *vertices;\n\n    (void)num_crects;\n    (void)crects;\n    (void)width;\n    (void)height;\n\n    vertices = g_new(GLfloat, 12);\n    if (vertices == NULL)\n    {\n        return NULL;\n    }\n    vertices[0]  = -1;\n    vertices[1]  =  1;\n    vertices[2]  = -1;\n    vertices[3]  = -1;\n    vertices[4]  =  1;\n    vertices[5]  =  1;\n    vertices[6]  = -1;\n    vertices[7]  = -1;\n    vertices[8]  =  1;\n    vertices[9]  =  1;\n    vertices[10] =  1;\n    vertices[11] = -1;\n    *vertices_bytes = sizeof(GLfloat) * 12;\n    *vertices_pointes = 6;\n    return vertices;\n}\n\n/*****************************************************************************/\nstatic GLfloat *\nget_vertices420(GLuint *vertices_bytes, GLuint *vertices_pointes,\n                int num_crects, struct xh_rect *crects,\n                int left, int top, int width, int height)\n{\n    GLfloat *vertices;\n    GLfloat *vert;\n    GLfloat x1;\n    GLfloat x2;\n    GLfloat y1;\n    GLfloat y2;\n    int index;\n    GLfloat fwidth;\n    GLfloat fheight;\n    const GLfloat fac13 = 1.0 / 3.0;\n    const GLfloat fac23 = 2.0 / 3.0;\n    const GLfloat fac43 = 4.0 / 3.0;\n    struct xh_rect *crect;\n\n    if (num_crects < 1)\n    {\n        return get_vertices_all(vertices_bytes, vertices_pointes,\n                                num_crects, crects, left, top, width, height);\n    }\n    vertices = g_new(GLfloat, num_crects * 24);\n    if (vertices == NULL)\n    {\n        return NULL;\n    }\n    fwidth = width  / 2.0;\n    fheight = height / 2.0;\n    for (index = 0; index < num_crects; index++)\n    {\n        crect = crects + index;\n        LOG_DEVEL(LOG_LEVEL_INFO, \"get_vertices420: \"\n                  \"rect index %d x %d y %d w %d h %d\",\n                  index, crect->x, crect->y, crect->w, crect->h);\n        x1 = (crect->x - left) / fwidth;\n        y1 = (crect->y - top) / fheight;\n        x2 = ((crect->x - left) + crect->w) / fwidth;\n        y2 = ((crect->y - top) + crect->h) / fheight;\n        vert = vertices + index * 24;\n        /* y box */\n        vert[0]  =  x1 - 1.0;\n        vert[1]  =  y1 * fac23 - 1.0;\n        vert[2]  =  x1 - 1.0;\n        vert[3]  =  y2 * fac23 - 1.0;\n        vert[4]  =  x2 - 1.0;\n        vert[5]  =  y1 * fac23 - 1.0;\n        vert[6]  =  x1 - 1.0;\n        vert[7]  =  y2 * fac23 - 1.0;\n        vert[8]  =  x2 - 1.0;\n        vert[9]  =  y1 * fac23 - 1.0;\n        vert[10] =  x2 - 1.0;\n        vert[11] =  y2 * fac23 - 1.0;\n        /* uv box */\n        vert[12] =  x1 - 1.0;\n        vert[13] = (y1 * fac13 + fac43) - 1.0;\n        vert[14] =  x1 - 1.0;\n        vert[15] = (y2 * fac13 + fac43) - 1.0;\n        vert[16] =  x2 - 1.0;\n        vert[17] = (y1 * fac13 + fac43) - 1.0;\n        vert[18] =  x1  - 1.0;\n        vert[19] = (y2 * fac13 + fac43) - 1.0;\n        vert[20] =  x2 - 1.0;\n        vert[21] = (y1 * fac13 + fac43) - 1.0;\n        vert[22] =  x2 - 1.0;\n        vert[23] = (y2 * fac13 + fac43) - 1.0;\n    }\n    *vertices_bytes = sizeof(GLfloat) * num_crects * 24;\n    *vertices_pointes = num_crects * 12;\n    return vertices;\n}\n\n/*****************************************************************************/\nstatic GLfloat *\nget_vertices444(GLuint *vertices_bytes, GLuint *vertices_pointes,\n                int num_crects, struct xh_rect *crects,\n                int left, int top, int width, int height)\n{\n    GLfloat *vertices;\n    GLfloat *vert;\n    GLfloat x1;\n    GLfloat x2;\n    GLfloat y1;\n    GLfloat y2;\n    int index;\n    GLfloat fwidth;\n    GLfloat fheight;\n    struct xh_rect *crect;\n\n    if (num_crects < 1)\n    {\n        return get_vertices_all(vertices_bytes, vertices_pointes,\n                                num_crects, crects, left, top, width, height);\n    }\n    vertices = g_new(GLfloat, num_crects * 12);\n    if (vertices == NULL)\n    {\n        return NULL;\n    }\n    fwidth = width  / 2.0;\n    fheight = height / 2.0;\n    for (index = 0; index < num_crects; index++)\n    {\n        crect = crects + index;\n        x1 = (crect->x - left) / fwidth;\n        y1 = (crect->y - top) / fheight;\n        x2 = ((crect->x - left) + crect->w) / fwidth;\n        y2 = ((crect->y - top) + crect->h) / fheight;\n        vert = vertices + index * 12;\n        vert[0]  = x1 - 1.0;\n        vert[1]  = y1 - 1.0;\n        vert[2]  = x1 - 1.0;\n        vert[3]  = y2 - 1.0;\n        vert[4]  = x2 - 1.0;\n        vert[5]  = y1 - 1.0;\n        vert[6]  = x1 - 1.0;\n        vert[7]  = y2 - 1.0;\n        vert[8]  = x2 - 1.0;\n        vert[9]  = y1 - 1.0;\n        vert[10] = x2 - 1.0;\n        vert[11] = y2 - 1.0;\n    }\n    *vertices_bytes = sizeof(GLfloat) * num_crects * 12;\n    *vertices_pointes = num_crects * 6;\n    return vertices;\n}\n\n/*****************************************************************************/\nint\nxrdp_accel_assist_x11_create_pixmap(int width, int height, int magic,\n                                    int con_id, int mon_id)\n{\n    struct mon_info *mi;\n    Pixmap pixmap;\n    XImage *ximage;\n    int img[64];\n    inf_image_t inf_image;\n    GLuint bmp_texture;\n    GLuint enc_texture;\n\n    mi = g_mons + mon_id % MAX_MON;\n    if (mi->pixmap != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_accel_assist_x11_create_pixmap: \"\n            \"error already setup\");\n        return 1;\n    }\n    LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_create_pixmap: \"\n        \"width %d height %d, magic 0x%8.8x, con_id %d mod_id %d\",\n        width, height, magic, con_id, mon_id);\n    pixmap = XCreatePixmap(g_display, g_root_window, width, height, 24);\n    LOG(LOG_LEVEL_INFO, \"pixmap %d\", (int) pixmap);\n\n    if (g_inf_funcs[g_inf].create_image(pixmap, &inf_image) != 0)\n    {\n        return 1;\n    }\n    LOG(LOG_LEVEL_INFO, \"inf_image %p\", (void *) inf_image);\n\n    g_memset(img, 0, sizeof(img));\n    img[0] = magic;\n    img[1] = con_id;\n    img[2] = mon_id;\n    ximage = XCreateImage(g_display, g_vis, 24, ZPixmap, 0, (char *) img,\n                          4, 4, 32, 0);\n    XPutImage(g_display, pixmap, g_gc, ximage, 0, 0, 0, 0, 4, 4);\n    XFree(ximage);\n\n    glEnable(GL_TEXTURE_2D);\n    /* texture that gets encoded */\n    glGenTextures(1, &enc_texture);\n    glBindTexture(GL_TEXTURE_2D, enc_texture);\n    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\n    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\n    if (g_enc == ENC_NVENC)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_create_pixmap: \"\n            \"using XH_YUV420\");\n        mi->tex_format = XH_YUV420;\n        glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height * 3 / 2, 0,\n                     GL_RED, GL_UNSIGNED_BYTE, NULL);\n        mi->get_vertices = get_vertices420;\n        mi->viewport.x = 0;\n        mi->viewport.y = 0;\n        mi->viewport.w = width;\n        mi->viewport.h = height * 3 / 2;\n    }\n    else if (g_enc == ENC_VA)\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_create_pixmap: \"\n            \"using XH_YUV422\");\n        mi->tex_format = XH_YUV422;\n        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width / 2, height, 0,\n                     GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, NULL);\n        mi->get_vertices = get_vertices444; /* same as 444 */\n        mi->viewport.x = 0;\n        mi->viewport.y = 0;\n        mi->viewport.w = width / 2;\n        mi->viewport.h = height;\n    }\n    else\n    {\n        LOG(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_create_pixmap: \"\n            \"using XH_YUV444\");\n        mi->tex_format = XH_YUV444;\n        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,\n                     GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, NULL);\n        mi->get_vertices = get_vertices444;\n        mi->viewport.x = 0;\n        mi->viewport.y = 0;\n        mi->viewport.w = width;\n        mi->viewport.h = height;\n    }\n    /* texture that binds with pixmap */\n    glGenTextures(1, &bmp_texture);\n    glBindTexture(GL_TEXTURE_2D, bmp_texture);\n    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\n    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\n    glBindTexture(GL_TEXTURE_2D, 0);\n\n    if (g_enc_funcs[g_enc].create_enc(width, height,\n                                      enc_texture, mi->tex_format,\n                                      &(mi->ei)) != 0)\n    {\n        return 1;\n    }\n\n    mi->pixmap = pixmap;\n    mi->inf_image = inf_image;\n    mi->enc_texture = enc_texture;\n    mi->width = width;\n    mi->height = height;\n    mi->bmp_texture = bmp_texture;\n\n    return 0;\n}\n\n#if XR_DUMP_FRAMEBUFFER\n\nstatic int g_framebuffer_file_index = 0;\n\n/*****************************************************************************/\nstatic int\nsave_fb_to_file(int width, int height)\n{\n    char *pixels;\n    char filename[256];\n\n    pixels = (char *) g_malloc(width * height * 4, 0);\n    if (pixels != NULL)\n    {\n        glReadPixels(0, 0, width / 2, height, GL_BGRA,\n                     GL_UNSIGNED_INT_8_8_8_8_REV, pixels);\n        snprintf(filename, 255, \"/tmp/gl_surface%8.8x.bmp\",\n                 g_framebuffer_file_index++);\n        g_save_to_bmp(filename, pixels, width * 2, width / 2, height, 24, 32);\n        g_free(pixels);\n    }\n    return 0;\n}\n\n#endif\n\n/*****************************************************************************/\nstatic void\nxrdp_accel_assist_x11_run_shader(int left, int top, int width, int height,\n                                 struct mon_info *mi,\n                                 struct shader_info *si,\n                                 int num_crects, struct xh_rect *crects)\n{\n    GLuint vao;\n    GLuint vbo;\n    GLfloat *vertices;\n    GLuint vertices_bytes;\n    GLuint vertices_pointes;\n\n    /* rgb to yuv */\n    glEnable(GL_TEXTURE_2D);\n    glActiveTexture(GL_TEXTURE0);\n    glBindTexture(GL_TEXTURE_2D, mi->bmp_texture);\n    g_inf_funcs[g_inf].bind_tex_image(mi->inf_image);\n    glBindFramebuffer(GL_FRAMEBUFFER, g_fb);\n    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,\n                           GL_TEXTURE_2D, mi->enc_texture, 0);\n    glUseProgram(si->program);\n    /* setup vertices from crects */\n    vertices = mi->get_vertices(&vertices_bytes, &vertices_pointes,\n                                num_crects, crects,\n                                left, top, width, height);\n    if (vertices == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_accel_assist_x11_run_shader: \"\n            \"error get_vertices failed num_crects %d\",\n            num_crects);\n        return;\n    }\n    glGenVertexArrays(1, &vao);\n    glGenBuffers(1, &vbo);\n    glBindVertexArray(vao);\n    glBindBuffer(GL_ARRAY_BUFFER, vbo);\n    glBufferData(GL_ARRAY_BUFFER, vertices_bytes, vertices, GL_STATIC_DRAW);\n    glEnableVertexAttribArray(0);\n    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, NULL);\n    /* uniforms */\n    glUniform2f(si->tex_size_loc, mi->width, mi->height);\n    /* viewport and draw */\n    glViewport(mi->viewport.x, mi->viewport.y, mi->viewport.w, mi->viewport.h);\n    glDrawArrays(GL_TRIANGLES, 0, vertices_pointes);\n    /* cleanup */\n    glBindBuffer(GL_ARRAY_BUFFER, 0);\n    glBindVertexArray(0);\n    glDeleteBuffers(1, &vbo);\n    glDeleteVertexArrays(1, &vao);\n    g_free(vertices);\n#if XR_DUMP_FRAMEBUFFER\n    save_fb_to_file(width, height);\n#endif\n    glBindFramebuffer(GL_FRAMEBUFFER, 0);\n    g_inf_funcs[g_inf].release_tex_image(mi->inf_image);\n    glBindTexture(GL_TEXTURE_2D, 0);\n    glUseProgram(0);\n}\n\n#if XR_DUMP_PIXMAP\n\nstatic int g_pixmap_file_index = 0;\n\n/*****************************************************************************/\nstatic int\nsave_pixmap_to_file(Pixmap pix, int width, int height)\n{\n    XImage *image;\n    char filename[256];\n\n    image = XGetImage(g_display, pix, 0, 0, width, height, AllPlanes, ZPixmap);\n    if (image != NULL)\n    {\n        snprintf(filename, 255, \"/tmp/pixmap%8.8x.bmp\", g_pixmap_file_index++);\n        g_save_to_bmp(filename, image->data, width * 4, width, height, 24, 32);\n        XFree(image);\n    }\n    return 0;\n}\n#endif\n\n/*****************************************************************************/\nenum encoder_result\nxrdp_accel_assist_x11_encode_pixmap(int left, int top, int width, int height,\n                                    int mon_id, int num_crects,\n                                    struct xh_rect *crects,\n                                    void *cdata, int *cdata_bytes,\n                                    int flags)\n{\n    struct mon_info *mi;\n    struct shader_info *si;\n    enum encoder_result rv;\n\n    mi = g_mons + mon_id % MAX_MON;\n    LOG_DEVEL(LOG_LEVEL_INFO, \"xrdp_accel_assist_x11_encode_pixmap: \"\n              \"left %d top %d width %d height %d mon_id %d\",\n              left, top, width, height, mon_id);\n    if ((width != mi->width) || (height != mi->height))\n    {\n        LOG(LOG_LEVEL_ERROR, \"xrdp_accel_assist_x11_encode_pixmap: \"\n            \"error width %d should be %d \"\n            \"height %d should be %d\",\n            width, mi->width, height, mi->height);\n        return ENCODER_ERROR;\n    }\n#if XR_DUMP_PIXMAP\n    save_pixmap_to_file(mi->pixmap, width, height);\n#endif\n    si = g_si + mi->tex_format % XH_NUM_SHADERS;\n    xrdp_accel_assist_x11_run_shader(left, top, width, height, mi, si,\n                                     num_crects, crects);\n    /* flush before encoding, let encoders call glFinish() as needed */\n    XFlush(g_display);\n    /* encode */\n    rv = g_enc_funcs[g_enc].encode(mi->ei, mi->enc_texture,\n                                   cdata, cdata_bytes, flags);\n    return rv;\n}\n"
  },
  {
    "path": "xrdp_accel_assist/xrdp_accel_assist_x11.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2020-2024\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef _XRDP_ACCEL_ASSIST_X11_H\n#define _XRDP_ACCEL_ASSIST_X11_H\n\n/* generic type that can hold either a GLXPixmap(XID, unsigned int or long)\n * or EGLSurface(void*) */\ntypedef intptr_t inf_image_t;\n\n/* forward declaration used in xrdp_accel_assist_nvenc and\n   xrdp_accel_assist_yami */\nstruct enc_info;\n\nint\nxrdp_accel_assist_x11_init(void);\nint\nxrdp_accel_assist_x11_get_wait_objs(intptr_t *objs, int *obj_count);\nint\nxrdp_accel_assist_x11_check_wait_objs(void);\nint\nxrdp_accel_assist_x11_delete_all_pixmaps(void);\nint\nxrdp_accel_assist_x11_create_pixmap(int width, int height, int magic,\n                                    int con_id, int mon_id);\nenum encoder_result\nxrdp_accel_assist_x11_encode_pixmap(int left, int top, int width, int height,\n                                    int mon_id, int num_crects,\n                                    struct xh_rect *crects,\n                                    void *cdata, int *cdata_bytes,\n                                    int flags);\n\n#endif\n"
  },
  {
    "path": "xrdpapi/Makefile.am",
    "content": "EXTRA_DIST = \\\n  simple.c \\\n  connectmon.c \\\n  vrplayer.c \\\n  vrplayer.mk\n\nAM_CPPFLAGS = \\\n  -DXRDP_SOCKET_ROOT_PATH=\\\"${socketdir}\\\" \\\n  -I$(top_srcdir)/common\n\nmodule_LTLIBRARIES = \\\n  libxrdpapi.la\n\nlibxrdpapi_la_SOURCES = \\\n  xrdpapi.c \\\n  xrdpapi.h\n\nlibxrdpapi_la_LIBADD = \\\n  $(top_builddir)/common/libcommon.la\n\n# Build the 'simple' example programs, so they are added to the CI\nnoinst_PROGRAMS = \\\n  xrdp-xrdpapi-connectmon \\\n  xrdp-xrdpapi-simple\n\nxrdp_xrdpapi_connectmon_SOURCES = \\\n  connectmon.c\n\n# If you change this, update the standalone build instructions in connectmon.c\nxrdp_xrdpapi_connectmon_LDADD = \\\n  libxrdpapi.la \\\n  $(top_builddir)/common/libcommon.la\n\nxrdp_xrdpapi_simple_SOURCES = \\\n  simple.c\n\n# If you change this, update the standalone build instructions in simple.c\nxrdp_xrdpapi_simple_LDADD = \\\n  libxrdpapi.la \\\n  $(top_builddir)/common/libcommon.la\n"
  },
  {
    "path": "xrdpapi/connectmon.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2013\n * Copyright (C) Laxmikant Rashinkar 2012-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * sample program to demonstrate use of xrdpapi connection monitoring\n *\n */\n\n/*\n * build instructions:\n *     gcc connectmon.c -o connectmon \\\n *         -I.. -I../common -L./.libs -L../common/.libs \\\n *         -DHAVE_CONFIG_H -lxrdpapi -lcommon\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdpapi.h\"\n#include \"log.h\"\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <poll.h>\n#include <errno.h>\n\n/******************************************************************************/\nstatic void\nprint_current_connection_state(void)\n{\n    WTS_CONNECTSTATE_CLASS connect_state;\n    char buff[64];\n    const char *statestr = \"unavailable\";\n    if (WTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE,\n                                    WTS_CURRENT_SESSION,\n                                    WTSConnectState,\n                                    &connect_state, NULL, NULL))\n    {\n        if (connect_state == WTSConnected)\n        {\n            statestr = \"connected\";\n        }\n        else if (connect_state == WTSDisconnected)\n        {\n            statestr = \"disconnected\";\n        }\n        else\n        {\n            snprintf(buff, sizeof(buff),\n                     \"unrecognised val %d\", (int)connect_state);\n            statestr = buff;\n        }\n    }\n    printf(\"Current connect state is %s\\n\", statestr);\n}\n\n/******************************************************************************/\nstatic LRESULT\ncallback (void *cbdata, UINT msg, WPARAM wParam, LPARAM lParam)\n{\n    LRESULT result = 1;\n    int *countptr = (int *)cbdata;\n\n    switch (wParam)\n    {\n        case WTS_REMOTE_CONNECT:\n            ++*countptr;\n            printf(\"State change %d : Connect to session\\n\", *countptr);\n            print_current_connection_state();\n            break;\n\n        case WTS_REMOTE_DISCONNECT:\n            ++*countptr;\n            printf(\"State change %d : Disconnect from session\\n\", *countptr);\n            print_current_connection_state();\n            break;\n\n        default:\n            printf(\"** Unexpected callback reason %ld\\n\", (long)wParam);\n            result = 0;\n    }\n\n    return result;\n}\n\n/******************************************************************************/\nint\nmain(int argc, char **argv)\n{\n    int result = 0;\n    int changes = 10;\n    int fd;\n    struct log_config *lc;\n\n    if ((lc = log_config_init_for_console(LOG_LEVEL_DEBUG, NULL)) != NULL)\n    {\n        log_start_from_param(lc);\n    }\n\n    if (argc > 1 && atoi(argv[1]) >= 0)\n    {\n        changes = atoi(argv[1]);\n        if (changes > 1000)\n        {\n            changes = 1000; // Use 0 for more than this\n        }\n    }\n    if (changes > 0)\n    {\n        printf(\"Connection monitor : exiting after %d state changes\\n\", changes);\n    }\n    else\n    {\n        printf(\"Connection monitor\\n\");\n    }\n\n    print_current_connection_state();\n\n\n    if (!WTSRegisterSessionNotificationEx(WTS_CURRENT_SERVER_HANDLE, &fd, 0, NULL))\n    {\n        result = 1; // Error occurred (should be logged)\n    }\n    else\n    {\n        int count = 0;\n        while (result == 0)\n        {\n            struct pollfd pollarg =\n            {\n                .fd = fd,\n                .events = (POLLIN | POLLERR),\n                .revents = 0\n            };\n            int pollstat;\n            LRESULT cbresult;\n\n            if (changes > 0 && count >= changes)\n            {\n                break;\n            }\n\n            if ((pollstat = poll(&pollarg, 1, -1)) < 0)\n            {\n                printf(\"** Error from poll() : %s\\n\", strerror(errno));\n                result = 1;\n            }\n            else if (pollstat == 0)\n            {\n                printf(\"** Timeout from poll() !?\\n\");\n                result = 1;\n            }\n            else if ((pollarg.revents & POLLERR))\n            {\n                printf(\"** File descriptor was closed\\n\");\n                result = 1;\n            }\n            else if (!WTSGetDispatchMessage(&count, callback, &cbresult))\n            {\n                printf(\"** Unexpected faiure to dispatch message\\n\");\n                result = 1;\n            }\n            else if (!cbresult)\n            {\n                printf(\"** Callback failed\\n\");\n                result = 1;\n            }\n        }\n\n        (void)WTSUnRegisterSessionNotificationEx(WTS_CURRENT_SERVER_HANDLE,\n                fd, NULL);\n    }\n\n    if (lc != NULL)\n    {\n        log_config_free(lc);\n        log_end();\n    }\n\n    return result;\n}\n"
  },
  {
    "path": "xrdpapi/simple.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2013\n * Copyright (C) Laxmikant Rashinkar 2012-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * sample program to demonstrate use of xrdpapi\n *\n */\n\n/*\n * build instructions:\n *     gcc simple.c -o simple -I.. -I../common -L./.libs -L../common/.libs \\\n *                            -DHAVE_CONFIG_H -lxrdpapi -lcommon\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#ifdef __WIN32__\n#include <mstsapi.h>\n#endif\n\n#include \"xrdpapi.h\"\n#include \"log.h\"\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <unistd.h>\n#include <string.h>\n#include <errno.h>\n\n/* forward declarations */\nint run_echo_test(void);\nint run_tsmf_test(void);\n\nint\nmain(int argc, char **argv)\n{\n    int result;\n    struct log_config *lc;\n\n    if ((lc = log_config_init_for_console(LOG_LEVEL_DEBUG, NULL)) != NULL)\n    {\n        log_start_from_param(lc);\n    }\n\n    if (argc > 1 && strcasecmp(argv[1], \"echo\") == 0)\n    {\n        result = run_echo_test();\n    }\n    else if (argc > 1 && strcasecmp(argv[1], \"tsmf\") == 0)\n    {\n        result = run_tsmf_test();\n    }\n    else\n    {\n        printf(\"usage: simple <echo|tsmf>\\n\");\n        result = 1;\n    }\n\n    if (lc != NULL)\n    {\n        log_config_free(lc);\n        log_end();\n    }\n\n    return result;\n}\n\n/**\n * perform an ECHO test with a Microsoft Windows RDP client\n *\n * A Microsoft Windows RDP client echos data written\n * to a dynamic virtual channel named ECHO\n *\n * NOTE: THIS TEST WILL FAIL IF CONNECTED FROM A NON\n *       WINDOWS RDP CLIENT\n *\n * @return 0 on success, -1 on failure\n */\nint\nrun_echo_test(void)\n{\n    char    out_buf[8192];\n    char    in_buf[1700];\n    void   *channel;\n    int     bytes_left;\n    int     rv;\n    int     count;\n    int     pkt_count;\n    unsigned int i;\n    unsigned int bytes_written;\n    unsigned int bytes_read;\n\n    unsigned char c;\n    char *rd_ptr;\n    char *wr_ptr;\n\n    /* fill out_buf[] with incremental values */\n    for (i = 0, c = 0; i < 8192; i++, c++)\n    {\n        out_buf[i] = (char)c;\n    }\n\n    /* open a virtual channel named ECHO */\n    channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, \"ECHO\", WTS_CHANNEL_OPTION_DYNAMIC_PRI_LOW);\n\n    if (channel == NULL)\n    {\n        printf(\"###  WTSVirtualChannelOpenEx() failed!\\n\");\n        return -1;\n    }\n\n    bytes_left = 8192;\n    wr_ptr = out_buf;\n    rd_ptr = out_buf;\n    pkt_count = 1;\n\n    while (bytes_left > 0)\n    {\n        /* write data to virtual channel */\n        count = (bytes_left > 1700) ? 1700 : bytes_left;\n        rv = WTSVirtualChannelWrite(channel, wr_ptr, count, &bytes_written);\n\n        if ((rv == 0) || (bytes_written == 0))\n        {\n            printf(\"### WTSVirtualChannelWrite() failed\\n\");\n            return -1;\n        }\n\n        count = bytes_written;\n\n        while (count)\n        {\n            /* read back the echo */\n            rv = WTSVirtualChannelRead(channel, 5000, in_buf, count, &bytes_read);\n\n            if ((rv == 0) || (bytes_read == 0))\n            {\n                printf(\"### WTSVirtualChannelRead() failed\\n\");\n                return -1;\n            }\n\n            /* validate the echo */\n            for (i = 0; i < bytes_read; i++, rd_ptr++)\n            {\n                if (*rd_ptr != in_buf[i])\n                {\n                    printf(\"### data mismatch: expected 0x%x got 0x%x\\n\",\n                           (unsigned char) *rd_ptr, (unsigned char) in_buf[i]);\n                    return -1;\n                }\n            }\n\n            count -= bytes_read;\n        }\n\n        bytes_left -= bytes_written;\n        wr_ptr += bytes_written;\n        printf(\"### pkt %d passed echo test\\n\", pkt_count++);\n    }\n\n    WTSVirtualChannelClose(channel);\n    return 0;\n}\n\nint\nrun_tsmf_test(void)\n{\n    void *channel;\n\n    printf(\"this test not yet implemented!\\n\");\n    return 1;\n\n    /* open virtual channel */\n    channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, \"TSMF\", WTS_CHANNEL_OPTION_DYNAMIC_PRI_LOW);\n\n    if (channel == NULL)\n    {\n        printf(\"###  WTSVirtualChannelOpenEx() failed!\\n\");\n        return 1;\n    }\n\n    WTSVirtualChannelClose(channel);\n    return 0;\n}\n"
  },
  {
    "path": "xrdpapi/vrplayer.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2012-2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * a program that uses xrdpapi and ffmpeg to redirect media streams\n * to a FreeRDP client where it is decompressed and played locally\n *\n */\n\n/******************************************************************************\n * build instructions:  make -f vrplayer.mk\n * setup environment:   export LD_LIBRARY_PATH=\".libs:../xrdpvr/.libs\"\n * run vrplayer:        vrplayer <media file>\n *****************************************************************************/\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#ifdef __WIN32__\n#include <mstsapi.h>\n#endif\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <unistd.h>\n#include <string.h>\n#include <errno.h>\n#include <stdint.h>\n\n#include \"xrdpapi.h\"\n#include \"xrdpvr.h\"\n\nvoid\nextract_32(uint32_t *value, char *buf)\n{\n    *value =  ((buf[3] << 24) & 0xff000000)\n              | ((buf[2] << 16) & 0x00ff0000)\n              | ((buf[1] <<  8) & 0x0000ff00)\n              |  (buf[0]        & 0x000000ff);\n}\n\nint\nmain(int argc, char **argv)\n{\n    void    *channel;\n\n    if (argc < 2)\n    {\n        printf(\"usage: vrplayer <media filename> >\\n\");\n        return 1;\n    }\n\n    /* open a virtual channel and connect to remote client */\n    channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, \"xrdpvr\", 0);\n\n    if (channel == NULL)\n    {\n        fprintf(stderr, \"WTSVirtualChannelOpenEx() failed\\n\");\n        return 1;\n    }\n\n    /* initialize the player */\n    if (xrdpvr_init_player(channel, 101, argv[1]))\n    {\n        fprintf(stderr, \"failed to initialize the player\\n\");\n        return 1;\n    }\n\n    /* send compressed media data to client; client will decompress */\n    /* the media and play it locally                                */\n    xrdpvr_play_media(channel, 101, argv[1]);\n\n    /* perform clean up */\n    xrdpvr_deinit_player(channel, 101);\n\n    WTSVirtualChannelClose(channel);\n    return 0;\n}\n"
  },
  {
    "path": "xrdpapi/vrplayer.mk",
    "content": "CFLAGS = -I../xrdpvr\nLIBS = -L./.libs -L../xrdpvr/.libs -lxrdpapi -lxrdpvr -lavformat\n\nvrplayer: vrplayer.o\n\tgcc $(CFLAGS) vrplayer.c -o vrplayer $(LIBS)\n"
  },
  {
    "path": "xrdpapi/xrdp-ssh-agent.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2013\n * Copyright (C) Laxmikant Rashinkar 2012-2013\n * Copyright (C) Ben Cohen 2017\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * Portions are from OpenSSH, under the following license:\n *\n * Author: Tatu Ylonen <ylo@cs.hut.fi>\n * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland\n *                    All rights reserved\n * The authentication agent program.\n *\n * As far as I am concerned, the code I have written for this software\n * can be used freely for any purpose.  Any derived versions of this\n * software must be clearly marked as such, and if the derived work is\n * incompatible with the protocol description in the RFC file, it must be\n * called by a name other than \"ssh\" or \"Secure Shell\".\n *\n * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n *    notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n *    notice, this list of conditions and the following disclaimer in the\n *    documentation and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\n * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/*\n * xrdp-ssh-agent.c: program to forward ssh-agent protocol from xrdp session\n *\n * This performs the equivalent function of ssh-agent on a server you connect\n * to via ssh, but the ssh-agent protocol is over an RDP dynamic virtual\n * channel and not an SSH channel.\n *\n * This will print out variables to set in your environment (specifically,\n * $SSH_AUTH_SOCK) for ssh clients to find the agent's socket, then it will\n * run in the background.  This is suitable to run just as you would run the\n * normal ssh-agent, e.g. in your Xsession or /etc/xrdp/startwm.sh.\n *\n * Your RDP client needs to be running a compatible client-side plugin\n * that can see a local ssh-agent.\n *\n * usage (from within an xrdp session):\n *     xrdp-ssh-agent\n *\n * build instructions:\n *     gcc xrdp-ssh-agent.c -o xrdp-ssh-agent -L./.libs -lxrdpapi -Wall\n *\n * protocol specification:\n *     Forward data verbatim over RDP dynamic virtual channel named \"sshagent\"\n *     between a ssh client on the xrdp server and the real ssh-agent where\n *     the RDP client is running.  Each connection by a separate client to\n *     xrdp-ssh-agent gets a separate DVC invocation.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#ifdef __WIN32__\n#include <mstsapi.h>\n#endif\n\n#include \"xrdpapi.h\"\n#include <stdlib.h>\n#include <stdio.h>\n#include <unistd.h>\n#include <string.h>\n#include <errno.h>\n#include <sys/types.h>\n#include <sys/socket.h>\n#include <sys/un.h>\n#include <sys/stat.h>\n#include <linux/limits.h>\n#include <fcntl.h>\n#include <sys/time.h>\n#include <sys/resource.h>\n#include <poll.h>\n\n#define _PATH_DEVNULL  \"/dev/null\"\n\nchar socket_name[PATH_MAX];\nchar socket_dir[PATH_MAX];\nstatic int sa_uds_fd = -1;\nstatic int is_going = 1;\n\n\n/* Make a template filename for mk[sd]temp() */\n/* This is from mktemp_proto() in misc.c from openssh */\nvoid\nmktemp_proto(char *s, size_t len)\n{\n    const char *tmpdir;\n    int r;\n\n    if ((tmpdir = getenv(\"TMPDIR\")) != NULL)\n    {\n        r = snprintf(s, len, \"%s/ssh-XXXXXXXXXXXX\", tmpdir);\n        if (r > 0 && (size_t)r < len)\n        {\n            return;\n        }\n    }\n    r = snprintf(s, len, \"/tmp/ssh-XXXXXXXXXXXX\");\n    if (r < 0 || (size_t)r >= len)\n    {\n        fprintf(stderr, \"%s: template string too short\", __func__);\n        exit(1);\n    }\n}\n\n\n/* This uses parts of main() in ssh-agent.c from openssh */\nstatic void\nsetup_ssh_agent(struct sockaddr_un *addr)\n{\n    int rc;\n\n    /* Create private directory for agent socket */\n    mktemp_proto(socket_dir, sizeof(socket_dir));\n    if (mkdtemp(socket_dir) == NULL)\n    {\n        perror(\"mkdtemp: private socket dir\");\n        exit(1);\n    }\n    snprintf(socket_name, sizeof socket_name, \"%s/agent.%ld\", socket_dir,\n             (long)getpid());\n\n    /* Create unix domain socket */\n    unlink(socket_name);\n\n    sa_uds_fd = socket(AF_UNIX, SOCK_STREAM, 0);\n    if (sa_uds_fd == -1)\n    {\n        fprintf(stderr, \"sshagent: socket creation failed\");\n        exit(2);\n    }\n\n    memset(addr, 0, sizeof(struct sockaddr_un));\n    addr->sun_family = AF_UNIX;\n    strncpy(addr->sun_path, socket_name, sizeof(addr->sun_path));\n    addr->sun_path[sizeof(addr->sun_path) - 1] = 0;\n\n    /* Create with privileges rw------- so other users can't access the UDS */\n    mode_t umask_sav = umask(0177);\n    rc = bind(sa_uds_fd, (struct sockaddr *)addr, sizeof(struct sockaddr_un));\n    if (rc != 0)\n    {\n        fprintf(stderr, \"sshagent: bind failed\");\n        close(sa_uds_fd);\n        unlink(socket_name);\n        exit(3);\n    }\n    umask(umask_sav);\n\n    rc = listen(sa_uds_fd, /* backlog = */ 5);\n    if (rc != 0)\n    {\n        fprintf(stderr, \"listen failed\\n\");\n        close(sa_uds_fd);\n        unlink(socket_name);\n        exit(1);\n    }\n\n    /* Now fork: the child becomes the ssh-agent daemon and the parent prints\n     * out the pid and socket name. */\n    pid_t pid = fork();\n    if (pid == -1)\n    {\n        perror(\"fork\");\n        exit(1);\n    }\n    else if (pid != 0)\n    {\n        /* Parent */\n        close(sa_uds_fd);\n        printf(\"SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;\\n\", socket_name);\n        printf(\"SSH_AGENT_PID=%d; export SSH_AGENT_PID;\\n\", pid);\n        printf(\"echo Agent pid %d;\\n\", pid);\n        exit(0);\n    }\n\n    /* Child */\n\n    if (setsid() == -1)\n    {\n        fprintf(stderr, \"setsid failed\");\n        exit(1);\n    }\n\n    (void)chdir(\"/\");\n    int devnullfd;\n    if ((devnullfd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1)\n    {\n        /* XXX might close listen socket */\n        (void)dup2(devnullfd, STDIN_FILENO);\n        (void)dup2(devnullfd, STDOUT_FILENO);\n        (void)dup2(devnullfd, STDERR_FILENO);\n        if (devnullfd > 2)\n        {\n            close(devnullfd);\n        }\n    }\n\n    /* deny core dumps, since memory contains unencrypted private keys */\n    struct rlimit rlim;\n    rlim.rlim_cur = rlim.rlim_max = 0;\n    if (setrlimit(RLIMIT_CORE, &rlim) < 0)\n    {\n        fprintf(stderr, \"setrlimit RLIMIT_CORE: %s\", strerror(errno));\n        exit(1);\n    }\n}\n\n\nstatic void\nhandle_connection(int client_fd)\n{\n    int     rdp_fd = -1;\n    int     rc;\n    void *channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION,\n                                            \"SSHAGENT\",\n                                            WTS_CHANNEL_OPTION_DYNAMIC_PRI_MED);\n    if (channel == NULL)\n    {\n        fprintf(stderr, \"WTSVirtualChannelOpenEx() failed\\n\");\n    }\n\n    unsigned int retlen;\n    int *retdata;\n    rc = WTSVirtualChannelQuery(channel,\n                                WTSVirtualFileHandle,\n                                (void **)&retdata,\n                                &retlen);\n    if (!rc)\n    {\n        fprintf(stderr, \"WTSVirtualChannelQuery() failed\\n\");\n    }\n    if (retlen != sizeof(rdp_fd))\n    {\n        fprintf(stderr, \"WTSVirtualChannelQuery() returned wrong length %u\\n\",\n                retlen);\n    }\n    rdp_fd = *retdata;\n\n    int client_going = 1;\n    while (client_going)\n    {\n        struct pollfd pollfd[2];\n        enum\n        {\n            RDP_FD = 0,\n            CLIENT_FD\n        };\n\n        /* Wait for data from RDP or the client */\n        pollfd[RDP_FD].fd = rdp_fd;\n        pollfd[RDP_FD].events = POLLIN;\n        pollfd[RDP_FD].revents = 0;\n        pollfd[CLIENT_FD].fd = client_fd;\n        pollfd[CLIENT_FD].events = POLLIN;\n        pollfd[CLIENT_FD].revents = 0;\n\n        poll(pollfd, 2, -1);\n\n        if ((pollfd[RDP_FD].revents & (POLLIN | POLLHUP)) != 0)\n        {\n            /* Read from RDP and write to the client */\n            char buffer[4096];\n            unsigned int bytes_to_write;\n            rc = WTSVirtualChannelRead(channel,\n                                       /* TimeOut = */ 5000,\n                                       buffer,\n                                       sizeof(buffer),\n                                       &bytes_to_write);\n            if (rc == 1)\n            {\n                char *pos = buffer;\n                errno = 0;\n                while (bytes_to_write > 0)\n                {\n                    int bytes_written = send(client_fd, pos, bytes_to_write, 0);\n\n                    if (bytes_written > 0)\n                    {\n                        bytes_to_write -= bytes_written;\n                        pos += bytes_written;\n                    }\n                    else if (bytes_written == 0)\n                    {\n                        fprintf(stderr, \"send() returned 0!\\n\");\n                    }\n                    else if (errno != EINTR)\n                    {\n                        /* Error */\n                        fprintf(stderr, \"Error %d on recv\\n\", errno);\n                        client_going = 0;\n                    }\n                }\n            }\n            else\n            {\n                /* Error */\n                fprintf(stderr, \"WTSVirtualChannelRead() failed: %d\\n\", errno);\n                client_going = 0;\n            }\n        }\n\n        if ((pollfd[CLIENT_FD].revents & (POLLIN | POLLHUP)) != 0)\n        {\n            /* Read from the client and write to RDP */\n            char buffer[4096];\n            ssize_t bytes_to_write = recv(client_fd, buffer, sizeof(buffer), 0);\n            if (bytes_to_write > 0)\n            {\n                char *pos = buffer;\n                while (bytes_to_write > 0)\n                {\n                    unsigned int bytes_written;\n                    int rc = WTSVirtualChannelWrite(channel,\n                                                    pos,\n                                                    bytes_to_write,\n                                                    &bytes_written);\n                    if (rc == 0)\n                    {\n                        fprintf(stderr, \"WTSVirtualChannelWrite() failed: %d\\n\",\n                                errno);\n                        client_going = 0;\n                    }\n                    else\n                    {\n                        bytes_to_write -= bytes_written;\n                        pos += bytes_written;\n                    }\n                }\n            }\n            else if (bytes_to_write == 0)\n            {\n                /* Client has closed connection */\n                client_going = 0;\n            }\n            else\n            {\n                /* Error */\n                fprintf(stderr, \"Error %d on recv\\n\", errno);\n                client_going = 0;\n            }\n        }\n    }\n    WTSVirtualChannelClose(channel);\n}\n\n\nint\nmain(int argc, char **argv)\n{\n    /* Setup the Unix domain socket and daemon process */\n    struct sockaddr_un addr;\n    setup_ssh_agent(&addr);\n\n    /* Wait for a client to connect to the socket */\n    while (is_going)\n    {\n        struct pollfd pollfd;\n\n        pollfd.fd = sa_uds_fd;\n        pollfd.events = POLLIN;\n        pollfd.revents = 0;\n\n        poll(pollfd, 1, -1);\n\n        /* If something connected then get it...\n         * (You can test this using \"socat - UNIX-CONNECT:<udspath>\".) */\n        if ((pollfd.revents & (POLLIN | POLLHUP)) != 0)\n\n        {\n            socklen_t addrsize = sizeof(addr);\n            int client_fd = accept(sa_uds_fd,\n                                   (struct sockaddr *)&addr,\n                                   &addrsize);\n            handle_connection(client_fd);\n            close(client_fd);\n        }\n    }\n\n    close(sa_uds_fd);\n    unlink(socket_name);\n\n    return 0;\n}\n"
  },
  {
    "path": "xrdpapi/xrdpapi.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2013\n * Copyright (C) Laxmikant Rashinkar 2012-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <stdint.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <sys/socket.h>\n#include <sys/un.h>\n#include <poll.h>\n\n#include \"log.h\"\n#include \"xrdp_constants.h\"\n#include \"xrdp_sockets.h\"\n#include \"string_calls.h\"\n#include \"channel_defs.h\"\n#include \"xrdpapi.h\"\n\nstruct wts_obj\n{\n    int fd;\n    char display_name[MAX_DISPLAY_NAME_SIZE];\n};\n\n/**\n * Data we store for each server\n */\nstruct wts_server\n{\n    struct wts_obj *info_obj; // Object to get session notifications\n    struct xrdp_chan_session_state session_state; // session state\n};\n\nstatic struct wts_server wts_current_server;\n\n/* helper functions used by WTSxxx API - do not invoke directly */\nstatic int\ncan_send(int sck, int millis, int restart);\nstatic int\ncan_recv(int sck, int millis, int restart);\nstatic int\nmysend(int sck, const void *adata, int bytes);\nstatic int\nmyrecv(int sck, void *adata, int bytes);\nstatic int\nmypeek(int sck, void *adata, int bytes);\n\nstatic void\nfree_wts(struct wts_obj *wts)\n{\n    if (wts != NULL)\n    {\n        if (wts->fd >= 0)\n        {\n            close(wts->fd);\n        }\n        free(wts);\n    }\n}\n\n/*\n * Opens a handle to the server end of a specified virtual channel\n *\n * @param  SessionId     - current session ID; *must* be WTS_CURRENT_SESSION\n * @param  pVirtualName  - virtual channel name when using SVC\n *                       - name of endpoint listener when using DVC\n * @param  flags         - type of channel and channel priority if DVC\n * @param  private_chan  - If != 0, this is a private channel defined\n *                          in channel_defs.h\n * @param[out] errcode   - Indication for the user of a possible\n *                         error. Cannot be defaulted. Is only set on error.\n *\n * @return a valid pointer on success, NULL on error\n ******************************************************************************/\nstatic void *\nVirtualChannelOpen(unsigned int SessionId, const char *pVirtualName,\n                   unsigned int flags,\n                   unsigned int private_chan,\n                   enum wts_errcode *errcode)\n{\n    struct wts_obj *wts;\n    int bytes;\n    unsigned long long1;\n    struct sockaddr_un s;\n    // Pad the connect data out to a larger size to allow for\n    // changes to struct xrdp_chan_connect\n    union\n    {\n        char pad[XRDPAPI_CONNECT_PDU_LEN];\n        struct xrdp_chan_connect connect_data;\n    } cd = {0};\n\n    uint32_t connect_result;\n    int lerrno;\n\n    if (SessionId != WTS_CURRENT_SESSION)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: bad SessionId\");\n        *errcode = WTS_E_BAD_SESSION_ID;\n        return 0;\n    }\n\n    wts = (struct wts_obj *) calloc(1, sizeof(struct wts_obj));\n    if (wts == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: calloc failed\");\n        *errcode = WTS_E_RESOURCE_ERROR;\n        return 0;\n    }\n    wts->fd = -1;\n    if (g_get_display_string(wts->display_name, sizeof(wts->display_name)) < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: fatal error; invalid DISPLAY\");\n        *errcode = WTS_E_RESOURCE_ERROR;\n        free_wts(wts);\n        return NULL;\n    }\n\n    /* we use unix domain socket to communicate with chansrv */\n    if ((wts->fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: socket failed\");\n        *errcode = WTS_E_RESOURCE_ERROR;\n        free_wts(wts);\n        return NULL;\n    }\n\n    /* set non blocking */\n    long1 = fcntl(wts->fd, F_GETFL);\n    long1 = long1 | O_NONBLOCK;\n    if (fcntl(wts->fd, F_SETFL, long1) < 0)\n    {\n        LOG(LOG_LEVEL_WARNING, \"WTSVirtualChannelOpenEx: set non-block mode failed\");\n    }\n\n    /* connect to chansrv session */\n    memset(&s, 0, sizeof(struct sockaddr_un));\n    s.sun_family = AF_UNIX;\n    bytes = sizeof(s.sun_path);\n    snprintf(s.sun_path, bytes - 1, CHANSRV_API_STR,\n             getuid(), wts->display_name);\n    s.sun_path[bytes - 1] = 0;\n    bytes = sizeof(struct sockaddr_un);\n\n    if (connect(wts->fd, (struct sockaddr *) &s, bytes) < 0)\n    {\n        lerrno = errno;\n        if ((lerrno == EWOULDBLOCK) || (lerrno == EAGAIN) ||\n                (lerrno == EINPROGRESS))\n        {\n            /* ok */\n        }\n        else\n        {\n            LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: connect failed\");\n            *errcode = WTS_E_CHANSRV_NOT_UP;\n            free_wts(wts);\n            return NULL;\n        }\n    }\n\n    /* wait for connection to complete */\n    if (!can_send(wts->fd, 500, 1))\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: can_send failed\");\n        *errcode = WTS_E_CHANSRV_NOT_UP;\n        free_wts(wts);\n        return NULL;\n    }\n\n    cd.connect_data.version = XRDPAPI_CONNECT_PDU_VERSION;\n    cd.connect_data.private_chan = private_chan;\n    cd.connect_data.flags = flags;\n    strlcpy(cd.connect_data.name, pVirtualName, sizeof(cd.connect_data.name));\n\n    if (mysend(wts->fd, &cd, sizeof(cd)) != sizeof(cd))\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: mysend failed\");\n        *errcode = WTS_E_RESOURCE_ERROR;\n        free_wts(wts);\n        return NULL;\n    }\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"WTSVirtualChannelOpenEx: sent ok\");\n\n    if (!can_recv(wts->fd, 500, 1))\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: can_recv failed\");\n        *errcode = WTS_E_RESOURCE_ERROR;\n        free_wts(wts);\n        return NULL;\n    }\n\n    /* get response */\n    if (myrecv(wts->fd, &connect_result, sizeof(connect_result)) !=\n            sizeof(connect_result))\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: myrecv failed\");\n        *errcode = WTS_E_RESOURCE_ERROR;\n        free_wts(wts);\n        return NULL;\n    }\n\n    if (connect_result != 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelOpenEx: connect_data not ok\");\n        *errcode = WTS_E_RESOURCE_ERROR;\n        free_wts(wts);\n        return NULL;\n    }\n\n    return wts;\n}\n\n/*\n * Opens a handle to the server end of a specified virtual channel - this\n * call is deprecated - use WTSVirtualChannelOpenEx() instead\n *\n * @param  hServer       - *must* be WTS_CURRENT_SERVER_HANDLE\n * @param  SessionId     - current session ID; *must* be WTS_CURRENT_SESSION\n * @param  pVirtualName  - virtual channel name when using SVC\n *                       - name of endpoint listener when using DVC\n *\n * @return a valid pointer on success, NULL on error\n ******************************************************************************/\nvoid *\nWTSVirtualChannelOpen(void *hServer, unsigned int SessionId,\n                      const char *pVirtualName)\n{\n    enum wts_errcode errcode_dummy = WTS_E_NO_ERROR;\n\n    if (hServer != WTS_CURRENT_SERVER_HANDLE)\n    {\n        return 0;\n    }\n    return VirtualChannelOpen(SessionId, pVirtualName, 0, 0, &errcode_dummy);\n}\n\n/*\n * Opens a handle to the server end of a specified virtual channel\n *\n * @param  SessionId     - current session ID; *must* be WTS_CURRENT_SESSION\n * @param  pVirtualName  - virtual channel name when using SVC\n *                       - name of endpoint listener when using DVC\n * @param  flags         - type of channel and channel priority if DVC\n *\n * @return a valid pointer on success, NULL on error\n ******************************************************************************/\nvoid *\nWTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName,\n                        unsigned int flags)\n{\n    enum wts_errcode errcode_dummy = WTS_E_NO_ERROR;\n    return VirtualChannelOpen(SessionId, pVirtualName,\n                              flags, 0, &errcode_dummy);\n}\n\n/*\n * Prevent receiving SIGPIPE on disconnect using either MSG_NOSIGNAL (Linux)\n * or SO_NOSIGPIPE (Mac OS X)\n */\n#if !defined(MSG_NOSIGNAL)\n#define MSG_NOSIGNAL 0\n#endif\n\n/*****************************************************************************/\nstatic int\nmysend(int sck, const void *adata, int bytes)\n{\n    int sent;\n    int error;\n    const char *data;\n\n#if defined(SO_NOSIGPIPE)\n    const int on = 1;\n    setsockopt(sck, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));\n#endif\n\n    data = (const char *) adata;\n    sent = 0;\n    while (sent < bytes)\n    {\n        if (can_send(sck, 100, 0))\n        {\n            error = send(sck, data + sent, bytes - sent, MSG_NOSIGNAL);\n            if (error < 1)\n            {\n                return -1;\n            }\n            sent += error;\n        }\n    }\n    return sent;\n}\n\n/*****************************************************************************/\nstatic int\nmyrecv(int sck, void *adata, int bytes)\n{\n    int recd;\n    int error;\n    char *data;\n\n#if defined(SO_NOSIGPIPE)\n    const int on = 1;\n    setsockopt(sck, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));\n#endif\n\n    data = (char *) adata;\n    recd = 0;\n    while (recd < bytes)\n    {\n        if (can_recv(sck, 100, 0))\n        {\n            error = recv(sck, data + recd, bytes - recd, MSG_NOSIGNAL);\n            if (error < 1)\n            {\n                return -1;\n            }\n            recd += error;\n        }\n    }\n    return recd;\n}\n\n/*****************************************************************************/\nstatic int\nmypeek(int sck, void *adata, int bytes)\n{\n    int error;\n\n#if defined(SO_NOSIGPIPE)\n    const int on = 1;\n    setsockopt(sck, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));\n#endif\n\n    error = 0;\n    if (can_recv(sck, 100, 0))\n    {\n        error = recv(sck, adata, bytes, MSG_NOSIGNAL | MSG_PEEK);\n    }\n    return error;\n}\n\n/*\n * write data to client connection\n *\n * @return 1 on success, 0 on error\n *****************************************************************************/\nint\nWTSVirtualChannelWrite(void *hChannelHandle, const char *Buffer,\n                       unsigned int Length, unsigned int *pBytesWritten)\n{\n    struct wts_obj *wts;\n    int rv;\n\n    wts = (struct wts_obj *) hChannelHandle;\n\n    *pBytesWritten = 0;\n\n    if (wts == 0)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSVirtualChannelWrite: wts is NULL\");\n        return 0;\n    }\n\n    if (!can_send(wts->fd, 0, 0))\n    {\n        return 1;    /* can't write now, ok to try again */\n    }\n\n    rv = mysend(wts->fd, Buffer, Length);\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"WTSVirtualChannelWrite: mysend() returned %d\", rv);\n\n    if (rv >= 0)\n    {\n        /* success, but zero bytes may have been written */\n        *pBytesWritten = rv;\n        return 1;\n    }\n\n    /* fatal error */\n    return 0;\n}\n\n/*\n * read data from a client connection\n *\n * @return 1 on success, 0 on error\n *****************************************************************************/\nint\nWTSVirtualChannelRead(void *hChannelHandle, unsigned int TimeOut,\n                      char *Buffer, unsigned int BufferSize,\n                      unsigned int *pBytesRead)\n{\n    struct wts_obj *wts;\n    int rv;\n    int lerrno;\n\n    wts = (struct wts_obj *)hChannelHandle;\n\n    if (wts == 0)\n    {\n        return 0;\n    }\n\n    if (can_recv(wts->fd, TimeOut, 0))\n    {\n        rv = recv(wts->fd, Buffer, BufferSize, 0);\n\n        if (rv == -1)\n        {\n            lerrno = errno;\n\n            if ((lerrno == EWOULDBLOCK) || (lerrno == EAGAIN) ||\n                    (lerrno == EINPROGRESS))\n            {\n                *pBytesRead = 0;\n                return 1;\n            }\n\n            return 0;\n        }\n        else if (rv == 0)\n        {\n            return 0;\n        }\n        else if (rv > 0)\n        {\n            *pBytesRead = rv;\n            return 1;\n        }\n    }\n\n    *pBytesRead = 0;\n    return 1;\n}\n\n/*****************************************************************************/\nint\nWTSVirtualChannelClose(void *hChannelHandle)\n{\n    struct wts_obj *wts = (struct wts_obj *)hChannelHandle;\n\n    if (wts == NULL)\n    {\n        return 0;\n    }\n\n    free_wts(wts);\n    return 1;\n}\n\n/*****************************************************************************/\nint\nWTSVirtualChannelQuery(void *hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,\n                       void **ppBuffer, unsigned int *pBytesReturned)\n{\n    struct wts_obj *wts;\n\n    wts = (struct wts_obj *)hChannelHandle;\n\n    if (wts == NULL)\n    {\n        return 0;\n    }\n\n    if (WtsVirtualClass == WTSVirtualFileHandle)\n    {\n        *pBytesReturned = 4;\n        *ppBuffer = malloc(4);\n        if (*ppBuffer == NULL)\n        {\n            return 0;\n        }\n        memcpy(*ppBuffer, &(wts->fd), 4);\n    }\n\n    return 1;\n}\n\n/*****************************************************************************/\nvoid\nWTSFreeMemory(void *pMemory)\n{\n    if (pMemory != NULL)\n    {\n        free(pMemory);\n    }\n}\n\n/*****************************************************************************\n**                                                                          **\n**                                                                          **\n**      Helper functions used by WTSxxx API - do not invoke directly        **\n**                                                                          **\n**                                                                          **\n*****************************************************************************/\n\n/*\n * check if socket is in a writable state - i.e will not block on write\n *\n * @param  sck    socket to check\n * @param  millis timeout value in milliseconds\n * @param  restart Try again if interrupted, even if this exceeds the timeout\n *\n * @return 0 if write will block\n * @return 1 if write will not block\n ******************************************************************************/\nstatic int\ncan_send(int sck, int millis, int restart)\n{\n    int rv = 0;\n    struct pollfd pollfd;\n    int status;\n\n    pollfd.fd = sck;\n    pollfd.events = POLLOUT;\n    pollfd.revents = 0;\n\n    do\n    {\n        status = poll(&pollfd, 1, millis);\n    }\n    while (status < 0 && errno == EINTR && restart);\n\n    if (status > 0)\n    {\n        if ((pollfd.revents & POLLOUT) != 0)\n        {\n            rv = 1;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nstatic int\ncan_recv(int sck, int millis, int restart)\n{\n    int rv = 0;\n    struct pollfd pollfd;\n    int status;\n\n    pollfd.fd = sck;\n    pollfd.events = POLLIN;\n    pollfd.revents = 0;\n    do\n    {\n        status = poll(&pollfd, 1, millis);\n    }\n    while (status < 0 && errno == EINTR && restart);\n\n    if (status > 0)\n    {\n        if ((pollfd.revents & (POLLIN | POLLHUP)) != 0)\n        {\n            rv = 1;\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint WTSQuerySessionInformationA(void *hServer,\n                                unsigned int SessionId,\n                                WTS_INFO_CLASS WTSInfoClass,\n                                void           *ppBuffer,\n                                DWORD          *pBytesReturned,\n                                enum wts_errcode *errcode)\n{\n    int rv = 0;\n    enum wts_errcode errcode_dummy;\n    if (errcode == NULL)\n    {\n        errcode = &errcode_dummy;\n    }\n    *errcode = WTS_E_NO_ERROR;\n\n    if (hServer != WTS_CURRENT_SERVER_HANDLE)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSQuerySessionInformationA: bad hServer\");\n        *errcode = WTS_E_BAD_SERVER;\n    }\n    else if (SessionId != WTS_CURRENT_SESSION)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSQuerySessionInformationA: bad SessionId\");\n        *errcode = WTS_E_BAD_SESSION_ID;\n    }\n    else if (WTSInfoClass != WTSConnectState)\n    {\n        LOG(LOG_LEVEL_ERROR,\n            \"WTSQuerySessionInformationA: unsupported WTSInfoClass\");\n        *errcode = WTS_E_BAD_INFO_CLASS;\n    }\n    else\n    {\n        rv = 1; // Assume success\n        if (wts_current_server.info_obj == NULL)\n        {\n            // We don't have a current connection for server state events.\n            // Set one up to update our cached values, then tear it down again.\n            int fd;\n\n            rv = WTSRegisterSessionNotificationEx(hServer, &fd, 0, errcode) &&\n                 WTSUnRegisterSessionNotificationEx(hServer, fd, errcode);\n        }\n\n        if (rv == 1)\n        {\n            *(WTS_CONNECTSTATE_CLASS *)ppBuffer =\n                (wts_current_server.session_state.is_connected)\n                ? WTSConnected\n                : WTSDisconnected;\n            if (pBytesReturned != NULL)\n            {\n                *pBytesReturned = sizeof(WTS_CONNECTSTATE_CLASS);\n            }\n        }\n    }\n\n    return rv;\n}\n\n/*****************************************************************************/\nint WTSRegisterSessionNotificationEx(void *hServer,\n                                     int *fd_ptr,\n                                     int dwFlags,\n                                     enum wts_errcode *errcode)\n{\n    (void)dwFlags;  // Unused parameter\n    enum wts_errcode errcode_dummy;\n    if (errcode == NULL)\n    {\n        errcode = &errcode_dummy;\n    }\n    *errcode = WTS_E_NO_ERROR;\n\n    if (hServer != WTS_CURRENT_SERVER_HANDLE)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSRegisterSessionNotificationEx: bad hServer\");\n        *errcode = WTS_E_BAD_SERVER;\n        return 0;\n    }\n\n    if (wts_current_server.info_obj == NULL)\n    {\n        // Open a private channel for session info messages\n        // The name and flags args are ignored for xrdp private channels\n        struct wts_obj *wts = (struct wts_obj *)\n                              VirtualChannelOpen(WTS_CURRENT_SESSION,\n                                  \"\", 0,\n                                  CHAN_ID_XRDP_SESSION_INFO,\n                                  errcode);\n        if (wts != NULL)\n        {\n            // Server will pass the current session state now\n            struct xrdp_chan_session_state sess_state;\n            if (!can_recv(wts->fd, 1000, 1))\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"WTSRegisterSessionNotificationEx: can_recv failed\");\n                *errcode = WTS_E_RESOURCE_ERROR;\n                free_wts(wts);\n            }\n            /* get server_status */\n            else if (myrecv(wts->fd, &sess_state, sizeof(sess_state)) !=\n                     sizeof(sess_state))\n            {\n                LOG(LOG_LEVEL_ERROR,\n                    \"WTSRegisterSessionNotificationEx: myrecv failed\");\n                *errcode = WTS_E_RESOURCE_ERROR;\n                free_wts(wts);\n            }\n            else\n            {\n                wts_current_server.info_obj = wts;\n                wts_current_server.session_state = sess_state;\n            }\n        }\n    }\n    if (wts_current_server.info_obj == NULL)\n    {\n        *fd_ptr = -1;\n        return 0;\n    }\n    *fd_ptr = wts_current_server.info_obj->fd;\n    return 1;\n}\n\n/*****************************************************************************/\nint WTSUnRegisterSessionNotificationEx(void *hServer,\n                                       int fd,\n                                       enum wts_errcode *errcode)\n{\n    (void)fd;  // Unused parameter\n    enum wts_errcode errcode_dummy;\n    if (errcode == NULL)\n    {\n        errcode = &errcode_dummy;\n    }\n    *errcode = WTS_E_NO_ERROR;\n\n    if (hServer != WTS_CURRENT_SERVER_HANDLE)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSUnRegisterSessionNotificationEx: bad hServer\");\n        *errcode = WTS_E_BAD_SERVER;\n        return 0;\n    }\n\n    free_wts(wts_current_server.info_obj);\n    wts_current_server.info_obj = NULL;\n    return 1;\n}\n\n/*****************************************************************************/\nint\nWTSGetDispatchMessage(void *cbdata, WNDPROC wndproc, LRESULT *lResult)\n{\n    LRESULT result = 0;\n    struct xrdp_chan_session_state new_state;\n\n    /* get response */\n    if (wts_current_server.info_obj == NULL)\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSGetDispatchMessage: No notification channel was opened\");\n    }\n    else if (!can_recv(wts_current_server.info_obj->fd, 0, 1))\n    {\n        // No message available - nothing to log\n    }\n    else if (mypeek(wts_current_server.info_obj->fd,\n                    &new_state, sizeof(new_state)) != sizeof(new_state))\n    {\n        LOG(LOG_LEVEL_ERROR, \"WTSGetDispatchMessage: An incomplete message was received\");\n    }\n    else\n    {\n        /* We've peeked a message. Find a SINGLE difference with our\n         * own state, update our state, and issue a callback. If there\n         * are more differences, the application will call us back and\n         * we can process the next one. When all the differences are\n         * accounted for, we can clear the message from the queue, and\n         * the fd will no longer be readable */\n        UINT msgno = 0; // 0 means 'no message'\n        WPARAM wParam = 0;\n        LPARAM lParam = 0;\n        // Look for a single difference in the state we have, and the\n        // current state from the server\n        struct xrdp_chan_session_state *curr_state;\n        curr_state = &wts_current_server.session_state;\n\n        if (curr_state->is_connected != new_state.is_connected)\n        {\n            curr_state->is_connected = new_state.is_connected;\n            msgno = WM_WTSSESSION_CHANGE;\n            wParam = (new_state.is_connected)\n                     ? WTS_REMOTE_CONNECT : WTS_REMOTE_DISCONNECT;\n        }\n\n        // If we found a difference, activate the callback\n        if (msgno != 0)\n        {\n            *lResult = wndproc(cbdata, msgno, wParam, lParam);\n            result = 1;\n        }\n\n        // If we've exhausted all the differences between the old and\n        // the new state, purge the message from the queue\n        if (curr_state->is_connected == new_state.is_connected &&\n                /* Add further checks here in the future */\n                1)\n        {\n            /* Sanity check on the fd */\n            if (wts_current_server.info_obj->fd >= 0)\n            {\n                (void)myrecv(wts_current_server.info_obj->fd,\n                             &new_state, sizeof(new_state));\n            }\n        }\n    }\n\n    return result;\n}\n"
  },
  {
    "path": "xrdpapi/xrdpapi.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2012-2013\n * Copyright (C) Thomas Goddard 2012-2013\n * Copyright (C) Laxmikant Rashinkar 2012-2013\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * xrdpapi header, do not use os_calls.h, arch.h or any xrdp internal headers\n * this file is included in 3rd party apps\n */\n\n#if !defined(XRDPAPI_H_)\n#define XRDPAPI_H_\n\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define WTS_CURRENT_SERVER_HANDLE                   0x00000000\n#define WTS_CURRENT_SESSION                         0xffffffff\n\n#define WTS_CHANNEL_OPTION_STATIC                   0x00000000\n#define WTS_CHANNEL_OPTION_DYNAMIC                  0x00000001\n#define WTS_CHANNEL_OPTION_DYNAMIC_NO_COMPRESS      0x00000001\n#define WTS_CHANNEL_OPTION_DYNAMIC_PRI_LOW          0x00000001\n#define WTS_CHANNEL_OPTION_DYNAMIC_PRI_MED          0x00000002\n#define WTS_CHANNEL_OPTION_DYNAMIC_PRI_HIGH         0x00000003\n#define WTS_CHANNEL_OPTION_DYNAMIC_PRI_REAL         0x00000004\n\n#define WM_WTSSESSION_CHANGE            0x02B1\n\n/*\n * codes passed in WPARAM for WM_WTSSESSION_CHANGE\n * Unlisted codes are not yet implemented.\n */\n#define WTS_REMOTE_CONNECT                 0x3\n#define WTS_REMOTE_DISCONNECT              0x4\n\ntypedef enum _WTS_INFO_CLASS\n{\n    //WTSInitialProgram,   // Not yet implemented\n    //WTSApplicationName,  // Not yet implemented\n    //WTSWorkingDirectory, // Not yet implemented\n    //WTSOEMId,            // Not yet implemented\n    //WTSSessionId,        // Not yet implemented\n    //WTSUserName,         // Not yet implemented\n    //WTSWinStationName,   // Not yet implemented\n    //WTSDomainName,       // Not yet implemented\n    WTSConnectState = 8\n} WTS_INFO_CLASS;\n\ntypedef enum _WTS_CONNECTSTATE_CLASS\n{\n    // WTSActive,\n    WTSConnected = 1,\n    // WTSConnectQuery,\n    // WTSShadow,\n    WTSDisconnected = 4,\n    // WTSIdle,\n    // WTSListen,\n    // WTSReset,\n    // WTSDown,\n    // WTSInit\n} WTS_CONNECTSTATE_CLASS;\n\ntypedef enum _WTS_VIRTUAL_CLASS\n{\n    WTSVirtualClientData,\n    WTSVirtualFileHandle\n}\nWTS_VIRTUAL_CLASS;\n\n// Enumerated type for an error code from some calls. This is not\n// compatible with the Windows API.\nenum wts_errcode\n{\n    WTS_E_NO_ERROR = 0,\n    // Retryable errors\n    WTS_E_CHANSRV_NOT_UP,\n    // Fatal errors\n    WTS_E_BAD_SERVER = 32,\n    WTS_E_BAD_SESSION_ID,\n    WTS_E_RESOURCE_ERROR,\n    WTS_E_BAD_INFO_CLASS\n};\n\n#define WTS_ERRCODE_FATAL(errcode) ((int)(errcode) >= (int)WTS_E_BAD_SERVER)\n\n// Win32 basic types\n// See https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types\ntypedef uint32_t DWORD;\ntypedef uint32_t UINT;\ntypedef intptr_t UINT_PTR;\ntypedef intptr_t LONG_PTR;\ntypedef UINT_PTR WPARAM;\ntypedef LONG_PTR LPARAM;\ntypedef LONG_PTR LRESULT;\n\n// WNDPROC emulation for WTSRegisterSessionNotificationEx()\ntypedef LRESULT WNDPROC(void *cbdata, UINT msg, WPARAM wParam, LPARAM lParam);\n\n/*\n * Reference:\n * http://msdn.microsoft.com/en-us/library/windows/desktop/aa383464(v=vs.85).aspx\n */\n\nvoid *WTSVirtualChannelOpen(void *hServer, unsigned int SessionId,\n                            const char *pVirtualName);\n\nvoid *WTSVirtualChannelOpenEx(unsigned int SessionId,\n                              const char *pVirtualName, unsigned int flags);\n\nint WTSVirtualChannelWrite(void *hChannelHandle, const char *Buffer,\n                           unsigned int Length, unsigned int *pBytesWritten);\n\nint WTSVirtualChannelRead(void *hChannelHandle, unsigned int TimeOut,\n                          char *Buffer, unsigned int BufferSize,\n                          unsigned int *pBytesRead);\n\nint WTSVirtualChannelClose(void *hChannelHandle);\n\nint WTSVirtualChannelQuery(void *hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,\n                           void **ppBuffer, unsigned int *pBytesReturned);\n\nvoid WTSFreeMemory(void *pMemory);\n\n/**\n * This function is similar to, but not the same as the Win32\n * function of the same name.\n *\n * The purpose of it is to allow an application to find out\n * (rather limited) information about the session\n *\n * @param hServer set to WTS_CURRENT_SERVER_HANDLE\n * @param SessionId current session ID; *must* be WTS_CURRENT_SESSION\n * @param WTSInfoClass parameter to query\n * @param ppBuffer pointer for result\n * @param pBytesReturned size of result\n * @param[out] errcode Status of operation if false returned. Can be NULL.\n * @return true for success\n */\nint WTSQuerySessionInformationA(void *hServer,\n                                unsigned int SessionId,\n                                WTS_INFO_CLASS WTSInfoClass,\n                                void           *ppBuffer,\n                                DWORD          *pBytesReturned,\n                                enum wts_errcode *errcode);\n\n/**\n * This function is similar to, but not the same as the Win32\n * function of the same name.\n *\n * The purpose of it is to allow an application to receive\n * WM_WTSSESSION_CHANGE messages.\n *\n * @param hServer set to WTS_CURRENT_SERVER_HANDLE\n * @param[out] fd_ptr File descriptor to check for notification messages\n * @param dwFlags ignored\n * @param[out] errcode Status of operation if false returned. Can be NULL.\n * @return true for success\n *\n * The fd_ptr replaces the hWnd parameter in the Win32 call.\n *\n * After a successful call, the location pointed-to by fd_ptr will contain a\n * file descriptor which the caller can poll for session change messages.\n * When the file descriptor becomes readable, a call to\n * WTSGetDispatchMessage() will process a single session change message.\n *\n * The caller must do nothing with the returned file descriptor except poll it.\n */\nint WTSRegisterSessionNotificationEx(void *hServer,\n                                     int *fd_ptr,\n                                     int dwFlags,\n                                     enum wts_errcode *errcode);\n\n/**\n * This function is similar to, but not the same as the Win32\n * function of the same name.\n *\n * The purpose of it is to deallocate resources associated with\n * WTSRegisterSessionNotificationEx()\n *\n * @param hServer set to WTS_CURRENT_SERVER_HANDLE\n * @param fd File descriptor from WTSRegisterSessionNotificationEx\n * @param[out] errcode Status of operation if false returned. Can be NULL.\n * @return true for success\n */\nint WTSUnRegisterSessionNotificationEx(void *hServer,\n                                       int fd,\n                                       enum wts_errcode *errcode);\n\n\n/** Replaces Win32 GetMessage() / DispatchMessage()\n *\n * @param cbdata callback data to pass in to WNDPROC\n * @param wndproc WNDPROC to call\n * @param[out] lResult Result of WNDPROC if call is successful\n * @return != 0 if a WNDPROC was successfully called\n */\nint\nWTSGetDispatchMessage(void *cbdata, WNDPROC wndproc, LRESULT *lResult);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* XRDPAPI_H_ */\n"
  },
  {
    "path": "xrdpvr/Makefile.am",
    "content": "module_LTLIBRARIES = \\\n  libxrdpvr.la\n\nlibxrdpvr_la_SOURCES = \\\n  xrdpvr.c \\\n  xrdpvr.h \\\n  xrdpvr_internal.h\n"
  },
  {
    "path": "xrdpvr/xrdpvr.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2012-2013 LK.Rashinkar@gmail.com\n * Copyright (C) Jay Sorg 2013 jay.sorg@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * a program that uses xrdpapi and ffmpeg to redirect media streams\n * to a FreeRDP client where it is decompressed and played locally\n *\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xrdpvr.h\"\n#include \"xrdpvr_internal.h\"\n\n/* globals */\nPLAYER_STATE_INFO g_psi;\nint g_video_index = -1;\nint g_audio_index = -1;\n\n/*****************************************************************************/\n/* produce a hex dump */\nvoid\nhexdump(char *p, int len)\n{\n    unsigned char *line;\n    int i;\n    int thisline;\n    int offset;\n\n    line = (unsigned char *)p;\n    offset = 0;\n\n    while (offset < len)\n    {\n        printf(\"%04x \", offset);\n        thisline = len - offset;\n\n        if (thisline > 16)\n        {\n            thisline = 16;\n        }\n\n        for (i = 0; i < thisline; i++)\n        {\n            printf(\"%02x \", line[i]);\n        }\n\n        for (; i < 16; i++)\n        {\n            printf(\"   \");\n        }\n\n        for (i = 0; i < thisline; i++)\n        {\n            printf(\"%c\", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');\n        }\n\n        printf(\"\\n\");\n        offset += thisline;\n        line += thisline;\n    }\n}\n\n/**\n * initialize the media player\n *\n * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx\n * @param  stream_id  unique identification number for this stream\n * @param  filename   media file to play\n *\n * @return  0 on success, -1 on error\n *****************************************************************************/\nint\nxrdpvr_init_player(void *channel, int stream_id, char *filename)\n{\n    printf(\"xrdpvr_init_player:\\n\");\n    if ((channel == NULL) || (stream_id <= 0) || (filename == NULL))\n    {\n        return -1;\n    }\n\n    xrdpvr_send_init(channel);\n}\n\n/**\n * de-initialize the media player\n *\n * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx\n * @param  stream_id  unique identification number for this stream\n *\n * @return  0 on success, -1 on error\n *****************************************************************************/\nint\nxrdpvr_deinit_player(void *channel, int stream_id)\n{\n    STREAM  *s;\n    char    *cptr;\n    int     rv;\n    int     len;\n\n    if ((channel == NULL) || (stream_id <= 0))\n    {\n        return -1;\n    }\n\n    /* do local clean up */\n    if (g_psi.frame != 0)\n    {\n        av_free(g_psi.frame);\n        g_psi.frame = 0;\n    }\n    if (g_psi.p_audio_codec_ctx != 0)\n    {\n        avcodec_close(g_psi.p_audio_codec_ctx);\n        g_psi.p_audio_codec_ctx = 0;\n    }\n    if (g_psi.p_video_codec_ctx != 0)\n    {\n        avcodec_close(g_psi.p_video_codec_ctx);\n        g_psi.p_video_codec_ctx = 0;\n    }\n    //avformat_close_input(&g_psi.p_format_ctx);\n    if (g_psi.p_format_ctx != 0)\n    {\n        av_close_input_file(g_psi.p_format_ctx);\n        g_psi.p_format_ctx = 0;\n    }\n\n    /* do remote cleanup */\n\n    stream_new(s, MAX_PDU_SIZE);\n\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_DEINIT_XRDPVR);\n    stream_ins_u32_le(s, stream_id);\n\n    /* insert number of bytes in stream */\n    len = stream_length(s) - 4;\n    cptr = s->p;\n    s->p = s->data;\n    stream_ins_u32_le(s, len);\n    s->p = cptr;\n\n    /* write data to virtual channel */\n    rv = xrdpvr_write_to_client(channel, s);\n    stream_free(s);\n\n    return 0;\n}\n\n/**\n * play the media\n *\n * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx\n * @param  stream_id  unique identification number for this stream\n * @param  filename   media file to play\n *\n * @return  0 on success, -1 on error\n *****************************************************************************/\nint\nxrdpvr_play_media(void *channel, int stream_id, char *filename)\n{\n    int i;\n\n    printf(\"$$$$$$ xrdpvr_play_media: setting audioTimeout & \"\n           \"videoTimeout to -1\\n\");\n    g_psi.videoTimeout = -1;\n    g_psi.audioTimeout = -1;\n\n    /* register all available fileformats and codecs */\n    av_register_all();\n\n    /* open media file - this will read just the header */\n    //if (avformat_open_input(&g_psi.p_format_ctx, filename, NULL, NULL))\n    if (av_open_input_file(&g_psi.p_format_ctx, filename, NULL, 0, NULL))\n    {\n        printf(\"ERROR opening %s\\n\", filename);\n        return -1;\n    }\n\n    /* now get the real stream info */\n    //if (avformat_find_stream_info(g_psi.p_format_ctx, NULL) < 0)\n    if (av_find_stream_info(g_psi.p_format_ctx) < 0)\n    {\n        printf(\"ERROR reading stream info\\n\");\n        return -1;\n    }\n\n#if 1\n    /* print media info to standard out */\n    av_dump_format(g_psi.p_format_ctx, 0, filename, 0);\n#endif\n\n    printf(\"nb_streams %d\\n\", g_psi.p_format_ctx->nb_streams);\n\n    g_audio_index = -1;\n    g_video_index = -1;\n\n    /* find first audio / video stream */\n    for (i = 0; i < g_psi.p_format_ctx->nb_streams; i++)\n    {\n        if (g_psi.p_format_ctx->streams[i]->codec->codec_type ==\n                CODEC_TYPE_VIDEO &&\n                g_psi.p_format_ctx->streams[i]->codec->codec_id ==\n                CODEC_ID_H264 &&\n                g_video_index < 0)\n        {\n            g_video_index = i;\n        }\n\n        if (g_psi.p_format_ctx->streams[i]->codec->codec_type ==\n                CODEC_TYPE_AUDIO &&\n                g_psi.p_format_ctx->streams[i]->codec->codec_id ==\n                CODEC_ID_AAC &&\n                g_audio_index < 0)\n        {\n            g_audio_index = i;\n        }\n    }\n\n    if ((g_audio_index < 0) || (g_video_index < 0))\n    {\n        /* close file and return with error */\n        printf(\"ERROR: no audio/video stream found in %s\\n\", filename);\n        //avformat_close_input(&g_psi.p_format_ctx);\n        av_close_input_file(g_psi.p_format_ctx);\n        return -1;\n    }\n\n    g_psi.audio_stream_index = g_audio_index;\n    g_psi.video_stream_index = g_video_index;\n\n    /* get pointers to codex contexts for both streams */\n    g_psi.p_audio_codec_ctx = g_psi.p_format_ctx->streams[g_audio_index]->codec;\n    g_psi.p_video_codec_ctx = g_psi.p_format_ctx->streams[g_video_index]->codec;\n\n    /* find decoder for audio stream */\n    g_psi.p_audio_codec =\n        avcodec_find_decoder(g_psi.p_audio_codec_ctx->codec_id);\n\n    if (g_psi.p_audio_codec == NULL)\n    {\n        printf(\"ERROR: audio codec not supported\\n\");\n    }\n\n    /* find decoder for video stream */\n    g_psi.p_video_codec =\n        avcodec_find_decoder(g_psi.p_video_codec_ctx->codec_id);\n\n    if (g_psi.p_video_codec == NULL)\n    {\n        printf(\"ERROR: video codec not supported\\n\");\n    }\n\n    /* open decoder for audio stream */\n    //if (avcodec_open2(g_psi.p_audio_codec_ctx, g_psi.p_audio_codec,\n    //                  NULL) < 0)\n    if (avcodec_open(g_psi.p_audio_codec_ctx, g_psi.p_audio_codec) < 0)\n    {\n        printf(\"ERROR: could not open audio decoder\\n\");\n        return -1;\n    }\n\n    printf(\"%d\\n\", g_psi.p_audio_codec_ctx->extradata_size);\n    hexdump(g_psi.p_audio_codec_ctx->extradata,\n            g_psi.p_audio_codec_ctx->extradata_size);\n    printf(\"%d %d %d %d\\n\", g_psi.p_audio_codec_ctx->sample_rate,\n           g_psi.p_audio_codec_ctx->bit_rate,\n           g_psi.p_audio_codec_ctx->channels,\n           g_psi.p_audio_codec_ctx->block_align);\n\n    /* open decoder for video stream */\n    //if (avcodec_open2(g_psi.p_video_codec_ctx, g_psi.p_video_codec,\n    //                  NULL) < 0)\n    if (avcodec_open(g_psi.p_video_codec_ctx, g_psi.p_video_codec) < 0)\n    {\n        printf(\"ERROR: could not open video decoder\\n\");\n        return -1;\n    }\n\n    g_psi.bsfc = av_bitstream_filter_init(\"h264_mp4toannexb\");\n    printf(\"g_psi.bsfc %p\\n\", g_psi.bsfc);\n\n    if (xrdpvr_set_video_format(channel, 101, 0,\n                                g_psi.p_video_codec_ctx->width,\n                                g_psi.p_video_codec_ctx->height))\n    {\n        printf(\"xrdpvr_set_video_format() failed\\n\");\n        return -1;\n    }\n\n    printf(\"xrdpvr_play_media: calling xrdpvr_set_audio_format\\n\");\n    if (xrdpvr_set_audio_format(channel, 101, 0,\n                                g_psi.p_audio_codec_ctx->extradata,\n                                g_psi.p_audio_codec_ctx->extradata_size,\n                                g_psi.p_audio_codec_ctx->sample_rate,\n                                g_psi.p_audio_codec_ctx->bit_rate,\n                                g_psi.p_audio_codec_ctx->channels,\n                                g_psi.p_audio_codec_ctx->block_align))\n    {\n        printf(\"xrdpvr_set_audio_format() failed\\n\");\n        return 1;\n    }\n\n    return 0;\n}\n\nstatic int firstAudioPkt = 1;\nstatic int firstVideoPkt = 1;\n\n/******************************************************************************/\nint\nxrdpvr_get_frame(void **av_pkt_ret, int *is_video_frame, int *delay_in_us)\n{\n    AVPacket                 *av_pkt;\n    double                    dts;\n    int                       error;\n    AVBitStreamFilterContext *bsfc;\n    AVPacket                  new_pkt;\n\n    //printf(\"xrdpvr_get_frame:\\n\");\n    /* alloc an AVPacket */\n    if ((av_pkt = (AVPacket *) malloc(sizeof(AVPacket))) == NULL)\n    {\n        return -1;\n    }\n\n    /* read one frame into AVPacket */\n    if (av_read_frame(g_psi.p_format_ctx, av_pkt) < 0)\n    {\n        free(av_pkt);\n        return -1;\n    }\n\n    if (av_pkt->stream_index == g_audio_index)\n    {\n        /* got an audio packet */\n        dts = av_pkt->dts;\n        dts *= av_q2d(g_psi.p_format_ctx->streams[g_audio_index]->time_base);\n\n        if (g_psi.audioTimeout < 0)\n        {\n            *delay_in_us = 1000 * 5;\n            g_psi.audioTimeout = dts;\n        }\n        else\n        {\n            *delay_in_us = (int) ((dts - g_psi.audioTimeout) * 1000000);\n            g_psi.audioTimeout = dts;\n        }\n        *is_video_frame = 0;\n\n        if (firstAudioPkt)\n        {\n            firstAudioPkt = 0;\n        }\n    }\n    else if (av_pkt->stream_index == g_video_index)\n    {\n\n        bsfc = g_psi.bsfc;\n        while (bsfc != 0)\n        {\n            new_pkt = *av_pkt;\n            error = av_bitstream_filter_filter(bsfc, g_psi.p_video_codec_ctx, 0,\n                                               &new_pkt.data, &new_pkt.size,\n                                               av_pkt->data, av_pkt->size,\n                                               av_pkt->flags & PKT_FLAG_KEY);\n            if (error > 0)\n            {\n                av_free_packet(av_pkt);\n                new_pkt.destruct = av_destruct_packet;\n            }\n            else if (error < 0)\n            {\n                printf(\"bitstream filter error\\n\");\n            }\n            *av_pkt = new_pkt;\n            bsfc = bsfc->next;\n        }\n\n        dts = av_pkt->dts;\n\n        dts *= av_q2d(g_psi.p_format_ctx->streams[g_video_index]->time_base);\n\n        if (g_psi.videoTimeout < 0)\n        {\n            *delay_in_us = 1000 * 5;\n            g_psi.videoTimeout = dts;\n        }\n        else\n        {\n            *delay_in_us = (int) ((dts - g_psi.videoTimeout) * 1000000);\n            g_psi.videoTimeout = dts;\n        }\n        *is_video_frame = 1;\n\n        if (firstVideoPkt)\n        {\n            firstVideoPkt = 0;\n        }\n    }\n\n    *av_pkt_ret = av_pkt;\n    return 0;\n}\n\n/******************************************************************************/\nint\nsend_audio_pkt(void *channel, int stream_id, void *pkt_p)\n{\n    AVPacket *av_pkt = (AVPacket *) pkt_p;\n\n    xrdpvr_send_audio_data(channel, stream_id, av_pkt->size, av_pkt->data);\n    av_free_packet(av_pkt);\n    free(av_pkt);\n}\n\n/******************************************************************************/\nint\nsend_video_pkt(void *channel, int stream_id, void *pkt_p)\n{\n    AVPacket *av_pkt = (AVPacket *) pkt_p;\n\n    xrdpvr_send_video_data(channel, stream_id, av_pkt->size, av_pkt->data);\n    av_free_packet(av_pkt);\n    free(av_pkt);\n}\n\n/******************************************************************************/\nint\nxrdpvr_play_frame(void *channel, int stream_id, int *videoTimeout,\n                  int *audioTimeout)\n{\n    AVPacket                  av_pkt;\n    double                    dts;\n    int                       delay_in_us;\n    int                       error;\n    AVBitStreamFilterContext *bsfc;\n    AVPacket                  new_pkt;\n\n    //printf(\"xrdpvr_play_frame:\\n\");\n\n    if (av_read_frame(g_psi.p_format_ctx, &av_pkt) < 0)\n    {\n        printf(\"xrdpvr_play_frame: av_read_frame failed\\n\");\n        return -1;\n    }\n\n    if (av_pkt.stream_index == g_audio_index)\n    {\n        xrdpvr_send_audio_data(channel, stream_id, av_pkt.size, av_pkt.data);\n\n        dts = av_pkt.dts;\n        dts *= av_q2d(g_psi.p_format_ctx->streams[g_audio_index]->time_base);\n\n        *audioTimeout = (int) ((dts - g_psi.audioTimeout) * 1000000);\n        *videoTimeout = -1;\n\n        if (g_psi.audioTimeout > dts)\n        {\n            g_psi.audioTimeout = dts;\n            delay_in_us = 1000 * 40;\n        }\n        else\n        {\n            delay_in_us = (int) ((dts - g_psi.audioTimeout) * 1000000);\n            g_psi.audioTimeout = dts;\n        }\n\n        printf(\"audio delay: %d\\n\", delay_in_us);\n        usleep(delay_in_us);\n        //usleep(1000 * 1);\n    }\n    else if (av_pkt.stream_index == g_video_index)\n    {\n        bsfc = g_psi.bsfc;\n        while (bsfc != 0)\n        {\n            new_pkt = av_pkt;\n            error = av_bitstream_filter_filter(bsfc, g_psi.p_video_codec_ctx, 0,\n                                               &new_pkt.data, &new_pkt.size,\n                                               av_pkt.data, av_pkt.size,\n                                               av_pkt.flags & PKT_FLAG_KEY);\n            if (error > 0)\n            {\n                av_free_packet(&av_pkt);\n                new_pkt.destruct = av_destruct_packet;\n            }\n            else if (error < 0)\n            {\n                printf(\"bitstream filter error\\n\");\n            }\n            av_pkt = new_pkt;\n            bsfc = bsfc->next;\n        }\n\n        xrdpvr_send_video_data(channel, stream_id, av_pkt.size, av_pkt.data);\n\n        dts = av_pkt.dts;\n        dts *= av_q2d(g_psi.p_format_ctx->streams[g_video_index]->time_base);\n\n        *videoTimeout = (int) ((dts - g_psi.videoTimeout) * 1000000);\n        *audioTimeout = -1;\n\n        if (g_psi.videoTimeout > dts)\n        {\n            g_psi.videoTimeout = dts;\n            delay_in_us = 1000 * 40;\n        }\n        else\n        {\n            delay_in_us = (int) ((dts - g_psi.videoTimeout) * 1000000);\n            g_psi.videoTimeout = dts;\n        }\n\n        printf(\"video delay: %d\\n\", delay_in_us);\n        usleep(delay_in_us);\n    }\n\n    av_free_packet(&av_pkt);\n    return 0;\n}\n\n/******************************************************************************/\nint\nxrdpvr_seek_media(int64_t pos, int backward)\n{\n    int64_t seek_target;\n    int     seek_flag;\n\n    printf(\"xrdpvr_seek_media() entered\\n\");\n\n    g_psi.audioTimeout = -1;\n    g_psi.videoTimeout = -1;\n\n    seek_flag = (backward) ? AVSEEK_FLAG_BACKWARD : 0;\n\n    seek_target = av_rescale_q(pos * AV_TIME_BASE,\n                               AV_TIME_BASE_Q,\n                               g_psi.p_format_ctx->streams[g_video_index]->time_base);\n\n\n    if (av_seek_frame(g_psi.p_format_ctx, g_video_index, seek_target,\n                      seek_flag) < 0)\n    {\n        printf(\"media seek error\\n\");\n        return -1;\n    }\n    printf(\"xrdpvr_seek_media: success\\n\");\n    return 0;\n}\n\n/******************************************************************************/\nvoid\nxrdpvr_get_media_duration(int64_t *start_time, int64_t *duration)\n{\n    *start_time = g_psi.p_format_ctx->start_time / AV_TIME_BASE;\n    *duration = g_psi.p_format_ctx->duration / AV_TIME_BASE;\n}\n\n/******************************************************************************/\nint\nxrdpvr_set_geometry(void *channel, int stream_id, int xpos, int ypos,\n                    int width, int height)\n{\n    STREAM  *s;\n    char    *cptr;\n    int     rv;\n    int     len;\n\n    printf(\"xrdpvr_set_geometry: entered; x=%d y=%d\\n\", xpos, ypos);\n\n    stream_new(s, MAX_PDU_SIZE);\n\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_SET_GEOMETRY);\n    stream_ins_u32_le(s, stream_id);\n    stream_ins_u32_le(s, xpos);\n    stream_ins_u32_le(s, ypos);\n    stream_ins_u32_le(s, width);\n    stream_ins_u32_le(s, height);\n\n    /* insert number of bytes in stream */\n    len = stream_length(s) - 4;\n    cptr = s->p;\n    s->p = s->data;\n    stream_ins_u32_le(s, len);\n    s->p = cptr;\n\n    /* write data to virtual channel */\n    rv = xrdpvr_write_to_client(channel, s);\n    stream_free(s);\n    return rv;\n}\n\n/**\n * set video format\n *\n * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx\n * @param  stream_id  unique identification number for this stream\n *\n * @return  0 on success, -1 on error\n *****************************************************************************/\nint\nxrdpvr_set_video_format(void *channel, uint32_t stream_id, int format,\n                        int width, int height)\n{\n    STREAM  *s;\n    char    *cptr;\n    int     rv;\n    int     len;\n\n    width = (width + 15) & ~15;\n    stream_new(s, MAX_PDU_SIZE);\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_SET_VIDEO_FORMAT);\n    stream_ins_u32_le(s, stream_id);\n    stream_ins_u32_le(s, format);\n    stream_ins_u32_le(s, width);\n    stream_ins_u32_le(s, height);\n\n    /* insert number of bytes in stream */\n    len = stream_length(s) - 4;\n    cptr = s->p;\n    s->p = s->data;\n    stream_ins_u32_le(s, len);\n    s->p = cptr;\n\n    /* write data to virtual channel */\n    rv = xrdpvr_write_to_client(channel, s);\n    stream_free(s);\n    return rv;\n}\n\n/**\n * set audio format\n *\n * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx\n * @param  stream_id  unique identification number for this stream\n *\n * @return  0 on success, -1 on error\n *****************************************************************************/\nint\nxrdpvr_set_audio_format(void *channel, uint32_t stream_id, int format,\n                        char *extradata, int extradata_size, int sample_rate,\n                        int bit_rate, int channels, int block_align)\n{\n    STREAM  *s;\n    char    *cptr;\n    int     rv;\n    int     len;\n\n    stream_new(s, MAX_PDU_SIZE);\n\n    printf(\"extradata_size %d sample_rate %d bit_rate %d channels %d \"\n           \"block_align %d\\n\", extradata_size, sample_rate, bit_rate,\n           channels, block_align);\n\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_SET_AUDIO_FORMAT);\n    stream_ins_u32_le(s, stream_id);\n    stream_ins_u32_le(s, format);\n    stream_ins_u32_le(s, extradata_size);\n    memcpy(s->p, extradata, extradata_size);\n    s->p += extradata_size;\n    stream_ins_u32_le(s, sample_rate);\n    stream_ins_u32_le(s, bit_rate);\n    stream_ins_u32_le(s, channels);\n    stream_ins_u32_le(s, block_align);\n\n    /* insert number of bytes in stream */\n    len = stream_length(s) - 4;\n    cptr = s->p;\n    s->p = s->data;\n    stream_ins_u32_le(s, len);\n    s->p = cptr;\n\n    /* write data to virtual channel */\n    rv = xrdpvr_write_to_client(channel, s);\n    stream_free(s);\n    return rv;\n}\n\n/**\n * send video data to client\n *\n * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx\n * @param  stream_id  unique identification number for this stream\n * @param  data_len   number of bytes to send\n * @param  data       video data to send\n *\n * @return  0 on success, -1 on error\n *****************************************************************************/\nint\nxrdpvr_send_video_data(void *channel, uint32_t stream_id,\n                       uint32_t data_len, uint8_t *data)\n{\n    STREAM  *s;\n    char    *cptr;\n    int     rv;\n    int     len;\n\n    //printf(\"xrdpvr_send_video_data:\\n\");\n    stream_new(s, MAX_PDU_SIZE + data_len);\n\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_SEND_VIDEO_DATA);\n    stream_ins_u32_le(s, stream_id);\n    stream_ins_u32_le(s, data_len);\n    stream_ins_byte_array(s, data, data_len);\n\n    /* insert number of bytes in stream */\n    len = stream_length(s) - 4;\n    cptr = s->p;\n    s->p = s->data;\n    stream_ins_u32_le(s, len);\n    s->p = cptr;\n\n    /* write data to virtual channel */\n    rv = xrdpvr_write_to_client(channel, s);\n    stream_free(s);\n\n#ifdef DEBUG_FRAGMENTS\n    printf(\"### sent %d + 4 bytes video data to client\\n\", len);\n#endif\n\n    return rv;\n}\n\n/**\n * send audio data to client\n *\n * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx\n * @param  stream_id  unique identification number for this stream\n * @param  data_len   number of bytes to send\n * @param  data       audio data to send\n *\n * @return  0 on success, -1 on error\n *****************************************************************************/\nint\nxrdpvr_send_audio_data(void *channel, uint32_t stream_id, uint32_t data_len,\n                       uint8_t *data)\n{\n    STREAM  *s;\n    char    *cptr;\n    int     rv;\n    int     len;\n\n    //printf(\"xrdpvr_send_audio_data:\\n\");\n    stream_new(s, MAX_PDU_SIZE + data_len);\n\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_SEND_AUDIO_DATA);\n    stream_ins_u32_le(s, stream_id);\n    stream_ins_u32_le(s, data_len);\n    stream_ins_byte_array(s, data, data_len);\n\n    /* insert number of bytes in stream */\n    len = stream_length(s) - 4;\n    cptr = s->p;\n    s->p = s->data;\n    stream_ins_u32_le(s, len);\n    s->p = cptr;\n\n    /* write data to virtual channel */\n    rv = xrdpvr_write_to_client(channel, s);\n    stream_free(s);\n\n    return rv;\n}\n\n/**\n * send media meta-data to client\n *\n * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx\n * @param  filename   media file\n *\n * @return  0 on success, -1 on error\n *****************************************************************************/\nint\nxrdpvr_create_metadata_file(void *channel, char *filename)\n{\n    STREAM  *s;\n    char    *cptr;\n    int     rv;\n    int     len;\n    int     fd;\n\n    if ((fd = open(filename, O_RDONLY)) < 0)\n    {\n        return -1;\n    }\n\n    stream_new(s, MAX_PDU_SIZE + 1048576);\n\n    /* send CMD_CREATE_META_DATA_FILE */\n    stream_ins_u32_le(s, 4); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_CREATE_META_DATA_FILE);\n\n    if (xrdpvr_write_to_client(channel, s))\n    {\n        close(fd);\n        return -1;\n    }\n\n    /* read first 1MB of file and send to client */\n    s->p = s->data;\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_WRITE_META_DATA);\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n\n    if ((rv = read(fd, s->p, 1048576)) <= 0)\n    {\n        close(fd);\n        return -1;\n    }\n\n    s->p += rv;\n\n    /* insert number of bytes in stream */\n    len = stream_length(s) - 4;\n    cptr = s->p;\n    s->p = s->data;\n    stream_ins_u32_le(s, len); /* number of bytes in this cmd */\n    s->p += 4;\n    stream_ins_u32_le(s, rv); /* number of metadata bytes */\n    s->p = cptr;\n\n    /* write data to virtual channel */\n    rv = xrdpvr_write_to_client(channel, s);\n\n    /* send CMD_CLOSE_META_DATA_FILE */\n    s->p = s->data;\n    stream_ins_u32_le(s, 4); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_CLOSE_META_DATA_FILE);\n\n    if (xrdpvr_write_to_client(channel, s))\n    {\n        close(fd);\n        return -1;\n    }\n\n    stream_free(s);\n    return rv;\n}\n\n/**\n ******************************************************************************/\nstatic int\nxrdpvr_read_from_client(void *channel, STREAM *s, int bytes, int timeout)\n{\n    unsigned int bytes_read;\n    int total_read;\n    int ok;\n\n    //printf(\"xrdpvr_read_from_client:\\n\");\n    total_read = 0;\n    while (total_read < bytes)\n    {\n        //printf(\"xrdpvr_read_from_client: loop\\n\");\n        bytes_read = bytes - total_read;\n        ok = WTSVirtualChannelRead(channel, timeout, s->p, bytes_read,\n                                   &bytes_read);\n        //printf(\"xrdpvr_read_from_client: loop ok %d\\n\", ok);\n        if (ok)\n        {\n            //printf(\"xrdpvr_read_from_client: bytes_read %d\\n\", bytes_read);\n            total_read += bytes_read;\n            s->p += bytes_read;\n        }\n    }\n    return 0;\n}\n\n/**\n * write data to a xrdpvr client\n *\n * @param  channel  opaque handle returned by WTSVirtualChannelOpenEx\n * @param  s        structure containing data to write\n *\n * @return 0 on success, -1 on failure\n ******************************************************************************/\nstatic int\nxrdpvr_write_to_client(void *channel, STREAM *s)\n{\n    int bytes_to_send;\n    int bytes_written;\n    int index = 0;\n    int rv;\n\n    if ((channel == NULL) || (s == NULL))\n    {\n        return -1;\n    }\n\n    bytes_to_send = stream_length(s);\n\n    while (1)\n    {\n        rv = WTSVirtualChannelWrite(channel, &s->data[index], bytes_to_send,\n                                    &bytes_written);\n\n        if (rv == 0)\n        {\n            return -1;\n        }\n\n        index += bytes_written;\n        bytes_to_send -= bytes_written;\n\n        usleep(1000 * 3);\n    }\n}\n\n/**\n * write set volume to a xrdpvr client\n *\n * @param  channel  opaque handle returned by WTSVirtualChannelOpenEx\n * @param  volume   volume 0x0000 to 0xffff\n *\n * @return 0 on success, -1 on failure\n ******************************************************************************/\nint\nxrdpvr_set_volume(void *channel, int volume)\n{\n    STREAM  *s;\n    char    *cptr;\n    int     rv;\n    int     len;\n\n    stream_new(s, MAX_BUFSIZE);\n\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_SET_VOLUME);\n    stream_ins_u32_le(s, volume);\n\n    /* insert number of bytes in stream */\n    len = stream_length(s) - 4;\n    cptr = s->p;\n    s->p = s->data;\n    stream_ins_u32_le(s, len);\n    s->p = cptr;\n\n    /* write data to virtual channel */\n    rv = xrdpvr_write_to_client(channel, s);\n    stream_free(s);\n    return rv;\n}\n\nint\nxrdpvr_send_init(void *channel)\n{\n    STREAM  *s;\n    char    *cptr;\n    int     rv;\n    int     len;\n\n    printf(\"xrdpvr_send_init:\\n\");\n    stream_new(s, MAX_BUFSIZE);\n\n    stream_ins_u32_le(s, 0); /* number of bytes to follow */\n    stream_ins_u32_le(s, CMD_INIT_XRDPVR);\n\n    /* insert number of bytes in stream */\n    len = stream_length(s) - 4;\n    cptr = s->p;\n    s->p = s->data;\n    stream_ins_u32_le(s, len);\n    s->p = cptr;\n\n    /* write data to virtual channel */\n    rv = xrdpvr_write_to_client(channel, s);\n    stream_free(s);\n    return rv;\n}\n\nint\nxrdpvr_read_ack(void *channel, int *frame)\n{\n    STREAM  *s;\n\n    stream_new(s, MAX_PDU_SIZE);\n    xrdpvr_read_from_client(channel, s, 4, 1000);\n    s->p = s->data;\n    stream_ext_u32_le(s, *frame);\n    stream_free(s);\n    return 0;\n}\n"
  },
  {
    "path": "xrdpvr/xrdpvr.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2012-2013 LK.Rashinkar@gmail.com\n * Copyright (C) Jay Sorg 2013 jay.sorg@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * a program that uses xrdpapi and ffmpeg to redirect media streams\n * to a FreeRDP client where it is decompressed and played locally\n *\n */\n\n#ifndef __XRDPVR_H__\n#define __XRDPVR_H__\n\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nint  xrdpvr_init_player(void *channel, int stream_id, char *filename);\nint  xrdpvr_deinit_player(void *channel, int stream_id);\nint  xrdpvr_play_media(void *channel, int stream_id, char *filename);\nint  xrdpvr_set_geometry(void *channel, int stream_id, int xpos, int ypos,\n                         int width, int height);\nint  xrdpvr_set_video_format(void *channel, uint32_t stream_id, int format,\n                             int width, int height);\nint  xrdpvr_set_audio_format(void *channel, uint32_t stream_id, int format,\n                             char *extradata, int extradata_size,\n                             int sample_rate, int bit_rate,\n                             int channels, int block_align);\nint  xrdpvr_send_video_data(void *channel, uint32_t stream_id,\n                            uint32_t data_len, uint8_t *data);\nint  xrdpvr_send_audio_data(void *channel, uint32_t stream_id,\n                            uint32_t data_len, uint8_t *data);\nint  xrdpvr_create_metadata_file(void *channel, char *filename);\nint  xrdpvr_play_frame(void *channel, int stream_id, int *vdoTimeout,\n                       int *audioTimeout);\nvoid xrdpvr_get_media_duration(int64_t *start_time, int64_t *duration);\nint  xrdpvr_seek_media(int64_t pos, int backward);\nint  xrdpvr_get_frame(void **av_pkt_ret, int *is_video_frame,\n                      int *delay_in_us);\nint  send_audio_pkt(void *channel, int stream_id, void *pkt_p);\nint  send_video_pkt(void *channel, int stream_id, void *pkt_p);\nint  xrdpvr_set_volume(void *channel, int volume);\nint  xrdpvr_send_init(void *channel);\nint  xrdpvr_read_ack(void *channel, int *frame);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* __XRDPVR_H__ */\n"
  },
  {
    "path": "xrdpvr/xrdpvr_internal.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Laxmikant Rashinkar 2012-2013 LK.Rashinkar@gmail.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * a program that uses xrdpapi and ffmpeg to redirect media streams\n * to a FreeRDP client where it is decompressed and played locally\n *\n */\n\n#ifndef __XRDPVR_INTERNAL_H__\n#define __XRDPVR_INTERNAL_H__\n\n#include <stdint.h>\n#include <sys/types.h>\n#include <fcntl.h>\n#include <libavcodec/avcodec.h>\n#include <libavformat/avformat.h>\n\n#if LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR == 20\n#define DISTRO_DEBIAN6\n#endif\n\n#if LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR == 72\n#define DISTRO_UBUNTU1104\n#endif\n\n#if LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR == 35\n#define DISTRO_UBUNTU1204\n#endif\n\n#if !defined(DISTRO_DEBIAN6) && !defined(DISTRO_UBUNTU1104) && !defined(DISTRO_UBUNTU1204)\n#warning unsupported distro\n#endif\n\n#ifdef DISTRO_UBUNTU1204\n#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO\n#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO\n#define PKT_FLAG_KEY AV_PKT_FLAG_KEY\n#endif\n\n#define MAX_BUFSIZE (1024 * 1024 * 8)\n\n#define CMD_SET_VIDEO_FORMAT        1\n#define CMD_SET_AUDIO_FORMAT        2\n#define CMD_SEND_VIDEO_DATA         3\n#define CMD_SEND_AUDIO_DATA         4\n#define CMD_CREATE_META_DATA_FILE   5\n#define CMD_CLOSE_META_DATA_FILE    6\n#define CMD_WRITE_META_DATA         7\n#define CMD_DEINIT_XRDPVR           8\n#define CMD_SET_GEOMETRY            9\n#define CMD_SET_VOLUME              10\n#define CMD_INIT_XRDPVR             11\n\n/* max number of bytes we can send in one pkt */\n#define MAX_PDU_SIZE                1600\n\ntypedef uint8_t  u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\n\ntypedef struct stream\n{\n    u8  *data;\n    u8  *p;\n    u32  size;\n    int  from_buf;\n} STREAM;\n\n/**\n * create and init a new stream\n *\n * @param  _s     stream to create and init\n * @param  _len   number of bytes to store in stream\n ******************************************************************************/\n#define stream_new(_s, _len)                          \\\n    do                                                \\\n    {                                                 \\\n        (_s) = (STREAM *) calloc(1, sizeof(STREAM));  \\\n        if (!(_s))                                    \\\n        {                                             \\\n            abort();                                  \\\n        }                                             \\\n        (_s)->data = (u8 *) calloc(1, (_len));        \\\n        (_s)->p = (_s)->data;                         \\\n        (_s)->size = (_len);                          \\\n        (_s)->from_buf = 0;                           \\\n    } while (0)\n\n/**\n * create a stream from an existing buffer\n ******************************************************************************/\n#define stream_from_buffer(_s, _buf, _buf_len)        \\\n    do                                                \\\n    {                                                 \\\n        (_s) = (STREAM *) calloc(1, sizeof(STREAM));  \\\n        (_s)->data = (u8 *) (_buf);                   \\\n        (_s)->p = (_s)->data;                         \\\n        (_s)->size = (_buf_len);                      \\\n        (_s)->from_buf = 1;                           \\\n    } while (0)\n\n/**\n * release stream resources, including stream itself\n * note: release _s->data only if we allocated it\n *\n * @param  _s  the stream whose resources are to be released\n ******************************************************************************/\n#define stream_free(_s)                               \\\n    do                                                \\\n    {                                                 \\\n        if (!(_s)->from_buf)                          \\\n        {                                             \\\n            free((_s)->data);                         \\\n        }                                             \\\n        free((_s));                                   \\\n        (_s) = NULL;                                  \\\n    } while (0)\n\n/** return number of bytes in stream */\n#define stream_length(_s) (int) ((_s)->p - (_s)->data)\n\n/** insert a 8 bit value into stream */\n#define stream_ins_u8(_s, _val)                       \\\n    do                                                \\\n    {                                                 \\\n        *(_s)->p++ = (unsigned char) (_val);          \\\n    } while(0)\n\n/** insert a 16 bit value into stream */\n#define stream_ins_u16_le(_s, _val)                   \\\n    do                                                \\\n    {                                                 \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 0);   \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 8);   \\\n    } while (0)\n\n/** insert a 32 bit value into stream */\n#define stream_ins_u32_le(_s, _val)                   \\\n    do                                                \\\n    {                                                 \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 0);   \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 8);   \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 16);  \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 24);  \\\n    } while (0)\n\n/** insert a 64 bit value into stream */\n#define stream_ins_u64_le(_s, _val)                   \\\n    do                                                \\\n    {                                                 \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 0);   \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 8);   \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 16);  \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 24);  \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 32);  \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 40);  \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 48);  \\\n        *(_s)->p++ = (unsigned char) ((_val) >> 56);  \\\n    } while (0)\n\n/** insert array of chars into stream */\n#define stream_ins_byte_array(_s, _ba, _count)        \\\n    do                                                \\\n    {                                                 \\\n        memcpy((_s)->p, (_ba), (_count));             \\\n        (_s)->p += (_count);                          \\\n    } while (0)\n\n/** extract a 8 bit value from stream */\n#define stream_ext_u8(_s, _v)                         \\\n    do                                                \\\n    {                                                 \\\n        (_v) = (u8) *(_s)->p++;                       \\\n    } while (0)\n\n/** extract a 16 bit value from stream */\n#define stream_ext_u16_le(_s, _v)                     \\\n    do                                                \\\n    {                                                 \\\n        (_v) = (u16) ((_s)->p[1] << 8 | (_s)->p[0]);  \\\n        (_s)->p += 2;                                 \\\n    } while (0)\n\n/** extract a 32 bit value from stream */\n#define stream_ext_u32_le(_s, _v)                     \\\n    do                                                \\\n    {                                                 \\\n        (_v) = (u32) ((_s)->p[3] << 24 |              \\\n                      (_s)->p[2] << 16 |              \\\n                      (_s)->p[1] << 8  |              \\\n                      (_s)->p[0]);                    \\\n        (_s)->p += 4;                                 \\\n    } while (0)\n\ntypedef struct _player_state_info\n{\n    AVFormatContext *p_format_ctx;\n    AVCodecContext  *p_audio_codec_ctx;\n    AVCodecContext  *p_video_codec_ctx;\n    AVCodec         *p_audio_codec;\n    AVCodec         *p_video_codec;\n\n    int              audio_stream_index;\n    int              video_stream_index;\n    double           audioTimeout;\n    double           videoTimeout;\n\n    /* LK_TODO delete this after we fix the problem */\n    AVFrame         *frame;\n    AVPacket        avpkt;\n\n    AVBitStreamFilterContext *bsfc;\n\n} PLAYER_STATE_INFO;\n\nstatic int xrdpvr_read_from_client(void *channel, STREAM *s, int bytes, int timeout);\nstatic int xrdpvr_write_to_client(void *channel, STREAM *s);\n\n#endif /* __XRDPVR_INTERNAL_H__ */\n"
  },
  {
    "path": "xup/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n  -DXRDP_CFG_PATH=\\\"${sysconfdir}/${sysconfsubdir}\\\" \\\n  -DXRDP_SBIN_PATH=\\\"${sbindir}\\\" \\\n  -DXRDP_SHARE_PATH=\\\"${datadir}/xrdp\\\" \\\n  -DXRDP_PID_PATH=\\\"${localstatedir}/run\\\" \\\n  -I$(top_srcdir)/common\n\nmodule_LTLIBRARIES = \\\n  libxup.la\n\nlibxup_la_SOURCES = \\\n  xup.c \\\n  xup.h\n\nlibxup_la_LIBADD = \\\n  $(top_builddir)/common/libcommon.la\n\nif !MACOS\nlibxup_la_LDFLAGS = -avoid-version -module\nendif\n"
  },
  {
    "path": "xup/xup.c",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libxup main file\n */\n\n#if defined(HAVE_CONFIG_H)\n#include <config_ac.h>\n#endif\n\n#include \"xup.h\"\n#include \"xup_client_info.h\"\n#include \"log.h\"\n#include \"trans.h\"\n#include \"string_calls.h\"\n#include \"scancode.h\"\n\nstatic int\nsend_server_monitor_update(struct mod *v, struct stream *s,\n                           int width, int height,\n                           int num_monitors,\n                           const struct monitor_info *monitors);\n\nstatic int\nsend_server_monitor_full_invalidate(\n    struct mod *mod, struct stream *s, int width, int height);\n\nstatic int\nsend_server_version_message(struct mod *v, struct stream *s);\n\nstatic int\nlib_mod_process_message(struct mod *mod, struct stream *s);\n\n/******************************************************************************/\nstatic int\nlib_send_copy(struct mod *mod, struct stream *s)\n{\n    return trans_write_copy_s(mod->trans, s);\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_start(struct mod *mod, int w, int h, int bpp)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"in lib_mod_start\");\n    mod->width = w;\n    mod->height = h;\n    mod->bpp = bpp;\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"out lib_mod_start\");\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlib_mod_log_peer(struct mod *mod)\n{\n    int my_pid;\n    int pid;\n    int uid;\n    int gid;\n\n    my_pid = g_getpid();\n    if (g_sck_get_peer_cred(mod->trans->sck, &pid, &uid, &gid) == 0)\n    {\n        LOG(LOG_LEVEL_INFO, \"lib_mod_log_peer: xrdp_pid=%d connected \"\n            \"to Xorg_pid=%d Xorg_uid=%d Xorg_gid=%d \"\n            \"client=%s\",\n            my_pid, pid, uid, gid,\n            mod->client_info.client_description);\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"lib_mod_log_peer: g_sck_get_peer_cred \"\n            \"failed\");\n    }\n    return 0;\n}\n\n/******************************************************************************/\nstatic int\nlib_data_in(struct trans *trans)\n{\n    struct mod *self;\n    struct stream *s;\n    int len;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lib_data_in:\");\n    if (trans == 0)\n    {\n        return 1;\n    }\n\n    self = (struct mod *)(trans->callback_data);\n    s = trans_get_in_s(trans);\n\n    if (s == 0)\n    {\n        return 1;\n    }\n\n    switch (trans->extra_flags)\n    {\n        case 1:\n            s->p = s->data;\n            in_uint8s(s, 4); /* processed later in lib_mod_process_message */\n            in_uint32_le(s, len);\n            if (len < 0 || len > 128 * 1024)\n            {\n                LOG(LOG_LEVEL_ERROR, \"lib_data_in: bad size\");\n                return 1;\n            }\n            if (len > 0)\n            {\n                trans->header_size = len + 8;\n                trans->extra_flags = 2;\n                break;\n            }\n        /* fall through */\n        case 2:\n            s->p = s->data;\n            if (lib_mod_process_message(self, s) != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"lib_data_in: lib_mod_process_message failed\");\n                return 1;\n            }\n            init_stream(s, 0);\n            trans->header_size = 8;\n            trans->extra_flags = 1;\n            break;\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\n/*\n * Wait for module caps message from Xorg module\n *\n * This routine waits for the Xorg module to send a caps message.\n *\n * We use this to check the caps are compatible with us before we\n * go for a fuull-on connect\n */\nstatic int\nwait_for_module_caps_message(struct mod *mod)\n{\n    int robjs_count;\n    intptr_t robjs[10];\n\n    mod->caps_processing_status = E_CAPS_NOT_PROCESSED;\n\n    while (mod->caps_processing_status == E_CAPS_NOT_PROCESSED)\n    {\n        robjs_count = 0;\n        if (trans_get_wait_objs(mod->trans, robjs, &robjs_count) != 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"Xorg module has dropped connection\");\n            return 1;\n        }\n\n        // We don't need a big timeout here, as all the module has to do is\n        // turn around the version message.\n        int status = g_obj_wait(robjs, robjs_count, 0, 0, 3 * 1000);\n\n        if (status < 0)\n        {\n            LOG(LOG_LEVEL_ERROR, \"No response from Xorg module before timeout\");\n            return 1;\n        }\n\n        (void)trans_check_wait_objs(mod->trans);\n    }\n\n    return (mod->caps_processing_status == E_CAPS_OK) ? 0 : 1;\n}\n\n/******************************************************************************/\n/* Convert the internal xrdp_client_info structure to an\n * external xup_client_info structure */\nstatic void\nconvert_xrdp_client_info_to_xup_client_info(\n    const struct xrdp_client_info *src,\n    struct xup_client_info *dst)\n{\n    dst->size = sizeof(*dst);\n    dst->version = XUP_CLIENT_INFO_CURRENT_VERSION;\n    dst->bpp = src->bpp;\n    dst->jpeg = src->jpeg;\n    dst->offscreen_support_level = src->offscreen_support_level;\n    dst->offscreen_cache_size = src->offscreen_cache_size;\n    dst->offscreen_cache_entries = src->offscreen_cache_entries;\n\n    memcpy(dst->orders, src->orders, XR_PRIMARY_ORDER_COUNT);\n    dst->order_flags_ex = src->order_flags_ex;\n    dst->pointer_flags = src->pointer_flags;\n    dst->large_pointer_support_flags = src->large_pointer_support_flags;\n\n    dst->display_sizes = src->display_sizes;\n\n    dst->capture_code = src->capture_code;\n    dst->capture_format = src->capture_format;\n\n    memcpy(dst->model, src->model, CI_KBD_MODEL_SIZE);\n    memcpy(dst->layout, src->layout, CI_KBD_LAYOUT_SIZE);\n    memcpy(dst->variant, src->variant, CI_KBD_VARIANT_SIZE);\n    memcpy(dst->options, src->options, CI_KBD_OPTIONS_SIZE);\n    memcpy(dst->xkb_rules, src->xkb_rules, CI_KBD_XKB_RULES_SIZE);\n\n    dst->x11_keycode_caps_lock = src->x11_keycode_caps_lock;\n    dst->x11_keycode_num_lock = src->x11_keycode_num_lock;\n    dst->x11_keycode_scroll_lock = src->x11_keycode_scroll_lock;\n\n    dst->rfx_frame_interval = src->rfx_frame_interval;\n    dst->h264_frame_interval = src->h264_frame_interval;\n    dst->normal_frame_interval = src->normal_frame_interval;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_send_client_info(struct mod *mod)\n{\n    struct stream *s;\n    int len;\n    struct xup_client_info xup_client_info;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lib_send_client_info:\");\n\n    convert_xrdp_client_info_to_xup_client_info(&mod->client_info,\n            &xup_client_info);\n    make_stream(s);\n    init_stream(s, (int)sizeof(xup_client_info) + 64);\n    s_push_layer(s, iso_hdr, 4);\n    out_uint16_le(s, 104);\n    g_memcpy(s->p, &xup_client_info, sizeof(xup_client_info));\n    s->p += sizeof(xup_client_info);\n    s_mark_end(s);\n    len = (int)(s->end - s->data);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, len);\n    lib_send_copy(mod, s);\n    free_stream(s);\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_connect(struct mod *mod, int fd)\n{\n    int error;\n    int socket_mode;\n    struct stream *s;\n    char con_port[256];\n\n    mod->server_msg(mod, \"started connecting\", 0);\n\n    /* only support 8, 15, 16, 24, and 32 bpp connections from rdp client */\n    if (mod->bpp != 8\n            && mod->bpp != 15\n            && mod->bpp != 16\n            && mod->bpp != 24\n            && mod->bpp != 32)\n    {\n        mod->server_msg(mod,\n                        \"error - only supporting 8, 15, 16, 24, and 32\"\n                        \" bpp rdp connections\", 0);\n        return 1;\n    }\n\n    // This is a good place to finalise any parameters that need to\n    // be set.\n    //\n    // Load the XKB layout\n    if (mod->keycode_set[0] != '\\0')\n    {\n        if (scancode_set_keycode_set(mod->keycode_set) == 0)\n        {\n            LOG(LOG_LEVEL_INFO, \"Loaded '%s' keycode set\", mod->keycode_set);\n        }\n        else\n        {\n            LOG(LOG_LEVEL_WARNING, \"Unable to load '%s' keycode set\",\n                mod->keycode_set);\n        }\n    }\n    mod->server_init_xkb_layout(mod, &(mod->client_info));\n    LOG(LOG_LEVEL_INFO, \"XKB rules '%s' will be used by the module\",\n        mod->client_info.xkb_rules);\n\n    if (mod->client_info.h264_frame_interval <= 0)\n    {\n        mod->client_info.h264_frame_interval = DEFAULT_H264_FRAME_INTERVAL;\n    }\n    if (mod->client_info.rfx_frame_interval <= 0)\n    {\n        mod->client_info.rfx_frame_interval = DEFAULT_RFX_FRAME_INTERVAL;\n    }\n    if (mod->client_info.normal_frame_interval <= 0)\n    {\n        mod->client_info.normal_frame_interval = DEFAULT_NORMAL_FRAME_INTERVAL;\n    }\n\n    make_stream(s);\n    g_sprintf(con_port, \"%s\", mod->port);\n\n    error = 0;\n    mod->sck_closed = 0;\n\n    if (con_port[0] == '/')\n    {\n        socket_mode = TRANS_MODE_UNIX;\n        LOG(LOG_LEVEL_INFO, \"lib_mod_connect: connecting via UNIX socket\");\n    }\n    else\n    {\n        socket_mode = TRANS_MODE_TCP;\n        LOG(LOG_LEVEL_INFO, \"lib_mod_connect: connecting via TCP socket\");\n        if (g_strcmp(mod->ip, \"\") == 0)\n        {\n            mod->server_msg(mod, \"error - no ip set\", 0);\n            free_stream(s);\n            return 1;\n        }\n    }\n\n    mod->trans = trans_create(socket_mode, 8 * 8192, 8192);\n    if (mod->trans == 0)\n    {\n        free_stream(s);\n        return 1;\n    }\n\n    // Set the transport up\n    mod->trans->si = mod->si;\n    mod->trans->my_source = XRDP_SOURCE_MOD;\n    mod->trans->is_term = mod->server_is_term;\n    mod->trans->trans_data_in = lib_data_in;\n    mod->trans->header_size = 8;\n    mod->trans->callback_data = mod;\n    mod->trans->no_stream_init_on_data_in = 1;\n    mod->trans->extra_flags = 1;\n\n    if (fd >= 0)\n    {\n        mod->trans->sck = fd;\n        mod->trans->status = TRANS_STATUS_UP; /* ok */\n        mod->trans->type1 = TRANS_TYPE_CLIENT; /* client */\n        error = 0;\n    }\n    else\n    {\n        /* Give the X server a bit of time to start */\n        error = trans_connect(mod->trans, mod->ip, con_port, 30 * 1000);\n    }\n\n    if (error == 0)\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO, \"lib_mod_connect: connected to Xserver \"\n                  \"(Xorg) sck %lld\",\n                  (long long) (mod->trans->sck));\n        if (socket_mode == TRANS_MODE_UNIX)\n        {\n            lib_mod_log_peer(mod);\n        }\n    }\n    else\n    {\n        LOG(LOG_LEVEL_ERROR, \"Error connecting to X server [%s]\",\n            g_get_strerror());\n    }\n\n    if (error == 0)\n    {\n        error = send_server_version_message(mod, s);\n    }\n\n    if (error == 0)\n    {\n        error = wait_for_module_caps_message(mod);\n    }\n\n    if (error == 0)\n    {\n        error = lib_send_client_info(mod);\n    }\n\n    if (error == 0)\n    {\n        error = send_server_monitor_full_invalidate(\n                    mod, s, mod->width, mod->height);\n    }\n\n    free_stream(s);\n\n    if (error != 0)\n    {\n        trans_delete(mod->trans);\n        mod->trans = 0;\n        mod->server_msg(mod, \"Error connecting to Xorg - check log\", 0);\n    }\n    else\n    {\n        mod->server_msg(mod, \"connected ok\", 0);\n    }\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"out lib_mod_connect\");\n    return error;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_event(struct mod *mod, int msg, tbus param1, tbus param2,\n              tbus param3, tbus param4)\n{\n    struct stream *s;\n    int len;\n    int key;\n    int rv;\n    int scancode;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"in lib_mod_event\");\n    make_stream(s);\n\n    if ((msg >= 15) && (msg <= 16)) /* key events */\n    {\n        key = param2;\n\n        if (key > 0)\n        {\n            if (key == 65027) /* altgr */\n            {\n                if (mod->shift_state)\n                {\n                    LOG_DEVEL(LOG_LEVEL_TRACE, \"special\");\n                    /* fix for mstsc sending left control down with altgr */\n                    /* control down / up\n                    msg param1 param2 param3 param4\n                    15  0      65507  29     0\n                    16  0      65507  29     49152 */\n                    init_stream(s, 8192);\n                    s_push_layer(s, iso_hdr, 4);\n                    out_uint16_le(s, 103);\n                    out_uint32_le(s, 16); /* key up */\n                    out_uint32_le(s, 0);\n                    out_uint32_le(s, 65507); /* left control */\n                    out_uint32_le(s, 29); /* RDP scan code */\n                    out_uint32_le(s, 0xc000); /* flags */\n                    s_mark_end(s);\n                    len = (int)(s->end - s->data);\n                    s_pop_layer(s, iso_hdr);\n                    out_uint32_le(s, len);\n                    lib_send_copy(mod, s);\n                }\n            }\n\n            if (key == 65507) /* left control */\n            {\n                mod->shift_state = msg == 15;\n            }\n        }\n\n        /* xup doesn't need the Unicode character mapping in param1. Send\n         * the X11 scancode instead, so xorgxrdp doesn't have to do this\n         * work again */\n        scancode = SCANCODE_FROM_KBD_EVENT(param3, param4);\n        param1 = scancode_to_x11_keycode(scancode);\n    }\n\n    init_stream(s, 8192);\n    s_push_layer(s, iso_hdr, 4);\n    out_uint16_le(s, 103);\n    out_uint32_le(s, msg);\n    out_uint32_le(s, param1);\n    out_uint32_le(s, param2);\n    out_uint32_le(s, param3);\n    out_uint32_le(s, param4);\n    s_mark_end(s);\n    len = (int)(s->end - s->data);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, len);\n    rv = lib_send_copy(mod, s);\n    free_stream(s);\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"out lib_mod_event\");\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_fill_rect(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    int cx;\n    int cy;\n\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, cx);\n    in_uint16_le(s, cy);\n    rv = mod->server_fill_rect(mod, x, y, cx, cy);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_screen_blt(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int srcx;\n    int srcy;\n\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, cx);\n    in_uint16_le(s, cy);\n    in_sint16_le(s, srcx);\n    in_sint16_le(s, srcy);\n    rv = mod->server_screen_blt(mod, x, y, cx, cy, srcx, srcy);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_paint_rect(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int len_bmpdata;\n    char *bmpdata;\n    int width;\n    int height;\n    int srcx;\n    int srcy;\n\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, cx);\n    in_uint16_le(s, cy);\n    in_uint32_le(s, len_bmpdata);\n    in_uint8p(s, bmpdata, len_bmpdata);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n    in_sint16_le(s, srcx);\n    in_sint16_le(s, srcy);\n    rv = mod->server_paint_rect(mod, x, y, cx, cy,\n                                bmpdata, width, height,\n                                srcx, srcy);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_clip(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    int cx;\n    int cy;\n\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, cx);\n    in_uint16_le(s, cy);\n    rv = mod->server_set_clip(mod, x, y, cx, cy);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_reset_clip(struct mod *mod, struct stream *s)\n{\n    int rv;\n\n    rv = mod->server_reset_clip(mod);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_fgcolor(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int fgcolor;\n\n    in_uint32_le(s, fgcolor);\n    rv = mod->server_set_fgcolor(mod, fgcolor);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_bgcolor(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int bgcolor;\n\n    in_uint32_le(s, bgcolor);\n    rv = mod->server_set_bgcolor(mod, bgcolor);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_opcode(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int opcode;\n\n    in_uint16_le(s, opcode);\n    rv = mod->server_set_opcode(mod, opcode);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_pen(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int style;\n    int width;\n\n    in_uint16_le(s, style);\n    in_uint16_le(s, width);\n    rv = mod->server_set_pen(mod, style, width);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_draw_line(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int x1;\n    int y1;\n    int x2;\n    int y2;\n\n    in_sint16_le(s, x1);\n    in_sint16_le(s, y1);\n    in_sint16_le(s, x2);\n    in_sint16_le(s, y2);\n    rv = mod->server_draw_line(mod, x1, y1, x2, y2);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_cursor(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    char cur_data[32 * (32 * 3)];\n    char cur_mask[32 * (32 / 8)];\n\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint8a(s, cur_data, 32 * (32 * 3));\n    in_uint8a(s, cur_mask, 32 * (32 / 8));\n    rv = mod->server_set_cursor(mod, x, y, cur_data, cur_mask);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_create_os_surface(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int rdpid;\n    int width;\n    int height;\n\n    in_uint32_le(s, rdpid);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n    rv = mod->server_create_os_surface(mod, rdpid, width, height);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_switch_os_surface(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int rdpid;\n\n    in_uint32_le(s, rdpid);\n    rv = mod->server_switch_os_surface(mod, rdpid);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_delete_os_surface(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int rdpid;\n\n    in_uint32_le(s, rdpid);\n    rv = mod->server_delete_os_surface(mod, rdpid);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_paint_rect_os(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int rdpid;\n    int srcx;\n    int srcy;\n\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, cx);\n    in_uint16_le(s, cy);\n    in_uint32_le(s, rdpid);\n    in_sint16_le(s, srcx);\n    in_sint16_le(s, srcy);\n    rv = mod->server_paint_rect_os(mod, x, y, cx, cy,\n                                   rdpid, srcx, srcy);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_hints(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int hints;\n    int mask;\n\n    in_uint32_le(s, hints);\n    in_uint32_le(s, mask);\n    rv = mod->server_set_hints(mod, hints, mask);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_window_new_update(struct mod *mod, struct stream *s)\n{\n    int flags;\n    int window_id;\n    int title_bytes;\n    int index;\n    int bytes;\n    int rv;\n    struct rail_window_state_order rwso;\n\n    g_memset(&rwso, 0, sizeof(rwso));\n    in_uint32_le(s, window_id);\n    in_uint32_le(s, rwso.owner_window_id);\n    in_uint32_le(s, rwso.style);\n    in_uint32_le(s, rwso.extended_style);\n    in_uint32_le(s, rwso.show_state);\n    in_uint16_le(s, title_bytes);\n\n    if (title_bytes > 0)\n    {\n        rwso.title_info = g_new(char, title_bytes + 1);\n        in_uint8a(s, rwso.title_info, title_bytes);\n        rwso.title_info[title_bytes] = 0;\n    }\n\n    in_uint32_le(s, rwso.client_offset_x);\n    in_uint32_le(s, rwso.client_offset_y);\n    in_uint32_le(s, rwso.client_area_width);\n    in_uint32_le(s, rwso.client_area_height);\n    in_uint32_le(s, rwso.rp_content);\n    in_uint32_le(s, rwso.root_parent_handle);\n    in_uint32_le(s, rwso.window_offset_x);\n    in_uint32_le(s, rwso.window_offset_y);\n    in_uint32_le(s, rwso.window_client_delta_x);\n    in_uint32_le(s, rwso.window_client_delta_y);\n    in_uint32_le(s, rwso.window_width);\n    in_uint32_le(s, rwso.window_height);\n    in_uint16_le(s, rwso.num_window_rects);\n\n    if (rwso.num_window_rects > 0)\n    {\n        bytes = sizeof(struct rail_window_rect) * rwso.num_window_rects;\n        rwso.window_rects = (struct rail_window_rect *)g_malloc(bytes, 0);\n\n        for (index = 0; index < rwso.num_window_rects; index++)\n        {\n            in_uint16_le(s, rwso.window_rects[index].left);\n            in_uint16_le(s, rwso.window_rects[index].top);\n            in_uint16_le(s, rwso.window_rects[index].right);\n            in_uint16_le(s, rwso.window_rects[index].bottom);\n        }\n    }\n\n    in_uint32_le(s, rwso.visible_offset_x);\n    in_uint32_le(s, rwso.visible_offset_y);\n    in_uint16_le(s, rwso.num_visibility_rects);\n\n    if (rwso.num_visibility_rects > 0)\n    {\n        bytes = sizeof(struct rail_window_rect) * rwso.num_visibility_rects;\n        rwso.visibility_rects = (struct rail_window_rect *)g_malloc(bytes, 0);\n\n        for (index = 0; index < rwso.num_visibility_rects; index++)\n        {\n            in_uint16_le(s, rwso.visibility_rects[index].left);\n            in_uint16_le(s, rwso.visibility_rects[index].top);\n            in_uint16_le(s, rwso.visibility_rects[index].right);\n            in_uint16_le(s, rwso.visibility_rects[index].bottom);\n        }\n    }\n\n    in_uint32_le(s, flags);\n    mod->server_window_new_update(mod, window_id, &rwso, flags);\n    rv = 0;\n    g_free(rwso.title_info);\n    g_free(rwso.window_rects);\n    g_free(rwso.visibility_rects);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_window_delete(struct mod *mod, struct stream *s)\n{\n    int window_id;\n    int rv;\n\n    in_uint32_le(s, window_id);\n    mod->server_window_delete(mod, window_id);\n    rv = 0;\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_window_show(struct mod *mod, struct stream *s)\n{\n    int window_id;\n    int rv;\n    int flags;\n    struct rail_window_state_order rwso;\n\n    g_memset(&rwso, 0, sizeof(rwso));\n    in_uint32_le(s, window_id);\n    in_uint32_le(s, flags);\n    in_uint32_le(s, rwso.show_state);\n    mod->server_window_new_update(mod, window_id, &rwso, flags);\n    rv = 0;\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_add_char(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int font;\n    int character;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int len_bmpdata;\n    char *bmpdata;\n\n    in_uint16_le(s, font);\n    in_uint16_le(s, character);\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, cx);\n    in_uint16_le(s, cy);\n    in_uint16_le(s, len_bmpdata);\n    in_uint8p(s, bmpdata, len_bmpdata);\n    rv = mod->server_add_char(mod, font, character, x, y, cx, cy, bmpdata);\n    return rv;\n}\n\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_add_char_alpha(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int font;\n    int character;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int len_bmpdata;\n    char *bmpdata;\n\n    in_uint16_le(s, font);\n    in_uint16_le(s, character);\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, cx);\n    in_uint16_le(s, cy);\n    in_uint16_le(s, len_bmpdata);\n    in_uint8p(s, bmpdata, len_bmpdata);\n    rv = mod->server_add_char_alpha(mod, font, character, x, y, cx, cy,\n                                    bmpdata);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_draw_text(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int font;\n    int flags;\n    int mixmode;\n    int clip_left;\n    int clip_top;\n    int clip_right;\n    int clip_bottom;\n    int box_left;\n    int box_top;\n    int box_right;\n    int box_bottom;\n    int x;\n    int y;\n    int len_bmpdata;\n    char *bmpdata;\n\n    in_uint16_le(s, font);\n    in_uint16_le(s, flags);\n    in_uint16_le(s, mixmode);\n    in_sint16_le(s, clip_left);\n    in_sint16_le(s, clip_top);\n    in_sint16_le(s, clip_right);\n    in_sint16_le(s, clip_bottom);\n    in_sint16_le(s, box_left);\n    in_sint16_le(s, box_top);\n    in_sint16_le(s, box_right);\n    in_sint16_le(s, box_bottom);\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, len_bmpdata);\n    in_uint8p(s, bmpdata, len_bmpdata);\n    rv = mod->server_draw_text(mod, font, flags, mixmode, clip_left, clip_top,\n                               clip_right, clip_bottom, box_left, box_top,\n                               box_right, box_bottom, x, y, bmpdata, len_bmpdata);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_create_os_surface_bpp(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int rdpid;\n    int width;\n    int height;\n    int bpp;\n\n    in_uint32_le(s, rdpid);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n    in_uint8(s, bpp);\n    rv = mod->server_create_os_surface_bpp(mod, rdpid, width, height, bpp);\n    return rv;\n}\n\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_paint_rect_bpp(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int len_bmpdata;\n    char *bmpdata;\n    int width;\n    int height;\n    int srcx;\n    int srcy;\n    int bpp;\n\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, cx);\n    in_uint16_le(s, cy);\n    in_uint32_le(s, len_bmpdata);\n    in_uint8p(s, bmpdata, len_bmpdata);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n    in_sint16_le(s, srcx);\n    in_sint16_le(s, srcy);\n    in_uint8(s, bpp);\n    rv = mod->server_paint_rect_bpp(mod, x, y, cx, cy,\n                                    bmpdata, width, height,\n                                    srcx, srcy, bpp);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_composite(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int srcidx;\n    int srcformat;\n    int srcwidth;\n    int srcrepeat;\n    int transform[10];\n    int mskflags;\n    int mskidx;\n    int mskformat;\n    int mskwidth;\n    int mskrepeat;\n    int op;\n    int srcx;\n    int srcy;\n    int mskx;\n    int msky;\n    int dstx;\n    int dsty;\n    int width;\n    int height;\n    int dstformat;\n\n    in_uint16_le(s, srcidx);\n    in_uint32_le(s, srcformat);\n    in_uint16_le(s, srcwidth);\n    in_uint8(s, srcrepeat);\n    g_memcpy(transform, s->p, 40);\n    in_uint8s(s, 40);\n    in_uint8(s, mskflags);\n    in_uint16_le(s, mskidx);\n    in_uint32_le(s, mskformat);\n    in_uint16_le(s, mskwidth);\n    in_uint8(s, mskrepeat);\n    in_uint8(s, op);\n    in_sint16_le(s, srcx);\n    in_sint16_le(s, srcy);\n    in_sint16_le(s, mskx);\n    in_sint16_le(s, msky);\n    in_sint16_le(s, dstx);\n    in_sint16_le(s, dsty);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n    in_uint32_le(s, dstformat);\n    rv = mod->server_composite(mod, srcidx, srcformat, srcwidth, srcrepeat,\n                               transform, mskflags, mskidx, mskformat,\n                               mskwidth, mskrepeat, op, srcx, srcy, mskx, msky,\n                               dstx, dsty, width, height, dstformat);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_pointer_ex(struct mod *mod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    int bpp;\n    int Bpp;\n    char cur_data[32 * (32 * 4)];\n    char cur_mask[32 * (32 / 8)];\n\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, bpp);\n    Bpp = (bpp == 0) ? 3 : (bpp + 7) / 8;\n    in_uint8a(s, cur_data, 32 * (32 * Bpp));\n    in_uint8a(s, cur_mask, 32 * (32 / 8));\n    rv = mod->server_set_cursor_ex(mod, x, y, cur_data, cur_mask, bpp);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nsend_paint_rect_ack(struct mod *mod, int flags, int x, int y, int cx, int cy,\n                    int frame_id)\n{\n    int len;\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    s_push_layer(s, iso_hdr, 4);\n    out_uint16_le(s, 105);\n    out_uint32_le(s, flags);\n    out_uint32_le(s, frame_id);\n    out_uint32_le(s, x);\n    out_uint32_le(s, y);\n    out_uint32_le(s, cx);\n    out_uint32_le(s, cy);\n    s_mark_end(s);\n    len = (int)(s->end - s->data);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, len);\n    lib_send_copy(mod, s);\n    free_stream(s);\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_paint_rect_shmem(struct mod *amod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    int cx;\n    int cy;\n    int flags;\n    int frame_id;\n    int shmem_id;\n    int shmem_offset;\n    int width;\n    int height;\n    int srcx;\n    int srcy;\n    char *bmpdata;\n\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, cx);\n    in_uint16_le(s, cy);\n    in_uint32_le(s, flags);\n    in_uint32_le(s, frame_id);\n    in_uint32_le(s, shmem_id);\n    in_uint32_le(s, shmem_offset);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n    in_sint16_le(s, srcx);\n    in_sint16_le(s, srcy);\n\n    bmpdata = 0;\n    rv = 0;\n    if (amod->screen_shmem_id_mapped == 0)\n    {\n        amod->screen_shmem_id = shmem_id;\n        amod->screen_shmem_pixels = (char *) g_shmat(amod->screen_shmem_id);\n        if (amod->screen_shmem_pixels == (void *) -1)\n        {\n            /* failed */\n            amod->screen_shmem_id = 0;\n            amod->screen_shmem_pixels = 0;\n            amod->screen_shmem_id_mapped = 0;\n        }\n        else\n        {\n            amod->screen_shmem_id_mapped = 1;\n        }\n    }\n    else if (amod->screen_shmem_id != shmem_id)\n    {\n        amod->screen_shmem_id = shmem_id;\n        g_shmdt(amod->screen_shmem_pixels);\n        amod->screen_shmem_pixels = (char *) g_shmat(amod->screen_shmem_id);\n        if (amod->screen_shmem_pixels == (void *) -1)\n        {\n            /* failed */\n            amod->screen_shmem_id = 0;\n            amod->screen_shmem_pixels = 0;\n            amod->screen_shmem_id_mapped = 0;\n        }\n    }\n    if (amod->screen_shmem_pixels != 0)\n    {\n        bmpdata = amod->screen_shmem_pixels + shmem_offset;\n    }\n    if (bmpdata != 0)\n    {\n        rv = amod->server_paint_rect(amod, x, y, cx, cy,\n                                     bmpdata, width, height,\n                                     srcx, srcy);\n    }\n    send_paint_rect_ack(amod, flags, x, y, cx, cy, frame_id);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nsend_paint_rect_ex_ack(struct mod *mod, int flags, int frame_id)\n{\n    int len;\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    s_push_layer(s, iso_hdr, 4);\n    out_uint16_le(s, 106);\n    out_uint32_le(s, flags);\n    out_uint32_le(s, frame_id);\n    s_mark_end(s);\n    len = (int)(s->end - s->data);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, len);\n    lib_send_copy(mod, s);\n    free_stream(s);\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nsend_suppress_output(struct mod *mod, int suppress,\n                     int left, int top, int right, int bottom)\n{\n    int len;\n    struct stream *s;\n\n    make_stream(s);\n    init_stream(s, 8192);\n    s_push_layer(s, iso_hdr, 4);\n    out_uint16_le(s, 108);\n    out_uint32_le(s, suppress);\n    out_uint32_le(s, left);\n    out_uint32_le(s, top);\n    out_uint32_le(s, right);\n    out_uint32_le(s, bottom);\n    s_mark_end(s);\n    len = (int)(s->end - s->data);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, len);\n    lib_send_copy(mod, s);\n    free_stream(s);\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_paint_rect_shmem_ex(struct mod *amod, struct stream *s)\n{\n    LOG(LOG_LEVEL_TRACE, \"process_server_paint_rect_shmem_ex:\");\n\n    int num_drects;\n    int num_crects;\n    int flags;\n    int frame_id;\n    int shmem_id;\n    int shmem_offset;\n    int width;\n    int height;\n    int index;\n    int rv;\n    tsi16 *ldrects;\n    tsi16 *ldrects1;\n    tsi16 *lcrects;\n    tsi16 *lcrects1;\n    char *bmpdata;\n\n    /* dirty pixels */\n    in_uint16_le(s, num_drects);\n    ldrects = (tsi16 *) g_malloc(2 * 4 * num_drects, 0);\n    ldrects1 = ldrects;\n    for (index = 0; index < num_drects; index++)\n    {\n        in_sint16_le(s, ldrects1[0]);\n        in_sint16_le(s, ldrects1[1]);\n        in_sint16_le(s, ldrects1[2]);\n        in_sint16_le(s, ldrects1[3]);\n        ldrects1 += 4;\n    }\n\n    /* copied pixels */\n    in_uint16_le(s, num_crects);\n    lcrects = (tsi16 *) g_malloc(2 * 4 * num_crects, 0);\n    lcrects1 = lcrects;\n    for (index = 0; index < num_crects; index++)\n    {\n        in_sint16_le(s, lcrects1[0]);\n        in_sint16_le(s, lcrects1[1]);\n        in_sint16_le(s, lcrects1[2]);\n        in_sint16_le(s, lcrects1[3]);\n        lcrects1 += 4;\n    }\n\n    in_uint32_le(s, flags);\n    in_uint32_le(s, frame_id);\n    in_uint32_le(s, shmem_id);\n    in_uint32_le(s, shmem_offset);\n\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n\n    bmpdata = 0;\n    if (amod->screen_shmem_id_mapped == 0)\n    {\n        amod->screen_shmem_id = shmem_id;\n        amod->screen_shmem_pixels = (char *) g_shmat(amod->screen_shmem_id);\n        if (amod->screen_shmem_pixels == (void *) -1)\n        {\n            /* failed */\n            amod->screen_shmem_id = 0;\n            amod->screen_shmem_pixels = 0;\n            amod->screen_shmem_id_mapped = 0;\n        }\n        else\n        {\n            amod->screen_shmem_id_mapped = 1;\n        }\n    }\n    else if (amod->screen_shmem_id != shmem_id)\n    {\n        amod->screen_shmem_id = shmem_id;\n        g_shmdt(amod->screen_shmem_pixels);\n        amod->screen_shmem_pixels = (char *) g_shmat(amod->screen_shmem_id);\n        if (amod->screen_shmem_pixels == (void *) -1)\n        {\n            /* failed */\n            amod->screen_shmem_id = 0;\n            amod->screen_shmem_pixels = 0;\n            amod->screen_shmem_id_mapped = 0;\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_ERROR, \"process_server_paint_rect_shmem_ex:\"\n                  \" flags=%d frame_id=%d, shmem_id=%d, shmem_offset=%d,\"\n                  \" width=%d, height=%d\",\n                  flags, frame_id, shmem_id, shmem_offset,\n                  width, height);\n    }\n    if (amod->screen_shmem_pixels != 0)\n    {\n        bmpdata = amod->screen_shmem_pixels + shmem_offset;\n    }\n    if (bmpdata != 0)\n    {\n        rv = amod->server_paint_rects(amod, num_drects, ldrects,\n                                      num_crects, lcrects,\n                                      bmpdata, width, height,\n                                      flags, frame_id);\n    }\n    else\n    {\n        rv = 1;\n    }\n\n    g_free(lcrects);\n    g_free(ldrects);\n\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_egfx_shmfd(struct mod *amod, struct stream *s)\n{\n    char *data;\n    char *cmd;\n    int rv;\n    int cmd_bytes;\n    int shmem_bytes;\n    int fd;\n    int recv_bytes;\n    unsigned int num_fds;\n    void *shmem_ptr;\n    char msg[4];\n\n    rv = 0;\n    in_uint32_le(s, cmd_bytes);\n    in_uint8p(s, cmd, cmd_bytes);\n    in_uint32_le(s, shmem_bytes);\n    if (shmem_bytes == 0)\n    {\n        return amod->server_egfx_cmd(amod, cmd, cmd_bytes, NULL, 0);\n    }\n    fd = -1;\n    num_fds = -1;\n    if (g_tcp_can_recv(amod->trans->sck, 5000) == 0)\n    {\n        return 1;\n    }\n    recv_bytes = g_sck_recv_fd_set(amod->trans->sck, msg, 4, &fd, 1, &num_fds);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_server_egfx_shmfd: \"\n              \"g_sck_recv_fd_set rv %d fd %d\", recv_bytes, fd);\n    if (recv_bytes == 4)\n    {\n        if (num_fds == 1)\n        {\n            if (g_file_map(fd, 1, 0, shmem_bytes, &shmem_ptr) == 0)\n            {\n                /* we give up ownership of shmem_ptr\n                   will get cleaned up in server_egfx_cmd or\n                   xrdp_mm_process_enc_done(gfx) */\n                data = (char *) shmem_ptr;\n                rv = amod->server_egfx_cmd(amod, cmd, cmd_bytes,\n                                           data, shmem_bytes);\n            }\n            g_file_close(fd);\n        }\n    }\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_pointer_shmfd(struct mod *amod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n    int bpp;\n    int Bpp;\n    int width;\n    int height;\n    int fd;\n    int recv_bytes;\n    int shmembytes;\n    unsigned int num_fds;\n    void *shmemptr;\n    char *cur_data;\n    char *cur_mask;\n    char msg[4];\n\n    rv = 0;\n    in_sint16_le(s, x);\n    in_sint16_le(s, y);\n    in_uint16_le(s, bpp);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n    fd = -1;\n    num_fds = -1;\n    if (g_tcp_can_recv(amod->trans->sck, 5000) == 0)\n    {\n        return 1;\n    }\n    recv_bytes = g_sck_recv_fd_set(amod->trans->sck, msg, 4, &fd, 1, &num_fds);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_server_set_pointer_shmfd: \"\n              \"g_sck_recv_fd_set rv %d fd %d\", recv_bytes, fd);\n    if (recv_bytes == 4)\n    {\n        if (num_fds == 1)\n        {\n            Bpp = (bpp == 0) ? 3 : (bpp + 7) / 8;\n            shmembytes = width * height * Bpp + width * height / 8;\n            if (g_file_map(fd, 1, 0, shmembytes, &shmemptr) == 0)\n            {\n                cur_data = (char *)shmemptr;\n                cur_mask = cur_data + width * height * Bpp;\n                rv = amod->server_set_pointer_large(amod, x, y,\n                                                    cur_data, cur_mask,\n                                                    bpp, width, height);\n                g_munmap(shmemptr, shmembytes);\n            }\n            g_file_close(fd);\n        }\n    }\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_paint_rect_shmfd(struct mod *amod, struct stream *s)\n{\n    int num_drects;\n    int num_crects;\n    int flags;\n    int frame_id;\n    int shmem_bytes;\n    int shmem_offset;\n    int left;\n    int top;\n    int width;\n    int height;\n    int index;\n    int rv;\n    int16_t *ldrects;\n    int16_t *ldrects1;\n    int16_t *lcrects;\n    int16_t *lcrects1;\n    char *bmpdata;\n    int fd;\n    int recv_bytes;\n    unsigned int num_fds;\n    void *shmem_ptr;\n    char msg[4];\n\n    /* dirty pixels */\n    in_uint16_le(s, num_drects);\n    ldrects = g_new(int16_t, 2 * 4 * num_drects);\n    ldrects1 = ldrects;\n    for (index = 0; index < num_drects; index++)\n    {\n        in_sint16_le(s, ldrects1[0]);\n        in_sint16_le(s, ldrects1[1]);\n        in_sint16_le(s, ldrects1[2]);\n        in_sint16_le(s, ldrects1[3]);\n        ldrects1 += 4;\n    }\n\n    /* copied pixels */\n    in_uint16_le(s, num_crects);\n    lcrects = g_new(int16_t, 2 * 4 * num_crects);\n    lcrects1 = lcrects;\n    for (index = 0; index < num_crects; index++)\n    {\n        in_sint16_le(s, lcrects1[0]);\n        in_sint16_le(s, lcrects1[1]);\n        in_sint16_le(s, lcrects1[2]);\n        in_sint16_le(s, lcrects1[3]);\n        lcrects1 += 4;\n    }\n\n    in_uint32_le(s, flags);\n    in_uint32_le(s, frame_id);\n    in_uint32_le(s, shmem_bytes);\n    in_uint32_le(s, shmem_offset);\n\n    in_uint16_le(s, left);\n    in_uint16_le(s, top);\n    in_uint16_le(s, width);\n    in_uint16_le(s, height);\n\n    if (g_tcp_can_recv(amod->trans->sck, 5000) == 0)\n    {\n        g_free(ldrects);\n        g_free(lcrects);\n        return 1;\n    }\n    rv = 1;\n    recv_bytes = g_sck_recv_fd_set(amod->trans->sck, msg, 4, &fd, 1, &num_fds);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"process_server_paint_rect_shmfd: \"\n              \"g_sck_recv_fd_set rv %d fd %d\", recv_bytes, fd);\n    if (recv_bytes == 4)\n    {\n        if (num_fds == 1)\n        {\n            if (g_file_map(fd, 1, 0, shmem_bytes, &shmem_ptr) == 0)\n            {\n                bmpdata = (char *)shmem_ptr;\n                bmpdata += shmem_offset;\n                /* we give up ownership of shmem_ptr\n                   will get cleaned up in server_paint_rects_ex or\n                   xrdp_mm_process_enc_done(rfx, gfx) */\n                rv = amod->server_paint_rects_ex(amod, num_drects, ldrects,\n                                                 num_crects, lcrects, bmpdata,\n                                                 left, top, width, height,\n                                                 flags, frame_id,\n                                                 shmem_ptr, shmem_bytes);\n            }\n            g_file_close(fd);\n        }\n    }\n    g_free(ldrects);\n    g_free(lcrects);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_pointer_system(struct mod *amod, struct stream *s)\n{\n    int rv;\n    int pointer_type;\n\n    in_uint32_le(s, pointer_type);\n    rv = amod->server_set_pointer_system(amod, pointer_type);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nprocess_server_set_pointer_position(struct mod *amod, struct stream *s)\n{\n    int rv;\n    int x;\n    int y;\n\n    in_uint16_le(s, x);\n    in_uint16_le(s, y);\n    rv = amod->server_set_pointer_position(amod, x, y);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nsend_server_version_message(struct mod *mod, struct stream *s)\n{\n    /* send version message */\n    init_stream(s, 8192);\n    s_push_layer(s, iso_hdr, 4);\n    out_uint16_le(s, 103);\n    out_uint32_le(s, 301);\n    out_uint32_le(s, 0);\n    out_uint32_le(s, 0);\n    out_uint32_le(s, 0);\n    out_uint32_le(s, 1);\n    s_mark_end(s);\n    int len = (int)(s->end - s->data);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, len);\n    int rv = lib_send_copy(mod, s);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nsend_server_monitor_update(struct mod *mod, struct stream *s,\n                           int width, int height,\n                           int num_monitors,\n                           const struct monitor_info *monitors)\n{\n    /* send monitor update message */\n    init_stream(s, 8192);\n    s_push_layer(s, iso_hdr, 4);\n    out_uint16_le(s, 103);\n    out_uint32_le(s, 302);\n    out_uint32_le(s, width);\n    out_uint32_le(s, height);\n    out_uint32_le(s, num_monitors);\n    out_uint32_le(s, 0);\n    out_uint8a(s, monitors, sizeof(monitors[0]) * num_monitors);\n    s_mark_end(s);\n    int len = (int)(s->end - s->data);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, len);\n    int rv = lib_send_copy(mod, s);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"send_server_monitor_update:\"\n              \" sent monitor updsate message with following properties to\"\n              \" xorgxrdp backend width=%d, height=%d, num=%d, return value=%d\",\n              width, height, num_monitors, rv);\n    return rv;\n}\n\nstatic int\nsend_server_monitor_full_invalidate(\n    struct mod *mod, struct stream *s, int width, int height)\n{\n    /* send invalidate message */\n    init_stream(s, 8192);\n    s_push_layer(s, iso_hdr, 4);\n    out_uint16_le(s, 103);\n    out_uint32_le(s, 200);\n    /* x and y */\n    int i = 0;\n    out_uint32_le(s, i);\n    /* width and height */\n    i = ((width & 0xffff) << 16) | height;\n    out_uint32_le(s, i);\n    out_uint32_le(s, 0);\n    out_uint32_le(s, 0);\n    s_mark_end(s);\n    int len = (int)(s->end - s->data);\n    s_pop_layer(s, iso_hdr);\n    out_uint32_le(s, len);\n    int rv = lib_send_copy(mod, s);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"send_server_monitor_full_invalidate:\"\n              \" sent invalidate message with following\"\n              \" properties to xorgxrdp backend\"\n              \" width=%d, height=%d, return value=%d\",\n              width, height, rv);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_send_server_version_message(struct mod *mod)\n{\n    /* send server version message */\n    struct stream *s;\n    make_stream(s);\n    int rv = send_server_version_message(mod, s);\n    free_stream(s);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_send_server_monitor_resize(struct mod *mod, int width, int height,\n                               int num_monitors,\n                               const struct monitor_info *monitors,\n                               int *in_progress)\n{\n    struct stream *s;\n    make_stream(s);\n    int rv = send_server_monitor_update(mod, s, width, height,\n                                        num_monitors, monitors);\n    *in_progress = (rv == 0);\n    free_stream(s);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_send_server_monitor_full_invalidate(struct mod *mod, int width, int height)\n{\n    /* send invalidate message */\n    struct stream *s;\n    make_stream(s);\n    int rv = send_server_monitor_full_invalidate(mod, s, width, height);\n    free_stream(s);\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_process_orders(struct mod *mod, int type, struct stream *s)\n{\n    int rv;\n\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lib_mod_process_orders: type %d\", type);\n    rv = 0;\n    switch (type)\n    {\n        case 1: /* server_begin_update */\n            rv = mod->server_begin_update(mod);\n            break;\n        case 2: /* server_end_update */\n            rv = mod->server_end_update(mod);\n            break;\n        case 3: /* server_fill_rect */\n            rv = process_server_fill_rect(mod, s);\n            break;\n        case 4: /* server_screen_blt */\n            rv = process_server_screen_blt(mod, s);\n            break;\n        case 5: /* server_paint_rect */\n            rv = process_server_paint_rect(mod, s);\n            break;\n        case 10: /* server_set_clip */\n            rv = process_server_set_clip(mod, s);\n            break;\n        case 11: /* server_reset_clip */\n            rv = process_server_reset_clip(mod, s);\n            break;\n        case 12: /* server_set_fgcolor */\n            rv = process_server_set_fgcolor(mod, s);\n            break;\n        case 13: /* server_set_bgcolor */\n            rv = process_server_set_bgcolor(mod, s);\n            break;\n        case 14: /* server_set_opcode */\n            rv =  process_server_set_opcode(mod, s);\n            break;\n        case 17: /* server_set_pen */\n            rv = process_server_set_pen(mod, s);\n            break;\n        case 18: /* server_draw_line */\n            rv = process_server_draw_line(mod, s);\n            break;\n        case 19: /* server_set_cursor */\n            rv = process_server_set_cursor(mod, s);\n            break;\n        case 20: /* server_create_os_surface */\n            rv = process_server_create_os_surface(mod, s);\n            break;\n        case 21: /* server_switch_os_surface */\n            rv = process_server_switch_os_surface(mod, s);\n            break;\n        case 22: /* server_delete_os_surface */\n            rv = process_server_delete_os_surface(mod, s);\n            break;\n        case 23: /* server_paint_rect_os */\n            rv = process_server_paint_rect_os(mod, s);\n            break;\n        case 24: /* server_set_hints */\n            rv = process_server_set_hints(mod, s);\n            break;\n        case 25: /* server_window_new_update */\n            rv = process_server_window_new_update(mod, s);\n            break;\n        case 26: /* server_window_delete */\n            rv = process_server_window_delete(mod, s);\n            break;\n        case 27: /* server_window_new_update - show */\n            rv = process_server_window_show(mod, s);\n            break;\n        case 28: /* server_add_char */\n            rv = process_server_add_char(mod, s);\n            break;\n        case 29: /* server_add_char_alpha */\n            rv = process_server_add_char_alpha(mod, s);\n            break;\n        case 30: /* server_draw_text */\n            rv = process_server_draw_text(mod, s);\n            break;\n        case 31: /* server_create_os_surface_bpp */\n            rv = process_server_create_os_surface_bpp(mod, s);\n            break;\n        case 32: /* server_paint_rect_bpp */\n            rv = process_server_paint_rect_bpp(mod, s);\n            break;\n        case 33: /* server_composite */\n            rv = process_server_composite(mod, s);\n            break;\n        case 51: /* server_set_pointer_ex */\n            rv = process_server_set_pointer_ex(mod, s);\n            break;\n        case 60: /* server_paint_rect_shmem */\n            rv = process_server_paint_rect_shmem(mod, s);\n            break;\n        case 61: /* server_paint_rect_shmem_ex */\n            rv = process_server_paint_rect_shmem_ex(mod, s);\n            break;\n        case 62:\n            rv = process_server_egfx_shmfd(mod, s);\n            break;\n        case 63: /* server_set_pointer_shmfd */\n            rv = process_server_set_pointer_shmfd(mod, s);\n            break;\n        case 64: /* server_paint_rect_shmfd */\n            rv = process_server_paint_rect_shmfd(mod, s);\n            break;\n        case 65: /* server_set_pointer_system */\n            rv = process_server_set_pointer_system(mod, s);\n            break;\n        case 66: /* server_set_pointer_position */\n            rv = process_server_set_pointer_position(mod, s);\n            break;\n        default:\n            LOG_DEVEL(LOG_LEVEL_WARNING,\n                      \"lib_mod_process_orders: unknown order type %d\", type);\n            rv = 0;\n            break;\n    }\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_process_message(struct mod *mod, struct stream *s)\n{\n    int num_orders;\n    int index;\n    int rv;\n    int len;\n    int type;\n    char *phold;\n    int version;\n\n    int width;\n    int height;\n\n    LOG_DEVEL(LOG_LEVEL_TRACE, \"lib_mod_process_message:\");\n    in_uint16_le(s, type);\n    in_uint16_le(s, num_orders);\n    in_uint32_le(s, len);\n    LOG_DEVEL(LOG_LEVEL_DEBUG, \"lib_mod_process_message: type %d\", type);\n\n    rv = 0;\n    if (type == 1) /* original order list */\n    {\n        for (index = 0; index < num_orders; ++index)\n        {\n            in_uint16_le(s, type);\n            rv = lib_mod_process_orders(mod, type, s);\n\n            if (rv != 0)\n            {\n                break;\n            }\n        }\n    }\n    else if (type == 2) /* caps */\n    {\n        mod->caps_processing_status = E_CAPS_OK;   /* Assume all OK */\n        LOG_DEVEL(LOG_LEVEL_TRACE,\n                  \"lib_mod_process_message: type 2 len %d\", len);\n        for (index = 0; index < num_orders; index++)\n        {\n            phold = s->p;\n            in_uint16_le(s, type);\n            in_uint16_le(s, len);\n\n            switch (type)\n            {\n                case 100:\n                    in_uint32_le(s, version);\n                    if (version != XUP_CLIENT_INFO_CURRENT_VERSION)\n                    {\n                        char msg[128];\n                        g_snprintf(msg, sizeof(msg),\n                                   \"Xorg module has version %d, expected %d\",\n                                   version, XUP_CLIENT_INFO_CURRENT_VERSION);\n                        LOG(LOG_LEVEL_ERROR, \"%s\", msg);\n                        mod->server_msg(mod, msg, 0);\n                        mod->caps_processing_status = E_CAPS_NOT_OK;\n                    }\n                    break;\n\n                default:\n                    LOG_DEVEL(LOG_LEVEL_TRACE,\n                              \"lib_mod_process_message: unknown\"\n                              \" cap type %d len %d\",\n                              type, len);\n                    break;\n            }\n            s->p = phold + len;\n        }\n    }\n    else if (type == 3) /* order list with len after type */\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO,\n                  \"lib_mod_process_message: type 3 len %d\", len);\n        for (index = 0; index < num_orders; index++)\n        {\n            phold = s->p;\n            in_uint16_le(s, type);\n            in_uint16_le(s, len);\n            rv = lib_mod_process_orders(mod, type, s);\n\n            if (rv != 0)\n            {\n                break;\n            }\n\n            s->p = phold + len;\n        }\n    }\n    else if (type == 100) // metadata commands.\n    {\n        LOG_DEVEL(LOG_LEVEL_INFO,\n                  \"lib_mod_process_message: type 100 len %d\", len);\n        for (index = 0; index < num_orders; ++index)\n        {\n            phold = s->p;\n            in_uint16_le(s, type);\n            in_uint16_le(s, len);\n            switch (type)\n            {\n                case 3: // memory allocation complete\n                    in_uint16_le(s, width);\n                    in_uint16_le(s, height);\n                    LOG(LOG_LEVEL_INFO, \"Received memory_allocation_complete\"\n                        \" command. width: %d, height: %d\",\n                        width, height);\n                    rv = mod->server_monitor_resize_done(mod);\n                    break;\n            }\n            s->p = phold + len;\n        }\n    }\n    else\n    {\n        LOG_DEVEL(LOG_LEVEL_TRACE, \"unknown type %d\", type);\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_signal(struct mod *mod)\n{\n    // no-op\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_end(struct mod *mod)\n{\n    if (mod->screen_shmem_pixels != 0)\n    {\n        g_shmdt(mod->screen_shmem_pixels);\n        mod->screen_shmem_pixels = 0;\n    }\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_set_param(struct mod *mod, const char *name, const char *value)\n{\n    if (g_strcasecmp(name, \"username\") == 0)\n    {\n        g_strncpy(mod->username, value, INFO_CLIENT_MAX_CB_LEN - 1);\n    }\n    else if (g_strcasecmp(name, \"password\") == 0)\n    {\n        g_strncpy(mod->password, value, INFO_CLIENT_MAX_CB_LEN - 1);\n    }\n    else if (g_strcasecmp(name, \"ip\") == 0)\n    {\n        g_strncpy(mod->ip, value, 255);\n    }\n    else if (g_strcasecmp(name, \"port\") == 0)\n    {\n        g_strncpy(mod->port, value, 255);\n    }\n    else if (g_strcasecmp(name, \"keycode_set\") == 0)\n    {\n        g_snprintf(mod->keycode_set, sizeof(mod->keycode_set), \"%s\", value);\n    }\n    else if (g_strcasecmp(name, \"h264_frame_interval\") == 0)\n    {\n        mod->client_info.h264_frame_interval = g_atoi(value);\n    }\n    else if (g_strcasecmp(name, \"rfx_frame_interval\") == 0)\n    {\n        mod->client_info.rfx_frame_interval = g_atoi(value);\n    }\n    else if (g_strcasecmp(name, \"normal_frame_interval\") == 0)\n    {\n        mod->client_info.normal_frame_interval = g_atoi(value);\n    }\n    else if (g_strcasecmp(name, \"client_info\") == 0)\n    {\n        g_memcpy(&(mod->client_info), value, sizeof(mod->client_info));\n    }\n\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_get_wait_objs(struct mod *mod, tbus *read_objs, int *rcount,\n                      tbus *write_objs, int *wcount, int *timeout)\n{\n    if (mod != 0)\n    {\n        if (mod->trans != 0)\n        {\n            trans_get_wait_objs_rw(mod->trans, read_objs, rcount,\n                                   write_objs, wcount, timeout);\n        }\n    }\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_check_wait_objs(struct mod *mod)\n{\n    int rv;\n\n    rv = 0;\n    if (mod != 0)\n    {\n        if (mod->trans != 0)\n        {\n            rv = trans_check_wait_objs(mod->trans);\n            if (rv != 0)\n            {\n                LOG(LOG_LEVEL_ERROR, \"Xorg server closed connection\");\n            }\n        }\n    }\n\n    return rv;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_frame_ack(struct mod *amod, int flags, int frame_id)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE,\n              \"lib_mod_frame_ack: flags 0x%8.8x frame_id %d\", flags, frame_id);\n    send_paint_rect_ex_ack(amod, flags, frame_id);\n    return 0;\n}\n\n/******************************************************************************/\n/* return error */\nstatic int\nlib_mod_suppress_output(struct mod *amod, int suppress,\n                        int left, int top, int right, int bottom)\n{\n    LOG_DEVEL(LOG_LEVEL_TRACE,\n              \"lib_mod_suppress_output: suppress 0x%8.8x left %d top %d \"\n              \"right %d bottom %d\", suppress, left, top, right, bottom);\n    send_suppress_output(amod, suppress, left, top, right, bottom);\n    return 0;\n}\n\n/******************************************************************************/\ntintptr EXPORT_CC\nmod_init(void)\n{\n    struct mod *mod;\n\n    mod = (struct mod *)g_malloc(sizeof(struct mod), 1);\n    mod->size = sizeof(struct mod);\n    mod->version = CURRENT_MOD_VER;\n    mod->handle = (tintptr) mod;\n    mod->mod_connect = lib_mod_connect;\n    mod->mod_start = lib_mod_start;\n    mod->mod_event = lib_mod_event;\n    mod->mod_signal = lib_mod_signal;\n    mod->mod_end = lib_mod_end;\n    mod->mod_set_param = lib_mod_set_param;\n    mod->mod_get_wait_objs = lib_mod_get_wait_objs;\n    mod->mod_check_wait_objs = lib_mod_check_wait_objs;\n    mod->mod_frame_ack = lib_mod_frame_ack;\n    mod->mod_suppress_output = lib_mod_suppress_output;\n    mod->mod_server_monitor_resize = lib_send_server_monitor_resize;\n    mod->mod_server_monitor_full_invalidate\n        = lib_send_server_monitor_full_invalidate;\n    mod->mod_server_version_message = lib_send_server_version_message;\n    return (tintptr) mod;\n}\n\n/******************************************************************************/\nint EXPORT_CC\nmod_exit(tintptr handle)\n{\n    struct mod *mod = (struct mod *) handle;\n\n    if (mod == 0)\n    {\n        return 0;\n    }\n    trans_delete(mod->trans);\n    g_free(mod);\n    return 0;\n}\n"
  },
  {
    "path": "xup/xup.h",
    "content": "/**\n * xrdp: A Remote Desktop Protocol server.\n *\n * Copyright (C) Jay Sorg 2004-2015\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * libxup main header file\n */\n\n#ifndef XUP_H\n#define XUP_H\n\n/**\n * Enum for the states used to process a\n * capabilities message from the Xorg module\n */\nenum caps_processing_status\n{\n    E_CAPS_NOT_PROCESSED, ///< Capabilities mesage from module not processed\n    E_CAPS_OK,            ///< Capabilities are OK\n    E_CAPS_NOT_OK         ///< Capabilities are not OK\n};\n\n/* include other h files */\n#include \"arch.h\"\n#include \"parse.h\"\n#include \"os_calls.h\"\n#include \"defines.h\"\n#include \"log.h\"\n#include \"xrdp_client_info.h\"\n#include \"xrdp_constants.h\"\n#include \"xrdp_rail.h\"\n\n#define CURRENT_MOD_VER 4\n\nstruct source_info;\nstruct xrdp_client_info;\n\nstruct mod\n{\n    int size; /* size of this struct */\n    int version; /* internal version */\n    /* client functions */\n    int (*mod_start)(struct mod *v, int w, int h, int bpp);\n    int (*mod_connect)(struct mod *v, int fd);\n    int (*mod_event)(struct mod *v, int msg, tbus param1, tbus param2,\n                     tbus param3, tbus param4);\n    int (*mod_signal)(struct mod *v);\n    int (*mod_end)(struct mod *v);\n    int (*mod_set_param)(struct mod *v, const char *name, const char *value);\n    int (*mod_session_change)(struct mod *v, int, int);\n    int (*mod_get_wait_objs)(struct mod *v, tbus *read_objs, int *rcount,\n                             tbus *write_objs, int *wcount, int *timeout);\n    int (*mod_check_wait_objs)(struct mod *v);\n    int (*mod_frame_ack)(struct mod *v, int flags, int frame_id);\n    int (*mod_suppress_output)(struct mod *v, int suppress,\n                               int left, int top, int right, int bottom);\n    int (*mod_server_monitor_resize)(struct mod *v,\n                                     int width, int height,\n                                     int num_monitors,\n                                     const struct monitor_info *monitors,\n                                     int *in_progress);\n    int (*mod_server_monitor_full_invalidate)(struct mod *v,\n            int width, int height);\n    int (*mod_server_version_message)(struct mod *v);\n    tintptr mod_dumby[100 - 14]; /* align, 100 minus the number of mod\n                                 functions above */\n    /* server functions */\n    int (*server_begin_update)(struct mod *v);\n    int (*server_end_update)(struct mod *v);\n    int (*server_fill_rect)(struct mod *v, int x, int y, int cx, int cy);\n    int (*server_screen_blt)(struct mod *v, int x, int y, int cx, int cy,\n                             int srcx, int srcy);\n    int (*server_paint_rect)(struct mod *v, int x, int y, int cx, int cy,\n                             char *data, int width, int height,\n                             int srcx, int srcy);\n    int (*server_set_cursor)(struct mod *v, int x, int y, char *data, char *mask);\n    int (*server_palette)(struct mod *v, int *palette);\n    int (*server_msg)(struct mod *v, const char *msg, int code);\n    int (*server_is_term)(void);\n    int (*server_set_clip)(struct mod *v, int x, int y, int cx, int cy);\n    int (*server_reset_clip)(struct mod *v);\n    int (*server_set_fgcolor)(struct mod *v, int fgcolor);\n    int (*server_set_bgcolor)(struct mod *v, int bgcolor);\n    int (*server_set_opcode)(struct mod *v, int opcode);\n    int (*server_set_mixmode)(struct mod *v, int mixmode);\n    int (*server_set_brush)(struct mod *v, int x_origin, int y_origin,\n                            int style, char *pattern);\n    int (*server_set_pen)(struct mod *v, int style,\n                          int width);\n    int (*server_draw_line)(struct mod *v, int x1, int y1, int x2, int y2);\n    int (*server_add_char)(struct mod *v, int font, int character,\n                           int offset, int baseline,\n                           int width, int height, char *data);\n    int (*server_draw_text)(struct mod *v, int font,\n                            int flags, int mixmode, int clip_left, int clip_top,\n                            int clip_right, int clip_bottom,\n                            int box_left, int box_top,\n                            int box_right, int box_bottom,\n                            int x, int y, char *data, int data_len);\n    int (*client_monitor_resize)(struct mod *v, int width, int height,\n                                 int num_monitors,\n                                 const struct monitor_info *monitors);\n    int (*server_monitor_resize_done)(struct mod *v);\n    int (*server_get_channel_count)(struct mod *v);\n    int (*server_query_channel)(struct mod *v, int index,\n                                char *channel_name,\n                                int *channel_flags);\n    int (*server_get_channel_id)(struct mod *v, const char *name);\n    int (*server_send_to_channel)(struct mod *v, int channel_id,\n                                  char *data, int data_len,\n                                  int total_data_len, int flags);\n    int (*server_bell_trigger)(struct mod *v);\n    int (*server_chansrv_in_use)(struct mod *v);\n    void (*server_init_xkb_layout)(struct mod *v,\n                                   struct xrdp_client_info *client_info);\n    /* off screen bitmaps */\n    int (*server_create_os_surface)(struct mod *v, int rdpindex,\n                                    int width, int height);\n    int (*server_switch_os_surface)(struct mod *v, int rdpindex);\n    int (*server_delete_os_surface)(struct mod *v, int rdpindex);\n    int (*server_paint_rect_os)(struct mod *v, int x, int y,\n                                int cx, int cy,\n                                int rdpindex, int srcx, int srcy);\n    int (*server_set_hints)(struct mod *v, int hints, int mask);\n    /* rail */\n    int (*server_window_new_update)(struct mod *v, int window_id,\n                                    struct rail_window_state_order *window_state,\n                                    int flags);\n    int (*server_window_delete)(struct mod *v, int window_id);\n    int (*server_window_icon)(struct mod *v,\n                              int window_id, int cache_entry, int cache_id,\n                              struct rail_icon_info *icon_info,\n                              int flags);\n    int (*server_window_cached_icon)(struct mod *v,\n                                     int window_id, int cache_entry,\n                                     int cache_id, int flags);\n    int (*server_notify_new_update)(struct mod *v,\n                                    int window_id, int notify_id,\n                                    struct rail_notify_state_order *notify_state,\n                                    int flags);\n    int (*server_notify_delete)(struct mod *v, int window_id,\n                                int notify_id);\n    int (*server_monitored_desktop)(struct mod *v,\n                                    struct rail_monitored_desktop_order *mdo,\n                                    int flags);\n    int (*server_set_cursor_ex)(struct mod *v, int x, int y, char *data,\n                                char *mask, int bpp);\n    int (*server_add_char_alpha)(struct mod *v, int font, int character,\n                                 int offset, int baseline,\n                                 int width, int height, char *data);\n    int (*server_create_os_surface_bpp)(struct mod *v, int rdpindex,\n                                        int width, int height, int bpp);\n    int (*server_paint_rect_bpp)(struct mod *v, int x, int y, int cx, int cy,\n                                 char *data, int width, int height,\n                                 int srcx, int srcy, int bpp);\n    int (*server_composite)(struct mod *v, int srcidx, int srcformat, int srcwidth,\n                            int srcrepeat, int *srctransform, int mskflags, int mskidx,\n                            int mskformat, int mskwidth, int mskrepeat, int op,\n                            int srcx, int srcy, int mskx, int msky,\n                            int dstx, int dsty, int width, int height, int dstformat);\n    int (*server_paint_rects)(struct mod *v,\n                              int num_drects, short *drects,\n                              int num_crects, short *crects,\n                              char *data, int width, int height,\n                              int flags, int frame_id);\n    int (*server_session_info)(struct mod *v, const char *data,\n                               int data_bytes);\n    int (*server_set_pointer_large)(struct mod *v, int x, int y,\n                                    char *data, char *mask, int bpp,\n                                    int width, int height);\n    int (*server_paint_rects_ex)(struct mod *v,\n                                 int num_drects, short *drects,\n                                 int num_crects, short *crects,\n                                 char *data, int left, int top,\n                                 int width, int height,\n                                 int flags, int frame_id,\n                                 void *shmem_ptr, int shmem_bytes);\n    int (*server_egfx_cmd)(struct mod *v,\n                           char *cmd, int cmd_bytes,\n                           char *data, int data_bytes);\n    int (*server_set_pointer_system)(struct mod *v, int pointer_type);\n    int (*server_set_pointer_position)(struct mod *v, int x, int y);\n    tintptr server_dumby[100 - 53]; /* align, 100 minus the number of server\n                                     functions above */\n    /* common */\n    tintptr handle; /* pointer to self as long */\n    tintptr wm;\n    tintptr painter;\n    struct source_info *si;\n    /* mod data */\n    int width;\n    int height;\n    int bpp;\n    int sck_closed;\n    char username[INFO_CLIENT_MAX_CB_LEN];\n    char password[INFO_CLIENT_MAX_CB_LEN];\n    char ip[256];\n    char port[256];\n    int shift_state;\n    struct xrdp_client_info client_info;\n    int screen_shmem_id;\n    int screen_shmem_id_mapped; /* boolean */\n    char *screen_shmem_pixels;\n    struct trans *trans;\n    char keycode_set[32];\n    enum caps_processing_status caps_processing_status;\n};\n\n#endif // XUP_H\n"
  }
]