Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/XRDP/xrdp/   (X11 Server Version 0.10.6.1©)  Datei vom 7.6.2026 mit Größe 9 kB image not shown  

Quelle  lang.c

  Sprache: C
 

/**
 * xrdp: A Remote Desktop Protocol server.
 *
 * Copyright (C) Jay Sorg 2004-2014
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * keylayout
 * maximum unicode 19996(0x4e00)
 */


#if defined(HAVE_CONFIG_H)
#include <config_ac.h>
#endif

#include "xrdp.h"
#include "ms-rdpbcgr.h"
#include "log.h"
#include "string_calls.h"

/* map for rdp to x11 scancodes
   code1 is regular scancode, code2 is extended scancode */

struct codepair
{
    tui8 code1;
    tui8 code2;
};
static struct codepair g_map[] =
{
    { 00 }, { 90 }, { 100 }, { 110 }, { 120 }, /* 0 - 4 */
    { 130 }, { 140 }, { 150 }, { 160 }, { 170 }, /* 5 - 9 */
    { 180 }, { 190 }, { 200 }, { 210 }, { 220 }, /* 10 - 14 */
    { 230 }, { 240 }, { 250 }, { 260 }, { 270 }, /* 15 - 19 */
    { 280 }, { 290 }, { 300 }, { 310 }, { 320 }, /* 20 - 24 */
    { 330 }, { 340 }, { 350 }, { 36108 }, { 37109 }, /* 25 - 29 */
    { 380 }, { 390 }, { 400 }, { 410 }, { 420 }, /* 30 - 34 */
    { 430 }, { 440 }, { 450 }, { 460 }, { 470 }, /* 35 - 39 */
    { 480 }, { 490 }, { 500 }, { 510 }, { 520 }, /* 40 - 44 */
    { 530 }, { 540 }, { 550 }, { 560 }, { 570 }, /* 45 - 49 */
    { 580 }, { 590 }, { 600 }, { 61112 }, { 620 }, /* 50 - 54 */
    { 63111 }, { 64113 }, { 650 }, { 660 }, { 670 }, /* 55 - 59 */
    { 680 }, { 690 }, { 700 }, { 710 }, { 720 }, /* 60 - 64 */
    { 730 }, { 740 }, { 750 }, { 760 }, { 770 }, /* 65 - 69 */
    { 780 }, { 7997 }, { 8098 }, { 8199 }, { 820 }, /* 70 - 74 */
    { 83100 }, { 840 }, { 85102 }, { 860 }, { 87103 }, /* 75 - 79 */
    { 88104 }, { 89105 }, { 90106 }, { 91107 }, { 920 }, /* 80 - 84 */
    { 930 }, { 940 }, { 950 }, { 960 }, { 970 }, /* 85 - 89 */
    { 980 }, { 0115 }, { 0116 }, { 0117 }, { 1020 }, /* 90 - 94 */
    { 1030 }, { 1040 }, { 1050 }, { 1060 }, { 1070 }, /* 95 - 99 */
    { 1080 }, { 1090 }, { 1100 }, { 1110 }, { 1120 }, /* 100 - 104 */
    { 1130 }, { 1140 }, { 1150 }, { 1160 }, { 1170 }, /* 105 - 109 */
    { 1180 }, { 1190 }, { 1200 }, { 1210 }, { 1220 }, /* 110 - 114 */
    { 1230 }, { 1240 }, { 1250 }, { 1260 }, { 1270 }, /* 115 - 119 */
    { 1280 }, { 1290 }, { 1300 }, { 1310 }, { 1320 }, /* 120 - 124 */
    { 1330 }, { 1340 }, { 1350 } /* 125 - 127 */
};

/*****************************************************************************/
struct xrdp_key_info *
get_key_info_from_scan_code(int device_flags, int scan_code, int *keys,
                            int caps_lock, int num_lock, int scroll_lock,
                            struct xrdp_keymap *keymap)
{
    struct xrdp_key_info *rv;
    int shift;
    int altgr;
    int ext;
    int index;

    ext = device_flags & KBD_FLAG_EXT;  /* 0x0100 */
    shift = keys[42] || keys[54];
    altgr = keys[56] & KBD_FLAG_EXT;  /* right alt */
    rv = 0;
    scan_code = scan_code & 0x7f;
    index = ext ? g_map[scan_code].code2 : g_map[scan_code].code1;

    /* keymap file is created with numlock off so we have to do this */
    if ((index >= 79) && (index <= 91))
    {
        if (num_lock)
        {
            rv = &(keymap->keys_shift[index]);
        }
        else
        {
            rv = &(keymap->keys_noshift[index]);
        }
    }
    else if (shift && caps_lock && altgr)
    {
        rv = &(keymap->keys_shiftcapslockaltgr[index]);
    }
    else if (shift && caps_lock)
    {
        rv = &(keymap->keys_shiftcapslock[index]);
    }
    else if (shift && altgr)
    {
        rv = &(keymap->keys_shiftaltgr[index]);
    }
    else if (shift)
    {
        rv = &(keymap->keys_shift[index]);
    }
    else if (caps_lock && altgr)
    {
        rv = &(keymap->keys_capslockaltgr[index]);
    }
    else if (caps_lock)
    {
        rv = &(keymap->keys_capslock[index]);
    }
    else if (altgr)
    {
        rv = &(keymap->keys_altgr[index]);
    }
    else
    {
        rv = &(keymap->keys_noshift[index]);
    }

