File: guid.h

package info (click to toggle)
xrdp 0.10.2-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 14,928 kB
  • sloc: ansic: 106,223; sh: 5,686; asm: 4,742; cpp: 2,555; makefile: 1,450
file content (94 lines) | stat: -rw-r--r-- 2,281 bytes parent folder | download | duplicates (2)
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
85
86
87
88
89
90
91
92
93
94
/**
 * xrdp: A Remote Desktop Protocol server.
 *
 * Copyright (C) Jay Sorg 2004-2021
 *
 * 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.h
 * @brief GUID manipulation declarations
  */

#ifndef GUID_H
#define GUID_H

#include "arch.h"

#define GUID_SIZE 16  /* bytes */
#define GUID_STR_SIZE (GUID_SIZE * 2 + 4 + 1)   /* w/ 4 hyphens + null terminator */


/**
 * Use a struct for the guid so we can easily copy by assignment.
 * We use an array of char so that
 * we can compare GUIDs with a straight memcmp()
 *
 * Some fields of the GUID are in little-endian-order as specified by
 * [MS-DTYP]. This is at odds with RFC4122 which specifies big-endian
 * order for all fields.
 *
 * Octets RFC4122 field
 * ------ -------------
 * 0-3    time_low (little-endian)
 * 4-5    time_mid (little-endian)
 * 6-7    time_hi_and_version (little-endian)
 * 8      clock_seq_hi_and_reserved
 * 9      clock_seq_low (in order)
 * 10-15  node
  */
struct guid
{
    char g[GUID_SIZE];
};

/**
 * Get an initialised GUID
 *
 * The GUID is compatible with RFC4122 section 4.4.
 *
 * @return new GUID
 */
struct guid guid_new(void);

/**
 * Clears an initialised GUID, so guid_is_set() returns true
 *
 * @param guid GUID to clear
 */
void
guid_clear(struct guid *guid);

/**
 * Checks if a GUID is initialised
 *
 * @param guid GUID to check (can be NULL)
 * @return non-zero if GUID is set
 */
int
guid_is_set(const struct guid *guid);

/**
 * Converts a GUID to a string representation
 *
 * @param guid GUID to represent
 * @param dest destionation pointer to at least GUID_STR_SIZE
 *             bytes to store the representation
 * @return dest is returned for convenience
 */
const char *guid_to_str(const struct guid *guid, char *dest);

#endif