Welcome to mirror list, hosted at ThFree Co, Russian Federation.

guid.c « common - github.com/neutrinolabs/xrdp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cf863648a5156cbac4893acd2343342905602268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
 * xrdp: A Remote Desktop Protocol server.
 *
 * Copyright (C) 2021 Matt Burt, all xrdp contributors
 *
 * 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.
 *
 */

/**
 * @file common/guid.c
 * @brief GUID manipulation definitions
 */

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

#include "guid.h"
#include "os_calls.h"
#include "string_calls.h"

struct guid
guid_new(void)
{
    struct guid guid = {0};
    g_random(guid.g, sizeof(guid.g));
    return guid;
}

void
guid_clear(struct guid *guid)
{
    g_memset(&guid->g, '\x00', GUID_SIZE);
}

int
guid_is_set(const struct guid *guid)
{
    unsigned int i;
    int rv = 0;
    if (guid != NULL)
    {
        for (i = 0 ; i < GUID_SIZE; ++i)
        {
            if (guid->g[i] != '\x00')
            {
                rv = 1;
                break;
            }
        }
    }

    return rv;

}

const char *guid_to_str(const struct guid *src, char *dest)
{
    const unsigned char *guid = (const unsigned char *)src->g;

    /*
     * Flipping integers into little-endian
     * See also: https://devblogs.microsoft.com/oldnewthing/20220928-00/?p=107221
     */
    g_sprintf(dest, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
              guid[3], guid[2], guid[1], guid[0],
              guid[5], guid[4],
              guid[7], guid[6],
              guid[8], guid[9],
              guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]);

    return dest;
}