    return rv;
}

/*****************************************************************************/
int
get_keysym_from_scan_code(int device_flags, int scan_code, int *keys,
                          int caps_lock, int num_lock, int scroll_lock,
                          struct xrdp_keymap *keymap)
{
    struct xrdp_key_info *ki;

    ki = get_key_info_from_scan_code(device_flags, scan_code, keys,
                                     caps_lock, num_lock, scroll_lock,
                                     keymap);

    if (ki == 0)
    {
        return 0;
    }

    return ki->sym;
}

/*****************************************************************************/
char32_t
get_char_from_scan_code(int device_flags, int scan_code, int *keys,
                        int caps_lock, int num_lock, int scroll_lock,
                        struct xrdp_keymap *keymap)
{
    struct xrdp_key_info *ki;

    ki = get_key_info_from_scan_code(device_flags, scan_code, keys,
                                     caps_lock, num_lock, scroll_lock,
                                     keymap);

    if (ki == 0)
    {
        return 0;
    }

    return ki->chr;
}

/*****************************************************************************/
static int
km_read_section(int fd, const char *section_name, struct xrdp_key_info *keymap)
{
    struct list *names;
    struct list *values;
    int index;
    int code;
    int pos1;
    char *name;
    char *value;

    names = list_create();
    names->auto_free = 1;
    values = list_create();
    values->auto_free = 1;

    if (file_read_section(fd, section_name, names, values) == 0)
    {
        for (index = names->count - 1; index >= 0; index--)
        {
            name = (char *)list_get_item(names, index);
            value = (char *)list_get_item(values, index);

            if ((name != 0) && (value != 0))
            {
                if (g_strncasecmp(name, "key"3) == 0)
                {
                    code = g_atoi(name + 3);
                }
                else
                {
                    code = g_atoi(name);
                }

                if ((code >= 0) && (code < 256))
                {
                    pos1 = g_pos(value, ":");

                    if (pos1 >= 0)
                    {
                        keymap[code].chr = g_atoi(value + pos1 + 1);
                    }

                    keymap[code].sym = g_atoi(value);
                }
            }
        }
    }

    list_delete(names);
    list_delete(values);
    return 0;
}

/*****************************************************************************/
int
get_keymaps(int keylayout, struct xrdp_keymap *keymap)
{
    int basic_key_layout = keylayout & 0x0000ffff;
    char *filename;
    struct xrdp_keymap *lkeymap;

    filename = (char *)g_malloc(2560);

    /* check if there is a keymap file e.g. km-e00100411.ini */
    g_snprintf(filename, 255"%s/km-%08x.ini", XRDP_CFG_PATH, keylayout);

    /* if the file does not exist, use only lower 16 bits instead */
    if (!g_file_exist(filename))
    {
        LOG(LOG_LEVEL_WARNING, "Cannot find keymap file %s", filename);
        /* e.g. km-00000411.ini */
        g_snprintf(filename, 255"%s/km-%08x.ini", XRDP_CFG_PATH, basic_key_layout);
    }

    /* finally, use 'en-us' */
    if (!g_file_exist(filename))
    {
        LOG(LOG_LEVEL_WARNING, "Cannot find keymap file %s", filename);
        g_snprintf(filename, 255"%s/km-00000409.ini", XRDP_CFG_PATH);
    }

    if (g_file_exist(filename))
    {

        lkeymap = (struct xrdp_keymap *)g_malloc(sizeof(struct xrdp_keymap), 0);
        /* make a copy of the built-in keymap */
        g_memcpy(lkeymap, keymap, sizeof(struct xrdp_keymap));

        km_load_file(filename, keymap);

        if (g_memcmp(lkeymap, keymap, sizeof(struct xrdp_keymap)) != 0)
        {
            LOG(LOG_LEVEL_WARNING,
                "local keymap file for 0x%08x found and doesn't match "
                "built in keymap, using local keymap file", keylayout);
        }

        g_free(lkeymap);
    }
    else
    {
        LOG(LOG_LEVEL_WARNING, "File does not exist: %s", filename);
    }

    g_free(filename);
    return 0;
}

/*****************************************************************************/
int km_load_file(const char *filename, struct xrdp_keymap *keymap)
{
    int fd;

    LOG(LOG_LEVEL_INFO, "Loading keymap file %s", filename);
    fd = g_file_open_ro(filename);

    if (fd != -1)
    {
        /* read the keymaps */
        km_read_section(fd, "noshift", keymap->keys_noshift);
        km_read_section(fd, "shift", keymap->keys_shift);
        km_read_section(fd, "altgr", keymap->keys_altgr);
        km_read_section(fd, "shiftaltgr", keymap->keys_shiftaltgr);
        km_read_section(fd, "capslock", keymap->keys_capslock);
        km_read_section(fd, "capslockaltgr", keymap->keys_capslockaltgr);
        km_read_section(fd, "shiftcapslock", keymap->keys_shiftcapslock);
        km_read_section(fd, "shiftcapslockaltgr", keymap->keys_shiftcapslockaltgr);

        g_file_close(fd);
    }
    else
    {
        LOG(LOG_LEVEL_ERROR, "Error loading keymap file %s (%s)", filename, g_get_strerror());
        return 1;
    }

    return 0;
}

Messung V0.5 in Prozent
C=94 H=96 G=94

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-07-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.